1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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_Cat
; use Sem_Cat
;
47 with Sem_Ch3
; use Sem_Ch3
;
48 with Sem_Ch6
; use Sem_Ch6
;
49 with Sem_Ch8
; use Sem_Ch8
;
50 with Sem_Disp
; use Sem_Disp
;
51 with Sem_Dist
; use Sem_Dist
;
52 with Sem_Eval
; use Sem_Eval
;
53 with Sem_Res
; use Sem_Res
;
54 with Sem_Util
; use Sem_Util
;
55 with Sem_Type
; use Sem_Type
;
56 with Stand
; use Stand
;
57 with Sinfo
; use Sinfo
;
58 with Snames
; use Snames
;
59 with Tbuild
; use Tbuild
;
61 package body Sem_Ch4
is
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 procedure Analyze_Concatenation_Rest
(N
: Node_Id
);
68 -- Does the "rest" of the work of Analyze_Concatenation, after the left
69 -- operand has been analyzed. See Analyze_Concatenation for details.
71 procedure Analyze_Expression
(N
: Node_Id
);
72 -- For expressions that are not names, this is just a call to analyze.
73 -- If the expression is a name, it may be a call to a parameterless
74 -- function, and if so must be converted into an explicit call node
75 -- and analyzed as such. This deproceduring must be done during the first
76 -- pass of overload resolution, because otherwise a procedure call with
77 -- overloaded actuals may fail to resolve.
79 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
);
80 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
81 -- is an operator name or an expanded name whose selector is an operator
82 -- name, and one possible interpretation is as a predefined operator.
84 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
);
85 -- If the prefix of a selected_component is overloaded, the proper
86 -- interpretation that yields a record type with the proper selector
87 -- name must be selected.
89 procedure Analyze_User_Defined_Binary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
90 -- Procedure to analyze a user defined binary operator, which is resolved
91 -- like a function, but instead of a list of actuals it is presented
92 -- with the left and right operands of an operator node.
94 procedure Analyze_User_Defined_Unary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
95 -- Procedure to analyze a user defined unary operator, which is resolved
96 -- like a function, but instead of a list of actuals, it is presented with
97 -- the operand of the operator node.
99 procedure Ambiguous_Operands
(N
: Node_Id
);
100 -- for equality, membership, and comparison operators with overloaded
101 -- arguments, list possible interpretations.
103 procedure Analyze_One_Call
107 Success
: out Boolean;
108 Skip_First
: Boolean := False);
109 -- Check one interpretation of an overloaded subprogram name for
110 -- compatibility with the types of the actuals in a call. If there is a
111 -- single interpretation which does not match, post error if Report is
114 -- Nam is the entity that provides the formals against which the actuals
115 -- are checked. Nam is either the name of a subprogram, or the internal
116 -- subprogram type constructed for an access_to_subprogram. If the actuals
117 -- are compatible with Nam, then Nam is added to the list of candidate
118 -- interpretations for N, and Success is set to True.
120 -- The flag Skip_First is used when analyzing a call that was rewritten
121 -- from object notation. In this case the first actual may have to receive
122 -- an explicit dereference, depending on the first formal of the operation
123 -- being called. The caller will have verified that the object is legal
124 -- for the call. If the remaining parameters match, the first parameter
125 -- will rewritten as a dereference if needed, prior to completing analysis.
127 procedure Check_Misspelled_Selector
130 -- Give possible misspelling diagnostic if Sel is likely to be a mis-
131 -- spelling of one of the selectors of the Prefix. This is called by
132 -- Analyze_Selected_Component after producing an invalid selector error
135 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean;
136 -- Verify that type T is declared in scope S. Used to find interpretations
137 -- for operators given by expanded names. This is abstracted as a separate
138 -- function to handle extensions to System, where S is System, but T is
139 -- declared in the extension.
141 procedure Find_Arithmetic_Types
145 -- L and R are the operands of an arithmetic operator. Find
146 -- consistent pairs of interpretations for L and R that have a
147 -- numeric type consistent with the semantics of the operator.
149 procedure Find_Comparison_Types
153 -- L and R are operands of a comparison operator. Find consistent
154 -- pairs of interpretations for L and R.
156 procedure Find_Concatenation_Types
160 -- For the four varieties of concatenation
162 procedure Find_Equality_Types
166 -- Ditto for equality operators
168 procedure Find_Boolean_Types
172 -- Ditto for binary logical operations
174 procedure Find_Negation_Types
178 -- Find consistent interpretation for operand of negation operator
180 procedure Find_Non_Universal_Interpretations
185 -- For equality and comparison operators, the result is always boolean,
186 -- and the legality of the operation is determined from the visibility
187 -- of the operand types. If one of the operands has a universal interpre-
188 -- tation, the legality check uses some compatible non-universal
189 -- interpretation of the other operand. N can be an operator node, or
190 -- a function call whose name is an operator designator.
192 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean;
193 -- Find candidate interpretations for the name Obj.Proc when it appears
194 -- in a subprogram renaming declaration.
196 procedure Find_Unary_Types
200 -- Unary arithmetic types: plus, minus, abs
202 procedure Check_Arithmetic_Pair
206 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
207 -- types for left and right operand. Determine whether they constitute
208 -- a valid pair for the given operator, and record the corresponding
209 -- interpretation of the operator node. The node N may be an operator
210 -- node (the usual case) or a function call whose prefix is an operator
211 -- designator. In both cases Op_Id is the operator name itself.
213 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
);
214 -- Give detailed information on overloaded call where none of the
215 -- interpretations match. N is the call node, Nam the designator for
216 -- the overloaded entity being called.
218 function Junk_Operand
(N
: Node_Id
) return Boolean;
219 -- Test for an operand that is an inappropriate entity (e.g. a package
220 -- name or a label). If so, issue an error message and return True. If
221 -- the operand is not an inappropriate entity kind, return False.
223 procedure Operator_Check
(N
: Node_Id
);
224 -- Verify that an operator has received some valid interpretation. If none
225 -- was found, determine whether a use clause would make the operation
226 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
227 -- every type compatible with the operator, even if the operator for the
228 -- type is not directly visible. The routine uses this type to emit a more
229 -- informative message.
231 function Process_Implicit_Dereference_Prefix
233 P
: Node_Id
) return Entity_Id
;
234 -- Called when P is the prefix of an implicit dereference, denoting an
235 -- object E. The function returns the designated type of the prefix, taking
236 -- into account that the designated type of an anonymous access type may be
237 -- a limited view, when the non-limited view is visible.
238 -- If in semantics only mode (-gnatc or generic), the function also records
239 -- that the prefix is a reference to E, if any. Normally, such a reference
240 -- is generated only when the implicit dereference is expanded into an
241 -- explicit one, but for consistency we must generate the reference when
242 -- expansion is disabled as well.
244 procedure Remove_Abstract_Operations
(N
: Node_Id
);
245 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
246 -- operation is not a candidate interpretation.
248 function Try_Indexed_Call
252 Skip_First
: Boolean) return Boolean;
253 -- If a function has defaults for all its actuals, a call to it may in fact
254 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
255 -- interpretation as an indexing, prior to analysis as a call. If both are
256 -- possible, the node is overloaded with both interpretations (same symbol
257 -- but two different types). If the call is written in prefix form, the
258 -- prefix becomes the first parameter in the call, and only the remaining
259 -- actuals must be checked for the presence of defaults.
261 function Try_Indirect_Call
264 Typ
: Entity_Id
) return Boolean;
265 -- Similarly, a function F that needs no actuals can return an access to a
266 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
267 -- the call may be overloaded with both interpretations.
269 function Try_Object_Operation
(N
: Node_Id
) return Boolean;
270 -- Ada 2005 (AI-252): Support the object.operation notation
272 procedure wpo
(T
: Entity_Id
);
273 pragma Warnings
(Off
, wpo
);
274 -- Used for debugging: obtain list of primitive operations even if
275 -- type is not frozen and dispatch table is not built yet.
277 ------------------------
278 -- Ambiguous_Operands --
279 ------------------------
281 procedure Ambiguous_Operands
(N
: Node_Id
) is
282 procedure List_Operand_Interps
(Opnd
: Node_Id
);
284 --------------------------
285 -- List_Operand_Interps --
286 --------------------------
288 procedure List_Operand_Interps
(Opnd
: Node_Id
) is
293 if Is_Overloaded
(Opnd
) then
294 if Nkind
(Opnd
) in N_Op
then
296 elsif Nkind
(Opnd
) = N_Function_Call
then
306 if Opnd
= Left_Opnd
(N
) then
308 ("\left operand has the following interpretations", N
);
311 ("\right operand has the following interpretations", N
);
315 List_Interps
(Nam
, Err
);
316 end List_Operand_Interps
;
318 -- Start of processing for Ambiguous_Operands
321 if Nkind
(N
) in N_Membership_Test
then
322 Error_Msg_N
("ambiguous operands for membership", N
);
324 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
) then
325 Error_Msg_N
("ambiguous operands for equality", N
);
328 Error_Msg_N
("ambiguous operands for comparison", N
);
331 if All_Errors_Mode
then
332 List_Operand_Interps
(Left_Opnd
(N
));
333 List_Operand_Interps
(Right_Opnd
(N
));
335 Error_Msg_N
("\use -gnatf switch for details", N
);
337 end Ambiguous_Operands
;
339 -----------------------
340 -- Analyze_Aggregate --
341 -----------------------
343 -- Most of the analysis of Aggregates requires that the type be known,
344 -- and is therefore put off until resolution.
346 procedure Analyze_Aggregate
(N
: Node_Id
) is
348 if No
(Etype
(N
)) then
349 Set_Etype
(N
, Any_Composite
);
351 end Analyze_Aggregate
;
353 -----------------------
354 -- Analyze_Allocator --
355 -----------------------
357 procedure Analyze_Allocator
(N
: Node_Id
) is
358 Loc
: constant Source_Ptr
:= Sloc
(N
);
359 Sav_Errs
: constant Nat
:= Serious_Errors_Detected
;
360 E
: Node_Id
:= Expression
(N
);
361 Acc_Type
: Entity_Id
;
365 -- In accordance with H.4(7), the No_Allocators restriction only applies
366 -- to user-written allocators.
368 if Comes_From_Source
(N
) then
369 Check_Restriction
(No_Allocators
, N
);
372 if Nkind
(E
) = N_Qualified_Expression
then
373 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
374 Set_Etype
(Acc_Type
, Acc_Type
);
375 Find_Type
(Subtype_Mark
(E
));
377 -- Analyze the qualified expression, and apply the name resolution
378 -- rule given in 4.7 (3).
381 Type_Id
:= Etype
(E
);
382 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
384 Resolve
(Expression
(E
), Type_Id
);
386 if Is_Limited_Type
(Type_Id
)
387 and then Comes_From_Source
(N
)
388 and then not In_Instance_Body
390 if not OK_For_Limited_Init
(Expression
(E
)) then
391 Error_Msg_N
("initialization not allowed for limited types", N
);
392 Explain_Limited_Type
(Type_Id
, N
);
396 -- A qualified expression requires an exact match of the type,
397 -- class-wide matching is not allowed.
399 -- if Is_Class_Wide_Type (Type_Id)
400 -- and then Base_Type
401 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
403 -- Wrong_Type (Expression (E), Type_Id);
406 Check_Non_Static_Context
(Expression
(E
));
408 -- We don't analyze the qualified expression itself because it's
409 -- part of the allocator
411 Set_Etype
(E
, Type_Id
);
413 -- Case where allocator has a subtype indication
418 Base_Typ
: Entity_Id
;
421 -- If the allocator includes a N_Subtype_Indication then a
422 -- constraint is present, otherwise the node is a subtype mark.
423 -- Introduce an explicit subtype declaration into the tree
424 -- defining some anonymous subtype and rewrite the allocator to
425 -- use this subtype rather than the subtype indication.
427 -- It is important to introduce the explicit subtype declaration
428 -- so that the bounds of the subtype indication are attached to
429 -- the tree in case the allocator is inside a generic unit.
431 if Nkind
(E
) = N_Subtype_Indication
then
433 -- A constraint is only allowed for a composite type in Ada
434 -- 95. In Ada 83, a constraint is also allowed for an
435 -- access-to-composite type, but the constraint is ignored.
437 Find_Type
(Subtype_Mark
(E
));
438 Base_Typ
:= Entity
(Subtype_Mark
(E
));
440 if Is_Elementary_Type
(Base_Typ
) then
441 if not (Ada_Version
= Ada_83
442 and then Is_Access_Type
(Base_Typ
))
444 Error_Msg_N
("constraint not allowed here", E
);
446 if Nkind
(Constraint
(E
)) =
447 N_Index_Or_Discriminant_Constraint
449 Error_Msg_N
-- CODEFIX
450 ("\if qualified expression was meant, " &
451 "use apostrophe", Constraint
(E
));
455 -- Get rid of the bogus constraint:
457 Rewrite
(E
, New_Copy_Tree
(Subtype_Mark
(E
)));
458 Analyze_Allocator
(N
);
461 -- Ada 2005, AI-363: if the designated type has a constrained
462 -- partial view, it cannot receive a discriminant constraint,
463 -- and the allocated object is unconstrained.
465 elsif Ada_Version
>= Ada_05
466 and then Has_Constrained_Partial_View
(Base_Typ
)
469 ("constraint no allowed when type " &
470 "has a constrained partial view", Constraint
(E
));
473 if Expander_Active
then
475 Make_Defining_Identifier
(Loc
, New_Internal_Name
('S'));
478 Make_Subtype_Declaration
(Loc
,
479 Defining_Identifier
=> Def_Id
,
480 Subtype_Indication
=> Relocate_Node
(E
)));
482 if Sav_Errs
/= Serious_Errors_Detected
483 and then Nkind
(Constraint
(E
)) =
484 N_Index_Or_Discriminant_Constraint
486 Error_Msg_N
-- CODEFIX
487 ("if qualified expression was meant, " &
488 "use apostrophe!", Constraint
(E
));
491 E
:= New_Occurrence_Of
(Def_Id
, Loc
);
492 Rewrite
(Expression
(N
), E
);
496 Type_Id
:= Process_Subtype
(E
, N
);
497 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
498 Set_Etype
(Acc_Type
, Acc_Type
);
499 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
500 Check_Fully_Declared
(Type_Id
, N
);
502 -- Ada 2005 (AI-231): If the designated type is itself an access
503 -- type that excludes null, its default initialization will
504 -- be a null object, and we can insert an unconditional raise
505 -- before the allocator.
507 if Can_Never_Be_Null
(Type_Id
) then
509 Not_Null_Check
: constant Node_Id
:=
510 Make_Raise_Constraint_Error
(Sloc
(E
),
511 Reason
=> CE_Null_Not_Allowed
);
513 if Expander_Active
then
514 Insert_Action
(N
, Not_Null_Check
);
515 Analyze
(Not_Null_Check
);
517 Error_Msg_N
("null value not allowed here?", E
);
522 -- Check restriction against dynamically allocated protected
523 -- objects. Note that when limited aggregates are supported,
524 -- a similar test should be applied to an allocator with a
525 -- qualified expression ???
527 if Is_Protected_Type
(Type_Id
) then
528 Check_Restriction
(No_Protected_Type_Allocators
, N
);
531 -- Check for missing initialization. Skip this check if we already
532 -- had errors on analyzing the allocator, since in that case these
533 -- are probably cascaded errors.
535 if Is_Indefinite_Subtype
(Type_Id
)
536 and then Serious_Errors_Detected
= Sav_Errs
538 if Is_Class_Wide_Type
(Type_Id
) then
540 ("initialization required in class-wide allocation", N
);
542 if Ada_Version
< Ada_05
543 and then Is_Limited_Type
(Type_Id
)
545 Error_Msg_N
("unconstrained allocation not allowed", N
);
547 if Is_Array_Type
(Type_Id
) then
549 ("\constraint with array bounds required", N
);
551 elsif Has_Unknown_Discriminants
(Type_Id
) then
554 else pragma Assert
(Has_Discriminants
(Type_Id
));
556 ("\constraint with discriminant values required", N
);
559 -- Limited Ada 2005 and general non-limited case
563 ("uninitialized unconstrained allocation not allowed",
566 if Is_Array_Type
(Type_Id
) then
568 ("\qualified expression or constraint with " &
569 "array bounds required", N
);
571 elsif Has_Unknown_Discriminants
(Type_Id
) then
572 Error_Msg_N
("\qualified expression required", N
);
574 else pragma Assert
(Has_Discriminants
(Type_Id
));
576 ("\qualified expression or constraint with " &
577 "discriminant values required", N
);
585 if Is_Abstract_Type
(Type_Id
) then
586 Error_Msg_N
("cannot allocate abstract object", E
);
589 if Has_Task
(Designated_Type
(Acc_Type
)) then
590 Check_Restriction
(No_Tasking
, N
);
591 Check_Restriction
(Max_Tasks
, N
);
592 Check_Restriction
(No_Task_Allocators
, N
);
595 -- If the No_Streams restriction is set, check that the type of the
596 -- object is not, and does not contain, any subtype derived from
597 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
598 -- Has_Stream just for efficiency reasons. There is no point in
599 -- spending time on a Has_Stream check if the restriction is not set.
601 if Restrictions
.Set
(No_Streams
) then
602 if Has_Stream
(Designated_Type
(Acc_Type
)) then
603 Check_Restriction
(No_Streams
, N
);
607 Set_Etype
(N
, Acc_Type
);
609 if not Is_Library_Level_Entity
(Acc_Type
) then
610 Check_Restriction
(No_Local_Allocators
, N
);
613 if Serious_Errors_Detected
> Sav_Errs
then
614 Set_Error_Posted
(N
);
615 Set_Etype
(N
, Any_Type
);
617 end Analyze_Allocator
;
619 ---------------------------
620 -- Analyze_Arithmetic_Op --
621 ---------------------------
623 procedure Analyze_Arithmetic_Op
(N
: Node_Id
) is
624 L
: constant Node_Id
:= Left_Opnd
(N
);
625 R
: constant Node_Id
:= Right_Opnd
(N
);
629 Candidate_Type
:= Empty
;
630 Analyze_Expression
(L
);
631 Analyze_Expression
(R
);
633 -- If the entity is already set, the node is the instantiation of a
634 -- generic node with a non-local reference, or was manufactured by a
635 -- call to Make_Op_xxx. In either case the entity is known to be valid,
636 -- and we do not need to collect interpretations, instead we just get
637 -- the single possible interpretation.
641 if Present
(Op_Id
) then
642 if Ekind
(Op_Id
) = E_Operator
then
644 if Nkind_In
(N
, N_Op_Divide
, N_Op_Mod
, N_Op_Multiply
, N_Op_Rem
)
645 and then Treat_Fixed_As_Integer
(N
)
649 Set_Etype
(N
, Any_Type
);
650 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
654 Set_Etype
(N
, Any_Type
);
655 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
658 -- Entity is not already set, so we do need to collect interpretations
661 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
662 Set_Etype
(N
, Any_Type
);
664 while Present
(Op_Id
) loop
665 if Ekind
(Op_Id
) = E_Operator
666 and then Present
(Next_Entity
(First_Entity
(Op_Id
)))
668 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
670 -- The following may seem superfluous, because an operator cannot
671 -- be generic, but this ignores the cleverness of the author of
674 elsif Is_Overloadable
(Op_Id
) then
675 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
678 Op_Id
:= Homonym
(Op_Id
);
683 end Analyze_Arithmetic_Op
;
689 -- Function, procedure, and entry calls are checked here. The Name in
690 -- the call may be overloaded. The actuals have been analyzed and may
691 -- themselves be overloaded. On exit from this procedure, the node N
692 -- may have zero, one or more interpretations. In the first case an
693 -- error message is produced. In the last case, the node is flagged
694 -- as overloaded and the interpretations are collected in All_Interp.
696 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
697 -- the type-checking is similar to that of other calls.
699 procedure Analyze_Call
(N
: Node_Id
) is
700 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
705 Success
: Boolean := False;
707 Deref
: Boolean := False;
708 -- Flag indicates whether an interpretation of the prefix is a
709 -- parameterless call that returns an access_to_subprogram.
711 function Name_Denotes_Function
return Boolean;
712 -- If the type of the name is an access to subprogram, this may be the
713 -- type of a name, or the return type of the function being called. If
714 -- the name is not an entity then it can denote a protected function.
715 -- Until we distinguish Etype from Return_Type, we must use this routine
716 -- to resolve the meaning of the name in the call.
718 procedure No_Interpretation
;
719 -- Output error message when no valid interpretation exists
721 ---------------------------
722 -- Name_Denotes_Function --
723 ---------------------------
725 function Name_Denotes_Function
return Boolean is
727 if Is_Entity_Name
(Nam
) then
728 return Ekind
(Entity
(Nam
)) = E_Function
;
730 elsif Nkind
(Nam
) = N_Selected_Component
then
731 return Ekind
(Entity
(Selector_Name
(Nam
))) = E_Function
;
736 end Name_Denotes_Function
;
738 -----------------------
739 -- No_Interpretation --
740 -----------------------
742 procedure No_Interpretation
is
743 L
: constant Boolean := Is_List_Member
(N
);
744 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
747 -- If the node is in a list whose parent is not an expression then it
748 -- must be an attempted procedure call.
750 if L
and then K
not in N_Subexpr
then
751 if Ekind
(Entity
(Nam
)) = E_Generic_Procedure
then
753 ("must instantiate generic procedure& before call",
757 ("procedure or entry name expected", Nam
);
760 -- Check for tasking cases where only an entry call will do
763 and then Nkind_In
(K
, N_Entry_Call_Alternative
,
764 N_Triggering_Alternative
)
766 Error_Msg_N
("entry name expected", Nam
);
768 -- Otherwise give general error message
771 Error_Msg_N
("invalid prefix in call", Nam
);
773 end No_Interpretation
;
775 -- Start of processing for Analyze_Call
778 -- Initialize the type of the result of the call to the error type,
779 -- which will be reset if the type is successfully resolved.
781 Set_Etype
(N
, Any_Type
);
785 if not Is_Overloaded
(Nam
) then
787 -- Only one interpretation to check
789 if Ekind
(Etype
(Nam
)) = E_Subprogram_Type
then
790 Nam_Ent
:= Etype
(Nam
);
792 -- If the prefix is an access_to_subprogram, this may be an indirect
793 -- call. This is the case if the name in the call is not an entity
794 -- name, or if it is a function name in the context of a procedure
795 -- call. In this latter case, we have a call to a parameterless
796 -- function that returns a pointer_to_procedure which is the entity
797 -- being called. Finally, F (X) may be a call to a parameterless
798 -- function that returns a pointer to a function with parameters.
800 elsif Is_Access_Type
(Etype
(Nam
))
801 and then Ekind
(Designated_Type
(Etype
(Nam
))) = E_Subprogram_Type
803 (not Name_Denotes_Function
804 or else Nkind
(N
) = N_Procedure_Call_Statement
806 (Nkind
(Parent
(N
)) /= N_Explicit_Dereference
807 and then Is_Entity_Name
(Nam
)
808 and then No
(First_Formal
(Entity
(Nam
)))
809 and then Present
(Actuals
)))
811 Nam_Ent
:= Designated_Type
(Etype
(Nam
));
812 Insert_Explicit_Dereference
(Nam
);
814 -- Selected component case. Simple entry or protected operation,
815 -- where the entry name is given by the selector name.
817 elsif Nkind
(Nam
) = N_Selected_Component
then
818 Nam_Ent
:= Entity
(Selector_Name
(Nam
));
820 if Ekind
(Nam_Ent
) /= E_Entry
821 and then Ekind
(Nam_Ent
) /= E_Entry_Family
822 and then Ekind
(Nam_Ent
) /= E_Function
823 and then Ekind
(Nam_Ent
) /= E_Procedure
825 Error_Msg_N
("name in call is not a callable entity", Nam
);
826 Set_Etype
(N
, Any_Type
);
830 -- If the name is an Indexed component, it can be a call to a member
831 -- of an entry family. The prefix must be a selected component whose
832 -- selector is the entry. Analyze_Procedure_Call normalizes several
833 -- kinds of call into this form.
835 elsif Nkind
(Nam
) = N_Indexed_Component
then
836 if Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
837 Nam_Ent
:= Entity
(Selector_Name
(Prefix
(Nam
)));
839 Error_Msg_N
("name in call is not a callable entity", Nam
);
840 Set_Etype
(N
, Any_Type
);
844 elsif not Is_Entity_Name
(Nam
) then
845 Error_Msg_N
("name in call is not a callable entity", Nam
);
846 Set_Etype
(N
, Any_Type
);
850 Nam_Ent
:= Entity
(Nam
);
852 -- If no interpretations, give error message
854 if not Is_Overloadable
(Nam_Ent
) then
860 -- Operations generated for RACW stub types are called only through
861 -- dispatching, and can never be the static interpretation of a call.
863 if Is_RACW_Stub_Type_Operation
(Nam_Ent
) then
868 Analyze_One_Call
(N
, Nam_Ent
, True, Success
);
870 -- If this is an indirect call, the return type of the access_to
871 -- subprogram may be an incomplete type. At the point of the call,
872 -- use the full type if available, and at the same time update
873 -- the return type of the access_to_subprogram.
876 and then Nkind
(Nam
) = N_Explicit_Dereference
877 and then Ekind
(Etype
(N
)) = E_Incomplete_Type
878 and then Present
(Full_View
(Etype
(N
)))
880 Set_Etype
(N
, Full_View
(Etype
(N
)));
881 Set_Etype
(Nam_Ent
, Etype
(N
));
885 -- An overloaded selected component must denote overloaded operations
886 -- of a concurrent type. The interpretations are attached to the
887 -- simple name of those operations.
889 if Nkind
(Nam
) = N_Selected_Component
then
890 Nam
:= Selector_Name
(Nam
);
893 Get_First_Interp
(Nam
, X
, It
);
895 while Present
(It
.Nam
) loop
899 -- Name may be call that returns an access to subprogram, or more
900 -- generally an overloaded expression one of whose interpretations
901 -- yields an access to subprogram. If the name is an entity, we
902 -- do not dereference, because the node is a call that returns
903 -- the access type: note difference between f(x), where the call
904 -- may return an access subprogram type, and f(x)(y), where the
905 -- type returned by the call to f is implicitly dereferenced to
906 -- analyze the outer call.
908 if Is_Access_Type
(Nam_Ent
) then
909 Nam_Ent
:= Designated_Type
(Nam_Ent
);
911 elsif Is_Access_Type
(Etype
(Nam_Ent
))
913 (not Is_Entity_Name
(Nam
)
914 or else Nkind
(N
) = N_Procedure_Call_Statement
)
915 and then Ekind
(Designated_Type
(Etype
(Nam_Ent
)))
918 Nam_Ent
:= Designated_Type
(Etype
(Nam_Ent
));
920 if Is_Entity_Name
(Nam
) then
925 Analyze_One_Call
(N
, Nam_Ent
, False, Success
);
927 -- If the interpretation succeeds, mark the proper type of the
928 -- prefix (any valid candidate will do). If not, remove the
929 -- candidate interpretation. This only needs to be done for
930 -- overloaded protected operations, for other entities disambi-
931 -- guation is done directly in Resolve.
935 and then Nkind
(Parent
(N
)) /= N_Explicit_Dereference
937 Set_Entity
(Nam
, It
.Nam
);
938 Insert_Explicit_Dereference
(Nam
);
939 Set_Etype
(Nam
, Nam_Ent
);
942 Set_Etype
(Nam
, It
.Typ
);
945 elsif Nkind_In
(Name
(N
), N_Selected_Component
,
951 Get_Next_Interp
(X
, It
);
954 -- If the name is the result of a function call, it can only
955 -- be a call to a function returning an access to subprogram.
956 -- Insert explicit dereference.
958 if Nkind
(Nam
) = N_Function_Call
then
959 Insert_Explicit_Dereference
(Nam
);
962 if Etype
(N
) = Any_Type
then
964 -- None of the interpretations is compatible with the actuals
966 Diagnose_Call
(N
, Nam
);
968 -- Special checks for uninstantiated put routines
970 if Nkind
(N
) = N_Procedure_Call_Statement
971 and then Is_Entity_Name
(Nam
)
972 and then Chars
(Nam
) = Name_Put
973 and then List_Length
(Actuals
) = 1
976 Arg
: constant Node_Id
:= First
(Actuals
);
980 if Nkind
(Arg
) = N_Parameter_Association
then
981 Typ
:= Etype
(Explicit_Actual_Parameter
(Arg
));
986 if Is_Signed_Integer_Type
(Typ
) then
988 ("possible missing instantiation of " &
989 "'Text_'I'O.'Integer_'I'O!", Nam
);
991 elsif Is_Modular_Integer_Type
(Typ
) then
993 ("possible missing instantiation of " &
994 "'Text_'I'O.'Modular_'I'O!", Nam
);
996 elsif Is_Floating_Point_Type
(Typ
) then
998 ("possible missing instantiation of " &
999 "'Text_'I'O.'Float_'I'O!", Nam
);
1001 elsif Is_Ordinary_Fixed_Point_Type
(Typ
) then
1003 ("possible missing instantiation of " &
1004 "'Text_'I'O.'Fixed_'I'O!", Nam
);
1006 elsif Is_Decimal_Fixed_Point_Type
(Typ
) then
1008 ("possible missing instantiation of " &
1009 "'Text_'I'O.'Decimal_'I'O!", Nam
);
1011 elsif Is_Enumeration_Type
(Typ
) then
1013 ("possible missing instantiation of " &
1014 "'Text_'I'O.'Enumeration_'I'O!", Nam
);
1019 elsif not Is_Overloaded
(N
)
1020 and then Is_Entity_Name
(Nam
)
1022 -- Resolution yields a single interpretation. Verify that the
1023 -- reference has capitalization consistent with the declaration.
1025 Set_Entity_With_Style_Check
(Nam
, Entity
(Nam
));
1026 Generate_Reference
(Entity
(Nam
), Nam
);
1028 Set_Etype
(Nam
, Etype
(Entity
(Nam
)));
1030 Remove_Abstract_Operations
(N
);
1037 ---------------------------
1038 -- Analyze_Comparison_Op --
1039 ---------------------------
1041 procedure Analyze_Comparison_Op
(N
: Node_Id
) is
1042 L
: constant Node_Id
:= Left_Opnd
(N
);
1043 R
: constant Node_Id
:= Right_Opnd
(N
);
1044 Op_Id
: Entity_Id
:= Entity
(N
);
1047 Set_Etype
(N
, Any_Type
);
1048 Candidate_Type
:= Empty
;
1050 Analyze_Expression
(L
);
1051 Analyze_Expression
(R
);
1053 if Present
(Op_Id
) then
1054 if Ekind
(Op_Id
) = E_Operator
then
1055 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1057 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1060 if Is_Overloaded
(L
) then
1061 Set_Etype
(L
, Intersect_Types
(L
, R
));
1065 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1066 while Present
(Op_Id
) loop
1067 if Ekind
(Op_Id
) = E_Operator
then
1068 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1070 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1073 Op_Id
:= Homonym
(Op_Id
);
1078 end Analyze_Comparison_Op
;
1080 ---------------------------
1081 -- Analyze_Concatenation --
1082 ---------------------------
1084 procedure Analyze_Concatenation
(N
: Node_Id
) is
1086 -- We wish to avoid deep recursion, because concatenations are often
1087 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1088 -- operands nonrecursively until we find something that is not a
1089 -- concatenation (A in this case), or has already been analyzed. We
1090 -- analyze that, and then walk back up the tree following Parent
1091 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1092 -- work at each level. The Parent pointers allow us to avoid recursion,
1093 -- and thus avoid running out of memory.
1099 Candidate_Type
:= Empty
;
1101 -- The following code is equivalent to:
1103 -- Set_Etype (N, Any_Type);
1104 -- Analyze_Expression (Left_Opnd (N));
1105 -- Analyze_Concatenation_Rest (N);
1107 -- where the Analyze_Expression call recurses back here if the left
1108 -- operand is a concatenation.
1110 -- Walk down left operands
1113 Set_Etype
(NN
, Any_Type
);
1114 L
:= Left_Opnd
(NN
);
1115 exit when Nkind
(L
) /= N_Op_Concat
or else Analyzed
(L
);
1119 -- Now (given the above example) NN is A&B and L is A
1121 -- First analyze L ...
1123 Analyze_Expression
(L
);
1125 -- ... then walk NN back up until we reach N (where we started), calling
1126 -- Analyze_Concatenation_Rest along the way.
1129 Analyze_Concatenation_Rest
(NN
);
1133 end Analyze_Concatenation
;
1135 --------------------------------
1136 -- Analyze_Concatenation_Rest --
1137 --------------------------------
1139 -- If the only one-dimensional array type in scope is String,
1140 -- this is the resulting type of the operation. Otherwise there
1141 -- will be a concatenation operation defined for each user-defined
1142 -- one-dimensional array.
1144 procedure Analyze_Concatenation_Rest
(N
: Node_Id
) is
1145 L
: constant Node_Id
:= Left_Opnd
(N
);
1146 R
: constant Node_Id
:= Right_Opnd
(N
);
1147 Op_Id
: Entity_Id
:= Entity
(N
);
1152 Analyze_Expression
(R
);
1154 -- If the entity is present, the node appears in an instance, and
1155 -- denotes a predefined concatenation operation. The resulting type is
1156 -- obtained from the arguments when possible. If the arguments are
1157 -- aggregates, the array type and the concatenation type must be
1160 if Present
(Op_Id
) then
1161 if Ekind
(Op_Id
) = E_Operator
then
1163 LT
:= Base_Type
(Etype
(L
));
1164 RT
:= Base_Type
(Etype
(R
));
1166 if Is_Array_Type
(LT
)
1167 and then (RT
= LT
or else RT
= Base_Type
(Component_Type
(LT
)))
1169 Add_One_Interp
(N
, Op_Id
, LT
);
1171 elsif Is_Array_Type
(RT
)
1172 and then LT
= Base_Type
(Component_Type
(RT
))
1174 Add_One_Interp
(N
, Op_Id
, RT
);
1176 -- If one operand is a string type or a user-defined array type,
1177 -- and the other is a literal, result is of the specific type.
1180 (Root_Type
(LT
) = Standard_String
1181 or else Scope
(LT
) /= Standard_Standard
)
1182 and then Etype
(R
) = Any_String
1184 Add_One_Interp
(N
, Op_Id
, LT
);
1187 (Root_Type
(RT
) = Standard_String
1188 or else Scope
(RT
) /= Standard_Standard
)
1189 and then Etype
(L
) = Any_String
1191 Add_One_Interp
(N
, Op_Id
, RT
);
1193 elsif not Is_Generic_Type
(Etype
(Op_Id
)) then
1194 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1197 -- Type and its operations must be visible
1199 Set_Entity
(N
, Empty
);
1200 Analyze_Concatenation
(N
);
1204 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1208 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Concat
);
1209 while Present
(Op_Id
) loop
1210 if Ekind
(Op_Id
) = E_Operator
then
1212 -- Do not consider operators declared in dead code, they can
1213 -- not be part of the resolution.
1215 if Is_Eliminated
(Op_Id
) then
1218 Find_Concatenation_Types
(L
, R
, Op_Id
, N
);
1222 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1225 Op_Id
:= Homonym
(Op_Id
);
1230 end Analyze_Concatenation_Rest
;
1232 ------------------------------------
1233 -- Analyze_Conditional_Expression --
1234 ------------------------------------
1236 procedure Analyze_Conditional_Expression
(N
: Node_Id
) is
1237 Condition
: constant Node_Id
:= First
(Expressions
(N
));
1238 Then_Expr
: constant Node_Id
:= Next
(Condition
);
1239 Else_Expr
: constant Node_Id
:= Next
(Then_Expr
);
1241 Analyze_Expression
(Condition
);
1242 Analyze_Expression
(Then_Expr
);
1243 Analyze_Expression
(Else_Expr
);
1244 Set_Etype
(N
, Etype
(Then_Expr
));
1245 end Analyze_Conditional_Expression
;
1247 -------------------------
1248 -- Analyze_Equality_Op --
1249 -------------------------
1251 procedure Analyze_Equality_Op
(N
: Node_Id
) is
1252 Loc
: constant Source_Ptr
:= Sloc
(N
);
1253 L
: constant Node_Id
:= Left_Opnd
(N
);
1254 R
: constant Node_Id
:= Right_Opnd
(N
);
1258 Set_Etype
(N
, Any_Type
);
1259 Candidate_Type
:= Empty
;
1261 Analyze_Expression
(L
);
1262 Analyze_Expression
(R
);
1264 -- If the entity is set, the node is a generic instance with a non-local
1265 -- reference to the predefined operator or to a user-defined function.
1266 -- It can also be an inequality that is expanded into the negation of a
1267 -- call to a user-defined equality operator.
1269 -- For the predefined case, the result is Boolean, regardless of the
1270 -- type of the operands. The operands may even be limited, if they are
1271 -- generic actuals. If they are overloaded, label the left argument with
1272 -- the common type that must be present, or with the type of the formal
1273 -- of the user-defined function.
1275 if Present
(Entity
(N
)) then
1276 Op_Id
:= Entity
(N
);
1278 if Ekind
(Op_Id
) = E_Operator
then
1279 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
);
1281 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1284 if Is_Overloaded
(L
) then
1285 if Ekind
(Op_Id
) = E_Operator
then
1286 Set_Etype
(L
, Intersect_Types
(L
, R
));
1288 Set_Etype
(L
, Etype
(First_Formal
(Op_Id
)));
1293 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1294 while Present
(Op_Id
) loop
1295 if Ekind
(Op_Id
) = E_Operator
then
1296 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1298 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1301 Op_Id
:= Homonym
(Op_Id
);
1305 -- If there was no match, and the operator is inequality, this may
1306 -- be a case where inequality has not been made explicit, as for
1307 -- tagged types. Analyze the node as the negation of an equality
1308 -- operation. This cannot be done earlier, because before analysis
1309 -- we cannot rule out the presence of an explicit inequality.
1311 if Etype
(N
) = Any_Type
1312 and then Nkind
(N
) = N_Op_Ne
1314 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Eq
);
1315 while Present
(Op_Id
) loop
1316 if Ekind
(Op_Id
) = E_Operator
then
1317 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1319 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1322 Op_Id
:= Homonym
(Op_Id
);
1325 if Etype
(N
) /= Any_Type
then
1326 Op_Id
:= Entity
(N
);
1332 Left_Opnd
=> Left_Opnd
(N
),
1333 Right_Opnd
=> Right_Opnd
(N
))));
1335 Set_Entity
(Right_Opnd
(N
), Op_Id
);
1341 end Analyze_Equality_Op
;
1343 ----------------------------------
1344 -- Analyze_Explicit_Dereference --
1345 ----------------------------------
1347 procedure Analyze_Explicit_Dereference
(N
: Node_Id
) is
1348 Loc
: constant Source_Ptr
:= Sloc
(N
);
1349 P
: constant Node_Id
:= Prefix
(N
);
1355 function Is_Function_Type
return Boolean;
1356 -- Check whether node may be interpreted as an implicit function call
1358 ----------------------
1359 -- Is_Function_Type --
1360 ----------------------
1362 function Is_Function_Type
return Boolean is
1367 if not Is_Overloaded
(N
) then
1368 return Ekind
(Base_Type
(Etype
(N
))) = E_Subprogram_Type
1369 and then Etype
(Base_Type
(Etype
(N
))) /= Standard_Void_Type
;
1372 Get_First_Interp
(N
, I
, It
);
1373 while Present
(It
.Nam
) loop
1374 if Ekind
(Base_Type
(It
.Typ
)) /= E_Subprogram_Type
1375 or else Etype
(Base_Type
(It
.Typ
)) = Standard_Void_Type
1380 Get_Next_Interp
(I
, It
);
1385 end Is_Function_Type
;
1387 -- Start of processing for Analyze_Explicit_Dereference
1391 Set_Etype
(N
, Any_Type
);
1393 -- Test for remote access to subprogram type, and if so return
1394 -- after rewriting the original tree.
1396 if Remote_AST_E_Dereference
(P
) then
1400 -- Normal processing for other than remote access to subprogram type
1402 if not Is_Overloaded
(P
) then
1403 if Is_Access_Type
(Etype
(P
)) then
1405 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
1406 -- avoid other problems caused by the Private_Subtype and it is
1407 -- safe to go to the Base_Type because this is the same as
1408 -- converting the access value to its Base_Type.
1411 DT
: Entity_Id
:= Designated_Type
(Etype
(P
));
1414 if Ekind
(DT
) = E_Private_Subtype
1415 and then Is_For_Access_Subtype
(DT
)
1417 DT
:= Base_Type
(DT
);
1420 -- An explicit dereference is a legal occurrence of an
1421 -- incomplete type imported through a limited_with clause,
1422 -- if the full view is visible.
1424 if From_With_Type
(DT
)
1425 and then not From_With_Type
(Scope
(DT
))
1427 (Is_Immediately_Visible
(Scope
(DT
))
1429 (Is_Child_Unit
(Scope
(DT
))
1430 and then Is_Visible_Child_Unit
(Scope
(DT
))))
1432 Set_Etype
(N
, Available_View
(DT
));
1439 elsif Etype
(P
) /= Any_Type
then
1440 Error_Msg_N
("prefix of dereference must be an access type", N
);
1445 Get_First_Interp
(P
, I
, It
);
1446 while Present
(It
.Nam
) loop
1449 if Is_Access_Type
(T
) then
1450 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
1453 Get_Next_Interp
(I
, It
);
1456 -- Error if no interpretation of the prefix has an access type
1458 if Etype
(N
) = Any_Type
then
1460 ("access type required in prefix of explicit dereference", P
);
1461 Set_Etype
(N
, Any_Type
);
1467 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
1469 and then (Nkind
(Parent
(N
)) /= N_Function_Call
1470 or else N
/= Name
(Parent
(N
)))
1472 and then (Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1473 or else N
/= Name
(Parent
(N
)))
1475 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
1476 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
1478 (Attribute_Name
(Parent
(N
)) /= Name_Address
1480 Attribute_Name
(Parent
(N
)) /= Name_Access
))
1482 -- Name is a function call with no actuals, in a context that
1483 -- requires deproceduring (including as an actual in an enclosing
1484 -- function or procedure call). There are some pathological cases
1485 -- where the prefix might include functions that return access to
1486 -- subprograms and others that return a regular type. Disambiguation
1487 -- of those has to take place in Resolve.
1490 Make_Function_Call
(Loc
,
1491 Name
=> Make_Explicit_Dereference
(Loc
, P
),
1492 Parameter_Associations
=> New_List
);
1494 -- If the prefix is overloaded, remove operations that have formals,
1495 -- we know that this is a parameterless call.
1497 if Is_Overloaded
(P
) then
1498 Get_First_Interp
(P
, I
, It
);
1499 while Present
(It
.Nam
) loop
1502 if No
(First_Formal
(Base_Type
(Designated_Type
(T
)))) then
1508 Get_Next_Interp
(I
, It
);
1515 elsif not Is_Function_Type
1516 and then Is_Overloaded
(N
)
1518 -- The prefix may include access to subprograms and other access
1519 -- types. If the context selects the interpretation that is a
1520 -- function call (not a procedure call) we cannot rewrite the node
1521 -- yet, but we include the result of the call interpretation.
1523 Get_First_Interp
(N
, I
, It
);
1524 while Present
(It
.Nam
) loop
1525 if Ekind
(Base_Type
(It
.Typ
)) = E_Subprogram_Type
1526 and then Etype
(Base_Type
(It
.Typ
)) /= Standard_Void_Type
1527 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1529 Add_One_Interp
(N
, Etype
(It
.Typ
), Etype
(It
.Typ
));
1532 Get_Next_Interp
(I
, It
);
1536 -- A value of remote access-to-class-wide must not be dereferenced
1539 Validate_Remote_Access_To_Class_Wide_Type
(N
);
1540 end Analyze_Explicit_Dereference
;
1542 ------------------------
1543 -- Analyze_Expression --
1544 ------------------------
1546 procedure Analyze_Expression
(N
: Node_Id
) is
1549 Check_Parameterless_Call
(N
);
1550 end Analyze_Expression
;
1552 ------------------------------------
1553 -- Analyze_Indexed_Component_Form --
1554 ------------------------------------
1556 procedure Analyze_Indexed_Component_Form
(N
: Node_Id
) is
1557 P
: constant Node_Id
:= Prefix
(N
);
1558 Exprs
: constant List_Id
:= Expressions
(N
);
1564 procedure Process_Function_Call
;
1565 -- Prefix in indexed component form is an overloadable entity,
1566 -- so the node is a function call. Reformat it as such.
1568 procedure Process_Indexed_Component
;
1569 -- Prefix in indexed component form is actually an indexed component.
1570 -- This routine processes it, knowing that the prefix is already
1573 procedure Process_Indexed_Component_Or_Slice
;
1574 -- An indexed component with a single index may designate a slice if
1575 -- the index is a subtype mark. This routine disambiguates these two
1576 -- cases by resolving the prefix to see if it is a subtype mark.
1578 procedure Process_Overloaded_Indexed_Component
;
1579 -- If the prefix of an indexed component is overloaded, the proper
1580 -- interpretation is selected by the index types and the context.
1582 ---------------------------
1583 -- Process_Function_Call --
1584 ---------------------------
1586 procedure Process_Function_Call
is
1590 Change_Node
(N
, N_Function_Call
);
1592 Set_Parameter_Associations
(N
, Exprs
);
1594 -- Analyze actuals prior to analyzing the call itself
1596 Actual
:= First
(Parameter_Associations
(N
));
1597 while Present
(Actual
) loop
1599 Check_Parameterless_Call
(Actual
);
1601 -- Move to next actual. Note that we use Next, not Next_Actual
1602 -- here. The reason for this is a bit subtle. If a function call
1603 -- includes named associations, the parser recognizes the node as
1604 -- a call, and it is analyzed as such. If all associations are
1605 -- positional, the parser builds an indexed_component node, and
1606 -- it is only after analysis of the prefix that the construct
1607 -- is recognized as a call, in which case Process_Function_Call
1608 -- rewrites the node and analyzes the actuals. If the list of
1609 -- actuals is malformed, the parser may leave the node as an
1610 -- indexed component (despite the presence of named associations).
1611 -- The iterator Next_Actual is equivalent to Next if the list is
1612 -- positional, but follows the normalized chain of actuals when
1613 -- named associations are present. In this case normalization has
1614 -- not taken place, and actuals remain unanalyzed, which leads to
1615 -- subsequent crashes or loops if there is an attempt to continue
1616 -- analysis of the program.
1622 end Process_Function_Call
;
1624 -------------------------------
1625 -- Process_Indexed_Component --
1626 -------------------------------
1628 procedure Process_Indexed_Component
is
1630 Array_Type
: Entity_Id
;
1632 Pent
: Entity_Id
:= Empty
;
1635 Exp
:= First
(Exprs
);
1637 if Is_Overloaded
(P
) then
1638 Process_Overloaded_Indexed_Component
;
1641 Array_Type
:= Etype
(P
);
1643 if Is_Entity_Name
(P
) then
1645 elsif Nkind
(P
) = N_Selected_Component
1646 and then Is_Entity_Name
(Selector_Name
(P
))
1648 Pent
:= Entity
(Selector_Name
(P
));
1651 -- Prefix must be appropriate for an array type, taking into
1652 -- account a possible implicit dereference.
1654 if Is_Access_Type
(Array_Type
) then
1655 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
1656 Array_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, P
);
1659 if Is_Array_Type
(Array_Type
) then
1662 elsif Present
(Pent
) and then Ekind
(Pent
) = E_Entry_Family
then
1664 Set_Etype
(N
, Any_Type
);
1666 if not Has_Compatible_Type
1667 (Exp
, Entry_Index_Type
(Pent
))
1669 Error_Msg_N
("invalid index type in entry name", N
);
1671 elsif Present
(Next
(Exp
)) then
1672 Error_Msg_N
("too many subscripts in entry reference", N
);
1675 Set_Etype
(N
, Etype
(P
));
1680 elsif Is_Record_Type
(Array_Type
)
1681 and then Remote_AST_I_Dereference
(P
)
1685 elsif Array_Type
= Any_Type
then
1686 Set_Etype
(N
, Any_Type
);
1689 -- Here we definitely have a bad indexing
1692 if Nkind
(Parent
(N
)) = N_Requeue_Statement
1693 and then Present
(Pent
) and then Ekind
(Pent
) = E_Entry
1696 ("REQUEUE does not permit parameters", First
(Exprs
));
1698 elsif Is_Entity_Name
(P
)
1699 and then Etype
(P
) = Standard_Void_Type
1701 Error_Msg_NE
("incorrect use of&", P
, Entity
(P
));
1704 Error_Msg_N
("array type required in indexed component", P
);
1707 Set_Etype
(N
, Any_Type
);
1711 Index
:= First_Index
(Array_Type
);
1712 while Present
(Index
) and then Present
(Exp
) loop
1713 if not Has_Compatible_Type
(Exp
, Etype
(Index
)) then
1714 Wrong_Type
(Exp
, Etype
(Index
));
1715 Set_Etype
(N
, Any_Type
);
1723 Set_Etype
(N
, Component_Type
(Array_Type
));
1725 if Present
(Index
) then
1727 ("too few subscripts in array reference", First
(Exprs
));
1729 elsif Present
(Exp
) then
1730 Error_Msg_N
("too many subscripts in array reference", Exp
);
1733 end Process_Indexed_Component
;
1735 ----------------------------------------
1736 -- Process_Indexed_Component_Or_Slice --
1737 ----------------------------------------
1739 procedure Process_Indexed_Component_Or_Slice
is
1741 Exp
:= First
(Exprs
);
1742 while Present
(Exp
) loop
1743 Analyze_Expression
(Exp
);
1747 Exp
:= First
(Exprs
);
1749 -- If one index is present, and it is a subtype name, then the
1750 -- node denotes a slice (note that the case of an explicit range
1751 -- for a slice was already built as an N_Slice node in the first
1752 -- place, so that case is not handled here).
1754 -- We use a replace rather than a rewrite here because this is one
1755 -- of the cases in which the tree built by the parser is plain wrong.
1758 and then Is_Entity_Name
(Exp
)
1759 and then Is_Type
(Entity
(Exp
))
1762 Make_Slice
(Sloc
(N
),
1764 Discrete_Range
=> New_Copy
(Exp
)));
1767 -- Otherwise (more than one index present, or single index is not
1768 -- a subtype name), then we have the indexed component case.
1771 Process_Indexed_Component
;
1773 end Process_Indexed_Component_Or_Slice
;
1775 ------------------------------------------
1776 -- Process_Overloaded_Indexed_Component --
1777 ------------------------------------------
1779 procedure Process_Overloaded_Indexed_Component
is
1788 Set_Etype
(N
, Any_Type
);
1790 Get_First_Interp
(P
, I
, It
);
1791 while Present
(It
.Nam
) loop
1794 if Is_Access_Type
(Typ
) then
1795 Typ
:= Designated_Type
(Typ
);
1796 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
1799 if Is_Array_Type
(Typ
) then
1801 -- Got a candidate: verify that index types are compatible
1803 Index
:= First_Index
(Typ
);
1805 Exp
:= First
(Exprs
);
1806 while Present
(Index
) and then Present
(Exp
) loop
1807 if Has_Compatible_Type
(Exp
, Etype
(Index
)) then
1819 if Found
and then No
(Index
) and then No
(Exp
) then
1821 Etype
(Component_Type
(Typ
)),
1822 Etype
(Component_Type
(Typ
)));
1826 Get_Next_Interp
(I
, It
);
1829 if Etype
(N
) = Any_Type
then
1830 Error_Msg_N
("no legal interpretation for indexed component", N
);
1831 Set_Is_Overloaded
(N
, False);
1835 end Process_Overloaded_Indexed_Component
;
1837 -- Start of processing for Analyze_Indexed_Component_Form
1840 -- Get name of array, function or type
1844 if Nkind_In
(N
, N_Function_Call
, N_Procedure_Call_Statement
) then
1846 -- If P is an explicit dereference whose prefix is of a
1847 -- remote access-to-subprogram type, then N has already
1848 -- been rewritten as a subprogram call and analyzed.
1853 pragma Assert
(Nkind
(N
) = N_Indexed_Component
);
1855 P_T
:= Base_Type
(Etype
(P
));
1857 if Is_Entity_Name
(P
)
1858 or else Nkind
(P
) = N_Operator_Symbol
1862 if Is_Type
(U_N
) then
1864 -- Reformat node as a type conversion
1866 E
:= Remove_Head
(Exprs
);
1868 if Present
(First
(Exprs
)) then
1870 ("argument of type conversion must be single expression", N
);
1873 Change_Node
(N
, N_Type_Conversion
);
1874 Set_Subtype_Mark
(N
, P
);
1876 Set_Expression
(N
, E
);
1878 -- After changing the node, call for the specific Analysis
1879 -- routine directly, to avoid a double call to the expander.
1881 Analyze_Type_Conversion
(N
);
1885 if Is_Overloadable
(U_N
) then
1886 Process_Function_Call
;
1888 elsif Ekind
(Etype
(P
)) = E_Subprogram_Type
1889 or else (Is_Access_Type
(Etype
(P
))
1891 Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
)
1893 -- Call to access_to-subprogram with possible implicit dereference
1895 Process_Function_Call
;
1897 elsif Is_Generic_Subprogram
(U_N
) then
1899 -- A common beginner's (or C++ templates fan) error
1901 Error_Msg_N
("generic subprogram cannot be called", N
);
1902 Set_Etype
(N
, Any_Type
);
1906 Process_Indexed_Component_Or_Slice
;
1909 -- If not an entity name, prefix is an expression that may denote
1910 -- an array or an access-to-subprogram.
1913 if Ekind
(P_T
) = E_Subprogram_Type
1914 or else (Is_Access_Type
(P_T
)
1916 Ekind
(Designated_Type
(P_T
)) = E_Subprogram_Type
)
1918 Process_Function_Call
;
1920 elsif Nkind
(P
) = N_Selected_Component
1921 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
1923 Process_Function_Call
;
1926 -- Indexed component, slice, or a call to a member of a family
1927 -- entry, which will be converted to an entry call later.
1929 Process_Indexed_Component_Or_Slice
;
1932 end Analyze_Indexed_Component_Form
;
1934 ------------------------
1935 -- Analyze_Logical_Op --
1936 ------------------------
1938 procedure Analyze_Logical_Op
(N
: Node_Id
) is
1939 L
: constant Node_Id
:= Left_Opnd
(N
);
1940 R
: constant Node_Id
:= Right_Opnd
(N
);
1941 Op_Id
: Entity_Id
:= Entity
(N
);
1944 Set_Etype
(N
, Any_Type
);
1945 Candidate_Type
:= Empty
;
1947 Analyze_Expression
(L
);
1948 Analyze_Expression
(R
);
1950 if Present
(Op_Id
) then
1952 if Ekind
(Op_Id
) = E_Operator
then
1953 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
1955 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1959 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1960 while Present
(Op_Id
) loop
1961 if Ekind
(Op_Id
) = E_Operator
then
1962 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
1964 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1967 Op_Id
:= Homonym
(Op_Id
);
1972 end Analyze_Logical_Op
;
1974 ---------------------------
1975 -- Analyze_Membership_Op --
1976 ---------------------------
1978 procedure Analyze_Membership_Op
(N
: Node_Id
) is
1979 L
: constant Node_Id
:= Left_Opnd
(N
);
1980 R
: constant Node_Id
:= Right_Opnd
(N
);
1982 Index
: Interp_Index
;
1984 Found
: Boolean := False;
1988 procedure Try_One_Interp
(T1
: Entity_Id
);
1989 -- Routine to try one proposed interpretation. Note that the context
1990 -- of the operation plays no role in resolving the arguments, so that
1991 -- if there is more than one interpretation of the operands that is
1992 -- compatible with a membership test, the operation is ambiguous.
1994 --------------------
1995 -- Try_One_Interp --
1996 --------------------
1998 procedure Try_One_Interp
(T1
: Entity_Id
) is
2000 if Has_Compatible_Type
(R
, T1
) then
2002 and then Base_Type
(T1
) /= Base_Type
(T_F
)
2004 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
2006 if It
= No_Interp
then
2007 Ambiguous_Operands
(N
);
2008 Set_Etype
(L
, Any_Type
);
2026 -- Start of processing for Analyze_Membership_Op
2029 Analyze_Expression
(L
);
2031 if Nkind
(R
) = N_Range
2032 or else (Nkind
(R
) = N_Attribute_Reference
2033 and then Attribute_Name
(R
) = Name_Range
)
2037 if not Is_Overloaded
(L
) then
2038 Try_One_Interp
(Etype
(L
));
2041 Get_First_Interp
(L
, Index
, It
);
2042 while Present
(It
.Typ
) loop
2043 Try_One_Interp
(It
.Typ
);
2044 Get_Next_Interp
(Index
, It
);
2048 -- If not a range, it can only be a subtype mark, or else there
2049 -- is a more basic error, to be diagnosed in Find_Type.
2054 if Is_Entity_Name
(R
) then
2055 Check_Fully_Declared
(Entity
(R
), R
);
2059 -- Compatibility between expression and subtype mark or range is
2060 -- checked during resolution. The result of the operation is Boolean
2063 Set_Etype
(N
, Standard_Boolean
);
2065 if Comes_From_Source
(N
)
2066 and then Is_CPP_Class
(Etype
(Etype
(Right_Opnd
(N
))))
2068 Error_Msg_N
("membership test not applicable to cpp-class types", N
);
2070 end Analyze_Membership_Op
;
2072 ----------------------
2073 -- Analyze_Negation --
2074 ----------------------
2076 procedure Analyze_Negation
(N
: Node_Id
) is
2077 R
: constant Node_Id
:= Right_Opnd
(N
);
2078 Op_Id
: Entity_Id
:= Entity
(N
);
2081 Set_Etype
(N
, Any_Type
);
2082 Candidate_Type
:= Empty
;
2084 Analyze_Expression
(R
);
2086 if Present
(Op_Id
) then
2087 if Ekind
(Op_Id
) = E_Operator
then
2088 Find_Negation_Types
(R
, Op_Id
, N
);
2090 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2094 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
2095 while Present
(Op_Id
) loop
2096 if Ekind
(Op_Id
) = E_Operator
then
2097 Find_Negation_Types
(R
, Op_Id
, N
);
2099 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
2102 Op_Id
:= Homonym
(Op_Id
);
2107 end Analyze_Negation
;
2113 procedure Analyze_Null
(N
: Node_Id
) is
2115 Set_Etype
(N
, Any_Access
);
2118 ----------------------
2119 -- Analyze_One_Call --
2120 ----------------------
2122 procedure Analyze_One_Call
2126 Success
: out Boolean;
2127 Skip_First
: Boolean := False)
2129 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
2130 Prev_T
: constant Entity_Id
:= Etype
(N
);
2132 Must_Skip
: constant Boolean := Skip_First
2133 or else Nkind
(Original_Node
(N
)) = N_Selected_Component
2135 (Nkind
(Original_Node
(N
)) = N_Indexed_Component
2136 and then Nkind
(Prefix
(Original_Node
(N
)))
2137 = N_Selected_Component
);
2138 -- The first formal must be omitted from the match when trying to find
2139 -- a primitive operation that is a possible interpretation, and also
2140 -- after the call has been rewritten, because the corresponding actual
2141 -- is already known to be compatible, and because this may be an
2142 -- indexing of a call with default parameters.
2146 Is_Indexed
: Boolean := False;
2147 Is_Indirect
: Boolean := False;
2148 Subp_Type
: constant Entity_Id
:= Etype
(Nam
);
2151 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean;
2152 -- There may be a user-defined operator that hides the current
2153 -- interpretation. We must check for this independently of the
2154 -- analysis of the call with the user-defined operation, because
2155 -- the parameter names may be wrong and yet the hiding takes place.
2156 -- This fixes a problem with ACATS test B34014O.
2158 -- When the type Address is a visible integer type, and the DEC
2159 -- system extension is visible, the predefined operator may be
2160 -- hidden as well, by one of the address operations in auxdec.
2161 -- Finally, The abstract operations on address do not hide the
2162 -- predefined operator (this is the purpose of making them abstract).
2164 procedure Indicate_Name_And_Type
;
2165 -- If candidate interpretation matches, indicate name and type of
2166 -- result on call node.
2168 ----------------------------
2169 -- Indicate_Name_And_Type --
2170 ----------------------------
2172 procedure Indicate_Name_And_Type
is
2174 Add_One_Interp
(N
, Nam
, Etype
(Nam
));
2177 -- If the prefix of the call is a name, indicate the entity
2178 -- being called. If it is not a name, it is an expression that
2179 -- denotes an access to subprogram or else an entry or family. In
2180 -- the latter case, the name is a selected component, and the entity
2181 -- being called is noted on the selector.
2183 if not Is_Type
(Nam
) then
2184 if Is_Entity_Name
(Name
(N
))
2185 or else Nkind
(Name
(N
)) = N_Operator_Symbol
2187 Set_Entity
(Name
(N
), Nam
);
2189 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
2190 Set_Entity
(Selector_Name
(Name
(N
)), Nam
);
2194 if Debug_Flag_E
and not Report
then
2195 Write_Str
(" Overloaded call ");
2196 Write_Int
(Int
(N
));
2197 Write_Str
(" compatible with ");
2198 Write_Int
(Int
(Nam
));
2201 end Indicate_Name_And_Type
;
2203 ------------------------
2204 -- Operator_Hidden_By --
2205 ------------------------
2207 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean is
2208 Act1
: constant Node_Id
:= First_Actual
(N
);
2209 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
2210 Form1
: constant Entity_Id
:= First_Formal
(Fun
);
2211 Form2
: constant Entity_Id
:= Next_Formal
(Form1
);
2214 if Ekind
(Fun
) /= E_Function
2215 or else Is_Abstract_Subprogram
(Fun
)
2219 elsif not Has_Compatible_Type
(Act1
, Etype
(Form1
)) then
2222 elsif Present
(Form2
) then
2224 No
(Act2
) or else not Has_Compatible_Type
(Act2
, Etype
(Form2
))
2229 elsif Present
(Act2
) then
2233 -- Now we know that the arity of the operator matches the function,
2234 -- and the function call is a valid interpretation. The function
2235 -- hides the operator if it has the right signature, or if one of
2236 -- its operands is a non-abstract operation on Address when this is
2237 -- a visible integer type.
2239 return Hides_Op
(Fun
, Nam
)
2240 or else Is_Descendent_Of_Address
(Etype
(Form1
))
2243 and then Is_Descendent_Of_Address
(Etype
(Form2
)));
2244 end Operator_Hidden_By
;
2246 -- Start of processing for Analyze_One_Call
2251 -- If the subprogram has no formals or if all the formals have defaults,
2252 -- and the return type is an array type, the node may denote an indexing
2253 -- of the result of a parameterless call. In Ada 2005, the subprogram
2254 -- may have one non-defaulted formal, and the call may have been written
2255 -- in prefix notation, so that the rebuilt parameter list has more than
2258 if not Is_Overloadable
(Nam
)
2259 and then Ekind
(Nam
) /= E_Subprogram_Type
2260 and then Ekind
(Nam
) /= E_Entry_Family
2265 if Present
(Actuals
)
2267 (Needs_No_Actuals
(Nam
)
2269 (Needs_One_Actual
(Nam
)
2270 and then Present
(Next_Actual
(First
(Actuals
)))))
2272 if Is_Array_Type
(Subp_Type
) then
2273 Is_Indexed
:= Try_Indexed_Call
(N
, Nam
, Subp_Type
, Must_Skip
);
2275 elsif Is_Access_Type
(Subp_Type
)
2276 and then Is_Array_Type
(Designated_Type
(Subp_Type
))
2280 (N
, Nam
, Designated_Type
(Subp_Type
), Must_Skip
);
2282 -- The prefix can also be a parameterless function that returns an
2283 -- access to subprogram, in which case this is an indirect call.
2284 -- If this succeeds, an explicit dereference is added later on,
2285 -- in Analyze_Call or Resolve_Call.
2287 elsif Is_Access_Type
(Subp_Type
)
2288 and then Ekind
(Designated_Type
(Subp_Type
)) = E_Subprogram_Type
2290 Is_Indirect
:= Try_Indirect_Call
(N
, Nam
, Subp_Type
);
2295 -- If the call has been transformed into a slice, it is of the form
2296 -- F (Subtype) where F is parameterless. The node has been rewritten in
2297 -- Try_Indexed_Call and there is nothing else to do.
2300 and then Nkind
(N
) = N_Slice
2306 (N
, Nam
, (Report
and not Is_Indexed
and not Is_Indirect
), Norm_OK
);
2310 -- If an indirect call is a possible interpretation, indicate
2311 -- success to the caller.
2317 -- Mismatch in number or names of parameters
2319 elsif Debug_Flag_E
then
2320 Write_Str
(" normalization fails in call ");
2321 Write_Int
(Int
(N
));
2322 Write_Str
(" with subprogram ");
2323 Write_Int
(Int
(Nam
));
2327 -- If the context expects a function call, discard any interpretation
2328 -- that is a procedure. If the node is not overloaded, leave as is for
2329 -- better error reporting when type mismatch is found.
2331 elsif Nkind
(N
) = N_Function_Call
2332 and then Is_Overloaded
(Name
(N
))
2333 and then Ekind
(Nam
) = E_Procedure
2337 -- Ditto for function calls in a procedure context
2339 elsif Nkind
(N
) = N_Procedure_Call_Statement
2340 and then Is_Overloaded
(Name
(N
))
2341 and then Etype
(Nam
) /= Standard_Void_Type
2345 elsif No
(Actuals
) then
2347 -- If Normalize succeeds, then there are default parameters for
2350 Indicate_Name_And_Type
;
2352 elsif Ekind
(Nam
) = E_Operator
then
2353 if Nkind
(N
) = N_Procedure_Call_Statement
then
2357 -- This can occur when the prefix of the call is an operator
2358 -- name or an expanded name whose selector is an operator name.
2360 Analyze_Operator_Call
(N
, Nam
);
2362 if Etype
(N
) /= Prev_T
then
2364 -- Check that operator is not hidden by a function interpretation
2366 if Is_Overloaded
(Name
(N
)) then
2372 Get_First_Interp
(Name
(N
), I
, It
);
2373 while Present
(It
.Nam
) loop
2374 if Operator_Hidden_By
(It
.Nam
) then
2375 Set_Etype
(N
, Prev_T
);
2379 Get_Next_Interp
(I
, It
);
2384 -- If operator matches formals, record its name on the call.
2385 -- If the operator is overloaded, Resolve will select the
2386 -- correct one from the list of interpretations. The call
2387 -- node itself carries the first candidate.
2389 Set_Entity
(Name
(N
), Nam
);
2392 elsif Report
and then Etype
(N
) = Any_Type
then
2393 Error_Msg_N
("incompatible arguments for operator", N
);
2397 -- Normalize_Actuals has chained the named associations in the
2398 -- correct order of the formals.
2400 Actual
:= First_Actual
(N
);
2401 Formal
:= First_Formal
(Nam
);
2403 -- If we are analyzing a call rewritten from object notation,
2404 -- skip first actual, which may be rewritten later as an
2405 -- explicit dereference.
2408 Next_Actual
(Actual
);
2409 Next_Formal
(Formal
);
2412 while Present
(Actual
) and then Present
(Formal
) loop
2413 if Nkind
(Parent
(Actual
)) /= N_Parameter_Association
2414 or else Chars
(Selector_Name
(Parent
(Actual
))) = Chars
(Formal
)
2416 -- The actual can be compatible with the formal, but we must
2417 -- also check that the context is not an address type that is
2418 -- visibly an integer type, as is the case in VMS_64. In this
2419 -- case the use of literals is illegal, except in the body of
2420 -- descendents of system, where arithmetic operations on
2421 -- address are of course used.
2423 if Has_Compatible_Type
(Actual
, Etype
(Formal
))
2425 (Etype
(Actual
) /= Universal_Integer
2426 or else not Is_Descendent_Of_Address
(Etype
(Formal
))
2428 Is_Predefined_File_Name
2429 (Unit_File_Name
(Get_Source_Unit
(N
))))
2431 Next_Actual
(Actual
);
2432 Next_Formal
(Formal
);
2435 if Debug_Flag_E
then
2436 Write_Str
(" type checking fails in call ");
2437 Write_Int
(Int
(N
));
2438 Write_Str
(" with formal ");
2439 Write_Int
(Int
(Formal
));
2440 Write_Str
(" in subprogram ");
2441 Write_Int
(Int
(Nam
));
2445 if Report
and not Is_Indexed
and not Is_Indirect
then
2447 -- Ada 2005 (AI-251): Complete the error notification
2448 -- to help new Ada 2005 users
2450 if Is_Class_Wide_Type
(Etype
(Formal
))
2451 and then Is_Interface
(Etype
(Etype
(Formal
)))
2452 and then not Interface_Present_In_Ancestor
2453 (Typ
=> Etype
(Actual
),
2454 Iface
=> Etype
(Etype
(Formal
)))
2457 ("(Ada 2005) does not implement interface }",
2458 Actual
, Etype
(Etype
(Formal
)));
2461 Wrong_Type
(Actual
, Etype
(Formal
));
2463 if Nkind
(Actual
) = N_Op_Eq
2464 and then Nkind
(Left_Opnd
(Actual
)) = N_Identifier
2466 Formal
:= First_Formal
(Nam
);
2467 while Present
(Formal
) loop
2468 if Chars
(Left_Opnd
(Actual
)) = Chars
(Formal
) then
2469 Error_Msg_N
-- CODEFIX
2470 ("possible misspelling of `='>`!", Actual
);
2474 Next_Formal
(Formal
);
2478 if All_Errors_Mode
then
2479 Error_Msg_Sloc
:= Sloc
(Nam
);
2481 if Is_Overloadable
(Nam
)
2482 and then Present
(Alias
(Nam
))
2483 and then not Comes_From_Source
(Nam
)
2486 ("\\ =='> in call to inherited operation & #!",
2489 elsif Ekind
(Nam
) = E_Subprogram_Type
then
2491 Access_To_Subprogram_Typ
:
2492 constant Entity_Id
:=
2494 (Associated_Node_For_Itype
(Nam
));
2497 "\\ =='> in call to dereference of &#!",
2498 Actual
, Access_To_Subprogram_Typ
);
2503 ("\\ =='> in call to &#!", Actual
, Nam
);
2513 -- Normalize_Actuals has verified that a default value exists
2514 -- for this formal. Current actual names a subsequent formal.
2516 Next_Formal
(Formal
);
2520 -- On exit, all actuals match
2522 Indicate_Name_And_Type
;
2524 end Analyze_One_Call
;
2526 ---------------------------
2527 -- Analyze_Operator_Call --
2528 ---------------------------
2530 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
) is
2531 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
2532 Act1
: constant Node_Id
:= First_Actual
(N
);
2533 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
2536 -- Binary operator case
2538 if Present
(Act2
) then
2540 -- If more than two operands, then not binary operator after all
2542 if Present
(Next_Actual
(Act2
)) then
2545 elsif Op_Name
= Name_Op_Add
2546 or else Op_Name
= Name_Op_Subtract
2547 or else Op_Name
= Name_Op_Multiply
2548 or else Op_Name
= Name_Op_Divide
2549 or else Op_Name
= Name_Op_Mod
2550 or else Op_Name
= Name_Op_Rem
2551 or else Op_Name
= Name_Op_Expon
2553 Find_Arithmetic_Types
(Act1
, Act2
, Op_Id
, N
);
2555 elsif Op_Name
= Name_Op_And
2556 or else Op_Name
= Name_Op_Or
2557 or else Op_Name
= Name_Op_Xor
2559 Find_Boolean_Types
(Act1
, Act2
, Op_Id
, N
);
2561 elsif Op_Name
= Name_Op_Lt
2562 or else Op_Name
= Name_Op_Le
2563 or else Op_Name
= Name_Op_Gt
2564 or else Op_Name
= Name_Op_Ge
2566 Find_Comparison_Types
(Act1
, Act2
, Op_Id
, N
);
2568 elsif Op_Name
= Name_Op_Eq
2569 or else Op_Name
= Name_Op_Ne
2571 Find_Equality_Types
(Act1
, Act2
, Op_Id
, N
);
2573 elsif Op_Name
= Name_Op_Concat
then
2574 Find_Concatenation_Types
(Act1
, Act2
, Op_Id
, N
);
2576 -- Is this else null correct, or should it be an abort???
2582 -- Unary operator case
2585 if Op_Name
= Name_Op_Subtract
or else
2586 Op_Name
= Name_Op_Add
or else
2587 Op_Name
= Name_Op_Abs
2589 Find_Unary_Types
(Act1
, Op_Id
, N
);
2592 Op_Name
= Name_Op_Not
2594 Find_Negation_Types
(Act1
, Op_Id
, N
);
2596 -- Is this else null correct, or should it be an abort???
2602 end Analyze_Operator_Call
;
2604 -------------------------------------------
2605 -- Analyze_Overloaded_Selected_Component --
2606 -------------------------------------------
2608 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
) is
2609 Nam
: constant Node_Id
:= Prefix
(N
);
2610 Sel
: constant Node_Id
:= Selector_Name
(N
);
2617 Set_Etype
(Sel
, Any_Type
);
2619 Get_First_Interp
(Nam
, I
, It
);
2620 while Present
(It
.Typ
) loop
2621 if Is_Access_Type
(It
.Typ
) then
2622 T
:= Designated_Type
(It
.Typ
);
2623 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
2628 if Is_Record_Type
(T
) then
2630 -- If the prefix is a class-wide type, the visible components are
2631 -- those of the base type.
2633 if Is_Class_Wide_Type
(T
) then
2637 Comp
:= First_Entity
(T
);
2638 while Present
(Comp
) loop
2639 if Chars
(Comp
) = Chars
(Sel
)
2640 and then Is_Visible_Component
(Comp
)
2643 -- AI05-105: if the context is an object renaming with
2644 -- an anonymous access type, the expected type of the
2645 -- object must be anonymous. This is a name resolution rule.
2647 if Nkind
(Parent
(N
)) /= N_Object_Renaming_Declaration
2648 or else No
(Access_Definition
(Parent
(N
)))
2649 or else Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Type
2651 Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Subprogram_Type
2653 Set_Entity
(Sel
, Comp
);
2654 Set_Etype
(Sel
, Etype
(Comp
));
2655 Add_One_Interp
(N
, Etype
(Comp
), Etype
(Comp
));
2657 -- This also specifies a candidate to resolve the name.
2658 -- Further overloading will be resolved from context.
2659 -- The selector name itself does not carry overloading
2662 Set_Etype
(Nam
, It
.Typ
);
2665 -- Named access type in the context of a renaming
2666 -- declaration with an access definition. Remove
2667 -- inapplicable candidate.
2676 elsif Is_Concurrent_Type
(T
) then
2677 Comp
:= First_Entity
(T
);
2678 while Present
(Comp
)
2679 and then Comp
/= First_Private_Entity
(T
)
2681 if Chars
(Comp
) = Chars
(Sel
) then
2682 if Is_Overloadable
(Comp
) then
2683 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
2685 Set_Entity_With_Style_Check
(Sel
, Comp
);
2686 Generate_Reference
(Comp
, Sel
);
2689 Set_Etype
(Sel
, Etype
(Comp
));
2690 Set_Etype
(N
, Etype
(Comp
));
2691 Set_Etype
(Nam
, It
.Typ
);
2693 -- For access type case, introduce explicit deference for
2694 -- more uniform treatment of entry calls. Do this only
2695 -- once if several interpretations yield an access type.
2697 if Is_Access_Type
(Etype
(Nam
))
2698 and then Nkind
(Nam
) /= N_Explicit_Dereference
2700 Insert_Explicit_Dereference
(Nam
);
2702 (Warn_On_Dereference
, "?implicit dereference", N
);
2709 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
2712 Get_Next_Interp
(I
, It
);
2715 if Etype
(N
) = Any_Type
2716 and then not Try_Object_Operation
(N
)
2718 Error_Msg_NE
("undefined selector& for overloaded prefix", N
, Sel
);
2719 Set_Entity
(Sel
, Any_Id
);
2720 Set_Etype
(Sel
, Any_Type
);
2722 end Analyze_Overloaded_Selected_Component
;
2724 ----------------------------------
2725 -- Analyze_Qualified_Expression --
2726 ----------------------------------
2728 procedure Analyze_Qualified_Expression
(N
: Node_Id
) is
2729 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
2730 Expr
: constant Node_Id
:= Expression
(N
);
2736 Analyze_Expression
(Expr
);
2738 Set_Etype
(N
, Any_Type
);
2743 if T
= Any_Type
then
2747 Check_Fully_Declared
(T
, N
);
2749 -- If expected type is class-wide, check for exact match before
2750 -- expansion, because if the expression is a dispatching call it
2751 -- may be rewritten as explicit dereference with class-wide result.
2752 -- If expression is overloaded, retain only interpretations that
2753 -- will yield exact matches.
2755 if Is_Class_Wide_Type
(T
) then
2756 if not Is_Overloaded
(Expr
) then
2757 if Base_Type
(Etype
(Expr
)) /= Base_Type
(T
) then
2758 if Nkind
(Expr
) = N_Aggregate
then
2759 Error_Msg_N
("type of aggregate cannot be class-wide", Expr
);
2761 Wrong_Type
(Expr
, T
);
2766 Get_First_Interp
(Expr
, I
, It
);
2768 while Present
(It
.Nam
) loop
2769 if Base_Type
(It
.Typ
) /= Base_Type
(T
) then
2773 Get_Next_Interp
(I
, It
);
2779 end Analyze_Qualified_Expression
;
2785 procedure Analyze_Range
(N
: Node_Id
) is
2786 L
: constant Node_Id
:= Low_Bound
(N
);
2787 H
: constant Node_Id
:= High_Bound
(N
);
2788 I1
, I2
: Interp_Index
;
2791 procedure Check_Common_Type
(T1
, T2
: Entity_Id
);
2792 -- Verify the compatibility of two types, and choose the
2793 -- non universal one if the other is universal.
2795 procedure Check_High_Bound
(T
: Entity_Id
);
2796 -- Test one interpretation of the low bound against all those
2797 -- of the high bound.
2799 procedure Check_Universal_Expression
(N
: Node_Id
);
2800 -- In Ada83, reject bounds of a universal range that are not
2801 -- literals or entity names.
2803 -----------------------
2804 -- Check_Common_Type --
2805 -----------------------
2807 procedure Check_Common_Type
(T1
, T2
: Entity_Id
) is
2809 if Covers
(T1
=> T1
, T2
=> T2
)
2811 Covers
(T1
=> T2
, T2
=> T1
)
2813 if T1
= Universal_Integer
2814 or else T1
= Universal_Real
2815 or else T1
= Any_Character
2817 Add_One_Interp
(N
, Base_Type
(T2
), Base_Type
(T2
));
2820 Add_One_Interp
(N
, T1
, T1
);
2823 Add_One_Interp
(N
, Base_Type
(T1
), Base_Type
(T1
));
2826 end Check_Common_Type
;
2828 ----------------------
2829 -- Check_High_Bound --
2830 ----------------------
2832 procedure Check_High_Bound
(T
: Entity_Id
) is
2834 if not Is_Overloaded
(H
) then
2835 Check_Common_Type
(T
, Etype
(H
));
2837 Get_First_Interp
(H
, I2
, It2
);
2838 while Present
(It2
.Typ
) loop
2839 Check_Common_Type
(T
, It2
.Typ
);
2840 Get_Next_Interp
(I2
, It2
);
2843 end Check_High_Bound
;
2845 -----------------------------
2846 -- Is_Universal_Expression --
2847 -----------------------------
2849 procedure Check_Universal_Expression
(N
: Node_Id
) is
2851 if Etype
(N
) = Universal_Integer
2852 and then Nkind
(N
) /= N_Integer_Literal
2853 and then not Is_Entity_Name
(N
)
2854 and then Nkind
(N
) /= N_Attribute_Reference
2856 Error_Msg_N
("illegal bound in discrete range", N
);
2858 end Check_Universal_Expression
;
2860 -- Start of processing for Analyze_Range
2863 Set_Etype
(N
, Any_Type
);
2864 Analyze_Expression
(L
);
2865 Analyze_Expression
(H
);
2867 if Etype
(L
) = Any_Type
or else Etype
(H
) = Any_Type
then
2871 if not Is_Overloaded
(L
) then
2872 Check_High_Bound
(Etype
(L
));
2874 Get_First_Interp
(L
, I1
, It1
);
2875 while Present
(It1
.Typ
) loop
2876 Check_High_Bound
(It1
.Typ
);
2877 Get_Next_Interp
(I1
, It1
);
2881 -- If result is Any_Type, then we did not find a compatible pair
2883 if Etype
(N
) = Any_Type
then
2884 Error_Msg_N
("incompatible types in range ", N
);
2888 if Ada_Version
= Ada_83
2890 (Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
2891 or else Nkind
(Parent
(N
)) = N_Constrained_Array_Definition
)
2893 Check_Universal_Expression
(L
);
2894 Check_Universal_Expression
(H
);
2898 -----------------------
2899 -- Analyze_Reference --
2900 -----------------------
2902 procedure Analyze_Reference
(N
: Node_Id
) is
2903 P
: constant Node_Id
:= Prefix
(N
);
2906 Acc_Type
: Entity_Id
;
2911 -- An interesting error check, if we take the 'Reference of an object
2912 -- for which a pragma Atomic or Volatile has been given, and the type
2913 -- of the object is not Atomic or Volatile, then we are in trouble. The
2914 -- problem is that no trace of the atomic/volatile status will remain
2915 -- for the backend to respect when it deals with the resulting pointer,
2916 -- since the pointer type will not be marked atomic (it is a pointer to
2917 -- the base type of the object).
2919 -- It is not clear if that can ever occur, but in case it does, we will
2920 -- generate an error message. Not clear if this message can ever be
2921 -- generated, and pretty clear that it represents a bug if it is, still
2922 -- seems worth checking!
2926 if Is_Entity_Name
(P
)
2927 and then Is_Object_Reference
(P
)
2932 if (Has_Atomic_Components
(E
)
2933 and then not Has_Atomic_Components
(T
))
2935 (Has_Volatile_Components
(E
)
2936 and then not Has_Volatile_Components
(T
))
2937 or else (Is_Atomic
(E
) and then not Is_Atomic
(T
))
2938 or else (Is_Volatile
(E
) and then not Is_Volatile
(T
))
2940 Error_Msg_N
("cannot take reference to Atomic/Volatile object", N
);
2944 -- Carry on with normal processing
2946 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
2947 Set_Etype
(Acc_Type
, Acc_Type
);
2948 Set_Directly_Designated_Type
(Acc_Type
, Etype
(P
));
2949 Set_Etype
(N
, Acc_Type
);
2950 end Analyze_Reference
;
2952 --------------------------------
2953 -- Analyze_Selected_Component --
2954 --------------------------------
2956 -- Prefix is a record type or a task or protected type. In the
2957 -- later case, the selector must denote a visible entry.
2959 procedure Analyze_Selected_Component
(N
: Node_Id
) is
2960 Name
: constant Node_Id
:= Prefix
(N
);
2961 Sel
: constant Node_Id
:= Selector_Name
(N
);
2964 Has_Candidate
: Boolean := False;
2967 Pent
: Entity_Id
:= Empty
;
2968 Prefix_Type
: Entity_Id
;
2970 Type_To_Use
: Entity_Id
;
2971 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
2972 -- a class-wide type, we use its root type, whose components are
2973 -- present in the class-wide type.
2975 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean;
2976 -- It is known that the parent of N denotes a subprogram call. Comp
2977 -- is an overloadable component of the concurrent type of the prefix.
2978 -- Determine whether all formals of the parent of N and Comp are mode
2979 -- conformant. If the parent node is not analyzed yet it may be an
2980 -- indexed component rather than a function call.
2982 ------------------------------
2983 -- Has_Mode_Conformant_Spec --
2984 ------------------------------
2986 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean is
2987 Comp_Param
: Entity_Id
;
2989 Param_Typ
: Entity_Id
;
2992 Comp_Param
:= First_Formal
(Comp
);
2994 if Nkind
(Parent
(N
)) = N_Indexed_Component
then
2995 Param
:= First
(Expressions
(Parent
(N
)));
2997 Param
:= First
(Parameter_Associations
(Parent
(N
)));
3000 while Present
(Comp_Param
)
3001 and then Present
(Param
)
3003 Param_Typ
:= Find_Parameter_Type
(Param
);
3005 if Present
(Param_Typ
)
3007 not Conforming_Types
3008 (Etype
(Comp_Param
), Param_Typ
, Mode_Conformant
)
3013 Next_Formal
(Comp_Param
);
3017 -- One of the specs has additional formals
3019 if Present
(Comp_Param
) or else Present
(Param
) then
3024 end Has_Mode_Conformant_Spec
;
3026 -- Start of processing for Analyze_Selected_Component
3029 Set_Etype
(N
, Any_Type
);
3031 if Is_Overloaded
(Name
) then
3032 Analyze_Overloaded_Selected_Component
(N
);
3035 elsif Etype
(Name
) = Any_Type
then
3036 Set_Entity
(Sel
, Any_Id
);
3037 Set_Etype
(Sel
, Any_Type
);
3041 Prefix_Type
:= Etype
(Name
);
3044 if Is_Access_Type
(Prefix_Type
) then
3046 -- A RACW object can never be used as prefix of a selected
3047 -- component since that means it is dereferenced without
3048 -- being a controlling operand of a dispatching operation
3049 -- (RM E.2.2(16/1)). Before reporting an error, we must check
3050 -- whether this is actually a dispatching call in prefix form.
3052 if Is_Remote_Access_To_Class_Wide_Type
(Prefix_Type
)
3053 and then Comes_From_Source
(N
)
3055 if Try_Object_Operation
(N
) then
3059 ("invalid dereference of a remote access-to-class-wide value",
3063 -- Normal case of selected component applied to access type
3066 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
3068 if Is_Entity_Name
(Name
) then
3069 Pent
:= Entity
(Name
);
3070 elsif Nkind
(Name
) = N_Selected_Component
3071 and then Is_Entity_Name
(Selector_Name
(Name
))
3073 Pent
:= Entity
(Selector_Name
(Name
));
3076 Prefix_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, Name
);
3079 -- If we have an explicit dereference of a remote access-to-class-wide
3080 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
3081 -- have to check for the case of a prefix that is a controlling operand
3082 -- of a prefixed dispatching call, as the dereference is legal in that
3083 -- case. Normally this condition is checked in Validate_Remote_Access_
3084 -- To_Class_Wide_Type, but we have to defer the checking for selected
3085 -- component prefixes because of the prefixed dispatching call case.
3086 -- Note that implicit dereferences are checked for this just above.
3088 elsif Nkind
(Name
) = N_Explicit_Dereference
3089 and then Is_Remote_Access_To_Class_Wide_Type
(Etype
(Prefix
(Name
)))
3090 and then Comes_From_Source
(N
)
3092 if Try_Object_Operation
(N
) then
3096 ("invalid dereference of a remote access-to-class-wide value",
3101 -- (Ada 2005): if the prefix is the limited view of a type, and
3102 -- the context already includes the full view, use the full view
3103 -- in what follows, either to retrieve a component of to find
3104 -- a primitive operation. If the prefix is an explicit dereference,
3105 -- set the type of the prefix to reflect this transformation.
3106 -- If the non-limited view is itself an incomplete type, get the
3107 -- full view if available.
3109 if Is_Incomplete_Type
(Prefix_Type
)
3110 and then From_With_Type
(Prefix_Type
)
3111 and then Present
(Non_Limited_View
(Prefix_Type
))
3113 Prefix_Type
:= Get_Full_View
(Non_Limited_View
(Prefix_Type
));
3115 if Nkind
(N
) = N_Explicit_Dereference
then
3116 Set_Etype
(Prefix
(N
), Prefix_Type
);
3119 elsif Ekind
(Prefix_Type
) = E_Class_Wide_Type
3120 and then From_With_Type
(Prefix_Type
)
3121 and then Present
(Non_Limited_View
(Etype
(Prefix_Type
)))
3124 Class_Wide_Type
(Non_Limited_View
(Etype
(Prefix_Type
)));
3126 if Nkind
(N
) = N_Explicit_Dereference
then
3127 Set_Etype
(Prefix
(N
), Prefix_Type
);
3131 if Ekind
(Prefix_Type
) = E_Private_Subtype
then
3132 Prefix_Type
:= Base_Type
(Prefix_Type
);
3135 Type_To_Use
:= Prefix_Type
;
3137 -- For class-wide types, use the entity list of the root type. This
3138 -- indirection is specially important for private extensions because
3139 -- only the root type get switched (not the class-wide type).
3141 if Is_Class_Wide_Type
(Prefix_Type
) then
3142 Type_To_Use
:= Root_Type
(Prefix_Type
);
3145 Comp
:= First_Entity
(Type_To_Use
);
3147 -- If the selector has an original discriminant, the node appears in
3148 -- an instance. Replace the discriminant with the corresponding one
3149 -- in the current discriminated type. For nested generics, this must
3150 -- be done transitively, so note the new original discriminant.
3152 if Nkind
(Sel
) = N_Identifier
3153 and then Present
(Original_Discriminant
(Sel
))
3155 Comp
:= Find_Corresponding_Discriminant
(Sel
, Prefix_Type
);
3157 -- Mark entity before rewriting, for completeness and because
3158 -- subsequent semantic checks might examine the original node.
3160 Set_Entity
(Sel
, Comp
);
3161 Rewrite
(Selector_Name
(N
),
3162 New_Occurrence_Of
(Comp
, Sloc
(N
)));
3163 Set_Original_Discriminant
(Selector_Name
(N
), Comp
);
3164 Set_Etype
(N
, Etype
(Comp
));
3166 if Is_Access_Type
(Etype
(Name
)) then
3167 Insert_Explicit_Dereference
(Name
);
3168 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
3171 elsif Is_Record_Type
(Prefix_Type
) then
3173 -- Find component with given name
3175 while Present
(Comp
) loop
3176 if Chars
(Comp
) = Chars
(Sel
)
3177 and then Is_Visible_Component
(Comp
)
3179 Set_Entity_With_Style_Check
(Sel
, Comp
);
3180 Set_Etype
(Sel
, Etype
(Comp
));
3182 if Ekind
(Comp
) = E_Discriminant
then
3183 if Is_Unchecked_Union
(Base_Type
(Prefix_Type
)) then
3185 ("cannot reference discriminant of Unchecked_Union",
3189 if Is_Generic_Type
(Prefix_Type
)
3191 Is_Generic_Type
(Root_Type
(Prefix_Type
))
3193 Set_Original_Discriminant
(Sel
, Comp
);
3197 -- Resolve the prefix early otherwise it is not possible to
3198 -- build the actual subtype of the component: it may need
3199 -- to duplicate this prefix and duplication is only allowed
3200 -- on fully resolved expressions.
3204 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
3205 -- subtypes in a package specification.
3208 -- limited with Pkg;
3210 -- type Acc_Inc is access Pkg.T;
3212 -- N : Natural := X.all.Comp; -- ERROR, limited view
3213 -- end Pkg; -- Comp is not visible
3215 if Nkind
(Name
) = N_Explicit_Dereference
3216 and then From_With_Type
(Etype
(Prefix
(Name
)))
3217 and then not Is_Potentially_Use_Visible
(Etype
(Name
))
3218 and then Nkind
(Parent
(Cunit_Entity
(Current_Sem_Unit
))) =
3219 N_Package_Specification
3222 ("premature usage of incomplete}", Prefix
(Name
),
3223 Etype
(Prefix
(Name
)));
3226 -- We never need an actual subtype for the case of a selection
3227 -- for a indexed component of a non-packed array, since in
3228 -- this case gigi generates all the checks and can find the
3229 -- necessary bounds information.
3231 -- We also do not need an actual subtype for the case of
3232 -- a first, last, length, or range attribute applied to a
3233 -- non-packed array, since gigi can again get the bounds in
3234 -- these cases (gigi cannot handle the packed case, since it
3235 -- has the bounds of the packed array type, not the original
3236 -- bounds of the type). However, if the prefix is itself a
3237 -- selected component, as in a.b.c (i), gigi may regard a.b.c
3238 -- as a dynamic-sized temporary, so we do generate an actual
3239 -- subtype for this case.
3241 Parent_N
:= Parent
(N
);
3243 if not Is_Packed
(Etype
(Comp
))
3245 ((Nkind
(Parent_N
) = N_Indexed_Component
3246 and then Nkind
(Name
) /= N_Selected_Component
)
3248 (Nkind
(Parent_N
) = N_Attribute_Reference
3249 and then (Attribute_Name
(Parent_N
) = Name_First
3251 Attribute_Name
(Parent_N
) = Name_Last
3253 Attribute_Name
(Parent_N
) = Name_Length
3255 Attribute_Name
(Parent_N
) = Name_Range
)))
3257 Set_Etype
(N
, Etype
(Comp
));
3259 -- If full analysis is not enabled, we do not generate an
3260 -- actual subtype, because in the absence of expansion
3261 -- reference to a formal of a protected type, for example,
3262 -- will not be properly transformed, and will lead to
3263 -- out-of-scope references in gigi.
3265 -- In all other cases, we currently build an actual subtype.
3266 -- It seems likely that many of these cases can be avoided,
3267 -- but right now, the front end makes direct references to the
3268 -- bounds (e.g. in generating a length check), and if we do
3269 -- not make an actual subtype, we end up getting a direct
3270 -- reference to a discriminant, which will not do.
3272 elsif Full_Analysis
then
3274 Build_Actual_Subtype_Of_Component
(Etype
(Comp
), N
);
3275 Insert_Action
(N
, Act_Decl
);
3277 if No
(Act_Decl
) then
3278 Set_Etype
(N
, Etype
(Comp
));
3281 -- Component type depends on discriminants. Enter the
3282 -- main attributes of the subtype.
3285 Subt
: constant Entity_Id
:=
3286 Defining_Identifier
(Act_Decl
);
3289 Set_Etype
(Subt
, Base_Type
(Etype
(Comp
)));
3290 Set_Ekind
(Subt
, Ekind
(Etype
(Comp
)));
3291 Set_Etype
(N
, Subt
);
3295 -- If Full_Analysis not enabled, just set the Etype
3298 Set_Etype
(N
, Etype
(Comp
));
3304 -- If the prefix is a private extension, check only the visible
3305 -- components of the partial view. This must include the tag,
3306 -- which can appear in expanded code in a tag check.
3308 if Ekind
(Type_To_Use
) = E_Record_Type_With_Private
3309 and then Chars
(Selector_Name
(N
)) /= Name_uTag
3311 exit when Comp
= Last_Entity
(Type_To_Use
);
3317 -- Ada 2005 (AI-252): The selected component can be interpreted as
3318 -- a prefixed view of a subprogram. Depending on the context, this is
3319 -- either a name that can appear in a renaming declaration, or part
3320 -- of an enclosing call given in prefix form.
3322 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
3323 -- selected component should resolve to a name.
3325 if Ada_Version
>= Ada_05
3326 and then Is_Tagged_Type
(Prefix_Type
)
3327 and then not Is_Concurrent_Type
(Prefix_Type
)
3329 if Nkind
(Parent
(N
)) = N_Generic_Association
3330 or else Nkind
(Parent
(N
)) = N_Requeue_Statement
3331 or else Nkind
(Parent
(N
)) = N_Subprogram_Renaming_Declaration
3333 if Find_Primitive_Operation
(N
) then
3337 elsif Try_Object_Operation
(N
) then
3341 -- If the transformation fails, it will be necessary to redo the
3342 -- analysis with all errors enabled, to indicate candidate
3343 -- interpretations and reasons for each failure ???
3347 elsif Is_Private_Type
(Prefix_Type
) then
3349 -- Allow access only to discriminants of the type. If the type has
3350 -- no full view, gigi uses the parent type for the components, so we
3351 -- do the same here.
3353 if No
(Full_View
(Prefix_Type
)) then
3354 Type_To_Use
:= Root_Type
(Base_Type
(Prefix_Type
));
3355 Comp
:= First_Entity
(Type_To_Use
);
3358 while Present
(Comp
) loop
3359 if Chars
(Comp
) = Chars
(Sel
) then
3360 if Ekind
(Comp
) = E_Discriminant
then
3361 Set_Entity_With_Style_Check
(Sel
, Comp
);
3362 Generate_Reference
(Comp
, Sel
);
3364 Set_Etype
(Sel
, Etype
(Comp
));
3365 Set_Etype
(N
, Etype
(Comp
));
3367 if Is_Generic_Type
(Prefix_Type
)
3368 or else Is_Generic_Type
(Root_Type
(Prefix_Type
))
3370 Set_Original_Discriminant
(Sel
, Comp
);
3373 -- Before declaring an error, check whether this is tagged
3374 -- private type and a call to a primitive operation.
3376 elsif Ada_Version
>= Ada_05
3377 and then Is_Tagged_Type
(Prefix_Type
)
3378 and then Try_Object_Operation
(N
)
3384 ("invisible selector for }",
3385 N
, First_Subtype
(Prefix_Type
));
3386 Set_Entity
(Sel
, Any_Id
);
3387 Set_Etype
(N
, Any_Type
);
3396 elsif Is_Concurrent_Type
(Prefix_Type
) then
3398 -- Find visible operation with given name. For a protected type,
3399 -- the possible candidates are discriminants, entries or protected
3400 -- procedures. For a task type, the set can only include entries or
3401 -- discriminants if the task type is not an enclosing scope. If it
3402 -- is an enclosing scope (e.g. in an inner task) then all entities
3403 -- are visible, but the prefix must denote the enclosing scope, i.e.
3404 -- can only be a direct name or an expanded name.
3406 Set_Etype
(Sel
, Any_Type
);
3407 In_Scope
:= In_Open_Scopes
(Prefix_Type
);
3409 while Present
(Comp
) loop
3410 if Chars
(Comp
) = Chars
(Sel
) then
3411 if Is_Overloadable
(Comp
) then
3412 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
3414 -- If the prefix is tagged, the correct interpretation may
3415 -- lie in the primitive or class-wide operations of the
3416 -- type. Perform a simple conformance check to determine
3417 -- whether Try_Object_Operation should be invoked even if
3418 -- a visible entity is found.
3420 if Is_Tagged_Type
(Prefix_Type
)
3422 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
3424 N_Indexed_Component
)
3425 and then Has_Mode_Conformant_Spec
(Comp
)
3427 Has_Candidate
:= True;
3430 elsif Ekind
(Comp
) = E_Discriminant
3431 or else Ekind
(Comp
) = E_Entry_Family
3433 and then Is_Entity_Name
(Name
))
3435 Set_Entity_With_Style_Check
(Sel
, Comp
);
3436 Generate_Reference
(Comp
, Sel
);
3442 Set_Etype
(Sel
, Etype
(Comp
));
3443 Set_Etype
(N
, Etype
(Comp
));
3445 if Ekind
(Comp
) = E_Discriminant
then
3446 Set_Original_Discriminant
(Sel
, Comp
);
3449 -- For access type case, introduce explicit deference for more
3450 -- uniform treatment of entry calls.
3452 if Is_Access_Type
(Etype
(Name
)) then
3453 Insert_Explicit_Dereference
(Name
);
3455 (Warn_On_Dereference
, "?implicit dereference", N
);
3461 exit when not In_Scope
3463 Comp
= First_Private_Entity
(Base_Type
(Prefix_Type
));
3466 -- If there is no visible entity with the given name or none of the
3467 -- visible entities are plausible interpretations, check whether
3468 -- there is some other primitive operation with that name.
3470 if Ada_Version
>= Ada_05
3471 and then Is_Tagged_Type
(Prefix_Type
)
3473 if (Etype
(N
) = Any_Type
3474 or else not Has_Candidate
)
3475 and then Try_Object_Operation
(N
)
3479 -- If the context is not syntactically a procedure call, it
3480 -- may be a call to a primitive function declared outside of
3481 -- the synchronized type.
3483 -- If the context is a procedure call, there might still be
3484 -- an overloading between an entry and a primitive procedure
3485 -- declared outside of the synchronized type, called in prefix
3486 -- notation. This is harder to disambiguate because in one case
3487 -- the controlling formal is implicit ???
3489 elsif Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
3490 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
3491 and then Try_Object_Operation
(N
)
3497 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
3502 Error_Msg_NE
("invalid prefix in selected component&", N
, Sel
);
3505 -- If N still has no type, the component is not defined in the prefix
3507 if Etype
(N
) = Any_Type
then
3509 -- If the prefix is a single concurrent object, use its name in the
3510 -- error message, rather than that of its anonymous type.
3512 if Is_Concurrent_Type
(Prefix_Type
)
3513 and then Is_Internal_Name
(Chars
(Prefix_Type
))
3514 and then not Is_Derived_Type
(Prefix_Type
)
3515 and then Is_Entity_Name
(Name
)
3518 Error_Msg_Node_2
:= Entity
(Name
);
3519 Error_Msg_NE
("no selector& for&", N
, Sel
);
3521 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
3523 elsif Is_Generic_Type
(Prefix_Type
)
3524 and then Ekind
(Prefix_Type
) = E_Record_Type_With_Private
3525 and then Prefix_Type
/= Etype
(Prefix_Type
)
3526 and then Is_Record_Type
(Etype
(Prefix_Type
))
3528 -- If this is a derived formal type, the parent may have
3529 -- different visibility at this point. Try for an inherited
3530 -- component before reporting an error.
3532 Set_Etype
(Prefix
(N
), Etype
(Prefix_Type
));
3533 Analyze_Selected_Component
(N
);
3536 elsif Ekind
(Prefix_Type
) = E_Record_Subtype_With_Private
3537 and then Is_Generic_Actual_Type
(Prefix_Type
)
3538 and then Present
(Full_View
(Prefix_Type
))
3540 -- Similarly, if this the actual for a formal derived type, the
3541 -- component inherited from the generic parent may not be visible
3542 -- in the actual, but the selected component is legal.
3549 First_Component
(Generic_Parent_Type
(Parent
(Prefix_Type
)));
3550 while Present
(Comp
) loop
3551 if Chars
(Comp
) = Chars
(Sel
) then
3552 Set_Entity_With_Style_Check
(Sel
, Comp
);
3553 Set_Etype
(Sel
, Etype
(Comp
));
3554 Set_Etype
(N
, Etype
(Comp
));
3558 Next_Component
(Comp
);
3561 pragma Assert
(Etype
(N
) /= Any_Type
);
3565 if Ekind
(Prefix_Type
) = E_Record_Subtype
then
3567 -- Check whether this is a component of the base type
3568 -- which is absent from a statically constrained subtype.
3569 -- This will raise constraint error at run-time, but is
3570 -- not a compile-time error. When the selector is illegal
3571 -- for base type as well fall through and generate a
3572 -- compilation error anyway.
3574 Comp
:= First_Component
(Base_Type
(Prefix_Type
));
3575 while Present
(Comp
) loop
3576 if Chars
(Comp
) = Chars
(Sel
)
3577 and then Is_Visible_Component
(Comp
)
3579 Set_Entity_With_Style_Check
(Sel
, Comp
);
3580 Generate_Reference
(Comp
, Sel
);
3581 Set_Etype
(Sel
, Etype
(Comp
));
3582 Set_Etype
(N
, Etype
(Comp
));
3584 -- Emit appropriate message. Gigi will replace the
3585 -- node subsequently with the appropriate Raise.
3587 Apply_Compile_Time_Constraint_Error
3588 (N
, "component not present in }?",
3589 CE_Discriminant_Check_Failed
,
3590 Ent
=> Prefix_Type
, Rep
=> False);
3591 Set_Raises_Constraint_Error
(N
);
3595 Next_Component
(Comp
);
3600 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
3601 Error_Msg_NE
("no selector& for}", N
, Sel
);
3603 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
3606 Set_Entity
(Sel
, Any_Id
);
3607 Set_Etype
(Sel
, Any_Type
);
3609 end Analyze_Selected_Component
;
3611 ---------------------------
3612 -- Analyze_Short_Circuit --
3613 ---------------------------
3615 procedure Analyze_Short_Circuit
(N
: Node_Id
) is
3616 L
: constant Node_Id
:= Left_Opnd
(N
);
3617 R
: constant Node_Id
:= Right_Opnd
(N
);
3622 Analyze_Expression
(L
);
3623 Analyze_Expression
(R
);
3624 Set_Etype
(N
, Any_Type
);
3626 if not Is_Overloaded
(L
) then
3627 if Root_Type
(Etype
(L
)) = Standard_Boolean
3628 and then Has_Compatible_Type
(R
, Etype
(L
))
3630 Add_One_Interp
(N
, Etype
(L
), Etype
(L
));
3634 Get_First_Interp
(L
, Ind
, It
);
3635 while Present
(It
.Typ
) loop
3636 if Root_Type
(It
.Typ
) = Standard_Boolean
3637 and then Has_Compatible_Type
(R
, It
.Typ
)
3639 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
3642 Get_Next_Interp
(Ind
, It
);
3646 -- Here we have failed to find an interpretation. Clearly we know that
3647 -- it is not the case that both operands can have an interpretation of
3648 -- Boolean, but this is by far the most likely intended interpretation.
3649 -- So we simply resolve both operands as Booleans, and at least one of
3650 -- these resolutions will generate an error message, and we do not need
3651 -- to give another error message on the short circuit operation itself.
3653 if Etype
(N
) = Any_Type
then
3654 Resolve
(L
, Standard_Boolean
);
3655 Resolve
(R
, Standard_Boolean
);
3656 Set_Etype
(N
, Standard_Boolean
);
3658 end Analyze_Short_Circuit
;
3664 procedure Analyze_Slice
(N
: Node_Id
) is
3665 P
: constant Node_Id
:= Prefix
(N
);
3666 D
: constant Node_Id
:= Discrete_Range
(N
);
3667 Array_Type
: Entity_Id
;
3669 procedure Analyze_Overloaded_Slice
;
3670 -- If the prefix is overloaded, select those interpretations that
3671 -- yield a one-dimensional array type.
3673 ------------------------------
3674 -- Analyze_Overloaded_Slice --
3675 ------------------------------
3677 procedure Analyze_Overloaded_Slice
is
3683 Set_Etype
(N
, Any_Type
);
3685 Get_First_Interp
(P
, I
, It
);
3686 while Present
(It
.Nam
) loop
3689 if Is_Access_Type
(Typ
) then
3690 Typ
:= Designated_Type
(Typ
);
3691 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
3694 if Is_Array_Type
(Typ
)
3695 and then Number_Dimensions
(Typ
) = 1
3696 and then Has_Compatible_Type
(D
, Etype
(First_Index
(Typ
)))
3698 Add_One_Interp
(N
, Typ
, Typ
);
3701 Get_Next_Interp
(I
, It
);
3704 if Etype
(N
) = Any_Type
then
3705 Error_Msg_N
("expect array type in prefix of slice", N
);
3707 end Analyze_Overloaded_Slice
;
3709 -- Start of processing for Analyze_Slice
3715 if Is_Overloaded
(P
) then
3716 Analyze_Overloaded_Slice
;
3719 Array_Type
:= Etype
(P
);
3720 Set_Etype
(N
, Any_Type
);
3722 if Is_Access_Type
(Array_Type
) then
3723 Array_Type
:= Designated_Type
(Array_Type
);
3724 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
3727 if not Is_Array_Type
(Array_Type
) then
3728 Wrong_Type
(P
, Any_Array
);
3730 elsif Number_Dimensions
(Array_Type
) > 1 then
3732 ("type is not one-dimensional array in slice prefix", N
);
3735 Has_Compatible_Type
(D
, Etype
(First_Index
(Array_Type
)))
3737 Wrong_Type
(D
, Etype
(First_Index
(Array_Type
)));
3740 Set_Etype
(N
, Array_Type
);
3745 -----------------------------
3746 -- Analyze_Type_Conversion --
3747 -----------------------------
3749 procedure Analyze_Type_Conversion
(N
: Node_Id
) is
3750 Expr
: constant Node_Id
:= Expression
(N
);
3754 -- If Conversion_OK is set, then the Etype is already set, and the
3755 -- only processing required is to analyze the expression. This is
3756 -- used to construct certain "illegal" conversions which are not
3757 -- allowed by Ada semantics, but can be handled OK by Gigi, see
3758 -- Sinfo for further details.
3760 if Conversion_OK
(N
) then
3765 -- Otherwise full type analysis is required, as well as some semantic
3766 -- checks to make sure the argument of the conversion is appropriate.
3768 Find_Type
(Subtype_Mark
(N
));
3769 T
:= Entity
(Subtype_Mark
(N
));
3771 Check_Fully_Declared
(T
, N
);
3772 Analyze_Expression
(Expr
);
3773 Validate_Remote_Type_Type_Conversion
(N
);
3775 -- Only remaining step is validity checks on the argument. These
3776 -- are skipped if the conversion does not come from the source.
3778 if not Comes_From_Source
(N
) then
3781 -- If there was an error in a generic unit, no need to replicate the
3782 -- error message. Conversely, constant-folding in the generic may
3783 -- transform the argument of a conversion into a string literal, which
3784 -- is legal. Therefore the following tests are not performed in an
3787 elsif In_Instance
then
3790 elsif Nkind
(Expr
) = N_Null
then
3791 Error_Msg_N
("argument of conversion cannot be null", N
);
3792 Error_Msg_N
("\use qualified expression instead", N
);
3793 Set_Etype
(N
, Any_Type
);
3795 elsif Nkind
(Expr
) = N_Aggregate
then
3796 Error_Msg_N
("argument of conversion cannot be aggregate", N
);
3797 Error_Msg_N
("\use qualified expression instead", N
);
3799 elsif Nkind
(Expr
) = N_Allocator
then
3800 Error_Msg_N
("argument of conversion cannot be an allocator", N
);
3801 Error_Msg_N
("\use qualified expression instead", N
);
3803 elsif Nkind
(Expr
) = N_String_Literal
then
3804 Error_Msg_N
("argument of conversion cannot be string literal", N
);
3805 Error_Msg_N
("\use qualified expression instead", N
);
3807 elsif Nkind
(Expr
) = N_Character_Literal
then
3808 if Ada_Version
= Ada_83
then
3811 Error_Msg_N
("argument of conversion cannot be character literal",
3813 Error_Msg_N
("\use qualified expression instead", N
);
3816 elsif Nkind
(Expr
) = N_Attribute_Reference
3818 (Attribute_Name
(Expr
) = Name_Access
or else
3819 Attribute_Name
(Expr
) = Name_Unchecked_Access
or else
3820 Attribute_Name
(Expr
) = Name_Unrestricted_Access
)
3822 Error_Msg_N
("argument of conversion cannot be access", N
);
3823 Error_Msg_N
("\use qualified expression instead", N
);
3825 end Analyze_Type_Conversion
;
3827 ----------------------
3828 -- Analyze_Unary_Op --
3829 ----------------------
3831 procedure Analyze_Unary_Op
(N
: Node_Id
) is
3832 R
: constant Node_Id
:= Right_Opnd
(N
);
3833 Op_Id
: Entity_Id
:= Entity
(N
);
3836 Set_Etype
(N
, Any_Type
);
3837 Candidate_Type
:= Empty
;
3839 Analyze_Expression
(R
);
3841 if Present
(Op_Id
) then
3842 if Ekind
(Op_Id
) = E_Operator
then
3843 Find_Unary_Types
(R
, Op_Id
, N
);
3845 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3849 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
3850 while Present
(Op_Id
) loop
3851 if Ekind
(Op_Id
) = E_Operator
then
3852 if No
(Next_Entity
(First_Entity
(Op_Id
))) then
3853 Find_Unary_Types
(R
, Op_Id
, N
);
3856 elsif Is_Overloadable
(Op_Id
) then
3857 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
3860 Op_Id
:= Homonym
(Op_Id
);
3865 end Analyze_Unary_Op
;
3867 ----------------------------------
3868 -- Analyze_Unchecked_Expression --
3869 ----------------------------------
3871 procedure Analyze_Unchecked_Expression
(N
: Node_Id
) is
3873 Analyze
(Expression
(N
), Suppress
=> All_Checks
);
3874 Set_Etype
(N
, Etype
(Expression
(N
)));
3875 Save_Interps
(Expression
(N
), N
);
3876 end Analyze_Unchecked_Expression
;
3878 ---------------------------------------
3879 -- Analyze_Unchecked_Type_Conversion --
3880 ---------------------------------------
3882 procedure Analyze_Unchecked_Type_Conversion
(N
: Node_Id
) is
3884 Find_Type
(Subtype_Mark
(N
));
3885 Analyze_Expression
(Expression
(N
));
3886 Set_Etype
(N
, Entity
(Subtype_Mark
(N
)));
3887 end Analyze_Unchecked_Type_Conversion
;
3889 ------------------------------------
3890 -- Analyze_User_Defined_Binary_Op --
3891 ------------------------------------
3893 procedure Analyze_User_Defined_Binary_Op
3898 -- Only do analysis if the operator Comes_From_Source, since otherwise
3899 -- the operator was generated by the expander, and all such operators
3900 -- always refer to the operators in package Standard.
3902 if Comes_From_Source
(N
) then
3904 F1
: constant Entity_Id
:= First_Formal
(Op_Id
);
3905 F2
: constant Entity_Id
:= Next_Formal
(F1
);
3908 -- Verify that Op_Id is a visible binary function. Note that since
3909 -- we know Op_Id is overloaded, potentially use visible means use
3910 -- visible for sure (RM 9.4(11)).
3912 if Ekind
(Op_Id
) = E_Function
3913 and then Present
(F2
)
3914 and then (Is_Immediately_Visible
(Op_Id
)
3915 or else Is_Potentially_Use_Visible
(Op_Id
))
3916 and then Has_Compatible_Type
(Left_Opnd
(N
), Etype
(F1
))
3917 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F2
))
3919 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3921 -- If the left operand is overloaded, indicate that the
3922 -- current type is a viable candidate. This is redundant
3923 -- in most cases, but for equality and comparison operators
3924 -- where the context does not impose a type on the operands,
3925 -- setting the proper type is necessary to avoid subsequent
3926 -- ambiguities during resolution, when both user-defined and
3927 -- predefined operators may be candidates.
3929 if Is_Overloaded
(Left_Opnd
(N
)) then
3930 Set_Etype
(Left_Opnd
(N
), Etype
(F1
));
3933 if Debug_Flag_E
then
3934 Write_Str
("user defined operator ");
3935 Write_Name
(Chars
(Op_Id
));
3936 Write_Str
(" on node ");
3937 Write_Int
(Int
(N
));
3943 end Analyze_User_Defined_Binary_Op
;
3945 -----------------------------------
3946 -- Analyze_User_Defined_Unary_Op --
3947 -----------------------------------
3949 procedure Analyze_User_Defined_Unary_Op
3954 -- Only do analysis if the operator Comes_From_Source, since otherwise
3955 -- the operator was generated by the expander, and all such operators
3956 -- always refer to the operators in package Standard.
3958 if Comes_From_Source
(N
) then
3960 F
: constant Entity_Id
:= First_Formal
(Op_Id
);
3963 -- Verify that Op_Id is a visible unary function. Note that since
3964 -- we know Op_Id is overloaded, potentially use visible means use
3965 -- visible for sure (RM 9.4(11)).
3967 if Ekind
(Op_Id
) = E_Function
3968 and then No
(Next_Formal
(F
))
3969 and then (Is_Immediately_Visible
(Op_Id
)
3970 or else Is_Potentially_Use_Visible
(Op_Id
))
3971 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F
))
3973 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3977 end Analyze_User_Defined_Unary_Op
;
3979 ---------------------------
3980 -- Check_Arithmetic_Pair --
3981 ---------------------------
3983 procedure Check_Arithmetic_Pair
3984 (T1
, T2
: Entity_Id
;
3988 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
3990 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean;
3991 -- Check whether the fixed-point type Typ has a user-defined operator
3992 -- (multiplication or division) that should hide the corresponding
3993 -- predefined operator. Used to implement Ada 2005 AI-264, to make
3994 -- such operators more visible and therefore useful.
3996 -- If the name of the operation is an expanded name with prefix
3997 -- Standard, the predefined universal fixed operator is available,
3998 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
4000 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
;
4001 -- Get specific type (i.e. non-universal type if there is one)
4007 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean is
4008 Bas
: constant Entity_Id
:= Base_Type
(Typ
);
4014 -- If the universal_fixed operation is given explicitly the rule
4015 -- concerning primitive operations of the type do not apply.
4017 if Nkind
(N
) = N_Function_Call
4018 and then Nkind
(Name
(N
)) = N_Expanded_Name
4019 and then Entity
(Prefix
(Name
(N
))) = Standard_Standard
4024 -- The operation is treated as primitive if it is declared in the
4025 -- same scope as the type, and therefore on the same entity chain.
4027 Ent
:= Next_Entity
(Typ
);
4028 while Present
(Ent
) loop
4029 if Chars
(Ent
) = Chars
(Op
) then
4030 F1
:= First_Formal
(Ent
);
4031 F2
:= Next_Formal
(F1
);
4033 -- The operation counts as primitive if either operand or
4034 -- result are of the given base type, and both operands are
4035 -- fixed point types.
4037 if (Base_Type
(Etype
(F1
)) = Bas
4038 and then Is_Fixed_Point_Type
(Etype
(F2
)))
4041 (Base_Type
(Etype
(F2
)) = Bas
4042 and then Is_Fixed_Point_Type
(Etype
(F1
)))
4045 (Base_Type
(Etype
(Ent
)) = Bas
4046 and then Is_Fixed_Point_Type
(Etype
(F1
))
4047 and then Is_Fixed_Point_Type
(Etype
(F2
)))
4063 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
is
4065 if T1
= Universal_Integer
or else T1
= Universal_Real
then
4066 return Base_Type
(T2
);
4068 return Base_Type
(T1
);
4072 -- Start of processing for Check_Arithmetic_Pair
4075 if Op_Name
= Name_Op_Add
or else Op_Name
= Name_Op_Subtract
then
4077 if Is_Numeric_Type
(T1
)
4078 and then Is_Numeric_Type
(T2
)
4079 and then (Covers
(T1
=> T1
, T2
=> T2
)
4081 Covers
(T1
=> T2
, T2
=> T1
))
4083 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
4086 elsif Op_Name
= Name_Op_Multiply
or else Op_Name
= Name_Op_Divide
then
4088 if Is_Fixed_Point_Type
(T1
)
4089 and then (Is_Fixed_Point_Type
(T2
)
4090 or else T2
= Universal_Real
)
4092 -- If Treat_Fixed_As_Integer is set then the Etype is already set
4093 -- and no further processing is required (this is the case of an
4094 -- operator constructed by Exp_Fixd for a fixed point operation)
4095 -- Otherwise add one interpretation with universal fixed result
4096 -- If the operator is given in functional notation, it comes
4097 -- from source and Fixed_As_Integer cannot apply.
4099 if (Nkind
(N
) not in N_Op
4100 or else not Treat_Fixed_As_Integer
(N
))
4102 (not Has_Fixed_Op
(T1
, Op_Id
)
4103 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
4105 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
4108 elsif Is_Fixed_Point_Type
(T2
)
4109 and then (Nkind
(N
) not in N_Op
4110 or else not Treat_Fixed_As_Integer
(N
))
4111 and then T1
= Universal_Real
4113 (not Has_Fixed_Op
(T1
, Op_Id
)
4114 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
4116 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
4118 elsif Is_Numeric_Type
(T1
)
4119 and then Is_Numeric_Type
(T2
)
4120 and then (Covers
(T1
=> T1
, T2
=> T2
)
4122 Covers
(T1
=> T2
, T2
=> T1
))
4124 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
4126 elsif Is_Fixed_Point_Type
(T1
)
4127 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
4128 or else T2
= Universal_Integer
)
4130 Add_One_Interp
(N
, Op_Id
, T1
);
4132 elsif T2
= Universal_Real
4133 and then Base_Type
(T1
) = Base_Type
(Standard_Integer
)
4134 and then Op_Name
= Name_Op_Multiply
4136 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
4138 elsif T1
= Universal_Real
4139 and then Base_Type
(T2
) = Base_Type
(Standard_Integer
)
4141 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
4143 elsif Is_Fixed_Point_Type
(T2
)
4144 and then (Base_Type
(T1
) = Base_Type
(Standard_Integer
)
4145 or else T1
= Universal_Integer
)
4146 and then Op_Name
= Name_Op_Multiply
4148 Add_One_Interp
(N
, Op_Id
, T2
);
4150 elsif T1
= Universal_Real
and then T2
= Universal_Integer
then
4151 Add_One_Interp
(N
, Op_Id
, T1
);
4153 elsif T2
= Universal_Real
4154 and then T1
= Universal_Integer
4155 and then Op_Name
= Name_Op_Multiply
4157 Add_One_Interp
(N
, Op_Id
, T2
);
4160 elsif Op_Name
= Name_Op_Mod
or else Op_Name
= Name_Op_Rem
then
4162 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
4163 -- set does not require any special processing, since the Etype is
4164 -- already set (case of operation constructed by Exp_Fixed).
4166 if Is_Integer_Type
(T1
)
4167 and then (Covers
(T1
=> T1
, T2
=> T2
)
4169 Covers
(T1
=> T2
, T2
=> T1
))
4171 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
4174 elsif Op_Name
= Name_Op_Expon
then
4175 if Is_Numeric_Type
(T1
)
4176 and then not Is_Fixed_Point_Type
(T1
)
4177 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
4178 or else T2
= Universal_Integer
)
4180 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
4183 else pragma Assert
(Nkind
(N
) in N_Op_Shift
);
4185 -- If not one of the predefined operators, the node may be one
4186 -- of the intrinsic functions. Its kind is always specific, and
4187 -- we can use it directly, rather than the name of the operation.
4189 if Is_Integer_Type
(T1
)
4190 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
4191 or else T2
= Universal_Integer
)
4193 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
4196 end Check_Arithmetic_Pair
;
4198 -------------------------------
4199 -- Check_Misspelled_Selector --
4200 -------------------------------
4202 procedure Check_Misspelled_Selector
4203 (Prefix
: Entity_Id
;
4206 Max_Suggestions
: constant := 2;
4207 Nr_Of_Suggestions
: Natural := 0;
4209 Suggestion_1
: Entity_Id
:= Empty
;
4210 Suggestion_2
: Entity_Id
:= Empty
;
4215 -- All the components of the prefix of selector Sel are matched
4216 -- against Sel and a count is maintained of possible misspellings.
4217 -- When at the end of the analysis there are one or two (not more!)
4218 -- possible misspellings, these misspellings will be suggested as
4219 -- possible correction.
4221 if not (Is_Private_Type
(Prefix
) or else Is_Record_Type
(Prefix
)) then
4223 -- Concurrent types should be handled as well ???
4228 Comp
:= First_Entity
(Prefix
);
4229 while Nr_Of_Suggestions
<= Max_Suggestions
and then Present
(Comp
) loop
4230 if Is_Visible_Component
(Comp
) then
4231 if Is_Bad_Spelling_Of
(Chars
(Comp
), Chars
(Sel
)) then
4232 Nr_Of_Suggestions
:= Nr_Of_Suggestions
+ 1;
4234 case Nr_Of_Suggestions
is
4235 when 1 => Suggestion_1
:= Comp
;
4236 when 2 => Suggestion_2
:= Comp
;
4237 when others => exit;
4242 Comp
:= Next_Entity
(Comp
);
4245 -- Report at most two suggestions
4247 if Nr_Of_Suggestions
= 1 then
4248 Error_Msg_NE
-- CODEFIX
4249 ("\possible misspelling of&", Sel
, Suggestion_1
);
4251 elsif Nr_Of_Suggestions
= 2 then
4252 Error_Msg_Node_2
:= Suggestion_2
;
4253 Error_Msg_NE
-- CODEFIX
4254 ("\possible misspelling of& or&", Sel
, Suggestion_1
);
4256 end Check_Misspelled_Selector
;
4258 ----------------------
4259 -- Defined_In_Scope --
4260 ----------------------
4262 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean
4264 S1
: constant Entity_Id
:= Scope
(Base_Type
(T
));
4267 or else (S1
= System_Aux_Id
and then S
= Scope
(S1
));
4268 end Defined_In_Scope
;
4274 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
) is
4280 Void_Interp_Seen
: Boolean := False;
4283 pragma Warnings
(Off
, Boolean);
4286 if Ada_Version
>= Ada_05
then
4287 Actual
:= First_Actual
(N
);
4288 while Present
(Actual
) loop
4290 -- Ada 2005 (AI-50217): Post an error in case of premature
4291 -- usage of an entity from the limited view.
4293 if not Analyzed
(Etype
(Actual
))
4294 and then From_With_Type
(Etype
(Actual
))
4296 Error_Msg_Qual_Level
:= 1;
4298 ("missing with_clause for scope of imported type&",
4299 Actual
, Etype
(Actual
));
4300 Error_Msg_Qual_Level
:= 0;
4303 Next_Actual
(Actual
);
4307 -- Analyze each candidate call again, with full error reporting
4311 ("no candidate interpretations match the actuals:!", Nam
);
4312 Err_Mode
:= All_Errors_Mode
;
4313 All_Errors_Mode
:= True;
4315 -- If this is a call to an operation of a concurrent type,
4316 -- the failed interpretations have been removed from the
4317 -- name. Recover them to provide full diagnostics.
4319 if Nkind
(Parent
(Nam
)) = N_Selected_Component
then
4320 Set_Entity
(Nam
, Empty
);
4321 New_Nam
:= New_Copy_Tree
(Parent
(Nam
));
4322 Set_Is_Overloaded
(New_Nam
, False);
4323 Set_Is_Overloaded
(Selector_Name
(New_Nam
), False);
4324 Set_Parent
(New_Nam
, Parent
(Parent
(Nam
)));
4325 Analyze_Selected_Component
(New_Nam
);
4326 Get_First_Interp
(Selector_Name
(New_Nam
), X
, It
);
4328 Get_First_Interp
(Nam
, X
, It
);
4331 while Present
(It
.Nam
) loop
4332 if Etype
(It
.Nam
) = Standard_Void_Type
then
4333 Void_Interp_Seen
:= True;
4336 Analyze_One_Call
(N
, It
.Nam
, True, Success
);
4337 Get_Next_Interp
(X
, It
);
4340 if Nkind
(N
) = N_Function_Call
then
4341 Get_First_Interp
(Nam
, X
, It
);
4342 while Present
(It
.Nam
) loop
4343 if Ekind
(It
.Nam
) = E_Function
4344 or else Ekind
(It
.Nam
) = E_Operator
4348 Get_Next_Interp
(X
, It
);
4352 -- If all interpretations are procedures, this deserves a
4353 -- more precise message. Ditto if this appears as the prefix
4354 -- of a selected component, which may be a lexical error.
4357 ("\context requires function call, found procedure name", Nam
);
4359 if Nkind
(Parent
(N
)) = N_Selected_Component
4360 and then N
= Prefix
(Parent
(N
))
4362 Error_Msg_N
-- CODEFIX
4363 ("\period should probably be semicolon", Parent
(N
));
4366 elsif Nkind
(N
) = N_Procedure_Call_Statement
4367 and then not Void_Interp_Seen
4370 "\function name found in procedure call", Nam
);
4373 All_Errors_Mode
:= Err_Mode
;
4376 ---------------------------
4377 -- Find_Arithmetic_Types --
4378 ---------------------------
4380 procedure Find_Arithmetic_Types
4385 Index1
: Interp_Index
;
4386 Index2
: Interp_Index
;
4390 procedure Check_Right_Argument
(T
: Entity_Id
);
4391 -- Check right operand of operator
4393 --------------------------
4394 -- Check_Right_Argument --
4395 --------------------------
4397 procedure Check_Right_Argument
(T
: Entity_Id
) is
4399 if not Is_Overloaded
(R
) then
4400 Check_Arithmetic_Pair
(T
, Etype
(R
), Op_Id
, N
);
4402 Get_First_Interp
(R
, Index2
, It2
);
4403 while Present
(It2
.Typ
) loop
4404 Check_Arithmetic_Pair
(T
, It2
.Typ
, Op_Id
, N
);
4405 Get_Next_Interp
(Index2
, It2
);
4408 end Check_Right_Argument
;
4410 -- Start of processing for Find_Arithmetic_Types
4413 if not Is_Overloaded
(L
) then
4414 Check_Right_Argument
(Etype
(L
));
4417 Get_First_Interp
(L
, Index1
, It1
);
4418 while Present
(It1
.Typ
) loop
4419 Check_Right_Argument
(It1
.Typ
);
4420 Get_Next_Interp
(Index1
, It1
);
4424 end Find_Arithmetic_Types
;
4426 ------------------------
4427 -- Find_Boolean_Types --
4428 ------------------------
4430 procedure Find_Boolean_Types
4435 Index
: Interp_Index
;
4438 procedure Check_Numeric_Argument
(T
: Entity_Id
);
4439 -- Special case for logical operations one of whose operands is an
4440 -- integer literal. If both are literal the result is any modular type.
4442 ----------------------------
4443 -- Check_Numeric_Argument --
4444 ----------------------------
4446 procedure Check_Numeric_Argument
(T
: Entity_Id
) is
4448 if T
= Universal_Integer
then
4449 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
4451 elsif Is_Modular_Integer_Type
(T
) then
4452 Add_One_Interp
(N
, Op_Id
, T
);
4454 end Check_Numeric_Argument
;
4456 -- Start of processing for Find_Boolean_Types
4459 if not Is_Overloaded
(L
) then
4460 if Etype
(L
) = Universal_Integer
4461 or else Etype
(L
) = Any_Modular
4463 if not Is_Overloaded
(R
) then
4464 Check_Numeric_Argument
(Etype
(R
));
4467 Get_First_Interp
(R
, Index
, It
);
4468 while Present
(It
.Typ
) loop
4469 Check_Numeric_Argument
(It
.Typ
);
4470 Get_Next_Interp
(Index
, It
);
4474 -- If operands are aggregates, we must assume that they may be
4475 -- boolean arrays, and leave disambiguation for the second pass.
4476 -- If only one is an aggregate, verify that the other one has an
4477 -- interpretation as a boolean array
4479 elsif Nkind
(L
) = N_Aggregate
then
4480 if Nkind
(R
) = N_Aggregate
then
4481 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
4483 elsif not Is_Overloaded
(R
) then
4484 if Valid_Boolean_Arg
(Etype
(R
)) then
4485 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
4489 Get_First_Interp
(R
, Index
, It
);
4490 while Present
(It
.Typ
) loop
4491 if Valid_Boolean_Arg
(It
.Typ
) then
4492 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
4495 Get_Next_Interp
(Index
, It
);
4499 elsif Valid_Boolean_Arg
(Etype
(L
))
4500 and then Has_Compatible_Type
(R
, Etype
(L
))
4502 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
4506 Get_First_Interp
(L
, Index
, It
);
4507 while Present
(It
.Typ
) loop
4508 if Valid_Boolean_Arg
(It
.Typ
)
4509 and then Has_Compatible_Type
(R
, It
.Typ
)
4511 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
4514 Get_Next_Interp
(Index
, It
);
4517 end Find_Boolean_Types
;
4519 ---------------------------
4520 -- Find_Comparison_Types --
4521 ---------------------------
4523 procedure Find_Comparison_Types
4528 Index
: Interp_Index
;
4530 Found
: Boolean := False;
4533 Scop
: Entity_Id
:= Empty
;
4535 procedure Try_One_Interp
(T1
: Entity_Id
);
4536 -- Routine to try one proposed interpretation. Note that the context
4537 -- of the operator plays no role in resolving the arguments, so that
4538 -- if there is more than one interpretation of the operands that is
4539 -- compatible with comparison, the operation is ambiguous.
4541 --------------------
4542 -- Try_One_Interp --
4543 --------------------
4545 procedure Try_One_Interp
(T1
: Entity_Id
) is
4548 -- If the operator is an expanded name, then the type of the operand
4549 -- must be defined in the corresponding scope. If the type is
4550 -- universal, the context will impose the correct type.
4553 and then not Defined_In_Scope
(T1
, Scop
)
4554 and then T1
/= Universal_Integer
4555 and then T1
/= Universal_Real
4556 and then T1
/= Any_String
4557 and then T1
/= Any_Composite
4562 if Valid_Comparison_Arg
(T1
)
4563 and then Has_Compatible_Type
(R
, T1
)
4566 and then Base_Type
(T1
) /= Base_Type
(T_F
)
4568 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
4570 if It
= No_Interp
then
4571 Ambiguous_Operands
(N
);
4572 Set_Etype
(L
, Any_Type
);
4586 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
4591 -- Start of processing for Find_Comparison_Types
4594 -- If left operand is aggregate, the right operand has to
4595 -- provide a usable type for it.
4597 if Nkind
(L
) = N_Aggregate
4598 and then Nkind
(R
) /= N_Aggregate
4600 Find_Comparison_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
4604 if Nkind
(N
) = N_Function_Call
4605 and then Nkind
(Name
(N
)) = N_Expanded_Name
4607 Scop
:= Entity
(Prefix
(Name
(N
)));
4609 -- The prefix may be a package renaming, and the subsequent test
4610 -- requires the original package.
4612 if Ekind
(Scop
) = E_Package
4613 and then Present
(Renamed_Entity
(Scop
))
4615 Scop
:= Renamed_Entity
(Scop
);
4616 Set_Entity
(Prefix
(Name
(N
)), Scop
);
4620 if not Is_Overloaded
(L
) then
4621 Try_One_Interp
(Etype
(L
));
4624 Get_First_Interp
(L
, Index
, It
);
4625 while Present
(It
.Typ
) loop
4626 Try_One_Interp
(It
.Typ
);
4627 Get_Next_Interp
(Index
, It
);
4630 end Find_Comparison_Types
;
4632 ----------------------------------------
4633 -- Find_Non_Universal_Interpretations --
4634 ----------------------------------------
4636 procedure Find_Non_Universal_Interpretations
4642 Index
: Interp_Index
;
4646 if T1
= Universal_Integer
4647 or else T1
= Universal_Real
4649 if not Is_Overloaded
(R
) then
4651 (N
, Op_Id
, Standard_Boolean
, Base_Type
(Etype
(R
)));
4653 Get_First_Interp
(R
, Index
, It
);
4654 while Present
(It
.Typ
) loop
4655 if Covers
(It
.Typ
, T1
) then
4657 (N
, Op_Id
, Standard_Boolean
, Base_Type
(It
.Typ
));
4660 Get_Next_Interp
(Index
, It
);
4664 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(T1
));
4666 end Find_Non_Universal_Interpretations
;
4668 ------------------------------
4669 -- Find_Concatenation_Types --
4670 ------------------------------
4672 procedure Find_Concatenation_Types
4677 Op_Type
: constant Entity_Id
:= Etype
(Op_Id
);
4680 if Is_Array_Type
(Op_Type
)
4681 and then not Is_Limited_Type
(Op_Type
)
4683 and then (Has_Compatible_Type
(L
, Op_Type
)
4685 Has_Compatible_Type
(L
, Component_Type
(Op_Type
)))
4687 and then (Has_Compatible_Type
(R
, Op_Type
)
4689 Has_Compatible_Type
(R
, Component_Type
(Op_Type
)))
4691 Add_One_Interp
(N
, Op_Id
, Op_Type
);
4693 end Find_Concatenation_Types
;
4695 -------------------------
4696 -- Find_Equality_Types --
4697 -------------------------
4699 procedure Find_Equality_Types
4704 Index
: Interp_Index
;
4706 Found
: Boolean := False;
4709 Scop
: Entity_Id
:= Empty
;
4711 procedure Try_One_Interp
(T1
: Entity_Id
);
4712 -- The context of the equality operator plays no role in resolving the
4713 -- arguments, so that if there is more than one interpretation of the
4714 -- operands that is compatible with equality, the construct is ambiguous
4715 -- and an error can be emitted now, after trying to disambiguate, i.e.
4716 -- applying preference rules.
4718 --------------------
4719 -- Try_One_Interp --
4720 --------------------
4722 procedure Try_One_Interp
(T1
: Entity_Id
) is
4723 Bas
: constant Entity_Id
:= Base_Type
(T1
);
4726 -- If the operator is an expanded name, then the type of the operand
4727 -- must be defined in the corresponding scope. If the type is
4728 -- universal, the context will impose the correct type. An anonymous
4729 -- type for a 'Access reference is also universal in this sense, as
4730 -- the actual type is obtained from context.
4731 -- In Ada 2005, the equality operator for anonymous access types
4732 -- is declared in Standard, and preference rules apply to it.
4734 if Present
(Scop
) then
4735 if Defined_In_Scope
(T1
, Scop
)
4736 or else T1
= Universal_Integer
4737 or else T1
= Universal_Real
4738 or else T1
= Any_Access
4739 or else T1
= Any_String
4740 or else T1
= Any_Composite
4741 or else (Ekind
(T1
) = E_Access_Subprogram_Type
4742 and then not Comes_From_Source
(T1
))
4746 elsif Ekind
(T1
) = E_Anonymous_Access_Type
4747 and then Scop
= Standard_Standard
4752 -- The scope does not contain an operator for the type
4757 -- If we have infix notation, the operator must be usable.
4758 -- Within an instance, if the type is already established we
4759 -- know it is correct.
4760 -- In Ada 2005, the equality on anonymous access types is declared
4761 -- in Standard, and is always visible.
4763 elsif In_Open_Scopes
(Scope
(Bas
))
4764 or else Is_Potentially_Use_Visible
(Bas
)
4765 or else In_Use
(Bas
)
4766 or else (In_Use
(Scope
(Bas
))
4767 and then not Is_Hidden
(Bas
))
4768 or else (In_Instance
4769 and then First_Subtype
(T1
) = First_Subtype
(Etype
(R
)))
4770 or else Ekind
(T1
) = E_Anonymous_Access_Type
4775 -- Save candidate type for subsquent error message, if any
4777 if not Is_Limited_Type
(T1
) then
4778 Candidate_Type
:= T1
;
4784 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
4785 -- Do not allow anonymous access types in equality operators.
4787 if Ada_Version
< Ada_05
4788 and then Ekind
(T1
) = E_Anonymous_Access_Type
4793 if T1
/= Standard_Void_Type
4794 and then not Is_Limited_Type
(T1
)
4795 and then not Is_Limited_Composite
(T1
)
4796 and then Has_Compatible_Type
(R
, T1
)
4799 and then Base_Type
(T1
) /= Base_Type
(T_F
)
4801 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
4803 if It
= No_Interp
then
4804 Ambiguous_Operands
(N
);
4805 Set_Etype
(L
, Any_Type
);
4818 if not Analyzed
(L
) then
4822 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
4824 -- Case of operator was not visible, Etype still set to Any_Type
4826 if Etype
(N
) = Any_Type
then
4830 elsif Scop
= Standard_Standard
4831 and then Ekind
(T1
) = E_Anonymous_Access_Type
4837 -- Start of processing for Find_Equality_Types
4840 -- If left operand is aggregate, the right operand has to
4841 -- provide a usable type for it.
4843 if Nkind
(L
) = N_Aggregate
4844 and then Nkind
(R
) /= N_Aggregate
4846 Find_Equality_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
4850 if Nkind
(N
) = N_Function_Call
4851 and then Nkind
(Name
(N
)) = N_Expanded_Name
4853 Scop
:= Entity
(Prefix
(Name
(N
)));
4855 -- The prefix may be a package renaming, and the subsequent test
4856 -- requires the original package.
4858 if Ekind
(Scop
) = E_Package
4859 and then Present
(Renamed_Entity
(Scop
))
4861 Scop
:= Renamed_Entity
(Scop
);
4862 Set_Entity
(Prefix
(Name
(N
)), Scop
);
4866 if not Is_Overloaded
(L
) then
4867 Try_One_Interp
(Etype
(L
));
4870 Get_First_Interp
(L
, Index
, It
);
4871 while Present
(It
.Typ
) loop
4872 Try_One_Interp
(It
.Typ
);
4873 Get_Next_Interp
(Index
, It
);
4876 end Find_Equality_Types
;
4878 -------------------------
4879 -- Find_Negation_Types --
4880 -------------------------
4882 procedure Find_Negation_Types
4887 Index
: Interp_Index
;
4891 if not Is_Overloaded
(R
) then
4892 if Etype
(R
) = Universal_Integer
then
4893 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
4894 elsif Valid_Boolean_Arg
(Etype
(R
)) then
4895 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
4899 Get_First_Interp
(R
, Index
, It
);
4900 while Present
(It
.Typ
) loop
4901 if Valid_Boolean_Arg
(It
.Typ
) then
4902 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
4905 Get_Next_Interp
(Index
, It
);
4908 end Find_Negation_Types
;
4910 ------------------------------
4911 -- Find_Primitive_Operation --
4912 ------------------------------
4914 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean is
4915 Obj
: constant Node_Id
:= Prefix
(N
);
4916 Op
: constant Node_Id
:= Selector_Name
(N
);
4923 Set_Etype
(Op
, Any_Type
);
4925 if Is_Access_Type
(Etype
(Obj
)) then
4926 Typ
:= Designated_Type
(Etype
(Obj
));
4931 if Is_Class_Wide_Type
(Typ
) then
4932 Typ
:= Root_Type
(Typ
);
4935 Prims
:= Primitive_Operations
(Typ
);
4937 Prim
:= First_Elmt
(Prims
);
4938 while Present
(Prim
) loop
4939 if Chars
(Node
(Prim
)) = Chars
(Op
) then
4940 Add_One_Interp
(Op
, Node
(Prim
), Etype
(Node
(Prim
)));
4941 Set_Etype
(N
, Etype
(Node
(Prim
)));
4947 -- Now look for class-wide operations of the type or any of its
4948 -- ancestors by iterating over the homonyms of the selector.
4951 Cls_Type
: constant Entity_Id
:= Class_Wide_Type
(Typ
);
4955 Hom
:= Current_Entity
(Op
);
4956 while Present
(Hom
) loop
4957 if (Ekind
(Hom
) = E_Procedure
4959 Ekind
(Hom
) = E_Function
)
4960 and then Scope
(Hom
) = Scope
(Typ
)
4961 and then Present
(First_Formal
(Hom
))
4963 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
4965 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
4967 Ekind
(Etype
(First_Formal
(Hom
))) =
4968 E_Anonymous_Access_Type
4971 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
4974 Add_One_Interp
(Op
, Hom
, Etype
(Hom
));
4975 Set_Etype
(N
, Etype
(Hom
));
4978 Hom
:= Homonym
(Hom
);
4982 return Etype
(Op
) /= Any_Type
;
4983 end Find_Primitive_Operation
;
4985 ----------------------
4986 -- Find_Unary_Types --
4987 ----------------------
4989 procedure Find_Unary_Types
4994 Index
: Interp_Index
;
4998 if not Is_Overloaded
(R
) then
4999 if Is_Numeric_Type
(Etype
(R
)) then
5000 Add_One_Interp
(N
, Op_Id
, Base_Type
(Etype
(R
)));
5004 Get_First_Interp
(R
, Index
, It
);
5005 while Present
(It
.Typ
) loop
5006 if Is_Numeric_Type
(It
.Typ
) then
5007 Add_One_Interp
(N
, Op_Id
, Base_Type
(It
.Typ
));
5010 Get_Next_Interp
(Index
, It
);
5013 end Find_Unary_Types
;
5019 function Junk_Operand
(N
: Node_Id
) return Boolean is
5023 if Error_Posted
(N
) then
5027 -- Get entity to be tested
5029 if Is_Entity_Name
(N
)
5030 and then Present
(Entity
(N
))
5034 -- An odd case, a procedure name gets converted to a very peculiar
5035 -- function call, and here is where we detect this happening.
5037 elsif Nkind
(N
) = N_Function_Call
5038 and then Is_Entity_Name
(Name
(N
))
5039 and then Present
(Entity
(Name
(N
)))
5043 -- Another odd case, there are at least some cases of selected
5044 -- components where the selected component is not marked as having
5045 -- an entity, even though the selector does have an entity
5047 elsif Nkind
(N
) = N_Selected_Component
5048 and then Present
(Entity
(Selector_Name
(N
)))
5050 Enode
:= Selector_Name
(N
);
5056 -- Now test the entity we got to see if it is a bad case
5058 case Ekind
(Entity
(Enode
)) is
5062 ("package name cannot be used as operand", Enode
);
5064 when Generic_Unit_Kind
=>
5066 ("generic unit name cannot be used as operand", Enode
);
5070 ("subtype name cannot be used as operand", Enode
);
5074 ("entry name cannot be used as operand", Enode
);
5078 ("procedure name cannot be used as operand", Enode
);
5082 ("exception name cannot be used as operand", Enode
);
5084 when E_Block | E_Label | E_Loop
=>
5086 ("label name cannot be used as operand", Enode
);
5096 --------------------
5097 -- Operator_Check --
5098 --------------------
5100 procedure Operator_Check
(N
: Node_Id
) is
5102 Remove_Abstract_Operations
(N
);
5104 -- Test for case of no interpretation found for operator
5106 if Etype
(N
) = Any_Type
then
5110 Op_Id
: Entity_Id
:= Empty
;
5113 R
:= Right_Opnd
(N
);
5115 if Nkind
(N
) in N_Binary_Op
then
5121 -- If either operand has no type, then don't complain further,
5122 -- since this simply means that we have a propagated error.
5125 or else Etype
(R
) = Any_Type
5126 or else (Nkind
(N
) in N_Binary_Op
and then Etype
(L
) = Any_Type
)
5130 -- We explicitly check for the case of concatenation of component
5131 -- with component to avoid reporting spurious matching array types
5132 -- that might happen to be lurking in distant packages (such as
5133 -- run-time packages). This also prevents inconsistencies in the
5134 -- messages for certain ACVC B tests, which can vary depending on
5135 -- types declared in run-time interfaces. Another improvement when
5136 -- aggregates are present is to look for a well-typed operand.
5138 elsif Present
(Candidate_Type
)
5139 and then (Nkind
(N
) /= N_Op_Concat
5140 or else Is_Array_Type
(Etype
(L
))
5141 or else Is_Array_Type
(Etype
(R
)))
5144 if Nkind
(N
) = N_Op_Concat
then
5145 if Etype
(L
) /= Any_Composite
5146 and then Is_Array_Type
(Etype
(L
))
5148 Candidate_Type
:= Etype
(L
);
5150 elsif Etype
(R
) /= Any_Composite
5151 and then Is_Array_Type
(Etype
(R
))
5153 Candidate_Type
:= Etype
(R
);
5158 ("operator for} is not directly visible!",
5159 N
, First_Subtype
(Candidate_Type
));
5160 Error_Msg_N
("use clause would make operation legal!", N
);
5163 -- If either operand is a junk operand (e.g. package name), then
5164 -- post appropriate error messages, but do not complain further.
5166 -- Note that the use of OR in this test instead of OR ELSE is
5167 -- quite deliberate, we may as well check both operands in the
5168 -- binary operator case.
5170 elsif Junk_Operand
(R
)
5171 or (Nkind
(N
) in N_Binary_Op
and then Junk_Operand
(L
))
5175 -- If we have a logical operator, one of whose operands is
5176 -- Boolean, then we know that the other operand cannot resolve to
5177 -- Boolean (since we got no interpretations), but in that case we
5178 -- pretty much know that the other operand should be Boolean, so
5179 -- resolve it that way (generating an error)
5181 elsif Nkind_In
(N
, N_Op_And
, N_Op_Or
, N_Op_Xor
) then
5182 if Etype
(L
) = Standard_Boolean
then
5183 Resolve
(R
, Standard_Boolean
);
5185 elsif Etype
(R
) = Standard_Boolean
then
5186 Resolve
(L
, Standard_Boolean
);
5190 -- For an arithmetic operator or comparison operator, if one
5191 -- of the operands is numeric, then we know the other operand
5192 -- is not the same numeric type. If it is a non-numeric type,
5193 -- then probably it is intended to match the other operand.
5195 elsif Nkind_In
(N
, N_Op_Add
,
5201 Nkind_In
(N
, N_Op_Lt
,
5207 if Is_Numeric_Type
(Etype
(L
))
5208 and then not Is_Numeric_Type
(Etype
(R
))
5210 Resolve
(R
, Etype
(L
));
5213 elsif Is_Numeric_Type
(Etype
(R
))
5214 and then not Is_Numeric_Type
(Etype
(L
))
5216 Resolve
(L
, Etype
(R
));
5220 -- Comparisons on A'Access are common enough to deserve a
5223 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
)
5224 and then Ekind
(Etype
(L
)) = E_Access_Attribute_Type
5225 and then Ekind
(Etype
(R
)) = E_Access_Attribute_Type
5228 ("two access attributes cannot be compared directly", N
);
5230 ("\use qualified expression for one of the operands",
5234 -- Another one for C programmers
5236 elsif Nkind
(N
) = N_Op_Concat
5237 and then Valid_Boolean_Arg
(Etype
(L
))
5238 and then Valid_Boolean_Arg
(Etype
(R
))
5240 Error_Msg_N
("invalid operands for concatenation", N
);
5241 Error_Msg_N
-- CODEFIX
5242 ("\maybe AND was meant", N
);
5245 -- A special case for comparison of access parameter with null
5247 elsif Nkind
(N
) = N_Op_Eq
5248 and then Is_Entity_Name
(L
)
5249 and then Nkind
(Parent
(Entity
(L
))) = N_Parameter_Specification
5250 and then Nkind
(Parameter_Type
(Parent
(Entity
(L
)))) =
5252 and then Nkind
(R
) = N_Null
5254 Error_Msg_N
("access parameter is not allowed to be null", L
);
5255 Error_Msg_N
("\(call would raise Constraint_Error)", L
);
5258 -- Another special case for exponentiation, where the right
5259 -- operand must be Natural, independently of the base.
5261 elsif Nkind
(N
) = N_Op_Expon
5262 and then Is_Numeric_Type
(Etype
(L
))
5263 and then not Is_Overloaded
(R
)
5265 First_Subtype
(Base_Type
(Etype
(R
))) /= Standard_Integer
5266 and then Base_Type
(Etype
(R
)) /= Universal_Integer
5269 ("exponent must be of type Natural, found}", R
, Etype
(R
));
5273 -- If we fall through then just give general message. Note that in
5274 -- the following messages, if the operand is overloaded we choose
5275 -- an arbitrary type to complain about, but that is probably more
5276 -- useful than not giving a type at all.
5278 if Nkind
(N
) in N_Unary_Op
then
5279 Error_Msg_Node_2
:= Etype
(R
);
5280 Error_Msg_N
("operator& not defined for}", N
);
5284 if Nkind
(N
) in N_Binary_Op
then
5285 if not Is_Overloaded
(L
)
5286 and then not Is_Overloaded
(R
)
5287 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
5289 Error_Msg_Node_2
:= First_Subtype
(Etype
(R
));
5290 Error_Msg_N
("there is no applicable operator& for}", N
);
5293 -- Another attempt to find a fix: one of the candidate
5294 -- interpretations may not be use-visible. This has
5295 -- already been checked for predefined operators, so
5296 -- we examine only user-defined functions.
5298 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
5300 while Present
(Op_Id
) loop
5301 if Ekind
(Op_Id
) /= E_Operator
5302 and then Is_Overloadable
(Op_Id
)
5304 if not Is_Immediately_Visible
(Op_Id
)
5305 and then not In_Use
(Scope
(Op_Id
))
5306 and then not Is_Abstract_Subprogram
(Op_Id
)
5307 and then not Is_Hidden
(Op_Id
)
5308 and then Ekind
(Scope
(Op_Id
)) = E_Package
5311 (L
, Etype
(First_Formal
(Op_Id
)))
5313 (Next_Formal
(First_Formal
(Op_Id
)))
5317 Etype
(Next_Formal
(First_Formal
(Op_Id
))))
5320 ("No legal interpretation for operator&", N
);
5322 ("\use clause on& would make operation legal",
5328 Op_Id
:= Homonym
(Op_Id
);
5332 Error_Msg_N
("invalid operand types for operator&", N
);
5334 if Nkind
(N
) /= N_Op_Concat
then
5335 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
5336 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
5346 -----------------------------------------
5347 -- Process_Implicit_Dereference_Prefix --
5348 -----------------------------------------
5350 function Process_Implicit_Dereference_Prefix
5352 P
: Entity_Id
) return Entity_Id
5355 Typ
: constant Entity_Id
:= Designated_Type
(Etype
(P
));
5359 and then (Operating_Mode
= Check_Semantics
or else not Expander_Active
)
5361 -- We create a dummy reference to E to ensure that the reference
5362 -- is not considered as part of an assignment (an implicit
5363 -- dereference can never assign to its prefix). The Comes_From_Source
5364 -- attribute needs to be propagated for accurate warnings.
5366 Ref
:= New_Reference_To
(E
, Sloc
(P
));
5367 Set_Comes_From_Source
(Ref
, Comes_From_Source
(P
));
5368 Generate_Reference
(E
, Ref
);
5371 -- An implicit dereference is a legal occurrence of an
5372 -- incomplete type imported through a limited_with clause,
5373 -- if the full view is visible.
5375 if From_With_Type
(Typ
)
5376 and then not From_With_Type
(Scope
(Typ
))
5378 (Is_Immediately_Visible
(Scope
(Typ
))
5380 (Is_Child_Unit
(Scope
(Typ
))
5381 and then Is_Visible_Child_Unit
(Scope
(Typ
))))
5383 return Available_View
(Typ
);
5388 end Process_Implicit_Dereference_Prefix
;
5390 --------------------------------
5391 -- Remove_Abstract_Operations --
5392 --------------------------------
5394 procedure Remove_Abstract_Operations
(N
: Node_Id
) is
5395 Abstract_Op
: Entity_Id
:= Empty
;
5396 Address_Kludge
: Boolean := False;
5400 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
5401 -- activate this if either extensions are enabled, or if the abstract
5402 -- operation in question comes from a predefined file. This latter test
5403 -- allows us to use abstract to make operations invisible to users. In
5404 -- particular, if type Address is non-private and abstract subprograms
5405 -- are used to hide its operators, they will be truly hidden.
5407 type Operand_Position
is (First_Op
, Second_Op
);
5408 Univ_Type
: constant Entity_Id
:= Universal_Interpretation
(N
);
5410 procedure Remove_Address_Interpretations
(Op
: Operand_Position
);
5411 -- Ambiguities may arise when the operands are literal and the address
5412 -- operations in s-auxdec are visible. In that case, remove the
5413 -- interpretation of a literal as Address, to retain the semantics of
5414 -- Address as a private type.
5416 ------------------------------------
5417 -- Remove_Address_Interpretations --
5418 ------------------------------------
5420 procedure Remove_Address_Interpretations
(Op
: Operand_Position
) is
5424 if Is_Overloaded
(N
) then
5425 Get_First_Interp
(N
, I
, It
);
5426 while Present
(It
.Nam
) loop
5427 Formal
:= First_Entity
(It
.Nam
);
5429 if Op
= Second_Op
then
5430 Formal
:= Next_Entity
(Formal
);
5433 if Is_Descendent_Of_Address
(Etype
(Formal
)) then
5434 Address_Kludge
:= True;
5438 Get_Next_Interp
(I
, It
);
5441 end Remove_Address_Interpretations
;
5443 -- Start of processing for Remove_Abstract_Operations
5446 if Is_Overloaded
(N
) then
5447 Get_First_Interp
(N
, I
, It
);
5449 while Present
(It
.Nam
) loop
5450 if Is_Overloadable
(It
.Nam
)
5451 and then Is_Abstract_Subprogram
(It
.Nam
)
5452 and then not Is_Dispatching_Operation
(It
.Nam
)
5454 Abstract_Op
:= It
.Nam
;
5456 if Is_Descendent_Of_Address
(It
.Typ
) then
5457 Address_Kludge
:= True;
5461 -- In Ada 2005, this operation does not participate in Overload
5462 -- resolution. If the operation is defined in a predefined
5463 -- unit, it is one of the operations declared abstract in some
5464 -- variants of System, and it must be removed as well.
5466 elsif Ada_Version
>= Ada_05
5467 or else Is_Predefined_File_Name
5468 (Unit_File_Name
(Get_Source_Unit
(It
.Nam
)))
5475 Get_Next_Interp
(I
, It
);
5478 if No
(Abstract_Op
) then
5480 -- If some interpretation yields an integer type, it is still
5481 -- possible that there are address interpretations. Remove them
5482 -- if one operand is a literal, to avoid spurious ambiguities
5483 -- on systems where Address is a visible integer type.
5485 if Is_Overloaded
(N
)
5486 and then Nkind
(N
) in N_Op
5487 and then Is_Integer_Type
(Etype
(N
))
5489 if Nkind
(N
) in N_Binary_Op
then
5490 if Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
5491 Remove_Address_Interpretations
(Second_Op
);
5493 elsif Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
5494 Remove_Address_Interpretations
(First_Op
);
5499 elsif Nkind
(N
) in N_Op
then
5501 -- Remove interpretations that treat literals as addresses. This
5502 -- is never appropriate, even when Address is defined as a visible
5503 -- Integer type. The reason is that we would really prefer Address
5504 -- to behave as a private type, even in this case, which is there
5505 -- only to accommodate oddities of VMS address sizes. If Address
5506 -- is a visible integer type, we get lots of overload ambiguities.
5508 if Nkind
(N
) in N_Binary_Op
then
5510 U1
: constant Boolean :=
5511 Present
(Universal_Interpretation
(Right_Opnd
(N
)));
5512 U2
: constant Boolean :=
5513 Present
(Universal_Interpretation
(Left_Opnd
(N
)));
5517 Remove_Address_Interpretations
(Second_Op
);
5521 Remove_Address_Interpretations
(First_Op
);
5524 if not (U1
and U2
) then
5526 -- Remove corresponding predefined operator, which is
5527 -- always added to the overload set.
5529 Get_First_Interp
(N
, I
, It
);
5530 while Present
(It
.Nam
) loop
5531 if Scope
(It
.Nam
) = Standard_Standard
5532 and then Base_Type
(It
.Typ
) =
5533 Base_Type
(Etype
(Abstract_Op
))
5538 Get_Next_Interp
(I
, It
);
5541 elsif Is_Overloaded
(N
)
5542 and then Present
(Univ_Type
)
5544 -- If both operands have a universal interpretation,
5545 -- it is still necessary to remove interpretations that
5546 -- yield Address. Any remaining ambiguities will be
5547 -- removed in Disambiguate.
5549 Get_First_Interp
(N
, I
, It
);
5550 while Present
(It
.Nam
) loop
5551 if Is_Descendent_Of_Address
(It
.Typ
) then
5554 elsif not Is_Type
(It
.Nam
) then
5555 Set_Entity
(N
, It
.Nam
);
5558 Get_Next_Interp
(I
, It
);
5564 elsif Nkind
(N
) = N_Function_Call
5566 (Nkind
(Name
(N
)) = N_Operator_Symbol
5568 (Nkind
(Name
(N
)) = N_Expanded_Name
5570 Nkind
(Selector_Name
(Name
(N
))) = N_Operator_Symbol
))
5574 Arg1
: constant Node_Id
:= First
(Parameter_Associations
(N
));
5575 U1
: constant Boolean :=
5576 Present
(Universal_Interpretation
(Arg1
));
5577 U2
: constant Boolean :=
5578 Present
(Next
(Arg1
)) and then
5579 Present
(Universal_Interpretation
(Next
(Arg1
)));
5583 Remove_Address_Interpretations
(First_Op
);
5587 Remove_Address_Interpretations
(Second_Op
);
5590 if not (U1
and U2
) then
5591 Get_First_Interp
(N
, I
, It
);
5592 while Present
(It
.Nam
) loop
5593 if Scope
(It
.Nam
) = Standard_Standard
5594 and then It
.Typ
= Base_Type
(Etype
(Abstract_Op
))
5599 Get_Next_Interp
(I
, It
);
5605 -- If the removal has left no valid interpretations, emit an error
5606 -- message now and label node as illegal.
5608 if Present
(Abstract_Op
) then
5609 Get_First_Interp
(N
, I
, It
);
5613 -- Removal of abstract operation left no viable candidate
5615 Set_Etype
(N
, Any_Type
);
5616 Error_Msg_Sloc
:= Sloc
(Abstract_Op
);
5618 ("cannot call abstract operation& declared#", N
, Abstract_Op
);
5620 -- In Ada 2005, an abstract operation may disable predefined
5621 -- operators. Since the context is not yet known, we mark the
5622 -- predefined operators as potentially hidden. Do not include
5623 -- predefined operators when addresses are involved since this
5624 -- case is handled separately.
5626 elsif Ada_Version
>= Ada_05
5627 and then not Address_Kludge
5629 while Present
(It
.Nam
) loop
5630 if Is_Numeric_Type
(It
.Typ
)
5631 and then Scope
(It
.Typ
) = Standard_Standard
5633 Set_Abstract_Op
(I
, Abstract_Op
);
5636 Get_Next_Interp
(I
, It
);
5641 end Remove_Abstract_Operations
;
5643 -----------------------
5644 -- Try_Indirect_Call --
5645 -----------------------
5647 function Try_Indirect_Call
5650 Typ
: Entity_Id
) return Boolean
5656 pragma Warnings
(Off
, Call_OK
);
5659 Normalize_Actuals
(N
, Designated_Type
(Typ
), False, Call_OK
);
5661 Actual
:= First_Actual
(N
);
5662 Formal
:= First_Formal
(Designated_Type
(Typ
));
5663 while Present
(Actual
) and then Present
(Formal
) loop
5664 if not Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
5669 Next_Formal
(Formal
);
5672 if No
(Actual
) and then No
(Formal
) then
5673 Add_One_Interp
(N
, Nam
, Etype
(Designated_Type
(Typ
)));
5675 -- Nam is a candidate interpretation for the name in the call,
5676 -- if it is not an indirect call.
5678 if not Is_Type
(Nam
)
5679 and then Is_Entity_Name
(Name
(N
))
5681 Set_Entity
(Name
(N
), Nam
);
5688 end Try_Indirect_Call
;
5690 ----------------------
5691 -- Try_Indexed_Call --
5692 ----------------------
5694 function Try_Indexed_Call
5698 Skip_First
: Boolean) return Boolean
5700 Loc
: constant Source_Ptr
:= Sloc
(N
);
5701 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
5706 Actual
:= First
(Actuals
);
5708 -- If the call was originally written in prefix form, skip the first
5709 -- actual, which is obviously not defaulted.
5715 Index
:= First_Index
(Typ
);
5716 while Present
(Actual
) and then Present
(Index
) loop
5718 -- If the parameter list has a named association, the expression
5719 -- is definitely a call and not an indexed component.
5721 if Nkind
(Actual
) = N_Parameter_Association
then
5725 if Is_Entity_Name
(Actual
)
5726 and then Is_Type
(Entity
(Actual
))
5727 and then No
(Next
(Actual
))
5731 Prefix
=> Make_Function_Call
(Loc
,
5732 Name
=> Relocate_Node
(Name
(N
))),
5734 New_Occurrence_Of
(Entity
(Actual
), Sloc
(Actual
))));
5739 elsif not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
5747 if No
(Actual
) and then No
(Index
) then
5748 Add_One_Interp
(N
, Nam
, Component_Type
(Typ
));
5750 -- Nam is a candidate interpretation for the name in the call,
5751 -- if it is not an indirect call.
5753 if not Is_Type
(Nam
)
5754 and then Is_Entity_Name
(Name
(N
))
5756 Set_Entity
(Name
(N
), Nam
);
5763 end Try_Indexed_Call
;
5765 --------------------------
5766 -- Try_Object_Operation --
5767 --------------------------
5769 function Try_Object_Operation
(N
: Node_Id
) return Boolean is
5770 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
5771 Is_Subprg_Call
: constant Boolean := Nkind_In
5772 (K
, N_Procedure_Call_Statement
,
5774 Loc
: constant Source_Ptr
:= Sloc
(N
);
5775 Obj
: constant Node_Id
:= Prefix
(N
);
5776 Subprog
: constant Node_Id
:=
5777 Make_Identifier
(Sloc
(Selector_Name
(N
)),
5778 Chars
=> Chars
(Selector_Name
(N
)));
5779 -- Identifier on which possible interpretations will be collected
5781 Report_Error
: Boolean := False;
5782 -- If no candidate interpretation matches the context, redo the
5783 -- analysis with error enabled to provide additional information.
5786 Candidate
: Entity_Id
:= Empty
;
5787 New_Call_Node
: Node_Id
:= Empty
;
5788 Node_To_Replace
: Node_Id
;
5789 Obj_Type
: Entity_Id
:= Etype
(Obj
);
5790 Success
: Boolean := False;
5792 function Valid_Candidate
5795 Subp
: Entity_Id
) return Entity_Id
;
5796 -- If the subprogram is a valid interpretation, record it, and add
5797 -- to the list of interpretations of Subprog.
5799 procedure Complete_Object_Operation
5800 (Call_Node
: Node_Id
;
5801 Node_To_Replace
: Node_Id
);
5802 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
5803 -- Call_Node, insert the object (or its dereference) as the first actual
5804 -- in the call, and complete the analysis of the call.
5806 procedure Report_Ambiguity
(Op
: Entity_Id
);
5807 -- If a prefixed procedure call is ambiguous, indicate whether the
5808 -- call includes an implicit dereference or an implicit 'Access.
5810 procedure Transform_Object_Operation
5811 (Call_Node
: out Node_Id
;
5812 Node_To_Replace
: out Node_Id
);
5813 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
5814 -- Call_Node is the resulting subprogram call, Node_To_Replace is
5815 -- either N or the parent of N, and Subprog is a reference to the
5816 -- subprogram we are trying to match.
5818 function Try_Class_Wide_Operation
5819 (Call_Node
: Node_Id
;
5820 Node_To_Replace
: Node_Id
) return Boolean;
5821 -- Traverse all ancestor types looking for a class-wide subprogram
5822 -- for which the current operation is a valid non-dispatching call.
5824 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
);
5825 -- If prefix is overloaded, its interpretation may include different
5826 -- tagged types, and we must examine the primitive operations and
5827 -- the class-wide operations of each in order to find candidate
5828 -- interpretations for the call as a whole.
5830 function Try_Primitive_Operation
5831 (Call_Node
: Node_Id
;
5832 Node_To_Replace
: Node_Id
) return Boolean;
5833 -- Traverse the list of primitive subprograms looking for a dispatching
5834 -- operation for which the current node is a valid call .
5836 ---------------------
5837 -- Valid_Candidate --
5838 ---------------------
5840 function Valid_Candidate
5843 Subp
: Entity_Id
) return Entity_Id
5845 Arr_Type
: Entity_Id
;
5846 Comp_Type
: Entity_Id
;
5849 -- If the subprogram is a valid interpretation, record it in global
5850 -- variable Subprog, to collect all possible overloadings.
5853 if Subp
/= Entity
(Subprog
) then
5854 Add_One_Interp
(Subprog
, Subp
, Etype
(Subp
));
5858 -- If the call may be an indexed call, retrieve component type of
5859 -- resulting expression, and add possible interpretation.
5864 if Nkind
(Call
) = N_Function_Call
5865 and then Nkind
(Parent
(N
)) = N_Indexed_Component
5866 and then Needs_One_Actual
(Subp
)
5868 if Is_Array_Type
(Etype
(Subp
)) then
5869 Arr_Type
:= Etype
(Subp
);
5871 elsif Is_Access_Type
(Etype
(Subp
))
5872 and then Is_Array_Type
(Designated_Type
(Etype
(Subp
)))
5874 Arr_Type
:= Designated_Type
(Etype
(Subp
));
5878 if Present
(Arr_Type
) then
5880 -- Verify that the actuals (excluding the object)
5881 -- match the types of the indices.
5888 Actual
:= Next
(First_Actual
(Call
));
5889 Index
:= First_Index
(Arr_Type
);
5890 while Present
(Actual
) and then Present
(Index
) loop
5891 if not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
5896 Next_Actual
(Actual
);
5902 and then Present
(Arr_Type
)
5904 Comp_Type
:= Component_Type
(Arr_Type
);
5908 if Present
(Comp_Type
)
5909 and then Etype
(Subprog
) /= Comp_Type
5911 Add_One_Interp
(Subprog
, Subp
, Comp_Type
);
5915 if Etype
(Call
) /= Any_Type
then
5920 end Valid_Candidate
;
5922 -------------------------------
5923 -- Complete_Object_Operation --
5924 -------------------------------
5926 procedure Complete_Object_Operation
5927 (Call_Node
: Node_Id
;
5928 Node_To_Replace
: Node_Id
)
5930 Control
: constant Entity_Id
:= First_Formal
(Entity
(Subprog
));
5931 Formal_Type
: constant Entity_Id
:= Etype
(Control
);
5932 First_Actual
: Node_Id
;
5935 -- Place the name of the operation, with its interpretations,
5936 -- on the rewritten call.
5938 Set_Name
(Call_Node
, Subprog
);
5940 First_Actual
:= First
(Parameter_Associations
(Call_Node
));
5942 -- For cross-reference purposes, treat the new node as being in
5943 -- the source if the original one is.
5945 Set_Comes_From_Source
(Subprog
, Comes_From_Source
(N
));
5946 Set_Comes_From_Source
(Call_Node
, Comes_From_Source
(N
));
5948 if Nkind
(N
) = N_Selected_Component
5949 and then not Inside_A_Generic
5951 Set_Entity
(Selector_Name
(N
), Entity
(Subprog
));
5954 -- If need be, rewrite first actual as an explicit dereference
5955 -- If the call is overloaded, the rewriting can only be done
5956 -- once the primitive operation is identified.
5958 if Is_Overloaded
(Subprog
) then
5960 -- The prefix itself may be overloaded, and its interpretations
5961 -- must be propagated to the new actual in the call.
5963 if Is_Overloaded
(Obj
) then
5964 Save_Interps
(Obj
, First_Actual
);
5967 Rewrite
(First_Actual
, Obj
);
5969 elsif not Is_Access_Type
(Formal_Type
)
5970 and then Is_Access_Type
(Etype
(Obj
))
5972 Rewrite
(First_Actual
,
5973 Make_Explicit_Dereference
(Sloc
(Obj
), Obj
));
5974 Analyze
(First_Actual
);
5976 -- If we need to introduce an explicit dereference, verify that
5977 -- the resulting actual is compatible with the mode of the formal.
5979 if Ekind
(First_Formal
(Entity
(Subprog
))) /= E_In_Parameter
5980 and then Is_Access_Constant
(Etype
(Obj
))
5983 ("expect variable in call to&", Prefix
(N
), Entity
(Subprog
));
5986 -- Conversely, if the formal is an access parameter and the object
5987 -- is not, replace the actual with a 'Access reference. Its analysis
5988 -- will check that the object is aliased.
5990 elsif Is_Access_Type
(Formal_Type
)
5991 and then not Is_Access_Type
(Etype
(Obj
))
5993 -- A special case: A.all'access is illegal if A is an access to a
5994 -- constant and the context requires an access to a variable.
5996 if not Is_Access_Constant
(Formal_Type
) then
5997 if (Nkind
(Obj
) = N_Explicit_Dereference
5998 and then Is_Access_Constant
(Etype
(Prefix
(Obj
))))
5999 or else not Is_Variable
(Obj
)
6002 ("actual for& must be a variable", Obj
, Control
);
6006 Rewrite
(First_Actual
,
6007 Make_Attribute_Reference
(Loc
,
6008 Attribute_Name
=> Name_Access
,
6009 Prefix
=> Relocate_Node
(Obj
)));
6011 if not Is_Aliased_View
(Obj
) then
6013 ("object in prefixed call to& must be aliased"
6014 & " (RM-2005 4.3.1 (13))",
6015 Prefix
(First_Actual
), Subprog
);
6018 Analyze
(First_Actual
);
6021 if Is_Overloaded
(Obj
) then
6022 Save_Interps
(Obj
, First_Actual
);
6025 Rewrite
(First_Actual
, Obj
);
6028 Rewrite
(Node_To_Replace
, Call_Node
);
6030 -- Propagate the interpretations collected in subprog to the new
6031 -- function call node, to be resolved from context.
6033 if Is_Overloaded
(Subprog
) then
6034 Save_Interps
(Subprog
, Node_To_Replace
);
6036 Analyze
(Node_To_Replace
);
6038 end Complete_Object_Operation
;
6040 ----------------------
6041 -- Report_Ambiguity --
6042 ----------------------
6044 procedure Report_Ambiguity
(Op
: Entity_Id
) is
6045 Access_Formal
: constant Boolean :=
6046 Is_Access_Type
(Etype
(First_Formal
(Op
)));
6047 Access_Actual
: constant Boolean :=
6048 Is_Access_Type
(Etype
(Prefix
(N
)));
6051 Error_Msg_Sloc
:= Sloc
(Op
);
6053 if Access_Formal
and then not Access_Actual
then
6054 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
6056 ("\possible interpretation"
6057 & " (inherited, with implicit 'Access) #", N
);
6060 ("\possible interpretation (with implicit 'Access) #", N
);
6063 elsif not Access_Formal
and then Access_Actual
then
6064 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
6066 ("\possible interpretation"
6067 & " ( inherited, with implicit dereference) #", N
);
6070 ("\possible interpretation (with implicit dereference) #", N
);
6074 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
6075 Error_Msg_N
("\possible interpretation (inherited)#", N
);
6077 Error_Msg_N
-- CODEFIX
6078 ("\possible interpretation#", N
);
6081 end Report_Ambiguity
;
6083 --------------------------------
6084 -- Transform_Object_Operation --
6085 --------------------------------
6087 procedure Transform_Object_Operation
6088 (Call_Node
: out Node_Id
;
6089 Node_To_Replace
: out Node_Id
)
6091 Dummy
: constant Node_Id
:= New_Copy
(Obj
);
6092 -- Placeholder used as a first parameter in the call, replaced
6093 -- eventually by the proper object.
6095 Parent_Node
: constant Node_Id
:= Parent
(N
);
6101 -- Common case covering 1) Call to a procedure and 2) Call to a
6102 -- function that has some additional actuals.
6104 if Nkind_In
(Parent_Node
, N_Function_Call
,
6105 N_Procedure_Call_Statement
)
6107 -- N is a selected component node containing the name of the
6108 -- subprogram. If N is not the name of the parent node we must
6109 -- not replace the parent node by the new construct. This case
6110 -- occurs when N is a parameterless call to a subprogram that
6111 -- is an actual parameter of a call to another subprogram. For
6113 -- Some_Subprogram (..., Obj.Operation, ...)
6115 and then Name
(Parent_Node
) = N
6117 Node_To_Replace
:= Parent_Node
;
6119 Actuals
:= Parameter_Associations
(Parent_Node
);
6121 if Present
(Actuals
) then
6122 Prepend
(Dummy
, Actuals
);
6124 Actuals
:= New_List
(Dummy
);
6127 if Nkind
(Parent_Node
) = N_Procedure_Call_Statement
then
6129 Make_Procedure_Call_Statement
(Loc
,
6130 Name
=> New_Copy
(Subprog
),
6131 Parameter_Associations
=> Actuals
);
6135 Make_Function_Call
(Loc
,
6136 Name
=> New_Copy
(Subprog
),
6137 Parameter_Associations
=> Actuals
);
6141 -- Before analysis, a function call appears as an indexed component
6142 -- if there are no named associations.
6144 elsif Nkind
(Parent_Node
) = N_Indexed_Component
6145 and then N
= Prefix
(Parent_Node
)
6147 Node_To_Replace
:= Parent_Node
;
6149 Actuals
:= Expressions
(Parent_Node
);
6151 Actual
:= First
(Actuals
);
6152 while Present
(Actual
) loop
6157 Prepend
(Dummy
, Actuals
);
6160 Make_Function_Call
(Loc
,
6161 Name
=> New_Copy
(Subprog
),
6162 Parameter_Associations
=> Actuals
);
6164 -- Parameterless call: Obj.F is rewritten as F (Obj)
6167 Node_To_Replace
:= N
;
6170 Make_Function_Call
(Loc
,
6171 Name
=> New_Copy
(Subprog
),
6172 Parameter_Associations
=> New_List
(Dummy
));
6174 end Transform_Object_Operation
;
6176 ------------------------------
6177 -- Try_Class_Wide_Operation --
6178 ------------------------------
6180 function Try_Class_Wide_Operation
6181 (Call_Node
: Node_Id
;
6182 Node_To_Replace
: Node_Id
) return Boolean
6184 Anc_Type
: Entity_Id
;
6185 Matching_Op
: Entity_Id
:= Empty
;
6188 procedure Traverse_Homonyms
6189 (Anc_Type
: Entity_Id
;
6190 Error
: out Boolean);
6191 -- Traverse the homonym chain of the subprogram searching for those
6192 -- homonyms whose first formal has the Anc_Type's class-wide type,
6193 -- or an anonymous access type designating the class-wide type. If
6194 -- an ambiguity is detected, then Error is set to True.
6196 procedure Traverse_Interfaces
6197 (Anc_Type
: Entity_Id
;
6198 Error
: out Boolean);
6199 -- Traverse the list of interfaces, if any, associated with Anc_Type
6200 -- and search for acceptable class-wide homonyms associated with each
6201 -- interface. If an ambiguity is detected, then Error is set to True.
6203 -----------------------
6204 -- Traverse_Homonyms --
6205 -----------------------
6207 procedure Traverse_Homonyms
6208 (Anc_Type
: Entity_Id
;
6209 Error
: out Boolean)
6211 Cls_Type
: Entity_Id
;
6219 Cls_Type
:= Class_Wide_Type
(Anc_Type
);
6221 Hom
:= Current_Entity
(Subprog
);
6223 -- Find operation whose first parameter is of the class-wide
6224 -- type, a subtype thereof, or an anonymous access to same.
6226 while Present
(Hom
) loop
6227 if (Ekind
(Hom
) = E_Procedure
6229 Ekind
(Hom
) = E_Function
)
6230 and then Scope
(Hom
) = Scope
(Anc_Type
)
6231 and then Present
(First_Formal
(Hom
))
6233 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
6235 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
6237 Ekind
(Etype
(First_Formal
(Hom
))) =
6238 E_Anonymous_Access_Type
6241 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
6244 Set_Etype
(Call_Node
, Any_Type
);
6245 Set_Is_Overloaded
(Call_Node
, False);
6248 if No
(Matching_Op
) then
6249 Hom_Ref
:= New_Reference_To
(Hom
, Sloc
(Subprog
));
6250 Set_Etype
(Call_Node
, Any_Type
);
6251 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
6253 Set_Name
(Call_Node
, Hom_Ref
);
6258 Report
=> Report_Error
,
6260 Skip_First
=> True);
6263 Valid_Candidate
(Success
, Call_Node
, Hom
);
6269 Report
=> Report_Error
,
6271 Skip_First
=> True);
6273 if Present
(Valid_Candidate
(Success
, Call_Node
, Hom
))
6274 and then Nkind
(Call_Node
) /= N_Function_Call
6276 Error_Msg_NE
("ambiguous call to&", N
, Hom
);
6277 Report_Ambiguity
(Matching_Op
);
6278 Report_Ambiguity
(Hom
);
6285 Hom
:= Homonym
(Hom
);
6287 end Traverse_Homonyms
;
6289 -------------------------
6290 -- Traverse_Interfaces --
6291 -------------------------
6293 procedure Traverse_Interfaces
6294 (Anc_Type
: Entity_Id
;
6295 Error
: out Boolean)
6297 Intface_List
: constant List_Id
:=
6298 Abstract_Interface_List
(Anc_Type
);
6304 if Is_Non_Empty_List
(Intface_List
) then
6305 Intface
:= First
(Intface_List
);
6306 while Present
(Intface
) loop
6308 -- Look for acceptable class-wide homonyms associated with
6311 Traverse_Homonyms
(Etype
(Intface
), Error
);
6317 -- Continue the search by looking at each of the interface's
6318 -- associated interface ancestors.
6320 Traverse_Interfaces
(Etype
(Intface
), Error
);
6329 end Traverse_Interfaces
;
6331 -- Start of processing for Try_Class_Wide_Operation
6334 -- Loop through ancestor types (including interfaces), traversing
6335 -- the homonym chain of the subprogram, trying out those homonyms
6336 -- whose first formal has the class-wide type of the ancestor, or
6337 -- an anonymous access type designating the class-wide type.
6339 Anc_Type
:= Obj_Type
;
6341 -- Look for a match among homonyms associated with the ancestor
6343 Traverse_Homonyms
(Anc_Type
, Error
);
6349 -- Continue the search for matches among homonyms associated with
6350 -- any interfaces implemented by the ancestor.
6352 Traverse_Interfaces
(Anc_Type
, Error
);
6358 exit when Etype
(Anc_Type
) = Anc_Type
;
6359 Anc_Type
:= Etype
(Anc_Type
);
6362 if Present
(Matching_Op
) then
6363 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
6366 return Present
(Matching_Op
);
6367 end Try_Class_Wide_Operation
;
6369 -----------------------------------
6370 -- Try_One_Prefix_Interpretation --
6371 -----------------------------------
6373 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
) is
6377 if Is_Access_Type
(Obj_Type
) then
6378 Obj_Type
:= Designated_Type
(Obj_Type
);
6381 if Ekind
(Obj_Type
) = E_Private_Subtype
then
6382 Obj_Type
:= Base_Type
(Obj_Type
);
6385 if Is_Class_Wide_Type
(Obj_Type
) then
6386 Obj_Type
:= Etype
(Class_Wide_Type
(Obj_Type
));
6389 -- The type may have be obtained through a limited_with clause,
6390 -- in which case the primitive operations are available on its
6391 -- non-limited view. If still incomplete, retrieve full view.
6393 if Ekind
(Obj_Type
) = E_Incomplete_Type
6394 and then From_With_Type
(Obj_Type
)
6396 Obj_Type
:= Get_Full_View
(Non_Limited_View
(Obj_Type
));
6399 -- If the object is not tagged, or the type is still an incomplete
6400 -- type, this is not a prefixed call.
6402 if not Is_Tagged_Type
(Obj_Type
)
6403 or else Is_Incomplete_Type
(Obj_Type
)
6408 if Try_Primitive_Operation
6409 (Call_Node
=> New_Call_Node
,
6410 Node_To_Replace
=> Node_To_Replace
)
6412 Try_Class_Wide_Operation
6413 (Call_Node
=> New_Call_Node
,
6414 Node_To_Replace
=> Node_To_Replace
)
6418 end Try_One_Prefix_Interpretation
;
6420 -----------------------------
6421 -- Try_Primitive_Operation --
6422 -----------------------------
6424 function Try_Primitive_Operation
6425 (Call_Node
: Node_Id
;
6426 Node_To_Replace
: Node_Id
) return Boolean
6429 Prim_Op
: Entity_Id
;
6430 Matching_Op
: Entity_Id
:= Empty
;
6431 Prim_Op_Ref
: Node_Id
:= Empty
;
6433 Corr_Type
: Entity_Id
:= Empty
;
6434 -- If the prefix is a synchronized type, the controlling type of
6435 -- the primitive operation is the corresponding record type, else
6436 -- this is the object type itself.
6438 Success
: Boolean := False;
6440 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
;
6441 -- For tagged types the candidate interpretations are found in
6442 -- the list of primitive operations of the type and its ancestors.
6443 -- For formal tagged types we have to find the operations declared
6444 -- in the same scope as the type (including in the generic formal
6445 -- part) because the type itself carries no primitive operations,
6446 -- except for formal derived types that inherit the operations of
6447 -- the parent and progenitors.
6448 -- If the context is a generic subprogram body, the generic formals
6449 -- are visible by name, but are not in the entity list of the
6450 -- subprogram because that list starts with the subprogram formals.
6451 -- We retrieve the candidate operations from the generic declaration.
6453 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean;
6454 -- Verify that the prefix, dereferenced if need be, is a valid
6455 -- controlling argument in a call to Op. The remaining actuals
6456 -- are checked in the subsequent call to Analyze_One_Call.
6458 ------------------------------
6459 -- Collect_Generic_Type_Ops --
6460 ------------------------------
6462 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
is
6463 Bas
: constant Entity_Id
:= Base_Type
(T
);
6464 Candidates
: constant Elist_Id
:= New_Elmt_List
;
6468 procedure Check_Candidate
;
6469 -- The operation is a candidate if its first parameter is a
6470 -- controlling operand of the desired type.
6472 -----------------------
6473 -- Check_Candidate; --
6474 -----------------------
6476 procedure Check_Candidate
is
6478 Formal
:= First_Formal
(Subp
);
6481 and then Is_Controlling_Formal
(Formal
)
6483 (Base_Type
(Etype
(Formal
)) = Bas
6485 (Is_Access_Type
(Etype
(Formal
))
6486 and then Designated_Type
(Etype
(Formal
)) = Bas
))
6488 Append_Elmt
(Subp
, Candidates
);
6490 end Check_Candidate
;
6492 -- Start of processing for Collect_Generic_Type_Ops
6495 if Is_Derived_Type
(T
) then
6496 return Primitive_Operations
(T
);
6498 elsif Ekind
(Scope
(T
)) = E_Procedure
6499 or else Ekind
(Scope
(T
)) = E_Function
6501 -- Scan the list of generic formals to find subprograms
6502 -- that may have a first controlling formal of the type.
6509 First
(Generic_Formal_Declarations
6510 (Unit_Declaration_Node
(Scope
(T
))));
6511 while Present
(Decl
) loop
6512 if Nkind
(Decl
) in N_Formal_Subprogram_Declaration
then
6513 Subp
:= Defining_Entity
(Decl
);
6524 -- Scan the list of entities declared in the same scope as
6525 -- the type. In general this will be an open scope, given that
6526 -- the call we are analyzing can only appear within a generic
6527 -- declaration or body (either the one that declares T, or a
6530 Subp
:= First_Entity
(Scope
(T
));
6531 while Present
(Subp
) loop
6532 if Is_Overloadable
(Subp
) then
6541 end Collect_Generic_Type_Ops
;
6543 -----------------------------
6544 -- Valid_First_Argument_Of --
6545 -----------------------------
6547 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean is
6548 Typ
: Entity_Id
:= Etype
(First_Formal
(Op
));
6551 if Is_Concurrent_Type
(Typ
)
6552 and then Present
(Corresponding_Record_Type
(Typ
))
6554 Typ
:= Corresponding_Record_Type
(Typ
);
6557 -- Simple case. Object may be a subtype of the tagged type or
6558 -- may be the corresponding record of a synchronized type.
6560 return Obj_Type
= Typ
6561 or else Base_Type
(Obj_Type
) = Typ
6562 or else Corr_Type
= Typ
6564 -- Prefix can be dereferenced
6567 (Is_Access_Type
(Corr_Type
)
6568 and then Designated_Type
(Corr_Type
) = Typ
)
6570 -- Formal is an access parameter, for which the object
6571 -- can provide an access.
6574 (Ekind
(Typ
) = E_Anonymous_Access_Type
6575 and then Designated_Type
(Typ
) = Base_Type
(Corr_Type
));
6576 end Valid_First_Argument_Of
;
6578 -- Start of processing for Try_Primitive_Operation
6581 -- Look for subprograms in the list of primitive operations. The name
6582 -- must be identical, and the kind of call indicates the expected
6583 -- kind of operation (function or procedure). If the type is a
6584 -- (tagged) synchronized type, the primitive ops are attached to the
6585 -- corresponding record (base) type.
6587 if Is_Concurrent_Type
(Obj_Type
) then
6588 if not Present
(Corresponding_Record_Type
(Obj_Type
)) then
6592 Corr_Type
:= Base_Type
(Corresponding_Record_Type
(Obj_Type
));
6593 Elmt
:= First_Elmt
(Primitive_Operations
(Corr_Type
));
6595 elsif not Is_Generic_Type
(Obj_Type
) then
6596 Corr_Type
:= Obj_Type
;
6597 Elmt
:= First_Elmt
(Primitive_Operations
(Obj_Type
));
6600 Corr_Type
:= Obj_Type
;
6601 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
6604 while Present
(Elmt
) loop
6605 Prim_Op
:= Node
(Elmt
);
6607 if Chars
(Prim_Op
) = Chars
(Subprog
)
6608 and then Present
(First_Formal
(Prim_Op
))
6609 and then Valid_First_Argument_Of
(Prim_Op
)
6611 (Nkind
(Call_Node
) = N_Function_Call
)
6612 = (Ekind
(Prim_Op
) = E_Function
)
6614 -- Ada 2005 (AI-251): If this primitive operation corresponds
6615 -- with an immediate ancestor interface there is no need to add
6616 -- it to the list of interpretations; the corresponding aliased
6617 -- primitive is also in this list of primitive operations and
6618 -- will be used instead.
6620 if (Present
(Interface_Alias
(Prim_Op
))
6621 and then Is_Ancestor
(Find_Dispatching_Type
6622 (Alias
(Prim_Op
)), Corr_Type
))
6625 -- Do not consider hidden primitives unless the type is
6626 -- in an open scope or we are within an instance, where
6627 -- visibility is known to be correct.
6629 (Is_Hidden
(Prim_Op
)
6630 and then not Is_Immediately_Visible
(Obj_Type
)
6631 and then not In_Instance
)
6636 Set_Etype
(Call_Node
, Any_Type
);
6637 Set_Is_Overloaded
(Call_Node
, False);
6639 if No
(Matching_Op
) then
6640 Prim_Op_Ref
:= New_Reference_To
(Prim_Op
, Sloc
(Subprog
));
6641 Candidate
:= Prim_Op
;
6643 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
6645 Set_Name
(Call_Node
, Prim_Op_Ref
);
6651 Report
=> Report_Error
,
6653 Skip_First
=> True);
6655 Matching_Op
:= Valid_Candidate
(Success
, Call_Node
, Prim_Op
);
6657 -- More than one interpretation, collect for subsequent
6658 -- disambiguation. If this is a procedure call and there
6659 -- is another match, report ambiguity now.
6665 Report
=> Report_Error
,
6667 Skip_First
=> True);
6669 if Present
(Valid_Candidate
(Success
, Call_Node
, Prim_Op
))
6670 and then Nkind
(Call_Node
) /= N_Function_Call
6672 Error_Msg_NE
("ambiguous call to&", N
, Prim_Op
);
6673 Report_Ambiguity
(Matching_Op
);
6674 Report_Ambiguity
(Prim_Op
);
6684 if Present
(Matching_Op
) then
6685 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
6688 return Present
(Matching_Op
);
6689 end Try_Primitive_Operation
;
6691 -- Start of processing for Try_Object_Operation
6694 Analyze_Expression
(Obj
);
6696 -- Analyze the actuals if node is known to be a subprogram call
6698 if Is_Subprg_Call
and then N
= Name
(Parent
(N
)) then
6699 Actual
:= First
(Parameter_Associations
(Parent
(N
)));
6700 while Present
(Actual
) loop
6701 Analyze_Expression
(Actual
);
6706 -- Build a subprogram call node, using a copy of Obj as its first
6707 -- actual. This is a placeholder, to be replaced by an explicit
6708 -- dereference when needed.
6710 Transform_Object_Operation
6711 (Call_Node
=> New_Call_Node
,
6712 Node_To_Replace
=> Node_To_Replace
);
6714 Set_Etype
(New_Call_Node
, Any_Type
);
6715 Set_Etype
(Subprog
, Any_Type
);
6716 Set_Parent
(New_Call_Node
, Parent
(Node_To_Replace
));
6718 if not Is_Overloaded
(Obj
) then
6719 Try_One_Prefix_Interpretation
(Obj_Type
);
6726 Get_First_Interp
(Obj
, I
, It
);
6727 while Present
(It
.Nam
) loop
6728 Try_One_Prefix_Interpretation
(It
.Typ
);
6729 Get_Next_Interp
(I
, It
);
6734 if Etype
(New_Call_Node
) /= Any_Type
then
6735 Complete_Object_Operation
6736 (Call_Node
=> New_Call_Node
,
6737 Node_To_Replace
=> Node_To_Replace
);
6740 elsif Present
(Candidate
) then
6742 -- The argument list is not type correct. Re-analyze with error
6743 -- reporting enabled, and use one of the possible candidates.
6744 -- In All_Errors_Mode, re-analyze all failed interpretations.
6746 if All_Errors_Mode
then
6747 Report_Error
:= True;
6748 if Try_Primitive_Operation
6749 (Call_Node
=> New_Call_Node
,
6750 Node_To_Replace
=> Node_To_Replace
)
6753 Try_Class_Wide_Operation
6754 (Call_Node
=> New_Call_Node
,
6755 Node_To_Replace
=> Node_To_Replace
)
6762 (N
=> New_Call_Node
,
6766 Skip_First
=> True);
6769 -- No need for further errors
6774 -- There was no candidate operation, so report it as an error
6775 -- in the caller: Analyze_Selected_Component.
6779 end Try_Object_Operation
;
6785 procedure wpo
(T
: Entity_Id
) is
6790 if not Is_Tagged_Type
(T
) then
6794 E
:= First_Elmt
(Primitive_Operations
(Base_Type
(T
)));
6795 while Present
(E
) loop
6797 Write_Int
(Int
(Op
));
6798 Write_Str
(" === ");
6799 Write_Name
(Chars
(Op
));
6801 Write_Name
(Chars
(Scope
(Op
)));