1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Util
; use Exp_Util
;
33 with Fname
; use Fname
;
34 with Itypes
; use Itypes
;
36 with Lib
.Xref
; use Lib
.Xref
;
37 with Namet
; use Namet
;
38 with Nlists
; use Nlists
;
39 with Nmake
; use Nmake
;
41 with Output
; use Output
;
42 with Restrict
; use Restrict
;
43 with Rident
; use Rident
;
44 with Rtsfind
; use Rtsfind
;
46 with Sem_Cat
; use Sem_Cat
;
47 with Sem_Ch3
; use Sem_Ch3
;
48 with Sem_Ch8
; use Sem_Ch8
;
49 with Sem_Dist
; use Sem_Dist
;
50 with Sem_Eval
; use Sem_Eval
;
51 with Sem_Res
; use Sem_Res
;
52 with Sem_Util
; use Sem_Util
;
53 with Sem_Type
; use Sem_Type
;
54 with Stand
; use Stand
;
55 with Sinfo
; use Sinfo
;
56 with Snames
; use Snames
;
57 with Tbuild
; use Tbuild
;
59 with GNAT
.Spelling_Checker
; use GNAT
.Spelling_Checker
;
61 package body Sem_Ch4
is
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 procedure Analyze_Expression
(N
: Node_Id
);
68 -- For expressions that are not names, this is just a call to analyze.
69 -- If the expression is a name, it may be a call to a parameterless
70 -- function, and if so must be converted into an explicit call node
71 -- and analyzed as such. This deproceduring must be done during the first
72 -- pass of overload resolution, because otherwise a procedure call with
73 -- overloaded actuals may fail to resolve. See 4327-001 for an example.
75 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
);
76 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
77 -- is an operator name or an expanded name whose selector is an operator
78 -- name, and one possible interpretation is as a predefined operator.
80 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
);
81 -- If the prefix of a selected_component is overloaded, the proper
82 -- interpretation that yields a record type with the proper selector
83 -- name must be selected.
85 procedure Analyze_User_Defined_Binary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
86 -- Procedure to analyze a user defined binary operator, which is resolved
87 -- like a function, but instead of a list of actuals it is presented
88 -- with the left and right operands of an operator node.
90 procedure Analyze_User_Defined_Unary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
91 -- Procedure to analyze a user defined unary operator, which is resolved
92 -- like a function, but instead of a list of actuals, it is presented with
93 -- the operand of the operator node.
95 procedure Ambiguous_Operands
(N
: Node_Id
);
96 -- for equality, membership, and comparison operators with overloaded
97 -- arguments, list possible interpretations.
99 procedure Analyze_One_Call
103 Success
: out Boolean;
104 Skip_First
: Boolean := False);
105 -- Check one interpretation of an overloaded subprogram name for
106 -- compatibility with the types of the actuals in a call. If there is a
107 -- single interpretation which does not match, post error if Report is
110 -- Nam is the entity that provides the formals against which the actuals
111 -- are checked. Nam is either the name of a subprogram, or the internal
112 -- subprogram type constructed for an access_to_subprogram. If the actuals
113 -- are compatible with Nam, then Nam is added to the list of candidate
114 -- interpretations for N, and Success is set to True.
116 -- The flag Skip_First is used when analyzing a call that was rewritten
117 -- from object notation. In this case the first actual may have to receive
118 -- an explicit dereference, depending on the first formal of the operation
119 -- being called. The caller will have verified that the object is legal
120 -- for the call. If the remaining parameters match, the first parameter
121 -- will rewritten as a dereference if needed, prior to completing analysis.
123 procedure Check_Misspelled_Selector
126 -- Give possible misspelling diagnostic if Sel is likely to be
127 -- a misspelling of one of the selectors of the Prefix.
128 -- This is called by Analyze_Selected_Component after producing
129 -- an invalid selector error message.
131 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean;
132 -- Verify that type T is declared in scope S. Used to find intepretations
133 -- for operators given by expanded names. This is abstracted as a separate
134 -- function to handle extensions to System, where S is System, but T is
135 -- declared in the extension.
137 procedure Find_Arithmetic_Types
141 -- L and R are the operands of an arithmetic operator. Find
142 -- consistent pairs of interpretations for L and R that have a
143 -- numeric type consistent with the semantics of the operator.
145 procedure Find_Comparison_Types
149 -- L and R are operands of a comparison operator. Find consistent
150 -- pairs of interpretations for L and R.
152 procedure Find_Concatenation_Types
156 -- For the four varieties of concatenation
158 procedure Find_Equality_Types
162 -- Ditto for equality operators
164 procedure Find_Boolean_Types
168 -- Ditto for binary logical operations
170 procedure Find_Negation_Types
174 -- Find consistent interpretation for operand of negation operator
176 procedure Find_Non_Universal_Interpretations
181 -- For equality and comparison operators, the result is always boolean,
182 -- and the legality of the operation is determined from the visibility
183 -- of the operand types. If one of the operands has a universal interpre-
184 -- tation, the legality check uses some compatible non-universal
185 -- interpretation of the other operand. N can be an operator node, or
186 -- a function call whose name is an operator designator.
188 procedure Find_Unary_Types
192 -- Unary arithmetic types: plus, minus, abs
194 procedure Check_Arithmetic_Pair
198 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
199 -- types for left and right operand. Determine whether they constitute
200 -- a valid pair for the given operator, and record the corresponding
201 -- interpretation of the operator node. The node N may be an operator
202 -- node (the usual case) or a function call whose prefix is an operator
203 -- designator. In both cases Op_Id is the operator name itself.
205 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
);
206 -- Give detailed information on overloaded call where none of the
207 -- interpretations match. N is the call node, Nam the designator for
208 -- the overloaded entity being called.
210 function Junk_Operand
(N
: Node_Id
) return Boolean;
211 -- Test for an operand that is an inappropriate entity (e.g. a package
212 -- name or a label). If so, issue an error message and return True. If
213 -- the operand is not an inappropriate entity kind, return False.
215 procedure Operator_Check
(N
: Node_Id
);
216 -- Verify that an operator has received some valid interpretation. If none
217 -- was found, determine whether a use clause would make the operation
218 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
219 -- every type compatible with the operator, even if the operator for the
220 -- type is not directly visible. The routine uses this type to emit a more
221 -- informative message.
223 procedure Process_Implicit_Dereference_Prefix
226 -- Called when P is the prefix of an implicit dereference, denoting an
227 -- object E. If in semantics only mode (-gnatc or generic), record that is
228 -- a reference to E. Normally, such a reference is generated only when the
229 -- implicit dereference is expanded into an explicit one. E may be empty,
230 -- in which case this procedure does nothing.
232 procedure Remove_Abstract_Operations
(N
: Node_Id
);
233 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
234 -- operation is not a candidate interpretation.
236 function Try_Indexed_Call
239 Typ
: Entity_Id
) return Boolean;
240 -- If a function has defaults for all its actuals, a call to it may
241 -- in fact be an indexing on the result of the call. Try_Indexed_Call
242 -- attempts the interpretation as an indexing, prior to analysis as
243 -- a call. If both are possible, the node is overloaded with both
244 -- interpretations (same symbol but two different types).
246 function Try_Indirect_Call
249 Typ
: Entity_Id
) return Boolean;
250 -- Similarly, a function F that needs no actuals can return an access
251 -- to a subprogram, and the call F (X) interpreted as F.all (X). In
252 -- this case the call may be overloaded with both interpretations.
254 function Try_Object_Operation
(N
: Node_Id
) return Boolean;
255 -- Ada 2005 (AI-252): Give support to the object operation notation
257 ------------------------
258 -- Ambiguous_Operands --
259 ------------------------
261 procedure Ambiguous_Operands
(N
: Node_Id
) is
262 procedure List_Operand_Interps
(Opnd
: Node_Id
);
264 --------------------------
265 -- List_Operand_Interps --
266 --------------------------
268 procedure List_Operand_Interps
(Opnd
: Node_Id
) is
273 if Is_Overloaded
(Opnd
) then
274 if Nkind
(Opnd
) in N_Op
then
276 elsif Nkind
(Opnd
) = N_Function_Call
then
286 if Opnd
= Left_Opnd
(N
) then
288 ("\left operand has the following interpretations", N
);
291 ("\right operand has the following interpretations", N
);
295 List_Interps
(Nam
, Err
);
296 end List_Operand_Interps
;
298 -- Start of processing for Ambiguous_Operands
302 or else Nkind
(N
) = N_Not_In
304 Error_Msg_N
("ambiguous operands for membership", N
);
306 elsif Nkind
(N
) = N_Op_Eq
307 or else Nkind
(N
) = N_Op_Ne
309 Error_Msg_N
("ambiguous operands for equality", N
);
312 Error_Msg_N
("ambiguous operands for comparison", N
);
315 if All_Errors_Mode
then
316 List_Operand_Interps
(Left_Opnd
(N
));
317 List_Operand_Interps
(Right_Opnd
(N
));
319 Error_Msg_N
("\use -gnatf switch for details", N
);
321 end Ambiguous_Operands
;
323 -----------------------
324 -- Analyze_Aggregate --
325 -----------------------
327 -- Most of the analysis of Aggregates requires that the type be known,
328 -- and is therefore put off until resolution.
330 procedure Analyze_Aggregate
(N
: Node_Id
) is
332 if No
(Etype
(N
)) then
333 Set_Etype
(N
, Any_Composite
);
335 end Analyze_Aggregate
;
337 -----------------------
338 -- Analyze_Allocator --
339 -----------------------
341 procedure Analyze_Allocator
(N
: Node_Id
) is
342 Loc
: constant Source_Ptr
:= Sloc
(N
);
343 Sav_Errs
: constant Nat
:= Serious_Errors_Detected
;
344 E
: Node_Id
:= Expression
(N
);
345 Acc_Type
: Entity_Id
;
349 Check_Restriction
(No_Allocators
, N
);
351 if Nkind
(E
) = N_Qualified_Expression
then
352 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
353 Set_Etype
(Acc_Type
, Acc_Type
);
354 Init_Size_Align
(Acc_Type
);
355 Find_Type
(Subtype_Mark
(E
));
356 Type_Id
:= Entity
(Subtype_Mark
(E
));
357 Check_Fully_Declared
(Type_Id
, N
);
358 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
360 if Is_Limited_Type
(Type_Id
)
361 and then Comes_From_Source
(N
)
362 and then not In_Instance_Body
364 -- Ada 2005 (AI-287): Do not post an error if the expression
365 -- corresponds to a limited aggregate. Limited aggregates
366 -- are checked in sem_aggr in a per-component manner
367 -- (compare with handling of Get_Value subprogram).
369 if Ada_Version
>= Ada_05
370 and then Nkind
(Expression
(E
)) = N_Aggregate
374 Error_Msg_N
("initialization not allowed for limited types", N
);
375 Explain_Limited_Type
(Type_Id
, N
);
379 Analyze_And_Resolve
(Expression
(E
), Type_Id
);
381 -- A qualified expression requires an exact match of the type,
382 -- class-wide matching is not allowed.
384 if Is_Class_Wide_Type
(Type_Id
)
385 and then Base_Type
(Etype
(Expression
(E
))) /= Base_Type
(Type_Id
)
387 Wrong_Type
(Expression
(E
), Type_Id
);
390 Check_Non_Static_Context
(Expression
(E
));
392 -- We don't analyze the qualified expression itself because it's
393 -- part of the allocator
395 Set_Etype
(E
, Type_Id
);
397 -- Case where no qualified expression is present
402 Base_Typ
: Entity_Id
;
405 -- If the allocator includes a N_Subtype_Indication then a
406 -- constraint is present, otherwise the node is a subtype mark.
407 -- Introduce an explicit subtype declaration into the tree
408 -- defining some anonymous subtype and rewrite the allocator to
409 -- use this subtype rather than the subtype indication.
411 -- It is important to introduce the explicit subtype declaration
412 -- so that the bounds of the subtype indication are attached to
413 -- the tree in case the allocator is inside a generic unit.
415 if Nkind
(E
) = N_Subtype_Indication
then
417 -- A constraint is only allowed for a composite type in Ada
418 -- 95. In Ada 83, a constraint is also allowed for an
419 -- access-to-composite type, but the constraint is ignored.
421 Find_Type
(Subtype_Mark
(E
));
422 Base_Typ
:= Entity
(Subtype_Mark
(E
));
424 if Is_Elementary_Type
(Base_Typ
) then
425 if not (Ada_Version
= Ada_83
426 and then Is_Access_Type
(Base_Typ
))
428 Error_Msg_N
("constraint not allowed here", E
);
430 if Nkind
(Constraint
(E
))
431 = N_Index_Or_Discriminant_Constraint
434 ("\if qualified expression was meant, " &
435 "use apostrophe", Constraint
(E
));
439 -- Get rid of the bogus constraint:
441 Rewrite
(E
, New_Copy_Tree
(Subtype_Mark
(E
)));
442 Analyze_Allocator
(N
);
445 -- Ada 2005, AI-363: if the designated type has a constrained
446 -- partial view, it cannot receive a discriminant constraint,
447 -- and the allocated object is unconstrained.
449 elsif Ada_Version
>= Ada_05
450 and then Has_Constrained_Partial_View
(Base_Typ
)
453 ("constraint no allowed when type " &
454 "has a constrained partial view", Constraint
(E
));
457 if Expander_Active
then
459 Make_Defining_Identifier
(Loc
, New_Internal_Name
('S'));
462 Make_Subtype_Declaration
(Loc
,
463 Defining_Identifier
=> Def_Id
,
464 Subtype_Indication
=> Relocate_Node
(E
)));
466 if Sav_Errs
/= Serious_Errors_Detected
467 and then Nkind
(Constraint
(E
))
468 = N_Index_Or_Discriminant_Constraint
471 ("if qualified expression was meant, " &
472 "use apostrophe!", Constraint
(E
));
475 E
:= New_Occurrence_Of
(Def_Id
, Loc
);
476 Rewrite
(Expression
(N
), E
);
480 Type_Id
:= Process_Subtype
(E
, N
);
481 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
482 Set_Etype
(Acc_Type
, Acc_Type
);
483 Init_Size_Align
(Acc_Type
);
484 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
485 Check_Fully_Declared
(Type_Id
, N
);
489 if Can_Never_Be_Null
(Type_Id
) then
490 Error_Msg_N
("(Ada 2005) qualified expression required",
494 -- Check restriction against dynamically allocated protected
495 -- objects. Note that when limited aggregates are supported,
496 -- a similar test should be applied to an allocator with a
497 -- qualified expression ???
499 if Is_Protected_Type
(Type_Id
) then
500 Check_Restriction
(No_Protected_Type_Allocators
, N
);
503 -- Check for missing initialization. Skip this check if we already
504 -- had errors on analyzing the allocator, since in that case these
505 -- are probably cascaded errors
507 if Is_Indefinite_Subtype
(Type_Id
)
508 and then Serious_Errors_Detected
= Sav_Errs
510 if Is_Class_Wide_Type
(Type_Id
) then
512 ("initialization required in class-wide allocation", N
);
515 ("initialization required in unconstrained allocation", N
);
521 if Is_Abstract
(Type_Id
) then
522 Error_Msg_N
("cannot allocate abstract object", E
);
525 if Has_Task
(Designated_Type
(Acc_Type
)) then
526 Check_Restriction
(No_Tasking
, N
);
527 Check_Restriction
(Max_Tasks
, N
);
528 Check_Restriction
(No_Task_Allocators
, N
);
531 -- If the No_Streams restriction is set, check that the type of the
532 -- object is not, and does not contain, any subtype derived from
533 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
534 -- Has_Stream just for efficiency reasons. There is no point in
535 -- spending time on a Has_Stream check if the restriction is not set.
537 if Restrictions
.Set
(No_Streams
) then
538 if Has_Stream
(Designated_Type
(Acc_Type
)) then
539 Check_Restriction
(No_Streams
, N
);
543 Set_Etype
(N
, Acc_Type
);
545 if not Is_Library_Level_Entity
(Acc_Type
) then
546 Check_Restriction
(No_Local_Allocators
, N
);
549 if Serious_Errors_Detected
> Sav_Errs
then
550 Set_Error_Posted
(N
);
551 Set_Etype
(N
, Any_Type
);
553 end Analyze_Allocator
;
555 ---------------------------
556 -- Analyze_Arithmetic_Op --
557 ---------------------------
559 procedure Analyze_Arithmetic_Op
(N
: Node_Id
) is
560 L
: constant Node_Id
:= Left_Opnd
(N
);
561 R
: constant Node_Id
:= Right_Opnd
(N
);
565 Candidate_Type
:= Empty
;
566 Analyze_Expression
(L
);
567 Analyze_Expression
(R
);
569 -- If the entity is already set, the node is the instantiation of
570 -- a generic node with a non-local reference, or was manufactured
571 -- by a call to Make_Op_xxx. In either case the entity is known to
572 -- be valid, and we do not need to collect interpretations, instead
573 -- we just get the single possible interpretation.
577 if Present
(Op_Id
) then
578 if Ekind
(Op_Id
) = E_Operator
then
580 if (Nkind
(N
) = N_Op_Divide
or else
581 Nkind
(N
) = N_Op_Mod
or else
582 Nkind
(N
) = N_Op_Multiply
or else
583 Nkind
(N
) = N_Op_Rem
)
584 and then Treat_Fixed_As_Integer
(N
)
588 Set_Etype
(N
, Any_Type
);
589 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
593 Set_Etype
(N
, Any_Type
);
594 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
597 -- Entity is not already set, so we do need to collect interpretations
600 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
601 Set_Etype
(N
, Any_Type
);
603 while Present
(Op_Id
) loop
604 if Ekind
(Op_Id
) = E_Operator
605 and then Present
(Next_Entity
(First_Entity
(Op_Id
)))
607 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
609 -- The following may seem superfluous, because an operator cannot
610 -- be generic, but this ignores the cleverness of the author of
613 elsif Is_Overloadable
(Op_Id
) then
614 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
617 Op_Id
:= Homonym
(Op_Id
);
622 end Analyze_Arithmetic_Op
;
628 -- Function, procedure, and entry calls are checked here. The Name in
629 -- the call may be overloaded. The actuals have been analyzed and may
630 -- themselves be overloaded. On exit from this procedure, the node N
631 -- may have zero, one or more interpretations. In the first case an
632 -- error message is produced. In the last case, the node is flagged
633 -- as overloaded and the interpretations are collected in All_Interp.
635 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
636 -- the type-checking is similar to that of other calls.
638 procedure Analyze_Call
(N
: Node_Id
) is
639 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
640 Nam
: Node_Id
:= Name
(N
);
644 Success
: Boolean := False;
646 function Name_Denotes_Function
return Boolean;
647 -- If the type of the name is an access to subprogram, this may be
648 -- the type of a name, or the return type of the function being called.
649 -- If the name is not an entity then it can denote a protected function.
650 -- Until we distinguish Etype from Return_Type, we must use this
651 -- routine to resolve the meaning of the name in the call.
653 ---------------------------
654 -- Name_Denotes_Function --
655 ---------------------------
657 function Name_Denotes_Function
return Boolean is
659 if Is_Entity_Name
(Nam
) then
660 return Ekind
(Entity
(Nam
)) = E_Function
;
662 elsif Nkind
(Nam
) = N_Selected_Component
then
663 return Ekind
(Entity
(Selector_Name
(Nam
))) = E_Function
;
668 end Name_Denotes_Function
;
670 -- Start of processing for Analyze_Call
673 -- Initialize the type of the result of the call to the error type,
674 -- which will be reset if the type is successfully resolved.
676 Set_Etype
(N
, Any_Type
);
678 if not Is_Overloaded
(Nam
) then
680 -- Only one interpretation to check
682 if Ekind
(Etype
(Nam
)) = E_Subprogram_Type
then
683 Nam_Ent
:= Etype
(Nam
);
685 -- If the prefix is an access_to_subprogram, this may be an indirect
686 -- call. This is the case if the name in the call is not an entity
687 -- name, or if it is a function name in the context of a procedure
688 -- call. In this latter case, we have a call to a parameterless
689 -- function that returns a pointer_to_procedure which is the entity
692 elsif Is_Access_Type
(Etype
(Nam
))
693 and then Ekind
(Designated_Type
(Etype
(Nam
))) = E_Subprogram_Type
695 (not Name_Denotes_Function
696 or else Nkind
(N
) = N_Procedure_Call_Statement
)
698 Nam_Ent
:= Designated_Type
(Etype
(Nam
));
699 Insert_Explicit_Dereference
(Nam
);
701 -- Selected component case. Simple entry or protected operation,
702 -- where the entry name is given by the selector name.
704 elsif Nkind
(Nam
) = N_Selected_Component
then
705 Nam_Ent
:= Entity
(Selector_Name
(Nam
));
707 if Ekind
(Nam_Ent
) /= E_Entry
708 and then Ekind
(Nam_Ent
) /= E_Entry_Family
709 and then Ekind
(Nam_Ent
) /= E_Function
710 and then Ekind
(Nam_Ent
) /= E_Procedure
712 Error_Msg_N
("name in call is not a callable entity", Nam
);
713 Set_Etype
(N
, Any_Type
);
717 -- If the name is an Indexed component, it can be a call to a member
718 -- of an entry family. The prefix must be a selected component whose
719 -- selector is the entry. Analyze_Procedure_Call normalizes several
720 -- kinds of call into this form.
722 elsif Nkind
(Nam
) = N_Indexed_Component
then
724 if Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
725 Nam_Ent
:= Entity
(Selector_Name
(Prefix
(Nam
)));
727 Error_Msg_N
("name in call is not a callable entity", Nam
);
728 Set_Etype
(N
, Any_Type
);
732 elsif not Is_Entity_Name
(Nam
) then
733 Error_Msg_N
("name in call is not a callable entity", Nam
);
734 Set_Etype
(N
, Any_Type
);
738 Nam_Ent
:= Entity
(Nam
);
740 -- If no interpretations, give error message
742 if not Is_Overloadable
(Nam_Ent
) then
744 L
: constant Boolean := Is_List_Member
(N
);
745 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
748 -- If the node is in a list whose parent is not an
749 -- expression then it must be an attempted procedure call.
751 if L
and then K
not in N_Subexpr
then
752 if Ekind
(Entity
(Nam
)) = E_Generic_Procedure
then
754 ("must instantiate generic procedure& before call",
758 ("procedure or entry name expected", Nam
);
761 -- Check for tasking cases where only an entry call will do
764 and then (K
= N_Entry_Call_Alternative
765 or else K
= N_Triggering_Alternative
)
767 Error_Msg_N
("entry name expected", Nam
);
769 -- Otherwise give general error message
772 Error_Msg_N
("invalid prefix in call", Nam
);
780 Analyze_One_Call
(N
, Nam_Ent
, True, Success
);
782 -- If this is an indirect call, the return type of the access_to
783 -- subprogram may be an incomplete type. At the point of the call,
784 -- use the full type if available, and at the same time update
785 -- the return type of the access_to_subprogram.
788 and then Nkind
(Nam
) = N_Explicit_Dereference
789 and then Ekind
(Etype
(N
)) = E_Incomplete_Type
790 and then Present
(Full_View
(Etype
(N
)))
792 Set_Etype
(N
, Full_View
(Etype
(N
)));
793 Set_Etype
(Nam_Ent
, Etype
(N
));
797 -- An overloaded selected component must denote overloaded
798 -- operations of a concurrent type. The interpretations are
799 -- attached to the simple name of those operations.
801 if Nkind
(Nam
) = N_Selected_Component
then
802 Nam
:= Selector_Name
(Nam
);
805 Get_First_Interp
(Nam
, X
, It
);
807 while Present
(It
.Nam
) loop
810 -- Name may be call that returns an access to subprogram, or more
811 -- generally an overloaded expression one of whose interpretations
812 -- yields an access to subprogram. If the name is an entity, we
813 -- do not dereference, because the node is a call that returns
814 -- the access type: note difference between f(x), where the call
815 -- may return an access subprogram type, and f(x)(y), where the
816 -- type returned by the call to f is implicitly dereferenced to
817 -- analyze the outer call.
819 if Is_Access_Type
(Nam_Ent
) then
820 Nam_Ent
:= Designated_Type
(Nam_Ent
);
822 elsif Is_Access_Type
(Etype
(Nam_Ent
))
823 and then not Is_Entity_Name
(Nam
)
824 and then Ekind
(Designated_Type
(Etype
(Nam_Ent
)))
827 Nam_Ent
:= Designated_Type
(Etype
(Nam_Ent
));
830 Analyze_One_Call
(N
, Nam_Ent
, False, Success
);
832 -- If the interpretation succeeds, mark the proper type of the
833 -- prefix (any valid candidate will do). If not, remove the
834 -- candidate interpretation. This only needs to be done for
835 -- overloaded protected operations, for other entities disambi-
836 -- guation is done directly in Resolve.
839 Set_Etype
(Nam
, It
.Typ
);
841 elsif Nkind
(Name
(N
)) = N_Selected_Component
842 or else Nkind
(Name
(N
)) = N_Function_Call
847 Get_Next_Interp
(X
, It
);
850 -- If the name is the result of a function call, it can only
851 -- be a call to a function returning an access to subprogram.
852 -- Insert explicit dereference.
854 if Nkind
(Nam
) = N_Function_Call
then
855 Insert_Explicit_Dereference
(Nam
);
858 if Etype
(N
) = Any_Type
then
860 -- None of the interpretations is compatible with the actuals
862 Diagnose_Call
(N
, Nam
);
864 -- Special checks for uninstantiated put routines
866 if Nkind
(N
) = N_Procedure_Call_Statement
867 and then Is_Entity_Name
(Nam
)
868 and then Chars
(Nam
) = Name_Put
869 and then List_Length
(Actuals
) = 1
872 Arg
: constant Node_Id
:= First
(Actuals
);
876 if Nkind
(Arg
) = N_Parameter_Association
then
877 Typ
:= Etype
(Explicit_Actual_Parameter
(Arg
));
882 if Is_Signed_Integer_Type
(Typ
) then
884 ("possible missing instantiation of " &
885 "'Text_'I'O.'Integer_'I'O!", Nam
);
887 elsif Is_Modular_Integer_Type
(Typ
) then
889 ("possible missing instantiation of " &
890 "'Text_'I'O.'Modular_'I'O!", Nam
);
892 elsif Is_Floating_Point_Type
(Typ
) then
894 ("possible missing instantiation of " &
895 "'Text_'I'O.'Float_'I'O!", Nam
);
897 elsif Is_Ordinary_Fixed_Point_Type
(Typ
) then
899 ("possible missing instantiation of " &
900 "'Text_'I'O.'Fixed_'I'O!", Nam
);
902 elsif Is_Decimal_Fixed_Point_Type
(Typ
) then
904 ("possible missing instantiation of " &
905 "'Text_'I'O.'Decimal_'I'O!", Nam
);
907 elsif Is_Enumeration_Type
(Typ
) then
909 ("possible missing instantiation of " &
910 "'Text_'I'O.'Enumeration_'I'O!", Nam
);
915 elsif not Is_Overloaded
(N
)
916 and then Is_Entity_Name
(Nam
)
918 -- Resolution yields a single interpretation. Verify that
919 -- is has the proper capitalization.
921 Set_Entity_With_Style_Check
(Nam
, Entity
(Nam
));
922 Generate_Reference
(Entity
(Nam
), Nam
);
924 Set_Etype
(Nam
, Etype
(Entity
(Nam
)));
926 Remove_Abstract_Operations
(N
);
933 ---------------------------
934 -- Analyze_Comparison_Op --
935 ---------------------------
937 procedure Analyze_Comparison_Op
(N
: Node_Id
) is
938 L
: constant Node_Id
:= Left_Opnd
(N
);
939 R
: constant Node_Id
:= Right_Opnd
(N
);
940 Op_Id
: Entity_Id
:= Entity
(N
);
943 Set_Etype
(N
, Any_Type
);
944 Candidate_Type
:= Empty
;
946 Analyze_Expression
(L
);
947 Analyze_Expression
(R
);
949 if Present
(Op_Id
) then
950 if Ekind
(Op_Id
) = E_Operator
then
951 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
953 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
956 if Is_Overloaded
(L
) then
957 Set_Etype
(L
, Intersect_Types
(L
, R
));
961 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
962 while Present
(Op_Id
) loop
963 if Ekind
(Op_Id
) = E_Operator
then
964 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
966 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
969 Op_Id
:= Homonym
(Op_Id
);
974 end Analyze_Comparison_Op
;
976 ---------------------------
977 -- Analyze_Concatenation --
978 ---------------------------
980 -- If the only one-dimensional array type in scope is String,
981 -- this is the resulting type of the operation. Otherwise there
982 -- will be a concatenation operation defined for each user-defined
983 -- one-dimensional array.
985 procedure Analyze_Concatenation
(N
: Node_Id
) is
986 L
: constant Node_Id
:= Left_Opnd
(N
);
987 R
: constant Node_Id
:= Right_Opnd
(N
);
988 Op_Id
: Entity_Id
:= Entity
(N
);
993 Set_Etype
(N
, Any_Type
);
994 Candidate_Type
:= Empty
;
996 Analyze_Expression
(L
);
997 Analyze_Expression
(R
);
999 -- If the entity is present, the node appears in an instance,
1000 -- and denotes a predefined concatenation operation. The resulting
1001 -- type is obtained from the arguments when possible. If the arguments
1002 -- are aggregates, the array type and the concatenation type must be
1005 if Present
(Op_Id
) then
1006 if Ekind
(Op_Id
) = E_Operator
then
1008 LT
:= Base_Type
(Etype
(L
));
1009 RT
:= Base_Type
(Etype
(R
));
1011 if Is_Array_Type
(LT
)
1012 and then (RT
= LT
or else RT
= Base_Type
(Component_Type
(LT
)))
1014 Add_One_Interp
(N
, Op_Id
, LT
);
1016 elsif Is_Array_Type
(RT
)
1017 and then LT
= Base_Type
(Component_Type
(RT
))
1019 Add_One_Interp
(N
, Op_Id
, RT
);
1021 -- If one operand is a string type or a user-defined array type,
1022 -- and the other is a literal, result is of the specific type.
1025 (Root_Type
(LT
) = Standard_String
1026 or else Scope
(LT
) /= Standard_Standard
)
1027 and then Etype
(R
) = Any_String
1029 Add_One_Interp
(N
, Op_Id
, LT
);
1032 (Root_Type
(RT
) = Standard_String
1033 or else Scope
(RT
) /= Standard_Standard
)
1034 and then Etype
(L
) = Any_String
1036 Add_One_Interp
(N
, Op_Id
, RT
);
1038 elsif not Is_Generic_Type
(Etype
(Op_Id
)) then
1039 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1042 -- Type and its operations must be visible
1044 Set_Entity
(N
, Empty
);
1045 Analyze_Concatenation
(N
);
1049 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1053 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Concat
);
1054 while Present
(Op_Id
) loop
1055 if Ekind
(Op_Id
) = E_Operator
then
1057 -- Do not consider operators declared in dead code, they can
1058 -- not be part of the resolution.
1060 if Is_Eliminated
(Op_Id
) then
1063 Find_Concatenation_Types
(L
, R
, Op_Id
, N
);
1067 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1070 Op_Id
:= Homonym
(Op_Id
);
1075 end Analyze_Concatenation
;
1077 ------------------------------------
1078 -- Analyze_Conditional_Expression --
1079 ------------------------------------
1081 procedure Analyze_Conditional_Expression
(N
: Node_Id
) is
1082 Condition
: constant Node_Id
:= First
(Expressions
(N
));
1083 Then_Expr
: constant Node_Id
:= Next
(Condition
);
1084 Else_Expr
: constant Node_Id
:= Next
(Then_Expr
);
1086 Analyze_Expression
(Condition
);
1087 Analyze_Expression
(Then_Expr
);
1088 Analyze_Expression
(Else_Expr
);
1089 Set_Etype
(N
, Etype
(Then_Expr
));
1090 end Analyze_Conditional_Expression
;
1092 -------------------------
1093 -- Analyze_Equality_Op --
1094 -------------------------
1096 procedure Analyze_Equality_Op
(N
: Node_Id
) is
1097 Loc
: constant Source_Ptr
:= Sloc
(N
);
1098 L
: constant Node_Id
:= Left_Opnd
(N
);
1099 R
: constant Node_Id
:= Right_Opnd
(N
);
1103 Set_Etype
(N
, Any_Type
);
1104 Candidate_Type
:= Empty
;
1106 Analyze_Expression
(L
);
1107 Analyze_Expression
(R
);
1109 -- If the entity is set, the node is a generic instance with a non-local
1110 -- reference to the predefined operator or to a user-defined function.
1111 -- It can also be an inequality that is expanded into the negation of a
1112 -- call to a user-defined equality operator.
1114 -- For the predefined case, the result is Boolean, regardless of the
1115 -- type of the operands. The operands may even be limited, if they are
1116 -- generic actuals. If they are overloaded, label the left argument with
1117 -- the common type that must be present, or with the type of the formal
1118 -- of the user-defined function.
1120 if Present
(Entity
(N
)) then
1121 Op_Id
:= Entity
(N
);
1123 if Ekind
(Op_Id
) = E_Operator
then
1124 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
);
1126 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1129 if Is_Overloaded
(L
) then
1130 if Ekind
(Op_Id
) = E_Operator
then
1131 Set_Etype
(L
, Intersect_Types
(L
, R
));
1133 Set_Etype
(L
, Etype
(First_Formal
(Op_Id
)));
1138 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1139 while Present
(Op_Id
) loop
1140 if Ekind
(Op_Id
) = E_Operator
then
1141 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1143 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1146 Op_Id
:= Homonym
(Op_Id
);
1150 -- If there was no match, and the operator is inequality, this may
1151 -- be a case where inequality has not been made explicit, as for
1152 -- tagged types. Analyze the node as the negation of an equality
1153 -- operation. This cannot be done earlier, because before analysis
1154 -- we cannot rule out the presence of an explicit inequality.
1156 if Etype
(N
) = Any_Type
1157 and then Nkind
(N
) = N_Op_Ne
1159 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Eq
);
1160 while Present
(Op_Id
) loop
1161 if Ekind
(Op_Id
) = E_Operator
then
1162 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1164 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1167 Op_Id
:= Homonym
(Op_Id
);
1170 if Etype
(N
) /= Any_Type
then
1171 Op_Id
:= Entity
(N
);
1177 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
1178 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
)))));
1180 Set_Entity
(Right_Opnd
(N
), Op_Id
);
1186 end Analyze_Equality_Op
;
1188 ----------------------------------
1189 -- Analyze_Explicit_Dereference --
1190 ----------------------------------
1192 procedure Analyze_Explicit_Dereference
(N
: Node_Id
) is
1193 Loc
: constant Source_Ptr
:= Sloc
(N
);
1194 P
: constant Node_Id
:= Prefix
(N
);
1200 function Is_Function_Type
return Boolean;
1201 -- Check whether node may be interpreted as an implicit function call
1203 ----------------------
1204 -- Is_Function_Type --
1205 ----------------------
1207 function Is_Function_Type
return Boolean is
1212 if not Is_Overloaded
(N
) then
1213 return Ekind
(Base_Type
(Etype
(N
))) = E_Subprogram_Type
1214 and then Etype
(Base_Type
(Etype
(N
))) /= Standard_Void_Type
;
1217 Get_First_Interp
(N
, I
, It
);
1218 while Present
(It
.Nam
) loop
1219 if Ekind
(Base_Type
(It
.Typ
)) /= E_Subprogram_Type
1220 or else Etype
(Base_Type
(It
.Typ
)) = Standard_Void_Type
1225 Get_Next_Interp
(I
, It
);
1230 end Is_Function_Type
;
1232 -- Start of processing for Analyze_Explicit_Dereference
1236 Set_Etype
(N
, Any_Type
);
1238 -- Test for remote access to subprogram type, and if so return
1239 -- after rewriting the original tree.
1241 if Remote_AST_E_Dereference
(P
) then
1245 -- Normal processing for other than remote access to subprogram type
1247 if not Is_Overloaded
(P
) then
1248 if Is_Access_Type
(Etype
(P
)) then
1250 -- Set the Etype. We need to go thru Is_For_Access_Subtypes
1251 -- to avoid other problems caused by the Private_Subtype
1252 -- and it is safe to go to the Base_Type because this is the
1253 -- same as converting the access value to its Base_Type.
1256 DT
: Entity_Id
:= Designated_Type
(Etype
(P
));
1259 if Ekind
(DT
) = E_Private_Subtype
1260 and then Is_For_Access_Subtype
(DT
)
1262 DT
:= Base_Type
(DT
);
1268 elsif Etype
(P
) /= Any_Type
then
1269 Error_Msg_N
("prefix of dereference must be an access type", N
);
1274 Get_First_Interp
(P
, I
, It
);
1275 while Present
(It
.Nam
) loop
1278 if Is_Access_Type
(T
) then
1279 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
1282 Get_Next_Interp
(I
, It
);
1285 -- Error if no interpretation of the prefix has an access type
1287 if Etype
(N
) = Any_Type
then
1289 ("access type required in prefix of explicit dereference", P
);
1290 Set_Etype
(N
, Any_Type
);
1296 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
1298 and then (Nkind
(Parent
(N
)) /= N_Function_Call
1299 or else N
/= Name
(Parent
(N
)))
1301 and then (Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1302 or else N
/= Name
(Parent
(N
)))
1304 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
1305 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
1307 (Attribute_Name
(Parent
(N
)) /= Name_Address
1309 Attribute_Name
(Parent
(N
)) /= Name_Access
))
1311 -- Name is a function call with no actuals, in a context that
1312 -- requires deproceduring (including as an actual in an enclosing
1313 -- function or procedure call). There are some pathological cases
1314 -- where the prefix might include functions that return access to
1315 -- subprograms and others that return a regular type. Disambiguation
1316 -- of those has to take place in Resolve.
1317 -- See e.g. 7117-014 and E317-001.
1320 Make_Function_Call
(Loc
,
1321 Name
=> Make_Explicit_Dereference
(Loc
, P
),
1322 Parameter_Associations
=> New_List
);
1324 -- If the prefix is overloaded, remove operations that have formals,
1325 -- we know that this is a parameterless call.
1327 if Is_Overloaded
(P
) then
1328 Get_First_Interp
(P
, I
, It
);
1329 while Present
(It
.Nam
) loop
1332 if No
(First_Formal
(Base_Type
(Designated_Type
(T
)))) then
1338 Get_Next_Interp
(I
, It
);
1345 elsif not Is_Function_Type
1346 and then Is_Overloaded
(N
)
1348 -- The prefix may include access to subprograms and other access
1349 -- types. If the context selects the interpretation that is a call,
1350 -- we cannot rewrite the node yet, but we include the result of
1351 -- the call interpretation.
1353 Get_First_Interp
(N
, I
, It
);
1354 while Present
(It
.Nam
) loop
1355 if Ekind
(Base_Type
(It
.Typ
)) = E_Subprogram_Type
1356 and then Etype
(Base_Type
(It
.Typ
)) /= Standard_Void_Type
1358 Add_One_Interp
(N
, Etype
(It
.Typ
), Etype
(It
.Typ
));
1361 Get_Next_Interp
(I
, It
);
1365 -- A value of remote access-to-class-wide must not be dereferenced
1368 Validate_Remote_Access_To_Class_Wide_Type
(N
);
1369 end Analyze_Explicit_Dereference
;
1371 ------------------------
1372 -- Analyze_Expression --
1373 ------------------------
1375 procedure Analyze_Expression
(N
: Node_Id
) is
1378 Check_Parameterless_Call
(N
);
1379 end Analyze_Expression
;
1381 ------------------------------------
1382 -- Analyze_Indexed_Component_Form --
1383 ------------------------------------
1385 procedure Analyze_Indexed_Component_Form
(N
: Node_Id
) is
1386 P
: constant Node_Id
:= Prefix
(N
);
1387 Exprs
: constant List_Id
:= Expressions
(N
);
1393 procedure Process_Function_Call
;
1394 -- Prefix in indexed component form is an overloadable entity,
1395 -- so the node is a function call. Reformat it as such.
1397 procedure Process_Indexed_Component
;
1398 -- Prefix in indexed component form is actually an indexed component.
1399 -- This routine processes it, knowing that the prefix is already
1402 procedure Process_Indexed_Component_Or_Slice
;
1403 -- An indexed component with a single index may designate a slice if
1404 -- the index is a subtype mark. This routine disambiguates these two
1405 -- cases by resolving the prefix to see if it is a subtype mark.
1407 procedure Process_Overloaded_Indexed_Component
;
1408 -- If the prefix of an indexed component is overloaded, the proper
1409 -- interpretation is selected by the index types and the context.
1411 ---------------------------
1412 -- Process_Function_Call --
1413 ---------------------------
1415 procedure Process_Function_Call
is
1419 Change_Node
(N
, N_Function_Call
);
1421 Set_Parameter_Associations
(N
, Exprs
);
1423 Actual
:= First
(Parameter_Associations
(N
));
1424 while Present
(Actual
) loop
1426 Check_Parameterless_Call
(Actual
);
1427 Next_Actual
(Actual
);
1431 end Process_Function_Call
;
1433 -------------------------------
1434 -- Process_Indexed_Component --
1435 -------------------------------
1437 procedure Process_Indexed_Component
is
1439 Array_Type
: Entity_Id
;
1441 Pent
: Entity_Id
:= Empty
;
1444 Exp
:= First
(Exprs
);
1446 if Is_Overloaded
(P
) then
1447 Process_Overloaded_Indexed_Component
;
1450 Array_Type
:= Etype
(P
);
1452 if Is_Entity_Name
(P
) then
1454 elsif Nkind
(P
) = N_Selected_Component
1455 and then Is_Entity_Name
(Selector_Name
(P
))
1457 Pent
:= Entity
(Selector_Name
(P
));
1460 -- Prefix must be appropriate for an array type, taking into
1461 -- account a possible implicit dereference.
1463 if Is_Access_Type
(Array_Type
) then
1464 Array_Type
:= Designated_Type
(Array_Type
);
1465 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
1466 Process_Implicit_Dereference_Prefix
(Pent
, P
);
1469 if Is_Array_Type
(Array_Type
) then
1472 elsif Present
(Pent
) and then Ekind
(Pent
) = E_Entry_Family
then
1474 Set_Etype
(N
, Any_Type
);
1476 if not Has_Compatible_Type
1477 (Exp
, Entry_Index_Type
(Pent
))
1479 Error_Msg_N
("invalid index type in entry name", N
);
1481 elsif Present
(Next
(Exp
)) then
1482 Error_Msg_N
("too many subscripts in entry reference", N
);
1485 Set_Etype
(N
, Etype
(P
));
1490 elsif Is_Record_Type
(Array_Type
)
1491 and then Remote_AST_I_Dereference
(P
)
1495 elsif Array_Type
= Any_Type
then
1496 Set_Etype
(N
, Any_Type
);
1499 -- Here we definitely have a bad indexing
1502 if Nkind
(Parent
(N
)) = N_Requeue_Statement
1503 and then Present
(Pent
) and then Ekind
(Pent
) = E_Entry
1506 ("REQUEUE does not permit parameters", First
(Exprs
));
1508 elsif Is_Entity_Name
(P
)
1509 and then Etype
(P
) = Standard_Void_Type
1511 Error_Msg_NE
("incorrect use of&", P
, Entity
(P
));
1514 Error_Msg_N
("array type required in indexed component", P
);
1517 Set_Etype
(N
, Any_Type
);
1521 Index
:= First_Index
(Array_Type
);
1522 while Present
(Index
) and then Present
(Exp
) loop
1523 if not Has_Compatible_Type
(Exp
, Etype
(Index
)) then
1524 Wrong_Type
(Exp
, Etype
(Index
));
1525 Set_Etype
(N
, Any_Type
);
1533 Set_Etype
(N
, Component_Type
(Array_Type
));
1535 if Present
(Index
) then
1537 ("too few subscripts in array reference", First
(Exprs
));
1539 elsif Present
(Exp
) then
1540 Error_Msg_N
("too many subscripts in array reference", Exp
);
1543 end Process_Indexed_Component
;
1545 ----------------------------------------
1546 -- Process_Indexed_Component_Or_Slice --
1547 ----------------------------------------
1549 procedure Process_Indexed_Component_Or_Slice
is
1551 Exp
:= First
(Exprs
);
1552 while Present
(Exp
) loop
1553 Analyze_Expression
(Exp
);
1557 Exp
:= First
(Exprs
);
1559 -- If one index is present, and it is a subtype name, then the
1560 -- node denotes a slice (note that the case of an explicit range
1561 -- for a slice was already built as an N_Slice node in the first
1562 -- place, so that case is not handled here).
1564 -- We use a replace rather than a rewrite here because this is one
1565 -- of the cases in which the tree built by the parser is plain wrong.
1568 and then Is_Entity_Name
(Exp
)
1569 and then Is_Type
(Entity
(Exp
))
1572 Make_Slice
(Sloc
(N
),
1574 Discrete_Range
=> New_Copy
(Exp
)));
1577 -- Otherwise (more than one index present, or single index is not
1578 -- a subtype name), then we have the indexed component case.
1581 Process_Indexed_Component
;
1583 end Process_Indexed_Component_Or_Slice
;
1585 ------------------------------------------
1586 -- Process_Overloaded_Indexed_Component --
1587 ------------------------------------------
1589 procedure Process_Overloaded_Indexed_Component
is
1598 Set_Etype
(N
, Any_Type
);
1600 Get_First_Interp
(P
, I
, It
);
1601 while Present
(It
.Nam
) loop
1604 if Is_Access_Type
(Typ
) then
1605 Typ
:= Designated_Type
(Typ
);
1606 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
1609 if Is_Array_Type
(Typ
) then
1611 -- Got a candidate: verify that index types are compatible
1613 Index
:= First_Index
(Typ
);
1615 Exp
:= First
(Exprs
);
1616 while Present
(Index
) and then Present
(Exp
) loop
1617 if Has_Compatible_Type
(Exp
, Etype
(Index
)) then
1629 if Found
and then No
(Index
) and then No
(Exp
) then
1631 Etype
(Component_Type
(Typ
)),
1632 Etype
(Component_Type
(Typ
)));
1636 Get_Next_Interp
(I
, It
);
1639 if Etype
(N
) = Any_Type
then
1640 Error_Msg_N
("no legal interpetation for indexed component", N
);
1641 Set_Is_Overloaded
(N
, False);
1645 end Process_Overloaded_Indexed_Component
;
1647 -- Start of processing for Analyze_Indexed_Component_Form
1650 -- Get name of array, function or type
1653 if Nkind
(N
) = N_Function_Call
1654 or else Nkind
(N
) = N_Procedure_Call_Statement
1656 -- If P is an explicit dereference whose prefix is of a
1657 -- remote access-to-subprogram type, then N has already
1658 -- been rewritten as a subprogram call and analyzed.
1663 pragma Assert
(Nkind
(N
) = N_Indexed_Component
);
1665 P_T
:= Base_Type
(Etype
(P
));
1667 if Is_Entity_Name
(P
)
1668 or else Nkind
(P
) = N_Operator_Symbol
1672 if Ekind
(U_N
) in Type_Kind
then
1674 -- Reformat node as a type conversion
1676 E
:= Remove_Head
(Exprs
);
1678 if Present
(First
(Exprs
)) then
1680 ("argument of type conversion must be single expression", N
);
1683 Change_Node
(N
, N_Type_Conversion
);
1684 Set_Subtype_Mark
(N
, P
);
1686 Set_Expression
(N
, E
);
1688 -- After changing the node, call for the specific Analysis
1689 -- routine directly, to avoid a double call to the expander.
1691 Analyze_Type_Conversion
(N
);
1695 if Is_Overloadable
(U_N
) then
1696 Process_Function_Call
;
1698 elsif Ekind
(Etype
(P
)) = E_Subprogram_Type
1699 or else (Is_Access_Type
(Etype
(P
))
1701 Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
)
1703 -- Call to access_to-subprogram with possible implicit dereference
1705 Process_Function_Call
;
1707 elsif Is_Generic_Subprogram
(U_N
) then
1709 -- A common beginner's (or C++ templates fan) error
1711 Error_Msg_N
("generic subprogram cannot be called", N
);
1712 Set_Etype
(N
, Any_Type
);
1716 Process_Indexed_Component_Or_Slice
;
1719 -- If not an entity name, prefix is an expression that may denote
1720 -- an array or an access-to-subprogram.
1723 if Ekind
(P_T
) = E_Subprogram_Type
1724 or else (Is_Access_Type
(P_T
)
1726 Ekind
(Designated_Type
(P_T
)) = E_Subprogram_Type
)
1728 Process_Function_Call
;
1730 elsif Nkind
(P
) = N_Selected_Component
1731 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
1733 Process_Function_Call
;
1736 -- Indexed component, slice, or a call to a member of a family
1737 -- entry, which will be converted to an entry call later.
1739 Process_Indexed_Component_Or_Slice
;
1742 end Analyze_Indexed_Component_Form
;
1744 ------------------------
1745 -- Analyze_Logical_Op --
1746 ------------------------
1748 procedure Analyze_Logical_Op
(N
: Node_Id
) is
1749 L
: constant Node_Id
:= Left_Opnd
(N
);
1750 R
: constant Node_Id
:= Right_Opnd
(N
);
1751 Op_Id
: Entity_Id
:= Entity
(N
);
1754 Set_Etype
(N
, Any_Type
);
1755 Candidate_Type
:= Empty
;
1757 Analyze_Expression
(L
);
1758 Analyze_Expression
(R
);
1760 if Present
(Op_Id
) then
1762 if Ekind
(Op_Id
) = E_Operator
then
1763 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
1765 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1769 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1770 while Present
(Op_Id
) loop
1771 if Ekind
(Op_Id
) = E_Operator
then
1772 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
1774 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1777 Op_Id
:= Homonym
(Op_Id
);
1782 end Analyze_Logical_Op
;
1784 ---------------------------
1785 -- Analyze_Membership_Op --
1786 ---------------------------
1788 procedure Analyze_Membership_Op
(N
: Node_Id
) is
1789 L
: constant Node_Id
:= Left_Opnd
(N
);
1790 R
: constant Node_Id
:= Right_Opnd
(N
);
1792 Index
: Interp_Index
;
1794 Found
: Boolean := False;
1798 procedure Try_One_Interp
(T1
: Entity_Id
);
1799 -- Routine to try one proposed interpretation. Note that the context
1800 -- of the operation plays no role in resolving the arguments, so that
1801 -- if there is more than one interpretation of the operands that is
1802 -- compatible with a membership test, the operation is ambiguous.
1804 --------------------
1805 -- Try_One_Interp --
1806 --------------------
1808 procedure Try_One_Interp
(T1
: Entity_Id
) is
1810 if Has_Compatible_Type
(R
, T1
) then
1812 and then Base_Type
(T1
) /= Base_Type
(T_F
)
1814 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
1816 if It
= No_Interp
then
1817 Ambiguous_Operands
(N
);
1818 Set_Etype
(L
, Any_Type
);
1836 -- Start of processing for Analyze_Membership_Op
1839 Analyze_Expression
(L
);
1841 if Nkind
(R
) = N_Range
1842 or else (Nkind
(R
) = N_Attribute_Reference
1843 and then Attribute_Name
(R
) = Name_Range
)
1847 if not Is_Overloaded
(L
) then
1848 Try_One_Interp
(Etype
(L
));
1851 Get_First_Interp
(L
, Index
, It
);
1852 while Present
(It
.Typ
) loop
1853 Try_One_Interp
(It
.Typ
);
1854 Get_Next_Interp
(Index
, It
);
1858 -- If not a range, it can only be a subtype mark, or else there
1859 -- is a more basic error, to be diagnosed in Find_Type.
1864 if Is_Entity_Name
(R
) then
1865 Check_Fully_Declared
(Entity
(R
), R
);
1869 -- Compatibility between expression and subtype mark or range is
1870 -- checked during resolution. The result of the operation is Boolean
1873 Set_Etype
(N
, Standard_Boolean
);
1875 if Comes_From_Source
(N
)
1876 and then Is_CPP_Class
(Etype
(Etype
(Right_Opnd
(N
))))
1878 Error_Msg_N
("membership test not applicable to cpp-class types", N
);
1880 end Analyze_Membership_Op
;
1882 ----------------------
1883 -- Analyze_Negation --
1884 ----------------------
1886 procedure Analyze_Negation
(N
: Node_Id
) is
1887 R
: constant Node_Id
:= Right_Opnd
(N
);
1888 Op_Id
: Entity_Id
:= Entity
(N
);
1891 Set_Etype
(N
, Any_Type
);
1892 Candidate_Type
:= Empty
;
1894 Analyze_Expression
(R
);
1896 if Present
(Op_Id
) then
1897 if Ekind
(Op_Id
) = E_Operator
then
1898 Find_Negation_Types
(R
, Op_Id
, N
);
1900 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1904 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1905 while Present
(Op_Id
) loop
1906 if Ekind
(Op_Id
) = E_Operator
then
1907 Find_Negation_Types
(R
, Op_Id
, N
);
1909 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
1912 Op_Id
:= Homonym
(Op_Id
);
1917 end Analyze_Negation
;
1923 procedure Analyze_Null
(N
: Node_Id
) is
1925 Set_Etype
(N
, Any_Access
);
1928 ----------------------
1929 -- Analyze_One_Call --
1930 ----------------------
1932 procedure Analyze_One_Call
1936 Success
: out Boolean;
1937 Skip_First
: Boolean := False)
1939 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
1940 Prev_T
: constant Entity_Id
:= Etype
(N
);
1943 Is_Indexed
: Boolean := False;
1944 Subp_Type
: constant Entity_Id
:= Etype
(Nam
);
1947 procedure Indicate_Name_And_Type
;
1948 -- If candidate interpretation matches, indicate name and type of
1949 -- result on call node.
1951 ----------------------------
1952 -- Indicate_Name_And_Type --
1953 ----------------------------
1955 procedure Indicate_Name_And_Type
is
1957 Add_One_Interp
(N
, Nam
, Etype
(Nam
));
1960 -- If the prefix of the call is a name, indicate the entity
1961 -- being called. If it is not a name, it is an expression that
1962 -- denotes an access to subprogram or else an entry or family. In
1963 -- the latter case, the name is a selected component, and the entity
1964 -- being called is noted on the selector.
1966 if not Is_Type
(Nam
) then
1967 if Is_Entity_Name
(Name
(N
))
1968 or else Nkind
(Name
(N
)) = N_Operator_Symbol
1970 Set_Entity
(Name
(N
), Nam
);
1972 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
1973 Set_Entity
(Selector_Name
(Name
(N
)), Nam
);
1977 if Debug_Flag_E
and not Report
then
1978 Write_Str
(" Overloaded call ");
1979 Write_Int
(Int
(N
));
1980 Write_Str
(" compatible with ");
1981 Write_Int
(Int
(Nam
));
1984 end Indicate_Name_And_Type
;
1986 -- Start of processing for Analyze_One_Call
1991 -- If the subprogram has no formals, or if all the formals have
1992 -- defaults, and the return type is an array type, the node may
1993 -- denote an indexing of the result of a parameterless call.
1995 if Needs_No_Actuals
(Nam
)
1996 and then Present
(Actuals
)
1998 if Is_Array_Type
(Subp_Type
) then
1999 Is_Indexed
:= Try_Indexed_Call
(N
, Nam
, Subp_Type
);
2001 elsif Is_Access_Type
(Subp_Type
)
2002 and then Is_Array_Type
(Designated_Type
(Subp_Type
))
2005 Try_Indexed_Call
(N
, Nam
, Designated_Type
(Subp_Type
));
2007 -- The prefix can also be a parameterless function that returns an
2008 -- access to subprogram. in which case this is an indirect call.
2010 elsif Is_Access_Type
(Subp_Type
)
2011 and then Ekind
(Designated_Type
(Subp_Type
)) = E_Subprogram_Type
2013 Is_Indexed
:= Try_Indirect_Call
(N
, Nam
, Subp_Type
);
2018 Normalize_Actuals
(N
, Nam
, (Report
and not Is_Indexed
), Norm_OK
);
2022 -- Mismatch in number or names of parameters
2024 if Debug_Flag_E
then
2025 Write_Str
(" normalization fails in call ");
2026 Write_Int
(Int
(N
));
2027 Write_Str
(" with subprogram ");
2028 Write_Int
(Int
(Nam
));
2032 -- If the context expects a function call, discard any interpretation
2033 -- that is a procedure. If the node is not overloaded, leave as is for
2034 -- better error reporting when type mismatch is found.
2036 elsif Nkind
(N
) = N_Function_Call
2037 and then Is_Overloaded
(Name
(N
))
2038 and then Ekind
(Nam
) = E_Procedure
2042 -- Ditto for function calls in a procedure context
2044 elsif Nkind
(N
) = N_Procedure_Call_Statement
2045 and then Is_Overloaded
(Name
(N
))
2046 and then Etype
(Nam
) /= Standard_Void_Type
2050 elsif No
(Actuals
) then
2052 -- If Normalize succeeds, then there are default parameters for
2055 Indicate_Name_And_Type
;
2057 elsif Ekind
(Nam
) = E_Operator
then
2058 if Nkind
(N
) = N_Procedure_Call_Statement
then
2062 -- This can occur when the prefix of the call is an operator
2063 -- name or an expanded name whose selector is an operator name.
2065 Analyze_Operator_Call
(N
, Nam
);
2067 if Etype
(N
) /= Prev_T
then
2069 -- There may be a user-defined operator that hides the
2070 -- current interpretation. We must check for this independently
2071 -- of the analysis of the call with the user-defined operation,
2072 -- because the parameter names may be wrong and yet the hiding
2073 -- takes place. Fixes b34014o.
2075 if Is_Overloaded
(Name
(N
)) then
2081 Get_First_Interp
(Name
(N
), I
, It
);
2082 while Present
(It
.Nam
) loop
2083 if Ekind
(It
.Nam
) /= E_Operator
2084 and then Hides_Op
(It
.Nam
, Nam
)
2087 (First_Actual
(N
), Etype
(First_Formal
(It
.Nam
)))
2088 and then (No
(Next_Actual
(First_Actual
(N
)))
2089 or else Has_Compatible_Type
2090 (Next_Actual
(First_Actual
(N
)),
2091 Etype
(Next_Formal
(First_Formal
(It
.Nam
)))))
2093 Set_Etype
(N
, Prev_T
);
2097 Get_Next_Interp
(I
, It
);
2102 -- If operator matches formals, record its name on the call.
2103 -- If the operator is overloaded, Resolve will select the
2104 -- correct one from the list of interpretations. The call
2105 -- node itself carries the first candidate.
2107 Set_Entity
(Name
(N
), Nam
);
2110 elsif Report
and then Etype
(N
) = Any_Type
then
2111 Error_Msg_N
("incompatible arguments for operator", N
);
2115 -- Normalize_Actuals has chained the named associations in the
2116 -- correct order of the formals.
2118 Actual
:= First_Actual
(N
);
2119 Formal
:= First_Formal
(Nam
);
2121 -- If we are analyzing a call rewritten from object notation,
2122 -- skip first actual, which may be rewritten later as an
2123 -- explicit dereference.
2126 Next_Actual
(Actual
);
2127 Next_Formal
(Formal
);
2130 while Present
(Actual
) and then Present
(Formal
) loop
2131 if Nkind
(Parent
(Actual
)) /= N_Parameter_Association
2132 or else Chars
(Selector_Name
(Parent
(Actual
))) = Chars
(Formal
)
2134 if Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
2135 Next_Actual
(Actual
);
2136 Next_Formal
(Formal
);
2139 if Debug_Flag_E
then
2140 Write_Str
(" type checking fails in call ");
2141 Write_Int
(Int
(N
));
2142 Write_Str
(" with formal ");
2143 Write_Int
(Int
(Formal
));
2144 Write_Str
(" in subprogram ");
2145 Write_Int
(Int
(Nam
));
2149 if Report
and not Is_Indexed
then
2151 -- Ada 2005 (AI-251): Complete the error notification
2152 -- to help new Ada 2005 users
2154 if Is_Class_Wide_Type
(Etype
(Formal
))
2155 and then Is_Interface
(Etype
(Etype
(Formal
)))
2156 and then not Interface_Present_In_Ancestor
2157 (Typ
=> Etype
(Actual
),
2158 Iface
=> Etype
(Etype
(Formal
)))
2161 ("(Ada 2005) does not implement interface }",
2162 Actual
, Etype
(Etype
(Formal
)));
2165 Wrong_Type
(Actual
, Etype
(Formal
));
2167 if Nkind
(Actual
) = N_Op_Eq
2168 and then Nkind
(Left_Opnd
(Actual
)) = N_Identifier
2170 Formal
:= First_Formal
(Nam
);
2171 while Present
(Formal
) loop
2172 if Chars
(Left_Opnd
(Actual
)) = Chars
(Formal
) then
2174 ("possible misspelling of `='>`!", Actual
);
2178 Next_Formal
(Formal
);
2182 if All_Errors_Mode
then
2183 Error_Msg_Sloc
:= Sloc
(Nam
);
2185 if Is_Overloadable
(Nam
)
2186 and then Present
(Alias
(Nam
))
2187 and then not Comes_From_Source
(Nam
)
2190 (" =='> in call to &#(inherited)!", Actual
, Nam
);
2192 elsif Ekind
(Nam
) = E_Subprogram_Type
then
2194 Access_To_Subprogram_Typ
:
2195 constant Entity_Id
:=
2197 (Associated_Node_For_Itype
(Nam
));
2200 " =='> in call to dereference of &#!",
2201 Actual
, Access_To_Subprogram_Typ
);
2205 Error_Msg_NE
(" =='> in call to &#!", Actual
, Nam
);
2215 -- Normalize_Actuals has verified that a default value exists
2216 -- for this formal. Current actual names a subsequent formal.
2218 Next_Formal
(Formal
);
2222 -- On exit, all actuals match
2224 Indicate_Name_And_Type
;
2226 end Analyze_One_Call
;
2228 ---------------------------
2229 -- Analyze_Operator_Call --
2230 ---------------------------
2232 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
) is
2233 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
2234 Act1
: constant Node_Id
:= First_Actual
(N
);
2235 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
2238 -- Binary operator case
2240 if Present
(Act2
) then
2242 -- If more than two operands, then not binary operator after all
2244 if Present
(Next_Actual
(Act2
)) then
2247 elsif Op_Name
= Name_Op_Add
2248 or else Op_Name
= Name_Op_Subtract
2249 or else Op_Name
= Name_Op_Multiply
2250 or else Op_Name
= Name_Op_Divide
2251 or else Op_Name
= Name_Op_Mod
2252 or else Op_Name
= Name_Op_Rem
2253 or else Op_Name
= Name_Op_Expon
2255 Find_Arithmetic_Types
(Act1
, Act2
, Op_Id
, N
);
2257 elsif Op_Name
= Name_Op_And
2258 or else Op_Name
= Name_Op_Or
2259 or else Op_Name
= Name_Op_Xor
2261 Find_Boolean_Types
(Act1
, Act2
, Op_Id
, N
);
2263 elsif Op_Name
= Name_Op_Lt
2264 or else Op_Name
= Name_Op_Le
2265 or else Op_Name
= Name_Op_Gt
2266 or else Op_Name
= Name_Op_Ge
2268 Find_Comparison_Types
(Act1
, Act2
, Op_Id
, N
);
2270 elsif Op_Name
= Name_Op_Eq
2271 or else Op_Name
= Name_Op_Ne
2273 Find_Equality_Types
(Act1
, Act2
, Op_Id
, N
);
2275 elsif Op_Name
= Name_Op_Concat
then
2276 Find_Concatenation_Types
(Act1
, Act2
, Op_Id
, N
);
2278 -- Is this else null correct, or should it be an abort???
2284 -- Unary operator case
2287 if Op_Name
= Name_Op_Subtract
or else
2288 Op_Name
= Name_Op_Add
or else
2289 Op_Name
= Name_Op_Abs
2291 Find_Unary_Types
(Act1
, Op_Id
, N
);
2294 Op_Name
= Name_Op_Not
2296 Find_Negation_Types
(Act1
, Op_Id
, N
);
2298 -- Is this else null correct, or should it be an abort???
2304 end Analyze_Operator_Call
;
2306 -------------------------------------------
2307 -- Analyze_Overloaded_Selected_Component --
2308 -------------------------------------------
2310 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
) is
2311 Nam
: constant Node_Id
:= Prefix
(N
);
2312 Sel
: constant Node_Id
:= Selector_Name
(N
);
2319 Set_Etype
(Sel
, Any_Type
);
2321 Get_First_Interp
(Nam
, I
, It
);
2322 while Present
(It
.Typ
) loop
2323 if Is_Access_Type
(It
.Typ
) then
2324 T
:= Designated_Type
(It
.Typ
);
2325 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
2330 if Is_Record_Type
(T
) then
2331 Comp
:= First_Entity
(T
);
2332 while Present
(Comp
) loop
2333 if Chars
(Comp
) = Chars
(Sel
)
2334 and then Is_Visible_Component
(Comp
)
2336 Set_Entity_With_Style_Check
(Sel
, Comp
);
2337 Generate_Reference
(Comp
, Sel
);
2339 Set_Etype
(Sel
, Etype
(Comp
));
2340 Add_One_Interp
(N
, Etype
(Comp
), Etype
(Comp
));
2342 -- This also specifies a candidate to resolve the name.
2343 -- Further overloading will be resolved from context.
2345 Set_Etype
(Nam
, It
.Typ
);
2351 elsif Is_Concurrent_Type
(T
) then
2352 Comp
:= First_Entity
(T
);
2353 while Present
(Comp
)
2354 and then Comp
/= First_Private_Entity
(T
)
2356 if Chars
(Comp
) = Chars
(Sel
) then
2357 if Is_Overloadable
(Comp
) then
2358 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
2360 Set_Entity_With_Style_Check
(Sel
, Comp
);
2361 Generate_Reference
(Comp
, Sel
);
2364 Set_Etype
(Sel
, Etype
(Comp
));
2365 Set_Etype
(N
, Etype
(Comp
));
2366 Set_Etype
(Nam
, It
.Typ
);
2368 -- For access type case, introduce explicit deference for
2369 -- more uniform treatment of entry calls.
2371 if Is_Access_Type
(Etype
(Nam
)) then
2372 Insert_Explicit_Dereference
(Nam
);
2374 (Warn_On_Dereference
, "?implicit dereference", N
);
2381 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
2384 Get_Next_Interp
(I
, It
);
2387 if Etype
(N
) = Any_Type
then
2388 Error_Msg_NE
("undefined selector& for overloaded prefix", N
, Sel
);
2389 Set_Entity
(Sel
, Any_Id
);
2390 Set_Etype
(Sel
, Any_Type
);
2392 end Analyze_Overloaded_Selected_Component
;
2394 ----------------------------------
2395 -- Analyze_Qualified_Expression --
2396 ----------------------------------
2398 procedure Analyze_Qualified_Expression
(N
: Node_Id
) is
2399 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
2403 Set_Etype
(N
, Any_Type
);
2407 if T
= Any_Type
then
2411 Check_Fully_Declared
(T
, N
);
2412 Analyze_Expression
(Expression
(N
));
2414 end Analyze_Qualified_Expression
;
2420 procedure Analyze_Range
(N
: Node_Id
) is
2421 L
: constant Node_Id
:= Low_Bound
(N
);
2422 H
: constant Node_Id
:= High_Bound
(N
);
2423 I1
, I2
: Interp_Index
;
2426 procedure Check_Common_Type
(T1
, T2
: Entity_Id
);
2427 -- Verify the compatibility of two types, and choose the
2428 -- non universal one if the other is universal.
2430 procedure Check_High_Bound
(T
: Entity_Id
);
2431 -- Test one interpretation of the low bound against all those
2432 -- of the high bound.
2434 procedure Check_Universal_Expression
(N
: Node_Id
);
2435 -- In Ada83, reject bounds of a universal range that are not
2436 -- literals or entity names.
2438 -----------------------
2439 -- Check_Common_Type --
2440 -----------------------
2442 procedure Check_Common_Type
(T1
, T2
: Entity_Id
) is
2444 if Covers
(T1
, T2
) or else Covers
(T2
, T1
) then
2445 if T1
= Universal_Integer
2446 or else T1
= Universal_Real
2447 or else T1
= Any_Character
2449 Add_One_Interp
(N
, Base_Type
(T2
), Base_Type
(T2
));
2452 Add_One_Interp
(N
, T1
, T1
);
2455 Add_One_Interp
(N
, Base_Type
(T1
), Base_Type
(T1
));
2458 end Check_Common_Type
;
2460 ----------------------
2461 -- Check_High_Bound --
2462 ----------------------
2464 procedure Check_High_Bound
(T
: Entity_Id
) is
2466 if not Is_Overloaded
(H
) then
2467 Check_Common_Type
(T
, Etype
(H
));
2469 Get_First_Interp
(H
, I2
, It2
);
2470 while Present
(It2
.Typ
) loop
2471 Check_Common_Type
(T
, It2
.Typ
);
2472 Get_Next_Interp
(I2
, It2
);
2475 end Check_High_Bound
;
2477 -----------------------------
2478 -- Is_Universal_Expression --
2479 -----------------------------
2481 procedure Check_Universal_Expression
(N
: Node_Id
) is
2483 if Etype
(N
) = Universal_Integer
2484 and then Nkind
(N
) /= N_Integer_Literal
2485 and then not Is_Entity_Name
(N
)
2486 and then Nkind
(N
) /= N_Attribute_Reference
2488 Error_Msg_N
("illegal bound in discrete range", N
);
2490 end Check_Universal_Expression
;
2492 -- Start of processing for Analyze_Range
2495 Set_Etype
(N
, Any_Type
);
2496 Analyze_Expression
(L
);
2497 Analyze_Expression
(H
);
2499 if Etype
(L
) = Any_Type
or else Etype
(H
) = Any_Type
then
2503 if not Is_Overloaded
(L
) then
2504 Check_High_Bound
(Etype
(L
));
2506 Get_First_Interp
(L
, I1
, It1
);
2507 while Present
(It1
.Typ
) loop
2508 Check_High_Bound
(It1
.Typ
);
2509 Get_Next_Interp
(I1
, It1
);
2513 -- If result is Any_Type, then we did not find a compatible pair
2515 if Etype
(N
) = Any_Type
then
2516 Error_Msg_N
("incompatible types in range ", N
);
2520 if Ada_Version
= Ada_83
2522 (Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
2523 or else Nkind
(Parent
(N
)) = N_Constrained_Array_Definition
)
2525 Check_Universal_Expression
(L
);
2526 Check_Universal_Expression
(H
);
2530 -----------------------
2531 -- Analyze_Reference --
2532 -----------------------
2534 procedure Analyze_Reference
(N
: Node_Id
) is
2535 P
: constant Node_Id
:= Prefix
(N
);
2536 Acc_Type
: Entity_Id
;
2539 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
2540 Set_Etype
(Acc_Type
, Acc_Type
);
2541 Init_Size_Align
(Acc_Type
);
2542 Set_Directly_Designated_Type
(Acc_Type
, Etype
(P
));
2543 Set_Etype
(N
, Acc_Type
);
2544 end Analyze_Reference
;
2546 --------------------------------
2547 -- Analyze_Selected_Component --
2548 --------------------------------
2550 -- Prefix is a record type or a task or protected type. In the
2551 -- later case, the selector must denote a visible entry.
2553 procedure Analyze_Selected_Component
(N
: Node_Id
) is
2554 Name
: constant Node_Id
:= Prefix
(N
);
2555 Sel
: constant Node_Id
:= Selector_Name
(N
);
2557 Entity_List
: Entity_Id
;
2558 Prefix_Type
: Entity_Id
;
2559 Pent
: Entity_Id
:= Empty
;
2564 -- Start of processing for Analyze_Selected_Component
2567 Set_Etype
(N
, Any_Type
);
2569 if Is_Overloaded
(Name
) then
2570 Analyze_Overloaded_Selected_Component
(N
);
2573 elsif Etype
(Name
) = Any_Type
then
2574 Set_Entity
(Sel
, Any_Id
);
2575 Set_Etype
(Sel
, Any_Type
);
2579 Prefix_Type
:= Etype
(Name
);
2582 if Is_Access_Type
(Prefix_Type
) then
2584 -- A RACW object can never be used as prefix of a selected
2585 -- component since that means it is dereferenced without
2586 -- being a controlling operand of a dispatching operation
2589 if Is_Remote_Access_To_Class_Wide_Type
(Prefix_Type
)
2590 and then Comes_From_Source
(N
)
2593 ("invalid dereference of a remote access to class-wide value",
2596 -- Normal case of selected component applied to access type
2599 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
2601 if Is_Entity_Name
(Name
) then
2602 Pent
:= Entity
(Name
);
2603 elsif Nkind
(Name
) = N_Selected_Component
2604 and then Is_Entity_Name
(Selector_Name
(Name
))
2606 Pent
:= Entity
(Selector_Name
(Name
));
2609 Process_Implicit_Dereference_Prefix
(Pent
, Name
);
2612 Prefix_Type
:= Designated_Type
(Prefix_Type
);
2615 if Ekind
(Prefix_Type
) = E_Private_Subtype
then
2616 Prefix_Type
:= Base_Type
(Prefix_Type
);
2619 Entity_List
:= Prefix_Type
;
2621 -- For class-wide types, use the entity list of the root type. This
2622 -- indirection is specially important for private extensions because
2623 -- only the root type get switched (not the class-wide type).
2625 if Is_Class_Wide_Type
(Prefix_Type
) then
2626 Entity_List
:= Root_Type
(Prefix_Type
);
2629 Comp
:= First_Entity
(Entity_List
);
2631 -- If the selector has an original discriminant, the node appears in
2632 -- an instance. Replace the discriminant with the corresponding one
2633 -- in the current discriminated type. For nested generics, this must
2634 -- be done transitively, so note the new original discriminant.
2636 if Nkind
(Sel
) = N_Identifier
2637 and then Present
(Original_Discriminant
(Sel
))
2639 Comp
:= Find_Corresponding_Discriminant
(Sel
, Prefix_Type
);
2641 -- Mark entity before rewriting, for completeness and because
2642 -- subsequent semantic checks might examine the original node.
2644 Set_Entity
(Sel
, Comp
);
2645 Rewrite
(Selector_Name
(N
),
2646 New_Occurrence_Of
(Comp
, Sloc
(N
)));
2647 Set_Original_Discriminant
(Selector_Name
(N
), Comp
);
2648 Set_Etype
(N
, Etype
(Comp
));
2650 if Is_Access_Type
(Etype
(Name
)) then
2651 Insert_Explicit_Dereference
(Name
);
2652 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
2655 elsif Is_Record_Type
(Prefix_Type
) then
2657 -- Find component with given name
2659 while Present
(Comp
) loop
2660 if Chars
(Comp
) = Chars
(Sel
)
2661 and then Is_Visible_Component
(Comp
)
2663 Set_Entity_With_Style_Check
(Sel
, Comp
);
2664 Generate_Reference
(Comp
, Sel
);
2666 Set_Etype
(Sel
, Etype
(Comp
));
2668 if Ekind
(Comp
) = E_Discriminant
then
2669 if Is_Unchecked_Union
(Base_Type
(Prefix_Type
)) then
2671 ("cannot reference discriminant of Unchecked_Union",
2675 if Is_Generic_Type
(Prefix_Type
)
2677 Is_Generic_Type
(Root_Type
(Prefix_Type
))
2679 Set_Original_Discriminant
(Sel
, Comp
);
2683 -- Resolve the prefix early otherwise it is not possible to
2684 -- build the actual subtype of the component: it may need
2685 -- to duplicate this prefix and duplication is only allowed
2686 -- on fully resolved expressions.
2690 -- Ada 2005 (AI-50217): Check wrong use of incomplete type.
2693 -- limited with Pkg;
2695 -- type Acc_Inc is access Pkg.T;
2697 -- N : Natural := X.all.Comp; -- ERROR
2700 if Nkind
(Name
) = N_Explicit_Dereference
2701 and then From_With_Type
(Etype
(Prefix
(Name
)))
2702 and then not Is_Potentially_Use_Visible
(Etype
(Name
))
2705 ("premature usage of incomplete}", Prefix
(Name
),
2706 Etype
(Prefix
(Name
)));
2709 -- We never need an actual subtype for the case of a selection
2710 -- for a indexed component of a non-packed array, since in
2711 -- this case gigi generates all the checks and can find the
2712 -- necessary bounds information.
2714 -- We also do not need an actual subtype for the case of
2715 -- a first, last, length, or range attribute applied to a
2716 -- non-packed array, since gigi can again get the bounds in
2717 -- these cases (gigi cannot handle the packed case, since it
2718 -- has the bounds of the packed array type, not the original
2719 -- bounds of the type). However, if the prefix is itself a
2720 -- selected component, as in a.b.c (i), gigi may regard a.b.c
2721 -- as a dynamic-sized temporary, so we do generate an actual
2722 -- subtype for this case.
2724 Parent_N
:= Parent
(N
);
2726 if not Is_Packed
(Etype
(Comp
))
2728 ((Nkind
(Parent_N
) = N_Indexed_Component
2729 and then Nkind
(Name
) /= N_Selected_Component
)
2731 (Nkind
(Parent_N
) = N_Attribute_Reference
2732 and then (Attribute_Name
(Parent_N
) = Name_First
2734 Attribute_Name
(Parent_N
) = Name_Last
2736 Attribute_Name
(Parent_N
) = Name_Length
2738 Attribute_Name
(Parent_N
) = Name_Range
)))
2740 Set_Etype
(N
, Etype
(Comp
));
2742 -- If full analysis is not enabled, we do not generate an
2743 -- actual subtype, because in the absence of expansion
2744 -- reference to a formal of a protected type, for example,
2745 -- will not be properly transformed, and will lead to
2746 -- out-of-scope references in gigi.
2748 -- In all other cases, we currently build an actual subtype.
2749 -- It seems likely that many of these cases can be avoided,
2750 -- but right now, the front end makes direct references to the
2751 -- bounds (e.g. in generating a length check), and if we do
2752 -- not make an actual subtype, we end up getting a direct
2753 -- reference to a discriminant, which will not do.
2755 elsif Full_Analysis
then
2757 Build_Actual_Subtype_Of_Component
(Etype
(Comp
), N
);
2758 Insert_Action
(N
, Act_Decl
);
2760 if No
(Act_Decl
) then
2761 Set_Etype
(N
, Etype
(Comp
));
2764 -- Component type depends on discriminants. Enter the
2765 -- main attributes of the subtype.
2768 Subt
: constant Entity_Id
:=
2769 Defining_Identifier
(Act_Decl
);
2772 Set_Etype
(Subt
, Base_Type
(Etype
(Comp
)));
2773 Set_Ekind
(Subt
, Ekind
(Etype
(Comp
)));
2774 Set_Etype
(N
, Subt
);
2778 -- If Full_Analysis not enabled, just set the Etype
2781 Set_Etype
(N
, Etype
(Comp
));
2790 -- Ada 2005 (AI-252)
2792 if Ada_Version
>= Ada_05
2793 and then Is_Tagged_Type
(Prefix_Type
)
2794 and then Try_Object_Operation
(N
)
2798 -- If the transformation fails, it will be necessary to redo the
2799 -- analysis with all errors enabled, to indicate candidate
2800 -- interpretations and reasons for each failure ???
2804 elsif Is_Private_Type
(Prefix_Type
) then
2806 -- Allow access only to discriminants of the type. If the type has
2807 -- no full view, gigi uses the parent type for the components, so we
2808 -- do the same here.
2810 if No
(Full_View
(Prefix_Type
)) then
2811 Entity_List
:= Root_Type
(Base_Type
(Prefix_Type
));
2812 Comp
:= First_Entity
(Entity_List
);
2815 while Present
(Comp
) loop
2816 if Chars
(Comp
) = Chars
(Sel
) then
2817 if Ekind
(Comp
) = E_Discriminant
then
2818 Set_Entity_With_Style_Check
(Sel
, Comp
);
2819 Generate_Reference
(Comp
, Sel
);
2821 Set_Etype
(Sel
, Etype
(Comp
));
2822 Set_Etype
(N
, Etype
(Comp
));
2824 if Is_Generic_Type
(Prefix_Type
)
2826 Is_Generic_Type
(Root_Type
(Prefix_Type
))
2828 Set_Original_Discriminant
(Sel
, Comp
);
2833 ("invisible selector for }",
2834 N
, First_Subtype
(Prefix_Type
));
2835 Set_Entity
(Sel
, Any_Id
);
2836 Set_Etype
(N
, Any_Type
);
2845 elsif Is_Concurrent_Type
(Prefix_Type
) then
2847 -- Prefix is concurrent type. Find visible operation with given name
2848 -- For a task, this can only include entries or discriminants if the
2849 -- task type is not an enclosing scope. If it is an enclosing scope
2850 -- (e.g. in an inner task) then all entities are visible, but the
2851 -- prefix must denote the enclosing scope, i.e. can only be a direct
2852 -- name or an expanded name.
2854 Set_Etype
(Sel
, Any_Type
);
2855 In_Scope
:= In_Open_Scopes
(Prefix_Type
);
2857 while Present
(Comp
) loop
2858 if Chars
(Comp
) = Chars
(Sel
) then
2859 if Is_Overloadable
(Comp
) then
2860 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
2862 elsif Ekind
(Comp
) = E_Discriminant
2863 or else Ekind
(Comp
) = E_Entry_Family
2865 and then Is_Entity_Name
(Name
))
2867 Set_Entity_With_Style_Check
(Sel
, Comp
);
2868 Generate_Reference
(Comp
, Sel
);
2874 Set_Etype
(Sel
, Etype
(Comp
));
2875 Set_Etype
(N
, Etype
(Comp
));
2877 if Ekind
(Comp
) = E_Discriminant
then
2878 Set_Original_Discriminant
(Sel
, Comp
);
2881 -- For access type case, introduce explicit deference for more
2882 -- uniform treatment of entry calls.
2884 if Is_Access_Type
(Etype
(Name
)) then
2885 Insert_Explicit_Dereference
(Name
);
2887 (Warn_On_Dereference
, "?implicit dereference", N
);
2893 exit when not In_Scope
2895 Comp
= First_Private_Entity
(Base_Type
(Prefix_Type
));
2898 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
2903 Error_Msg_NE
("invalid prefix in selected component&", N
, Sel
);
2906 -- If N still has no type, the component is not defined in the prefix
2908 if Etype
(N
) = Any_Type
then
2910 -- If the prefix is a single concurrent object, use its name in the
2911 -- error message, rather than that of its anonymous type.
2913 if Is_Concurrent_Type
(Prefix_Type
)
2914 and then Is_Internal_Name
(Chars
(Prefix_Type
))
2915 and then not Is_Derived_Type
(Prefix_Type
)
2916 and then Is_Entity_Name
(Name
)
2919 Error_Msg_Node_2
:= Entity
(Name
);
2920 Error_Msg_NE
("no selector& for&", N
, Sel
);
2922 Check_Misspelled_Selector
(Entity_List
, Sel
);
2924 elsif Is_Generic_Type
(Prefix_Type
)
2925 and then Ekind
(Prefix_Type
) = E_Record_Type_With_Private
2926 and then Prefix_Type
/= Etype
(Prefix_Type
)
2927 and then Is_Record_Type
(Etype
(Prefix_Type
))
2929 -- If this is a derived formal type, the parent may have
2930 -- different visibility at this point. Try for an inherited
2931 -- component before reporting an error.
2933 Set_Etype
(Prefix
(N
), Etype
(Prefix_Type
));
2934 Analyze_Selected_Component
(N
);
2937 elsif Ekind
(Prefix_Type
) = E_Record_Subtype_With_Private
2938 and then Is_Generic_Actual_Type
(Prefix_Type
)
2939 and then Present
(Full_View
(Prefix_Type
))
2941 -- Similarly, if this the actual for a formal derived type, the
2942 -- component inherited from the generic parent may not be visible
2943 -- in the actual, but the selected component is legal.
2950 First_Component
(Generic_Parent_Type
(Parent
(Prefix_Type
)));
2951 while Present
(Comp
) loop
2952 if Chars
(Comp
) = Chars
(Sel
) then
2953 Set_Entity_With_Style_Check
(Sel
, Comp
);
2954 Set_Etype
(Sel
, Etype
(Comp
));
2955 Set_Etype
(N
, Etype
(Comp
));
2959 Next_Component
(Comp
);
2962 pragma Assert
(Etype
(N
) /= Any_Type
);
2966 if Ekind
(Prefix_Type
) = E_Record_Subtype
then
2968 -- Check whether this is a component of the base type
2969 -- which is absent from a statically constrained subtype.
2970 -- This will raise constraint error at run-time, but is
2971 -- not a compile-time error. When the selector is illegal
2972 -- for base type as well fall through and generate a
2973 -- compilation error anyway.
2975 Comp
:= First_Component
(Base_Type
(Prefix_Type
));
2976 while Present
(Comp
) loop
2977 if Chars
(Comp
) = Chars
(Sel
)
2978 and then Is_Visible_Component
(Comp
)
2980 Set_Entity_With_Style_Check
(Sel
, Comp
);
2981 Generate_Reference
(Comp
, Sel
);
2982 Set_Etype
(Sel
, Etype
(Comp
));
2983 Set_Etype
(N
, Etype
(Comp
));
2985 -- Emit appropriate message. Gigi will replace the
2986 -- node subsequently with the appropriate Raise.
2988 Apply_Compile_Time_Constraint_Error
2989 (N
, "component not present in }?",
2990 CE_Discriminant_Check_Failed
,
2991 Ent
=> Prefix_Type
, Rep
=> False);
2992 Set_Raises_Constraint_Error
(N
);
2996 Next_Component
(Comp
);
3001 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
3002 Error_Msg_NE
("no selector& for}", N
, Sel
);
3004 Check_Misspelled_Selector
(Entity_List
, Sel
);
3008 Set_Entity
(Sel
, Any_Id
);
3009 Set_Etype
(Sel
, Any_Type
);
3011 end Analyze_Selected_Component
;
3013 ---------------------------
3014 -- Analyze_Short_Circuit --
3015 ---------------------------
3017 procedure Analyze_Short_Circuit
(N
: Node_Id
) is
3018 L
: constant Node_Id
:= Left_Opnd
(N
);
3019 R
: constant Node_Id
:= Right_Opnd
(N
);
3024 Analyze_Expression
(L
);
3025 Analyze_Expression
(R
);
3026 Set_Etype
(N
, Any_Type
);
3028 if not Is_Overloaded
(L
) then
3030 if Root_Type
(Etype
(L
)) = Standard_Boolean
3031 and then Has_Compatible_Type
(R
, Etype
(L
))
3033 Add_One_Interp
(N
, Etype
(L
), Etype
(L
));
3037 Get_First_Interp
(L
, Ind
, It
);
3038 while Present
(It
.Typ
) loop
3039 if Root_Type
(It
.Typ
) = Standard_Boolean
3040 and then Has_Compatible_Type
(R
, It
.Typ
)
3042 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
3045 Get_Next_Interp
(Ind
, It
);
3049 -- Here we have failed to find an interpretation. Clearly we
3050 -- know that it is not the case that both operands can have
3051 -- an interpretation of Boolean, but this is by far the most
3052 -- likely intended interpretation. So we simply resolve both
3053 -- operands as Booleans, and at least one of these resolutions
3054 -- will generate an error message, and we do not need to give
3055 -- a further error message on the short circuit operation itself.
3057 if Etype
(N
) = Any_Type
then
3058 Resolve
(L
, Standard_Boolean
);
3059 Resolve
(R
, Standard_Boolean
);
3060 Set_Etype
(N
, Standard_Boolean
);
3062 end Analyze_Short_Circuit
;
3068 procedure Analyze_Slice
(N
: Node_Id
) is
3069 P
: constant Node_Id
:= Prefix
(N
);
3070 D
: constant Node_Id
:= Discrete_Range
(N
);
3071 Array_Type
: Entity_Id
;
3073 procedure Analyze_Overloaded_Slice
;
3074 -- If the prefix is overloaded, select those interpretations that
3075 -- yield a one-dimensional array type.
3077 ------------------------------
3078 -- Analyze_Overloaded_Slice --
3079 ------------------------------
3081 procedure Analyze_Overloaded_Slice
is
3087 Set_Etype
(N
, Any_Type
);
3089 Get_First_Interp
(P
, I
, It
);
3090 while Present
(It
.Nam
) loop
3093 if Is_Access_Type
(Typ
) then
3094 Typ
:= Designated_Type
(Typ
);
3095 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
3098 if Is_Array_Type
(Typ
)
3099 and then Number_Dimensions
(Typ
) = 1
3100 and then Has_Compatible_Type
(D
, Etype
(First_Index
(Typ
)))
3102 Add_One_Interp
(N
, Typ
, Typ
);
3105 Get_Next_Interp
(I
, It
);
3108 if Etype
(N
) = Any_Type
then
3109 Error_Msg_N
("expect array type in prefix of slice", N
);
3111 end Analyze_Overloaded_Slice
;
3113 -- Start of processing for Analyze_Slice
3119 if Is_Overloaded
(P
) then
3120 Analyze_Overloaded_Slice
;
3123 Array_Type
:= Etype
(P
);
3124 Set_Etype
(N
, Any_Type
);
3126 if Is_Access_Type
(Array_Type
) then
3127 Array_Type
:= Designated_Type
(Array_Type
);
3128 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
3131 if not Is_Array_Type
(Array_Type
) then
3132 Wrong_Type
(P
, Any_Array
);
3134 elsif Number_Dimensions
(Array_Type
) > 1 then
3136 ("type is not one-dimensional array in slice prefix", N
);
3139 Has_Compatible_Type
(D
, Etype
(First_Index
(Array_Type
)))
3141 Wrong_Type
(D
, Etype
(First_Index
(Array_Type
)));
3144 Set_Etype
(N
, Array_Type
);
3149 -----------------------------
3150 -- Analyze_Type_Conversion --
3151 -----------------------------
3153 procedure Analyze_Type_Conversion
(N
: Node_Id
) is
3154 Expr
: constant Node_Id
:= Expression
(N
);
3158 -- If Conversion_OK is set, then the Etype is already set, and the
3159 -- only processing required is to analyze the expression. This is
3160 -- used to construct certain "illegal" conversions which are not
3161 -- allowed by Ada semantics, but can be handled OK by Gigi, see
3162 -- Sinfo for further details.
3164 if Conversion_OK
(N
) then
3169 -- Otherwise full type analysis is required, as well as some semantic
3170 -- checks to make sure the argument of the conversion is appropriate.
3172 Find_Type
(Subtype_Mark
(N
));
3173 T
:= Entity
(Subtype_Mark
(N
));
3175 Check_Fully_Declared
(T
, N
);
3176 Analyze_Expression
(Expr
);
3177 Validate_Remote_Type_Type_Conversion
(N
);
3179 -- Only remaining step is validity checks on the argument. These
3180 -- are skipped if the conversion does not come from the source.
3182 if not Comes_From_Source
(N
) then
3185 elsif Nkind
(Expr
) = N_Null
then
3186 Error_Msg_N
("argument of conversion cannot be null", N
);
3187 Error_Msg_N
("\use qualified expression instead", N
);
3188 Set_Etype
(N
, Any_Type
);
3190 elsif Nkind
(Expr
) = N_Aggregate
then
3191 Error_Msg_N
("argument of conversion cannot be aggregate", N
);
3192 Error_Msg_N
("\use qualified expression instead", N
);
3194 elsif Nkind
(Expr
) = N_Allocator
then
3195 Error_Msg_N
("argument of conversion cannot be an allocator", N
);
3196 Error_Msg_N
("\use qualified expression instead", N
);
3198 elsif Nkind
(Expr
) = N_String_Literal
then
3199 Error_Msg_N
("argument of conversion cannot be string literal", N
);
3200 Error_Msg_N
("\use qualified expression instead", N
);
3202 elsif Nkind
(Expr
) = N_Character_Literal
then
3203 if Ada_Version
= Ada_83
then
3206 Error_Msg_N
("argument of conversion cannot be character literal",
3208 Error_Msg_N
("\use qualified expression instead", N
);
3211 elsif Nkind
(Expr
) = N_Attribute_Reference
3213 (Attribute_Name
(Expr
) = Name_Access
or else
3214 Attribute_Name
(Expr
) = Name_Unchecked_Access
or else
3215 Attribute_Name
(Expr
) = Name_Unrestricted_Access
)
3217 Error_Msg_N
("argument of conversion cannot be access", N
);
3218 Error_Msg_N
("\use qualified expression instead", N
);
3220 end Analyze_Type_Conversion
;
3222 ----------------------
3223 -- Analyze_Unary_Op --
3224 ----------------------
3226 procedure Analyze_Unary_Op
(N
: Node_Id
) is
3227 R
: constant Node_Id
:= Right_Opnd
(N
);
3228 Op_Id
: Entity_Id
:= Entity
(N
);
3231 Set_Etype
(N
, Any_Type
);
3232 Candidate_Type
:= Empty
;
3234 Analyze_Expression
(R
);
3236 if Present
(Op_Id
) then
3237 if Ekind
(Op_Id
) = E_Operator
then
3238 Find_Unary_Types
(R
, Op_Id
, N
);
3240 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3244 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
3245 while Present
(Op_Id
) loop
3246 if Ekind
(Op_Id
) = E_Operator
then
3247 if No
(Next_Entity
(First_Entity
(Op_Id
))) then
3248 Find_Unary_Types
(R
, Op_Id
, N
);
3251 elsif Is_Overloadable
(Op_Id
) then
3252 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
3255 Op_Id
:= Homonym
(Op_Id
);
3260 end Analyze_Unary_Op
;
3262 ----------------------------------
3263 -- Analyze_Unchecked_Expression --
3264 ----------------------------------
3266 procedure Analyze_Unchecked_Expression
(N
: Node_Id
) is
3268 Analyze
(Expression
(N
), Suppress
=> All_Checks
);
3269 Set_Etype
(N
, Etype
(Expression
(N
)));
3270 Save_Interps
(Expression
(N
), N
);
3271 end Analyze_Unchecked_Expression
;
3273 ---------------------------------------
3274 -- Analyze_Unchecked_Type_Conversion --
3275 ---------------------------------------
3277 procedure Analyze_Unchecked_Type_Conversion
(N
: Node_Id
) is
3279 Find_Type
(Subtype_Mark
(N
));
3280 Analyze_Expression
(Expression
(N
));
3281 Set_Etype
(N
, Entity
(Subtype_Mark
(N
)));
3282 end Analyze_Unchecked_Type_Conversion
;
3284 ------------------------------------
3285 -- Analyze_User_Defined_Binary_Op --
3286 ------------------------------------
3288 procedure Analyze_User_Defined_Binary_Op
3293 -- Only do analysis if the operator Comes_From_Source, since otherwise
3294 -- the operator was generated by the expander, and all such operators
3295 -- always refer to the operators in package Standard.
3297 if Comes_From_Source
(N
) then
3299 F1
: constant Entity_Id
:= First_Formal
(Op_Id
);
3300 F2
: constant Entity_Id
:= Next_Formal
(F1
);
3303 -- Verify that Op_Id is a visible binary function. Note that since
3304 -- we know Op_Id is overloaded, potentially use visible means use
3305 -- visible for sure (RM 9.4(11)).
3307 if Ekind
(Op_Id
) = E_Function
3308 and then Present
(F2
)
3309 and then (Is_Immediately_Visible
(Op_Id
)
3310 or else Is_Potentially_Use_Visible
(Op_Id
))
3311 and then Has_Compatible_Type
(Left_Opnd
(N
), Etype
(F1
))
3312 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F2
))
3314 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3316 if Debug_Flag_E
then
3317 Write_Str
("user defined operator ");
3318 Write_Name
(Chars
(Op_Id
));
3319 Write_Str
(" on node ");
3320 Write_Int
(Int
(N
));
3326 end Analyze_User_Defined_Binary_Op
;
3328 -----------------------------------
3329 -- Analyze_User_Defined_Unary_Op --
3330 -----------------------------------
3332 procedure Analyze_User_Defined_Unary_Op
3337 -- Only do analysis if the operator Comes_From_Source, since otherwise
3338 -- the operator was generated by the expander, and all such operators
3339 -- always refer to the operators in package Standard.
3341 if Comes_From_Source
(N
) then
3343 F
: constant Entity_Id
:= First_Formal
(Op_Id
);
3346 -- Verify that Op_Id is a visible unary function. Note that since
3347 -- we know Op_Id is overloaded, potentially use visible means use
3348 -- visible for sure (RM 9.4(11)).
3350 if Ekind
(Op_Id
) = E_Function
3351 and then No
(Next_Formal
(F
))
3352 and then (Is_Immediately_Visible
(Op_Id
)
3353 or else Is_Potentially_Use_Visible
(Op_Id
))
3354 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F
))
3356 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3360 end Analyze_User_Defined_Unary_Op
;
3362 ---------------------------
3363 -- Check_Arithmetic_Pair --
3364 ---------------------------
3366 procedure Check_Arithmetic_Pair
3367 (T1
, T2
: Entity_Id
;
3371 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
3373 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean;
3374 -- Check whether the fixed-point type Typ has a user-defined operator
3375 -- (multiplication or division) that should hide the corresponding
3376 -- predefined operator. Used to implement Ada 2005 AI-264, to make
3377 -- such operators more visible and therefore useful.
3379 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
;
3380 -- Get specific type (i.e. non-universal type if there is one)
3386 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean is
3392 -- The operation is treated as primitive if it is declared in the
3393 -- same scope as the type, and therefore on the same entity chain.
3395 Ent
:= Next_Entity
(Typ
);
3396 while Present
(Ent
) loop
3397 if Chars
(Ent
) = Chars
(Op
) then
3398 F1
:= First_Formal
(Ent
);
3399 F2
:= Next_Formal
(F1
);
3401 -- The operation counts as primitive if either operand or
3402 -- result are of the given type, and both operands are fixed
3405 if (Etype
(F1
) = Typ
3406 and then Is_Fixed_Point_Type
(Etype
(F2
)))
3410 and then Is_Fixed_Point_Type
(Etype
(F1
)))
3414 and then Is_Fixed_Point_Type
(Etype
(F1
))
3415 and then Is_Fixed_Point_Type
(Etype
(F2
)))
3431 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
is
3433 if T1
= Universal_Integer
or else T1
= Universal_Real
then
3434 return Base_Type
(T2
);
3436 return Base_Type
(T1
);
3440 -- Start of processing for Check_Arithmetic_Pair
3443 if Op_Name
= Name_Op_Add
or else Op_Name
= Name_Op_Subtract
then
3445 if Is_Numeric_Type
(T1
)
3446 and then Is_Numeric_Type
(T2
)
3447 and then (Covers
(T1
, T2
) or else Covers
(T2
, T1
))
3449 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
3452 elsif Op_Name
= Name_Op_Multiply
or else Op_Name
= Name_Op_Divide
then
3454 if Is_Fixed_Point_Type
(T1
)
3455 and then (Is_Fixed_Point_Type
(T2
)
3456 or else T2
= Universal_Real
)
3458 -- If Treat_Fixed_As_Integer is set then the Etype is already set
3459 -- and no further processing is required (this is the case of an
3460 -- operator constructed by Exp_Fixd for a fixed point operation)
3461 -- Otherwise add one interpretation with universal fixed result
3462 -- If the operator is given in functional notation, it comes
3463 -- from source and Fixed_As_Integer cannot apply.
3465 if (Nkind
(N
) not in N_Op
3466 or else not Treat_Fixed_As_Integer
(N
))
3468 (not (Ada_Version
>= Ada_05
and then Has_Fixed_Op
(T1
, Op_Id
))
3469 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
3471 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
3474 elsif Is_Fixed_Point_Type
(T2
)
3475 and then (Nkind
(N
) not in N_Op
3476 or else not Treat_Fixed_As_Integer
(N
))
3477 and then T1
= Universal_Real
3479 (not (Ada_Version
>= Ada_05
and then Has_Fixed_Op
(T1
, Op_Id
))
3480 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
3482 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
3484 elsif Is_Numeric_Type
(T1
)
3485 and then Is_Numeric_Type
(T2
)
3486 and then (Covers
(T1
, T2
) or else Covers
(T2
, T1
))
3488 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
3490 elsif Is_Fixed_Point_Type
(T1
)
3491 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3492 or else T2
= Universal_Integer
)
3494 Add_One_Interp
(N
, Op_Id
, T1
);
3496 elsif T2
= Universal_Real
3497 and then Base_Type
(T1
) = Base_Type
(Standard_Integer
)
3498 and then Op_Name
= Name_Op_Multiply
3500 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
3502 elsif T1
= Universal_Real
3503 and then Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3505 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
3507 elsif Is_Fixed_Point_Type
(T2
)
3508 and then (Base_Type
(T1
) = Base_Type
(Standard_Integer
)
3509 or else T1
= Universal_Integer
)
3510 and then Op_Name
= Name_Op_Multiply
3512 Add_One_Interp
(N
, Op_Id
, T2
);
3514 elsif T1
= Universal_Real
and then T2
= Universal_Integer
then
3515 Add_One_Interp
(N
, Op_Id
, T1
);
3517 elsif T2
= Universal_Real
3518 and then T1
= Universal_Integer
3519 and then Op_Name
= Name_Op_Multiply
3521 Add_One_Interp
(N
, Op_Id
, T2
);
3524 elsif Op_Name
= Name_Op_Mod
or else Op_Name
= Name_Op_Rem
then
3526 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
3527 -- set does not require any special processing, since the Etype is
3528 -- already set (case of operation constructed by Exp_Fixed).
3530 if Is_Integer_Type
(T1
)
3531 and then (Covers
(T1
, T2
) or else Covers
(T2
, T1
))
3533 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
3536 elsif Op_Name
= Name_Op_Expon
then
3537 if Is_Numeric_Type
(T1
)
3538 and then not Is_Fixed_Point_Type
(T1
)
3539 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3540 or else T2
= Universal_Integer
)
3542 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
3545 else pragma Assert
(Nkind
(N
) in N_Op_Shift
);
3547 -- If not one of the predefined operators, the node may be one
3548 -- of the intrinsic functions. Its kind is always specific, and
3549 -- we can use it directly, rather than the name of the operation.
3551 if Is_Integer_Type
(T1
)
3552 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3553 or else T2
= Universal_Integer
)
3555 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
3558 end Check_Arithmetic_Pair
;
3560 -------------------------------
3561 -- Check_Misspelled_Selector --
3562 -------------------------------
3564 procedure Check_Misspelled_Selector
3565 (Prefix
: Entity_Id
;
3568 Max_Suggestions
: constant := 2;
3569 Nr_Of_Suggestions
: Natural := 0;
3571 Suggestion_1
: Entity_Id
:= Empty
;
3572 Suggestion_2
: Entity_Id
:= Empty
;
3577 -- All the components of the prefix of selector Sel are matched
3578 -- against Sel and a count is maintained of possible misspellings.
3579 -- When at the end of the analysis there are one or two (not more!)
3580 -- possible misspellings, these misspellings will be suggested as
3581 -- possible correction.
3583 if not (Is_Private_Type
(Prefix
) or else Is_Record_Type
(Prefix
)) then
3585 -- Concurrent types should be handled as well ???
3590 Get_Name_String
(Chars
(Sel
));
3593 S
: constant String (1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
3596 Comp
:= First_Entity
(Prefix
);
3597 while Nr_Of_Suggestions
<= Max_Suggestions
3598 and then Present
(Comp
)
3600 if Is_Visible_Component
(Comp
) then
3601 Get_Name_String
(Chars
(Comp
));
3603 if Is_Bad_Spelling_Of
(Name_Buffer
(1 .. Name_Len
), S
) then
3604 Nr_Of_Suggestions
:= Nr_Of_Suggestions
+ 1;
3606 case Nr_Of_Suggestions
is
3607 when 1 => Suggestion_1
:= Comp
;
3608 when 2 => Suggestion_2
:= Comp
;
3609 when others => exit;
3614 Comp
:= Next_Entity
(Comp
);
3617 -- Report at most two suggestions
3619 if Nr_Of_Suggestions
= 1 then
3620 Error_Msg_NE
("\possible misspelling of&", Sel
, Suggestion_1
);
3622 elsif Nr_Of_Suggestions
= 2 then
3623 Error_Msg_Node_2
:= Suggestion_2
;
3624 Error_Msg_NE
("\possible misspelling of& or&",
3628 end Check_Misspelled_Selector
;
3630 ----------------------
3631 -- Defined_In_Scope --
3632 ----------------------
3634 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean
3636 S1
: constant Entity_Id
:= Scope
(Base_Type
(T
));
3639 or else (S1
= System_Aux_Id
and then S
= Scope
(S1
));
3640 end Defined_In_Scope
;
3646 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
) is
3653 Void_Interp_Seen
: Boolean := False;
3656 if Ada_Version
>= Ada_05
then
3657 Actual
:= First_Actual
(N
);
3658 while Present
(Actual
) loop
3660 -- Ada 2005 (AI-50217): Post an error in case of premature
3661 -- usage of an entity from the limited view.
3663 if not Analyzed
(Etype
(Actual
))
3664 and then From_With_Type
(Etype
(Actual
))
3666 Error_Msg_Qual_Level
:= 1;
3668 ("missing with_clause for scope of imported type&",
3669 Actual
, Etype
(Actual
));
3670 Error_Msg_Qual_Level
:= 0;
3673 Next_Actual
(Actual
);
3677 -- Analyze each candidate call again, with full error reporting
3681 ("no candidate interpretations match the actuals:!", Nam
);
3682 Err_Mode
:= All_Errors_Mode
;
3683 All_Errors_Mode
:= True;
3685 -- If this is a call to an operation of a concurrent type,
3686 -- the failed interpretations have been removed from the
3687 -- name. Recover them to provide full diagnostics.
3689 if Nkind
(Parent
(Nam
)) = N_Selected_Component
then
3690 Set_Entity
(Nam
, Empty
);
3691 New_Nam
:= New_Copy_Tree
(Parent
(Nam
));
3692 Set_Is_Overloaded
(New_Nam
, False);
3693 Set_Is_Overloaded
(Selector_Name
(New_Nam
), False);
3694 Set_Parent
(New_Nam
, Parent
(Parent
(Nam
)));
3695 Analyze_Selected_Component
(New_Nam
);
3696 Get_First_Interp
(Selector_Name
(New_Nam
), X
, It
);
3698 Get_First_Interp
(Nam
, X
, It
);
3701 while Present
(It
.Nam
) loop
3702 if Etype
(It
.Nam
) = Standard_Void_Type
then
3703 Void_Interp_Seen
:= True;
3706 Analyze_One_Call
(N
, It
.Nam
, True, Success
);
3707 Get_Next_Interp
(X
, It
);
3710 if Nkind
(N
) = N_Function_Call
then
3711 Get_First_Interp
(Nam
, X
, It
);
3712 while Present
(It
.Nam
) loop
3713 if Ekind
(It
.Nam
) = E_Function
3714 or else Ekind
(It
.Nam
) = E_Operator
3718 Get_Next_Interp
(X
, It
);
3722 -- If all interpretations are procedures, this deserves a
3723 -- more precise message. Ditto if this appears as the prefix
3724 -- of a selected component, which may be a lexical error.
3727 ("\context requires function call, found procedure name", Nam
);
3729 if Nkind
(Parent
(N
)) = N_Selected_Component
3730 and then N
= Prefix
(Parent
(N
))
3733 "\period should probably be semicolon", Parent
(N
));
3736 elsif Nkind
(N
) = N_Procedure_Call_Statement
3737 and then not Void_Interp_Seen
3740 "\function name found in procedure call", Nam
);
3743 All_Errors_Mode
:= Err_Mode
;
3746 ---------------------------
3747 -- Find_Arithmetic_Types --
3748 ---------------------------
3750 procedure Find_Arithmetic_Types
3755 Index1
: Interp_Index
;
3756 Index2
: Interp_Index
;
3760 procedure Check_Right_Argument
(T
: Entity_Id
);
3761 -- Check right operand of operator
3763 --------------------------
3764 -- Check_Right_Argument --
3765 --------------------------
3767 procedure Check_Right_Argument
(T
: Entity_Id
) is
3769 if not Is_Overloaded
(R
) then
3770 Check_Arithmetic_Pair
(T
, Etype
(R
), Op_Id
, N
);
3772 Get_First_Interp
(R
, Index2
, It2
);
3773 while Present
(It2
.Typ
) loop
3774 Check_Arithmetic_Pair
(T
, It2
.Typ
, Op_Id
, N
);
3775 Get_Next_Interp
(Index2
, It2
);
3778 end Check_Right_Argument
;
3780 -- Start processing for Find_Arithmetic_Types
3783 if not Is_Overloaded
(L
) then
3784 Check_Right_Argument
(Etype
(L
));
3787 Get_First_Interp
(L
, Index1
, It1
);
3788 while Present
(It1
.Typ
) loop
3789 Check_Right_Argument
(It1
.Typ
);
3790 Get_Next_Interp
(Index1
, It1
);
3794 end Find_Arithmetic_Types
;
3796 ------------------------
3797 -- Find_Boolean_Types --
3798 ------------------------
3800 procedure Find_Boolean_Types
3805 Index
: Interp_Index
;
3808 procedure Check_Numeric_Argument
(T
: Entity_Id
);
3809 -- Special case for logical operations one of whose operands is an
3810 -- integer literal. If both are literal the result is any modular type.
3812 ----------------------------
3813 -- Check_Numeric_Argument --
3814 ----------------------------
3816 procedure Check_Numeric_Argument
(T
: Entity_Id
) is
3818 if T
= Universal_Integer
then
3819 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
3821 elsif Is_Modular_Integer_Type
(T
) then
3822 Add_One_Interp
(N
, Op_Id
, T
);
3824 end Check_Numeric_Argument
;
3826 -- Start of processing for Find_Boolean_Types
3829 if not Is_Overloaded
(L
) then
3830 if Etype
(L
) = Universal_Integer
3831 or else Etype
(L
) = Any_Modular
3833 if not Is_Overloaded
(R
) then
3834 Check_Numeric_Argument
(Etype
(R
));
3837 Get_First_Interp
(R
, Index
, It
);
3838 while Present
(It
.Typ
) loop
3839 Check_Numeric_Argument
(It
.Typ
);
3840 Get_Next_Interp
(Index
, It
);
3844 elsif Valid_Boolean_Arg
(Etype
(L
))
3845 and then Has_Compatible_Type
(R
, Etype
(L
))
3847 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
3851 Get_First_Interp
(L
, Index
, It
);
3852 while Present
(It
.Typ
) loop
3853 if Valid_Boolean_Arg
(It
.Typ
)
3854 and then Has_Compatible_Type
(R
, It
.Typ
)
3856 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
3859 Get_Next_Interp
(Index
, It
);
3862 end Find_Boolean_Types
;
3864 ---------------------------
3865 -- Find_Comparison_Types --
3866 ---------------------------
3868 procedure Find_Comparison_Types
3873 Index
: Interp_Index
;
3875 Found
: Boolean := False;
3878 Scop
: Entity_Id
:= Empty
;
3880 procedure Try_One_Interp
(T1
: Entity_Id
);
3881 -- Routine to try one proposed interpretation. Note that the context
3882 -- of the operator plays no role in resolving the arguments, so that
3883 -- if there is more than one interpretation of the operands that is
3884 -- compatible with comparison, the operation is ambiguous.
3886 --------------------
3887 -- Try_One_Interp --
3888 --------------------
3890 procedure Try_One_Interp
(T1
: Entity_Id
) is
3893 -- If the operator is an expanded name, then the type of the operand
3894 -- must be defined in the corresponding scope. If the type is
3895 -- universal, the context will impose the correct type.
3898 and then not Defined_In_Scope
(T1
, Scop
)
3899 and then T1
/= Universal_Integer
3900 and then T1
/= Universal_Real
3901 and then T1
/= Any_String
3902 and then T1
/= Any_Composite
3907 if Valid_Comparison_Arg
(T1
)
3908 and then Has_Compatible_Type
(R
, T1
)
3911 and then Base_Type
(T1
) /= Base_Type
(T_F
)
3913 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
3915 if It
= No_Interp
then
3916 Ambiguous_Operands
(N
);
3917 Set_Etype
(L
, Any_Type
);
3931 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
3936 -- Start processing for Find_Comparison_Types
3939 -- If left operand is aggregate, the right operand has to
3940 -- provide a usable type for it.
3942 if Nkind
(L
) = N_Aggregate
3943 and then Nkind
(R
) /= N_Aggregate
3945 Find_Comparison_Types
(R
, L
, Op_Id
, N
);
3949 if Nkind
(N
) = N_Function_Call
3950 and then Nkind
(Name
(N
)) = N_Expanded_Name
3952 Scop
:= Entity
(Prefix
(Name
(N
)));
3954 -- The prefix may be a package renaming, and the subsequent test
3955 -- requires the original package.
3957 if Ekind
(Scop
) = E_Package
3958 and then Present
(Renamed_Entity
(Scop
))
3960 Scop
:= Renamed_Entity
(Scop
);
3961 Set_Entity
(Prefix
(Name
(N
)), Scop
);
3965 if not Is_Overloaded
(L
) then
3966 Try_One_Interp
(Etype
(L
));
3969 Get_First_Interp
(L
, Index
, It
);
3970 while Present
(It
.Typ
) loop
3971 Try_One_Interp
(It
.Typ
);
3972 Get_Next_Interp
(Index
, It
);
3975 end Find_Comparison_Types
;
3977 ----------------------------------------
3978 -- Find_Non_Universal_Interpretations --
3979 ----------------------------------------
3981 procedure Find_Non_Universal_Interpretations
3987 Index
: Interp_Index
;
3991 if T1
= Universal_Integer
3992 or else T1
= Universal_Real
3994 if not Is_Overloaded
(R
) then
3996 (N
, Op_Id
, Standard_Boolean
, Base_Type
(Etype
(R
)));
3998 Get_First_Interp
(R
, Index
, It
);
3999 while Present
(It
.Typ
) loop
4000 if Covers
(It
.Typ
, T1
) then
4002 (N
, Op_Id
, Standard_Boolean
, Base_Type
(It
.Typ
));
4005 Get_Next_Interp
(Index
, It
);
4009 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(T1
));
4011 end Find_Non_Universal_Interpretations
;
4013 ------------------------------
4014 -- Find_Concatenation_Types --
4015 ------------------------------
4017 procedure Find_Concatenation_Types
4022 Op_Type
: constant Entity_Id
:= Etype
(Op_Id
);
4025 if Is_Array_Type
(Op_Type
)
4026 and then not Is_Limited_Type
(Op_Type
)
4028 and then (Has_Compatible_Type
(L
, Op_Type
)
4030 Has_Compatible_Type
(L
, Component_Type
(Op_Type
)))
4032 and then (Has_Compatible_Type
(R
, Op_Type
)
4034 Has_Compatible_Type
(R
, Component_Type
(Op_Type
)))
4036 Add_One_Interp
(N
, Op_Id
, Op_Type
);
4038 end Find_Concatenation_Types
;
4040 -------------------------
4041 -- Find_Equality_Types --
4042 -------------------------
4044 procedure Find_Equality_Types
4049 Index
: Interp_Index
;
4051 Found
: Boolean := False;
4054 Scop
: Entity_Id
:= Empty
;
4056 procedure Try_One_Interp
(T1
: Entity_Id
);
4057 -- The context of the operator plays no role in resolving the
4058 -- arguments, so that if there is more than one interpretation
4059 -- of the operands that is compatible with equality, the construct
4060 -- is ambiguous and an error can be emitted now, after trying to
4061 -- disambiguate, i.e. applying preference rules.
4063 --------------------
4064 -- Try_One_Interp --
4065 --------------------
4067 procedure Try_One_Interp
(T1
: Entity_Id
) is
4069 -- If the operator is an expanded name, then the type of the operand
4070 -- must be defined in the corresponding scope. If the type is
4071 -- universal, the context will impose the correct type. An anonymous
4072 -- type for a 'Access reference is also universal in this sense, as
4073 -- the actual type is obtained from context.
4074 -- In Ada 2005, the equality operator for anonymous access types
4075 -- is declared in Standard, and preference rules apply to it.
4077 if Present
(Scop
) then
4078 if Defined_In_Scope
(T1
, Scop
)
4079 or else T1
= Universal_Integer
4080 or else T1
= Universal_Real
4081 or else T1
= Any_Access
4082 or else T1
= Any_String
4083 or else T1
= Any_Composite
4084 or else (Ekind
(T1
) = E_Access_Subprogram_Type
4085 and then not Comes_From_Source
(T1
))
4089 elsif Ekind
(T1
) = E_Anonymous_Access_Type
4090 and then Scop
= Standard_Standard
4095 -- The scope does not contain an operator for the type
4101 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
4102 -- Do not allow anonymous access types in equality operators.
4104 if Ada_Version
< Ada_05
4105 and then Ekind
(T1
) = E_Anonymous_Access_Type
4110 if T1
/= Standard_Void_Type
4111 and then not Is_Limited_Type
(T1
)
4112 and then not Is_Limited_Composite
(T1
)
4113 and then Has_Compatible_Type
(R
, T1
)
4116 and then Base_Type
(T1
) /= Base_Type
(T_F
)
4118 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
4120 if It
= No_Interp
then
4121 Ambiguous_Operands
(N
);
4122 Set_Etype
(L
, Any_Type
);
4135 if not Analyzed
(L
) then
4139 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
4141 -- Case of operator was not visible, Etype still set to Any_Type
4143 if Etype
(N
) = Any_Type
then
4147 elsif Scop
= Standard_Standard
4148 and then Ekind
(T1
) = E_Anonymous_Access_Type
4154 -- Start of processing for Find_Equality_Types
4157 -- If left operand is aggregate, the right operand has to
4158 -- provide a usable type for it.
4160 if Nkind
(L
) = N_Aggregate
4161 and then Nkind
(R
) /= N_Aggregate
4163 Find_Equality_Types
(R
, L
, Op_Id
, N
);
4167 if Nkind
(N
) = N_Function_Call
4168 and then Nkind
(Name
(N
)) = N_Expanded_Name
4170 Scop
:= Entity
(Prefix
(Name
(N
)));
4172 -- The prefix may be a package renaming, and the subsequent test
4173 -- requires the original package.
4175 if Ekind
(Scop
) = E_Package
4176 and then Present
(Renamed_Entity
(Scop
))
4178 Scop
:= Renamed_Entity
(Scop
);
4179 Set_Entity
(Prefix
(Name
(N
)), Scop
);
4183 if not Is_Overloaded
(L
) then
4184 Try_One_Interp
(Etype
(L
));
4187 Get_First_Interp
(L
, Index
, It
);
4188 while Present
(It
.Typ
) loop
4189 Try_One_Interp
(It
.Typ
);
4190 Get_Next_Interp
(Index
, It
);
4193 end Find_Equality_Types
;
4195 -------------------------
4196 -- Find_Negation_Types --
4197 -------------------------
4199 procedure Find_Negation_Types
4204 Index
: Interp_Index
;
4208 if not Is_Overloaded
(R
) then
4209 if Etype
(R
) = Universal_Integer
then
4210 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
4211 elsif Valid_Boolean_Arg
(Etype
(R
)) then
4212 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
4216 Get_First_Interp
(R
, Index
, It
);
4217 while Present
(It
.Typ
) loop
4218 if Valid_Boolean_Arg
(It
.Typ
) then
4219 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
4222 Get_Next_Interp
(Index
, It
);
4225 end Find_Negation_Types
;
4227 ----------------------
4228 -- Find_Unary_Types --
4229 ----------------------
4231 procedure Find_Unary_Types
4236 Index
: Interp_Index
;
4240 if not Is_Overloaded
(R
) then
4241 if Is_Numeric_Type
(Etype
(R
)) then
4242 Add_One_Interp
(N
, Op_Id
, Base_Type
(Etype
(R
)));
4246 Get_First_Interp
(R
, Index
, It
);
4247 while Present
(It
.Typ
) loop
4248 if Is_Numeric_Type
(It
.Typ
) then
4249 Add_One_Interp
(N
, Op_Id
, Base_Type
(It
.Typ
));
4252 Get_Next_Interp
(Index
, It
);
4255 end Find_Unary_Types
;
4261 function Junk_Operand
(N
: Node_Id
) return Boolean is
4265 if Error_Posted
(N
) then
4269 -- Get entity to be tested
4271 if Is_Entity_Name
(N
)
4272 and then Present
(Entity
(N
))
4276 -- An odd case, a procedure name gets converted to a very peculiar
4277 -- function call, and here is where we detect this happening.
4279 elsif Nkind
(N
) = N_Function_Call
4280 and then Is_Entity_Name
(Name
(N
))
4281 and then Present
(Entity
(Name
(N
)))
4285 -- Another odd case, there are at least some cases of selected
4286 -- components where the selected component is not marked as having
4287 -- an entity, even though the selector does have an entity
4289 elsif Nkind
(N
) = N_Selected_Component
4290 and then Present
(Entity
(Selector_Name
(N
)))
4292 Enode
:= Selector_Name
(N
);
4298 -- Now test the entity we got to see if it is a bad case
4300 case Ekind
(Entity
(Enode
)) is
4304 ("package name cannot be used as operand", Enode
);
4306 when Generic_Unit_Kind
=>
4308 ("generic unit name cannot be used as operand", Enode
);
4312 ("subtype name cannot be used as operand", Enode
);
4316 ("entry name cannot be used as operand", Enode
);
4320 ("procedure name cannot be used as operand", Enode
);
4324 ("exception name cannot be used as operand", Enode
);
4326 when E_Block | E_Label | E_Loop
=>
4328 ("label name cannot be used as operand", Enode
);
4338 --------------------
4339 -- Operator_Check --
4340 --------------------
4342 procedure Operator_Check
(N
: Node_Id
) is
4344 Remove_Abstract_Operations
(N
);
4346 -- Test for case of no interpretation found for operator
4348 if Etype
(N
) = Any_Type
then
4354 R
:= Right_Opnd
(N
);
4356 if Nkind
(N
) in N_Binary_Op
then
4362 -- If either operand has no type, then don't complain further,
4363 -- since this simply means that we have a propagated error.
4366 or else Etype
(R
) = Any_Type
4367 or else (Nkind
(N
) in N_Binary_Op
and then Etype
(L
) = Any_Type
)
4371 -- We explicitly check for the case of concatenation of component
4372 -- with component to avoid reporting spurious matching array types
4373 -- that might happen to be lurking in distant packages (such as
4374 -- run-time packages). This also prevents inconsistencies in the
4375 -- messages for certain ACVC B tests, which can vary depending on
4376 -- types declared in run-time interfaces. Another improvement when
4377 -- aggregates are present is to look for a well-typed operand.
4379 elsif Present
(Candidate_Type
)
4380 and then (Nkind
(N
) /= N_Op_Concat
4381 or else Is_Array_Type
(Etype
(L
))
4382 or else Is_Array_Type
(Etype
(R
)))
4385 if Nkind
(N
) = N_Op_Concat
then
4386 if Etype
(L
) /= Any_Composite
4387 and then Is_Array_Type
(Etype
(L
))
4389 Candidate_Type
:= Etype
(L
);
4391 elsif Etype
(R
) /= Any_Composite
4392 and then Is_Array_Type
(Etype
(R
))
4394 Candidate_Type
:= Etype
(R
);
4399 ("operator for} is not directly visible!",
4400 N
, First_Subtype
(Candidate_Type
));
4401 Error_Msg_N
("use clause would make operation legal!", N
);
4404 -- If either operand is a junk operand (e.g. package name), then
4405 -- post appropriate error messages, but do not complain further.
4407 -- Note that the use of OR in this test instead of OR ELSE is
4408 -- quite deliberate, we may as well check both operands in the
4409 -- binary operator case.
4411 elsif Junk_Operand
(R
)
4412 or (Nkind
(N
) in N_Binary_Op
and then Junk_Operand
(L
))
4416 -- If we have a logical operator, one of whose operands is
4417 -- Boolean, then we know that the other operand cannot resolve to
4418 -- Boolean (since we got no interpretations), but in that case we
4419 -- pretty much know that the other operand should be Boolean, so
4420 -- resolve it that way (generating an error)
4422 elsif Nkind
(N
) = N_Op_And
4426 Nkind
(N
) = N_Op_Xor
4428 if Etype
(L
) = Standard_Boolean
then
4429 Resolve
(R
, Standard_Boolean
);
4431 elsif Etype
(R
) = Standard_Boolean
then
4432 Resolve
(L
, Standard_Boolean
);
4436 -- For an arithmetic operator or comparison operator, if one
4437 -- of the operands is numeric, then we know the other operand
4438 -- is not the same numeric type. If it is a non-numeric type,
4439 -- then probably it is intended to match the other operand.
4441 elsif Nkind
(N
) = N_Op_Add
or else
4442 Nkind
(N
) = N_Op_Divide
or else
4443 Nkind
(N
) = N_Op_Ge
or else
4444 Nkind
(N
) = N_Op_Gt
or else
4445 Nkind
(N
) = N_Op_Le
or else
4446 Nkind
(N
) = N_Op_Lt
or else
4447 Nkind
(N
) = N_Op_Mod
or else
4448 Nkind
(N
) = N_Op_Multiply
or else
4449 Nkind
(N
) = N_Op_Rem
or else
4450 Nkind
(N
) = N_Op_Subtract
4452 if Is_Numeric_Type
(Etype
(L
))
4453 and then not Is_Numeric_Type
(Etype
(R
))
4455 Resolve
(R
, Etype
(L
));
4458 elsif Is_Numeric_Type
(Etype
(R
))
4459 and then not Is_Numeric_Type
(Etype
(L
))
4461 Resolve
(L
, Etype
(R
));
4465 -- Comparisons on A'Access are common enough to deserve a
4468 elsif (Nkind
(N
) = N_Op_Eq
or else
4469 Nkind
(N
) = N_Op_Ne
)
4470 and then Ekind
(Etype
(L
)) = E_Access_Attribute_Type
4471 and then Ekind
(Etype
(R
)) = E_Access_Attribute_Type
4474 ("two access attributes cannot be compared directly", N
);
4476 ("\they must be converted to an explicit type for comparison",
4480 -- Another one for C programmers
4482 elsif Nkind
(N
) = N_Op_Concat
4483 and then Valid_Boolean_Arg
(Etype
(L
))
4484 and then Valid_Boolean_Arg
(Etype
(R
))
4486 Error_Msg_N
("invalid operands for concatenation", N
);
4487 Error_Msg_N
("\maybe AND was meant", N
);
4490 -- A special case for comparison of access parameter with null
4492 elsif Nkind
(N
) = N_Op_Eq
4493 and then Is_Entity_Name
(L
)
4494 and then Nkind
(Parent
(Entity
(L
))) = N_Parameter_Specification
4495 and then Nkind
(Parameter_Type
(Parent
(Entity
(L
)))) =
4497 and then Nkind
(R
) = N_Null
4499 Error_Msg_N
("access parameter is not allowed to be null", L
);
4500 Error_Msg_N
("\(call would raise Constraint_Error)", L
);
4504 -- If we fall through then just give general message. Note that in
4505 -- the following messages, if the operand is overloaded we choose
4506 -- an arbitrary type to complain about, but that is probably more
4507 -- useful than not giving a type at all.
4509 if Nkind
(N
) in N_Unary_Op
then
4510 Error_Msg_Node_2
:= Etype
(R
);
4511 Error_Msg_N
("operator& not defined for}", N
);
4515 if Nkind
(N
) in N_Binary_Op
then
4516 if not Is_Overloaded
(L
)
4517 and then not Is_Overloaded
(R
)
4518 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
4520 Error_Msg_Node_2
:= First_Subtype
(Etype
(R
));
4521 Error_Msg_N
("there is no applicable operator& for}", N
);
4524 Error_Msg_N
("invalid operand types for operator&", N
);
4526 if Nkind
(N
) /= N_Op_Concat
then
4527 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
4528 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
4537 -----------------------------------------
4538 -- Process_Implicit_Dereference_Prefix --
4539 -----------------------------------------
4541 procedure Process_Implicit_Dereference_Prefix
4549 and then (Operating_Mode
= Check_Semantics
or else not Expander_Active
)
4551 -- We create a dummy reference to E to ensure that the reference
4552 -- is not considered as part of an assignment (an implicit
4553 -- dereference can never assign to its prefix). The Comes_From_Source
4554 -- attribute needs to be propagated for accurate warnings.
4556 Ref
:= New_Reference_To
(E
, Sloc
(P
));
4557 Set_Comes_From_Source
(Ref
, Comes_From_Source
(P
));
4558 Generate_Reference
(E
, Ref
);
4560 end Process_Implicit_Dereference_Prefix
;
4562 --------------------------------
4563 -- Remove_Abstract_Operations --
4564 --------------------------------
4566 procedure Remove_Abstract_Operations
(N
: Node_Id
) is
4569 Abstract_Op
: Entity_Id
:= Empty
;
4571 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
4572 -- activate this if either extensions are enabled, or if the abstract
4573 -- operation in question comes from a predefined file. This latter test
4574 -- allows us to use abstract to make operations invisible to users. In
4575 -- particular, if type Address is non-private and abstract subprograms
4576 -- are used to hide its operators, they will be truly hidden.
4578 type Operand_Position
is (First_Op
, Second_Op
);
4579 Univ_Type
: constant Entity_Id
:= Universal_Interpretation
(N
);
4581 procedure Remove_Address_Interpretations
(Op
: Operand_Position
);
4582 -- Ambiguities may arise when the operands are literal and the address
4583 -- operations in s-auxdec are visible. In that case, remove the
4584 -- interpretation of a literal as Address, to retain the semantics of
4585 -- Address as a private type.
4587 ------------------------------------
4588 -- Remove_Address_Interpretations --
4589 ------------------------------------
4591 procedure Remove_Address_Interpretations
(Op
: Operand_Position
) is
4595 if Is_Overloaded
(N
) then
4596 Get_First_Interp
(N
, I
, It
);
4597 while Present
(It
.Nam
) loop
4598 Formal
:= First_Entity
(It
.Nam
);
4600 if Op
= Second_Op
then
4601 Formal
:= Next_Entity
(Formal
);
4604 if Is_Descendent_Of_Address
(Etype
(Formal
)) then
4608 Get_Next_Interp
(I
, It
);
4611 end Remove_Address_Interpretations
;
4613 -- Start of processing for Remove_Abstract_Operations
4616 if Is_Overloaded
(N
) then
4617 Get_First_Interp
(N
, I
, It
);
4619 while Present
(It
.Nam
) loop
4620 if not Is_Type
(It
.Nam
)
4621 and then Is_Abstract
(It
.Nam
)
4622 and then not Is_Dispatching_Operation
(It
.Nam
)
4624 Abstract_Op
:= It
.Nam
;
4626 -- In Ada 2005, this operation does not participate in Overload
4627 -- resolution. If the operation is defined in in a predefined
4628 -- unit, it is one of the operations declared abstract in some
4629 -- variants of System, and it must be removed as well.
4631 if Ada_Version
>= Ada_05
4632 or else Is_Predefined_File_Name
4633 (Unit_File_Name
(Get_Source_Unit
(It
.Nam
)))
4634 or else Is_Descendent_Of_Address
(It
.Typ
)
4641 Get_Next_Interp
(I
, It
);
4644 if No
(Abstract_Op
) then
4646 -- If some interpretation yields an integer type, it is still
4647 -- possible that there are address interpretations. Remove them
4648 -- if one operand is a literal, to avoid spurious ambiguities
4649 -- on systems where Address is a visible integer type.
4651 if Is_Overloaded
(N
)
4652 and then Nkind
(N
) in N_Op
4653 and then Is_Integer_Type
(Etype
(N
))
4655 if Nkind
(N
) in N_Binary_Op
then
4656 if Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
4657 Remove_Address_Interpretations
(Second_Op
);
4659 elsif Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
4660 Remove_Address_Interpretations
(First_Op
);
4665 elsif Nkind
(N
) in N_Op
then
4667 -- Remove interpretations that treat literals as addresses. This
4668 -- is never appropriate, even when Address is defined as a visible
4669 -- Integer type. The reason is that we would really prefer Address
4670 -- to behave as a private type, even in this case, which is there
4671 -- only to accomodate oddities of VMS address sizes. If Address is
4672 -- a visible integer type, we get lots of overload ambiguities.
4674 if Nkind
(N
) in N_Binary_Op
then
4676 U1
: constant Boolean :=
4677 Present
(Universal_Interpretation
(Right_Opnd
(N
)));
4678 U2
: constant Boolean :=
4679 Present
(Universal_Interpretation
(Left_Opnd
(N
)));
4683 Remove_Address_Interpretations
(Second_Op
);
4687 Remove_Address_Interpretations
(First_Op
);
4690 if not (U1
and U2
) then
4692 -- Remove corresponding predefined operator, which is
4693 -- always added to the overload set.
4695 Get_First_Interp
(N
, I
, It
);
4696 while Present
(It
.Nam
) loop
4697 if Scope
(It
.Nam
) = Standard_Standard
4698 and then Base_Type
(It
.Typ
) =
4699 Base_Type
(Etype
(Abstract_Op
))
4704 Get_Next_Interp
(I
, It
);
4707 elsif Is_Overloaded
(N
)
4708 and then Present
(Univ_Type
)
4710 -- If both operands have a universal interpretation,
4711 -- it is still necessary to remove interpretations that
4712 -- yield Address. Any remaining ambiguities will be
4713 -- removed in Disambiguate.
4715 Get_First_Interp
(N
, I
, It
);
4716 while Present
(It
.Nam
) loop
4717 if Is_Descendent_Of_Address
(It
.Typ
) then
4720 elsif not Is_Type
(It
.Nam
) then
4721 Set_Entity
(N
, It
.Nam
);
4724 Get_Next_Interp
(I
, It
);
4730 elsif Nkind
(N
) = N_Function_Call
4732 (Nkind
(Name
(N
)) = N_Operator_Symbol
4734 (Nkind
(Name
(N
)) = N_Expanded_Name
4736 Nkind
(Selector_Name
(Name
(N
))) = N_Operator_Symbol
))
4740 Arg1
: constant Node_Id
:= First
(Parameter_Associations
(N
));
4741 U1
: constant Boolean :=
4742 Present
(Universal_Interpretation
(Arg1
));
4743 U2
: constant Boolean :=
4744 Present
(Next
(Arg1
)) and then
4745 Present
(Universal_Interpretation
(Next
(Arg1
)));
4749 Remove_Address_Interpretations
(First_Op
);
4753 Remove_Address_Interpretations
(Second_Op
);
4756 if not (U1
and U2
) then
4757 Get_First_Interp
(N
, I
, It
);
4758 while Present
(It
.Nam
) loop
4759 if Scope
(It
.Nam
) = Standard_Standard
4760 and then It
.Typ
= Base_Type
(Etype
(Abstract_Op
))
4765 Get_Next_Interp
(I
, It
);
4771 -- If the removal has left no valid interpretations, emit
4772 -- error message now and label node as illegal.
4774 if Present
(Abstract_Op
) then
4775 Get_First_Interp
(N
, I
, It
);
4779 -- Removal of abstract operation left no viable candidate
4781 Set_Etype
(N
, Any_Type
);
4782 Error_Msg_Sloc
:= Sloc
(Abstract_Op
);
4784 ("cannot call abstract operation& declared#", N
, Abstract_Op
);
4788 end Remove_Abstract_Operations
;
4790 -----------------------
4791 -- Try_Indirect_Call --
4792 -----------------------
4794 function Try_Indirect_Call
4797 Typ
: Entity_Id
) return Boolean
4804 Normalize_Actuals
(N
, Designated_Type
(Typ
), False, Call_OK
);
4806 Actual
:= First_Actual
(N
);
4807 Formal
:= First_Formal
(Designated_Type
(Typ
));
4808 while Present
(Actual
) and then Present
(Formal
) loop
4809 if not Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
4814 Next_Formal
(Formal
);
4817 if No
(Actual
) and then No
(Formal
) then
4818 Add_One_Interp
(N
, Nam
, Etype
(Designated_Type
(Typ
)));
4820 -- Nam is a candidate interpretation for the name in the call,
4821 -- if it is not an indirect call.
4823 if not Is_Type
(Nam
)
4824 and then Is_Entity_Name
(Name
(N
))
4826 Set_Entity
(Name
(N
), Nam
);
4833 end Try_Indirect_Call
;
4835 ----------------------
4836 -- Try_Indexed_Call --
4837 ----------------------
4839 function Try_Indexed_Call
4842 Typ
: Entity_Id
) return Boolean
4844 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
4849 Actual
:= First
(Actuals
);
4850 Index
:= First_Index
(Typ
);
4851 while Present
(Actual
) and then Present
(Index
) loop
4853 -- If the parameter list has a named association, the expression
4854 -- is definitely a call and not an indexed component.
4856 if Nkind
(Actual
) = N_Parameter_Association
then
4860 if not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
4868 if No
(Actual
) and then No
(Index
) then
4869 Add_One_Interp
(N
, Nam
, Component_Type
(Typ
));
4871 -- Nam is a candidate interpretation for the name in the call,
4872 -- if it is not an indirect call.
4874 if not Is_Type
(Nam
)
4875 and then Is_Entity_Name
(Name
(N
))
4877 Set_Entity
(Name
(N
), Nam
);
4884 end Try_Indexed_Call
;
4886 --------------------------
4887 -- Try_Object_Operation --
4888 --------------------------
4890 function Try_Object_Operation
(N
: Node_Id
) return Boolean is
4891 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
4892 Loc
: constant Source_Ptr
:= Sloc
(N
);
4893 Is_Subprg_Call
: constant Boolean := K
= N_Procedure_Call_Statement
4894 or else K
= N_Function_Call
;
4895 Obj
: constant Node_Id
:= Prefix
(N
);
4896 Subprog
: constant Node_Id
:= Selector_Name
(N
);
4899 New_Call_Node
: Node_Id
:= Empty
;
4900 Node_To_Replace
: Node_Id
;
4901 Obj_Type
: Entity_Id
:= Etype
(Obj
);
4903 procedure Complete_Object_Operation
4904 (Call_Node
: Node_Id
;
4905 Node_To_Replace
: Node_Id
;
4907 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
4908 -- Call_Node, insert the object (or its dereference) as the first actual
4909 -- in the call, and complete the analysis of the call.
4911 procedure Transform_Object_Operation
4912 (Call_Node
: out Node_Id
;
4913 Node_To_Replace
: out Node_Id
;
4915 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
4916 -- Call_Node is the resulting subprogram call,
4917 -- Node_To_Replace is either N or the parent of N, and Subprog
4918 -- is a reference to the subprogram we are trying to match.
4920 function Try_Class_Wide_Operation
4921 (Call_Node
: Node_Id
;
4922 Node_To_Replace
: Node_Id
) return Boolean;
4923 -- Traverse all ancestor types looking for a class-wide subprogram
4924 -- for which the current operation is a valid non-dispatching call.
4926 function Try_Primitive_Operation
4927 (Call_Node
: Node_Id
;
4928 Node_To_Replace
: Node_Id
) return Boolean;
4929 -- Traverse the list of primitive subprograms looking for a dispatching
4930 -- operation for which the current node is a valid call .
4932 -------------------------------
4933 -- Complete_Object_Operation --
4934 -------------------------------
4936 procedure Complete_Object_Operation
4937 (Call_Node
: Node_Id
;
4938 Node_To_Replace
: Node_Id
;
4941 Formal_Type
: constant Entity_Id
:=
4942 Etype
(First_Formal
(Entity
(Subprog
)));
4943 First_Actual
: Node_Id
;
4946 First_Actual
:= First
(Parameter_Associations
(Call_Node
));
4947 Set_Name
(Call_Node
, Subprog
);
4949 if Nkind
(N
) = N_Selected_Component
4950 and then not Inside_A_Generic
4952 Set_Entity
(Selector_Name
(N
), Entity
(Subprog
));
4955 -- If need be, rewrite first actual as an explicit dereference
4957 if not Is_Access_Type
(Formal_Type
)
4958 and then Is_Access_Type
(Etype
(Obj
))
4960 Rewrite
(First_Actual
,
4961 Make_Explicit_Dereference
(Sloc
(Obj
), Obj
));
4962 Analyze
(First_Actual
);
4964 -- Conversely, if the formal is an access parameter and the
4965 -- object is not, replace the actual with a 'Access reference.
4966 -- Its analysis will check that the object is aliased.
4968 elsif Is_Access_Type
(Formal_Type
)
4969 and then not Is_Access_Type
(Etype
(Obj
))
4971 Rewrite
(First_Actual
,
4972 Make_Attribute_Reference
(Loc
,
4973 Attribute_Name
=> Name_Access
,
4974 Prefix
=> Relocate_Node
(Obj
)));
4975 Analyze
(First_Actual
);
4978 Rewrite
(First_Actual
, Obj
);
4981 Rewrite
(Node_To_Replace
, Call_Node
);
4982 Analyze
(Node_To_Replace
);
4983 end Complete_Object_Operation
;
4985 --------------------------------
4986 -- Transform_Object_Operation --
4987 --------------------------------
4989 procedure Transform_Object_Operation
4990 (Call_Node
: out Node_Id
;
4991 Node_To_Replace
: out Node_Id
;
4994 Parent_Node
: constant Node_Id
:= Parent
(N
);
4996 Dummy
: constant Node_Id
:= New_Copy
(Obj
);
4997 -- Placeholder used as a first parameter in the call, replaced
4998 -- eventually by the proper object.
5004 -- Common case covering 1) Call to a procedure and 2) Call to a
5005 -- function that has some additional actuals.
5007 if (Nkind
(Parent_Node
) = N_Function_Call
5009 Nkind
(Parent_Node
) = N_Procedure_Call_Statement
)
5011 -- N is a selected component node containing the name of the
5012 -- subprogram. If N is not the name of the parent node we must
5013 -- not replace the parent node by the new construct. This case
5014 -- occurs when N is a parameterless call to a subprogram that
5015 -- is an actual parameter of a call to another subprogram. For
5017 -- Some_Subprogram (..., Obj.Operation, ...)
5019 and then Name
(Parent_Node
) = N
5021 Node_To_Replace
:= Parent_Node
;
5023 Actuals
:= Parameter_Associations
(Parent_Node
);
5025 if Present
(Actuals
) then
5026 Prepend
(Dummy
, Actuals
);
5028 Actuals
:= New_List
(Dummy
);
5031 if Nkind
(Parent_Node
) = N_Procedure_Call_Statement
then
5033 Make_Procedure_Call_Statement
(Loc
,
5034 Name
=> New_Copy_Tree
(Subprog
),
5035 Parameter_Associations
=> Actuals
);
5039 Make_Function_Call
(Loc
,
5040 Name
=> New_Copy_Tree
(Subprog
),
5041 Parameter_Associations
=> Actuals
);
5045 -- Before analysis, the function call appears as an indexed component
5046 -- if there are no named associations.
5048 elsif Nkind
(Parent_Node
) = N_Indexed_Component
5049 and then N
= Prefix
(Parent_Node
)
5051 Node_To_Replace
:= Parent_Node
;
5053 Actuals
:= Expressions
(Parent_Node
);
5055 Actual
:= First
(Actuals
);
5056 while Present
(Actual
) loop
5061 Prepend
(Dummy
, Actuals
);
5064 Make_Function_Call
(Loc
,
5065 Name
=> New_Copy_Tree
(Subprog
),
5066 Parameter_Associations
=> Actuals
);
5068 -- Parameterless call: Obj.F is rewritten as F (Obj)
5071 Node_To_Replace
:= N
;
5074 Make_Function_Call
(Loc
,
5075 Name
=> New_Copy_Tree
(Subprog
),
5076 Parameter_Associations
=> New_List
(Dummy
));
5078 end Transform_Object_Operation
;
5080 ------------------------------
5081 -- Try_Class_Wide_Operation --
5082 ------------------------------
5084 function Try_Class_Wide_Operation
5085 (Call_Node
: Node_Id
;
5086 Node_To_Replace
: Node_Id
) return Boolean
5088 Anc_Type
: Entity_Id
;
5094 -- Loop through ancestor types, traverse the homonym chain of the
5095 -- subprogram, and try out those homonyms whose first formal has the
5096 -- class-wide type of the ancestor.
5098 -- Should we verify that it is declared in the same package as the
5099 -- ancestor type ???
5101 Anc_Type
:= Obj_Type
;
5104 Hom
:= Current_Entity
(Subprog
);
5105 while Present
(Hom
) loop
5106 if (Ekind
(Hom
) = E_Procedure
5108 Ekind
(Hom
) = E_Function
)
5109 and then Present
(First_Formal
(Hom
))
5110 and then Etype
(First_Formal
(Hom
)) =
5111 Class_Wide_Type
(Anc_Type
)
5113 Hom_Ref
:= New_Reference_To
(Hom
, Sloc
(Subprog
));
5115 Set_Etype
(Call_Node
, Any_Type
);
5116 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
5118 Set_Name
(Call_Node
, Hom_Ref
);
5125 Skip_First
=> True);
5129 -- Reformat into the proper call
5131 Complete_Object_Operation
5132 (Call_Node
=> Call_Node
,
5133 Node_To_Replace
=> Node_To_Replace
,
5134 Subprog
=> Hom_Ref
);
5140 Hom
:= Homonym
(Hom
);
5143 -- Examine other ancestor types
5145 exit when Etype
(Anc_Type
) = Anc_Type
;
5146 Anc_Type
:= Etype
(Anc_Type
);
5152 end Try_Class_Wide_Operation
;
5154 -----------------------------
5155 -- Try_Primitive_Operation --
5156 -----------------------------
5158 function Try_Primitive_Operation
5159 (Call_Node
: Node_Id
;
5160 Node_To_Replace
: Node_Id
) return Boolean
5163 Prim_Op
: Entity_Id
;
5164 Prim_Op_Ref
: Node_Id
:= Empty
;
5165 Success
: Boolean := False;
5166 Op_Exists
: Boolean := False;
5168 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean;
5169 -- Verify that the prefix, dereferenced if need be, is a valid
5170 -- controlling argument in a call to Op. The remaining actuals
5171 -- are checked in the subsequent call to Analyze_One_Call.
5173 -----------------------------
5174 -- Valid_First_Argument_Of --
5175 -----------------------------
5177 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean is
5178 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Op
));
5183 return Base_Type
(Obj_Type
) = Typ
5185 -- Prefix can be dereferenced
5188 (Is_Access_Type
(Obj_Type
)
5189 and then Designated_Type
(Obj_Type
) = Typ
)
5191 -- Formal is an access parameter, for which the object
5192 -- can provide an access.
5195 (Ekind
(Typ
) = E_Anonymous_Access_Type
5196 and then Designated_Type
(Typ
) = Obj_Type
);
5197 end Valid_First_Argument_Of
;
5199 -- Start of processing for Try_Primitive_Operation
5202 -- Look for subprograms in the list of primitive operations
5203 -- The name must be identical, and the kind of call indicates
5204 -- the expected kind of operation (function or procedure).
5206 Elmt
:= First_Elmt
(Primitive_Operations
(Obj_Type
));
5207 while Present
(Elmt
) loop
5208 Prim_Op
:= Node
(Elmt
);
5210 if Chars
(Prim_Op
) = Chars
(Subprog
)
5211 and then Present
(First_Formal
(Prim_Op
))
5212 and then Valid_First_Argument_Of
(Prim_Op
)
5214 (Nkind
(Call_Node
) = N_Function_Call
)
5215 = (Ekind
(Prim_Op
) = E_Function
)
5217 -- If this primitive operation corresponds with an immediate
5218 -- ancestor interface there is no need to add it to the list
5219 -- of interpretations; the corresponding aliased primitive is
5220 -- also in this list of primitive operations and will be
5223 if Present
(Abstract_Interface_Alias
(Prim_Op
))
5224 and then Present
(DTC_Entity
(Alias
(Prim_Op
)))
5225 and then Etype
(DTC_Entity
(Alias
(Prim_Op
))) = RTE
(RE_Tag
)
5231 Prim_Op_Ref
:= New_Reference_To
(Prim_Op
, Sloc
(Subprog
));
5233 Set_Etype
(Call_Node
, Any_Type
);
5234 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
5236 Set_Name
(Call_Node
, Prim_Op_Ref
);
5243 Skip_First
=> True);
5248 -- If the operation is a procedure call, there can only
5249 -- be one candidate and we found it. If it is a function
5250 -- we must collect all interpretations, because there
5251 -- may be several primitive operations that differ only
5252 -- in the return type.
5254 if Nkind
(Call_Node
) = N_Procedure_Call_Statement
then
5259 elsif Ekind
(Prim_Op
) = E_Function
then
5261 -- Collect remaining function interpretations, to be
5262 -- resolved from context.
5264 Add_One_Interp
(Prim_Op_Ref
, Prim_Op
, Etype
(Prim_Op
));
5273 Complete_Object_Operation
5274 (Call_Node
=> Call_Node
,
5275 Node_To_Replace
=> Node_To_Replace
,
5276 Subprog
=> Prim_Op_Ref
);
5280 end Try_Primitive_Operation
;
5282 -- Start of processing for Try_Object_Operation
5285 if Is_Access_Type
(Obj_Type
) then
5286 Obj_Type
:= Designated_Type
(Obj_Type
);
5289 if Ekind
(Obj_Type
) = E_Private_Subtype
then
5290 Obj_Type
:= Base_Type
(Obj_Type
);
5293 if Is_Class_Wide_Type
(Obj_Type
) then
5294 Obj_Type
:= Etype
(Class_Wide_Type
(Obj_Type
));
5297 -- The type may have be obtained through a limited_with clause,
5298 -- in which case the primitive operations are available on its
5299 -- non-limited view.
5301 if Ekind
(Obj_Type
) = E_Incomplete_Type
5302 and then From_With_Type
(Obj_Type
)
5304 Obj_Type
:= Non_Limited_View
(Obj_Type
);
5307 if not Is_Tagged_Type
(Obj_Type
) then
5311 -- Analyze the actuals if node is know to be a subprogram call
5313 if Is_Subprg_Call
and then N
= Name
(Parent
(N
)) then
5314 Actual
:= First
(Parameter_Associations
(Parent
(N
)));
5315 while Present
(Actual
) loop
5316 Analyze_Expression
(Actual
);
5321 Analyze_Expression
(Obj
);
5323 -- Build a subprogram call node, using a copy of Obj as its first
5324 -- actual. This is a placeholder, to be replaced by an explicit
5325 -- dereference when needed.
5327 Transform_Object_Operation
5328 (Call_Node
=> New_Call_Node
,
5329 Node_To_Replace
=> Node_To_Replace
,
5330 Subprog
=> Subprog
);
5332 Set_Etype
(New_Call_Node
, Any_Type
);
5333 Set_Parent
(New_Call_Node
, Parent
(Node_To_Replace
));
5336 Try_Primitive_Operation
5337 (Call_Node
=> New_Call_Node
,
5338 Node_To_Replace
=> Node_To_Replace
)
5341 Try_Class_Wide_Operation
5342 (Call_Node
=> New_Call_Node
,
5343 Node_To_Replace
=> Node_To_Replace
);
5344 end Try_Object_Operation
;