1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Debug
; use Debug
;
28 with Einfo
; use Einfo
;
29 with Elists
; use Elists
;
30 with Errout
; use Errout
;
31 with Exp_Util
; use Exp_Util
;
32 with Fname
; use Fname
;
33 with Itypes
; use Itypes
;
35 with Lib
.Xref
; use Lib
.Xref
;
36 with Namet
; use Namet
;
37 with Namet
.Sp
; use Namet
.Sp
;
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
;
45 with Sem_Aux
; use Sem_Aux
;
46 with Sem_Case
; use Sem_Case
;
47 with Sem_Cat
; use Sem_Cat
;
48 with Sem_Ch3
; use Sem_Ch3
;
49 with Sem_Ch6
; use Sem_Ch6
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Disp
; use Sem_Disp
;
52 with Sem_Dist
; use Sem_Dist
;
53 with Sem_Eval
; use Sem_Eval
;
54 with Sem_Res
; use Sem_Res
;
55 with Sem_Type
; use Sem_Type
;
56 with Sem_Util
; use Sem_Util
;
57 with Sem_Warn
; use Sem_Warn
;
58 with Stand
; use Stand
;
59 with Sinfo
; use Sinfo
;
60 with Snames
; use Snames
;
61 with Tbuild
; use Tbuild
;
63 package body Sem_Ch4
is
65 -----------------------
66 -- Local Subprograms --
67 -----------------------
69 procedure Analyze_Concatenation_Rest
(N
: Node_Id
);
70 -- Does the "rest" of the work of Analyze_Concatenation, after the left
71 -- operand has been analyzed. See Analyze_Concatenation for details.
73 procedure Analyze_Expression
(N
: Node_Id
);
74 -- For expressions that are not names, this is just a call to analyze.
75 -- If the expression is a name, it may be a call to a parameterless
76 -- function, and if so must be converted into an explicit call node
77 -- and analyzed as such. This deproceduring must be done during the first
78 -- pass of overload resolution, because otherwise a procedure call with
79 -- overloaded actuals may fail to resolve.
81 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
);
82 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
83 -- is an operator name or an expanded name whose selector is an operator
84 -- name, and one possible interpretation is as a predefined operator.
86 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
);
87 -- If the prefix of a selected_component is overloaded, the proper
88 -- interpretation that yields a record type with the proper selector
89 -- name must be selected.
91 procedure Analyze_User_Defined_Binary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
92 -- Procedure to analyze a user defined binary operator, which is resolved
93 -- like a function, but instead of a list of actuals it is presented
94 -- with the left and right operands of an operator node.
96 procedure Analyze_User_Defined_Unary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
97 -- Procedure to analyze a user defined unary operator, which is resolved
98 -- like a function, but instead of a list of actuals, it is presented with
99 -- the operand of the operator node.
101 procedure Ambiguous_Operands
(N
: Node_Id
);
102 -- for equality, membership, and comparison operators with overloaded
103 -- arguments, list possible interpretations.
105 procedure Analyze_One_Call
109 Success
: out Boolean;
110 Skip_First
: Boolean := False);
111 -- Check one interpretation of an overloaded subprogram name for
112 -- compatibility with the types of the actuals in a call. If there is a
113 -- single interpretation which does not match, post error if Report is
116 -- Nam is the entity that provides the formals against which the actuals
117 -- are checked. Nam is either the name of a subprogram, or the internal
118 -- subprogram type constructed for an access_to_subprogram. If the actuals
119 -- are compatible with Nam, then Nam is added to the list of candidate
120 -- interpretations for N, and Success is set to True.
122 -- The flag Skip_First is used when analyzing a call that was rewritten
123 -- from object notation. In this case the first actual may have to receive
124 -- an explicit dereference, depending on the first formal of the operation
125 -- being called. The caller will have verified that the object is legal
126 -- for the call. If the remaining parameters match, the first parameter
127 -- will rewritten as a dereference if needed, prior to completing analysis.
129 procedure Check_Misspelled_Selector
132 -- Give possible misspelling diagnostic if Sel is likely to be a mis-
133 -- spelling of one of the selectors of the Prefix. This is called by
134 -- Analyze_Selected_Component after producing an invalid selector error
137 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean;
138 -- Verify that type T is declared in scope S. Used to find interpretations
139 -- for operators given by expanded names. This is abstracted as a separate
140 -- function to handle extensions to System, where S is System, but T is
141 -- declared in the extension.
143 procedure Find_Arithmetic_Types
147 -- L and R are the operands of an arithmetic operator. Find
148 -- consistent pairs of interpretations for L and R that have a
149 -- numeric type consistent with the semantics of the operator.
151 procedure Find_Comparison_Types
155 -- L and R are operands of a comparison operator. Find consistent
156 -- pairs of interpretations for L and R.
158 procedure Find_Concatenation_Types
162 -- For the four varieties of concatenation
164 procedure Find_Equality_Types
168 -- Ditto for equality operators
170 procedure Find_Boolean_Types
174 -- Ditto for binary logical operations
176 procedure Find_Negation_Types
180 -- Find consistent interpretation for operand of negation operator
182 procedure Find_Non_Universal_Interpretations
187 -- For equality and comparison operators, the result is always boolean,
188 -- and the legality of the operation is determined from the visibility
189 -- of the operand types. If one of the operands has a universal interpre-
190 -- tation, the legality check uses some compatible non-universal
191 -- interpretation of the other operand. N can be an operator node, or
192 -- a function call whose name is an operator designator.
194 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean;
195 -- Find candidate interpretations for the name Obj.Proc when it appears
196 -- in a subprogram renaming declaration.
198 procedure Find_Unary_Types
202 -- Unary arithmetic types: plus, minus, abs
204 procedure Check_Arithmetic_Pair
208 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
209 -- types for left and right operand. Determine whether they constitute
210 -- a valid pair for the given operator, and record the corresponding
211 -- interpretation of the operator node. The node N may be an operator
212 -- node (the usual case) or a function call whose prefix is an operator
213 -- designator. In both cases Op_Id is the operator name itself.
215 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
);
216 -- Give detailed information on overloaded call where none of the
217 -- interpretations match. N is the call node, Nam the designator for
218 -- the overloaded entity being called.
220 function Junk_Operand
(N
: Node_Id
) return Boolean;
221 -- Test for an operand that is an inappropriate entity (e.g. a package
222 -- name or a label). If so, issue an error message and return True. If
223 -- the operand is not an inappropriate entity kind, return False.
225 procedure Operator_Check
(N
: Node_Id
);
226 -- Verify that an operator has received some valid interpretation. If none
227 -- was found, determine whether a use clause would make the operation
228 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
229 -- every type compatible with the operator, even if the operator for the
230 -- type is not directly visible. The routine uses this type to emit a more
231 -- informative message.
233 function Process_Implicit_Dereference_Prefix
235 P
: Node_Id
) return Entity_Id
;
236 -- Called when P is the prefix of an implicit dereference, denoting an
237 -- object E. The function returns the designated type of the prefix, taking
238 -- into account that the designated type of an anonymous access type may be
239 -- a limited view, when the non-limited view is visible.
240 -- If in semantics only mode (-gnatc or generic), the function also records
241 -- that the prefix is a reference to E, if any. Normally, such a reference
242 -- is generated only when the implicit dereference is expanded into an
243 -- explicit one, but for consistency we must generate the reference when
244 -- expansion is disabled as well.
246 procedure Remove_Abstract_Operations
(N
: Node_Id
);
247 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
248 -- operation is not a candidate interpretation.
250 function Try_Indexed_Call
254 Skip_First
: Boolean) return Boolean;
255 -- If a function has defaults for all its actuals, a call to it may in fact
256 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
257 -- interpretation as an indexing, prior to analysis as a call. If both are
258 -- possible, the node is overloaded with both interpretations (same symbol
259 -- but two different types). If the call is written in prefix form, the
260 -- prefix becomes the first parameter in the call, and only the remaining
261 -- actuals must be checked for the presence of defaults.
263 function Try_Indirect_Call
266 Typ
: Entity_Id
) return Boolean;
267 -- Similarly, a function F that needs no actuals can return an access to a
268 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
269 -- the call may be overloaded with both interpretations.
271 function Try_Object_Operation
(N
: Node_Id
) return Boolean;
272 -- Ada 2005 (AI-252): Support the object.operation notation. If node N
273 -- is a call in this notation, it is transformed into a normal subprogram
274 -- call where the prefix is a parameter, and True is returned. If node
275 -- N is not of this form, it is unchanged, and False is returned.
277 procedure wpo
(T
: Entity_Id
);
278 pragma Warnings
(Off
, wpo
);
279 -- Used for debugging: obtain list of primitive operations even if
280 -- type is not frozen and dispatch table is not built yet.
282 ------------------------
283 -- Ambiguous_Operands --
284 ------------------------
286 procedure Ambiguous_Operands
(N
: Node_Id
) is
287 procedure List_Operand_Interps
(Opnd
: Node_Id
);
289 --------------------------
290 -- List_Operand_Interps --
291 --------------------------
293 procedure List_Operand_Interps
(Opnd
: Node_Id
) is
298 if Is_Overloaded
(Opnd
) then
299 if Nkind
(Opnd
) in N_Op
then
301 elsif Nkind
(Opnd
) = N_Function_Call
then
311 if Opnd
= Left_Opnd
(N
) then
312 Error_Msg_N
("\left operand has the following interpretations", N
);
315 ("\right operand has the following interpretations", N
);
319 List_Interps
(Nam
, Err
);
320 end List_Operand_Interps
;
322 -- Start of processing for Ambiguous_Operands
325 if Nkind
(N
) in N_Membership_Test
then
326 Error_Msg_N
("ambiguous operands for membership", N
);
328 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
) then
329 Error_Msg_N
("ambiguous operands for equality", N
);
332 Error_Msg_N
("ambiguous operands for comparison", N
);
335 if All_Errors_Mode
then
336 List_Operand_Interps
(Left_Opnd
(N
));
337 List_Operand_Interps
(Right_Opnd
(N
));
339 Error_Msg_N
("\use -gnatf switch for details", N
);
341 end Ambiguous_Operands
;
343 -----------------------
344 -- Analyze_Aggregate --
345 -----------------------
347 -- Most of the analysis of Aggregates requires that the type be known,
348 -- and is therefore put off until resolution.
350 procedure Analyze_Aggregate
(N
: Node_Id
) is
352 if No
(Etype
(N
)) then
353 Set_Etype
(N
, Any_Composite
);
355 end Analyze_Aggregate
;
357 -----------------------
358 -- Analyze_Allocator --
359 -----------------------
361 procedure Analyze_Allocator
(N
: Node_Id
) is
362 Loc
: constant Source_Ptr
:= Sloc
(N
);
363 Sav_Errs
: constant Nat
:= Serious_Errors_Detected
;
364 E
: Node_Id
:= Expression
(N
);
365 Acc_Type
: Entity_Id
;
369 -- In accordance with H.4(7), the No_Allocators restriction only applies
370 -- to user-written allocators.
372 if Comes_From_Source
(N
) then
373 Check_Restriction
(No_Allocators
, N
);
376 if Nkind
(E
) = N_Qualified_Expression
then
377 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
378 Set_Etype
(Acc_Type
, Acc_Type
);
379 Find_Type
(Subtype_Mark
(E
));
381 -- Analyze the qualified expression, and apply the name resolution
382 -- rule given in 4.7 (3).
385 Type_Id
:= Etype
(E
);
386 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
388 Resolve
(Expression
(E
), Type_Id
);
390 if Is_Limited_Type
(Type_Id
)
391 and then Comes_From_Source
(N
)
392 and then not In_Instance_Body
394 if not OK_For_Limited_Init
(Type_Id
, Expression
(E
)) then
395 Error_Msg_N
("initialization not allowed for limited types", N
);
396 Explain_Limited_Type
(Type_Id
, N
);
400 -- A qualified expression requires an exact match of the type,
401 -- class-wide matching is not allowed.
403 -- if Is_Class_Wide_Type (Type_Id)
404 -- and then Base_Type
405 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
407 -- Wrong_Type (Expression (E), Type_Id);
410 Check_Non_Static_Context
(Expression
(E
));
412 -- We don't analyze the qualified expression itself because it's
413 -- part of the allocator
415 Set_Etype
(E
, Type_Id
);
417 -- Case where allocator has a subtype indication
422 Base_Typ
: Entity_Id
;
425 -- If the allocator includes a N_Subtype_Indication then a
426 -- constraint is present, otherwise the node is a subtype mark.
427 -- Introduce an explicit subtype declaration into the tree
428 -- defining some anonymous subtype and rewrite the allocator to
429 -- use this subtype rather than the subtype indication.
431 -- It is important to introduce the explicit subtype declaration
432 -- so that the bounds of the subtype indication are attached to
433 -- the tree in case the allocator is inside a generic unit.
435 if Nkind
(E
) = N_Subtype_Indication
then
437 -- A constraint is only allowed for a composite type in Ada
438 -- 95. In Ada 83, a constraint is also allowed for an
439 -- access-to-composite type, but the constraint is ignored.
441 Find_Type
(Subtype_Mark
(E
));
442 Base_Typ
:= Entity
(Subtype_Mark
(E
));
444 if Is_Elementary_Type
(Base_Typ
) then
445 if not (Ada_Version
= Ada_83
446 and then Is_Access_Type
(Base_Typ
))
448 Error_Msg_N
("constraint not allowed here", E
);
450 if Nkind
(Constraint
(E
)) =
451 N_Index_Or_Discriminant_Constraint
453 Error_Msg_N
-- CODEFIX
454 ("\if qualified expression was meant, " &
455 "use apostrophe", Constraint
(E
));
459 -- Get rid of the bogus constraint:
461 Rewrite
(E
, New_Copy_Tree
(Subtype_Mark
(E
)));
462 Analyze_Allocator
(N
);
465 -- Ada 2005, AI-363: if the designated type has a constrained
466 -- partial view, it cannot receive a discriminant constraint,
467 -- and the allocated object is unconstrained.
469 elsif Ada_Version
>= Ada_05
470 and then Has_Constrained_Partial_View
(Base_Typ
)
473 ("constraint no allowed when type " &
474 "has a constrained partial view", Constraint
(E
));
477 if Expander_Active
then
478 Def_Id
:= Make_Temporary
(Loc
, 'S');
481 Make_Subtype_Declaration
(Loc
,
482 Defining_Identifier
=> Def_Id
,
483 Subtype_Indication
=> Relocate_Node
(E
)));
485 if Sav_Errs
/= Serious_Errors_Detected
486 and then Nkind
(Constraint
(E
)) =
487 N_Index_Or_Discriminant_Constraint
489 Error_Msg_N
-- CODEFIX
490 ("if qualified expression was meant, " &
491 "use apostrophe!", Constraint
(E
));
494 E
:= New_Occurrence_Of
(Def_Id
, Loc
);
495 Rewrite
(Expression
(N
), E
);
499 Type_Id
:= Process_Subtype
(E
, N
);
500 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
501 Set_Etype
(Acc_Type
, Acc_Type
);
502 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
503 Check_Fully_Declared
(Type_Id
, N
);
505 -- Ada 2005 (AI-231): If the designated type is itself an access
506 -- type that excludes null, its default initialization will
507 -- be a null object, and we can insert an unconditional raise
508 -- before the allocator.
510 if Can_Never_Be_Null
(Type_Id
) then
512 Not_Null_Check
: constant Node_Id
:=
513 Make_Raise_Constraint_Error
(Sloc
(E
),
514 Reason
=> CE_Null_Not_Allowed
);
516 if Expander_Active
then
517 Insert_Action
(N
, Not_Null_Check
);
518 Analyze
(Not_Null_Check
);
520 Error_Msg_N
("null value not allowed here?", E
);
525 -- Check restriction against dynamically allocated protected
526 -- objects. Note that when limited aggregates are supported,
527 -- a similar test should be applied to an allocator with a
528 -- qualified expression ???
530 if Is_Protected_Type
(Type_Id
) then
531 Check_Restriction
(No_Protected_Type_Allocators
, N
);
534 -- Check for missing initialization. Skip this check if we already
535 -- had errors on analyzing the allocator, since in that case these
536 -- are probably cascaded errors.
538 if Is_Indefinite_Subtype
(Type_Id
)
539 and then Serious_Errors_Detected
= Sav_Errs
541 if Is_Class_Wide_Type
(Type_Id
) then
543 ("initialization required in class-wide allocation", N
);
545 if Ada_Version
< Ada_05
546 and then Is_Limited_Type
(Type_Id
)
548 Error_Msg_N
("unconstrained allocation not allowed", N
);
550 if Is_Array_Type
(Type_Id
) then
552 ("\constraint with array bounds required", N
);
554 elsif Has_Unknown_Discriminants
(Type_Id
) then
557 else pragma Assert
(Has_Discriminants
(Type_Id
));
559 ("\constraint with discriminant values required", N
);
562 -- Limited Ada 2005 and general non-limited case
566 ("uninitialized unconstrained allocation not allowed",
569 if Is_Array_Type
(Type_Id
) then
571 ("\qualified expression or constraint with " &
572 "array bounds required", N
);
574 elsif Has_Unknown_Discriminants
(Type_Id
) then
575 Error_Msg_N
("\qualified expression required", N
);
577 else pragma Assert
(Has_Discriminants
(Type_Id
));
579 ("\qualified expression or constraint with " &
580 "discriminant values required", N
);
588 if Is_Abstract_Type
(Type_Id
) then
589 Error_Msg_N
("cannot allocate abstract object", E
);
592 if Has_Task
(Designated_Type
(Acc_Type
)) then
593 Check_Restriction
(No_Tasking
, N
);
594 Check_Restriction
(Max_Tasks
, N
);
595 Check_Restriction
(No_Task_Allocators
, N
);
597 -- Check that an allocator with task parts isn't for a nested access
598 -- type when restriction No_Task_Hierarchy applies.
600 if not Is_Library_Level_Entity
(Acc_Type
) then
601 Check_Restriction
(No_Task_Hierarchy
, N
);
605 -- Check that an allocator of a nested access type doesn't create a
606 -- protected object when restriction No_Local_Protected_Objects applies.
607 -- We don't have an equivalent to Has_Task for protected types, so only
608 -- cases where the designated type itself is a protected type are
609 -- currently checked. ???
611 if Is_Protected_Type
(Designated_Type
(Acc_Type
))
612 and then not Is_Library_Level_Entity
(Acc_Type
)
614 Check_Restriction
(No_Local_Protected_Objects
, N
);
617 -- If the No_Streams restriction is set, check that the type of the
618 -- object is not, and does not contain, any subtype derived from
619 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
620 -- Has_Stream just for efficiency reasons. There is no point in
621 -- spending time on a Has_Stream check if the restriction is not set.
623 if Restriction_Check_Required
(No_Streams
) then
624 if Has_Stream
(Designated_Type
(Acc_Type
)) then
625 Check_Restriction
(No_Streams
, N
);
629 Set_Etype
(N
, Acc_Type
);
631 if not Is_Library_Level_Entity
(Acc_Type
) then
632 Check_Restriction
(No_Local_Allocators
, N
);
635 if Serious_Errors_Detected
> Sav_Errs
then
636 Set_Error_Posted
(N
);
637 Set_Etype
(N
, Any_Type
);
639 end Analyze_Allocator
;
641 ---------------------------
642 -- Analyze_Arithmetic_Op --
643 ---------------------------
645 procedure Analyze_Arithmetic_Op
(N
: Node_Id
) is
646 L
: constant Node_Id
:= Left_Opnd
(N
);
647 R
: constant Node_Id
:= Right_Opnd
(N
);
651 Candidate_Type
:= Empty
;
652 Analyze_Expression
(L
);
653 Analyze_Expression
(R
);
655 -- If the entity is already set, the node is the instantiation of a
656 -- generic node with a non-local reference, or was manufactured by a
657 -- call to Make_Op_xxx. In either case the entity is known to be valid,
658 -- and we do not need to collect interpretations, instead we just get
659 -- the single possible interpretation.
663 if Present
(Op_Id
) then
664 if Ekind
(Op_Id
) = E_Operator
then
666 if Nkind_In
(N
, N_Op_Divide
, N_Op_Mod
, N_Op_Multiply
, N_Op_Rem
)
667 and then Treat_Fixed_As_Integer
(N
)
671 Set_Etype
(N
, Any_Type
);
672 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
676 Set_Etype
(N
, Any_Type
);
677 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
680 -- Entity is not already set, so we do need to collect interpretations
683 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
684 Set_Etype
(N
, Any_Type
);
686 while Present
(Op_Id
) loop
687 if Ekind
(Op_Id
) = E_Operator
688 and then Present
(Next_Entity
(First_Entity
(Op_Id
)))
690 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
692 -- The following may seem superfluous, because an operator cannot
693 -- be generic, but this ignores the cleverness of the author of
696 elsif Is_Overloadable
(Op_Id
) then
697 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
700 Op_Id
:= Homonym
(Op_Id
);
705 end Analyze_Arithmetic_Op
;
711 -- Function, procedure, and entry calls are checked here. The Name in
712 -- the call may be overloaded. The actuals have been analyzed and may
713 -- themselves be overloaded. On exit from this procedure, the node N
714 -- may have zero, one or more interpretations. In the first case an
715 -- error message is produced. In the last case, the node is flagged
716 -- as overloaded and the interpretations are collected in All_Interp.
718 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
719 -- the type-checking is similar to that of other calls.
721 procedure Analyze_Call
(N
: Node_Id
) is
722 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
727 Success
: Boolean := False;
729 Deref
: Boolean := False;
730 -- Flag indicates whether an interpretation of the prefix is a
731 -- parameterless call that returns an access_to_subprogram.
733 function Name_Denotes_Function
return Boolean;
734 -- If the type of the name is an access to subprogram, this may be the
735 -- type of a name, or the return type of the function being called. If
736 -- the name is not an entity then it can denote a protected function.
737 -- Until we distinguish Etype from Return_Type, we must use this routine
738 -- to resolve the meaning of the name in the call.
740 procedure No_Interpretation
;
741 -- Output error message when no valid interpretation exists
743 ---------------------------
744 -- Name_Denotes_Function --
745 ---------------------------
747 function Name_Denotes_Function
return Boolean is
749 if Is_Entity_Name
(Nam
) then
750 return Ekind
(Entity
(Nam
)) = E_Function
;
752 elsif Nkind
(Nam
) = N_Selected_Component
then
753 return Ekind
(Entity
(Selector_Name
(Nam
))) = E_Function
;
758 end Name_Denotes_Function
;
760 -----------------------
761 -- No_Interpretation --
762 -----------------------
764 procedure No_Interpretation
is
765 L
: constant Boolean := Is_List_Member
(N
);
766 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
769 -- If the node is in a list whose parent is not an expression then it
770 -- must be an attempted procedure call.
772 if L
and then K
not in N_Subexpr
then
773 if Ekind
(Entity
(Nam
)) = E_Generic_Procedure
then
775 ("must instantiate generic procedure& before call",
779 ("procedure or entry name expected", Nam
);
782 -- Check for tasking cases where only an entry call will do
785 and then Nkind_In
(K
, N_Entry_Call_Alternative
,
786 N_Triggering_Alternative
)
788 Error_Msg_N
("entry name expected", Nam
);
790 -- Otherwise give general error message
793 Error_Msg_N
("invalid prefix in call", Nam
);
795 end No_Interpretation
;
797 -- Start of processing for Analyze_Call
800 -- Initialize the type of the result of the call to the error type,
801 -- which will be reset if the type is successfully resolved.
803 Set_Etype
(N
, Any_Type
);
807 if not Is_Overloaded
(Nam
) then
809 -- Only one interpretation to check
811 if Ekind
(Etype
(Nam
)) = E_Subprogram_Type
then
812 Nam_Ent
:= Etype
(Nam
);
814 -- If the prefix is an access_to_subprogram, this may be an indirect
815 -- call. This is the case if the name in the call is not an entity
816 -- name, or if it is a function name in the context of a procedure
817 -- call. In this latter case, we have a call to a parameterless
818 -- function that returns a pointer_to_procedure which is the entity
819 -- being called. Finally, F (X) may be a call to a parameterless
820 -- function that returns a pointer to a function with parameters.
822 elsif Is_Access_Type
(Etype
(Nam
))
823 and then Ekind
(Designated_Type
(Etype
(Nam
))) = E_Subprogram_Type
825 (not Name_Denotes_Function
826 or else Nkind
(N
) = N_Procedure_Call_Statement
828 (Nkind
(Parent
(N
)) /= N_Explicit_Dereference
829 and then Is_Entity_Name
(Nam
)
830 and then No
(First_Formal
(Entity
(Nam
)))
831 and then Present
(Actuals
)))
833 Nam_Ent
:= Designated_Type
(Etype
(Nam
));
834 Insert_Explicit_Dereference
(Nam
);
836 -- Selected component case. Simple entry or protected operation,
837 -- where the entry name is given by the selector name.
839 elsif Nkind
(Nam
) = N_Selected_Component
then
840 Nam_Ent
:= Entity
(Selector_Name
(Nam
));
842 if not Ekind_In
(Nam_Ent
, E_Entry
,
847 Error_Msg_N
("name in call is not a callable entity", Nam
);
848 Set_Etype
(N
, Any_Type
);
852 -- If the name is an Indexed component, it can be a call to a member
853 -- of an entry family. The prefix must be a selected component whose
854 -- selector is the entry. Analyze_Procedure_Call normalizes several
855 -- kinds of call into this form.
857 elsif Nkind
(Nam
) = N_Indexed_Component
then
858 if Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
859 Nam_Ent
:= Entity
(Selector_Name
(Prefix
(Nam
)));
861 Error_Msg_N
("name in call is not a callable entity", Nam
);
862 Set_Etype
(N
, Any_Type
);
866 elsif not Is_Entity_Name
(Nam
) then
867 Error_Msg_N
("name in call is not a callable entity", Nam
);
868 Set_Etype
(N
, Any_Type
);
872 Nam_Ent
:= Entity
(Nam
);
874 -- If no interpretations, give error message
876 if not Is_Overloadable
(Nam_Ent
) then
882 -- Operations generated for RACW stub types are called only through
883 -- dispatching, and can never be the static interpretation of a call.
885 if Is_RACW_Stub_Type_Operation
(Nam_Ent
) then
890 Analyze_One_Call
(N
, Nam_Ent
, True, Success
);
892 -- If this is an indirect call, the return type of the access_to
893 -- subprogram may be an incomplete type. At the point of the call,
894 -- use the full type if available, and at the same time update
895 -- the return type of the access_to_subprogram.
898 and then Nkind
(Nam
) = N_Explicit_Dereference
899 and then Ekind
(Etype
(N
)) = E_Incomplete_Type
900 and then Present
(Full_View
(Etype
(N
)))
902 Set_Etype
(N
, Full_View
(Etype
(N
)));
903 Set_Etype
(Nam_Ent
, Etype
(N
));
907 -- An overloaded selected component must denote overloaded operations
908 -- of a concurrent type. The interpretations are attached to the
909 -- simple name of those operations.
911 if Nkind
(Nam
) = N_Selected_Component
then
912 Nam
:= Selector_Name
(Nam
);
915 Get_First_Interp
(Nam
, X
, It
);
917 while Present
(It
.Nam
) loop
921 -- Name may be call that returns an access to subprogram, or more
922 -- generally an overloaded expression one of whose interpretations
923 -- yields an access to subprogram. If the name is an entity, we
924 -- do not dereference, because the node is a call that returns
925 -- the access type: note difference between f(x), where the call
926 -- may return an access subprogram type, and f(x)(y), where the
927 -- type returned by the call to f is implicitly dereferenced to
928 -- analyze the outer call.
930 if Is_Access_Type
(Nam_Ent
) then
931 Nam_Ent
:= Designated_Type
(Nam_Ent
);
933 elsif Is_Access_Type
(Etype
(Nam_Ent
))
935 (not Is_Entity_Name
(Nam
)
936 or else Nkind
(N
) = N_Procedure_Call_Statement
)
937 and then Ekind
(Designated_Type
(Etype
(Nam_Ent
)))
940 Nam_Ent
:= Designated_Type
(Etype
(Nam_Ent
));
942 if Is_Entity_Name
(Nam
) then
947 -- If the call has been rewritten from a prefixed call, the first
948 -- parameter has been analyzed, but may need a subsequent
949 -- dereference, so skip its analysis now.
951 if N
/= Original_Node
(N
)
952 and then Nkind
(Original_Node
(N
)) = Nkind
(N
)
953 and then Nkind
(Name
(N
)) /= Nkind
(Name
(Original_Node
(N
)))
954 and then Present
(Parameter_Associations
(N
))
955 and then Present
(Etype
(First
(Parameter_Associations
(N
))))
958 (N
, Nam_Ent
, False, Success
, Skip_First
=> True);
960 Analyze_One_Call
(N
, Nam_Ent
, False, Success
);
963 -- If the interpretation succeeds, mark the proper type of the
964 -- prefix (any valid candidate will do). If not, remove the
965 -- candidate interpretation. This only needs to be done for
966 -- overloaded protected operations, for other entities disambi-
967 -- guation is done directly in Resolve.
971 and then Nkind
(Parent
(N
)) /= N_Explicit_Dereference
973 Set_Entity
(Nam
, It
.Nam
);
974 Insert_Explicit_Dereference
(Nam
);
975 Set_Etype
(Nam
, Nam_Ent
);
978 Set_Etype
(Nam
, It
.Typ
);
981 elsif Nkind_In
(Name
(N
), N_Selected_Component
,
987 Get_Next_Interp
(X
, It
);
990 -- If the name is the result of a function call, it can only
991 -- be a call to a function returning an access to subprogram.
992 -- Insert explicit dereference.
994 if Nkind
(Nam
) = N_Function_Call
then
995 Insert_Explicit_Dereference
(Nam
);
998 if Etype
(N
) = Any_Type
then
1000 -- None of the interpretations is compatible with the actuals
1002 Diagnose_Call
(N
, Nam
);
1004 -- Special checks for uninstantiated put routines
1006 if Nkind
(N
) = N_Procedure_Call_Statement
1007 and then Is_Entity_Name
(Nam
)
1008 and then Chars
(Nam
) = Name_Put
1009 and then List_Length
(Actuals
) = 1
1012 Arg
: constant Node_Id
:= First
(Actuals
);
1016 if Nkind
(Arg
) = N_Parameter_Association
then
1017 Typ
:= Etype
(Explicit_Actual_Parameter
(Arg
));
1022 if Is_Signed_Integer_Type
(Typ
) then
1024 ("possible missing instantiation of " &
1025 "'Text_'I'O.'Integer_'I'O!", Nam
);
1027 elsif Is_Modular_Integer_Type
(Typ
) then
1029 ("possible missing instantiation of " &
1030 "'Text_'I'O.'Modular_'I'O!", Nam
);
1032 elsif Is_Floating_Point_Type
(Typ
) then
1034 ("possible missing instantiation of " &
1035 "'Text_'I'O.'Float_'I'O!", Nam
);
1037 elsif Is_Ordinary_Fixed_Point_Type
(Typ
) then
1039 ("possible missing instantiation of " &
1040 "'Text_'I'O.'Fixed_'I'O!", Nam
);
1042 elsif Is_Decimal_Fixed_Point_Type
(Typ
) then
1044 ("possible missing instantiation of " &
1045 "'Text_'I'O.'Decimal_'I'O!", Nam
);
1047 elsif Is_Enumeration_Type
(Typ
) then
1049 ("possible missing instantiation of " &
1050 "'Text_'I'O.'Enumeration_'I'O!", Nam
);
1055 elsif not Is_Overloaded
(N
)
1056 and then Is_Entity_Name
(Nam
)
1058 -- Resolution yields a single interpretation. Verify that the
1059 -- reference has capitalization consistent with the declaration.
1061 Set_Entity_With_Style_Check
(Nam
, Entity
(Nam
));
1062 Generate_Reference
(Entity
(Nam
), Nam
);
1064 Set_Etype
(Nam
, Etype
(Entity
(Nam
)));
1066 Remove_Abstract_Operations
(N
);
1073 -----------------------------
1074 -- Analyze_Case_Expression --
1075 -----------------------------
1077 procedure Analyze_Case_Expression
(N
: Node_Id
) is
1078 Expr
: constant Node_Id
:= Expression
(N
);
1079 FirstX
: constant Node_Id
:= Expression
(First
(Alternatives
(N
)));
1081 Exp_Type
: Entity_Id
;
1082 Exp_Btype
: Entity_Id
;
1085 Dont_Care
: Boolean;
1086 Others_Present
: Boolean;
1088 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
1089 -- Error routine invoked by the generic instantiation below when
1090 -- the case expression has a non static choice.
1092 package Case_Choices_Processing
is new
1093 Generic_Choices_Processing
1094 (Get_Alternatives
=> Alternatives
,
1095 Get_Choices
=> Discrete_Choices
,
1096 Process_Empty_Choice
=> No_OP
,
1097 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
1098 Process_Associated_Node
=> No_OP
);
1099 use Case_Choices_Processing
;
1101 Case_Table
: Choice_Table_Type
(1 .. Number_Of_Choices
(N
));
1103 -----------------------------
1104 -- Non_Static_Choice_Error --
1105 -----------------------------
1107 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
1109 Flag_Non_Static_Expr
1110 ("choice given in case expression is not static!", Choice
);
1111 end Non_Static_Choice_Error
;
1113 -- Start of processing for Analyze_Case_Expression
1116 if Comes_From_Source
(N
) then
1117 Check_Compiler_Unit
(N
);
1120 Analyze_And_Resolve
(Expr
, Any_Discrete
);
1121 Check_Unset_Reference
(Expr
);
1122 Exp_Type
:= Etype
(Expr
);
1123 Exp_Btype
:= Base_Type
(Exp_Type
);
1125 Alt
:= First
(Alternatives
(N
));
1126 while Present
(Alt
) loop
1127 Analyze
(Expression
(Alt
));
1131 if not Is_Overloaded
(FirstX
) then
1132 Set_Etype
(N
, Etype
(FirstX
));
1140 Set_Etype
(N
, Any_Type
);
1142 Get_First_Interp
(FirstX
, I
, It
);
1143 while Present
(It
.Nam
) loop
1145 -- For each intepretation of the first expression, we only
1146 -- add the intepretation if every other expression in the
1147 -- case expression alternatives has a compatible type.
1149 Alt
:= Next
(First
(Alternatives
(N
)));
1150 while Present
(Alt
) loop
1151 exit when not Has_Compatible_Type
(Expression
(Alt
), It
.Typ
);
1156 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
1159 Get_Next_Interp
(I
, It
);
1164 Exp_Btype
:= Base_Type
(Exp_Type
);
1166 -- The expression must be of a discrete type which must be determinable
1167 -- independently of the context in which the expression occurs, but
1168 -- using the fact that the expression must be of a discrete type.
1169 -- Moreover, the type this expression must not be a character literal
1170 -- (which is always ambiguous).
1172 -- If error already reported by Resolve, nothing more to do
1174 if Exp_Btype
= Any_Discrete
1175 or else Exp_Btype
= Any_Type
1179 elsif Exp_Btype
= Any_Character
then
1181 ("character literal as case expression is ambiguous", Expr
);
1185 -- If the case expression is a formal object of mode in out, then
1186 -- treat it as having a nonstatic subtype by forcing use of the base
1187 -- type (which has to get passed to Check_Case_Choices below). Also
1188 -- use base type when the case expression is parenthesized.
1190 if Paren_Count
(Expr
) > 0
1191 or else (Is_Entity_Name
(Expr
)
1192 and then Ekind
(Entity
(Expr
)) = E_Generic_In_Out_Parameter
)
1194 Exp_Type
:= Exp_Btype
;
1197 -- Call instantiated Analyze_Choices which does the rest of the work
1200 (N
, Exp_Type
, Case_Table
, Last_Choice
, Dont_Care
, Others_Present
);
1202 if Exp_Type
= Universal_Integer
and then not Others_Present
then
1204 ("case on universal integer requires OTHERS choice", Expr
);
1206 end Analyze_Case_Expression
;
1208 ---------------------------
1209 -- Analyze_Comparison_Op --
1210 ---------------------------
1212 procedure Analyze_Comparison_Op
(N
: Node_Id
) is
1213 L
: constant Node_Id
:= Left_Opnd
(N
);
1214 R
: constant Node_Id
:= Right_Opnd
(N
);
1215 Op_Id
: Entity_Id
:= Entity
(N
);
1218 Set_Etype
(N
, Any_Type
);
1219 Candidate_Type
:= Empty
;
1221 Analyze_Expression
(L
);
1222 Analyze_Expression
(R
);
1224 if Present
(Op_Id
) then
1225 if Ekind
(Op_Id
) = E_Operator
then
1226 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1228 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1231 if Is_Overloaded
(L
) then
1232 Set_Etype
(L
, Intersect_Types
(L
, R
));
1236 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1237 while Present
(Op_Id
) loop
1238 if Ekind
(Op_Id
) = E_Operator
then
1239 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1241 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1244 Op_Id
:= Homonym
(Op_Id
);
1249 end Analyze_Comparison_Op
;
1251 ---------------------------
1252 -- Analyze_Concatenation --
1253 ---------------------------
1255 procedure Analyze_Concatenation
(N
: Node_Id
) is
1257 -- We wish to avoid deep recursion, because concatenations are often
1258 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1259 -- operands nonrecursively until we find something that is not a
1260 -- concatenation (A in this case), or has already been analyzed. We
1261 -- analyze that, and then walk back up the tree following Parent
1262 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1263 -- work at each level. The Parent pointers allow us to avoid recursion,
1264 -- and thus avoid running out of memory.
1270 Candidate_Type
:= Empty
;
1272 -- The following code is equivalent to:
1274 -- Set_Etype (N, Any_Type);
1275 -- Analyze_Expression (Left_Opnd (N));
1276 -- Analyze_Concatenation_Rest (N);
1278 -- where the Analyze_Expression call recurses back here if the left
1279 -- operand is a concatenation.
1281 -- Walk down left operands
1284 Set_Etype
(NN
, Any_Type
);
1285 L
:= Left_Opnd
(NN
);
1286 exit when Nkind
(L
) /= N_Op_Concat
or else Analyzed
(L
);
1290 -- Now (given the above example) NN is A&B and L is A
1292 -- First analyze L ...
1294 Analyze_Expression
(L
);
1296 -- ... then walk NN back up until we reach N (where we started), calling
1297 -- Analyze_Concatenation_Rest along the way.
1300 Analyze_Concatenation_Rest
(NN
);
1304 end Analyze_Concatenation
;
1306 --------------------------------
1307 -- Analyze_Concatenation_Rest --
1308 --------------------------------
1310 -- If the only one-dimensional array type in scope is String,
1311 -- this is the resulting type of the operation. Otherwise there
1312 -- will be a concatenation operation defined for each user-defined
1313 -- one-dimensional array.
1315 procedure Analyze_Concatenation_Rest
(N
: Node_Id
) is
1316 L
: constant Node_Id
:= Left_Opnd
(N
);
1317 R
: constant Node_Id
:= Right_Opnd
(N
);
1318 Op_Id
: Entity_Id
:= Entity
(N
);
1323 Analyze_Expression
(R
);
1325 -- If the entity is present, the node appears in an instance, and
1326 -- denotes a predefined concatenation operation. The resulting type is
1327 -- obtained from the arguments when possible. If the arguments are
1328 -- aggregates, the array type and the concatenation type must be
1331 if Present
(Op_Id
) then
1332 if Ekind
(Op_Id
) = E_Operator
then
1333 LT
:= Base_Type
(Etype
(L
));
1334 RT
:= Base_Type
(Etype
(R
));
1336 if Is_Array_Type
(LT
)
1337 and then (RT
= LT
or else RT
= Base_Type
(Component_Type
(LT
)))
1339 Add_One_Interp
(N
, Op_Id
, LT
);
1341 elsif Is_Array_Type
(RT
)
1342 and then LT
= Base_Type
(Component_Type
(RT
))
1344 Add_One_Interp
(N
, Op_Id
, RT
);
1346 -- If one operand is a string type or a user-defined array type,
1347 -- and the other is a literal, result is of the specific type.
1350 (Root_Type
(LT
) = Standard_String
1351 or else Scope
(LT
) /= Standard_Standard
)
1352 and then Etype
(R
) = Any_String
1354 Add_One_Interp
(N
, Op_Id
, LT
);
1357 (Root_Type
(RT
) = Standard_String
1358 or else Scope
(RT
) /= Standard_Standard
)
1359 and then Etype
(L
) = Any_String
1361 Add_One_Interp
(N
, Op_Id
, RT
);
1363 elsif not Is_Generic_Type
(Etype
(Op_Id
)) then
1364 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1367 -- Type and its operations must be visible
1369 Set_Entity
(N
, Empty
);
1370 Analyze_Concatenation
(N
);
1374 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1378 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Concat
);
1379 while Present
(Op_Id
) loop
1380 if Ekind
(Op_Id
) = E_Operator
then
1382 -- Do not consider operators declared in dead code, they can
1383 -- not be part of the resolution.
1385 if Is_Eliminated
(Op_Id
) then
1388 Find_Concatenation_Types
(L
, R
, Op_Id
, N
);
1392 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1395 Op_Id
:= Homonym
(Op_Id
);
1400 end Analyze_Concatenation_Rest
;
1402 ------------------------------------
1403 -- Analyze_Conditional_Expression --
1404 ------------------------------------
1406 procedure Analyze_Conditional_Expression
(N
: Node_Id
) is
1407 Condition
: constant Node_Id
:= First
(Expressions
(N
));
1408 Then_Expr
: constant Node_Id
:= Next
(Condition
);
1409 Else_Expr
: Node_Id
;
1412 -- Defend against error of missing expressions from previous error
1414 if No
(Then_Expr
) then
1418 Else_Expr
:= Next
(Then_Expr
);
1420 if Comes_From_Source
(N
) then
1421 Check_Compiler_Unit
(N
);
1424 Analyze_Expression
(Condition
);
1425 Analyze_Expression
(Then_Expr
);
1427 if Present
(Else_Expr
) then
1428 Analyze_Expression
(Else_Expr
);
1431 -- If then expression not overloaded, then that decides the type
1433 if not Is_Overloaded
(Then_Expr
) then
1434 Set_Etype
(N
, Etype
(Then_Expr
));
1436 -- Case where then expression is overloaded
1444 Set_Etype
(N
, Any_Type
);
1445 Get_First_Interp
(Then_Expr
, I
, It
);
1446 while Present
(It
.Nam
) loop
1448 -- For each possible intepretation of the Then Expression,
1449 -- add it only if the else expression has a compatible type.
1451 -- Is this right if Else_Expr is empty?
1453 if Has_Compatible_Type
(Else_Expr
, It
.Typ
) then
1454 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
1457 Get_Next_Interp
(I
, It
);
1461 end Analyze_Conditional_Expression
;
1463 -------------------------
1464 -- Analyze_Equality_Op --
1465 -------------------------
1467 procedure Analyze_Equality_Op
(N
: Node_Id
) is
1468 Loc
: constant Source_Ptr
:= Sloc
(N
);
1469 L
: constant Node_Id
:= Left_Opnd
(N
);
1470 R
: constant Node_Id
:= Right_Opnd
(N
);
1474 Set_Etype
(N
, Any_Type
);
1475 Candidate_Type
:= Empty
;
1477 Analyze_Expression
(L
);
1478 Analyze_Expression
(R
);
1480 -- If the entity is set, the node is a generic instance with a non-local
1481 -- reference to the predefined operator or to a user-defined function.
1482 -- It can also be an inequality that is expanded into the negation of a
1483 -- call to a user-defined equality operator.
1485 -- For the predefined case, the result is Boolean, regardless of the
1486 -- type of the operands. The operands may even be limited, if they are
1487 -- generic actuals. If they are overloaded, label the left argument with
1488 -- the common type that must be present, or with the type of the formal
1489 -- of the user-defined function.
1491 if Present
(Entity
(N
)) then
1492 Op_Id
:= Entity
(N
);
1494 if Ekind
(Op_Id
) = E_Operator
then
1495 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
);
1497 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1500 if Is_Overloaded
(L
) then
1501 if Ekind
(Op_Id
) = E_Operator
then
1502 Set_Etype
(L
, Intersect_Types
(L
, R
));
1504 Set_Etype
(L
, Etype
(First_Formal
(Op_Id
)));
1509 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1510 while Present
(Op_Id
) loop
1511 if Ekind
(Op_Id
) = E_Operator
then
1512 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1514 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1517 Op_Id
:= Homonym
(Op_Id
);
1521 -- If there was no match, and the operator is inequality, this may
1522 -- be a case where inequality has not been made explicit, as for
1523 -- tagged types. Analyze the node as the negation of an equality
1524 -- operation. This cannot be done earlier, because before analysis
1525 -- we cannot rule out the presence of an explicit inequality.
1527 if Etype
(N
) = Any_Type
1528 and then Nkind
(N
) = N_Op_Ne
1530 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Eq
);
1531 while Present
(Op_Id
) loop
1532 if Ekind
(Op_Id
) = E_Operator
then
1533 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1535 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1538 Op_Id
:= Homonym
(Op_Id
);
1541 if Etype
(N
) /= Any_Type
then
1542 Op_Id
:= Entity
(N
);
1548 Left_Opnd
=> Left_Opnd
(N
),
1549 Right_Opnd
=> Right_Opnd
(N
))));
1551 Set_Entity
(Right_Opnd
(N
), Op_Id
);
1557 end Analyze_Equality_Op
;
1559 ----------------------------------
1560 -- Analyze_Explicit_Dereference --
1561 ----------------------------------
1563 procedure Analyze_Explicit_Dereference
(N
: Node_Id
) is
1564 Loc
: constant Source_Ptr
:= Sloc
(N
);
1565 P
: constant Node_Id
:= Prefix
(N
);
1571 function Is_Function_Type
return Boolean;
1572 -- Check whether node may be interpreted as an implicit function call
1574 ----------------------
1575 -- Is_Function_Type --
1576 ----------------------
1578 function Is_Function_Type
return Boolean is
1583 if not Is_Overloaded
(N
) then
1584 return Ekind
(Base_Type
(Etype
(N
))) = E_Subprogram_Type
1585 and then Etype
(Base_Type
(Etype
(N
))) /= Standard_Void_Type
;
1588 Get_First_Interp
(N
, I
, It
);
1589 while Present
(It
.Nam
) loop
1590 if Ekind
(Base_Type
(It
.Typ
)) /= E_Subprogram_Type
1591 or else Etype
(Base_Type
(It
.Typ
)) = Standard_Void_Type
1596 Get_Next_Interp
(I
, It
);
1601 end Is_Function_Type
;
1603 -- Start of processing for Analyze_Explicit_Dereference
1607 Set_Etype
(N
, Any_Type
);
1609 -- Test for remote access to subprogram type, and if so return
1610 -- after rewriting the original tree.
1612 if Remote_AST_E_Dereference
(P
) then
1616 -- Normal processing for other than remote access to subprogram type
1618 if not Is_Overloaded
(P
) then
1619 if Is_Access_Type
(Etype
(P
)) then
1621 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
1622 -- avoid other problems caused by the Private_Subtype and it is
1623 -- safe to go to the Base_Type because this is the same as
1624 -- converting the access value to its Base_Type.
1627 DT
: Entity_Id
:= Designated_Type
(Etype
(P
));
1630 if Ekind
(DT
) = E_Private_Subtype
1631 and then Is_For_Access_Subtype
(DT
)
1633 DT
:= Base_Type
(DT
);
1636 -- An explicit dereference is a legal occurrence of an
1637 -- incomplete type imported through a limited_with clause,
1638 -- if the full view is visible.
1640 if From_With_Type
(DT
)
1641 and then not From_With_Type
(Scope
(DT
))
1643 (Is_Immediately_Visible
(Scope
(DT
))
1645 (Is_Child_Unit
(Scope
(DT
))
1646 and then Is_Visible_Child_Unit
(Scope
(DT
))))
1648 Set_Etype
(N
, Available_View
(DT
));
1655 elsif Etype
(P
) /= Any_Type
then
1656 Error_Msg_N
("prefix of dereference must be an access type", N
);
1661 Get_First_Interp
(P
, I
, It
);
1662 while Present
(It
.Nam
) loop
1665 if Is_Access_Type
(T
) then
1666 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
1669 Get_Next_Interp
(I
, It
);
1672 -- Error if no interpretation of the prefix has an access type
1674 if Etype
(N
) = Any_Type
then
1676 ("access type required in prefix of explicit dereference", P
);
1677 Set_Etype
(N
, Any_Type
);
1683 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
1685 and then (Nkind
(Parent
(N
)) /= N_Function_Call
1686 or else N
/= Name
(Parent
(N
)))
1688 and then (Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1689 or else N
/= Name
(Parent
(N
)))
1691 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
1692 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
1694 (Attribute_Name
(Parent
(N
)) /= Name_Address
1696 Attribute_Name
(Parent
(N
)) /= Name_Access
))
1698 -- Name is a function call with no actuals, in a context that
1699 -- requires deproceduring (including as an actual in an enclosing
1700 -- function or procedure call). There are some pathological cases
1701 -- where the prefix might include functions that return access to
1702 -- subprograms and others that return a regular type. Disambiguation
1703 -- of those has to take place in Resolve.
1706 Make_Function_Call
(Loc
,
1707 Name
=> Make_Explicit_Dereference
(Loc
, P
),
1708 Parameter_Associations
=> New_List
);
1710 -- If the prefix is overloaded, remove operations that have formals,
1711 -- we know that this is a parameterless call.
1713 if Is_Overloaded
(P
) then
1714 Get_First_Interp
(P
, I
, It
);
1715 while Present
(It
.Nam
) loop
1718 if No
(First_Formal
(Base_Type
(Designated_Type
(T
)))) then
1724 Get_Next_Interp
(I
, It
);
1731 elsif not Is_Function_Type
1732 and then Is_Overloaded
(N
)
1734 -- The prefix may include access to subprograms and other access
1735 -- types. If the context selects the interpretation that is a
1736 -- function call (not a procedure call) we cannot rewrite the node
1737 -- yet, but we include the result of the call interpretation.
1739 Get_First_Interp
(N
, I
, It
);
1740 while Present
(It
.Nam
) loop
1741 if Ekind
(Base_Type
(It
.Typ
)) = E_Subprogram_Type
1742 and then Etype
(Base_Type
(It
.Typ
)) /= Standard_Void_Type
1743 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1745 Add_One_Interp
(N
, Etype
(It
.Typ
), Etype
(It
.Typ
));
1748 Get_Next_Interp
(I
, It
);
1752 -- A value of remote access-to-class-wide must not be dereferenced
1755 Validate_Remote_Access_To_Class_Wide_Type
(N
);
1756 end Analyze_Explicit_Dereference
;
1758 ------------------------
1759 -- Analyze_Expression --
1760 ------------------------
1762 procedure Analyze_Expression
(N
: Node_Id
) is
1765 Check_Parameterless_Call
(N
);
1766 end Analyze_Expression
;
1768 -------------------------------------
1769 -- Analyze_Expression_With_Actions --
1770 -------------------------------------
1772 procedure Analyze_Expression_With_Actions
(N
: Node_Id
) is
1776 A
:= First
(Actions
(N
));
1783 Analyze_Expression
(Expression
(N
));
1784 Set_Etype
(N
, Etype
(Expression
(N
)));
1785 end Analyze_Expression_With_Actions
;
1787 ------------------------------------
1788 -- Analyze_Indexed_Component_Form --
1789 ------------------------------------
1791 procedure Analyze_Indexed_Component_Form
(N
: Node_Id
) is
1792 P
: constant Node_Id
:= Prefix
(N
);
1793 Exprs
: constant List_Id
:= Expressions
(N
);
1799 procedure Process_Function_Call
;
1800 -- Prefix in indexed component form is an overloadable entity,
1801 -- so the node is a function call. Reformat it as such.
1803 procedure Process_Indexed_Component
;
1804 -- Prefix in indexed component form is actually an indexed component.
1805 -- This routine processes it, knowing that the prefix is already
1808 procedure Process_Indexed_Component_Or_Slice
;
1809 -- An indexed component with a single index may designate a slice if
1810 -- the index is a subtype mark. This routine disambiguates these two
1811 -- cases by resolving the prefix to see if it is a subtype mark.
1813 procedure Process_Overloaded_Indexed_Component
;
1814 -- If the prefix of an indexed component is overloaded, the proper
1815 -- interpretation is selected by the index types and the context.
1817 ---------------------------
1818 -- Process_Function_Call --
1819 ---------------------------
1821 procedure Process_Function_Call
is
1825 Change_Node
(N
, N_Function_Call
);
1827 Set_Parameter_Associations
(N
, Exprs
);
1829 -- Analyze actuals prior to analyzing the call itself
1831 Actual
:= First
(Parameter_Associations
(N
));
1832 while Present
(Actual
) loop
1834 Check_Parameterless_Call
(Actual
);
1836 -- Move to next actual. Note that we use Next, not Next_Actual
1837 -- here. The reason for this is a bit subtle. If a function call
1838 -- includes named associations, the parser recognizes the node as
1839 -- a call, and it is analyzed as such. If all associations are
1840 -- positional, the parser builds an indexed_component node, and
1841 -- it is only after analysis of the prefix that the construct
1842 -- is recognized as a call, in which case Process_Function_Call
1843 -- rewrites the node and analyzes the actuals. If the list of
1844 -- actuals is malformed, the parser may leave the node as an
1845 -- indexed component (despite the presence of named associations).
1846 -- The iterator Next_Actual is equivalent to Next if the list is
1847 -- positional, but follows the normalized chain of actuals when
1848 -- named associations are present. In this case normalization has
1849 -- not taken place, and actuals remain unanalyzed, which leads to
1850 -- subsequent crashes or loops if there is an attempt to continue
1851 -- analysis of the program.
1857 end Process_Function_Call
;
1859 -------------------------------
1860 -- Process_Indexed_Component --
1861 -------------------------------
1863 procedure Process_Indexed_Component
is
1865 Array_Type
: Entity_Id
;
1867 Pent
: Entity_Id
:= Empty
;
1870 Exp
:= First
(Exprs
);
1872 if Is_Overloaded
(P
) then
1873 Process_Overloaded_Indexed_Component
;
1876 Array_Type
:= Etype
(P
);
1878 if Is_Entity_Name
(P
) then
1880 elsif Nkind
(P
) = N_Selected_Component
1881 and then Is_Entity_Name
(Selector_Name
(P
))
1883 Pent
:= Entity
(Selector_Name
(P
));
1886 -- Prefix must be appropriate for an array type, taking into
1887 -- account a possible implicit dereference.
1889 if Is_Access_Type
(Array_Type
) then
1890 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
1891 Array_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, P
);
1894 if Is_Array_Type
(Array_Type
) then
1897 elsif Present
(Pent
) and then Ekind
(Pent
) = E_Entry_Family
then
1899 Set_Etype
(N
, Any_Type
);
1901 if not Has_Compatible_Type
1902 (Exp
, Entry_Index_Type
(Pent
))
1904 Error_Msg_N
("invalid index type in entry name", N
);
1906 elsif Present
(Next
(Exp
)) then
1907 Error_Msg_N
("too many subscripts in entry reference", N
);
1910 Set_Etype
(N
, Etype
(P
));
1915 elsif Is_Record_Type
(Array_Type
)
1916 and then Remote_AST_I_Dereference
(P
)
1920 elsif Array_Type
= Any_Type
then
1921 Set_Etype
(N
, Any_Type
);
1923 -- In most cases the analysis of the prefix will have emitted
1924 -- an error already, but if the prefix may be interpreted as a
1925 -- call in prefixed notation, the report is left to the caller.
1926 -- To prevent cascaded errors, report only if no previous ones.
1928 if Serious_Errors_Detected
= 0 then
1929 Error_Msg_N
("invalid prefix in indexed component", P
);
1931 if Nkind
(P
) = N_Expanded_Name
then
1932 Error_Msg_NE
("\& is not visible", P
, Selector_Name
(P
));
1938 -- Here we definitely have a bad indexing
1941 if Nkind
(Parent
(N
)) = N_Requeue_Statement
1942 and then Present
(Pent
) and then Ekind
(Pent
) = E_Entry
1945 ("REQUEUE does not permit parameters", First
(Exprs
));
1947 elsif Is_Entity_Name
(P
)
1948 and then Etype
(P
) = Standard_Void_Type
1950 Error_Msg_NE
("incorrect use of&", P
, Entity
(P
));
1953 Error_Msg_N
("array type required in indexed component", P
);
1956 Set_Etype
(N
, Any_Type
);
1960 Index
:= First_Index
(Array_Type
);
1961 while Present
(Index
) and then Present
(Exp
) loop
1962 if not Has_Compatible_Type
(Exp
, Etype
(Index
)) then
1963 Wrong_Type
(Exp
, Etype
(Index
));
1964 Set_Etype
(N
, Any_Type
);
1972 Set_Etype
(N
, Component_Type
(Array_Type
));
1974 if Present
(Index
) then
1976 ("too few subscripts in array reference", First
(Exprs
));
1978 elsif Present
(Exp
) then
1979 Error_Msg_N
("too many subscripts in array reference", Exp
);
1982 end Process_Indexed_Component
;
1984 ----------------------------------------
1985 -- Process_Indexed_Component_Or_Slice --
1986 ----------------------------------------
1988 procedure Process_Indexed_Component_Or_Slice
is
1990 Exp
:= First
(Exprs
);
1991 while Present
(Exp
) loop
1992 Analyze_Expression
(Exp
);
1996 Exp
:= First
(Exprs
);
1998 -- If one index is present, and it is a subtype name, then the
1999 -- node denotes a slice (note that the case of an explicit range
2000 -- for a slice was already built as an N_Slice node in the first
2001 -- place, so that case is not handled here).
2003 -- We use a replace rather than a rewrite here because this is one
2004 -- of the cases in which the tree built by the parser is plain wrong.
2007 and then Is_Entity_Name
(Exp
)
2008 and then Is_Type
(Entity
(Exp
))
2011 Make_Slice
(Sloc
(N
),
2013 Discrete_Range
=> New_Copy
(Exp
)));
2016 -- Otherwise (more than one index present, or single index is not
2017 -- a subtype name), then we have the indexed component case.
2020 Process_Indexed_Component
;
2022 end Process_Indexed_Component_Or_Slice
;
2024 ------------------------------------------
2025 -- Process_Overloaded_Indexed_Component --
2026 ------------------------------------------
2028 procedure Process_Overloaded_Indexed_Component
is
2037 Set_Etype
(N
, Any_Type
);
2039 Get_First_Interp
(P
, I
, It
);
2040 while Present
(It
.Nam
) loop
2043 if Is_Access_Type
(Typ
) then
2044 Typ
:= Designated_Type
(Typ
);
2045 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
2048 if Is_Array_Type
(Typ
) then
2050 -- Got a candidate: verify that index types are compatible
2052 Index
:= First_Index
(Typ
);
2054 Exp
:= First
(Exprs
);
2055 while Present
(Index
) and then Present
(Exp
) loop
2056 if Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2068 if Found
and then No
(Index
) and then No
(Exp
) then
2070 Etype
(Component_Type
(Typ
)),
2071 Etype
(Component_Type
(Typ
)));
2075 Get_Next_Interp
(I
, It
);
2078 if Etype
(N
) = Any_Type
then
2079 Error_Msg_N
("no legal interpretation for indexed component", N
);
2080 Set_Is_Overloaded
(N
, False);
2084 end Process_Overloaded_Indexed_Component
;
2086 -- Start of processing for Analyze_Indexed_Component_Form
2089 -- Get name of array, function or type
2093 if Nkind_In
(N
, N_Function_Call
, N_Procedure_Call_Statement
) then
2095 -- If P is an explicit dereference whose prefix is of a
2096 -- remote access-to-subprogram type, then N has already
2097 -- been rewritten as a subprogram call and analyzed.
2102 pragma Assert
(Nkind
(N
) = N_Indexed_Component
);
2104 P_T
:= Base_Type
(Etype
(P
));
2106 if Is_Entity_Name
(P
)
2107 or else Nkind
(P
) = N_Operator_Symbol
2111 if Is_Type
(U_N
) then
2113 -- Reformat node as a type conversion
2115 E
:= Remove_Head
(Exprs
);
2117 if Present
(First
(Exprs
)) then
2119 ("argument of type conversion must be single expression", N
);
2122 Change_Node
(N
, N_Type_Conversion
);
2123 Set_Subtype_Mark
(N
, P
);
2125 Set_Expression
(N
, E
);
2127 -- After changing the node, call for the specific Analysis
2128 -- routine directly, to avoid a double call to the expander.
2130 Analyze_Type_Conversion
(N
);
2134 if Is_Overloadable
(U_N
) then
2135 Process_Function_Call
;
2137 elsif Ekind
(Etype
(P
)) = E_Subprogram_Type
2138 or else (Is_Access_Type
(Etype
(P
))
2140 Ekind
(Designated_Type
(Etype
(P
))) =
2143 -- Call to access_to-subprogram with possible implicit dereference
2145 Process_Function_Call
;
2147 elsif Is_Generic_Subprogram
(U_N
) then
2149 -- A common beginner's (or C++ templates fan) error
2151 Error_Msg_N
("generic subprogram cannot be called", N
);
2152 Set_Etype
(N
, Any_Type
);
2156 Process_Indexed_Component_Or_Slice
;
2159 -- If not an entity name, prefix is an expression that may denote
2160 -- an array or an access-to-subprogram.
2163 if Ekind
(P_T
) = E_Subprogram_Type
2164 or else (Is_Access_Type
(P_T
)
2166 Ekind
(Designated_Type
(P_T
)) = E_Subprogram_Type
)
2168 Process_Function_Call
;
2170 elsif Nkind
(P
) = N_Selected_Component
2171 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
2173 Process_Function_Call
;
2176 -- Indexed component, slice, or a call to a member of a family
2177 -- entry, which will be converted to an entry call later.
2179 Process_Indexed_Component_Or_Slice
;
2182 end Analyze_Indexed_Component_Form
;
2184 ------------------------
2185 -- Analyze_Logical_Op --
2186 ------------------------
2188 procedure Analyze_Logical_Op
(N
: Node_Id
) is
2189 L
: constant Node_Id
:= Left_Opnd
(N
);
2190 R
: constant Node_Id
:= Right_Opnd
(N
);
2191 Op_Id
: Entity_Id
:= Entity
(N
);
2194 Set_Etype
(N
, Any_Type
);
2195 Candidate_Type
:= Empty
;
2197 Analyze_Expression
(L
);
2198 Analyze_Expression
(R
);
2200 if Present
(Op_Id
) then
2202 if Ekind
(Op_Id
) = E_Operator
then
2203 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
2205 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2209 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
2210 while Present
(Op_Id
) loop
2211 if Ekind
(Op_Id
) = E_Operator
then
2212 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
2214 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
2217 Op_Id
:= Homonym
(Op_Id
);
2222 end Analyze_Logical_Op
;
2224 ---------------------------
2225 -- Analyze_Membership_Op --
2226 ---------------------------
2228 procedure Analyze_Membership_Op
(N
: Node_Id
) is
2229 L
: constant Node_Id
:= Left_Opnd
(N
);
2230 R
: constant Node_Id
:= Right_Opnd
(N
);
2232 Index
: Interp_Index
;
2234 Found
: Boolean := False;
2238 procedure Try_One_Interp
(T1
: Entity_Id
);
2239 -- Routine to try one proposed interpretation. Note that the context
2240 -- of the operation plays no role in resolving the arguments, so that
2241 -- if there is more than one interpretation of the operands that is
2242 -- compatible with a membership test, the operation is ambiguous.
2244 --------------------
2245 -- Try_One_Interp --
2246 --------------------
2248 procedure Try_One_Interp
(T1
: Entity_Id
) is
2250 if Has_Compatible_Type
(R
, T1
) then
2252 and then Base_Type
(T1
) /= Base_Type
(T_F
)
2254 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
2256 if It
= No_Interp
then
2257 Ambiguous_Operands
(N
);
2258 Set_Etype
(L
, Any_Type
);
2275 procedure Analyze_Set_Membership
;
2276 -- If a set of alternatives is present, analyze each and find the
2277 -- common type to which they must all resolve.
2279 ----------------------------
2280 -- Analyze_Set_Membership --
2281 ----------------------------
2283 procedure Analyze_Set_Membership
is
2285 Index
: Interp_Index
;
2287 Candidate_Interps
: Node_Id
;
2288 Common_Type
: Entity_Id
:= Empty
;
2292 Candidate_Interps
:= L
;
2294 if not Is_Overloaded
(L
) then
2295 Common_Type
:= Etype
(L
);
2297 Alt
:= First
(Alternatives
(N
));
2298 while Present
(Alt
) loop
2301 if not Has_Compatible_Type
(Alt
, Common_Type
) then
2302 Wrong_Type
(Alt
, Common_Type
);
2309 Alt
:= First
(Alternatives
(N
));
2310 while Present
(Alt
) loop
2312 if not Is_Overloaded
(Alt
) then
2313 Common_Type
:= Etype
(Alt
);
2316 Get_First_Interp
(Alt
, Index
, It
);
2317 while Present
(It
.Typ
) loop
2319 Has_Compatible_Type
(Candidate_Interps
, It
.Typ
)
2321 Remove_Interp
(Index
);
2324 Get_Next_Interp
(Index
, It
);
2327 Get_First_Interp
(Alt
, Index
, It
);
2330 Error_Msg_N
("alternative has no legal type", Alt
);
2334 -- If alternative is not overloaded, we have a unique type
2337 Set_Etype
(Alt
, It
.Typ
);
2338 Get_Next_Interp
(Index
, It
);
2341 Set_Is_Overloaded
(Alt
, False);
2342 Common_Type
:= Etype
(Alt
);
2345 Candidate_Interps
:= Alt
;
2352 Set_Etype
(N
, Standard_Boolean
);
2354 if Present
(Common_Type
) then
2355 Set_Etype
(L
, Common_Type
);
2356 Set_Is_Overloaded
(L
, False);
2359 Error_Msg_N
("cannot resolve membership operation", N
);
2361 end Analyze_Set_Membership
;
2363 -- Start of processing for Analyze_Membership_Op
2366 Analyze_Expression
(L
);
2369 and then Ada_Version
>= Ada_12
2371 Analyze_Set_Membership
;
2375 if Nkind
(R
) = N_Range
2376 or else (Nkind
(R
) = N_Attribute_Reference
2377 and then Attribute_Name
(R
) = Name_Range
)
2381 if not Is_Overloaded
(L
) then
2382 Try_One_Interp
(Etype
(L
));
2385 Get_First_Interp
(L
, Index
, It
);
2386 while Present
(It
.Typ
) loop
2387 Try_One_Interp
(It
.Typ
);
2388 Get_Next_Interp
(Index
, It
);
2392 -- If not a range, it can only be a subtype mark, or else there
2393 -- is a more basic error, to be diagnosed in Find_Type.
2398 if Is_Entity_Name
(R
) then
2399 Check_Fully_Declared
(Entity
(R
), R
);
2403 -- Compatibility between expression and subtype mark or range is
2404 -- checked during resolution. The result of the operation is Boolean
2407 Set_Etype
(N
, Standard_Boolean
);
2409 if Comes_From_Source
(N
)
2410 and then Present
(Right_Opnd
(N
))
2411 and then Is_CPP_Class
(Etype
(Etype
(Right_Opnd
(N
))))
2413 Error_Msg_N
("membership test not applicable to cpp-class types", N
);
2415 end Analyze_Membership_Op
;
2417 ----------------------
2418 -- Analyze_Negation --
2419 ----------------------
2421 procedure Analyze_Negation
(N
: Node_Id
) is
2422 R
: constant Node_Id
:= Right_Opnd
(N
);
2423 Op_Id
: Entity_Id
:= Entity
(N
);
2426 Set_Etype
(N
, Any_Type
);
2427 Candidate_Type
:= Empty
;
2429 Analyze_Expression
(R
);
2431 if Present
(Op_Id
) then
2432 if Ekind
(Op_Id
) = E_Operator
then
2433 Find_Negation_Types
(R
, Op_Id
, N
);
2435 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2439 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
2440 while Present
(Op_Id
) loop
2441 if Ekind
(Op_Id
) = E_Operator
then
2442 Find_Negation_Types
(R
, Op_Id
, N
);
2444 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
2447 Op_Id
:= Homonym
(Op_Id
);
2452 end Analyze_Negation
;
2458 procedure Analyze_Null
(N
: Node_Id
) is
2460 Set_Etype
(N
, Any_Access
);
2463 ----------------------
2464 -- Analyze_One_Call --
2465 ----------------------
2467 procedure Analyze_One_Call
2471 Success
: out Boolean;
2472 Skip_First
: Boolean := False)
2474 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
2475 Prev_T
: constant Entity_Id
:= Etype
(N
);
2477 Must_Skip
: constant Boolean := Skip_First
2478 or else Nkind
(Original_Node
(N
)) = N_Selected_Component
2480 (Nkind
(Original_Node
(N
)) = N_Indexed_Component
2481 and then Nkind
(Prefix
(Original_Node
(N
)))
2482 = N_Selected_Component
);
2483 -- The first formal must be omitted from the match when trying to find
2484 -- a primitive operation that is a possible interpretation, and also
2485 -- after the call has been rewritten, because the corresponding actual
2486 -- is already known to be compatible, and because this may be an
2487 -- indexing of a call with default parameters.
2491 Is_Indexed
: Boolean := False;
2492 Is_Indirect
: Boolean := False;
2493 Subp_Type
: constant Entity_Id
:= Etype
(Nam
);
2496 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean;
2497 -- There may be a user-defined operator that hides the current
2498 -- interpretation. We must check for this independently of the
2499 -- analysis of the call with the user-defined operation, because
2500 -- the parameter names may be wrong and yet the hiding takes place.
2501 -- This fixes a problem with ACATS test B34014O.
2503 -- When the type Address is a visible integer type, and the DEC
2504 -- system extension is visible, the predefined operator may be
2505 -- hidden as well, by one of the address operations in auxdec.
2506 -- Finally, The abstract operations on address do not hide the
2507 -- predefined operator (this is the purpose of making them abstract).
2509 procedure Indicate_Name_And_Type
;
2510 -- If candidate interpretation matches, indicate name and type of
2511 -- result on call node.
2513 ----------------------------
2514 -- Indicate_Name_And_Type --
2515 ----------------------------
2517 procedure Indicate_Name_And_Type
is
2519 Add_One_Interp
(N
, Nam
, Etype
(Nam
));
2522 -- If the prefix of the call is a name, indicate the entity
2523 -- being called. If it is not a name, it is an expression that
2524 -- denotes an access to subprogram or else an entry or family. In
2525 -- the latter case, the name is a selected component, and the entity
2526 -- being called is noted on the selector.
2528 if not Is_Type
(Nam
) then
2529 if Is_Entity_Name
(Name
(N
))
2530 or else Nkind
(Name
(N
)) = N_Operator_Symbol
2532 Set_Entity
(Name
(N
), Nam
);
2534 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
2535 Set_Entity
(Selector_Name
(Name
(N
)), Nam
);
2539 if Debug_Flag_E
and not Report
then
2540 Write_Str
(" Overloaded call ");
2541 Write_Int
(Int
(N
));
2542 Write_Str
(" compatible with ");
2543 Write_Int
(Int
(Nam
));
2546 end Indicate_Name_And_Type
;
2548 ------------------------
2549 -- Operator_Hidden_By --
2550 ------------------------
2552 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean is
2553 Act1
: constant Node_Id
:= First_Actual
(N
);
2554 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
2555 Form1
: constant Entity_Id
:= First_Formal
(Fun
);
2556 Form2
: constant Entity_Id
:= Next_Formal
(Form1
);
2559 if Ekind
(Fun
) /= E_Function
2560 or else Is_Abstract_Subprogram
(Fun
)
2564 elsif not Has_Compatible_Type
(Act1
, Etype
(Form1
)) then
2567 elsif Present
(Form2
) then
2569 No
(Act2
) or else not Has_Compatible_Type
(Act2
, Etype
(Form2
))
2574 elsif Present
(Act2
) then
2578 -- Now we know that the arity of the operator matches the function,
2579 -- and the function call is a valid interpretation. The function
2580 -- hides the operator if it has the right signature, or if one of
2581 -- its operands is a non-abstract operation on Address when this is
2582 -- a visible integer type.
2584 return Hides_Op
(Fun
, Nam
)
2585 or else Is_Descendent_Of_Address
(Etype
(Form1
))
2588 and then Is_Descendent_Of_Address
(Etype
(Form2
)));
2589 end Operator_Hidden_By
;
2591 -- Start of processing for Analyze_One_Call
2596 -- If the subprogram has no formals or if all the formals have defaults,
2597 -- and the return type is an array type, the node may denote an indexing
2598 -- of the result of a parameterless call. In Ada 2005, the subprogram
2599 -- may have one non-defaulted formal, and the call may have been written
2600 -- in prefix notation, so that the rebuilt parameter list has more than
2603 if not Is_Overloadable
(Nam
)
2604 and then Ekind
(Nam
) /= E_Subprogram_Type
2605 and then Ekind
(Nam
) /= E_Entry_Family
2610 -- An indexing requires at least one actual
2612 if not Is_Empty_List
(Actuals
)
2614 (Needs_No_Actuals
(Nam
)
2616 (Needs_One_Actual
(Nam
)
2617 and then Present
(Next_Actual
(First
(Actuals
)))))
2619 if Is_Array_Type
(Subp_Type
) then
2620 Is_Indexed
:= Try_Indexed_Call
(N
, Nam
, Subp_Type
, Must_Skip
);
2622 elsif Is_Access_Type
(Subp_Type
)
2623 and then Is_Array_Type
(Designated_Type
(Subp_Type
))
2627 (N
, Nam
, Designated_Type
(Subp_Type
), Must_Skip
);
2629 -- The prefix can also be a parameterless function that returns an
2630 -- access to subprogram, in which case this is an indirect call.
2631 -- If this succeeds, an explicit dereference is added later on,
2632 -- in Analyze_Call or Resolve_Call.
2634 elsif Is_Access_Type
(Subp_Type
)
2635 and then Ekind
(Designated_Type
(Subp_Type
)) = E_Subprogram_Type
2637 Is_Indirect
:= Try_Indirect_Call
(N
, Nam
, Subp_Type
);
2642 -- If the call has been transformed into a slice, it is of the form
2643 -- F (Subtype) where F is parameterless. The node has been rewritten in
2644 -- Try_Indexed_Call and there is nothing else to do.
2647 and then Nkind
(N
) = N_Slice
2653 (N
, Nam
, (Report
and not Is_Indexed
and not Is_Indirect
), Norm_OK
);
2657 -- If an indirect call is a possible interpretation, indicate
2658 -- success to the caller.
2664 -- Mismatch in number or names of parameters
2666 elsif Debug_Flag_E
then
2667 Write_Str
(" normalization fails in call ");
2668 Write_Int
(Int
(N
));
2669 Write_Str
(" with subprogram ");
2670 Write_Int
(Int
(Nam
));
2674 -- If the context expects a function call, discard any interpretation
2675 -- that is a procedure. If the node is not overloaded, leave as is for
2676 -- better error reporting when type mismatch is found.
2678 elsif Nkind
(N
) = N_Function_Call
2679 and then Is_Overloaded
(Name
(N
))
2680 and then Ekind
(Nam
) = E_Procedure
2684 -- Ditto for function calls in a procedure context
2686 elsif Nkind
(N
) = N_Procedure_Call_Statement
2687 and then Is_Overloaded
(Name
(N
))
2688 and then Etype
(Nam
) /= Standard_Void_Type
2692 elsif No
(Actuals
) then
2694 -- If Normalize succeeds, then there are default parameters for
2697 Indicate_Name_And_Type
;
2699 elsif Ekind
(Nam
) = E_Operator
then
2700 if Nkind
(N
) = N_Procedure_Call_Statement
then
2704 -- This can occur when the prefix of the call is an operator
2705 -- name or an expanded name whose selector is an operator name.
2707 Analyze_Operator_Call
(N
, Nam
);
2709 if Etype
(N
) /= Prev_T
then
2711 -- Check that operator is not hidden by a function interpretation
2713 if Is_Overloaded
(Name
(N
)) then
2719 Get_First_Interp
(Name
(N
), I
, It
);
2720 while Present
(It
.Nam
) loop
2721 if Operator_Hidden_By
(It
.Nam
) then
2722 Set_Etype
(N
, Prev_T
);
2726 Get_Next_Interp
(I
, It
);
2731 -- If operator matches formals, record its name on the call.
2732 -- If the operator is overloaded, Resolve will select the
2733 -- correct one from the list of interpretations. The call
2734 -- node itself carries the first candidate.
2736 Set_Entity
(Name
(N
), Nam
);
2739 elsif Report
and then Etype
(N
) = Any_Type
then
2740 Error_Msg_N
("incompatible arguments for operator", N
);
2744 -- Normalize_Actuals has chained the named associations in the
2745 -- correct order of the formals.
2747 Actual
:= First_Actual
(N
);
2748 Formal
:= First_Formal
(Nam
);
2750 -- If we are analyzing a call rewritten from object notation,
2751 -- skip first actual, which may be rewritten later as an
2752 -- explicit dereference.
2755 Next_Actual
(Actual
);
2756 Next_Formal
(Formal
);
2759 while Present
(Actual
) and then Present
(Formal
) loop
2760 if Nkind
(Parent
(Actual
)) /= N_Parameter_Association
2761 or else Chars
(Selector_Name
(Parent
(Actual
))) = Chars
(Formal
)
2763 -- The actual can be compatible with the formal, but we must
2764 -- also check that the context is not an address type that is
2765 -- visibly an integer type, as is the case in VMS_64. In this
2766 -- case the use of literals is illegal, except in the body of
2767 -- descendents of system, where arithmetic operations on
2768 -- address are of course used.
2770 if Has_Compatible_Type
(Actual
, Etype
(Formal
))
2772 (Etype
(Actual
) /= Universal_Integer
2773 or else not Is_Descendent_Of_Address
(Etype
(Formal
))
2775 Is_Predefined_File_Name
2776 (Unit_File_Name
(Get_Source_Unit
(N
))))
2778 Next_Actual
(Actual
);
2779 Next_Formal
(Formal
);
2782 if Debug_Flag_E
then
2783 Write_Str
(" type checking fails in call ");
2784 Write_Int
(Int
(N
));
2785 Write_Str
(" with formal ");
2786 Write_Int
(Int
(Formal
));
2787 Write_Str
(" in subprogram ");
2788 Write_Int
(Int
(Nam
));
2792 if Report
and not Is_Indexed
and not Is_Indirect
then
2794 -- Ada 2005 (AI-251): Complete the error notification
2795 -- to help new Ada 2005 users.
2797 if Is_Class_Wide_Type
(Etype
(Formal
))
2798 and then Is_Interface
(Etype
(Etype
(Formal
)))
2799 and then not Interface_Present_In_Ancestor
2800 (Typ
=> Etype
(Actual
),
2801 Iface
=> Etype
(Etype
(Formal
)))
2804 ("(Ada 2005) does not implement interface }",
2805 Actual
, Etype
(Etype
(Formal
)));
2808 Wrong_Type
(Actual
, Etype
(Formal
));
2810 if Nkind
(Actual
) = N_Op_Eq
2811 and then Nkind
(Left_Opnd
(Actual
)) = N_Identifier
2813 Formal
:= First_Formal
(Nam
);
2814 while Present
(Formal
) loop
2815 if Chars
(Left_Opnd
(Actual
)) = Chars
(Formal
) then
2816 Error_Msg_N
-- CODEFIX
2817 ("possible misspelling of `='>`!", Actual
);
2821 Next_Formal
(Formal
);
2825 if All_Errors_Mode
then
2826 Error_Msg_Sloc
:= Sloc
(Nam
);
2828 if Is_Overloadable
(Nam
)
2829 and then Present
(Alias
(Nam
))
2830 and then not Comes_From_Source
(Nam
)
2833 ("\\ =='> in call to inherited operation & #!",
2836 elsif Ekind
(Nam
) = E_Subprogram_Type
then
2838 Access_To_Subprogram_Typ
:
2839 constant Entity_Id
:=
2841 (Associated_Node_For_Itype
(Nam
));
2844 "\\ =='> in call to dereference of &#!",
2845 Actual
, Access_To_Subprogram_Typ
);
2850 ("\\ =='> in call to &#!", Actual
, Nam
);
2860 -- Normalize_Actuals has verified that a default value exists
2861 -- for this formal. Current actual names a subsequent formal.
2863 Next_Formal
(Formal
);
2867 -- On exit, all actuals match
2869 Indicate_Name_And_Type
;
2871 end Analyze_One_Call
;
2873 ---------------------------
2874 -- Analyze_Operator_Call --
2875 ---------------------------
2877 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
) is
2878 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
2879 Act1
: constant Node_Id
:= First_Actual
(N
);
2880 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
2883 -- Binary operator case
2885 if Present
(Act2
) then
2887 -- If more than two operands, then not binary operator after all
2889 if Present
(Next_Actual
(Act2
)) then
2892 elsif Op_Name
= Name_Op_Add
2893 or else Op_Name
= Name_Op_Subtract
2894 or else Op_Name
= Name_Op_Multiply
2895 or else Op_Name
= Name_Op_Divide
2896 or else Op_Name
= Name_Op_Mod
2897 or else Op_Name
= Name_Op_Rem
2898 or else Op_Name
= Name_Op_Expon
2900 Find_Arithmetic_Types
(Act1
, Act2
, Op_Id
, N
);
2902 elsif Op_Name
= Name_Op_And
2903 or else Op_Name
= Name_Op_Or
2904 or else Op_Name
= Name_Op_Xor
2906 Find_Boolean_Types
(Act1
, Act2
, Op_Id
, N
);
2908 elsif Op_Name
= Name_Op_Lt
2909 or else Op_Name
= Name_Op_Le
2910 or else Op_Name
= Name_Op_Gt
2911 or else Op_Name
= Name_Op_Ge
2913 Find_Comparison_Types
(Act1
, Act2
, Op_Id
, N
);
2915 elsif Op_Name
= Name_Op_Eq
2916 or else Op_Name
= Name_Op_Ne
2918 Find_Equality_Types
(Act1
, Act2
, Op_Id
, N
);
2920 elsif Op_Name
= Name_Op_Concat
then
2921 Find_Concatenation_Types
(Act1
, Act2
, Op_Id
, N
);
2923 -- Is this else null correct, or should it be an abort???
2929 -- Unary operator case
2932 if Op_Name
= Name_Op_Subtract
or else
2933 Op_Name
= Name_Op_Add
or else
2934 Op_Name
= Name_Op_Abs
2936 Find_Unary_Types
(Act1
, Op_Id
, N
);
2939 Op_Name
= Name_Op_Not
2941 Find_Negation_Types
(Act1
, Op_Id
, N
);
2943 -- Is this else null correct, or should it be an abort???
2949 end Analyze_Operator_Call
;
2951 -------------------------------------------
2952 -- Analyze_Overloaded_Selected_Component --
2953 -------------------------------------------
2955 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
) is
2956 Nam
: constant Node_Id
:= Prefix
(N
);
2957 Sel
: constant Node_Id
:= Selector_Name
(N
);
2964 Set_Etype
(Sel
, Any_Type
);
2966 Get_First_Interp
(Nam
, I
, It
);
2967 while Present
(It
.Typ
) loop
2968 if Is_Access_Type
(It
.Typ
) then
2969 T
:= Designated_Type
(It
.Typ
);
2970 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
2975 if Is_Record_Type
(T
) then
2977 -- If the prefix is a class-wide type, the visible components are
2978 -- those of the base type.
2980 if Is_Class_Wide_Type
(T
) then
2984 Comp
:= First_Entity
(T
);
2985 while Present
(Comp
) loop
2986 if Chars
(Comp
) = Chars
(Sel
)
2987 and then Is_Visible_Component
(Comp
)
2990 -- AI05-105: if the context is an object renaming with
2991 -- an anonymous access type, the expected type of the
2992 -- object must be anonymous. This is a name resolution rule.
2994 if Nkind
(Parent
(N
)) /= N_Object_Renaming_Declaration
2995 or else No
(Access_Definition
(Parent
(N
)))
2996 or else Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Type
2998 Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Subprogram_Type
3000 Set_Entity
(Sel
, Comp
);
3001 Set_Etype
(Sel
, Etype
(Comp
));
3002 Add_One_Interp
(N
, Etype
(Comp
), Etype
(Comp
));
3004 -- This also specifies a candidate to resolve the name.
3005 -- Further overloading will be resolved from context.
3006 -- The selector name itself does not carry overloading
3009 Set_Etype
(Nam
, It
.Typ
);
3012 -- Named access type in the context of a renaming
3013 -- declaration with an access definition. Remove
3014 -- inapplicable candidate.
3023 elsif Is_Concurrent_Type
(T
) then
3024 Comp
:= First_Entity
(T
);
3025 while Present
(Comp
)
3026 and then Comp
/= First_Private_Entity
(T
)
3028 if Chars
(Comp
) = Chars
(Sel
) then
3029 if Is_Overloadable
(Comp
) then
3030 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
3032 Set_Entity_With_Style_Check
(Sel
, Comp
);
3033 Generate_Reference
(Comp
, Sel
);
3036 Set_Etype
(Sel
, Etype
(Comp
));
3037 Set_Etype
(N
, Etype
(Comp
));
3038 Set_Etype
(Nam
, It
.Typ
);
3040 -- For access type case, introduce explicit dereference for
3041 -- more uniform treatment of entry calls. Do this only once
3042 -- if several interpretations yield an access type.
3044 if Is_Access_Type
(Etype
(Nam
))
3045 and then Nkind
(Nam
) /= N_Explicit_Dereference
3047 Insert_Explicit_Dereference
(Nam
);
3049 (Warn_On_Dereference
, "?implicit dereference", N
);
3056 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
3059 Get_Next_Interp
(I
, It
);
3062 if Etype
(N
) = Any_Type
3063 and then not Try_Object_Operation
(N
)
3065 Error_Msg_NE
("undefined selector& for overloaded prefix", N
, Sel
);
3066 Set_Entity
(Sel
, Any_Id
);
3067 Set_Etype
(Sel
, Any_Type
);
3069 end Analyze_Overloaded_Selected_Component
;
3071 ----------------------------------
3072 -- Analyze_Qualified_Expression --
3073 ----------------------------------
3075 procedure Analyze_Qualified_Expression
(N
: Node_Id
) is
3076 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
3077 Expr
: constant Node_Id
:= Expression
(N
);
3083 Analyze_Expression
(Expr
);
3085 Set_Etype
(N
, Any_Type
);
3090 if T
= Any_Type
then
3094 Check_Fully_Declared
(T
, N
);
3096 -- If expected type is class-wide, check for exact match before
3097 -- expansion, because if the expression is a dispatching call it
3098 -- may be rewritten as explicit dereference with class-wide result.
3099 -- If expression is overloaded, retain only interpretations that
3100 -- will yield exact matches.
3102 if Is_Class_Wide_Type
(T
) then
3103 if not Is_Overloaded
(Expr
) then
3104 if Base_Type
(Etype
(Expr
)) /= Base_Type
(T
) then
3105 if Nkind
(Expr
) = N_Aggregate
then
3106 Error_Msg_N
("type of aggregate cannot be class-wide", Expr
);
3108 Wrong_Type
(Expr
, T
);
3113 Get_First_Interp
(Expr
, I
, It
);
3115 while Present
(It
.Nam
) loop
3116 if Base_Type
(It
.Typ
) /= Base_Type
(T
) then
3120 Get_Next_Interp
(I
, It
);
3126 end Analyze_Qualified_Expression
;
3132 procedure Analyze_Range
(N
: Node_Id
) is
3133 L
: constant Node_Id
:= Low_Bound
(N
);
3134 H
: constant Node_Id
:= High_Bound
(N
);
3135 I1
, I2
: Interp_Index
;
3138 procedure Check_Common_Type
(T1
, T2
: Entity_Id
);
3139 -- Verify the compatibility of two types, and choose the
3140 -- non universal one if the other is universal.
3142 procedure Check_High_Bound
(T
: Entity_Id
);
3143 -- Test one interpretation of the low bound against all those
3144 -- of the high bound.
3146 procedure Check_Universal_Expression
(N
: Node_Id
);
3147 -- In Ada83, reject bounds of a universal range that are not
3148 -- literals or entity names.
3150 -----------------------
3151 -- Check_Common_Type --
3152 -----------------------
3154 procedure Check_Common_Type
(T1
, T2
: Entity_Id
) is
3156 if Covers
(T1
=> T1
, T2
=> T2
)
3158 Covers
(T1
=> T2
, T2
=> T1
)
3160 if T1
= Universal_Integer
3161 or else T1
= Universal_Real
3162 or else T1
= Any_Character
3164 Add_One_Interp
(N
, Base_Type
(T2
), Base_Type
(T2
));
3167 Add_One_Interp
(N
, T1
, T1
);
3170 Add_One_Interp
(N
, Base_Type
(T1
), Base_Type
(T1
));
3173 end Check_Common_Type
;
3175 ----------------------
3176 -- Check_High_Bound --
3177 ----------------------
3179 procedure Check_High_Bound
(T
: Entity_Id
) is
3181 if not Is_Overloaded
(H
) then
3182 Check_Common_Type
(T
, Etype
(H
));
3184 Get_First_Interp
(H
, I2
, It2
);
3185 while Present
(It2
.Typ
) loop
3186 Check_Common_Type
(T
, It2
.Typ
);
3187 Get_Next_Interp
(I2
, It2
);
3190 end Check_High_Bound
;
3192 -----------------------------
3193 -- Is_Universal_Expression --
3194 -----------------------------
3196 procedure Check_Universal_Expression
(N
: Node_Id
) is
3198 if Etype
(N
) = Universal_Integer
3199 and then Nkind
(N
) /= N_Integer_Literal
3200 and then not Is_Entity_Name
(N
)
3201 and then Nkind
(N
) /= N_Attribute_Reference
3203 Error_Msg_N
("illegal bound in discrete range", N
);
3205 end Check_Universal_Expression
;
3207 -- Start of processing for Analyze_Range
3210 Set_Etype
(N
, Any_Type
);
3211 Analyze_Expression
(L
);
3212 Analyze_Expression
(H
);
3214 if Etype
(L
) = Any_Type
or else Etype
(H
) = Any_Type
then
3218 if not Is_Overloaded
(L
) then
3219 Check_High_Bound
(Etype
(L
));
3221 Get_First_Interp
(L
, I1
, It1
);
3222 while Present
(It1
.Typ
) loop
3223 Check_High_Bound
(It1
.Typ
);
3224 Get_Next_Interp
(I1
, It1
);
3228 -- If result is Any_Type, then we did not find a compatible pair
3230 if Etype
(N
) = Any_Type
then
3231 Error_Msg_N
("incompatible types in range ", N
);
3235 if Ada_Version
= Ada_83
3237 (Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
3238 or else Nkind
(Parent
(N
)) = N_Constrained_Array_Definition
)
3240 Check_Universal_Expression
(L
);
3241 Check_Universal_Expression
(H
);
3245 -----------------------
3246 -- Analyze_Reference --
3247 -----------------------
3249 procedure Analyze_Reference
(N
: Node_Id
) is
3250 P
: constant Node_Id
:= Prefix
(N
);
3253 Acc_Type
: Entity_Id
;
3258 -- An interesting error check, if we take the 'Reference of an object
3259 -- for which a pragma Atomic or Volatile has been given, and the type
3260 -- of the object is not Atomic or Volatile, then we are in trouble. The
3261 -- problem is that no trace of the atomic/volatile status will remain
3262 -- for the backend to respect when it deals with the resulting pointer,
3263 -- since the pointer type will not be marked atomic (it is a pointer to
3264 -- the base type of the object).
3266 -- It is not clear if that can ever occur, but in case it does, we will
3267 -- generate an error message. Not clear if this message can ever be
3268 -- generated, and pretty clear that it represents a bug if it is, still
3269 -- seems worth checking, except in CodePeer mode where we do not really
3270 -- care and don't want to bother the user.
3274 if Is_Entity_Name
(P
)
3275 and then Is_Object_Reference
(P
)
3276 and then not CodePeer_Mode
3281 if (Has_Atomic_Components
(E
)
3282 and then not Has_Atomic_Components
(T
))
3284 (Has_Volatile_Components
(E
)
3285 and then not Has_Volatile_Components
(T
))
3286 or else (Is_Atomic
(E
) and then not Is_Atomic
(T
))
3287 or else (Is_Volatile
(E
) and then not Is_Volatile
(T
))
3289 Error_Msg_N
("cannot take reference to Atomic/Volatile object", N
);
3293 -- Carry on with normal processing
3295 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
3296 Set_Etype
(Acc_Type
, Acc_Type
);
3297 Set_Directly_Designated_Type
(Acc_Type
, Etype
(P
));
3298 Set_Etype
(N
, Acc_Type
);
3299 end Analyze_Reference
;
3301 --------------------------------
3302 -- Analyze_Selected_Component --
3303 --------------------------------
3305 -- Prefix is a record type or a task or protected type. In the latter case,
3306 -- the selector must denote a visible entry.
3308 procedure Analyze_Selected_Component
(N
: Node_Id
) is
3309 Name
: constant Node_Id
:= Prefix
(N
);
3310 Sel
: constant Node_Id
:= Selector_Name
(N
);
3313 Has_Candidate
: Boolean := False;
3316 Pent
: Entity_Id
:= Empty
;
3317 Prefix_Type
: Entity_Id
;
3319 Type_To_Use
: Entity_Id
;
3320 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
3321 -- a class-wide type, we use its root type, whose components are
3322 -- present in the class-wide type.
3324 Is_Single_Concurrent_Object
: Boolean;
3325 -- Set True if the prefix is a single task or a single protected object
3327 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean;
3328 -- It is known that the parent of N denotes a subprogram call. Comp
3329 -- is an overloadable component of the concurrent type of the prefix.
3330 -- Determine whether all formals of the parent of N and Comp are mode
3331 -- conformant. If the parent node is not analyzed yet it may be an
3332 -- indexed component rather than a function call.
3334 ------------------------------
3335 -- Has_Mode_Conformant_Spec --
3336 ------------------------------
3338 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean is
3339 Comp_Param
: Entity_Id
;
3341 Param_Typ
: Entity_Id
;
3344 Comp_Param
:= First_Formal
(Comp
);
3346 if Nkind
(Parent
(N
)) = N_Indexed_Component
then
3347 Param
:= First
(Expressions
(Parent
(N
)));
3349 Param
:= First
(Parameter_Associations
(Parent
(N
)));
3352 while Present
(Comp_Param
)
3353 and then Present
(Param
)
3355 Param_Typ
:= Find_Parameter_Type
(Param
);
3357 if Present
(Param_Typ
)
3359 not Conforming_Types
3360 (Etype
(Comp_Param
), Param_Typ
, Mode_Conformant
)
3365 Next_Formal
(Comp_Param
);
3369 -- One of the specs has additional formals
3371 if Present
(Comp_Param
) or else Present
(Param
) then
3376 end Has_Mode_Conformant_Spec
;
3378 -- Start of processing for Analyze_Selected_Component
3381 Set_Etype
(N
, Any_Type
);
3383 if Is_Overloaded
(Name
) then
3384 Analyze_Overloaded_Selected_Component
(N
);
3387 elsif Etype
(Name
) = Any_Type
then
3388 Set_Entity
(Sel
, Any_Id
);
3389 Set_Etype
(Sel
, Any_Type
);
3393 Prefix_Type
:= Etype
(Name
);
3396 if Is_Access_Type
(Prefix_Type
) then
3398 -- A RACW object can never be used as prefix of a selected component
3399 -- since that means it is dereferenced without being a controlling
3400 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
3401 -- reporting an error, we must check whether this is actually a
3402 -- dispatching call in prefix form.
3404 if Is_Remote_Access_To_Class_Wide_Type
(Prefix_Type
)
3405 and then Comes_From_Source
(N
)
3407 if Try_Object_Operation
(N
) then
3411 ("invalid dereference of a remote access-to-class-wide value",
3415 -- Normal case of selected component applied to access type
3418 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
3420 if Is_Entity_Name
(Name
) then
3421 Pent
:= Entity
(Name
);
3422 elsif Nkind
(Name
) = N_Selected_Component
3423 and then Is_Entity_Name
(Selector_Name
(Name
))
3425 Pent
:= Entity
(Selector_Name
(Name
));
3428 Prefix_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, Name
);
3431 -- If we have an explicit dereference of a remote access-to-class-wide
3432 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
3433 -- have to check for the case of a prefix that is a controlling operand
3434 -- of a prefixed dispatching call, as the dereference is legal in that
3435 -- case. Normally this condition is checked in Validate_Remote_Access_
3436 -- To_Class_Wide_Type, but we have to defer the checking for selected
3437 -- component prefixes because of the prefixed dispatching call case.
3438 -- Note that implicit dereferences are checked for this just above.
3440 elsif Nkind
(Name
) = N_Explicit_Dereference
3441 and then Is_Remote_Access_To_Class_Wide_Type
(Etype
(Prefix
(Name
)))
3442 and then Comes_From_Source
(N
)
3444 if Try_Object_Operation
(N
) then
3448 ("invalid dereference of a remote access-to-class-wide value",
3453 -- (Ada 2005): if the prefix is the limited view of a type, and
3454 -- the context already includes the full view, use the full view
3455 -- in what follows, either to retrieve a component of to find
3456 -- a primitive operation. If the prefix is an explicit dereference,
3457 -- set the type of the prefix to reflect this transformation.
3458 -- If the non-limited view is itself an incomplete type, get the
3459 -- full view if available.
3461 if Is_Incomplete_Type
(Prefix_Type
)
3462 and then From_With_Type
(Prefix_Type
)
3463 and then Present
(Non_Limited_View
(Prefix_Type
))
3465 Prefix_Type
:= Get_Full_View
(Non_Limited_View
(Prefix_Type
));
3467 if Nkind
(N
) = N_Explicit_Dereference
then
3468 Set_Etype
(Prefix
(N
), Prefix_Type
);
3471 elsif Ekind
(Prefix_Type
) = E_Class_Wide_Type
3472 and then From_With_Type
(Prefix_Type
)
3473 and then Present
(Non_Limited_View
(Etype
(Prefix_Type
)))
3476 Class_Wide_Type
(Non_Limited_View
(Etype
(Prefix_Type
)));
3478 if Nkind
(N
) = N_Explicit_Dereference
then
3479 Set_Etype
(Prefix
(N
), Prefix_Type
);
3483 if Ekind
(Prefix_Type
) = E_Private_Subtype
then
3484 Prefix_Type
:= Base_Type
(Prefix_Type
);
3487 Type_To_Use
:= Prefix_Type
;
3489 -- For class-wide types, use the entity list of the root type. This
3490 -- indirection is specially important for private extensions because
3491 -- only the root type get switched (not the class-wide type).
3493 if Is_Class_Wide_Type
(Prefix_Type
) then
3494 Type_To_Use
:= Root_Type
(Prefix_Type
);
3497 -- If the prefix is a single concurrent object, use its name in error
3498 -- messages, rather than that of its anonymous type.
3500 Is_Single_Concurrent_Object
:=
3501 Is_Concurrent_Type
(Prefix_Type
)
3502 and then Is_Internal_Name
(Chars
(Prefix_Type
))
3503 and then not Is_Derived_Type
(Prefix_Type
)
3504 and then Is_Entity_Name
(Name
);
3506 Comp
:= First_Entity
(Type_To_Use
);
3508 -- If the selector has an original discriminant, the node appears in
3509 -- an instance. Replace the discriminant with the corresponding one
3510 -- in the current discriminated type. For nested generics, this must
3511 -- be done transitively, so note the new original discriminant.
3513 if Nkind
(Sel
) = N_Identifier
3514 and then Present
(Original_Discriminant
(Sel
))
3516 Comp
:= Find_Corresponding_Discriminant
(Sel
, Prefix_Type
);
3518 -- Mark entity before rewriting, for completeness and because
3519 -- subsequent semantic checks might examine the original node.
3521 Set_Entity
(Sel
, Comp
);
3522 Rewrite
(Selector_Name
(N
),
3523 New_Occurrence_Of
(Comp
, Sloc
(N
)));
3524 Set_Original_Discriminant
(Selector_Name
(N
), Comp
);
3525 Set_Etype
(N
, Etype
(Comp
));
3527 if Is_Access_Type
(Etype
(Name
)) then
3528 Insert_Explicit_Dereference
(Name
);
3529 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
3532 elsif Is_Record_Type
(Prefix_Type
) then
3534 -- Find component with given name
3536 while Present
(Comp
) loop
3537 if Chars
(Comp
) = Chars
(Sel
)
3538 and then Is_Visible_Component
(Comp
)
3540 Set_Entity_With_Style_Check
(Sel
, Comp
);
3541 Set_Etype
(Sel
, Etype
(Comp
));
3543 if Ekind
(Comp
) = E_Discriminant
then
3544 if Is_Unchecked_Union
(Base_Type
(Prefix_Type
)) then
3546 ("cannot reference discriminant of Unchecked_Union",
3550 if Is_Generic_Type
(Prefix_Type
)
3552 Is_Generic_Type
(Root_Type
(Prefix_Type
))
3554 Set_Original_Discriminant
(Sel
, Comp
);
3558 -- Resolve the prefix early otherwise it is not possible to
3559 -- build the actual subtype of the component: it may need
3560 -- to duplicate this prefix and duplication is only allowed
3561 -- on fully resolved expressions.
3565 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
3566 -- subtypes in a package specification.
3569 -- limited with Pkg;
3571 -- type Acc_Inc is access Pkg.T;
3573 -- N : Natural := X.all.Comp; -- ERROR, limited view
3574 -- end Pkg; -- Comp is not visible
3576 if Nkind
(Name
) = N_Explicit_Dereference
3577 and then From_With_Type
(Etype
(Prefix
(Name
)))
3578 and then not Is_Potentially_Use_Visible
(Etype
(Name
))
3579 and then Nkind
(Parent
(Cunit_Entity
(Current_Sem_Unit
))) =
3580 N_Package_Specification
3583 ("premature usage of incomplete}", Prefix
(Name
),
3584 Etype
(Prefix
(Name
)));
3587 -- We never need an actual subtype for the case of a selection
3588 -- for a indexed component of a non-packed array, since in
3589 -- this case gigi generates all the checks and can find the
3590 -- necessary bounds information.
3592 -- We also do not need an actual subtype for the case of a
3593 -- first, last, length, or range attribute applied to a
3594 -- non-packed array, since gigi can again get the bounds in
3595 -- these cases (gigi cannot handle the packed case, since it
3596 -- has the bounds of the packed array type, not the original
3597 -- bounds of the type). However, if the prefix is itself a
3598 -- selected component, as in a.b.c (i), gigi may regard a.b.c
3599 -- as a dynamic-sized temporary, so we do generate an actual
3600 -- subtype for this case.
3602 Parent_N
:= Parent
(N
);
3604 if not Is_Packed
(Etype
(Comp
))
3606 ((Nkind
(Parent_N
) = N_Indexed_Component
3607 and then Nkind
(Name
) /= N_Selected_Component
)
3609 (Nkind
(Parent_N
) = N_Attribute_Reference
3610 and then (Attribute_Name
(Parent_N
) = Name_First
3612 Attribute_Name
(Parent_N
) = Name_Last
3614 Attribute_Name
(Parent_N
) = Name_Length
3616 Attribute_Name
(Parent_N
) = Name_Range
)))
3618 Set_Etype
(N
, Etype
(Comp
));
3620 -- If full analysis is not enabled, we do not generate an
3621 -- actual subtype, because in the absence of expansion
3622 -- reference to a formal of a protected type, for example,
3623 -- will not be properly transformed, and will lead to
3624 -- out-of-scope references in gigi.
3626 -- In all other cases, we currently build an actual subtype.
3627 -- It seems likely that many of these cases can be avoided,
3628 -- but right now, the front end makes direct references to the
3629 -- bounds (e.g. in generating a length check), and if we do
3630 -- not make an actual subtype, we end up getting a direct
3631 -- reference to a discriminant, which will not do.
3633 elsif Full_Analysis
then
3635 Build_Actual_Subtype_Of_Component
(Etype
(Comp
), N
);
3636 Insert_Action
(N
, Act_Decl
);
3638 if No
(Act_Decl
) then
3639 Set_Etype
(N
, Etype
(Comp
));
3642 -- Component type depends on discriminants. Enter the
3643 -- main attributes of the subtype.
3646 Subt
: constant Entity_Id
:=
3647 Defining_Identifier
(Act_Decl
);
3650 Set_Etype
(Subt
, Base_Type
(Etype
(Comp
)));
3651 Set_Ekind
(Subt
, Ekind
(Etype
(Comp
)));
3652 Set_Etype
(N
, Subt
);
3656 -- If Full_Analysis not enabled, just set the Etype
3659 Set_Etype
(N
, Etype
(Comp
));
3665 -- If the prefix is a private extension, check only the visible
3666 -- components of the partial view. This must include the tag,
3667 -- which can appear in expanded code in a tag check.
3669 if Ekind
(Type_To_Use
) = E_Record_Type_With_Private
3670 and then Chars
(Selector_Name
(N
)) /= Name_uTag
3672 exit when Comp
= Last_Entity
(Type_To_Use
);
3678 -- Ada 2005 (AI-252): The selected component can be interpreted as
3679 -- a prefixed view of a subprogram. Depending on the context, this is
3680 -- either a name that can appear in a renaming declaration, or part
3681 -- of an enclosing call given in prefix form.
3683 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
3684 -- selected component should resolve to a name.
3686 if Ada_Version
>= Ada_05
3687 and then Is_Tagged_Type
(Prefix_Type
)
3688 and then not Is_Concurrent_Type
(Prefix_Type
)
3690 if Nkind
(Parent
(N
)) = N_Generic_Association
3691 or else Nkind
(Parent
(N
)) = N_Requeue_Statement
3692 or else Nkind
(Parent
(N
)) = N_Subprogram_Renaming_Declaration
3694 if Find_Primitive_Operation
(N
) then
3698 elsif Try_Object_Operation
(N
) then
3702 -- If the transformation fails, it will be necessary to redo the
3703 -- analysis with all errors enabled, to indicate candidate
3704 -- interpretations and reasons for each failure ???
3708 elsif Is_Private_Type
(Prefix_Type
) then
3710 -- Allow access only to discriminants of the type. If the type has
3711 -- no full view, gigi uses the parent type for the components, so we
3712 -- do the same here.
3714 if No
(Full_View
(Prefix_Type
)) then
3715 Type_To_Use
:= Root_Type
(Base_Type
(Prefix_Type
));
3716 Comp
:= First_Entity
(Type_To_Use
);
3719 while Present
(Comp
) loop
3720 if Chars
(Comp
) = Chars
(Sel
) then
3721 if Ekind
(Comp
) = E_Discriminant
then
3722 Set_Entity_With_Style_Check
(Sel
, Comp
);
3723 Generate_Reference
(Comp
, Sel
);
3725 Set_Etype
(Sel
, Etype
(Comp
));
3726 Set_Etype
(N
, Etype
(Comp
));
3728 if Is_Generic_Type
(Prefix_Type
)
3729 or else Is_Generic_Type
(Root_Type
(Prefix_Type
))
3731 Set_Original_Discriminant
(Sel
, Comp
);
3734 -- Before declaring an error, check whether this is tagged
3735 -- private type and a call to a primitive operation.
3737 elsif Ada_Version
>= Ada_05
3738 and then Is_Tagged_Type
(Prefix_Type
)
3739 and then Try_Object_Operation
(N
)
3744 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
3745 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
3746 Set_Entity
(Sel
, Any_Id
);
3747 Set_Etype
(N
, Any_Type
);
3756 elsif Is_Concurrent_Type
(Prefix_Type
) then
3758 -- Find visible operation with given name. For a protected type,
3759 -- the possible candidates are discriminants, entries or protected
3760 -- procedures. For a task type, the set can only include entries or
3761 -- discriminants if the task type is not an enclosing scope. If it
3762 -- is an enclosing scope (e.g. in an inner task) then all entities
3763 -- are visible, but the prefix must denote the enclosing scope, i.e.
3764 -- can only be a direct name or an expanded name.
3766 Set_Etype
(Sel
, Any_Type
);
3767 In_Scope
:= In_Open_Scopes
(Prefix_Type
);
3769 while Present
(Comp
) loop
3770 if Chars
(Comp
) = Chars
(Sel
) then
3771 if Is_Overloadable
(Comp
) then
3772 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
3774 -- If the prefix is tagged, the correct interpretation may
3775 -- lie in the primitive or class-wide operations of the
3776 -- type. Perform a simple conformance check to determine
3777 -- whether Try_Object_Operation should be invoked even if
3778 -- a visible entity is found.
3780 if Is_Tagged_Type
(Prefix_Type
)
3782 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
3784 N_Indexed_Component
)
3785 and then Has_Mode_Conformant_Spec
(Comp
)
3787 Has_Candidate
:= True;
3790 -- Note: a selected component may not denote a component of a
3791 -- protected type (4.1.3(7)).
3793 elsif Ekind_In
(Comp
, E_Discriminant
, E_Entry_Family
)
3795 and then not Is_Protected_Type
(Prefix_Type
)
3796 and then Is_Entity_Name
(Name
))
3798 Set_Entity_With_Style_Check
(Sel
, Comp
);
3799 Generate_Reference
(Comp
, Sel
);
3805 Set_Etype
(Sel
, Etype
(Comp
));
3806 Set_Etype
(N
, Etype
(Comp
));
3808 if Ekind
(Comp
) = E_Discriminant
then
3809 Set_Original_Discriminant
(Sel
, Comp
);
3812 -- For access type case, introduce explicit dereference for
3813 -- more uniform treatment of entry calls.
3815 if Is_Access_Type
(Etype
(Name
)) then
3816 Insert_Explicit_Dereference
(Name
);
3818 (Warn_On_Dereference
, "?implicit dereference", N
);
3824 exit when not In_Scope
3826 Comp
= First_Private_Entity
(Base_Type
(Prefix_Type
));
3829 -- If there is no visible entity with the given name or none of the
3830 -- visible entities are plausible interpretations, check whether
3831 -- there is some other primitive operation with that name.
3833 if Ada_Version
>= Ada_05
3834 and then Is_Tagged_Type
(Prefix_Type
)
3836 if (Etype
(N
) = Any_Type
3837 or else not Has_Candidate
)
3838 and then Try_Object_Operation
(N
)
3842 -- If the context is not syntactically a procedure call, it
3843 -- may be a call to a primitive function declared outside of
3844 -- the synchronized type.
3846 -- If the context is a procedure call, there might still be
3847 -- an overloading between an entry and a primitive procedure
3848 -- declared outside of the synchronized type, called in prefix
3849 -- notation. This is harder to disambiguate because in one case
3850 -- the controlling formal is implicit ???
3852 elsif Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
3853 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
3854 and then Try_Object_Operation
(N
)
3860 if Etype
(N
) = Any_Type
and then Is_Protected_Type
(Prefix_Type
) then
3861 -- Case of a prefix of a protected type: selector might denote
3862 -- an invisible private component.
3864 Comp
:= First_Private_Entity
(Base_Type
(Prefix_Type
));
3865 while Present
(Comp
) and then Chars
(Comp
) /= Chars
(Sel
) loop
3869 if Present
(Comp
) then
3870 if Is_Single_Concurrent_Object
then
3871 Error_Msg_Node_2
:= Entity
(Name
);
3872 Error_Msg_NE
("invisible selector& for &", N
, Sel
);
3875 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
3876 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
3882 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
3887 Error_Msg_NE
("invalid prefix in selected component&", N
, Sel
);
3890 -- If N still has no type, the component is not defined in the prefix
3892 if Etype
(N
) = Any_Type
then
3894 if Is_Single_Concurrent_Object
then
3895 Error_Msg_Node_2
:= Entity
(Name
);
3896 Error_Msg_NE
("no selector& for&", N
, Sel
);
3898 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
3900 elsif Is_Generic_Type
(Prefix_Type
)
3901 and then Ekind
(Prefix_Type
) = E_Record_Type_With_Private
3902 and then Prefix_Type
/= Etype
(Prefix_Type
)
3903 and then Is_Record_Type
(Etype
(Prefix_Type
))
3905 -- If this is a derived formal type, the parent may have
3906 -- different visibility at this point. Try for an inherited
3907 -- component before reporting an error.
3909 Set_Etype
(Prefix
(N
), Etype
(Prefix_Type
));
3910 Analyze_Selected_Component
(N
);
3913 elsif Ekind
(Prefix_Type
) = E_Record_Subtype_With_Private
3914 and then Is_Generic_Actual_Type
(Prefix_Type
)
3915 and then Present
(Full_View
(Prefix_Type
))
3917 -- Similarly, if this the actual for a formal derived type, the
3918 -- component inherited from the generic parent may not be visible
3919 -- in the actual, but the selected component is legal.
3926 First_Component
(Generic_Parent_Type
(Parent
(Prefix_Type
)));
3927 while Present
(Comp
) loop
3928 if Chars
(Comp
) = Chars
(Sel
) then
3929 Set_Entity_With_Style_Check
(Sel
, Comp
);
3930 Set_Etype
(Sel
, Etype
(Comp
));
3931 Set_Etype
(N
, Etype
(Comp
));
3935 Next_Component
(Comp
);
3938 pragma Assert
(Etype
(N
) /= Any_Type
);
3942 if Ekind
(Prefix_Type
) = E_Record_Subtype
then
3944 -- Check whether this is a component of the base type which
3945 -- is absent from a statically constrained subtype. This will
3946 -- raise constraint error at run time, but is not a compile-
3947 -- time error. When the selector is illegal for base type as
3948 -- well fall through and generate a compilation error anyway.
3950 Comp
:= First_Component
(Base_Type
(Prefix_Type
));
3951 while Present
(Comp
) loop
3952 if Chars
(Comp
) = Chars
(Sel
)
3953 and then Is_Visible_Component
(Comp
)
3955 Set_Entity_With_Style_Check
(Sel
, Comp
);
3956 Generate_Reference
(Comp
, Sel
);
3957 Set_Etype
(Sel
, Etype
(Comp
));
3958 Set_Etype
(N
, Etype
(Comp
));
3960 -- Emit appropriate message. Gigi will replace the
3961 -- node subsequently with the appropriate Raise.
3963 Apply_Compile_Time_Constraint_Error
3964 (N
, "component not present in }?",
3965 CE_Discriminant_Check_Failed
,
3966 Ent
=> Prefix_Type
, Rep
=> False);
3967 Set_Raises_Constraint_Error
(N
);
3971 Next_Component
(Comp
);
3976 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
3977 Error_Msg_NE
("no selector& for}", N
, Sel
);
3979 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
3982 Set_Entity
(Sel
, Any_Id
);
3983 Set_Etype
(Sel
, Any_Type
);
3985 end Analyze_Selected_Component
;
3987 ---------------------------
3988 -- Analyze_Short_Circuit --
3989 ---------------------------
3991 procedure Analyze_Short_Circuit
(N
: Node_Id
) is
3992 L
: constant Node_Id
:= Left_Opnd
(N
);
3993 R
: constant Node_Id
:= Right_Opnd
(N
);
3998 Analyze_Expression
(L
);
3999 Analyze_Expression
(R
);
4000 Set_Etype
(N
, Any_Type
);
4002 if not Is_Overloaded
(L
) then
4003 if Root_Type
(Etype
(L
)) = Standard_Boolean
4004 and then Has_Compatible_Type
(R
, Etype
(L
))
4006 Add_One_Interp
(N
, Etype
(L
), Etype
(L
));
4010 Get_First_Interp
(L
, Ind
, It
);
4011 while Present
(It
.Typ
) loop
4012 if Root_Type
(It
.Typ
) = Standard_Boolean
4013 and then Has_Compatible_Type
(R
, It
.Typ
)
4015 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
4018 Get_Next_Interp
(Ind
, It
);
4022 -- Here we have failed to find an interpretation. Clearly we know that
4023 -- it is not the case that both operands can have an interpretation of
4024 -- Boolean, but this is by far the most likely intended interpretation.
4025 -- So we simply resolve both operands as Booleans, and at least one of
4026 -- these resolutions will generate an error message, and we do not need
4027 -- to give another error message on the short circuit operation itself.
4029 if Etype
(N
) = Any_Type
then
4030 Resolve
(L
, Standard_Boolean
);
4031 Resolve
(R
, Standard_Boolean
);
4032 Set_Etype
(N
, Standard_Boolean
);
4034 end Analyze_Short_Circuit
;
4040 procedure Analyze_Slice
(N
: Node_Id
) is
4041 P
: constant Node_Id
:= Prefix
(N
);
4042 D
: constant Node_Id
:= Discrete_Range
(N
);
4043 Array_Type
: Entity_Id
;
4045 procedure Analyze_Overloaded_Slice
;
4046 -- If the prefix is overloaded, select those interpretations that
4047 -- yield a one-dimensional array type.
4049 ------------------------------
4050 -- Analyze_Overloaded_Slice --
4051 ------------------------------
4053 procedure Analyze_Overloaded_Slice
is
4059 Set_Etype
(N
, Any_Type
);
4061 Get_First_Interp
(P
, I
, It
);
4062 while Present
(It
.Nam
) loop
4065 if Is_Access_Type
(Typ
) then
4066 Typ
:= Designated_Type
(Typ
);
4067 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
4070 if Is_Array_Type
(Typ
)
4071 and then Number_Dimensions
(Typ
) = 1
4072 and then Has_Compatible_Type
(D
, Etype
(First_Index
(Typ
)))
4074 Add_One_Interp
(N
, Typ
, Typ
);
4077 Get_Next_Interp
(I
, It
);
4080 if Etype
(N
) = Any_Type
then
4081 Error_Msg_N
("expect array type in prefix of slice", N
);
4083 end Analyze_Overloaded_Slice
;
4085 -- Start of processing for Analyze_Slice
4091 if Is_Overloaded
(P
) then
4092 Analyze_Overloaded_Slice
;
4095 Array_Type
:= Etype
(P
);
4096 Set_Etype
(N
, Any_Type
);
4098 if Is_Access_Type
(Array_Type
) then
4099 Array_Type
:= Designated_Type
(Array_Type
);
4100 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
4103 if not Is_Array_Type
(Array_Type
) then
4104 Wrong_Type
(P
, Any_Array
);
4106 elsif Number_Dimensions
(Array_Type
) > 1 then
4108 ("type is not one-dimensional array in slice prefix", N
);
4111 Has_Compatible_Type
(D
, Etype
(First_Index
(Array_Type
)))
4113 Wrong_Type
(D
, Etype
(First_Index
(Array_Type
)));
4116 Set_Etype
(N
, Array_Type
);
4121 -----------------------------
4122 -- Analyze_Type_Conversion --
4123 -----------------------------
4125 procedure Analyze_Type_Conversion
(N
: Node_Id
) is
4126 Expr
: constant Node_Id
:= Expression
(N
);
4130 -- If Conversion_OK is set, then the Etype is already set, and the
4131 -- only processing required is to analyze the expression. This is
4132 -- used to construct certain "illegal" conversions which are not
4133 -- allowed by Ada semantics, but can be handled OK by Gigi, see
4134 -- Sinfo for further details.
4136 if Conversion_OK
(N
) then
4141 -- Otherwise full type analysis is required, as well as some semantic
4142 -- checks to make sure the argument of the conversion is appropriate.
4144 Find_Type
(Subtype_Mark
(N
));
4145 T
:= Entity
(Subtype_Mark
(N
));
4147 Check_Fully_Declared
(T
, N
);
4148 Analyze_Expression
(Expr
);
4149 Validate_Remote_Type_Type_Conversion
(N
);
4151 -- Only remaining step is validity checks on the argument. These
4152 -- are skipped if the conversion does not come from the source.
4154 if not Comes_From_Source
(N
) then
4157 -- If there was an error in a generic unit, no need to replicate the
4158 -- error message. Conversely, constant-folding in the generic may
4159 -- transform the argument of a conversion into a string literal, which
4160 -- is legal. Therefore the following tests are not performed in an
4163 elsif In_Instance
then
4166 elsif Nkind
(Expr
) = N_Null
then
4167 Error_Msg_N
("argument of conversion cannot be null", N
);
4168 Error_Msg_N
("\use qualified expression instead", N
);
4169 Set_Etype
(N
, Any_Type
);
4171 elsif Nkind
(Expr
) = N_Aggregate
then
4172 Error_Msg_N
("argument of conversion cannot be aggregate", N
);
4173 Error_Msg_N
("\use qualified expression instead", N
);
4175 elsif Nkind
(Expr
) = N_Allocator
then
4176 Error_Msg_N
("argument of conversion cannot be an allocator", N
);
4177 Error_Msg_N
("\use qualified expression instead", N
);
4179 elsif Nkind
(Expr
) = N_String_Literal
then
4180 Error_Msg_N
("argument of conversion cannot be string literal", N
);
4181 Error_Msg_N
("\use qualified expression instead", N
);
4183 elsif Nkind
(Expr
) = N_Character_Literal
then
4184 if Ada_Version
= Ada_83
then
4187 Error_Msg_N
("argument of conversion cannot be character literal",
4189 Error_Msg_N
("\use qualified expression instead", N
);
4192 elsif Nkind
(Expr
) = N_Attribute_Reference
4194 (Attribute_Name
(Expr
) = Name_Access
or else
4195 Attribute_Name
(Expr
) = Name_Unchecked_Access
or else
4196 Attribute_Name
(Expr
) = Name_Unrestricted_Access
)
4198 Error_Msg_N
("argument of conversion cannot be access", N
);
4199 Error_Msg_N
("\use qualified expression instead", N
);
4201 end Analyze_Type_Conversion
;
4203 ----------------------
4204 -- Analyze_Unary_Op --
4205 ----------------------
4207 procedure Analyze_Unary_Op
(N
: Node_Id
) is
4208 R
: constant Node_Id
:= Right_Opnd
(N
);
4209 Op_Id
: Entity_Id
:= Entity
(N
);
4212 Set_Etype
(N
, Any_Type
);
4213 Candidate_Type
:= Empty
;
4215 Analyze_Expression
(R
);
4217 if Present
(Op_Id
) then
4218 if Ekind
(Op_Id
) = E_Operator
then
4219 Find_Unary_Types
(R
, Op_Id
, N
);
4221 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
4225 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
4226 while Present
(Op_Id
) loop
4227 if Ekind
(Op_Id
) = E_Operator
then
4228 if No
(Next_Entity
(First_Entity
(Op_Id
))) then
4229 Find_Unary_Types
(R
, Op_Id
, N
);
4232 elsif Is_Overloadable
(Op_Id
) then
4233 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
4236 Op_Id
:= Homonym
(Op_Id
);
4241 end Analyze_Unary_Op
;
4243 ----------------------------------
4244 -- Analyze_Unchecked_Expression --
4245 ----------------------------------
4247 procedure Analyze_Unchecked_Expression
(N
: Node_Id
) is
4249 Analyze
(Expression
(N
), Suppress
=> All_Checks
);
4250 Set_Etype
(N
, Etype
(Expression
(N
)));
4251 Save_Interps
(Expression
(N
), N
);
4252 end Analyze_Unchecked_Expression
;
4254 ---------------------------------------
4255 -- Analyze_Unchecked_Type_Conversion --
4256 ---------------------------------------
4258 procedure Analyze_Unchecked_Type_Conversion
(N
: Node_Id
) is
4260 Find_Type
(Subtype_Mark
(N
));
4261 Analyze_Expression
(Expression
(N
));
4262 Set_Etype
(N
, Entity
(Subtype_Mark
(N
)));
4263 end Analyze_Unchecked_Type_Conversion
;
4265 ------------------------------------
4266 -- Analyze_User_Defined_Binary_Op --
4267 ------------------------------------
4269 procedure Analyze_User_Defined_Binary_Op
4274 -- Only do analysis if the operator Comes_From_Source, since otherwise
4275 -- the operator was generated by the expander, and all such operators
4276 -- always refer to the operators in package Standard.
4278 if Comes_From_Source
(N
) then
4280 F1
: constant Entity_Id
:= First_Formal
(Op_Id
);
4281 F2
: constant Entity_Id
:= Next_Formal
(F1
);
4284 -- Verify that Op_Id is a visible binary function. Note that since
4285 -- we know Op_Id is overloaded, potentially use visible means use
4286 -- visible for sure (RM 9.4(11)).
4288 if Ekind
(Op_Id
) = E_Function
4289 and then Present
(F2
)
4290 and then (Is_Immediately_Visible
(Op_Id
)
4291 or else Is_Potentially_Use_Visible
(Op_Id
))
4292 and then Has_Compatible_Type
(Left_Opnd
(N
), Etype
(F1
))
4293 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F2
))
4295 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
4297 -- If the left operand is overloaded, indicate that the
4298 -- current type is a viable candidate. This is redundant
4299 -- in most cases, but for equality and comparison operators
4300 -- where the context does not impose a type on the operands,
4301 -- setting the proper type is necessary to avoid subsequent
4302 -- ambiguities during resolution, when both user-defined and
4303 -- predefined operators may be candidates.
4305 if Is_Overloaded
(Left_Opnd
(N
)) then
4306 Set_Etype
(Left_Opnd
(N
), Etype
(F1
));
4309 if Debug_Flag_E
then
4310 Write_Str
("user defined operator ");
4311 Write_Name
(Chars
(Op_Id
));
4312 Write_Str
(" on node ");
4313 Write_Int
(Int
(N
));
4319 end Analyze_User_Defined_Binary_Op
;
4321 -----------------------------------
4322 -- Analyze_User_Defined_Unary_Op --
4323 -----------------------------------
4325 procedure Analyze_User_Defined_Unary_Op
4330 -- Only do analysis if the operator Comes_From_Source, since otherwise
4331 -- the operator was generated by the expander, and all such operators
4332 -- always refer to the operators in package Standard.
4334 if Comes_From_Source
(N
) then
4336 F
: constant Entity_Id
:= First_Formal
(Op_Id
);
4339 -- Verify that Op_Id is a visible unary function. Note that since
4340 -- we know Op_Id is overloaded, potentially use visible means use
4341 -- visible for sure (RM 9.4(11)).
4343 if Ekind
(Op_Id
) = E_Function
4344 and then No
(Next_Formal
(F
))
4345 and then (Is_Immediately_Visible
(Op_Id
)
4346 or else Is_Potentially_Use_Visible
(Op_Id
))
4347 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F
))
4349 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
4353 end Analyze_User_Defined_Unary_Op
;
4355 ---------------------------
4356 -- Check_Arithmetic_Pair --
4357 ---------------------------
4359 procedure Check_Arithmetic_Pair
4360 (T1
, T2
: Entity_Id
;
4364 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
4366 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean;
4367 -- Check whether the fixed-point type Typ has a user-defined operator
4368 -- (multiplication or division) that should hide the corresponding
4369 -- predefined operator. Used to implement Ada 2005 AI-264, to make
4370 -- such operators more visible and therefore useful.
4372 -- If the name of the operation is an expanded name with prefix
4373 -- Standard, the predefined universal fixed operator is available,
4374 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
4376 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
;
4377 -- Get specific type (i.e. non-universal type if there is one)
4383 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean is
4384 Bas
: constant Entity_Id
:= Base_Type
(Typ
);
4390 -- If the universal_fixed operation is given explicitly the rule
4391 -- concerning primitive operations of the type do not apply.
4393 if Nkind
(N
) = N_Function_Call
4394 and then Nkind
(Name
(N
)) = N_Expanded_Name
4395 and then Entity
(Prefix
(Name
(N
))) = Standard_Standard
4400 -- The operation is treated as primitive if it is declared in the
4401 -- same scope as the type, and therefore on the same entity chain.
4403 Ent
:= Next_Entity
(Typ
);
4404 while Present
(Ent
) loop
4405 if Chars
(Ent
) = Chars
(Op
) then
4406 F1
:= First_Formal
(Ent
);
4407 F2
:= Next_Formal
(F1
);
4409 -- The operation counts as primitive if either operand or
4410 -- result are of the given base type, and both operands are
4411 -- fixed point types.
4413 if (Base_Type
(Etype
(F1
)) = Bas
4414 and then Is_Fixed_Point_Type
(Etype
(F2
)))
4417 (Base_Type
(Etype
(F2
)) = Bas
4418 and then Is_Fixed_Point_Type
(Etype
(F1
)))
4421 (Base_Type
(Etype
(Ent
)) = Bas
4422 and then Is_Fixed_Point_Type
(Etype
(F1
))
4423 and then Is_Fixed_Point_Type
(Etype
(F2
)))
4439 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
is
4441 if T1
= Universal_Integer
or else T1
= Universal_Real
then
4442 return Base_Type
(T2
);
4444 return Base_Type
(T1
);
4448 -- Start of processing for Check_Arithmetic_Pair
4451 if Op_Name
= Name_Op_Add
or else Op_Name
= Name_Op_Subtract
then
4453 if Is_Numeric_Type
(T1
)
4454 and then Is_Numeric_Type
(T2
)
4455 and then (Covers
(T1
=> T1
, T2
=> T2
)
4457 Covers
(T1
=> T2
, T2
=> T1
))
4459 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
4462 elsif Op_Name
= Name_Op_Multiply
or else Op_Name
= Name_Op_Divide
then
4464 if Is_Fixed_Point_Type
(T1
)
4465 and then (Is_Fixed_Point_Type
(T2
)
4466 or else T2
= Universal_Real
)
4468 -- If Treat_Fixed_As_Integer is set then the Etype is already set
4469 -- and no further processing is required (this is the case of an
4470 -- operator constructed by Exp_Fixd for a fixed point operation)
4471 -- Otherwise add one interpretation with universal fixed result
4472 -- If the operator is given in functional notation, it comes
4473 -- from source and Fixed_As_Integer cannot apply.
4475 if (Nkind
(N
) not in N_Op
4476 or else not Treat_Fixed_As_Integer
(N
))
4478 (not Has_Fixed_Op
(T1
, Op_Id
)
4479 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
4481 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
4484 elsif Is_Fixed_Point_Type
(T2
)
4485 and then (Nkind
(N
) not in N_Op
4486 or else not Treat_Fixed_As_Integer
(N
))
4487 and then T1
= Universal_Real
4489 (not Has_Fixed_Op
(T1
, Op_Id
)
4490 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
4492 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
4494 elsif Is_Numeric_Type
(T1
)
4495 and then Is_Numeric_Type
(T2
)
4496 and then (Covers
(T1
=> T1
, T2
=> T2
)
4498 Covers
(T1
=> T2
, T2
=> T1
))
4500 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
4502 elsif Is_Fixed_Point_Type
(T1
)
4503 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
4504 or else T2
= Universal_Integer
)
4506 Add_One_Interp
(N
, Op_Id
, T1
);
4508 elsif T2
= Universal_Real
4509 and then Base_Type
(T1
) = Base_Type
(Standard_Integer
)
4510 and then Op_Name
= Name_Op_Multiply
4512 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
4514 elsif T1
= Universal_Real
4515 and then Base_Type
(T2
) = Base_Type
(Standard_Integer
)
4517 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
4519 elsif Is_Fixed_Point_Type
(T2
)
4520 and then (Base_Type
(T1
) = Base_Type
(Standard_Integer
)
4521 or else T1
= Universal_Integer
)
4522 and then Op_Name
= Name_Op_Multiply
4524 Add_One_Interp
(N
, Op_Id
, T2
);
4526 elsif T1
= Universal_Real
and then T2
= Universal_Integer
then
4527 Add_One_Interp
(N
, Op_Id
, T1
);
4529 elsif T2
= Universal_Real
4530 and then T1
= Universal_Integer
4531 and then Op_Name
= Name_Op_Multiply
4533 Add_One_Interp
(N
, Op_Id
, T2
);
4536 elsif Op_Name
= Name_Op_Mod
or else Op_Name
= Name_Op_Rem
then
4538 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
4539 -- set does not require any special processing, since the Etype is
4540 -- already set (case of operation constructed by Exp_Fixed).
4542 if Is_Integer_Type
(T1
)
4543 and then (Covers
(T1
=> T1
, T2
=> T2
)
4545 Covers
(T1
=> T2
, T2
=> T1
))
4547 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
4550 elsif Op_Name
= Name_Op_Expon
then
4551 if Is_Numeric_Type
(T1
)
4552 and then not Is_Fixed_Point_Type
(T1
)
4553 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
4554 or else T2
= Universal_Integer
)
4556 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
4559 else pragma Assert
(Nkind
(N
) in N_Op_Shift
);
4561 -- If not one of the predefined operators, the node may be one
4562 -- of the intrinsic functions. Its kind is always specific, and
4563 -- we can use it directly, rather than the name of the operation.
4565 if Is_Integer_Type
(T1
)
4566 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
4567 or else T2
= Universal_Integer
)
4569 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
4572 end Check_Arithmetic_Pair
;
4574 -------------------------------
4575 -- Check_Misspelled_Selector --
4576 -------------------------------
4578 procedure Check_Misspelled_Selector
4579 (Prefix
: Entity_Id
;
4582 Max_Suggestions
: constant := 2;
4583 Nr_Of_Suggestions
: Natural := 0;
4585 Suggestion_1
: Entity_Id
:= Empty
;
4586 Suggestion_2
: Entity_Id
:= Empty
;
4591 -- All the components of the prefix of selector Sel are matched
4592 -- against Sel and a count is maintained of possible misspellings.
4593 -- When at the end of the analysis there are one or two (not more!)
4594 -- possible misspellings, these misspellings will be suggested as
4595 -- possible correction.
4597 if not (Is_Private_Type
(Prefix
) or else Is_Record_Type
(Prefix
)) then
4599 -- Concurrent types should be handled as well ???
4604 Comp
:= First_Entity
(Prefix
);
4605 while Nr_Of_Suggestions
<= Max_Suggestions
and then Present
(Comp
) loop
4606 if Is_Visible_Component
(Comp
) then
4607 if Is_Bad_Spelling_Of
(Chars
(Comp
), Chars
(Sel
)) then
4608 Nr_Of_Suggestions
:= Nr_Of_Suggestions
+ 1;
4610 case Nr_Of_Suggestions
is
4611 when 1 => Suggestion_1
:= Comp
;
4612 when 2 => Suggestion_2
:= Comp
;
4613 when others => exit;
4618 Comp
:= Next_Entity
(Comp
);
4621 -- Report at most two suggestions
4623 if Nr_Of_Suggestions
= 1 then
4624 Error_Msg_NE
-- CODEFIX
4625 ("\possible misspelling of&", Sel
, Suggestion_1
);
4627 elsif Nr_Of_Suggestions
= 2 then
4628 Error_Msg_Node_2
:= Suggestion_2
;
4629 Error_Msg_NE
-- CODEFIX
4630 ("\possible misspelling of& or&", Sel
, Suggestion_1
);
4632 end Check_Misspelled_Selector
;
4634 ----------------------
4635 -- Defined_In_Scope --
4636 ----------------------
4638 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean
4640 S1
: constant Entity_Id
:= Scope
(Base_Type
(T
));
4643 or else (S1
= System_Aux_Id
and then S
= Scope
(S1
));
4644 end Defined_In_Scope
;
4650 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
) is
4656 Void_Interp_Seen
: Boolean := False;
4659 pragma Warnings
(Off
, Boolean);
4662 if Ada_Version
>= Ada_05
then
4663 Actual
:= First_Actual
(N
);
4664 while Present
(Actual
) loop
4666 -- Ada 2005 (AI-50217): Post an error in case of premature
4667 -- usage of an entity from the limited view.
4669 if not Analyzed
(Etype
(Actual
))
4670 and then From_With_Type
(Etype
(Actual
))
4672 Error_Msg_Qual_Level
:= 1;
4674 ("missing with_clause for scope of imported type&",
4675 Actual
, Etype
(Actual
));
4676 Error_Msg_Qual_Level
:= 0;
4679 Next_Actual
(Actual
);
4683 -- Analyze each candidate call again, with full error reporting
4687 ("no candidate interpretations match the actuals:!", Nam
);
4688 Err_Mode
:= All_Errors_Mode
;
4689 All_Errors_Mode
:= True;
4691 -- If this is a call to an operation of a concurrent type,
4692 -- the failed interpretations have been removed from the
4693 -- name. Recover them to provide full diagnostics.
4695 if Nkind
(Parent
(Nam
)) = N_Selected_Component
then
4696 Set_Entity
(Nam
, Empty
);
4697 New_Nam
:= New_Copy_Tree
(Parent
(Nam
));
4698 Set_Is_Overloaded
(New_Nam
, False);
4699 Set_Is_Overloaded
(Selector_Name
(New_Nam
), False);
4700 Set_Parent
(New_Nam
, Parent
(Parent
(Nam
)));
4701 Analyze_Selected_Component
(New_Nam
);
4702 Get_First_Interp
(Selector_Name
(New_Nam
), X
, It
);
4704 Get_First_Interp
(Nam
, X
, It
);
4707 while Present
(It
.Nam
) loop
4708 if Etype
(It
.Nam
) = Standard_Void_Type
then
4709 Void_Interp_Seen
:= True;
4712 Analyze_One_Call
(N
, It
.Nam
, True, Success
);
4713 Get_Next_Interp
(X
, It
);
4716 if Nkind
(N
) = N_Function_Call
then
4717 Get_First_Interp
(Nam
, X
, It
);
4718 while Present
(It
.Nam
) loop
4719 if Ekind_In
(It
.Nam
, E_Function
, E_Operator
) then
4722 Get_Next_Interp
(X
, It
);
4726 -- If all interpretations are procedures, this deserves a
4727 -- more precise message. Ditto if this appears as the prefix
4728 -- of a selected component, which may be a lexical error.
4731 ("\context requires function call, found procedure name", Nam
);
4733 if Nkind
(Parent
(N
)) = N_Selected_Component
4734 and then N
= Prefix
(Parent
(N
))
4736 Error_Msg_N
-- CODEFIX
4737 ("\period should probably be semicolon", Parent
(N
));
4740 elsif Nkind
(N
) = N_Procedure_Call_Statement
4741 and then not Void_Interp_Seen
4744 "\function name found in procedure call", Nam
);
4747 All_Errors_Mode
:= Err_Mode
;
4750 ---------------------------
4751 -- Find_Arithmetic_Types --
4752 ---------------------------
4754 procedure Find_Arithmetic_Types
4759 Index1
: Interp_Index
;
4760 Index2
: Interp_Index
;
4764 procedure Check_Right_Argument
(T
: Entity_Id
);
4765 -- Check right operand of operator
4767 --------------------------
4768 -- Check_Right_Argument --
4769 --------------------------
4771 procedure Check_Right_Argument
(T
: Entity_Id
) is
4773 if not Is_Overloaded
(R
) then
4774 Check_Arithmetic_Pair
(T
, Etype
(R
), Op_Id
, N
);
4776 Get_First_Interp
(R
, Index2
, It2
);
4777 while Present
(It2
.Typ
) loop
4778 Check_Arithmetic_Pair
(T
, It2
.Typ
, Op_Id
, N
);
4779 Get_Next_Interp
(Index2
, It2
);
4782 end Check_Right_Argument
;
4784 -- Start of processing for Find_Arithmetic_Types
4787 if not Is_Overloaded
(L
) then
4788 Check_Right_Argument
(Etype
(L
));
4791 Get_First_Interp
(L
, Index1
, It1
);
4792 while Present
(It1
.Typ
) loop
4793 Check_Right_Argument
(It1
.Typ
);
4794 Get_Next_Interp
(Index1
, It1
);
4798 end Find_Arithmetic_Types
;
4800 ------------------------
4801 -- Find_Boolean_Types --
4802 ------------------------
4804 procedure Find_Boolean_Types
4809 Index
: Interp_Index
;
4812 procedure Check_Numeric_Argument
(T
: Entity_Id
);
4813 -- Special case for logical operations one of whose operands is an
4814 -- integer literal. If both are literal the result is any modular type.
4816 ----------------------------
4817 -- Check_Numeric_Argument --
4818 ----------------------------
4820 procedure Check_Numeric_Argument
(T
: Entity_Id
) is
4822 if T
= Universal_Integer
then
4823 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
4825 elsif Is_Modular_Integer_Type
(T
) then
4826 Add_One_Interp
(N
, Op_Id
, T
);
4828 end Check_Numeric_Argument
;
4830 -- Start of processing for Find_Boolean_Types
4833 if not Is_Overloaded
(L
) then
4834 if Etype
(L
) = Universal_Integer
4835 or else Etype
(L
) = Any_Modular
4837 if not Is_Overloaded
(R
) then
4838 Check_Numeric_Argument
(Etype
(R
));
4841 Get_First_Interp
(R
, Index
, It
);
4842 while Present
(It
.Typ
) loop
4843 Check_Numeric_Argument
(It
.Typ
);
4844 Get_Next_Interp
(Index
, It
);
4848 -- If operands are aggregates, we must assume that they may be
4849 -- boolean arrays, and leave disambiguation for the second pass.
4850 -- If only one is an aggregate, verify that the other one has an
4851 -- interpretation as a boolean array
4853 elsif Nkind
(L
) = N_Aggregate
then
4854 if Nkind
(R
) = N_Aggregate
then
4855 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
4857 elsif not Is_Overloaded
(R
) then
4858 if Valid_Boolean_Arg
(Etype
(R
)) then
4859 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
4863 Get_First_Interp
(R
, Index
, It
);
4864 while Present
(It
.Typ
) loop
4865 if Valid_Boolean_Arg
(It
.Typ
) then
4866 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
4869 Get_Next_Interp
(Index
, It
);
4873 elsif Valid_Boolean_Arg
(Etype
(L
))
4874 and then Has_Compatible_Type
(R
, Etype
(L
))
4876 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
4880 Get_First_Interp
(L
, Index
, It
);
4881 while Present
(It
.Typ
) loop
4882 if Valid_Boolean_Arg
(It
.Typ
)
4883 and then Has_Compatible_Type
(R
, It
.Typ
)
4885 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
4888 Get_Next_Interp
(Index
, It
);
4891 end Find_Boolean_Types
;
4893 ---------------------------
4894 -- Find_Comparison_Types --
4895 ---------------------------
4897 procedure Find_Comparison_Types
4902 Index
: Interp_Index
;
4904 Found
: Boolean := False;
4907 Scop
: Entity_Id
:= Empty
;
4909 procedure Try_One_Interp
(T1
: Entity_Id
);
4910 -- Routine to try one proposed interpretation. Note that the context
4911 -- of the operator plays no role in resolving the arguments, so that
4912 -- if there is more than one interpretation of the operands that is
4913 -- compatible with comparison, the operation is ambiguous.
4915 --------------------
4916 -- Try_One_Interp --
4917 --------------------
4919 procedure Try_One_Interp
(T1
: Entity_Id
) is
4922 -- If the operator is an expanded name, then the type of the operand
4923 -- must be defined in the corresponding scope. If the type is
4924 -- universal, the context will impose the correct type.
4927 and then not Defined_In_Scope
(T1
, Scop
)
4928 and then T1
/= Universal_Integer
4929 and then T1
/= Universal_Real
4930 and then T1
/= Any_String
4931 and then T1
/= Any_Composite
4936 if Valid_Comparison_Arg
(T1
)
4937 and then Has_Compatible_Type
(R
, T1
)
4940 and then Base_Type
(T1
) /= Base_Type
(T_F
)
4942 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
4944 if It
= No_Interp
then
4945 Ambiguous_Operands
(N
);
4946 Set_Etype
(L
, Any_Type
);
4960 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
4965 -- Start of processing for Find_Comparison_Types
4968 -- If left operand is aggregate, the right operand has to
4969 -- provide a usable type for it.
4971 if Nkind
(L
) = N_Aggregate
4972 and then Nkind
(R
) /= N_Aggregate
4974 Find_Comparison_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
4978 if Nkind
(N
) = N_Function_Call
4979 and then Nkind
(Name
(N
)) = N_Expanded_Name
4981 Scop
:= Entity
(Prefix
(Name
(N
)));
4983 -- The prefix may be a package renaming, and the subsequent test
4984 -- requires the original package.
4986 if Ekind
(Scop
) = E_Package
4987 and then Present
(Renamed_Entity
(Scop
))
4989 Scop
:= Renamed_Entity
(Scop
);
4990 Set_Entity
(Prefix
(Name
(N
)), Scop
);
4994 if not Is_Overloaded
(L
) then
4995 Try_One_Interp
(Etype
(L
));
4998 Get_First_Interp
(L
, Index
, It
);
4999 while Present
(It
.Typ
) loop
5000 Try_One_Interp
(It
.Typ
);
5001 Get_Next_Interp
(Index
, It
);
5004 end Find_Comparison_Types
;
5006 ----------------------------------------
5007 -- Find_Non_Universal_Interpretations --
5008 ----------------------------------------
5010 procedure Find_Non_Universal_Interpretations
5016 Index
: Interp_Index
;
5020 if T1
= Universal_Integer
5021 or else T1
= Universal_Real
5023 if not Is_Overloaded
(R
) then
5025 (N
, Op_Id
, Standard_Boolean
, Base_Type
(Etype
(R
)));
5027 Get_First_Interp
(R
, Index
, It
);
5028 while Present
(It
.Typ
) loop
5029 if Covers
(It
.Typ
, T1
) then
5031 (N
, Op_Id
, Standard_Boolean
, Base_Type
(It
.Typ
));
5034 Get_Next_Interp
(Index
, It
);
5038 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(T1
));
5040 end Find_Non_Universal_Interpretations
;
5042 ------------------------------
5043 -- Find_Concatenation_Types --
5044 ------------------------------
5046 procedure Find_Concatenation_Types
5051 Op_Type
: constant Entity_Id
:= Etype
(Op_Id
);
5054 if Is_Array_Type
(Op_Type
)
5055 and then not Is_Limited_Type
(Op_Type
)
5057 and then (Has_Compatible_Type
(L
, Op_Type
)
5059 Has_Compatible_Type
(L
, Component_Type
(Op_Type
)))
5061 and then (Has_Compatible_Type
(R
, Op_Type
)
5063 Has_Compatible_Type
(R
, Component_Type
(Op_Type
)))
5065 Add_One_Interp
(N
, Op_Id
, Op_Type
);
5067 end Find_Concatenation_Types
;
5069 -------------------------
5070 -- Find_Equality_Types --
5071 -------------------------
5073 procedure Find_Equality_Types
5078 Index
: Interp_Index
;
5080 Found
: Boolean := False;
5083 Scop
: Entity_Id
:= Empty
;
5085 procedure Try_One_Interp
(T1
: Entity_Id
);
5086 -- The context of the equality operator plays no role in resolving the
5087 -- arguments, so that if there is more than one interpretation of the
5088 -- operands that is compatible with equality, the construct is ambiguous
5089 -- and an error can be emitted now, after trying to disambiguate, i.e.
5090 -- applying preference rules.
5092 --------------------
5093 -- Try_One_Interp --
5094 --------------------
5096 procedure Try_One_Interp
(T1
: Entity_Id
) is
5097 Bas
: constant Entity_Id
:= Base_Type
(T1
);
5100 -- If the operator is an expanded name, then the type of the operand
5101 -- must be defined in the corresponding scope. If the type is
5102 -- universal, the context will impose the correct type. An anonymous
5103 -- type for a 'Access reference is also universal in this sense, as
5104 -- the actual type is obtained from context.
5105 -- In Ada 2005, the equality operator for anonymous access types
5106 -- is declared in Standard, and preference rules apply to it.
5108 if Present
(Scop
) then
5109 if Defined_In_Scope
(T1
, Scop
)
5110 or else T1
= Universal_Integer
5111 or else T1
= Universal_Real
5112 or else T1
= Any_Access
5113 or else T1
= Any_String
5114 or else T1
= Any_Composite
5115 or else (Ekind
(T1
) = E_Access_Subprogram_Type
5116 and then not Comes_From_Source
(T1
))
5120 elsif Ekind
(T1
) = E_Anonymous_Access_Type
5121 and then Scop
= Standard_Standard
5126 -- The scope does not contain an operator for the type
5131 -- If we have infix notation, the operator must be usable.
5132 -- Within an instance, if the type is already established we
5133 -- know it is correct.
5134 -- In Ada 2005, the equality on anonymous access types is declared
5135 -- in Standard, and is always visible.
5137 elsif In_Open_Scopes
(Scope
(Bas
))
5138 or else Is_Potentially_Use_Visible
(Bas
)
5139 or else In_Use
(Bas
)
5140 or else (In_Use
(Scope
(Bas
))
5141 and then not Is_Hidden
(Bas
))
5142 or else (In_Instance
5143 and then First_Subtype
(T1
) = First_Subtype
(Etype
(R
)))
5144 or else Ekind
(T1
) = E_Anonymous_Access_Type
5149 -- Save candidate type for subsquent error message, if any
5151 if not Is_Limited_Type
(T1
) then
5152 Candidate_Type
:= T1
;
5158 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
5159 -- Do not allow anonymous access types in equality operators.
5161 if Ada_Version
< Ada_05
5162 and then Ekind
(T1
) = E_Anonymous_Access_Type
5167 if T1
/= Standard_Void_Type
5168 and then not Is_Limited_Type
(T1
)
5169 and then not Is_Limited_Composite
(T1
)
5170 and then Has_Compatible_Type
(R
, T1
)
5173 and then Base_Type
(T1
) /= Base_Type
(T_F
)
5175 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
5177 if It
= No_Interp
then
5178 Ambiguous_Operands
(N
);
5179 Set_Etype
(L
, Any_Type
);
5192 if not Analyzed
(L
) then
5196 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
5198 -- Case of operator was not visible, Etype still set to Any_Type
5200 if Etype
(N
) = Any_Type
then
5204 elsif Scop
= Standard_Standard
5205 and then Ekind
(T1
) = E_Anonymous_Access_Type
5211 -- Start of processing for Find_Equality_Types
5214 -- If left operand is aggregate, the right operand has to
5215 -- provide a usable type for it.
5217 if Nkind
(L
) = N_Aggregate
5218 and then Nkind
(R
) /= N_Aggregate
5220 Find_Equality_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
5224 if Nkind
(N
) = N_Function_Call
5225 and then Nkind
(Name
(N
)) = N_Expanded_Name
5227 Scop
:= Entity
(Prefix
(Name
(N
)));
5229 -- The prefix may be a package renaming, and the subsequent test
5230 -- requires the original package.
5232 if Ekind
(Scop
) = E_Package
5233 and then Present
(Renamed_Entity
(Scop
))
5235 Scop
:= Renamed_Entity
(Scop
);
5236 Set_Entity
(Prefix
(Name
(N
)), Scop
);
5240 if not Is_Overloaded
(L
) then
5241 Try_One_Interp
(Etype
(L
));
5244 Get_First_Interp
(L
, Index
, It
);
5245 while Present
(It
.Typ
) loop
5246 Try_One_Interp
(It
.Typ
);
5247 Get_Next_Interp
(Index
, It
);
5250 end Find_Equality_Types
;
5252 -------------------------
5253 -- Find_Negation_Types --
5254 -------------------------
5256 procedure Find_Negation_Types
5261 Index
: Interp_Index
;
5265 if not Is_Overloaded
(R
) then
5266 if Etype
(R
) = Universal_Integer
then
5267 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
5268 elsif Valid_Boolean_Arg
(Etype
(R
)) then
5269 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
5273 Get_First_Interp
(R
, Index
, It
);
5274 while Present
(It
.Typ
) loop
5275 if Valid_Boolean_Arg
(It
.Typ
) then
5276 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
5279 Get_Next_Interp
(Index
, It
);
5282 end Find_Negation_Types
;
5284 ------------------------------
5285 -- Find_Primitive_Operation --
5286 ------------------------------
5288 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean is
5289 Obj
: constant Node_Id
:= Prefix
(N
);
5290 Op
: constant Node_Id
:= Selector_Name
(N
);
5297 Set_Etype
(Op
, Any_Type
);
5299 if Is_Access_Type
(Etype
(Obj
)) then
5300 Typ
:= Designated_Type
(Etype
(Obj
));
5305 if Is_Class_Wide_Type
(Typ
) then
5306 Typ
:= Root_Type
(Typ
);
5309 Prims
:= Primitive_Operations
(Typ
);
5311 Prim
:= First_Elmt
(Prims
);
5312 while Present
(Prim
) loop
5313 if Chars
(Node
(Prim
)) = Chars
(Op
) then
5314 Add_One_Interp
(Op
, Node
(Prim
), Etype
(Node
(Prim
)));
5315 Set_Etype
(N
, Etype
(Node
(Prim
)));
5321 -- Now look for class-wide operations of the type or any of its
5322 -- ancestors by iterating over the homonyms of the selector.
5325 Cls_Type
: constant Entity_Id
:= Class_Wide_Type
(Typ
);
5329 Hom
:= Current_Entity
(Op
);
5330 while Present
(Hom
) loop
5331 if (Ekind
(Hom
) = E_Procedure
5333 Ekind
(Hom
) = E_Function
)
5334 and then Scope
(Hom
) = Scope
(Typ
)
5335 and then Present
(First_Formal
(Hom
))
5337 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
5339 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
5341 Ekind
(Etype
(First_Formal
(Hom
))) =
5342 E_Anonymous_Access_Type
5345 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
5348 Add_One_Interp
(Op
, Hom
, Etype
(Hom
));
5349 Set_Etype
(N
, Etype
(Hom
));
5352 Hom
:= Homonym
(Hom
);
5356 return Etype
(Op
) /= Any_Type
;
5357 end Find_Primitive_Operation
;
5359 ----------------------
5360 -- Find_Unary_Types --
5361 ----------------------
5363 procedure Find_Unary_Types
5368 Index
: Interp_Index
;
5372 if not Is_Overloaded
(R
) then
5373 if Is_Numeric_Type
(Etype
(R
)) then
5374 Add_One_Interp
(N
, Op_Id
, Base_Type
(Etype
(R
)));
5378 Get_First_Interp
(R
, Index
, It
);
5379 while Present
(It
.Typ
) loop
5380 if Is_Numeric_Type
(It
.Typ
) then
5381 Add_One_Interp
(N
, Op_Id
, Base_Type
(It
.Typ
));
5384 Get_Next_Interp
(Index
, It
);
5387 end Find_Unary_Types
;
5393 function Junk_Operand
(N
: Node_Id
) return Boolean is
5397 if Error_Posted
(N
) then
5401 -- Get entity to be tested
5403 if Is_Entity_Name
(N
)
5404 and then Present
(Entity
(N
))
5408 -- An odd case, a procedure name gets converted to a very peculiar
5409 -- function call, and here is where we detect this happening.
5411 elsif Nkind
(N
) = N_Function_Call
5412 and then Is_Entity_Name
(Name
(N
))
5413 and then Present
(Entity
(Name
(N
)))
5417 -- Another odd case, there are at least some cases of selected
5418 -- components where the selected component is not marked as having
5419 -- an entity, even though the selector does have an entity
5421 elsif Nkind
(N
) = N_Selected_Component
5422 and then Present
(Entity
(Selector_Name
(N
)))
5424 Enode
:= Selector_Name
(N
);
5430 -- Now test the entity we got to see if it is a bad case
5432 case Ekind
(Entity
(Enode
)) is
5436 ("package name cannot be used as operand", Enode
);
5438 when Generic_Unit_Kind
=>
5440 ("generic unit name cannot be used as operand", Enode
);
5444 ("subtype name cannot be used as operand", Enode
);
5448 ("entry name cannot be used as operand", Enode
);
5452 ("procedure name cannot be used as operand", Enode
);
5456 ("exception name cannot be used as operand", Enode
);
5458 when E_Block | E_Label | E_Loop
=>
5460 ("label name cannot be used as operand", Enode
);
5470 --------------------
5471 -- Operator_Check --
5472 --------------------
5474 procedure Operator_Check
(N
: Node_Id
) is
5476 Remove_Abstract_Operations
(N
);
5478 -- Test for case of no interpretation found for operator
5480 if Etype
(N
) = Any_Type
then
5484 Op_Id
: Entity_Id
:= Empty
;
5487 R
:= Right_Opnd
(N
);
5489 if Nkind
(N
) in N_Binary_Op
then
5495 -- If either operand has no type, then don't complain further,
5496 -- since this simply means that we have a propagated error.
5499 or else Etype
(R
) = Any_Type
5500 or else (Nkind
(N
) in N_Binary_Op
and then Etype
(L
) = Any_Type
)
5504 -- We explicitly check for the case of concatenation of component
5505 -- with component to avoid reporting spurious matching array types
5506 -- that might happen to be lurking in distant packages (such as
5507 -- run-time packages). This also prevents inconsistencies in the
5508 -- messages for certain ACVC B tests, which can vary depending on
5509 -- types declared in run-time interfaces. Another improvement when
5510 -- aggregates are present is to look for a well-typed operand.
5512 elsif Present
(Candidate_Type
)
5513 and then (Nkind
(N
) /= N_Op_Concat
5514 or else Is_Array_Type
(Etype
(L
))
5515 or else Is_Array_Type
(Etype
(R
)))
5518 if Nkind
(N
) = N_Op_Concat
then
5519 if Etype
(L
) /= Any_Composite
5520 and then Is_Array_Type
(Etype
(L
))
5522 Candidate_Type
:= Etype
(L
);
5524 elsif Etype
(R
) /= Any_Composite
5525 and then Is_Array_Type
(Etype
(R
))
5527 Candidate_Type
:= Etype
(R
);
5531 Error_Msg_NE
-- CODEFIX
5532 ("operator for} is not directly visible!",
5533 N
, First_Subtype
(Candidate_Type
));
5534 Error_Msg_N
-- CODEFIX
5535 ("use clause would make operation legal!", N
);
5538 -- If either operand is a junk operand (e.g. package name), then
5539 -- post appropriate error messages, but do not complain further.
5541 -- Note that the use of OR in this test instead of OR ELSE is
5542 -- quite deliberate, we may as well check both operands in the
5543 -- binary operator case.
5545 elsif Junk_Operand
(R
)
5546 or (Nkind
(N
) in N_Binary_Op
and then Junk_Operand
(L
))
5550 -- If we have a logical operator, one of whose operands is
5551 -- Boolean, then we know that the other operand cannot resolve to
5552 -- Boolean (since we got no interpretations), but in that case we
5553 -- pretty much know that the other operand should be Boolean, so
5554 -- resolve it that way (generating an error)
5556 elsif Nkind_In
(N
, N_Op_And
, N_Op_Or
, N_Op_Xor
) then
5557 if Etype
(L
) = Standard_Boolean
then
5558 Resolve
(R
, Standard_Boolean
);
5560 elsif Etype
(R
) = Standard_Boolean
then
5561 Resolve
(L
, Standard_Boolean
);
5565 -- For an arithmetic operator or comparison operator, if one
5566 -- of the operands is numeric, then we know the other operand
5567 -- is not the same numeric type. If it is a non-numeric type,
5568 -- then probably it is intended to match the other operand.
5570 elsif Nkind_In
(N
, N_Op_Add
,
5576 Nkind_In
(N
, N_Op_Lt
,
5582 if Is_Numeric_Type
(Etype
(L
))
5583 and then not Is_Numeric_Type
(Etype
(R
))
5585 Resolve
(R
, Etype
(L
));
5588 elsif Is_Numeric_Type
(Etype
(R
))
5589 and then not Is_Numeric_Type
(Etype
(L
))
5591 Resolve
(L
, Etype
(R
));
5595 -- Comparisons on A'Access are common enough to deserve a
5598 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
)
5599 and then Ekind
(Etype
(L
)) = E_Access_Attribute_Type
5600 and then Ekind
(Etype
(R
)) = E_Access_Attribute_Type
5603 ("two access attributes cannot be compared directly", N
);
5605 ("\use qualified expression for one of the operands",
5609 -- Another one for C programmers
5611 elsif Nkind
(N
) = N_Op_Concat
5612 and then Valid_Boolean_Arg
(Etype
(L
))
5613 and then Valid_Boolean_Arg
(Etype
(R
))
5615 Error_Msg_N
("invalid operands for concatenation", N
);
5616 Error_Msg_N
-- CODEFIX
5617 ("\maybe AND was meant", N
);
5620 -- A special case for comparison of access parameter with null
5622 elsif Nkind
(N
) = N_Op_Eq
5623 and then Is_Entity_Name
(L
)
5624 and then Nkind
(Parent
(Entity
(L
))) = N_Parameter_Specification
5625 and then Nkind
(Parameter_Type
(Parent
(Entity
(L
)))) =
5627 and then Nkind
(R
) = N_Null
5629 Error_Msg_N
("access parameter is not allowed to be null", L
);
5630 Error_Msg_N
("\(call would raise Constraint_Error)", L
);
5633 -- Another special case for exponentiation, where the right
5634 -- operand must be Natural, independently of the base.
5636 elsif Nkind
(N
) = N_Op_Expon
5637 and then Is_Numeric_Type
(Etype
(L
))
5638 and then not Is_Overloaded
(R
)
5640 First_Subtype
(Base_Type
(Etype
(R
))) /= Standard_Integer
5641 and then Base_Type
(Etype
(R
)) /= Universal_Integer
5644 ("exponent must be of type Natural, found}", R
, Etype
(R
));
5648 -- If we fall through then just give general message. Note that in
5649 -- the following messages, if the operand is overloaded we choose
5650 -- an arbitrary type to complain about, but that is probably more
5651 -- useful than not giving a type at all.
5653 if Nkind
(N
) in N_Unary_Op
then
5654 Error_Msg_Node_2
:= Etype
(R
);
5655 Error_Msg_N
("operator& not defined for}", N
);
5659 if Nkind
(N
) in N_Binary_Op
then
5660 if not Is_Overloaded
(L
)
5661 and then not Is_Overloaded
(R
)
5662 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
5664 Error_Msg_Node_2
:= First_Subtype
(Etype
(R
));
5665 Error_Msg_N
("there is no applicable operator& for}", N
);
5668 -- Another attempt to find a fix: one of the candidate
5669 -- interpretations may not be use-visible. This has
5670 -- already been checked for predefined operators, so
5671 -- we examine only user-defined functions.
5673 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
5675 while Present
(Op_Id
) loop
5676 if Ekind
(Op_Id
) /= E_Operator
5677 and then Is_Overloadable
(Op_Id
)
5679 if not Is_Immediately_Visible
(Op_Id
)
5680 and then not In_Use
(Scope
(Op_Id
))
5681 and then not Is_Abstract_Subprogram
(Op_Id
)
5682 and then not Is_Hidden
(Op_Id
)
5683 and then Ekind
(Scope
(Op_Id
)) = E_Package
5686 (L
, Etype
(First_Formal
(Op_Id
)))
5688 (Next_Formal
(First_Formal
(Op_Id
)))
5692 Etype
(Next_Formal
(First_Formal
(Op_Id
))))
5695 ("No legal interpretation for operator&", N
);
5697 ("\use clause on& would make operation legal",
5703 Op_Id
:= Homonym
(Op_Id
);
5707 Error_Msg_N
("invalid operand types for operator&", N
);
5709 if Nkind
(N
) /= N_Op_Concat
then
5710 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
5711 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
5721 -----------------------------------------
5722 -- Process_Implicit_Dereference_Prefix --
5723 -----------------------------------------
5725 function Process_Implicit_Dereference_Prefix
5727 P
: Entity_Id
) return Entity_Id
5730 Typ
: constant Entity_Id
:= Designated_Type
(Etype
(P
));
5734 and then (Operating_Mode
= Check_Semantics
or else not Expander_Active
)
5736 -- We create a dummy reference to E to ensure that the reference
5737 -- is not considered as part of an assignment (an implicit
5738 -- dereference can never assign to its prefix). The Comes_From_Source
5739 -- attribute needs to be propagated for accurate warnings.
5741 Ref
:= New_Reference_To
(E
, Sloc
(P
));
5742 Set_Comes_From_Source
(Ref
, Comes_From_Source
(P
));
5743 Generate_Reference
(E
, Ref
);
5746 -- An implicit dereference is a legal occurrence of an
5747 -- incomplete type imported through a limited_with clause,
5748 -- if the full view is visible.
5750 if From_With_Type
(Typ
)
5751 and then not From_With_Type
(Scope
(Typ
))
5753 (Is_Immediately_Visible
(Scope
(Typ
))
5755 (Is_Child_Unit
(Scope
(Typ
))
5756 and then Is_Visible_Child_Unit
(Scope
(Typ
))))
5758 return Available_View
(Typ
);
5763 end Process_Implicit_Dereference_Prefix
;
5765 --------------------------------
5766 -- Remove_Abstract_Operations --
5767 --------------------------------
5769 procedure Remove_Abstract_Operations
(N
: Node_Id
) is
5770 Abstract_Op
: Entity_Id
:= Empty
;
5771 Address_Kludge
: Boolean := False;
5775 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
5776 -- activate this if either extensions are enabled, or if the abstract
5777 -- operation in question comes from a predefined file. This latter test
5778 -- allows us to use abstract to make operations invisible to users. In
5779 -- particular, if type Address is non-private and abstract subprograms
5780 -- are used to hide its operators, they will be truly hidden.
5782 type Operand_Position
is (First_Op
, Second_Op
);
5783 Univ_Type
: constant Entity_Id
:= Universal_Interpretation
(N
);
5785 procedure Remove_Address_Interpretations
(Op
: Operand_Position
);
5786 -- Ambiguities may arise when the operands are literal and the address
5787 -- operations in s-auxdec are visible. In that case, remove the
5788 -- interpretation of a literal as Address, to retain the semantics of
5789 -- Address as a private type.
5791 ------------------------------------
5792 -- Remove_Address_Interpretations --
5793 ------------------------------------
5795 procedure Remove_Address_Interpretations
(Op
: Operand_Position
) is
5799 if Is_Overloaded
(N
) then
5800 Get_First_Interp
(N
, I
, It
);
5801 while Present
(It
.Nam
) loop
5802 Formal
:= First_Entity
(It
.Nam
);
5804 if Op
= Second_Op
then
5805 Formal
:= Next_Entity
(Formal
);
5808 if Is_Descendent_Of_Address
(Etype
(Formal
)) then
5809 Address_Kludge
:= True;
5813 Get_Next_Interp
(I
, It
);
5816 end Remove_Address_Interpretations
;
5818 -- Start of processing for Remove_Abstract_Operations
5821 if Is_Overloaded
(N
) then
5822 Get_First_Interp
(N
, I
, It
);
5824 while Present
(It
.Nam
) loop
5825 if Is_Overloadable
(It
.Nam
)
5826 and then Is_Abstract_Subprogram
(It
.Nam
)
5827 and then not Is_Dispatching_Operation
(It
.Nam
)
5829 Abstract_Op
:= It
.Nam
;
5831 if Is_Descendent_Of_Address
(It
.Typ
) then
5832 Address_Kludge
:= True;
5836 -- In Ada 2005, this operation does not participate in Overload
5837 -- resolution. If the operation is defined in a predefined
5838 -- unit, it is one of the operations declared abstract in some
5839 -- variants of System, and it must be removed as well.
5841 elsif Ada_Version
>= Ada_05
5842 or else Is_Predefined_File_Name
5843 (Unit_File_Name
(Get_Source_Unit
(It
.Nam
)))
5850 Get_Next_Interp
(I
, It
);
5853 if No
(Abstract_Op
) then
5855 -- If some interpretation yields an integer type, it is still
5856 -- possible that there are address interpretations. Remove them
5857 -- if one operand is a literal, to avoid spurious ambiguities
5858 -- on systems where Address is a visible integer type.
5860 if Is_Overloaded
(N
)
5861 and then Nkind
(N
) in N_Op
5862 and then Is_Integer_Type
(Etype
(N
))
5864 if Nkind
(N
) in N_Binary_Op
then
5865 if Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
5866 Remove_Address_Interpretations
(Second_Op
);
5868 elsif Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
5869 Remove_Address_Interpretations
(First_Op
);
5874 elsif Nkind
(N
) in N_Op
then
5876 -- Remove interpretations that treat literals as addresses. This
5877 -- is never appropriate, even when Address is defined as a visible
5878 -- Integer type. The reason is that we would really prefer Address
5879 -- to behave as a private type, even in this case, which is there
5880 -- only to accommodate oddities of VMS address sizes. If Address
5881 -- is a visible integer type, we get lots of overload ambiguities.
5883 if Nkind
(N
) in N_Binary_Op
then
5885 U1
: constant Boolean :=
5886 Present
(Universal_Interpretation
(Right_Opnd
(N
)));
5887 U2
: constant Boolean :=
5888 Present
(Universal_Interpretation
(Left_Opnd
(N
)));
5892 Remove_Address_Interpretations
(Second_Op
);
5896 Remove_Address_Interpretations
(First_Op
);
5899 if not (U1
and U2
) then
5901 -- Remove corresponding predefined operator, which is
5902 -- always added to the overload set.
5904 Get_First_Interp
(N
, I
, It
);
5905 while Present
(It
.Nam
) loop
5906 if Scope
(It
.Nam
) = Standard_Standard
5907 and then Base_Type
(It
.Typ
) =
5908 Base_Type
(Etype
(Abstract_Op
))
5913 Get_Next_Interp
(I
, It
);
5916 elsif Is_Overloaded
(N
)
5917 and then Present
(Univ_Type
)
5919 -- If both operands have a universal interpretation,
5920 -- it is still necessary to remove interpretations that
5921 -- yield Address. Any remaining ambiguities will be
5922 -- removed in Disambiguate.
5924 Get_First_Interp
(N
, I
, It
);
5925 while Present
(It
.Nam
) loop
5926 if Is_Descendent_Of_Address
(It
.Typ
) then
5929 elsif not Is_Type
(It
.Nam
) then
5930 Set_Entity
(N
, It
.Nam
);
5933 Get_Next_Interp
(I
, It
);
5939 elsif Nkind
(N
) = N_Function_Call
5941 (Nkind
(Name
(N
)) = N_Operator_Symbol
5943 (Nkind
(Name
(N
)) = N_Expanded_Name
5945 Nkind
(Selector_Name
(Name
(N
))) = N_Operator_Symbol
))
5949 Arg1
: constant Node_Id
:= First
(Parameter_Associations
(N
));
5950 U1
: constant Boolean :=
5951 Present
(Universal_Interpretation
(Arg1
));
5952 U2
: constant Boolean :=
5953 Present
(Next
(Arg1
)) and then
5954 Present
(Universal_Interpretation
(Next
(Arg1
)));
5958 Remove_Address_Interpretations
(First_Op
);
5962 Remove_Address_Interpretations
(Second_Op
);
5965 if not (U1
and U2
) then
5966 Get_First_Interp
(N
, I
, It
);
5967 while Present
(It
.Nam
) loop
5968 if Scope
(It
.Nam
) = Standard_Standard
5969 and then It
.Typ
= Base_Type
(Etype
(Abstract_Op
))
5974 Get_Next_Interp
(I
, It
);
5980 -- If the removal has left no valid interpretations, emit an error
5981 -- message now and label node as illegal.
5983 if Present
(Abstract_Op
) then
5984 Get_First_Interp
(N
, I
, It
);
5988 -- Removal of abstract operation left no viable candidate
5990 Set_Etype
(N
, Any_Type
);
5991 Error_Msg_Sloc
:= Sloc
(Abstract_Op
);
5993 ("cannot call abstract operation& declared#", N
, Abstract_Op
);
5995 -- In Ada 2005, an abstract operation may disable predefined
5996 -- operators. Since the context is not yet known, we mark the
5997 -- predefined operators as potentially hidden. Do not include
5998 -- predefined operators when addresses are involved since this
5999 -- case is handled separately.
6001 elsif Ada_Version
>= Ada_05
6002 and then not Address_Kludge
6004 while Present
(It
.Nam
) loop
6005 if Is_Numeric_Type
(It
.Typ
)
6006 and then Scope
(It
.Typ
) = Standard_Standard
6008 Set_Abstract_Op
(I
, Abstract_Op
);
6011 Get_Next_Interp
(I
, It
);
6016 end Remove_Abstract_Operations
;
6018 -----------------------
6019 -- Try_Indirect_Call --
6020 -----------------------
6022 function Try_Indirect_Call
6025 Typ
: Entity_Id
) return Boolean
6031 pragma Warnings
(Off
, Call_OK
);
6034 Normalize_Actuals
(N
, Designated_Type
(Typ
), False, Call_OK
);
6036 Actual
:= First_Actual
(N
);
6037 Formal
:= First_Formal
(Designated_Type
(Typ
));
6038 while Present
(Actual
) and then Present
(Formal
) loop
6039 if not Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
6044 Next_Formal
(Formal
);
6047 if No
(Actual
) and then No
(Formal
) then
6048 Add_One_Interp
(N
, Nam
, Etype
(Designated_Type
(Typ
)));
6050 -- Nam is a candidate interpretation for the name in the call,
6051 -- if it is not an indirect call.
6053 if not Is_Type
(Nam
)
6054 and then Is_Entity_Name
(Name
(N
))
6056 Set_Entity
(Name
(N
), Nam
);
6063 end Try_Indirect_Call
;
6065 ----------------------
6066 -- Try_Indexed_Call --
6067 ----------------------
6069 function Try_Indexed_Call
6073 Skip_First
: Boolean) return Boolean
6075 Loc
: constant Source_Ptr
:= Sloc
(N
);
6076 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
6081 Actual
:= First
(Actuals
);
6083 -- If the call was originally written in prefix form, skip the first
6084 -- actual, which is obviously not defaulted.
6090 Index
:= First_Index
(Typ
);
6091 while Present
(Actual
) and then Present
(Index
) loop
6093 -- If the parameter list has a named association, the expression
6094 -- is definitely a call and not an indexed component.
6096 if Nkind
(Actual
) = N_Parameter_Association
then
6100 if Is_Entity_Name
(Actual
)
6101 and then Is_Type
(Entity
(Actual
))
6102 and then No
(Next
(Actual
))
6106 Prefix
=> Make_Function_Call
(Loc
,
6107 Name
=> Relocate_Node
(Name
(N
))),
6109 New_Occurrence_Of
(Entity
(Actual
), Sloc
(Actual
))));
6114 elsif not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
6122 if No
(Actual
) and then No
(Index
) then
6123 Add_One_Interp
(N
, Nam
, Component_Type
(Typ
));
6125 -- Nam is a candidate interpretation for the name in the call,
6126 -- if it is not an indirect call.
6128 if not Is_Type
(Nam
)
6129 and then Is_Entity_Name
(Name
(N
))
6131 Set_Entity
(Name
(N
), Nam
);
6138 end Try_Indexed_Call
;
6140 --------------------------
6141 -- Try_Object_Operation --
6142 --------------------------
6144 function Try_Object_Operation
(N
: Node_Id
) return Boolean is
6145 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
6146 Is_Subprg_Call
: constant Boolean := Nkind_In
6147 (K
, N_Procedure_Call_Statement
,
6149 Loc
: constant Source_Ptr
:= Sloc
(N
);
6150 Obj
: constant Node_Id
:= Prefix
(N
);
6152 Subprog
: constant Node_Id
:=
6153 Make_Identifier
(Sloc
(Selector_Name
(N
)),
6154 Chars
=> Chars
(Selector_Name
(N
)));
6155 -- Identifier on which possible interpretations will be collected
6157 Report_Error
: Boolean := False;
6158 -- If no candidate interpretation matches the context, redo the
6159 -- analysis with error enabled to provide additional information.
6162 Candidate
: Entity_Id
:= Empty
;
6163 New_Call_Node
: Node_Id
:= Empty
;
6164 Node_To_Replace
: Node_Id
;
6165 Obj_Type
: Entity_Id
:= Etype
(Obj
);
6166 Success
: Boolean := False;
6168 function Valid_Candidate
6171 Subp
: Entity_Id
) return Entity_Id
;
6172 -- If the subprogram is a valid interpretation, record it, and add
6173 -- to the list of interpretations of Subprog.
6175 procedure Complete_Object_Operation
6176 (Call_Node
: Node_Id
;
6177 Node_To_Replace
: Node_Id
);
6178 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
6179 -- Call_Node, insert the object (or its dereference) as the first actual
6180 -- in the call, and complete the analysis of the call.
6182 procedure Report_Ambiguity
(Op
: Entity_Id
);
6183 -- If a prefixed procedure call is ambiguous, indicate whether the
6184 -- call includes an implicit dereference or an implicit 'Access.
6186 procedure Transform_Object_Operation
6187 (Call_Node
: out Node_Id
;
6188 Node_To_Replace
: out Node_Id
);
6189 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
6190 -- Call_Node is the resulting subprogram call, Node_To_Replace is
6191 -- either N or the parent of N, and Subprog is a reference to the
6192 -- subprogram we are trying to match.
6194 function Try_Class_Wide_Operation
6195 (Call_Node
: Node_Id
;
6196 Node_To_Replace
: Node_Id
) return Boolean;
6197 -- Traverse all ancestor types looking for a class-wide subprogram
6198 -- for which the current operation is a valid non-dispatching call.
6200 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
);
6201 -- If prefix is overloaded, its interpretation may include different
6202 -- tagged types, and we must examine the primitive operations and
6203 -- the class-wide operations of each in order to find candidate
6204 -- interpretations for the call as a whole.
6206 function Try_Primitive_Operation
6207 (Call_Node
: Node_Id
;
6208 Node_To_Replace
: Node_Id
) return Boolean;
6209 -- Traverse the list of primitive subprograms looking for a dispatching
6210 -- operation for which the current node is a valid call .
6212 ---------------------
6213 -- Valid_Candidate --
6214 ---------------------
6216 function Valid_Candidate
6219 Subp
: Entity_Id
) return Entity_Id
6221 Arr_Type
: Entity_Id
;
6222 Comp_Type
: Entity_Id
;
6225 -- If the subprogram is a valid interpretation, record it in global
6226 -- variable Subprog, to collect all possible overloadings.
6229 if Subp
/= Entity
(Subprog
) then
6230 Add_One_Interp
(Subprog
, Subp
, Etype
(Subp
));
6234 -- If the call may be an indexed call, retrieve component type of
6235 -- resulting expression, and add possible interpretation.
6240 if Nkind
(Call
) = N_Function_Call
6241 and then Nkind
(Parent
(N
)) = N_Indexed_Component
6242 and then Needs_One_Actual
(Subp
)
6244 if Is_Array_Type
(Etype
(Subp
)) then
6245 Arr_Type
:= Etype
(Subp
);
6247 elsif Is_Access_Type
(Etype
(Subp
))
6248 and then Is_Array_Type
(Designated_Type
(Etype
(Subp
)))
6250 Arr_Type
:= Designated_Type
(Etype
(Subp
));
6254 if Present
(Arr_Type
) then
6256 -- Verify that the actuals (excluding the object)
6257 -- match the types of the indices.
6264 Actual
:= Next
(First_Actual
(Call
));
6265 Index
:= First_Index
(Arr_Type
);
6266 while Present
(Actual
) and then Present
(Index
) loop
6267 if not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
6272 Next_Actual
(Actual
);
6278 and then Present
(Arr_Type
)
6280 Comp_Type
:= Component_Type
(Arr_Type
);
6284 if Present
(Comp_Type
)
6285 and then Etype
(Subprog
) /= Comp_Type
6287 Add_One_Interp
(Subprog
, Subp
, Comp_Type
);
6291 if Etype
(Call
) /= Any_Type
then
6296 end Valid_Candidate
;
6298 -------------------------------
6299 -- Complete_Object_Operation --
6300 -------------------------------
6302 procedure Complete_Object_Operation
6303 (Call_Node
: Node_Id
;
6304 Node_To_Replace
: Node_Id
)
6306 Control
: constant Entity_Id
:= First_Formal
(Entity
(Subprog
));
6307 Formal_Type
: constant Entity_Id
:= Etype
(Control
);
6308 First_Actual
: Node_Id
;
6311 -- Place the name of the operation, with its interpretations,
6312 -- on the rewritten call.
6314 Set_Name
(Call_Node
, Subprog
);
6316 First_Actual
:= First
(Parameter_Associations
(Call_Node
));
6318 -- For cross-reference purposes, treat the new node as being in
6319 -- the source if the original one is.
6321 Set_Comes_From_Source
(Subprog
, Comes_From_Source
(N
));
6322 Set_Comes_From_Source
(Call_Node
, Comes_From_Source
(N
));
6324 if Nkind
(N
) = N_Selected_Component
6325 and then not Inside_A_Generic
6327 Set_Entity
(Selector_Name
(N
), Entity
(Subprog
));
6330 -- If need be, rewrite first actual as an explicit dereference
6331 -- If the call is overloaded, the rewriting can only be done
6332 -- once the primitive operation is identified.
6334 if Is_Overloaded
(Subprog
) then
6336 -- The prefix itself may be overloaded, and its interpretations
6337 -- must be propagated to the new actual in the call.
6339 if Is_Overloaded
(Obj
) then
6340 Save_Interps
(Obj
, First_Actual
);
6343 Rewrite
(First_Actual
, Obj
);
6345 elsif not Is_Access_Type
(Formal_Type
)
6346 and then Is_Access_Type
(Etype
(Obj
))
6348 Rewrite
(First_Actual
,
6349 Make_Explicit_Dereference
(Sloc
(Obj
), Obj
));
6350 Analyze
(First_Actual
);
6352 -- If we need to introduce an explicit dereference, verify that
6353 -- the resulting actual is compatible with the mode of the formal.
6355 if Ekind
(First_Formal
(Entity
(Subprog
))) /= E_In_Parameter
6356 and then Is_Access_Constant
(Etype
(Obj
))
6359 ("expect variable in call to&", Prefix
(N
), Entity
(Subprog
));
6362 -- Conversely, if the formal is an access parameter and the object
6363 -- is not, replace the actual with a 'Access reference. Its analysis
6364 -- will check that the object is aliased.
6366 elsif Is_Access_Type
(Formal_Type
)
6367 and then not Is_Access_Type
(Etype
(Obj
))
6369 -- A special case: A.all'access is illegal if A is an access to a
6370 -- constant and the context requires an access to a variable.
6372 if not Is_Access_Constant
(Formal_Type
) then
6373 if (Nkind
(Obj
) = N_Explicit_Dereference
6374 and then Is_Access_Constant
(Etype
(Prefix
(Obj
))))
6375 or else not Is_Variable
(Obj
)
6378 ("actual for& must be a variable", Obj
, Control
);
6382 Rewrite
(First_Actual
,
6383 Make_Attribute_Reference
(Loc
,
6384 Attribute_Name
=> Name_Access
,
6385 Prefix
=> Relocate_Node
(Obj
)));
6387 if not Is_Aliased_View
(Obj
) then
6389 ("object in prefixed call to& must be aliased"
6390 & " (RM-2005 4.3.1 (13))",
6391 Prefix
(First_Actual
), Subprog
);
6394 Analyze
(First_Actual
);
6397 if Is_Overloaded
(Obj
) then
6398 Save_Interps
(Obj
, First_Actual
);
6401 Rewrite
(First_Actual
, Obj
);
6404 Rewrite
(Node_To_Replace
, Call_Node
);
6406 -- Propagate the interpretations collected in subprog to the new
6407 -- function call node, to be resolved from context.
6409 if Is_Overloaded
(Subprog
) then
6410 Save_Interps
(Subprog
, Node_To_Replace
);
6413 Analyze
(Node_To_Replace
);
6415 -- If the operation has been rewritten into a call, which may get
6416 -- subsequently an explicit dereference, preserve the type on the
6417 -- original node (selected component or indexed component) for
6418 -- subsequent legality tests, e.g. Is_Variable. which examines
6419 -- the original node.
6421 if Nkind
(Node_To_Replace
) = N_Function_Call
then
6423 (Original_Node
(Node_To_Replace
), Etype
(Node_To_Replace
));
6426 end Complete_Object_Operation
;
6428 ----------------------
6429 -- Report_Ambiguity --
6430 ----------------------
6432 procedure Report_Ambiguity
(Op
: Entity_Id
) is
6433 Access_Formal
: constant Boolean :=
6434 Is_Access_Type
(Etype
(First_Formal
(Op
)));
6435 Access_Actual
: constant Boolean :=
6436 Is_Access_Type
(Etype
(Prefix
(N
)));
6439 Error_Msg_Sloc
:= Sloc
(Op
);
6441 if Access_Formal
and then not Access_Actual
then
6442 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
6444 ("\possible interpretation"
6445 & " (inherited, with implicit 'Access) #", N
);
6448 ("\possible interpretation (with implicit 'Access) #", N
);
6451 elsif not Access_Formal
and then Access_Actual
then
6452 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
6454 ("\possible interpretation"
6455 & " ( inherited, with implicit dereference) #", N
);
6458 ("\possible interpretation (with implicit dereference) #", N
);
6462 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
6463 Error_Msg_N
("\possible interpretation (inherited)#", N
);
6465 Error_Msg_N
-- CODEFIX
6466 ("\possible interpretation#", N
);
6469 end Report_Ambiguity
;
6471 --------------------------------
6472 -- Transform_Object_Operation --
6473 --------------------------------
6475 procedure Transform_Object_Operation
6476 (Call_Node
: out Node_Id
;
6477 Node_To_Replace
: out Node_Id
)
6479 Dummy
: constant Node_Id
:= New_Copy
(Obj
);
6480 -- Placeholder used as a first parameter in the call, replaced
6481 -- eventually by the proper object.
6483 Parent_Node
: constant Node_Id
:= Parent
(N
);
6489 -- Common case covering 1) Call to a procedure and 2) Call to a
6490 -- function that has some additional actuals.
6492 if Nkind_In
(Parent_Node
, N_Function_Call
,
6493 N_Procedure_Call_Statement
)
6495 -- N is a selected component node containing the name of the
6496 -- subprogram. If N is not the name of the parent node we must
6497 -- not replace the parent node by the new construct. This case
6498 -- occurs when N is a parameterless call to a subprogram that
6499 -- is an actual parameter of a call to another subprogram. For
6501 -- Some_Subprogram (..., Obj.Operation, ...)
6503 and then Name
(Parent_Node
) = N
6505 Node_To_Replace
:= Parent_Node
;
6507 Actuals
:= Parameter_Associations
(Parent_Node
);
6509 if Present
(Actuals
) then
6510 Prepend
(Dummy
, Actuals
);
6512 Actuals
:= New_List
(Dummy
);
6515 if Nkind
(Parent_Node
) = N_Procedure_Call_Statement
then
6517 Make_Procedure_Call_Statement
(Loc
,
6518 Name
=> New_Copy
(Subprog
),
6519 Parameter_Associations
=> Actuals
);
6523 Make_Function_Call
(Loc
,
6524 Name
=> New_Copy
(Subprog
),
6525 Parameter_Associations
=> Actuals
);
6529 -- Before analysis, a function call appears as an indexed component
6530 -- if there are no named associations.
6532 elsif Nkind
(Parent_Node
) = N_Indexed_Component
6533 and then N
= Prefix
(Parent_Node
)
6535 Node_To_Replace
:= Parent_Node
;
6536 Actuals
:= Expressions
(Parent_Node
);
6538 Actual
:= First
(Actuals
);
6539 while Present
(Actual
) loop
6544 Prepend
(Dummy
, Actuals
);
6547 Make_Function_Call
(Loc
,
6548 Name
=> New_Copy
(Subprog
),
6549 Parameter_Associations
=> Actuals
);
6551 -- Parameterless call: Obj.F is rewritten as F (Obj)
6554 Node_To_Replace
:= N
;
6557 Make_Function_Call
(Loc
,
6558 Name
=> New_Copy
(Subprog
),
6559 Parameter_Associations
=> New_List
(Dummy
));
6561 end Transform_Object_Operation
;
6563 ------------------------------
6564 -- Try_Class_Wide_Operation --
6565 ------------------------------
6567 function Try_Class_Wide_Operation
6568 (Call_Node
: Node_Id
;
6569 Node_To_Replace
: Node_Id
) return Boolean
6571 Anc_Type
: Entity_Id
;
6572 Matching_Op
: Entity_Id
:= Empty
;
6575 procedure Traverse_Homonyms
6576 (Anc_Type
: Entity_Id
;
6577 Error
: out Boolean);
6578 -- Traverse the homonym chain of the subprogram searching for those
6579 -- homonyms whose first formal has the Anc_Type's class-wide type,
6580 -- or an anonymous access type designating the class-wide type. If
6581 -- an ambiguity is detected, then Error is set to True.
6583 procedure Traverse_Interfaces
6584 (Anc_Type
: Entity_Id
;
6585 Error
: out Boolean);
6586 -- Traverse the list of interfaces, if any, associated with Anc_Type
6587 -- and search for acceptable class-wide homonyms associated with each
6588 -- interface. If an ambiguity is detected, then Error is set to True.
6590 -----------------------
6591 -- Traverse_Homonyms --
6592 -----------------------
6594 procedure Traverse_Homonyms
6595 (Anc_Type
: Entity_Id
;
6596 Error
: out Boolean)
6598 Cls_Type
: Entity_Id
;
6606 Cls_Type
:= Class_Wide_Type
(Anc_Type
);
6608 Hom
:= Current_Entity
(Subprog
);
6610 -- Find operation whose first parameter is of the class-wide
6611 -- type, a subtype thereof, or an anonymous access to same.
6613 while Present
(Hom
) loop
6614 if (Ekind
(Hom
) = E_Procedure
6616 Ekind
(Hom
) = E_Function
)
6617 and then Scope
(Hom
) = Scope
(Anc_Type
)
6618 and then Present
(First_Formal
(Hom
))
6620 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
6622 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
6624 Ekind
(Etype
(First_Formal
(Hom
))) =
6625 E_Anonymous_Access_Type
6628 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
6631 Set_Etype
(Call_Node
, Any_Type
);
6632 Set_Is_Overloaded
(Call_Node
, False);
6635 if No
(Matching_Op
) then
6636 Hom_Ref
:= New_Reference_To
(Hom
, Sloc
(Subprog
));
6637 Set_Etype
(Call_Node
, Any_Type
);
6638 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
6640 Set_Name
(Call_Node
, Hom_Ref
);
6645 Report
=> Report_Error
,
6647 Skip_First
=> True);
6650 Valid_Candidate
(Success
, Call_Node
, Hom
);
6656 Report
=> Report_Error
,
6658 Skip_First
=> True);
6660 if Present
(Valid_Candidate
(Success
, Call_Node
, Hom
))
6661 and then Nkind
(Call_Node
) /= N_Function_Call
6663 Error_Msg_NE
("ambiguous call to&", N
, Hom
);
6664 Report_Ambiguity
(Matching_Op
);
6665 Report_Ambiguity
(Hom
);
6672 Hom
:= Homonym
(Hom
);
6674 end Traverse_Homonyms
;
6676 -------------------------
6677 -- Traverse_Interfaces --
6678 -------------------------
6680 procedure Traverse_Interfaces
6681 (Anc_Type
: Entity_Id
;
6682 Error
: out Boolean)
6684 Intface_List
: constant List_Id
:=
6685 Abstract_Interface_List
(Anc_Type
);
6691 if Is_Non_Empty_List
(Intface_List
) then
6692 Intface
:= First
(Intface_List
);
6693 while Present
(Intface
) loop
6695 -- Look for acceptable class-wide homonyms associated with
6698 Traverse_Homonyms
(Etype
(Intface
), Error
);
6704 -- Continue the search by looking at each of the interface's
6705 -- associated interface ancestors.
6707 Traverse_Interfaces
(Etype
(Intface
), Error
);
6716 end Traverse_Interfaces
;
6718 -- Start of processing for Try_Class_Wide_Operation
6721 -- Loop through ancestor types (including interfaces), traversing
6722 -- the homonym chain of the subprogram, trying out those homonyms
6723 -- whose first formal has the class-wide type of the ancestor, or
6724 -- an anonymous access type designating the class-wide type.
6726 Anc_Type
:= Obj_Type
;
6728 -- Look for a match among homonyms associated with the ancestor
6730 Traverse_Homonyms
(Anc_Type
, Error
);
6736 -- Continue the search for matches among homonyms associated with
6737 -- any interfaces implemented by the ancestor.
6739 Traverse_Interfaces
(Anc_Type
, Error
);
6745 exit when Etype
(Anc_Type
) = Anc_Type
;
6746 Anc_Type
:= Etype
(Anc_Type
);
6749 if Present
(Matching_Op
) then
6750 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
6753 return Present
(Matching_Op
);
6754 end Try_Class_Wide_Operation
;
6756 -----------------------------------
6757 -- Try_One_Prefix_Interpretation --
6758 -----------------------------------
6760 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
) is
6764 if Is_Access_Type
(Obj_Type
) then
6765 Obj_Type
:= Designated_Type
(Obj_Type
);
6768 if Ekind
(Obj_Type
) = E_Private_Subtype
then
6769 Obj_Type
:= Base_Type
(Obj_Type
);
6772 if Is_Class_Wide_Type
(Obj_Type
) then
6773 Obj_Type
:= Etype
(Class_Wide_Type
(Obj_Type
));
6776 -- The type may have be obtained through a limited_with clause,
6777 -- in which case the primitive operations are available on its
6778 -- non-limited view. If still incomplete, retrieve full view.
6780 if Ekind
(Obj_Type
) = E_Incomplete_Type
6781 and then From_With_Type
(Obj_Type
)
6783 Obj_Type
:= Get_Full_View
(Non_Limited_View
(Obj_Type
));
6786 -- If the object is not tagged, or the type is still an incomplete
6787 -- type, this is not a prefixed call.
6789 if not Is_Tagged_Type
(Obj_Type
)
6790 or else Is_Incomplete_Type
(Obj_Type
)
6795 if Try_Primitive_Operation
6796 (Call_Node
=> New_Call_Node
,
6797 Node_To_Replace
=> Node_To_Replace
)
6799 Try_Class_Wide_Operation
6800 (Call_Node
=> New_Call_Node
,
6801 Node_To_Replace
=> Node_To_Replace
)
6805 end Try_One_Prefix_Interpretation
;
6807 -----------------------------
6808 -- Try_Primitive_Operation --
6809 -----------------------------
6811 function Try_Primitive_Operation
6812 (Call_Node
: Node_Id
;
6813 Node_To_Replace
: Node_Id
) return Boolean
6816 Prim_Op
: Entity_Id
;
6817 Matching_Op
: Entity_Id
:= Empty
;
6818 Prim_Op_Ref
: Node_Id
:= Empty
;
6820 Corr_Type
: Entity_Id
:= Empty
;
6821 -- If the prefix is a synchronized type, the controlling type of
6822 -- the primitive operation is the corresponding record type, else
6823 -- this is the object type itself.
6825 Success
: Boolean := False;
6827 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
;
6828 -- For tagged types the candidate interpretations are found in
6829 -- the list of primitive operations of the type and its ancestors.
6830 -- For formal tagged types we have to find the operations declared
6831 -- in the same scope as the type (including in the generic formal
6832 -- part) because the type itself carries no primitive operations,
6833 -- except for formal derived types that inherit the operations of
6834 -- the parent and progenitors.
6835 -- If the context is a generic subprogram body, the generic formals
6836 -- are visible by name, but are not in the entity list of the
6837 -- subprogram because that list starts with the subprogram formals.
6838 -- We retrieve the candidate operations from the generic declaration.
6840 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean;
6841 -- An operation that overrides an inherited operation in the private
6842 -- part of its package may be hidden, but if the inherited operation
6843 -- is visible a direct call to it will dispatch to the private one,
6844 -- which is therefore a valid candidate.
6846 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean;
6847 -- Verify that the prefix, dereferenced if need be, is a valid
6848 -- controlling argument in a call to Op. The remaining actuals
6849 -- are checked in the subsequent call to Analyze_One_Call.
6851 ------------------------------
6852 -- Collect_Generic_Type_Ops --
6853 ------------------------------
6855 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
is
6856 Bas
: constant Entity_Id
:= Base_Type
(T
);
6857 Candidates
: constant Elist_Id
:= New_Elmt_List
;
6861 procedure Check_Candidate
;
6862 -- The operation is a candidate if its first parameter is a
6863 -- controlling operand of the desired type.
6865 -----------------------
6866 -- Check_Candidate; --
6867 -----------------------
6869 procedure Check_Candidate
is
6871 Formal
:= First_Formal
(Subp
);
6874 and then Is_Controlling_Formal
(Formal
)
6876 (Base_Type
(Etype
(Formal
)) = Bas
6878 (Is_Access_Type
(Etype
(Formal
))
6879 and then Designated_Type
(Etype
(Formal
)) = Bas
))
6881 Append_Elmt
(Subp
, Candidates
);
6883 end Check_Candidate
;
6885 -- Start of processing for Collect_Generic_Type_Ops
6888 if Is_Derived_Type
(T
) then
6889 return Primitive_Operations
(T
);
6891 elsif Ekind_In
(Scope
(T
), E_Procedure
, E_Function
) then
6893 -- Scan the list of generic formals to find subprograms
6894 -- that may have a first controlling formal of the type.
6896 if Nkind
(Unit_Declaration_Node
(Scope
(T
)))
6897 = N_Generic_Subprogram_Declaration
6904 First
(Generic_Formal_Declarations
6905 (Unit_Declaration_Node
(Scope
(T
))));
6906 while Present
(Decl
) loop
6907 if Nkind
(Decl
) in N_Formal_Subprogram_Declaration
then
6908 Subp
:= Defining_Entity
(Decl
);
6919 -- Scan the list of entities declared in the same scope as
6920 -- the type. In general this will be an open scope, given that
6921 -- the call we are analyzing can only appear within a generic
6922 -- declaration or body (either the one that declares T, or a
6925 -- For a subtype representing a generic actual type, go to the
6928 if Is_Generic_Actual_Type
(T
) then
6929 Subp
:= First_Entity
(Scope
(Base_Type
(T
)));
6931 Subp
:= First_Entity
(Scope
(T
));
6934 while Present
(Subp
) loop
6935 if Is_Overloadable
(Subp
) then
6944 end Collect_Generic_Type_Ops
;
6946 ---------------------------
6947 -- Is_Private_Overriding --
6948 ---------------------------
6950 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean is
6951 Visible_Op
: constant Entity_Id
:= Homonym
(Op
);
6954 return Present
(Visible_Op
)
6955 and then Scope
(Op
) = Scope
(Visible_Op
)
6956 and then not Comes_From_Source
(Visible_Op
)
6957 and then Alias
(Visible_Op
) = Op
6958 and then not Is_Hidden
(Visible_Op
);
6959 end Is_Private_Overriding
;
6961 -----------------------------
6962 -- Valid_First_Argument_Of --
6963 -----------------------------
6965 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean is
6966 Typ
: Entity_Id
:= Etype
(First_Formal
(Op
));
6969 if Is_Concurrent_Type
(Typ
)
6970 and then Present
(Corresponding_Record_Type
(Typ
))
6972 Typ
:= Corresponding_Record_Type
(Typ
);
6975 -- Simple case. Object may be a subtype of the tagged type or
6976 -- may be the corresponding record of a synchronized type.
6978 return Obj_Type
= Typ
6979 or else Base_Type
(Obj_Type
) = Typ
6980 or else Corr_Type
= Typ
6982 -- Prefix can be dereferenced
6985 (Is_Access_Type
(Corr_Type
)
6986 and then Designated_Type
(Corr_Type
) = Typ
)
6988 -- Formal is an access parameter, for which the object
6989 -- can provide an access.
6992 (Ekind
(Typ
) = E_Anonymous_Access_Type
6993 and then Designated_Type
(Typ
) = Base_Type
(Corr_Type
));
6994 end Valid_First_Argument_Of
;
6996 -- Start of processing for Try_Primitive_Operation
6999 -- Look for subprograms in the list of primitive operations. The name
7000 -- must be identical, and the kind of call indicates the expected
7001 -- kind of operation (function or procedure). If the type is a
7002 -- (tagged) synchronized type, the primitive ops are attached to the
7003 -- corresponding record (base) type.
7005 if Is_Concurrent_Type
(Obj_Type
) then
7006 if Present
(Corresponding_Record_Type
(Obj_Type
)) then
7007 Corr_Type
:= Base_Type
(Corresponding_Record_Type
(Obj_Type
));
7008 Elmt
:= First_Elmt
(Primitive_Operations
(Corr_Type
));
7010 Corr_Type
:= Obj_Type
;
7011 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
7014 elsif not Is_Generic_Type
(Obj_Type
) then
7015 Corr_Type
:= Obj_Type
;
7016 Elmt
:= First_Elmt
(Primitive_Operations
(Obj_Type
));
7019 Corr_Type
:= Obj_Type
;
7020 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
7023 while Present
(Elmt
) loop
7024 Prim_Op
:= Node
(Elmt
);
7026 if Chars
(Prim_Op
) = Chars
(Subprog
)
7027 and then Present
(First_Formal
(Prim_Op
))
7028 and then Valid_First_Argument_Of
(Prim_Op
)
7030 (Nkind
(Call_Node
) = N_Function_Call
)
7031 = (Ekind
(Prim_Op
) = E_Function
)
7033 -- Ada 2005 (AI-251): If this primitive operation corresponds
7034 -- with an immediate ancestor interface there is no need to add
7035 -- it to the list of interpretations; the corresponding aliased
7036 -- primitive is also in this list of primitive operations and
7037 -- will be used instead.
7039 if (Present
(Interface_Alias
(Prim_Op
))
7040 and then Is_Ancestor
(Find_Dispatching_Type
7041 (Alias
(Prim_Op
)), Corr_Type
))
7043 -- Do not consider hidden primitives unless the type is in an
7044 -- open scope or we are within an instance, where visibility
7045 -- is known to be correct, or else if this is an overriding
7046 -- operation in the private part for an inherited operation.
7048 or else (Is_Hidden
(Prim_Op
)
7049 and then not Is_Immediately_Visible
(Obj_Type
)
7050 and then not In_Instance
7051 and then not Is_Private_Overriding
(Prim_Op
))
7056 Set_Etype
(Call_Node
, Any_Type
);
7057 Set_Is_Overloaded
(Call_Node
, False);
7059 if No
(Matching_Op
) then
7060 Prim_Op_Ref
:= New_Reference_To
(Prim_Op
, Sloc
(Subprog
));
7061 Candidate
:= Prim_Op
;
7063 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
7065 Set_Name
(Call_Node
, Prim_Op_Ref
);
7071 Report
=> Report_Error
,
7073 Skip_First
=> True);
7075 Matching_Op
:= Valid_Candidate
(Success
, Call_Node
, Prim_Op
);
7077 -- More than one interpretation, collect for subsequent
7078 -- disambiguation. If this is a procedure call and there
7079 -- is another match, report ambiguity now.
7085 Report
=> Report_Error
,
7087 Skip_First
=> True);
7089 if Present
(Valid_Candidate
(Success
, Call_Node
, Prim_Op
))
7090 and then Nkind
(Call_Node
) /= N_Function_Call
7092 Error_Msg_NE
("ambiguous call to&", N
, Prim_Op
);
7093 Report_Ambiguity
(Matching_Op
);
7094 Report_Ambiguity
(Prim_Op
);
7104 if Present
(Matching_Op
) then
7105 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
7108 return Present
(Matching_Op
);
7109 end Try_Primitive_Operation
;
7111 -- Start of processing for Try_Object_Operation
7114 Analyze_Expression
(Obj
);
7116 -- Analyze the actuals if node is known to be a subprogram call
7118 if Is_Subprg_Call
and then N
= Name
(Parent
(N
)) then
7119 Actual
:= First
(Parameter_Associations
(Parent
(N
)));
7120 while Present
(Actual
) loop
7121 Analyze_Expression
(Actual
);
7126 -- Build a subprogram call node, using a copy of Obj as its first
7127 -- actual. This is a placeholder, to be replaced by an explicit
7128 -- dereference when needed.
7130 Transform_Object_Operation
7131 (Call_Node
=> New_Call_Node
,
7132 Node_To_Replace
=> Node_To_Replace
);
7134 Set_Etype
(New_Call_Node
, Any_Type
);
7135 Set_Etype
(Subprog
, Any_Type
);
7136 Set_Parent
(New_Call_Node
, Parent
(Node_To_Replace
));
7138 if not Is_Overloaded
(Obj
) then
7139 Try_One_Prefix_Interpretation
(Obj_Type
);
7146 Get_First_Interp
(Obj
, I
, It
);
7147 while Present
(It
.Nam
) loop
7148 Try_One_Prefix_Interpretation
(It
.Typ
);
7149 Get_Next_Interp
(I
, It
);
7154 if Etype
(New_Call_Node
) /= Any_Type
then
7155 Complete_Object_Operation
7156 (Call_Node
=> New_Call_Node
,
7157 Node_To_Replace
=> Node_To_Replace
);
7160 elsif Present
(Candidate
) then
7162 -- The argument list is not type correct. Re-analyze with error
7163 -- reporting enabled, and use one of the possible candidates.
7164 -- In All_Errors_Mode, re-analyze all failed interpretations.
7166 if All_Errors_Mode
then
7167 Report_Error
:= True;
7168 if Try_Primitive_Operation
7169 (Call_Node
=> New_Call_Node
,
7170 Node_To_Replace
=> Node_To_Replace
)
7173 Try_Class_Wide_Operation
7174 (Call_Node
=> New_Call_Node
,
7175 Node_To_Replace
=> Node_To_Replace
)
7182 (N
=> New_Call_Node
,
7186 Skip_First
=> True);
7189 -- No need for further errors
7194 -- There was no candidate operation, so report it as an error
7195 -- in the caller: Analyze_Selected_Component.
7199 end Try_Object_Operation
;
7205 procedure wpo
(T
: Entity_Id
) is
7210 if not Is_Tagged_Type
(T
) then
7214 E
:= First_Elmt
(Primitive_Operations
(Base_Type
(T
)));
7215 while Present
(E
) loop
7217 Write_Int
(Int
(Op
));
7218 Write_Str
(" === ");
7219 Write_Name
(Chars
(Op
));
7221 Write_Name
(Chars
(Scope
(Op
)));