1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, 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 Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Util
; use Exp_Util
;
33 with Fname
; use Fname
;
34 with Itypes
; use Itypes
;
36 with Lib
.Xref
; use Lib
.Xref
;
37 with Namet
; use Namet
;
38 with Namet
.Sp
; use Namet
.Sp
;
39 with Nlists
; use Nlists
;
40 with Nmake
; use Nmake
;
42 with Output
; use Output
;
43 with Restrict
; use Restrict
;
44 with Rident
; use Rident
;
46 with Sem_Aux
; use Sem_Aux
;
47 with Sem_Case
; use Sem_Case
;
48 with Sem_Cat
; use Sem_Cat
;
49 with Sem_Ch3
; use Sem_Ch3
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch8
; use Sem_Ch8
;
52 with Sem_Dim
; use Sem_Dim
;
53 with Sem_Disp
; use Sem_Disp
;
54 with Sem_Dist
; use Sem_Dist
;
55 with Sem_Eval
; use Sem_Eval
;
56 with Sem_Res
; use Sem_Res
;
57 with Sem_Type
; use Sem_Type
;
58 with Sem_Util
; use Sem_Util
;
59 with Sem_Warn
; use Sem_Warn
;
60 with Stand
; use Stand
;
61 with Sinfo
; use Sinfo
;
62 with Snames
; use Snames
;
63 with Tbuild
; use Tbuild
;
64 with Uintp
; use Uintp
;
66 package body Sem_Ch4
is
68 -- Tables which speed up the identification of dangerous calls to Ada 2012
69 -- functions with writable actuals (AI05-0144).
71 -- The following table enumerates the Ada constructs which may evaluate in
72 -- arbitrary order. It does not cover all the language constructs which can
73 -- be evaluated in arbitrary order but the subset needed for AI05-0144.
75 Has_Arbitrary_Evaluation_Order
: constant array (Node_Kind
) of Boolean :=
77 N_Assignment_Statement
=> True,
78 N_Entry_Call_Statement
=> True,
79 N_Extension_Aggregate
=> True,
80 N_Full_Type_Declaration
=> True,
81 N_Indexed_Component
=> True,
82 N_Object_Declaration
=> True,
86 N_Array_Type_Definition
=> True,
87 N_Membership_Test
=> True,
89 N_Subprogram_Call
=> True,
92 -- The following table enumerates the nodes on which we stop climbing when
93 -- locating the outermost Ada construct that can be evaluated in arbitrary
96 Stop_Subtree_Climbing
: constant array (Node_Kind
) of Boolean :=
98 N_Assignment_Statement
=> True,
99 N_Entry_Call_Statement
=> True,
100 N_Extended_Return_Statement
=> True,
101 N_Extension_Aggregate
=> True,
102 N_Full_Type_Declaration
=> True,
103 N_Object_Declaration
=> True,
104 N_Object_Renaming_Declaration
=> True,
105 N_Package_Specification
=> True,
107 N_Procedure_Call_Statement
=> True,
108 N_Simple_Return_Statement
=> True,
109 N_Has_Condition
=> True,
112 -----------------------
113 -- Local Subprograms --
114 -----------------------
116 procedure Analyze_Concatenation_Rest
(N
: Node_Id
);
117 -- Does the "rest" of the work of Analyze_Concatenation, after the left
118 -- operand has been analyzed. See Analyze_Concatenation for details.
120 procedure Analyze_Expression
(N
: Node_Id
);
121 -- For expressions that are not names, this is just a call to analyze. If
122 -- the expression is a name, it may be a call to a parameterless function,
123 -- and if so must be converted into an explicit call node and analyzed as
124 -- such. This deproceduring must be done during the first pass of overload
125 -- resolution, because otherwise a procedure call with overloaded actuals
126 -- may fail to resolve.
128 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
);
129 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call is an
130 -- operator name or an expanded name whose selector is an operator name,
131 -- and one possible interpretation is as a predefined operator.
133 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
);
134 -- If the prefix of a selected_component is overloaded, the proper
135 -- interpretation that yields a record type with the proper selector
136 -- name must be selected.
138 procedure Analyze_User_Defined_Binary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
139 -- Procedure to analyze a user defined binary operator, which is resolved
140 -- like a function, but instead of a list of actuals it is presented
141 -- with the left and right operands of an operator node.
143 procedure Analyze_User_Defined_Unary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
144 -- Procedure to analyze a user defined unary operator, which is resolved
145 -- like a function, but instead of a list of actuals, it is presented with
146 -- the operand of the operator node.
148 procedure Ambiguous_Operands
(N
: Node_Id
);
149 -- For equality, membership, and comparison operators with overloaded
150 -- arguments, list possible interpretations.
152 procedure Analyze_One_Call
156 Success
: out Boolean;
157 Skip_First
: Boolean := False);
158 -- Check one interpretation of an overloaded subprogram name for
159 -- compatibility with the types of the actuals in a call. If there is a
160 -- single interpretation which does not match, post error if Report is
163 -- Nam is the entity that provides the formals against which the actuals
164 -- are checked. Nam is either the name of a subprogram, or the internal
165 -- subprogram type constructed for an access_to_subprogram. If the actuals
166 -- are compatible with Nam, then Nam is added to the list of candidate
167 -- interpretations for N, and Success is set to True.
169 -- The flag Skip_First is used when analyzing a call that was rewritten
170 -- from object notation. In this case the first actual may have to receive
171 -- an explicit dereference, depending on the first formal of the operation
172 -- being called. The caller will have verified that the object is legal
173 -- for the call. If the remaining parameters match, the first parameter
174 -- will rewritten as a dereference if needed, prior to completing analysis.
176 procedure Check_Misspelled_Selector
179 -- Give possible misspelling message if Sel seems likely to be a mis-
180 -- spelling of one of the selectors of the Prefix. This is called by
181 -- Analyze_Selected_Component after producing an invalid selector error
184 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean;
185 -- Verify that type T is declared in scope S. Used to find interpretations
186 -- for operators given by expanded names. This is abstracted as a separate
187 -- function to handle extensions to System, where S is System, but T is
188 -- declared in the extension.
190 procedure Find_Arithmetic_Types
194 -- L and R are the operands of an arithmetic operator. Find consistent
195 -- pairs of interpretations for L and R that have a numeric type consistent
196 -- with the semantics of the operator.
198 procedure Find_Comparison_Types
202 -- L and R are operands of a comparison operator. Find consistent pairs of
203 -- interpretations for L and R.
205 procedure Find_Concatenation_Types
209 -- For the four varieties of concatenation
211 procedure Find_Equality_Types
215 -- Ditto for equality operators
217 procedure Find_Boolean_Types
221 -- Ditto for binary logical operations
223 procedure Find_Negation_Types
227 -- Find consistent interpretation for operand of negation operator
229 procedure Find_Non_Universal_Interpretations
234 -- For equality and comparison operators, the result is always boolean, and
235 -- the legality of the operation is determined from the visibility of the
236 -- operand types. If one of the operands has a universal interpretation,
237 -- the legality check uses some compatible non-universal interpretation of
238 -- the other operand. N can be an operator node, or a function call whose
239 -- name is an operator designator. Any_Access, which is the initial type of
240 -- the literal NULL, is a universal type for the purpose of this routine.
242 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean;
243 -- Find candidate interpretations for the name Obj.Proc when it appears in
244 -- a subprogram renaming declaration.
246 procedure Find_Unary_Types
250 -- Unary arithmetic types: plus, minus, abs
252 procedure Check_Arithmetic_Pair
256 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid types
257 -- for left and right operand. Determine whether they constitute a valid
258 -- pair for the given operator, and record the corresponding interpretation
259 -- of the operator node. The node N may be an operator node (the usual
260 -- case) or a function call whose prefix is an operator designator. In
261 -- both cases Op_Id is the operator name itself.
263 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
);
264 -- Give detailed information on overloaded call where none of the
265 -- interpretations match. N is the call node, Nam the designator for
266 -- the overloaded entity being called.
268 function Junk_Operand
(N
: Node_Id
) return Boolean;
269 -- Test for an operand that is an inappropriate entity (e.g. a package
270 -- name or a label). If so, issue an error message and return True. If
271 -- the operand is not an inappropriate entity kind, return False.
273 procedure Operator_Check
(N
: Node_Id
);
274 -- Verify that an operator has received some valid interpretation. If none
275 -- was found, determine whether a use clause would make the operation
276 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
277 -- every type compatible with the operator, even if the operator for the
278 -- type is not directly visible. The routine uses this type to emit a more
279 -- informative message.
281 function Process_Implicit_Dereference_Prefix
283 P
: Node_Id
) return Entity_Id
;
284 -- Called when P is the prefix of an implicit dereference, denoting an
285 -- object E. The function returns the designated type of the prefix, taking
286 -- into account that the designated type of an anonymous access type may be
287 -- a limited view, when the non-limited view is visible.
289 -- If in semantics only mode (-gnatc or generic), the function also records
290 -- that the prefix is a reference to E, if any. Normally, such a reference
291 -- is generated only when the implicit dereference is expanded into an
292 -- explicit one, but for consistency we must generate the reference when
293 -- expansion is disabled as well.
295 procedure Remove_Abstract_Operations
(N
: Node_Id
);
296 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
297 -- operation is not a candidate interpretation.
299 function Try_Container_Indexing
302 Exprs
: List_Id
) return Boolean;
303 -- AI05-0139: Generalized indexing to support iterators over containers
305 function Try_Indexed_Call
309 Skip_First
: Boolean) return Boolean;
310 -- If a function has defaults for all its actuals, a call to it may in fact
311 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
312 -- interpretation as an indexing, prior to analysis as a call. If both are
313 -- possible, the node is overloaded with both interpretations (same symbol
314 -- but two different types). If the call is written in prefix form, the
315 -- prefix becomes the first parameter in the call, and only the remaining
316 -- actuals must be checked for the presence of defaults.
318 function Try_Indirect_Call
321 Typ
: Entity_Id
) return Boolean;
322 -- Similarly, a function F that needs no actuals can return an access to a
323 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
324 -- the call may be overloaded with both interpretations.
326 procedure wpo
(T
: Entity_Id
);
327 pragma Warnings
(Off
, wpo
);
328 -- Used for debugging: obtain list of primitive operations even if
329 -- type is not frozen and dispatch table is not built yet.
331 ------------------------
332 -- Ambiguous_Operands --
333 ------------------------
335 procedure Ambiguous_Operands
(N
: Node_Id
) is
336 procedure List_Operand_Interps
(Opnd
: Node_Id
);
338 --------------------------
339 -- List_Operand_Interps --
340 --------------------------
342 procedure List_Operand_Interps
(Opnd
: Node_Id
) is
347 if Is_Overloaded
(Opnd
) then
348 if Nkind
(Opnd
) in N_Op
then
351 elsif Nkind
(Opnd
) = N_Function_Call
then
354 elsif Ada_Version
>= Ada_2012
then
360 Get_First_Interp
(Opnd
, I
, It
);
361 while Present
(It
.Nam
) loop
362 if Has_Implicit_Dereference
(It
.Typ
) then
364 ("can be interpreted as implicit dereference", Opnd
);
368 Get_Next_Interp
(I
, It
);
379 if Opnd
= Left_Opnd
(N
) then
381 ("\left operand has the following interpretations", N
);
384 ("\right operand has the following interpretations", N
);
388 List_Interps
(Nam
, Err
);
389 end List_Operand_Interps
;
391 -- Start of processing for Ambiguous_Operands
394 if Nkind
(N
) in N_Membership_Test
then
395 Error_Msg_N
("ambiguous operands for membership", N
);
397 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
) then
398 Error_Msg_N
("ambiguous operands for equality", N
);
401 Error_Msg_N
("ambiguous operands for comparison", N
);
404 if All_Errors_Mode
then
405 List_Operand_Interps
(Left_Opnd
(N
));
406 List_Operand_Interps
(Right_Opnd
(N
));
408 Error_Msg_N
("\use -gnatf switch for details", N
);
410 end Ambiguous_Operands
;
412 -----------------------
413 -- Analyze_Aggregate --
414 -----------------------
416 -- Most of the analysis of Aggregates requires that the type be known,
417 -- and is therefore put off until resolution.
419 procedure Analyze_Aggregate
(N
: Node_Id
) is
421 if No
(Etype
(N
)) then
422 Set_Etype
(N
, Any_Composite
);
424 end Analyze_Aggregate
;
426 -----------------------
427 -- Analyze_Allocator --
428 -----------------------
430 procedure Analyze_Allocator
(N
: Node_Id
) is
431 Loc
: constant Source_Ptr
:= Sloc
(N
);
432 Sav_Errs
: constant Nat
:= Serious_Errors_Detected
;
433 E
: Node_Id
:= Expression
(N
);
434 Acc_Type
: Entity_Id
;
441 Check_SPARK_05_Restriction
("allocator is not allowed", N
);
443 -- Deal with allocator restrictions
445 -- In accordance with H.4(7), the No_Allocators restriction only applies
446 -- to user-written allocators. The same consideration applies to the
447 -- No_Standard_Allocators_Before_Elaboration restriction.
449 if Comes_From_Source
(N
) then
450 Check_Restriction
(No_Allocators
, N
);
452 -- Processing for No_Standard_Allocators_After_Elaboration, loop to
453 -- look at enclosing context, checking task/main subprogram case.
457 while Present
(P
) loop
459 -- For the task case we need a handled sequence of statements,
460 -- where the occurrence of the allocator is within the statements
461 -- and the parent is a task body
463 if Nkind
(P
) = N_Handled_Sequence_Of_Statements
464 and then Is_List_Member
(C
)
465 and then List_Containing
(C
) = Statements
(P
)
467 Onode
:= Original_Node
(Parent
(P
));
469 -- Check for allocator within task body, this is a definite
470 -- violation of No_Allocators_After_Elaboration we can detect
473 if Nkind
(Onode
) = N_Task_Body
then
475 (No_Standard_Allocators_After_Elaboration
, N
);
480 -- The other case is appearance in a subprogram body. This is
481 -- a violation if this is a library level subprogram with no
482 -- parameters. Note that this is now a static error even if the
483 -- subprogram is not the main program (this is a change, in an
484 -- earlier version only the main program was affected, and the
485 -- check had to be done in the binder.
487 if Nkind
(P
) = N_Subprogram_Body
488 and then Nkind
(Parent
(P
)) = N_Compilation_Unit
489 and then No
(Parameter_Specifications
(Specification
(P
)))
492 (No_Standard_Allocators_After_Elaboration
, N
);
500 -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
501 -- any. The expected type for the name is any type. A non-overloading
502 -- rule then requires it to be of a type descended from
503 -- System.Storage_Pools.Subpools.Subpool_Handle.
505 -- This isn't exactly what the AI says, but it seems to be the right
506 -- rule. The AI should be fixed.???
509 Subpool
: constant Node_Id
:= Subpool_Handle_Name
(N
);
512 if Present
(Subpool
) then
515 if Is_Overloaded
(Subpool
) then
516 Error_Msg_N
("ambiguous subpool handle", Subpool
);
519 -- Check that Etype (Subpool) is descended from Subpool_Handle
525 -- Analyze the qualified expression or subtype indication
527 if Nkind
(E
) = N_Qualified_Expression
then
528 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
529 Set_Etype
(Acc_Type
, Acc_Type
);
530 Find_Type
(Subtype_Mark
(E
));
532 -- Analyze the qualified expression, and apply the name resolution
533 -- rule given in 4.7(3).
536 Type_Id
:= Etype
(E
);
537 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
539 -- A qualified expression requires an exact match of the type,
540 -- class-wide matching is not allowed.
542 -- if Is_Class_Wide_Type (Type_Id)
543 -- and then Base_Type
544 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
546 -- Wrong_Type (Expression (E), Type_Id);
549 -- We don't analyze the qualified expression itself because it's
550 -- part of the allocator. It is fully analyzed and resolved when
551 -- the allocator is resolved with the context type.
553 Set_Etype
(E
, Type_Id
);
555 -- Case where allocator has a subtype indication
560 Base_Typ
: Entity_Id
;
563 -- If the allocator includes a N_Subtype_Indication then a
564 -- constraint is present, otherwise the node is a subtype mark.
565 -- Introduce an explicit subtype declaration into the tree
566 -- defining some anonymous subtype and rewrite the allocator to
567 -- use this subtype rather than the subtype indication.
569 -- It is important to introduce the explicit subtype declaration
570 -- so that the bounds of the subtype indication are attached to
571 -- the tree in case the allocator is inside a generic unit.
573 -- Finally, if there is no subtype indication and the type is
574 -- a tagged unconstrained type with discriminants, the designated
575 -- object is constrained by their default values, and it is
576 -- simplest to introduce an explicit constraint now. In some cases
577 -- this is done during expansion, but freeze actions are certain
578 -- to be emitted in the proper order if constraint is explicit.
580 if Is_Entity_Name
(E
) and then Expander_Active
then
582 Type_Id
:= Entity
(E
);
584 if Is_Tagged_Type
(Type_Id
)
585 and then Has_Discriminants
(Type_Id
)
586 and then not Is_Constrained
(Type_Id
)
589 (Discriminant_Default_Value
590 (First_Discriminant
(Type_Id
)))
593 Constr
: constant List_Id
:= New_List
;
594 Loc
: constant Source_Ptr
:= Sloc
(E
);
595 Discr
: Entity_Id
:= First_Discriminant
(Type_Id
);
598 if Present
(Discriminant_Default_Value
(Discr
)) then
599 while Present
(Discr
) loop
600 Append
(Discriminant_Default_Value
(Discr
), Constr
);
601 Next_Discriminant
(Discr
);
605 Make_Subtype_Indication
(Loc
,
606 Subtype_Mark
=> New_Occurrence_Of
(Type_Id
, Loc
),
608 Make_Index_Or_Discriminant_Constraint
(Loc
,
609 Constraints
=> Constr
)));
615 if Nkind
(E
) = N_Subtype_Indication
then
617 -- A constraint is only allowed for a composite type in Ada
618 -- 95. In Ada 83, a constraint is also allowed for an
619 -- access-to-composite type, but the constraint is ignored.
621 Find_Type
(Subtype_Mark
(E
));
622 Base_Typ
:= Entity
(Subtype_Mark
(E
));
624 if Is_Elementary_Type
(Base_Typ
) then
625 if not (Ada_Version
= Ada_83
626 and then Is_Access_Type
(Base_Typ
))
628 Error_Msg_N
("constraint not allowed here", E
);
630 if Nkind
(Constraint
(E
)) =
631 N_Index_Or_Discriminant_Constraint
633 Error_Msg_N
-- CODEFIX
634 ("\if qualified expression was meant, " &
635 "use apostrophe", Constraint
(E
));
639 -- Get rid of the bogus constraint:
641 Rewrite
(E
, New_Copy_Tree
(Subtype_Mark
(E
)));
642 Analyze_Allocator
(N
);
646 if Expander_Active
then
647 Def_Id
:= Make_Temporary
(Loc
, 'S');
650 Make_Subtype_Declaration
(Loc
,
651 Defining_Identifier
=> Def_Id
,
652 Subtype_Indication
=> Relocate_Node
(E
)));
654 if Sav_Errs
/= Serious_Errors_Detected
655 and then Nkind
(Constraint
(E
)) =
656 N_Index_Or_Discriminant_Constraint
658 Error_Msg_N
-- CODEFIX
659 ("if qualified expression was meant, "
660 & "use apostrophe!", Constraint
(E
));
663 E
:= New_Occurrence_Of
(Def_Id
, Loc
);
664 Rewrite
(Expression
(N
), E
);
668 Type_Id
:= Process_Subtype
(E
, N
);
669 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
670 Set_Etype
(Acc_Type
, Acc_Type
);
671 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
672 Check_Fully_Declared
(Type_Id
, N
);
674 -- Ada 2005 (AI-231): If the designated type is itself an access
675 -- type that excludes null, its default initialization will
676 -- be a null object, and we can insert an unconditional raise
677 -- before the allocator.
679 -- Ada 2012 (AI-104): A not null indication here is altogether
682 if Can_Never_Be_Null
(Type_Id
) then
684 Not_Null_Check
: constant Node_Id
:=
685 Make_Raise_Constraint_Error
(Sloc
(E
),
686 Reason
=> CE_Null_Not_Allowed
);
689 if Expander_Active
then
690 Insert_Action
(N
, Not_Null_Check
);
691 Analyze
(Not_Null_Check
);
693 elsif Warn_On_Ada_2012_Compatibility
then
695 ("null value not allowed here in Ada 2012?y?", E
);
700 -- Check for missing initialization. Skip this check if we already
701 -- had errors on analyzing the allocator, since in that case these
702 -- are probably cascaded errors.
704 if not Is_Definite_Subtype
(Type_Id
)
705 and then Serious_Errors_Detected
= Sav_Errs
707 -- The build-in-place machinery may produce an allocator when
708 -- the designated type is indefinite but the underlying type is
709 -- not. In this case the unknown discriminants are meaningless
710 -- and should not trigger error messages. Check the parent node
711 -- because the allocator is marked as coming from source.
713 if Present
(Underlying_Type
(Type_Id
))
714 and then Is_Definite_Subtype
(Underlying_Type
(Type_Id
))
715 and then not Comes_From_Source
(Parent
(N
))
719 -- An unusual case arises when the parent of a derived type is
720 -- a limited record extension with unknown discriminants, and
721 -- its full view has no discriminants.
723 -- A more general fix might be to create the proper underlying
724 -- type for such a derived type, but it is a record type with
725 -- no private attributes, so this required extending the
726 -- meaning of this attribute. ???
728 elsif Ekind
(Etype
(Type_Id
)) = E_Record_Type_With_Private
729 and then Present
(Underlying_Type
(Etype
(Type_Id
)))
731 not Has_Discriminants
(Underlying_Type
(Etype
(Type_Id
)))
732 and then not Comes_From_Source
(Parent
(N
))
736 elsif Is_Class_Wide_Type
(Type_Id
) then
738 ("initialization required in class-wide allocation", N
);
741 if Ada_Version
< Ada_2005
742 and then Is_Limited_Type
(Type_Id
)
744 Error_Msg_N
("unconstrained allocation not allowed", N
);
746 if Is_Array_Type
(Type_Id
) then
748 ("\constraint with array bounds required", N
);
750 elsif Has_Unknown_Discriminants
(Type_Id
) then
753 else pragma Assert
(Has_Discriminants
(Type_Id
));
755 ("\constraint with discriminant values required", N
);
758 -- Limited Ada 2005 and general non-limited case
762 ("uninitialized unconstrained allocation not "
765 if Is_Array_Type
(Type_Id
) then
767 ("\qualified expression or constraint with "
768 & "array bounds required", N
);
770 elsif Has_Unknown_Discriminants
(Type_Id
) then
771 Error_Msg_N
("\qualified expression required", N
);
773 else pragma Assert
(Has_Discriminants
(Type_Id
));
775 ("\qualified expression or constraint with "
776 & "discriminant values required", N
);
784 if Is_Abstract_Type
(Type_Id
) then
785 Error_Msg_N
("cannot allocate abstract object", E
);
788 if Has_Task
(Designated_Type
(Acc_Type
)) then
789 Check_Restriction
(No_Tasking
, N
);
790 Check_Restriction
(Max_Tasks
, N
);
791 Check_Restriction
(No_Task_Allocators
, N
);
794 -- Check restriction against dynamically allocated protected objects
796 if Has_Protected
(Designated_Type
(Acc_Type
)) then
797 Check_Restriction
(No_Protected_Type_Allocators
, N
);
800 -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
801 -- type is nested, and the designated type needs finalization. The rule
802 -- is conservative in that class-wide types need finalization.
804 if Needs_Finalization
(Designated_Type
(Acc_Type
))
805 and then not Is_Library_Level_Entity
(Acc_Type
)
807 Check_Restriction
(No_Nested_Finalization
, N
);
810 -- Check that an allocator of a nested access type doesn't create a
811 -- protected object when restriction No_Local_Protected_Objects applies.
813 if Has_Protected
(Designated_Type
(Acc_Type
))
814 and then not Is_Library_Level_Entity
(Acc_Type
)
816 Check_Restriction
(No_Local_Protected_Objects
, N
);
819 -- Likewise for No_Local_Timing_Events
821 if Has_Timing_Event
(Designated_Type
(Acc_Type
))
822 and then not Is_Library_Level_Entity
(Acc_Type
)
824 Check_Restriction
(No_Local_Timing_Events
, N
);
827 -- If the No_Streams restriction is set, check that the type of the
828 -- object is not, and does not contain, any subtype derived from
829 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
830 -- Has_Stream just for efficiency reasons. There is no point in
831 -- spending time on a Has_Stream check if the restriction is not set.
833 if Restriction_Check_Required
(No_Streams
) then
834 if Has_Stream
(Designated_Type
(Acc_Type
)) then
835 Check_Restriction
(No_Streams
, N
);
839 Set_Etype
(N
, Acc_Type
);
841 if not Is_Library_Level_Entity
(Acc_Type
) then
842 Check_Restriction
(No_Local_Allocators
, N
);
845 if Serious_Errors_Detected
> Sav_Errs
then
846 Set_Error_Posted
(N
);
847 Set_Etype
(N
, Any_Type
);
849 end Analyze_Allocator
;
851 ---------------------------
852 -- Analyze_Arithmetic_Op --
853 ---------------------------
855 procedure Analyze_Arithmetic_Op
(N
: Node_Id
) is
856 L
: constant Node_Id
:= Left_Opnd
(N
);
857 R
: constant Node_Id
:= Right_Opnd
(N
);
861 Candidate_Type
:= Empty
;
862 Analyze_Expression
(L
);
863 Analyze_Expression
(R
);
865 -- If the entity is already set, the node is the instantiation of a
866 -- generic node with a non-local reference, or was manufactured by a
867 -- call to Make_Op_xxx. In either case the entity is known to be valid,
868 -- and we do not need to collect interpretations, instead we just get
869 -- the single possible interpretation.
873 if Present
(Op_Id
) then
874 if Ekind
(Op_Id
) = E_Operator
then
876 if Nkind_In
(N
, N_Op_Divide
, N_Op_Mod
, N_Op_Multiply
, N_Op_Rem
)
877 and then Treat_Fixed_As_Integer
(N
)
881 Set_Etype
(N
, Any_Type
);
882 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
886 Set_Etype
(N
, Any_Type
);
887 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
890 -- Entity is not already set, so we do need to collect interpretations
893 Set_Etype
(N
, Any_Type
);
895 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
896 while Present
(Op_Id
) loop
897 if Ekind
(Op_Id
) = E_Operator
898 and then Present
(Next_Entity
(First_Entity
(Op_Id
)))
900 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
902 -- The following may seem superfluous, because an operator cannot
903 -- be generic, but this ignores the cleverness of the author of
906 elsif Is_Overloadable
(Op_Id
) then
907 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
910 Op_Id
:= Homonym
(Op_Id
);
915 Check_Function_Writable_Actuals
(N
);
916 end Analyze_Arithmetic_Op
;
922 -- Function, procedure, and entry calls are checked here. The Name in
923 -- the call may be overloaded. The actuals have been analyzed and may
924 -- themselves be overloaded. On exit from this procedure, the node N
925 -- may have zero, one or more interpretations. In the first case an
926 -- error message is produced. In the last case, the node is flagged
927 -- as overloaded and the interpretations are collected in All_Interp.
929 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
930 -- the type-checking is similar to that of other calls.
932 procedure Analyze_Call
(N
: Node_Id
) is
933 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
934 Loc
: constant Source_Ptr
:= Sloc
(N
);
939 Success
: Boolean := False;
941 Deref
: Boolean := False;
942 -- Flag indicates whether an interpretation of the prefix is a
943 -- parameterless call that returns an access_to_subprogram.
945 procedure Check_Mixed_Parameter_And_Named_Associations
;
946 -- Check that parameter and named associations are not mixed. This is
947 -- a restriction in SPARK mode.
949 procedure Check_Writable_Actuals
(N
: Node_Id
);
950 -- If the call has out or in-out parameters then mark its outermost
951 -- enclosing construct as a node on which the writable actuals check
952 -- must be performed.
954 function Name_Denotes_Function
return Boolean;
955 -- If the type of the name is an access to subprogram, this may be the
956 -- type of a name, or the return type of the function being called. If
957 -- the name is not an entity then it can denote a protected function.
958 -- Until we distinguish Etype from Return_Type, we must use this routine
959 -- to resolve the meaning of the name in the call.
961 procedure No_Interpretation
;
962 -- Output error message when no valid interpretation exists
964 --------------------------------------------------
965 -- Check_Mixed_Parameter_And_Named_Associations --
966 --------------------------------------------------
968 procedure Check_Mixed_Parameter_And_Named_Associations
is
970 Named_Seen
: Boolean;
975 Actual
:= First
(Actuals
);
976 while Present
(Actual
) loop
977 case Nkind
(Actual
) is
978 when N_Parameter_Association
=>
980 Check_SPARK_05_Restriction
981 ("named association cannot follow positional one",
992 end Check_Mixed_Parameter_And_Named_Associations
;
994 ----------------------------
995 -- Check_Writable_Actuals --
996 ----------------------------
998 -- The identification of conflicts in calls to functions with writable
999 -- actuals is performed in the analysis phase of the front end to ensure
1000 -- that it reports exactly the same errors compiling with and without
1001 -- expansion enabled. It is performed in two stages:
1003 -- 1) When a call to a function with out-mode parameters is found,
1004 -- we climb to the outermost enclosing construct that can be
1005 -- evaluated in arbitrary order and we mark it with the flag
1008 -- 2) When the analysis of the marked node is complete, we traverse
1009 -- its decorated subtree searching for conflicts (see function
1010 -- Sem_Util.Check_Function_Writable_Actuals).
1012 -- The unique exception to this general rule is for aggregates, since
1013 -- their analysis is performed by the front end in the resolution
1014 -- phase. For aggregates we do not climb to their enclosing construct:
1015 -- we restrict the analysis to the subexpressions initializing the
1016 -- aggregate components.
1018 -- This implies that the analysis of expressions containing aggregates
1019 -- is not complete, since there may be conflicts on writable actuals
1020 -- involving subexpressions of the enclosing logical or arithmetic
1021 -- expressions. However, we cannot wait and perform the analysis when
1022 -- the whole subtree is resolved, since the subtrees may be transformed,
1023 -- thus adding extra complexity and computation cost to identify and
1024 -- report exactly the same errors compiling with and without expansion
1027 procedure Check_Writable_Actuals
(N
: Node_Id
) is
1029 if Comes_From_Source
(N
)
1030 and then Present
(Get_Subprogram_Entity
(N
))
1031 and then Has_Out_Or_In_Out_Parameter
(Get_Subprogram_Entity
(N
))
1033 -- For procedures and entries there is no need to climb since
1034 -- we only need to check if the actuals of this call invoke
1035 -- functions whose out-mode parameters overlap.
1037 if Nkind
(N
) /= N_Function_Call
then
1038 Set_Check_Actuals
(N
);
1040 -- For calls to functions we climb to the outermost enclosing
1041 -- construct where the out-mode actuals of this function may
1042 -- introduce conflicts.
1046 Outermost
: Node_Id
;
1050 while Present
(P
) loop
1052 -- For object declarations we can climb to the node from
1053 -- its object definition branch or from its initializing
1054 -- expression. We prefer to mark the child node as the
1055 -- outermost construct to avoid adding further complexity
1056 -- to the routine that will later take care of
1057 -- performing the writable actuals check.
1059 if Has_Arbitrary_Evaluation_Order
(Nkind
(P
))
1060 and then not Nkind_In
(P
, N_Assignment_Statement
,
1061 N_Object_Declaration
)
1066 -- Avoid climbing more than needed!
1068 exit when Stop_Subtree_Climbing
(Nkind
(P
))
1069 or else (Nkind
(P
) = N_Range
1071 Nkind_In
(Parent
(P
), N_In
, N_Not_In
));
1076 Set_Check_Actuals
(Outermost
);
1080 end Check_Writable_Actuals
;
1082 ---------------------------
1083 -- Name_Denotes_Function --
1084 ---------------------------
1086 function Name_Denotes_Function
return Boolean is
1088 if Is_Entity_Name
(Nam
) then
1089 return Ekind
(Entity
(Nam
)) = E_Function
;
1090 elsif Nkind
(Nam
) = N_Selected_Component
then
1091 return Ekind
(Entity
(Selector_Name
(Nam
))) = E_Function
;
1095 end Name_Denotes_Function
;
1097 -----------------------
1098 -- No_Interpretation --
1099 -----------------------
1101 procedure No_Interpretation
is
1102 L
: constant Boolean := Is_List_Member
(N
);
1103 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
1106 -- If the node is in a list whose parent is not an expression then it
1107 -- must be an attempted procedure call.
1109 if L
and then K
not in N_Subexpr
then
1110 if Ekind
(Entity
(Nam
)) = E_Generic_Procedure
then
1112 ("must instantiate generic procedure& before call",
1115 Error_Msg_N
("procedure or entry name expected", Nam
);
1118 -- Check for tasking cases where only an entry call will do
1121 and then Nkind_In
(K
, N_Entry_Call_Alternative
,
1122 N_Triggering_Alternative
)
1124 Error_Msg_N
("entry name expected", Nam
);
1126 -- Otherwise give general error message
1129 Error_Msg_N
("invalid prefix in call", Nam
);
1131 end No_Interpretation
;
1133 -- Start of processing for Analyze_Call
1136 if Restriction_Check_Required
(SPARK_05
) then
1137 Check_Mixed_Parameter_And_Named_Associations
;
1140 -- Initialize the type of the result of the call to the error type,
1141 -- which will be reset if the type is successfully resolved.
1143 Set_Etype
(N
, Any_Type
);
1147 if not Is_Overloaded
(Nam
) then
1149 -- Only one interpretation to check
1151 if Ekind
(Etype
(Nam
)) = E_Subprogram_Type
then
1152 Nam_Ent
:= Etype
(Nam
);
1154 -- If the prefix is an access_to_subprogram, this may be an indirect
1155 -- call. This is the case if the name in the call is not an entity
1156 -- name, or if it is a function name in the context of a procedure
1157 -- call. In this latter case, we have a call to a parameterless
1158 -- function that returns a pointer_to_procedure which is the entity
1159 -- being called. Finally, F (X) may be a call to a parameterless
1160 -- function that returns a pointer to a function with parameters.
1161 -- Note that if F returns an access-to-subprogram whose designated
1162 -- type is an array, F (X) cannot be interpreted as an indirect call
1163 -- through the result of the call to F.
1165 elsif Is_Access_Type
(Etype
(Nam
))
1166 and then Ekind
(Designated_Type
(Etype
(Nam
))) = E_Subprogram_Type
1168 (not Name_Denotes_Function
1169 or else Nkind
(N
) = N_Procedure_Call_Statement
1171 (Nkind
(Parent
(N
)) /= N_Explicit_Dereference
1172 and then Is_Entity_Name
(Nam
)
1173 and then No
(First_Formal
(Entity
(Nam
)))
1175 Is_Array_Type
(Etype
(Designated_Type
(Etype
(Nam
))))
1176 and then Present
(Actuals
)))
1178 Nam_Ent
:= Designated_Type
(Etype
(Nam
));
1179 Insert_Explicit_Dereference
(Nam
);
1181 -- Selected component case. Simple entry or protected operation,
1182 -- where the entry name is given by the selector name.
1184 elsif Nkind
(Nam
) = N_Selected_Component
then
1185 Nam_Ent
:= Entity
(Selector_Name
(Nam
));
1187 if not Ekind_In
(Nam_Ent
, E_Entry
,
1192 Error_Msg_N
("name in call is not a callable entity", Nam
);
1193 Set_Etype
(N
, Any_Type
);
1197 -- If the name is an Indexed component, it can be a call to a member
1198 -- of an entry family. The prefix must be a selected component whose
1199 -- selector is the entry. Analyze_Procedure_Call normalizes several
1200 -- kinds of call into this form.
1202 elsif Nkind
(Nam
) = N_Indexed_Component
then
1203 if Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
1204 Nam_Ent
:= Entity
(Selector_Name
(Prefix
(Nam
)));
1206 Error_Msg_N
("name in call is not a callable entity", Nam
);
1207 Set_Etype
(N
, Any_Type
);
1211 elsif not Is_Entity_Name
(Nam
) then
1212 Error_Msg_N
("name in call is not a callable entity", Nam
);
1213 Set_Etype
(N
, Any_Type
);
1217 Nam_Ent
:= Entity
(Nam
);
1219 -- If not overloadable, this may be a generalized indexing
1220 -- operation with named associations. Rewrite again as an
1221 -- indexed component and analyze as container indexing.
1223 if not Is_Overloadable
(Nam_Ent
) then
1225 (Find_Value_Of_Aspect
1226 (Etype
(Nam_Ent
), Aspect_Constant_Indexing
))
1229 Make_Indexed_Component
(Sloc
(N
),
1231 Expressions
=> Parameter_Associations
(N
)));
1233 if Try_Container_Indexing
(N
, Nam
, Expressions
(N
)) then
1247 -- Operations generated for RACW stub types are called only through
1248 -- dispatching, and can never be the static interpretation of a call.
1250 if Is_RACW_Stub_Type_Operation
(Nam_Ent
) then
1255 Analyze_One_Call
(N
, Nam_Ent
, True, Success
);
1257 -- If this is an indirect call, the return type of the access_to
1258 -- subprogram may be an incomplete type. At the point of the call,
1259 -- use the full type if available, and at the same time update the
1260 -- return type of the access_to_subprogram.
1263 and then Nkind
(Nam
) = N_Explicit_Dereference
1264 and then Ekind
(Etype
(N
)) = E_Incomplete_Type
1265 and then Present
(Full_View
(Etype
(N
)))
1267 Set_Etype
(N
, Full_View
(Etype
(N
)));
1268 Set_Etype
(Nam_Ent
, Etype
(N
));
1274 -- An overloaded selected component must denote overloaded operations
1275 -- of a concurrent type. The interpretations are attached to the
1276 -- simple name of those operations.
1278 if Nkind
(Nam
) = N_Selected_Component
then
1279 Nam
:= Selector_Name
(Nam
);
1282 Get_First_Interp
(Nam
, X
, It
);
1283 while Present
(It
.Nam
) loop
1287 -- Name may be call that returns an access to subprogram, or more
1288 -- generally an overloaded expression one of whose interpretations
1289 -- yields an access to subprogram. If the name is an entity, we do
1290 -- not dereference, because the node is a call that returns the
1291 -- access type: note difference between f(x), where the call may
1292 -- return an access subprogram type, and f(x)(y), where the type
1293 -- returned by the call to f is implicitly dereferenced to analyze
1296 if Is_Access_Type
(Nam_Ent
) then
1297 Nam_Ent
:= Designated_Type
(Nam_Ent
);
1299 elsif Is_Access_Type
(Etype
(Nam_Ent
))
1301 (not Is_Entity_Name
(Nam
)
1302 or else Nkind
(N
) = N_Procedure_Call_Statement
)
1303 and then Ekind
(Designated_Type
(Etype
(Nam_Ent
)))
1306 Nam_Ent
:= Designated_Type
(Etype
(Nam_Ent
));
1308 if Is_Entity_Name
(Nam
) then
1313 -- If the call has been rewritten from a prefixed call, the first
1314 -- parameter has been analyzed, but may need a subsequent
1315 -- dereference, so skip its analysis now.
1317 if N
/= Original_Node
(N
)
1318 and then Nkind
(Original_Node
(N
)) = Nkind
(N
)
1319 and then Nkind
(Name
(N
)) /= Nkind
(Name
(Original_Node
(N
)))
1320 and then Present
(Parameter_Associations
(N
))
1321 and then Present
(Etype
(First
(Parameter_Associations
(N
))))
1324 (N
, Nam_Ent
, False, Success
, Skip_First
=> True);
1326 Analyze_One_Call
(N
, Nam_Ent
, False, Success
);
1329 -- If the interpretation succeeds, mark the proper type of the
1330 -- prefix (any valid candidate will do). If not, remove the
1331 -- candidate interpretation. If this is a parameterless call
1332 -- on an anonymous access to subprogram, X is a variable with
1333 -- an access discriminant D, the entity in the interpretation is
1334 -- D, so rewrite X as X.D.all.
1338 and then Nkind
(Parent
(N
)) /= N_Explicit_Dereference
1340 if Ekind
(It
.Nam
) = E_Discriminant
1341 and then Has_Implicit_Dereference
(It
.Nam
)
1344 Make_Explicit_Dereference
(Loc
,
1346 Make_Selected_Component
(Loc
,
1348 New_Occurrence_Of
(Entity
(Nam
), Loc
),
1350 New_Occurrence_Of
(It
.Nam
, Loc
))));
1356 Set_Entity
(Nam
, It
.Nam
);
1357 Insert_Explicit_Dereference
(Nam
);
1358 Set_Etype
(Nam
, Nam_Ent
);
1362 Set_Etype
(Nam
, It
.Typ
);
1365 elsif Nkind_In
(Name
(N
), N_Function_Call
, N_Selected_Component
)
1370 Get_Next_Interp
(X
, It
);
1373 -- If the name is the result of a function call, it can only be a
1374 -- call to a function returning an access to subprogram. Insert
1375 -- explicit dereference.
1377 if Nkind
(Nam
) = N_Function_Call
then
1378 Insert_Explicit_Dereference
(Nam
);
1381 if Etype
(N
) = Any_Type
then
1383 -- None of the interpretations is compatible with the actuals
1385 Diagnose_Call
(N
, Nam
);
1387 -- Special checks for uninstantiated put routines
1389 if Nkind
(N
) = N_Procedure_Call_Statement
1390 and then Is_Entity_Name
(Nam
)
1391 and then Chars
(Nam
) = Name_Put
1392 and then List_Length
(Actuals
) = 1
1395 Arg
: constant Node_Id
:= First
(Actuals
);
1399 if Nkind
(Arg
) = N_Parameter_Association
then
1400 Typ
:= Etype
(Explicit_Actual_Parameter
(Arg
));
1405 if Is_Signed_Integer_Type
(Typ
) then
1407 ("possible missing instantiation of "
1408 & "'Text_'I'O.'Integer_'I'O!", Nam
);
1410 elsif Is_Modular_Integer_Type
(Typ
) then
1412 ("possible missing instantiation of "
1413 & "'Text_'I'O.'Modular_'I'O!", Nam
);
1415 elsif Is_Floating_Point_Type
(Typ
) then
1417 ("possible missing instantiation of "
1418 & "'Text_'I'O.'Float_'I'O!", Nam
);
1420 elsif Is_Ordinary_Fixed_Point_Type
(Typ
) then
1422 ("possible missing instantiation of "
1423 & "'Text_'I'O.'Fixed_'I'O!", Nam
);
1425 elsif Is_Decimal_Fixed_Point_Type
(Typ
) then
1427 ("possible missing instantiation of "
1428 & "'Text_'I'O.'Decimal_'I'O!", Nam
);
1430 elsif Is_Enumeration_Type
(Typ
) then
1432 ("possible missing instantiation of "
1433 & "'Text_'I'O.'Enumeration_'I'O!", Nam
);
1438 elsif not Is_Overloaded
(N
)
1439 and then Is_Entity_Name
(Nam
)
1441 -- Resolution yields a single interpretation. Verify that the
1442 -- reference has capitalization consistent with the declaration.
1444 Set_Entity_With_Checks
(Nam
, Entity
(Nam
));
1445 Generate_Reference
(Entity
(Nam
), Nam
);
1447 Set_Etype
(Nam
, Etype
(Entity
(Nam
)));
1449 Remove_Abstract_Operations
(N
);
1455 if Ada_Version
>= Ada_2012
then
1457 -- Check if the call contains a function with writable actuals
1459 Check_Writable_Actuals
(N
);
1461 -- If found and the outermost construct that can be evaluated in
1462 -- an arbitrary order is precisely this call, then check all its
1465 Check_Function_Writable_Actuals
(N
);
1469 -----------------------------
1470 -- Analyze_Case_Expression --
1471 -----------------------------
1473 procedure Analyze_Case_Expression
(N
: Node_Id
) is
1474 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
1475 -- Error routine invoked by the generic instantiation below when
1476 -- the case expression has a non static choice.
1478 package Case_Choices_Analysis
is new
1479 Generic_Analyze_Choices
1480 (Process_Associated_Node
=> No_OP
);
1481 use Case_Choices_Analysis
;
1483 package Case_Choices_Checking
is new
1484 Generic_Check_Choices
1485 (Process_Empty_Choice
=> No_OP
,
1486 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
1487 Process_Associated_Node
=> No_OP
);
1488 use Case_Choices_Checking
;
1490 -----------------------------
1491 -- Non_Static_Choice_Error --
1492 -----------------------------
1494 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
1496 Flag_Non_Static_Expr
1497 ("choice given in case expression is not static!", Choice
);
1498 end Non_Static_Choice_Error
;
1502 Expr
: constant Node_Id
:= Expression
(N
);
1504 Exp_Type
: Entity_Id
;
1505 Exp_Btype
: Entity_Id
;
1507 FirstX
: Node_Id
:= Empty
;
1508 -- First expression in the case for which there is some type information
1509 -- available, i.e. it is not Any_Type, which can happen because of some
1510 -- error, or from the use of e.g. raise Constraint_Error.
1512 Others_Present
: Boolean;
1513 -- Indicates if Others was present
1515 Wrong_Alt
: Node_Id
:= Empty
;
1516 -- For error reporting
1518 -- Start of processing for Analyze_Case_Expression
1521 if Comes_From_Source
(N
) then
1522 Check_Compiler_Unit
("case expression", N
);
1525 Analyze_And_Resolve
(Expr
, Any_Discrete
);
1526 Check_Unset_Reference
(Expr
);
1527 Exp_Type
:= Etype
(Expr
);
1528 Exp_Btype
:= Base_Type
(Exp_Type
);
1530 Alt
:= First
(Alternatives
(N
));
1531 while Present
(Alt
) loop
1532 Analyze
(Expression
(Alt
));
1534 if No
(FirstX
) and then Etype
(Expression
(Alt
)) /= Any_Type
then
1535 FirstX
:= Expression
(Alt
);
1541 -- Get our initial type from the first expression for which we got some
1542 -- useful type information from the expression.
1544 if not Is_Overloaded
(FirstX
) then
1545 Set_Etype
(N
, Etype
(FirstX
));
1553 Set_Etype
(N
, Any_Type
);
1555 Get_First_Interp
(FirstX
, I
, It
);
1556 while Present
(It
.Nam
) loop
1558 -- For each interpretation of the first expression, we only
1559 -- add the interpretation if every other expression in the
1560 -- case expression alternatives has a compatible type.
1562 Alt
:= Next
(First
(Alternatives
(N
)));
1563 while Present
(Alt
) loop
1564 exit when not Has_Compatible_Type
(Expression
(Alt
), It
.Typ
);
1569 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
1574 Get_Next_Interp
(I
, It
);
1579 Exp_Btype
:= Base_Type
(Exp_Type
);
1581 -- The expression must be of a discrete type which must be determinable
1582 -- independently of the context in which the expression occurs, but
1583 -- using the fact that the expression must be of a discrete type.
1584 -- Moreover, the type this expression must not be a character literal
1585 -- (which is always ambiguous).
1587 -- If error already reported by Resolve, nothing more to do
1589 if Exp_Btype
= Any_Discrete
or else Exp_Btype
= Any_Type
then
1592 -- Special casee message for character literal
1594 elsif Exp_Btype
= Any_Character
then
1596 ("character literal as case expression is ambiguous", Expr
);
1600 if Etype
(N
) = Any_Type
and then Present
(Wrong_Alt
) then
1602 ("type incompatible with that of previous alternatives",
1603 Expression
(Wrong_Alt
));
1607 -- If the case expression is a formal object of mode in out, then
1608 -- treat it as having a nonstatic subtype by forcing use of the base
1609 -- type (which has to get passed to Check_Case_Choices below). Also
1610 -- use base type when the case expression is parenthesized.
1612 if Paren_Count
(Expr
) > 0
1613 or else (Is_Entity_Name
(Expr
)
1614 and then Ekind
(Entity
(Expr
)) = E_Generic_In_Out_Parameter
)
1616 Exp_Type
:= Exp_Btype
;
1619 -- The case expression alternatives cover the range of a static subtype
1620 -- subject to aspect Static_Predicate. Do not check the choices when the
1621 -- case expression has not been fully analyzed yet because this may lead
1624 if Is_OK_Static_Subtype
(Exp_Type
)
1625 and then Has_Static_Predicate_Aspect
(Exp_Type
)
1626 and then In_Spec_Expression
1630 -- Call Analyze_Choices and Check_Choices to do the rest of the work
1633 Analyze_Choices
(Alternatives
(N
), Exp_Type
);
1634 Check_Choices
(N
, Alternatives
(N
), Exp_Type
, Others_Present
);
1637 if Exp_Type
= Universal_Integer
and then not Others_Present
then
1639 ("case on universal integer requires OTHERS choice", Expr
);
1641 end Analyze_Case_Expression
;
1643 ---------------------------
1644 -- Analyze_Comparison_Op --
1645 ---------------------------
1647 procedure Analyze_Comparison_Op
(N
: Node_Id
) is
1648 L
: constant Node_Id
:= Left_Opnd
(N
);
1649 R
: constant Node_Id
:= Right_Opnd
(N
);
1650 Op_Id
: Entity_Id
:= Entity
(N
);
1653 Set_Etype
(N
, Any_Type
);
1654 Candidate_Type
:= Empty
;
1656 Analyze_Expression
(L
);
1657 Analyze_Expression
(R
);
1659 if Present
(Op_Id
) then
1660 if Ekind
(Op_Id
) = E_Operator
then
1661 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1663 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1666 if Is_Overloaded
(L
) then
1667 Set_Etype
(L
, Intersect_Types
(L
, R
));
1671 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1672 while Present
(Op_Id
) loop
1673 if Ekind
(Op_Id
) = E_Operator
then
1674 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1676 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1679 Op_Id
:= Homonym
(Op_Id
);
1684 Check_Function_Writable_Actuals
(N
);
1685 end Analyze_Comparison_Op
;
1687 ---------------------------
1688 -- Analyze_Concatenation --
1689 ---------------------------
1691 procedure Analyze_Concatenation
(N
: Node_Id
) is
1693 -- We wish to avoid deep recursion, because concatenations are often
1694 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1695 -- operands nonrecursively until we find something that is not a
1696 -- concatenation (A in this case), or has already been analyzed. We
1697 -- analyze that, and then walk back up the tree following Parent
1698 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1699 -- work at each level. The Parent pointers allow us to avoid recursion,
1700 -- and thus avoid running out of memory.
1706 Candidate_Type
:= Empty
;
1708 -- The following code is equivalent to:
1710 -- Set_Etype (N, Any_Type);
1711 -- Analyze_Expression (Left_Opnd (N));
1712 -- Analyze_Concatenation_Rest (N);
1714 -- where the Analyze_Expression call recurses back here if the left
1715 -- operand is a concatenation.
1717 -- Walk down left operands
1720 Set_Etype
(NN
, Any_Type
);
1721 L
:= Left_Opnd
(NN
);
1722 exit when Nkind
(L
) /= N_Op_Concat
or else Analyzed
(L
);
1726 -- Now (given the above example) NN is A&B and L is A
1728 -- First analyze L ...
1730 Analyze_Expression
(L
);
1732 -- ... then walk NN back up until we reach N (where we started), calling
1733 -- Analyze_Concatenation_Rest along the way.
1736 Analyze_Concatenation_Rest
(NN
);
1740 end Analyze_Concatenation
;
1742 --------------------------------
1743 -- Analyze_Concatenation_Rest --
1744 --------------------------------
1746 -- If the only one-dimensional array type in scope is String,
1747 -- this is the resulting type of the operation. Otherwise there
1748 -- will be a concatenation operation defined for each user-defined
1749 -- one-dimensional array.
1751 procedure Analyze_Concatenation_Rest
(N
: Node_Id
) is
1752 L
: constant Node_Id
:= Left_Opnd
(N
);
1753 R
: constant Node_Id
:= Right_Opnd
(N
);
1754 Op_Id
: Entity_Id
:= Entity
(N
);
1759 Analyze_Expression
(R
);
1761 -- If the entity is present, the node appears in an instance, and
1762 -- denotes a predefined concatenation operation. The resulting type is
1763 -- obtained from the arguments when possible. If the arguments are
1764 -- aggregates, the array type and the concatenation type must be
1767 if Present
(Op_Id
) then
1768 if Ekind
(Op_Id
) = E_Operator
then
1769 LT
:= Base_Type
(Etype
(L
));
1770 RT
:= Base_Type
(Etype
(R
));
1772 if Is_Array_Type
(LT
)
1773 and then (RT
= LT
or else RT
= Base_Type
(Component_Type
(LT
)))
1775 Add_One_Interp
(N
, Op_Id
, LT
);
1777 elsif Is_Array_Type
(RT
)
1778 and then LT
= Base_Type
(Component_Type
(RT
))
1780 Add_One_Interp
(N
, Op_Id
, RT
);
1782 -- If one operand is a string type or a user-defined array type,
1783 -- and the other is a literal, result is of the specific type.
1786 (Root_Type
(LT
) = Standard_String
1787 or else Scope
(LT
) /= Standard_Standard
)
1788 and then Etype
(R
) = Any_String
1790 Add_One_Interp
(N
, Op_Id
, LT
);
1793 (Root_Type
(RT
) = Standard_String
1794 or else Scope
(RT
) /= Standard_Standard
)
1795 and then Etype
(L
) = Any_String
1797 Add_One_Interp
(N
, Op_Id
, RT
);
1799 elsif not Is_Generic_Type
(Etype
(Op_Id
)) then
1800 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1803 -- Type and its operations must be visible
1805 Set_Entity
(N
, Empty
);
1806 Analyze_Concatenation
(N
);
1810 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1814 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Concat
);
1815 while Present
(Op_Id
) loop
1816 if Ekind
(Op_Id
) = E_Operator
then
1818 -- Do not consider operators declared in dead code, they can
1819 -- not be part of the resolution.
1821 if Is_Eliminated
(Op_Id
) then
1824 Find_Concatenation_Types
(L
, R
, Op_Id
, N
);
1828 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1831 Op_Id
:= Homonym
(Op_Id
);
1836 end Analyze_Concatenation_Rest
;
1838 -------------------------
1839 -- Analyze_Equality_Op --
1840 -------------------------
1842 procedure Analyze_Equality_Op
(N
: Node_Id
) is
1843 Loc
: constant Source_Ptr
:= Sloc
(N
);
1844 L
: constant Node_Id
:= Left_Opnd
(N
);
1845 R
: constant Node_Id
:= Right_Opnd
(N
);
1849 Set_Etype
(N
, Any_Type
);
1850 Candidate_Type
:= Empty
;
1852 Analyze_Expression
(L
);
1853 Analyze_Expression
(R
);
1855 -- If the entity is set, the node is a generic instance with a non-local
1856 -- reference to the predefined operator or to a user-defined function.
1857 -- It can also be an inequality that is expanded into the negation of a
1858 -- call to a user-defined equality operator.
1860 -- For the predefined case, the result is Boolean, regardless of the
1861 -- type of the operands. The operands may even be limited, if they are
1862 -- generic actuals. If they are overloaded, label the left argument with
1863 -- the common type that must be present, or with the type of the formal
1864 -- of the user-defined function.
1866 if Present
(Entity
(N
)) then
1867 Op_Id
:= Entity
(N
);
1869 if Ekind
(Op_Id
) = E_Operator
then
1870 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
);
1872 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1875 if Is_Overloaded
(L
) then
1876 if Ekind
(Op_Id
) = E_Operator
then
1877 Set_Etype
(L
, Intersect_Types
(L
, R
));
1879 Set_Etype
(L
, Etype
(First_Formal
(Op_Id
)));
1884 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1885 while Present
(Op_Id
) loop
1886 if Ekind
(Op_Id
) = E_Operator
then
1887 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1889 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1892 Op_Id
:= Homonym
(Op_Id
);
1896 -- If there was no match, and the operator is inequality, this may be
1897 -- a case where inequality has not been made explicit, as for tagged
1898 -- types. Analyze the node as the negation of an equality operation.
1899 -- This cannot be done earlier, because before analysis we cannot rule
1900 -- out the presence of an explicit inequality.
1902 if Etype
(N
) = Any_Type
1903 and then Nkind
(N
) = N_Op_Ne
1905 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Eq
);
1906 while Present
(Op_Id
) loop
1907 if Ekind
(Op_Id
) = E_Operator
then
1908 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1910 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1913 Op_Id
:= Homonym
(Op_Id
);
1916 if Etype
(N
) /= Any_Type
then
1917 Op_Id
:= Entity
(N
);
1923 Left_Opnd
=> Left_Opnd
(N
),
1924 Right_Opnd
=> Right_Opnd
(N
))));
1926 Set_Entity
(Right_Opnd
(N
), Op_Id
);
1932 Check_Function_Writable_Actuals
(N
);
1933 end Analyze_Equality_Op
;
1935 ----------------------------------
1936 -- Analyze_Explicit_Dereference --
1937 ----------------------------------
1939 procedure Analyze_Explicit_Dereference
(N
: Node_Id
) is
1940 Loc
: constant Source_Ptr
:= Sloc
(N
);
1941 P
: constant Node_Id
:= Prefix
(N
);
1947 function Is_Function_Type
return Boolean;
1948 -- Check whether node may be interpreted as an implicit function call
1950 ----------------------
1951 -- Is_Function_Type --
1952 ----------------------
1954 function Is_Function_Type
return Boolean is
1959 if not Is_Overloaded
(N
) then
1960 return Ekind
(Base_Type
(Etype
(N
))) = E_Subprogram_Type
1961 and then Etype
(Base_Type
(Etype
(N
))) /= Standard_Void_Type
;
1964 Get_First_Interp
(N
, I
, It
);
1965 while Present
(It
.Nam
) loop
1966 if Ekind
(Base_Type
(It
.Typ
)) /= E_Subprogram_Type
1967 or else Etype
(Base_Type
(It
.Typ
)) = Standard_Void_Type
1972 Get_Next_Interp
(I
, It
);
1977 end Is_Function_Type
;
1979 -- Start of processing for Analyze_Explicit_Dereference
1982 -- If source node, check SPARK restriction. We guard this with the
1983 -- source node check, because ???
1985 if Comes_From_Source
(N
) then
1986 Check_SPARK_05_Restriction
("explicit dereference is not allowed", N
);
1989 -- In formal verification mode, keep track of all reads and writes
1990 -- through explicit dereferences.
1992 if GNATprove_Mode
then
1993 SPARK_Specific
.Generate_Dereference
(N
);
1997 Set_Etype
(N
, Any_Type
);
1999 -- Test for remote access to subprogram type, and if so return
2000 -- after rewriting the original tree.
2002 if Remote_AST_E_Dereference
(P
) then
2006 -- Normal processing for other than remote access to subprogram type
2008 if not Is_Overloaded
(P
) then
2009 if Is_Access_Type
(Etype
(P
)) then
2011 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
2012 -- avoid other problems caused by the Private_Subtype and it is
2013 -- safe to go to the Base_Type because this is the same as
2014 -- converting the access value to its Base_Type.
2017 DT
: Entity_Id
:= Designated_Type
(Etype
(P
));
2020 if Ekind
(DT
) = E_Private_Subtype
2021 and then Is_For_Access_Subtype
(DT
)
2023 DT
:= Base_Type
(DT
);
2026 -- An explicit dereference is a legal occurrence of an
2027 -- incomplete type imported through a limited_with clause, if
2028 -- the full view is visible, or if we are within an instance
2029 -- body, where the enclosing body has a regular with_clause
2032 if From_Limited_With
(DT
)
2033 and then not From_Limited_With
(Scope
(DT
))
2035 (Is_Immediately_Visible
(Scope
(DT
))
2037 (Is_Child_Unit
(Scope
(DT
))
2038 and then Is_Visible_Lib_Unit
(Scope
(DT
)))
2039 or else In_Instance_Body
)
2041 Set_Etype
(N
, Available_View
(DT
));
2048 elsif Etype
(P
) /= Any_Type
then
2049 Error_Msg_N
("prefix of dereference must be an access type", N
);
2054 Get_First_Interp
(P
, I
, It
);
2055 while Present
(It
.Nam
) loop
2058 if Is_Access_Type
(T
) then
2059 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
2062 Get_Next_Interp
(I
, It
);
2065 -- Error if no interpretation of the prefix has an access type
2067 if Etype
(N
) = Any_Type
then
2069 ("access type required in prefix of explicit dereference", P
);
2070 Set_Etype
(N
, Any_Type
);
2076 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
2078 and then (Nkind
(Parent
(N
)) /= N_Function_Call
2079 or else N
/= Name
(Parent
(N
)))
2081 and then (Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
2082 or else N
/= Name
(Parent
(N
)))
2084 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
2085 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
2087 (Attribute_Name
(Parent
(N
)) /= Name_Address
2089 Attribute_Name
(Parent
(N
)) /= Name_Access
))
2091 -- Name is a function call with no actuals, in a context that
2092 -- requires deproceduring (including as an actual in an enclosing
2093 -- function or procedure call). There are some pathological cases
2094 -- where the prefix might include functions that return access to
2095 -- subprograms and others that return a regular type. Disambiguation
2096 -- of those has to take place in Resolve.
2099 Make_Function_Call
(Loc
,
2100 Name
=> Make_Explicit_Dereference
(Loc
, P
),
2101 Parameter_Associations
=> New_List
);
2103 -- If the prefix is overloaded, remove operations that have formals,
2104 -- we know that this is a parameterless call.
2106 if Is_Overloaded
(P
) then
2107 Get_First_Interp
(P
, I
, It
);
2108 while Present
(It
.Nam
) loop
2111 if No
(First_Formal
(Base_Type
(Designated_Type
(T
)))) then
2117 Get_Next_Interp
(I
, It
);
2124 elsif not Is_Function_Type
2125 and then Is_Overloaded
(N
)
2127 -- The prefix may include access to subprograms and other access
2128 -- types. If the context selects the interpretation that is a
2129 -- function call (not a procedure call) we cannot rewrite the node
2130 -- yet, but we include the result of the call interpretation.
2132 Get_First_Interp
(N
, I
, It
);
2133 while Present
(It
.Nam
) loop
2134 if Ekind
(Base_Type
(It
.Typ
)) = E_Subprogram_Type
2135 and then Etype
(Base_Type
(It
.Typ
)) /= Standard_Void_Type
2136 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
2138 Add_One_Interp
(N
, Etype
(It
.Typ
), Etype
(It
.Typ
));
2141 Get_Next_Interp
(I
, It
);
2145 -- A value of remote access-to-class-wide must not be dereferenced
2148 Validate_Remote_Access_To_Class_Wide_Type
(N
);
2149 end Analyze_Explicit_Dereference
;
2151 ------------------------
2152 -- Analyze_Expression --
2153 ------------------------
2155 procedure Analyze_Expression
(N
: Node_Id
) is
2158 -- If the expression is an indexed component that will be rewritten
2159 -- as a container indexing, it has already been analyzed.
2161 if Nkind
(N
) = N_Indexed_Component
2162 and then Present
(Generalized_Indexing
(N
))
2168 Check_Parameterless_Call
(N
);
2170 end Analyze_Expression
;
2172 -------------------------------------
2173 -- Analyze_Expression_With_Actions --
2174 -------------------------------------
2176 procedure Analyze_Expression_With_Actions
(N
: Node_Id
) is
2180 A
:= First
(Actions
(N
));
2181 while Present
(A
) loop
2186 Analyze_Expression
(Expression
(N
));
2187 Set_Etype
(N
, Etype
(Expression
(N
)));
2188 end Analyze_Expression_With_Actions
;
2190 ---------------------------
2191 -- Analyze_If_Expression --
2192 ---------------------------
2194 procedure Analyze_If_Expression
(N
: Node_Id
) is
2195 Condition
: constant Node_Id
:= First
(Expressions
(N
));
2196 Then_Expr
: constant Node_Id
:= Next
(Condition
);
2197 Else_Expr
: Node_Id
;
2200 -- Defend against error of missing expressions from previous error
2202 if No
(Then_Expr
) then
2203 Check_Error_Detected
;
2207 if Comes_From_Source
(N
) then
2208 Check_SPARK_05_Restriction
("if expression is not allowed", N
);
2211 Else_Expr
:= Next
(Then_Expr
);
2213 if Comes_From_Source
(N
) then
2214 Check_Compiler_Unit
("if expression", N
);
2217 -- Analyze and resolve the condition. We need to resolve this now so
2218 -- that it gets folded to True/False if possible, before we analyze
2219 -- the THEN/ELSE branches, because when analyzing these branches, we
2220 -- may call Is_Statically_Unevaluated, which expects the condition of
2221 -- an enclosing IF to have been analyze/resolved/evaluated.
2223 Analyze_Expression
(Condition
);
2224 Resolve
(Condition
, Any_Boolean
);
2226 -- Analyze THEN expression and (if present) ELSE expression. For those
2227 -- we delay resolution in the normal manner, because of overloading etc.
2229 Analyze_Expression
(Then_Expr
);
2231 if Present
(Else_Expr
) then
2232 Analyze_Expression
(Else_Expr
);
2235 -- If then expression not overloaded, then that decides the type
2237 if not Is_Overloaded
(Then_Expr
) then
2238 Set_Etype
(N
, Etype
(Then_Expr
));
2240 -- Case where then expression is overloaded
2248 Set_Etype
(N
, Any_Type
);
2250 -- Loop through interpretations of Then_Expr
2252 Get_First_Interp
(Then_Expr
, I
, It
);
2253 while Present
(It
.Nam
) loop
2255 -- Add possible interpretation of Then_Expr if no Else_Expr, or
2256 -- Else_Expr is present and has a compatible type.
2259 or else Has_Compatible_Type
(Else_Expr
, It
.Typ
)
2261 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
2264 Get_Next_Interp
(I
, It
);
2267 -- If no valid interpretation has been found, then the type of the
2268 -- ELSE expression does not match any interpretation of the THEN
2271 if Etype
(N
) = Any_Type
then
2273 ("type incompatible with that of `THEN` expression",
2279 end Analyze_If_Expression
;
2281 ------------------------------------
2282 -- Analyze_Indexed_Component_Form --
2283 ------------------------------------
2285 procedure Analyze_Indexed_Component_Form
(N
: Node_Id
) is
2286 P
: constant Node_Id
:= Prefix
(N
);
2287 Exprs
: constant List_Id
:= Expressions
(N
);
2293 procedure Process_Function_Call
;
2294 -- Prefix in indexed component form is an overloadable entity, so the
2295 -- node is a function call. Reformat it as such.
2297 procedure Process_Indexed_Component
;
2298 -- Prefix in indexed component form is actually an indexed component.
2299 -- This routine processes it, knowing that the prefix is already
2302 procedure Process_Indexed_Component_Or_Slice
;
2303 -- An indexed component with a single index may designate a slice if
2304 -- the index is a subtype mark. This routine disambiguates these two
2305 -- cases by resolving the prefix to see if it is a subtype mark.
2307 procedure Process_Overloaded_Indexed_Component
;
2308 -- If the prefix of an indexed component is overloaded, the proper
2309 -- interpretation is selected by the index types and the context.
2311 ---------------------------
2312 -- Process_Function_Call --
2313 ---------------------------
2315 procedure Process_Function_Call
is
2316 Loc
: constant Source_Ptr
:= Sloc
(N
);
2320 Change_Node
(N
, N_Function_Call
);
2322 Set_Parameter_Associations
(N
, Exprs
);
2324 -- Analyze actuals prior to analyzing the call itself
2326 Actual
:= First
(Parameter_Associations
(N
));
2327 while Present
(Actual
) loop
2329 Check_Parameterless_Call
(Actual
);
2331 -- Move to next actual. Note that we use Next, not Next_Actual
2332 -- here. The reason for this is a bit subtle. If a function call
2333 -- includes named associations, the parser recognizes the node
2334 -- as a call, and it is analyzed as such. If all associations are
2335 -- positional, the parser builds an indexed_component node, and
2336 -- it is only after analysis of the prefix that the construct
2337 -- is recognized as a call, in which case Process_Function_Call
2338 -- rewrites the node and analyzes the actuals. If the list of
2339 -- actuals is malformed, the parser may leave the node as an
2340 -- indexed component (despite the presence of named associations).
2341 -- The iterator Next_Actual is equivalent to Next if the list is
2342 -- positional, but follows the normalized chain of actuals when
2343 -- named associations are present. In this case normalization has
2344 -- not taken place, and actuals remain unanalyzed, which leads to
2345 -- subsequent crashes or loops if there is an attempt to continue
2346 -- analysis of the program.
2348 -- IF there is a single actual and it is a type name, the node
2349 -- can only be interpreted as a slice of a parameterless call.
2350 -- Rebuild the node as such and analyze.
2352 if No
(Next
(Actual
))
2353 and then Is_Entity_Name
(Actual
)
2354 and then Is_Type
(Entity
(Actual
))
2355 and then Is_Discrete_Type
(Entity
(Actual
))
2361 New_Occurrence_Of
(Entity
(Actual
), Loc
)));
2371 end Process_Function_Call
;
2373 -------------------------------
2374 -- Process_Indexed_Component --
2375 -------------------------------
2377 procedure Process_Indexed_Component
is
2379 Array_Type
: Entity_Id
;
2381 Pent
: Entity_Id
:= Empty
;
2384 Exp
:= First
(Exprs
);
2386 if Is_Overloaded
(P
) then
2387 Process_Overloaded_Indexed_Component
;
2390 Array_Type
:= Etype
(P
);
2392 if Is_Entity_Name
(P
) then
2394 elsif Nkind
(P
) = N_Selected_Component
2395 and then Is_Entity_Name
(Selector_Name
(P
))
2397 Pent
:= Entity
(Selector_Name
(P
));
2400 -- Prefix must be appropriate for an array type, taking into
2401 -- account a possible implicit dereference.
2403 if Is_Access_Type
(Array_Type
) then
2405 (Warn_On_Dereference
, "?d?implicit dereference", N
);
2406 Array_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, P
);
2409 if Is_Array_Type
(Array_Type
) then
2411 -- In order to correctly access First_Index component later,
2412 -- replace string literal subtype by its parent type.
2414 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
2415 Array_Type
:= Etype
(Array_Type
);
2418 elsif Present
(Pent
) and then Ekind
(Pent
) = E_Entry_Family
then
2420 Set_Etype
(N
, Any_Type
);
2422 if not Has_Compatible_Type
(Exp
, Entry_Index_Type
(Pent
)) then
2423 Error_Msg_N
("invalid index type in entry name", N
);
2425 elsif Present
(Next
(Exp
)) then
2426 Error_Msg_N
("too many subscripts in entry reference", N
);
2429 Set_Etype
(N
, Etype
(P
));
2434 elsif Is_Record_Type
(Array_Type
)
2435 and then Remote_AST_I_Dereference
(P
)
2439 elsif Try_Container_Indexing
(N
, P
, Exprs
) then
2442 elsif Array_Type
= Any_Type
then
2443 Set_Etype
(N
, Any_Type
);
2445 -- In most cases the analysis of the prefix will have emitted
2446 -- an error already, but if the prefix may be interpreted as a
2447 -- call in prefixed notation, the report is left to the caller.
2448 -- To prevent cascaded errors, report only if no previous ones.
2450 if Serious_Errors_Detected
= 0 then
2451 Error_Msg_N
("invalid prefix in indexed component", P
);
2453 if Nkind
(P
) = N_Expanded_Name
then
2454 Error_Msg_NE
("\& is not visible", P
, Selector_Name
(P
));
2460 -- Here we definitely have a bad indexing
2463 if Nkind
(Parent
(N
)) = N_Requeue_Statement
2464 and then Present
(Pent
) and then Ekind
(Pent
) = E_Entry
2467 ("REQUEUE does not permit parameters", First
(Exprs
));
2469 elsif Is_Entity_Name
(P
)
2470 and then Etype
(P
) = Standard_Void_Type
2472 Error_Msg_NE
("incorrect use of &", P
, Entity
(P
));
2475 Error_Msg_N
("array type required in indexed component", P
);
2478 Set_Etype
(N
, Any_Type
);
2482 Index
:= First_Index
(Array_Type
);
2483 while Present
(Index
) and then Present
(Exp
) loop
2484 if not Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2485 Wrong_Type
(Exp
, Etype
(Index
));
2486 Set_Etype
(N
, Any_Type
);
2494 Set_Etype
(N
, Component_Type
(Array_Type
));
2495 Check_Implicit_Dereference
(N
, Etype
(N
));
2497 if Present
(Index
) then
2499 ("too few subscripts in array reference", First
(Exprs
));
2501 elsif Present
(Exp
) then
2502 Error_Msg_N
("too many subscripts in array reference", Exp
);
2505 end Process_Indexed_Component
;
2507 ----------------------------------------
2508 -- Process_Indexed_Component_Or_Slice --
2509 ----------------------------------------
2511 procedure Process_Indexed_Component_Or_Slice
is
2513 Exp
:= First
(Exprs
);
2514 while Present
(Exp
) loop
2515 Analyze_Expression
(Exp
);
2519 Exp
:= First
(Exprs
);
2521 -- If one index is present, and it is a subtype name, then the node
2522 -- denotes a slice (note that the case of an explicit range for a
2523 -- slice was already built as an N_Slice node in the first place,
2524 -- so that case is not handled here).
2526 -- We use a replace rather than a rewrite here because this is one
2527 -- of the cases in which the tree built by the parser is plain wrong.
2530 and then Is_Entity_Name
(Exp
)
2531 and then Is_Type
(Entity
(Exp
))
2534 Make_Slice
(Sloc
(N
),
2536 Discrete_Range
=> New_Copy
(Exp
)));
2539 -- Otherwise (more than one index present, or single index is not
2540 -- a subtype name), then we have the indexed component case.
2543 Process_Indexed_Component
;
2545 end Process_Indexed_Component_Or_Slice
;
2547 ------------------------------------------
2548 -- Process_Overloaded_Indexed_Component --
2549 ------------------------------------------
2551 procedure Process_Overloaded_Indexed_Component
is
2560 Set_Etype
(N
, Any_Type
);
2562 Get_First_Interp
(P
, I
, It
);
2563 while Present
(It
.Nam
) loop
2566 if Is_Access_Type
(Typ
) then
2567 Typ
:= Designated_Type
(Typ
);
2569 (Warn_On_Dereference
, "?d?implicit dereference", N
);
2572 if Is_Array_Type
(Typ
) then
2574 -- Got a candidate: verify that index types are compatible
2576 Index
:= First_Index
(Typ
);
2578 Exp
:= First
(Exprs
);
2579 while Present
(Index
) and then Present
(Exp
) loop
2580 if Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2592 if Found
and then No
(Index
) and then No
(Exp
) then
2594 CT
: constant Entity_Id
:=
2595 Base_Type
(Component_Type
(Typ
));
2597 Add_One_Interp
(N
, CT
, CT
);
2598 Check_Implicit_Dereference
(N
, CT
);
2602 elsif Try_Container_Indexing
(N
, P
, Exprs
) then
2607 Get_Next_Interp
(I
, It
);
2610 if Etype
(N
) = Any_Type
then
2611 Error_Msg_N
("no legal interpretation for indexed component", N
);
2612 Set_Is_Overloaded
(N
, False);
2616 end Process_Overloaded_Indexed_Component
;
2618 -- Start of processing for Analyze_Indexed_Component_Form
2621 -- Get name of array, function or type
2625 -- If P is an explicit dereference whose prefix is of a remote access-
2626 -- to-subprogram type, then N has already been rewritten as a subprogram
2627 -- call and analyzed.
2629 if Nkind
(N
) in N_Subprogram_Call
then
2632 -- When the prefix is attribute 'Loop_Entry and the sole expression of
2633 -- the indexed component denotes a loop name, the indexed form is turned
2634 -- into an attribute reference.
2636 elsif Nkind
(N
) = N_Attribute_Reference
2637 and then Attribute_Name
(N
) = Name_Loop_Entry
2642 pragma Assert
(Nkind
(N
) = N_Indexed_Component
);
2644 P_T
:= Base_Type
(Etype
(P
));
2646 if Is_Entity_Name
(P
) and then Present
(Entity
(P
)) then
2649 if Is_Type
(U_N
) then
2651 -- Reformat node as a type conversion
2653 E
:= Remove_Head
(Exprs
);
2655 if Present
(First
(Exprs
)) then
2657 ("argument of type conversion must be single expression", N
);
2660 Change_Node
(N
, N_Type_Conversion
);
2661 Set_Subtype_Mark
(N
, P
);
2663 Set_Expression
(N
, E
);
2665 -- After changing the node, call for the specific Analysis
2666 -- routine directly, to avoid a double call to the expander.
2668 Analyze_Type_Conversion
(N
);
2672 if Is_Overloadable
(U_N
) then
2673 Process_Function_Call
;
2675 elsif Ekind
(Etype
(P
)) = E_Subprogram_Type
2676 or else (Is_Access_Type
(Etype
(P
))
2678 Ekind
(Designated_Type
(Etype
(P
))) =
2681 -- Call to access_to-subprogram with possible implicit dereference
2683 Process_Function_Call
;
2685 elsif Is_Generic_Subprogram
(U_N
) then
2687 -- A common beginner's (or C++ templates fan) error
2689 Error_Msg_N
("generic subprogram cannot be called", N
);
2690 Set_Etype
(N
, Any_Type
);
2694 Process_Indexed_Component_Or_Slice
;
2697 -- If not an entity name, prefix is an expression that may denote
2698 -- an array or an access-to-subprogram.
2701 if Ekind
(P_T
) = E_Subprogram_Type
2702 or else (Is_Access_Type
(P_T
)
2704 Ekind
(Designated_Type
(P_T
)) = E_Subprogram_Type
)
2706 Process_Function_Call
;
2708 elsif Nkind
(P
) = N_Selected_Component
2709 and then Present
(Entity
(Selector_Name
(P
)))
2710 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
2712 Process_Function_Call
;
2714 -- In ASIS mode within a generic, a prefixed call is analyzed and
2715 -- partially rewritten but the original indexed component has not
2716 -- yet been rewritten as a call. Perform the replacement now.
2718 elsif Nkind
(P
) = N_Selected_Component
2719 and then Nkind
(Parent
(P
)) = N_Function_Call
2722 Rewrite
(N
, Parent
(P
));
2726 -- Indexed component, slice, or a call to a member of a family
2727 -- entry, which will be converted to an entry call later.
2729 Process_Indexed_Component_Or_Slice
;
2733 Analyze_Dimension
(N
);
2734 end Analyze_Indexed_Component_Form
;
2736 ------------------------
2737 -- Analyze_Logical_Op --
2738 ------------------------
2740 procedure Analyze_Logical_Op
(N
: Node_Id
) is
2741 L
: constant Node_Id
:= Left_Opnd
(N
);
2742 R
: constant Node_Id
:= Right_Opnd
(N
);
2743 Op_Id
: Entity_Id
:= Entity
(N
);
2746 Set_Etype
(N
, Any_Type
);
2747 Candidate_Type
:= Empty
;
2749 Analyze_Expression
(L
);
2750 Analyze_Expression
(R
);
2752 if Present
(Op_Id
) then
2754 if Ekind
(Op_Id
) = E_Operator
then
2755 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
2757 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2761 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
2762 while Present
(Op_Id
) loop
2763 if Ekind
(Op_Id
) = E_Operator
then
2764 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
2766 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
2769 Op_Id
:= Homonym
(Op_Id
);
2774 Check_Function_Writable_Actuals
(N
);
2775 end Analyze_Logical_Op
;
2777 ---------------------------
2778 -- Analyze_Membership_Op --
2779 ---------------------------
2781 procedure Analyze_Membership_Op
(N
: Node_Id
) is
2782 Loc
: constant Source_Ptr
:= Sloc
(N
);
2783 L
: constant Node_Id
:= Left_Opnd
(N
);
2784 R
: constant Node_Id
:= Right_Opnd
(N
);
2786 Index
: Interp_Index
;
2788 Found
: Boolean := False;
2792 procedure Try_One_Interp
(T1
: Entity_Id
);
2793 -- Routine to try one proposed interpretation. Note that the context
2794 -- of the operation plays no role in resolving the arguments, so that
2795 -- if there is more than one interpretation of the operands that is
2796 -- compatible with a membership test, the operation is ambiguous.
2798 --------------------
2799 -- Try_One_Interp --
2800 --------------------
2802 procedure Try_One_Interp
(T1
: Entity_Id
) is
2804 if Has_Compatible_Type
(R
, T1
) then
2806 and then Base_Type
(T1
) /= Base_Type
(T_F
)
2808 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
2810 if It
= No_Interp
then
2811 Ambiguous_Operands
(N
);
2812 Set_Etype
(L
, Any_Type
);
2829 procedure Analyze_Set_Membership
;
2830 -- If a set of alternatives is present, analyze each and find the
2831 -- common type to which they must all resolve.
2833 ----------------------------
2834 -- Analyze_Set_Membership --
2835 ----------------------------
2837 procedure Analyze_Set_Membership
is
2839 Index
: Interp_Index
;
2841 Candidate_Interps
: Node_Id
;
2842 Common_Type
: Entity_Id
:= Empty
;
2845 if Comes_From_Source
(N
) then
2846 Check_Compiler_Unit
("set membership", N
);
2850 Candidate_Interps
:= L
;
2852 if not Is_Overloaded
(L
) then
2853 Common_Type
:= Etype
(L
);
2855 Alt
:= First
(Alternatives
(N
));
2856 while Present
(Alt
) loop
2859 if not Has_Compatible_Type
(Alt
, Common_Type
) then
2860 Wrong_Type
(Alt
, Common_Type
);
2867 Alt
:= First
(Alternatives
(N
));
2868 while Present
(Alt
) loop
2870 if not Is_Overloaded
(Alt
) then
2871 Common_Type
:= Etype
(Alt
);
2874 Get_First_Interp
(Alt
, Index
, It
);
2875 while Present
(It
.Typ
) loop
2877 Has_Compatible_Type
(Candidate_Interps
, It
.Typ
)
2879 Remove_Interp
(Index
);
2882 Get_Next_Interp
(Index
, It
);
2885 Get_First_Interp
(Alt
, Index
, It
);
2888 Error_Msg_N
("alternative has no legal type", Alt
);
2892 -- If alternative is not overloaded, we have a unique type
2895 Set_Etype
(Alt
, It
.Typ
);
2896 Get_Next_Interp
(Index
, It
);
2899 Set_Is_Overloaded
(Alt
, False);
2900 Common_Type
:= Etype
(Alt
);
2903 Candidate_Interps
:= Alt
;
2910 Set_Etype
(N
, Standard_Boolean
);
2912 if Present
(Common_Type
) then
2913 Set_Etype
(L
, Common_Type
);
2915 -- The left operand may still be overloaded, to be resolved using
2919 Error_Msg_N
("cannot resolve membership operation", N
);
2921 end Analyze_Set_Membership
;
2923 -- Start of processing for Analyze_Membership_Op
2926 Analyze_Expression
(L
);
2928 if No
(R
) and then Ada_Version
>= Ada_2012
then
2929 Analyze_Set_Membership
;
2930 Check_Function_Writable_Actuals
(N
);
2935 if Nkind
(R
) = N_Range
2936 or else (Nkind
(R
) = N_Attribute_Reference
2937 and then Attribute_Name
(R
) = Name_Range
)
2941 if not Is_Overloaded
(L
) then
2942 Try_One_Interp
(Etype
(L
));
2945 Get_First_Interp
(L
, Index
, It
);
2946 while Present
(It
.Typ
) loop
2947 Try_One_Interp
(It
.Typ
);
2948 Get_Next_Interp
(Index
, It
);
2952 -- If not a range, it can be a subtype mark, or else it is a degenerate
2953 -- membership test with a singleton value, i.e. a test for equality,
2954 -- if the types are compatible.
2959 if Is_Entity_Name
(R
)
2960 and then Is_Type
(Entity
(R
))
2963 Check_Fully_Declared
(Entity
(R
), R
);
2965 elsif Ada_Version
>= Ada_2012
2966 and then Has_Compatible_Type
(R
, Etype
(L
))
2968 if Nkind
(N
) = N_In
then
2984 -- In all versions of the language, if we reach this point there
2985 -- is a previous error that will be diagnosed below.
2991 -- Compatibility between expression and subtype mark or range is
2992 -- checked during resolution. The result of the operation is Boolean
2995 Set_Etype
(N
, Standard_Boolean
);
2997 if Comes_From_Source
(N
)
2998 and then Present
(Right_Opnd
(N
))
2999 and then Is_CPP_Class
(Etype
(Etype
(Right_Opnd
(N
))))
3001 Error_Msg_N
("membership test not applicable to cpp-class types", N
);
3004 Check_Function_Writable_Actuals
(N
);
3005 end Analyze_Membership_Op
;
3011 procedure Analyze_Mod
(N
: Node_Id
) is
3013 -- A special warning check, if we have an expression of the form:
3014 -- expr mod 2 * literal
3015 -- where literal is 64 or less, then probably what was meant was
3016 -- expr mod 2 ** literal
3017 -- so issue an appropriate warning.
3019 if Warn_On_Suspicious_Modulus_Value
3020 and then Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
3021 and then Intval
(Right_Opnd
(N
)) = Uint_2
3022 and then Nkind
(Parent
(N
)) = N_Op_Multiply
3023 and then Nkind
(Right_Opnd
(Parent
(N
))) = N_Integer_Literal
3024 and then Intval
(Right_Opnd
(Parent
(N
))) <= Uint_64
3027 ("suspicious MOD value, was '*'* intended'??M?", Parent
(N
));
3030 -- Remaining processing is same as for other arithmetic operators
3032 Analyze_Arithmetic_Op
(N
);
3035 ----------------------
3036 -- Analyze_Negation --
3037 ----------------------
3039 procedure Analyze_Negation
(N
: Node_Id
) is
3040 R
: constant Node_Id
:= Right_Opnd
(N
);
3041 Op_Id
: Entity_Id
:= Entity
(N
);
3044 Set_Etype
(N
, Any_Type
);
3045 Candidate_Type
:= Empty
;
3047 Analyze_Expression
(R
);
3049 if Present
(Op_Id
) then
3050 if Ekind
(Op_Id
) = E_Operator
then
3051 Find_Negation_Types
(R
, Op_Id
, N
);
3053 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3057 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
3058 while Present
(Op_Id
) loop
3059 if Ekind
(Op_Id
) = E_Operator
then
3060 Find_Negation_Types
(R
, Op_Id
, N
);
3062 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
3065 Op_Id
:= Homonym
(Op_Id
);
3070 end Analyze_Negation
;
3076 procedure Analyze_Null
(N
: Node_Id
) is
3078 Check_SPARK_05_Restriction
("null is not allowed", N
);
3080 Set_Etype
(N
, Any_Access
);
3083 ----------------------
3084 -- Analyze_One_Call --
3085 ----------------------
3087 procedure Analyze_One_Call
3091 Success
: out Boolean;
3092 Skip_First
: Boolean := False)
3094 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
3095 Prev_T
: constant Entity_Id
:= Etype
(N
);
3097 Must_Skip
: constant Boolean := Skip_First
3098 or else Nkind
(Original_Node
(N
)) = N_Selected_Component
3100 (Nkind
(Original_Node
(N
)) = N_Indexed_Component
3101 and then Nkind
(Prefix
(Original_Node
(N
)))
3102 = N_Selected_Component
);
3103 -- The first formal must be omitted from the match when trying to find
3104 -- a primitive operation that is a possible interpretation, and also
3105 -- after the call has been rewritten, because the corresponding actual
3106 -- is already known to be compatible, and because this may be an
3107 -- indexing of a call with default parameters.
3111 Is_Indexed
: Boolean := False;
3112 Is_Indirect
: Boolean := False;
3113 Subp_Type
: constant Entity_Id
:= Etype
(Nam
);
3116 function Compatible_Types_In_Predicate
3118 T2
: Entity_Id
) return Boolean;
3119 -- For an Ada 2012 predicate or invariant, a call may mention an
3120 -- incomplete type, while resolution of the corresponding predicate
3121 -- function may see the full view, as a consequence of the delayed
3122 -- resolution of the corresponding expressions. This may occur in
3123 -- the body of a predicate function, or in a call to such. Anomalies
3124 -- involving private and full views can also happen. In each case,
3125 -- rewrite node or add conversions to remove spurious type errors.
3127 procedure Indicate_Name_And_Type
;
3128 -- If candidate interpretation matches, indicate name and type of result
3131 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean;
3132 -- There may be a user-defined operator that hides the current
3133 -- interpretation. We must check for this independently of the
3134 -- analysis of the call with the user-defined operation, because
3135 -- the parameter names may be wrong and yet the hiding takes place.
3136 -- This fixes a problem with ACATS test B34014O.
3138 -- When the type Address is a visible integer type, and the DEC
3139 -- system extension is visible, the predefined operator may be
3140 -- hidden as well, by one of the address operations in auxdec.
3141 -- Finally, The abstract operations on address do not hide the
3142 -- predefined operator (this is the purpose of making them abstract).
3144 -----------------------------------
3145 -- Compatible_Types_In_Predicate --
3146 -----------------------------------
3148 function Compatible_Types_In_Predicate
3150 T2
: Entity_Id
) return Boolean
3152 function Common_Type
(T
: Entity_Id
) return Entity_Id
;
3153 -- Find non-private full view if any, without going to ancestor type
3154 -- (as opposed to Underlying_Type).
3160 function Common_Type
(T
: Entity_Id
) return Entity_Id
is
3162 if Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
3163 return Base_Type
(Full_View
(T
));
3165 return Base_Type
(T
);
3169 -- Start of processing for Compatible_Types_In_Predicate
3172 if (Ekind
(Current_Scope
) = E_Function
3173 and then Is_Predicate_Function
(Current_Scope
))
3175 (Ekind
(Nam
) = E_Function
3176 and then Is_Predicate_Function
(Nam
))
3178 if Is_Incomplete_Type
(T1
)
3179 and then Present
(Full_View
(T1
))
3180 and then Full_View
(T1
) = T2
3182 Set_Etype
(Formal
, Etype
(Actual
));
3185 elsif Common_Type
(T1
) = Common_Type
(T2
) then
3186 Rewrite
(Actual
, Unchecked_Convert_To
(Etype
(Formal
), Actual
));
3196 end Compatible_Types_In_Predicate
;
3198 ----------------------------
3199 -- Indicate_Name_And_Type --
3200 ----------------------------
3202 procedure Indicate_Name_And_Type
is
3204 Add_One_Interp
(N
, Nam
, Etype
(Nam
));
3205 Check_Implicit_Dereference
(N
, Etype
(Nam
));
3208 -- If the prefix of the call is a name, indicate the entity
3209 -- being called. If it is not a name, it is an expression that
3210 -- denotes an access to subprogram or else an entry or family. In
3211 -- the latter case, the name is a selected component, and the entity
3212 -- being called is noted on the selector.
3214 if not Is_Type
(Nam
) then
3215 if Is_Entity_Name
(Name
(N
)) then
3216 Set_Entity
(Name
(N
), Nam
);
3217 Set_Etype
(Name
(N
), Etype
(Nam
));
3219 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
3220 Set_Entity
(Selector_Name
(Name
(N
)), Nam
);
3224 if Debug_Flag_E
and not Report
then
3225 Write_Str
(" Overloaded call ");
3226 Write_Int
(Int
(N
));
3227 Write_Str
(" compatible with ");
3228 Write_Int
(Int
(Nam
));
3231 end Indicate_Name_And_Type
;
3233 ------------------------
3234 -- Operator_Hidden_By --
3235 ------------------------
3237 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean is
3238 Act1
: constant Node_Id
:= First_Actual
(N
);
3239 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
3240 Form1
: constant Entity_Id
:= First_Formal
(Fun
);
3241 Form2
: constant Entity_Id
:= Next_Formal
(Form1
);
3244 if Ekind
(Fun
) /= E_Function
or else Is_Abstract_Subprogram
(Fun
) then
3247 elsif not Has_Compatible_Type
(Act1
, Etype
(Form1
)) then
3250 elsif Present
(Form2
) then
3252 or else not Has_Compatible_Type
(Act2
, Etype
(Form2
))
3257 elsif Present
(Act2
) then
3261 -- Now we know that the arity of the operator matches the function,
3262 -- and the function call is a valid interpretation. The function
3263 -- hides the operator if it has the right signature, or if one of
3264 -- its operands is a non-abstract operation on Address when this is
3265 -- a visible integer type.
3267 return Hides_Op
(Fun
, Nam
)
3268 or else Is_Descendant_Of_Address
(Etype
(Form1
))
3271 and then Is_Descendant_Of_Address
(Etype
(Form2
)));
3272 end Operator_Hidden_By
;
3274 -- Start of processing for Analyze_One_Call
3279 -- If the subprogram has no formals or if all the formals have defaults,
3280 -- and the return type is an array type, the node may denote an indexing
3281 -- of the result of a parameterless call. In Ada 2005, the subprogram
3282 -- may have one non-defaulted formal, and the call may have been written
3283 -- in prefix notation, so that the rebuilt parameter list has more than
3286 if not Is_Overloadable
(Nam
)
3287 and then Ekind
(Nam
) /= E_Subprogram_Type
3288 and then Ekind
(Nam
) /= E_Entry_Family
3293 -- An indexing requires at least one actual. The name of the call cannot
3294 -- be an implicit indirect call, so it cannot be a generated explicit
3297 if not Is_Empty_List
(Actuals
)
3299 (Needs_No_Actuals
(Nam
)
3301 (Needs_One_Actual
(Nam
)
3302 and then Present
(Next_Actual
(First
(Actuals
)))))
3304 if Is_Array_Type
(Subp_Type
)
3306 (Nkind
(Name
(N
)) /= N_Explicit_Dereference
3307 or else Comes_From_Source
(Name
(N
)))
3309 Is_Indexed
:= Try_Indexed_Call
(N
, Nam
, Subp_Type
, Must_Skip
);
3311 elsif Is_Access_Type
(Subp_Type
)
3312 and then Is_Array_Type
(Designated_Type
(Subp_Type
))
3316 (N
, Nam
, Designated_Type
(Subp_Type
), Must_Skip
);
3318 -- The prefix can also be a parameterless function that returns an
3319 -- access to subprogram, in which case this is an indirect call.
3320 -- If this succeeds, an explicit dereference is added later on,
3321 -- in Analyze_Call or Resolve_Call.
3323 elsif Is_Access_Type
(Subp_Type
)
3324 and then Ekind
(Designated_Type
(Subp_Type
)) = E_Subprogram_Type
3326 Is_Indirect
:= Try_Indirect_Call
(N
, Nam
, Subp_Type
);
3331 -- If the call has been transformed into a slice, it is of the form
3332 -- F (Subtype) where F is parameterless. The node has been rewritten in
3333 -- Try_Indexed_Call and there is nothing else to do.
3336 and then Nkind
(N
) = N_Slice
3342 (N
, Nam
, (Report
and not Is_Indexed
and not Is_Indirect
), Norm_OK
);
3346 -- If an indirect call is a possible interpretation, indicate
3347 -- success to the caller. This may be an indexing of an explicit
3348 -- dereference of a call that returns an access type (see above).
3352 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
3353 and then Comes_From_Source
(Name
(N
)))
3358 -- Mismatch in number or names of parameters
3360 elsif Debug_Flag_E
then
3361 Write_Str
(" normalization fails in call ");
3362 Write_Int
(Int
(N
));
3363 Write_Str
(" with subprogram ");
3364 Write_Int
(Int
(Nam
));
3368 -- If the context expects a function call, discard any interpretation
3369 -- that is a procedure. If the node is not overloaded, leave as is for
3370 -- better error reporting when type mismatch is found.
3372 elsif Nkind
(N
) = N_Function_Call
3373 and then Is_Overloaded
(Name
(N
))
3374 and then Ekind
(Nam
) = E_Procedure
3378 -- Ditto for function calls in a procedure context
3380 elsif Nkind
(N
) = N_Procedure_Call_Statement
3381 and then Is_Overloaded
(Name
(N
))
3382 and then Etype
(Nam
) /= Standard_Void_Type
3386 elsif No
(Actuals
) then
3388 -- If Normalize succeeds, then there are default parameters for
3391 Indicate_Name_And_Type
;
3393 elsif Ekind
(Nam
) = E_Operator
then
3394 if Nkind
(N
) = N_Procedure_Call_Statement
then
3398 -- This can occur when the prefix of the call is an operator
3399 -- name or an expanded name whose selector is an operator name.
3401 Analyze_Operator_Call
(N
, Nam
);
3403 if Etype
(N
) /= Prev_T
then
3405 -- Check that operator is not hidden by a function interpretation
3407 if Is_Overloaded
(Name
(N
)) then
3413 Get_First_Interp
(Name
(N
), I
, It
);
3414 while Present
(It
.Nam
) loop
3415 if Operator_Hidden_By
(It
.Nam
) then
3416 Set_Etype
(N
, Prev_T
);
3420 Get_Next_Interp
(I
, It
);
3425 -- If operator matches formals, record its name on the call.
3426 -- If the operator is overloaded, Resolve will select the
3427 -- correct one from the list of interpretations. The call
3428 -- node itself carries the first candidate.
3430 Set_Entity
(Name
(N
), Nam
);
3433 elsif Report
and then Etype
(N
) = Any_Type
then
3434 Error_Msg_N
("incompatible arguments for operator", N
);
3438 -- Normalize_Actuals has chained the named associations in the
3439 -- correct order of the formals.
3441 Actual
:= First_Actual
(N
);
3442 Formal
:= First_Formal
(Nam
);
3444 -- If we are analyzing a call rewritten from object notation, skip
3445 -- first actual, which may be rewritten later as an explicit
3449 Next_Actual
(Actual
);
3450 Next_Formal
(Formal
);
3453 while Present
(Actual
) and then Present
(Formal
) loop
3454 if Nkind
(Parent
(Actual
)) /= N_Parameter_Association
3455 or else Chars
(Selector_Name
(Parent
(Actual
))) = Chars
(Formal
)
3457 -- The actual can be compatible with the formal, but we must
3458 -- also check that the context is not an address type that is
3459 -- visibly an integer type. In this case the use of literals is
3460 -- illegal, except in the body of descendants of system, where
3461 -- arithmetic operations on address are of course used.
3463 if Has_Compatible_Type
(Actual
, Etype
(Formal
))
3465 (Etype
(Actual
) /= Universal_Integer
3466 or else not Is_Descendant_Of_Address
(Etype
(Formal
))
3468 Is_Predefined_File_Name
3469 (Unit_File_Name
(Get_Source_Unit
(N
))))
3471 Next_Actual
(Actual
);
3472 Next_Formal
(Formal
);
3474 -- In Allow_Integer_Address mode, we allow an actual integer to
3475 -- match a formal address type and vice versa. We only do this
3476 -- if we are certain that an error will otherwise be issued
3478 elsif Address_Integer_Convert_OK
3479 (Etype
(Actual
), Etype
(Formal
))
3480 and then (Report
and not Is_Indexed
and not Is_Indirect
)
3482 -- Handle this case by introducing an unchecked conversion
3485 Unchecked_Convert_To
(Etype
(Formal
),
3486 Relocate_Node
(Actual
)));
3487 Analyze_And_Resolve
(Actual
, Etype
(Formal
));
3488 Next_Actual
(Actual
);
3489 Next_Formal
(Formal
);
3491 -- Under relaxed RM semantics silently replace occurrences of
3492 -- null by System.Address_Null. We only do this if we know that
3493 -- an error will otherwise be issued.
3495 elsif Null_To_Null_Address_Convert_OK
(Actual
, Etype
(Formal
))
3496 and then (Report
and not Is_Indexed
and not Is_Indirect
)
3498 Replace_Null_By_Null_Address
(Actual
);
3499 Analyze_And_Resolve
(Actual
, Etype
(Formal
));
3500 Next_Actual
(Actual
);
3501 Next_Formal
(Formal
);
3503 elsif Compatible_Types_In_Predicate
3504 (Etype
(Formal
), Etype
(Actual
))
3506 Next_Actual
(Actual
);
3507 Next_Formal
(Formal
);
3509 -- In a complex case where an enclosing generic and a nested
3510 -- generic package, both declared with partially parameterized
3511 -- formal subprograms with the same names, are instantiated
3512 -- with the same type, the types of the actual parameter and
3513 -- that of the formal may appear incompatible at first sight.
3516 -- type Outer_T is private;
3517 -- with function Func (Formal : Outer_T)
3518 -- return ... is <>;
3520 -- package Outer_Gen is
3522 -- type Inner_T is private;
3523 -- with function Func (Formal : Inner_T) -- (1)
3524 -- return ... is <>;
3526 -- package Inner_Gen is
3527 -- function Inner_Func (Formal : Inner_T) -- (2)
3528 -- return ... is (Func (Formal));
3530 -- end Outer_Generic;
3532 -- package Outer_Inst is new Outer_Gen (Actual_T);
3533 -- package Inner_Inst is new Outer_Inst.Inner_Gen (Actual_T);
3535 -- In the example above, the type of parameter
3536 -- Inner_Func.Formal at (2) is incompatible with the type of
3537 -- Func.Formal at (1) in the context of instantiations
3538 -- Outer_Inst and Inner_Inst. In reality both types are generic
3539 -- actual subtypes renaming base type Actual_T as part of the
3540 -- generic prologues for the instantiations.
3542 -- Recognize this case and add a type conversion to allow this
3543 -- kind of generic actual subtype conformance. Note that this
3544 -- is done only when the call is non-overloaded because the
3545 -- resolution mechanism already has the means to disambiguate
3548 elsif not Is_Overloaded
(Name
(N
))
3549 and then Is_Type
(Etype
(Actual
))
3550 and then Is_Type
(Etype
(Formal
))
3551 and then Is_Generic_Actual_Type
(Etype
(Actual
))
3552 and then Is_Generic_Actual_Type
(Etype
(Formal
))
3553 and then Base_Type
(Etype
(Actual
)) =
3554 Base_Type
(Etype
(Formal
))
3557 Convert_To
(Etype
(Formal
), Relocate_Node
(Actual
)));
3558 Analyze_And_Resolve
(Actual
, Etype
(Formal
));
3559 Next_Actual
(Actual
);
3560 Next_Formal
(Formal
);
3562 -- Handle failed type check
3565 if Debug_Flag_E
then
3566 Write_Str
(" type checking fails in call ");
3567 Write_Int
(Int
(N
));
3568 Write_Str
(" with formal ");
3569 Write_Int
(Int
(Formal
));
3570 Write_Str
(" in subprogram ");
3571 Write_Int
(Int
(Nam
));
3575 -- Comment needed on the following test???
3577 if Report
and not Is_Indexed
and not Is_Indirect
then
3579 -- Ada 2005 (AI-251): Complete the error notification
3580 -- to help new Ada 2005 users.
3582 if Is_Class_Wide_Type
(Etype
(Formal
))
3583 and then Is_Interface
(Etype
(Etype
(Formal
)))
3584 and then not Interface_Present_In_Ancestor
3585 (Typ
=> Etype
(Actual
),
3586 Iface
=> Etype
(Etype
(Formal
)))
3589 ("(Ada 2005) does not implement interface }",
3590 Actual
, Etype
(Etype
(Formal
)));
3593 Wrong_Type
(Actual
, Etype
(Formal
));
3595 if Nkind
(Actual
) = N_Op_Eq
3596 and then Nkind
(Left_Opnd
(Actual
)) = N_Identifier
3598 Formal
:= First_Formal
(Nam
);
3599 while Present
(Formal
) loop
3600 if Chars
(Left_Opnd
(Actual
)) = Chars
(Formal
) then
3601 Error_Msg_N
-- CODEFIX
3602 ("possible misspelling of `='>`!", Actual
);
3606 Next_Formal
(Formal
);
3610 if All_Errors_Mode
then
3611 Error_Msg_Sloc
:= Sloc
(Nam
);
3613 if Etype
(Formal
) = Any_Type
then
3615 ("there is no legal actual parameter", Actual
);
3618 if Is_Overloadable
(Nam
)
3619 and then Present
(Alias
(Nam
))
3620 and then not Comes_From_Source
(Nam
)
3623 ("\\ =='> in call to inherited operation & #!",
3626 elsif Ekind
(Nam
) = E_Subprogram_Type
then
3628 Access_To_Subprogram_Typ
:
3629 constant Entity_Id
:=
3631 (Associated_Node_For_Itype
(Nam
));
3634 ("\\ =='> in call to dereference of &#!",
3635 Actual
, Access_To_Subprogram_Typ
);
3640 ("\\ =='> in call to &#!", Actual
, Nam
);
3650 -- Normalize_Actuals has verified that a default value exists
3651 -- for this formal. Current actual names a subsequent formal.
3653 Next_Formal
(Formal
);
3657 -- On exit, all actuals match
3659 Indicate_Name_And_Type
;
3661 end Analyze_One_Call
;
3663 ---------------------------
3664 -- Analyze_Operator_Call --
3665 ---------------------------
3667 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
) is
3668 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
3669 Act1
: constant Node_Id
:= First_Actual
(N
);
3670 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
3673 -- Binary operator case
3675 if Present
(Act2
) then
3677 -- If more than two operands, then not binary operator after all
3679 if Present
(Next_Actual
(Act2
)) then
3683 -- Otherwise action depends on operator
3694 Find_Arithmetic_Types
(Act1
, Act2
, Op_Id
, N
);
3700 Find_Boolean_Types
(Act1
, Act2
, Op_Id
, N
);
3707 Find_Comparison_Types
(Act1
, Act2
, Op_Id
, N
);
3712 Find_Equality_Types
(Act1
, Act2
, Op_Id
, N
);
3714 when Name_Op_Concat
=>
3715 Find_Concatenation_Types
(Act1
, Act2
, Op_Id
, N
);
3717 -- Is this when others, or should it be an abort???
3723 -- Unary operator case
3731 Find_Unary_Types
(Act1
, Op_Id
, N
);
3734 Find_Negation_Types
(Act1
, Op_Id
, N
);
3736 -- Is this when others correct, or should it be an abort???
3742 end Analyze_Operator_Call
;
3744 -------------------------------------------
3745 -- Analyze_Overloaded_Selected_Component --
3746 -------------------------------------------
3748 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
) is
3749 Nam
: constant Node_Id
:= Prefix
(N
);
3750 Sel
: constant Node_Id
:= Selector_Name
(N
);
3757 Set_Etype
(Sel
, Any_Type
);
3759 Get_First_Interp
(Nam
, I
, It
);
3760 while Present
(It
.Typ
) loop
3761 if Is_Access_Type
(It
.Typ
) then
3762 T
:= Designated_Type
(It
.Typ
);
3763 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
3768 -- Locate the component. For a private prefix the selector can denote
3771 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
3773 -- If the prefix is a class-wide type, the visible components are
3774 -- those of the base type.
3776 if Is_Class_Wide_Type
(T
) then
3780 Comp
:= First_Entity
(T
);
3781 while Present
(Comp
) loop
3782 if Chars
(Comp
) = Chars
(Sel
)
3783 and then Is_Visible_Component
(Comp
)
3786 -- AI05-105: if the context is an object renaming with
3787 -- an anonymous access type, the expected type of the
3788 -- object must be anonymous. This is a name resolution rule.
3790 if Nkind
(Parent
(N
)) /= N_Object_Renaming_Declaration
3791 or else No
(Access_Definition
(Parent
(N
)))
3792 or else Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Type
3794 Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Subprogram_Type
3796 Set_Entity
(Sel
, Comp
);
3797 Set_Etype
(Sel
, Etype
(Comp
));
3798 Add_One_Interp
(N
, Etype
(Comp
), Etype
(Comp
));
3799 Check_Implicit_Dereference
(N
, Etype
(Comp
));
3801 -- This also specifies a candidate to resolve the name.
3802 -- Further overloading will be resolved from context.
3803 -- The selector name itself does not carry overloading
3806 Set_Etype
(Nam
, It
.Typ
);
3809 -- Named access type in the context of a renaming
3810 -- declaration with an access definition. Remove
3811 -- inapplicable candidate.
3820 elsif Is_Concurrent_Type
(T
) then
3821 Comp
:= First_Entity
(T
);
3822 while Present
(Comp
)
3823 and then Comp
/= First_Private_Entity
(T
)
3825 if Chars
(Comp
) = Chars
(Sel
) then
3826 if Is_Overloadable
(Comp
) then
3827 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
3829 Set_Entity_With_Checks
(Sel
, Comp
);
3830 Generate_Reference
(Comp
, Sel
);
3833 Set_Etype
(Sel
, Etype
(Comp
));
3834 Set_Etype
(N
, Etype
(Comp
));
3835 Set_Etype
(Nam
, It
.Typ
);
3837 -- For access type case, introduce explicit dereference for
3838 -- more uniform treatment of entry calls. Do this only once
3839 -- if several interpretations yield an access type.
3841 if Is_Access_Type
(Etype
(Nam
))
3842 and then Nkind
(Nam
) /= N_Explicit_Dereference
3844 Insert_Explicit_Dereference
(Nam
);
3846 (Warn_On_Dereference
, "?d?implicit dereference", N
);
3853 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
3856 Get_Next_Interp
(I
, It
);
3859 if Etype
(N
) = Any_Type
3860 and then not Try_Object_Operation
(N
)
3862 Error_Msg_NE
("undefined selector& for overloaded prefix", N
, Sel
);
3863 Set_Entity
(Sel
, Any_Id
);
3864 Set_Etype
(Sel
, Any_Type
);
3866 end Analyze_Overloaded_Selected_Component
;
3868 ----------------------------------
3869 -- Analyze_Qualified_Expression --
3870 ----------------------------------
3872 procedure Analyze_Qualified_Expression
(N
: Node_Id
) is
3873 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
3874 Expr
: constant Node_Id
:= Expression
(N
);
3880 Analyze_Expression
(Expr
);
3882 Set_Etype
(N
, Any_Type
);
3887 if T
= Any_Type
then
3891 Check_Fully_Declared
(T
, N
);
3893 -- If expected type is class-wide, check for exact match before
3894 -- expansion, because if the expression is a dispatching call it
3895 -- may be rewritten as explicit dereference with class-wide result.
3896 -- If expression is overloaded, retain only interpretations that
3897 -- will yield exact matches.
3899 if Is_Class_Wide_Type
(T
) then
3900 if not Is_Overloaded
(Expr
) then
3901 if Base_Type
(Etype
(Expr
)) /= Base_Type
(T
) then
3902 if Nkind
(Expr
) = N_Aggregate
then
3903 Error_Msg_N
("type of aggregate cannot be class-wide", Expr
);
3905 Wrong_Type
(Expr
, T
);
3910 Get_First_Interp
(Expr
, I
, It
);
3912 while Present
(It
.Nam
) loop
3913 if Base_Type
(It
.Typ
) /= Base_Type
(T
) then
3917 Get_Next_Interp
(I
, It
);
3923 end Analyze_Qualified_Expression
;
3925 -----------------------------------
3926 -- Analyze_Quantified_Expression --
3927 -----------------------------------
3929 procedure Analyze_Quantified_Expression
(N
: Node_Id
) is
3930 function Is_Empty_Range
(Typ
: Entity_Id
) return Boolean;
3931 -- If the iterator is part of a quantified expression, and the range is
3932 -- known to be statically empty, emit a warning and replace expression
3933 -- with its static value. Returns True if the replacement occurs.
3935 function No_Else_Or_Trivial_True
(If_Expr
: Node_Id
) return Boolean;
3936 -- Determine whether if expression If_Expr lacks an else part or if it
3937 -- has one, it evaluates to True.
3939 --------------------
3940 -- Is_Empty_Range --
3941 --------------------
3943 function Is_Empty_Range
(Typ
: Entity_Id
) return Boolean is
3944 Loc
: constant Source_Ptr
:= Sloc
(N
);
3947 if Is_Array_Type
(Typ
)
3948 and then Compile_Time_Known_Bounds
(Typ
)
3950 (Expr_Value
(Type_Low_Bound
(Etype
(First_Index
(Typ
)))) >
3951 Expr_Value
(Type_High_Bound
(Etype
(First_Index
(Typ
)))))
3953 Preanalyze_And_Resolve
(Condition
(N
), Standard_Boolean
);
3955 if All_Present
(N
) then
3957 ("??quantified expression with ALL "
3958 & "over a null range has value True", N
);
3959 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
3963 ("??quantified expression with SOME "
3964 & "over a null range has value False", N
);
3965 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
3976 -----------------------------
3977 -- No_Else_Or_Trivial_True --
3978 -----------------------------
3980 function No_Else_Or_Trivial_True
(If_Expr
: Node_Id
) return Boolean is
3981 Else_Expr
: constant Node_Id
:=
3982 Next
(Next
(First
(Expressions
(If_Expr
))));
3986 or else (Compile_Time_Known_Value
(Else_Expr
)
3987 and then Is_True
(Expr_Value
(Else_Expr
)));
3988 end No_Else_Or_Trivial_True
;
3992 Cond
: constant Node_Id
:= Condition
(N
);
3993 Loop_Id
: Entity_Id
;
3994 QE_Scop
: Entity_Id
;
3996 -- Start of processing for Analyze_Quantified_Expression
3999 Check_SPARK_05_Restriction
("quantified expression is not allowed", N
);
4001 -- Create a scope to emulate the loop-like behavior of the quantified
4002 -- expression. The scope is needed to provide proper visibility of the
4005 QE_Scop
:= New_Internal_Entity
(E_Loop
, Current_Scope
, Sloc
(N
), 'L');
4006 Set_Etype
(QE_Scop
, Standard_Void_Type
);
4007 Set_Scope
(QE_Scop
, Current_Scope
);
4008 Set_Parent
(QE_Scop
, N
);
4010 Push_Scope
(QE_Scop
);
4012 -- All constituents are preanalyzed and resolved to avoid untimely
4013 -- generation of various temporaries and types. Full analysis and
4014 -- expansion is carried out when the quantified expression is
4015 -- transformed into an expression with actions.
4017 if Present
(Iterator_Specification
(N
)) then
4018 Preanalyze
(Iterator_Specification
(N
));
4020 -- Do not proceed with the analysis when the range of iteration is
4021 -- empty. The appropriate error is issued by Is_Empty_Range.
4023 if Is_Entity_Name
(Name
(Iterator_Specification
(N
)))
4024 and then Is_Empty_Range
(Etype
(Name
(Iterator_Specification
(N
))))
4029 else pragma Assert
(Present
(Loop_Parameter_Specification
(N
)));
4031 Loop_Par
: constant Node_Id
:= Loop_Parameter_Specification
(N
);
4034 Preanalyze
(Loop_Par
);
4036 if Nkind
(Discrete_Subtype_Definition
(Loop_Par
)) = N_Function_Call
4037 and then Parent
(Loop_Par
) /= N
4039 -- The parser cannot distinguish between a loop specification
4040 -- and an iterator specification. If after pre-analysis the
4041 -- proper form has been recognized, rewrite the expression to
4042 -- reflect the right kind. This is needed for proper ASIS
4043 -- navigation. If expansion is enabled, the transformation is
4044 -- performed when the expression is rewritten as a loop.
4046 Set_Iterator_Specification
(N
,
4047 New_Copy_Tree
(Iterator_Specification
(Parent
(Loop_Par
))));
4049 Set_Defining_Identifier
(Iterator_Specification
(N
),
4050 Relocate_Node
(Defining_Identifier
(Loop_Par
)));
4051 Set_Name
(Iterator_Specification
(N
),
4052 Relocate_Node
(Discrete_Subtype_Definition
(Loop_Par
)));
4053 Set_Comes_From_Source
(Iterator_Specification
(N
),
4054 Comes_From_Source
(Loop_Parameter_Specification
(N
)));
4055 Set_Loop_Parameter_Specification
(N
, Empty
);
4060 Preanalyze_And_Resolve
(Cond
, Standard_Boolean
);
4063 Set_Etype
(N
, Standard_Boolean
);
4065 -- Verify that the loop variable is used within the condition of the
4066 -- quantified expression.
4068 if Present
(Iterator_Specification
(N
)) then
4069 Loop_Id
:= Defining_Identifier
(Iterator_Specification
(N
));
4071 Loop_Id
:= Defining_Identifier
(Loop_Parameter_Specification
(N
));
4074 if Warn_On_Suspicious_Contract
4075 and then not Referenced
(Loop_Id
, Cond
)
4077 -- Generating C, this check causes spurious warnings on inlined
4078 -- postconditions; we can safely disable it because this check
4079 -- was previously performed when analyzing the internally built
4080 -- postconditions procedure.
4082 if Modify_Tree_For_C
and then In_Inlined_Body
then
4085 Error_Msg_N
("?T?unused variable &", Loop_Id
);
4089 -- Diagnose a possible misuse of the SOME existential quantifier. When
4090 -- we have a quantified expression of the form:
4092 -- for some X => (if P then Q [else True])
4094 -- any value for X that makes P False results in the if expression being
4095 -- trivially True, and so also results in the quantified expression
4096 -- being trivially True.
4098 if Warn_On_Suspicious_Contract
4099 and then not All_Present
(N
)
4100 and then Nkind
(Cond
) = N_If_Expression
4101 and then No_Else_Or_Trivial_True
(Cond
)
4103 Error_Msg_N
("?T?suspicious expression", N
);
4104 Error_Msg_N
("\\did you mean (for all X ='> (if P then Q))", N
);
4105 Error_Msg_N
("\\or (for some X ='> P and then Q) instead'?", N
);
4107 end Analyze_Quantified_Expression
;
4113 procedure Analyze_Range
(N
: Node_Id
) is
4114 L
: constant Node_Id
:= Low_Bound
(N
);
4115 H
: constant Node_Id
:= High_Bound
(N
);
4116 I1
, I2
: Interp_Index
;
4119 procedure Check_Common_Type
(T1
, T2
: Entity_Id
);
4120 -- Verify the compatibility of two types, and choose the
4121 -- non universal one if the other is universal.
4123 procedure Check_High_Bound
(T
: Entity_Id
);
4124 -- Test one interpretation of the low bound against all those
4125 -- of the high bound.
4127 procedure Check_Universal_Expression
(N
: Node_Id
);
4128 -- In Ada 83, reject bounds of a universal range that are not literals
4131 -----------------------
4132 -- Check_Common_Type --
4133 -----------------------
4135 procedure Check_Common_Type
(T1
, T2
: Entity_Id
) is
4137 if Covers
(T1
=> T1
, T2
=> T2
)
4139 Covers
(T1
=> T2
, T2
=> T1
)
4141 if T1
= Universal_Integer
4142 or else T1
= Universal_Real
4143 or else T1
= Any_Character
4145 Add_One_Interp
(N
, Base_Type
(T2
), Base_Type
(T2
));
4148 Add_One_Interp
(N
, T1
, T1
);
4151 Add_One_Interp
(N
, Base_Type
(T1
), Base_Type
(T1
));
4154 end Check_Common_Type
;
4156 ----------------------
4157 -- Check_High_Bound --
4158 ----------------------
4160 procedure Check_High_Bound
(T
: Entity_Id
) is
4162 if not Is_Overloaded
(H
) then
4163 Check_Common_Type
(T
, Etype
(H
));
4165 Get_First_Interp
(H
, I2
, It2
);
4166 while Present
(It2
.Typ
) loop
4167 Check_Common_Type
(T
, It2
.Typ
);
4168 Get_Next_Interp
(I2
, It2
);
4171 end Check_High_Bound
;
4173 -----------------------------
4174 -- Is_Universal_Expression --
4175 -----------------------------
4177 procedure Check_Universal_Expression
(N
: Node_Id
) is
4179 if Etype
(N
) = Universal_Integer
4180 and then Nkind
(N
) /= N_Integer_Literal
4181 and then not Is_Entity_Name
(N
)
4182 and then Nkind
(N
) /= N_Attribute_Reference
4184 Error_Msg_N
("illegal bound in discrete range", N
);
4186 end Check_Universal_Expression
;
4188 -- Start of processing for Analyze_Range
4191 Set_Etype
(N
, Any_Type
);
4192 Analyze_Expression
(L
);
4193 Analyze_Expression
(H
);
4195 if Etype
(L
) = Any_Type
or else Etype
(H
) = Any_Type
then
4199 if not Is_Overloaded
(L
) then
4200 Check_High_Bound
(Etype
(L
));
4202 Get_First_Interp
(L
, I1
, It1
);
4203 while Present
(It1
.Typ
) loop
4204 Check_High_Bound
(It1
.Typ
);
4205 Get_Next_Interp
(I1
, It1
);
4209 -- If result is Any_Type, then we did not find a compatible pair
4211 if Etype
(N
) = Any_Type
then
4212 Error_Msg_N
("incompatible types in range ", N
);
4216 if Ada_Version
= Ada_83
4218 (Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
4219 or else Nkind
(Parent
(N
)) = N_Constrained_Array_Definition
)
4221 Check_Universal_Expression
(L
);
4222 Check_Universal_Expression
(H
);
4225 Check_Function_Writable_Actuals
(N
);
4228 -----------------------
4229 -- Analyze_Reference --
4230 -----------------------
4232 procedure Analyze_Reference
(N
: Node_Id
) is
4233 P
: constant Node_Id
:= Prefix
(N
);
4236 Acc_Type
: Entity_Id
;
4241 -- An interesting error check, if we take the 'Ref of an object for
4242 -- which a pragma Atomic or Volatile has been given, and the type of the
4243 -- object is not Atomic or Volatile, then we are in trouble. The problem
4244 -- is that no trace of the atomic/volatile status will remain for the
4245 -- backend to respect when it deals with the resulting pointer, since
4246 -- the pointer type will not be marked atomic (it is a pointer to the
4247 -- base type of the object).
4249 -- It is not clear if that can ever occur, but in case it does, we will
4250 -- generate an error message. Not clear if this message can ever be
4251 -- generated, and pretty clear that it represents a bug if it is, still
4252 -- seems worth checking, except in CodePeer mode where we do not really
4253 -- care and don't want to bother the user.
4257 if Is_Entity_Name
(P
)
4258 and then Is_Object_Reference
(P
)
4259 and then not CodePeer_Mode
4264 if (Has_Atomic_Components
(E
)
4265 and then not Has_Atomic_Components
(T
))
4267 (Has_Volatile_Components
(E
)
4268 and then not Has_Volatile_Components
(T
))
4269 or else (Is_Atomic
(E
) and then not Is_Atomic
(T
))
4270 or else (Is_Volatile
(E
) and then not Is_Volatile
(T
))
4272 Error_Msg_N
("cannot take reference to Atomic/Volatile object", N
);
4276 -- Carry on with normal processing
4278 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
4279 Set_Etype
(Acc_Type
, Acc_Type
);
4280 Set_Directly_Designated_Type
(Acc_Type
, Etype
(P
));
4281 Set_Etype
(N
, Acc_Type
);
4282 end Analyze_Reference
;
4284 --------------------------------
4285 -- Analyze_Selected_Component --
4286 --------------------------------
4288 -- Prefix is a record type or a task or protected type. In the latter case,
4289 -- the selector must denote a visible entry.
4291 procedure Analyze_Selected_Component
(N
: Node_Id
) is
4292 Name
: constant Node_Id
:= Prefix
(N
);
4293 Sel
: constant Node_Id
:= Selector_Name
(N
);
4296 Has_Candidate
: Boolean := False;
4299 Pent
: Entity_Id
:= Empty
;
4300 Prefix_Type
: Entity_Id
;
4302 Type_To_Use
: Entity_Id
;
4303 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
4304 -- a class-wide type, we use its root type, whose components are
4305 -- present in the class-wide type.
4307 Is_Single_Concurrent_Object
: Boolean;
4308 -- Set True if the prefix is a single task or a single protected object
4310 procedure Find_Component_In_Instance
(Rec
: Entity_Id
);
4311 -- In an instance, a component of a private extension may not be visible
4312 -- while it was visible in the generic. Search candidate scope for a
4313 -- component with the proper identifier. This is only done if all other
4314 -- searches have failed. If a match is found, the Etype of both N and
4315 -- Sel are set from this component, and the entity of Sel is set to
4316 -- reference this component. If no match is found, Entity (Sel) remains
4317 -- unset. For a derived type that is an actual of the instance, the
4318 -- desired component may be found in any ancestor.
4320 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean;
4321 -- It is known that the parent of N denotes a subprogram call. Comp
4322 -- is an overloadable component of the concurrent type of the prefix.
4323 -- Determine whether all formals of the parent of N and Comp are mode
4324 -- conformant. If the parent node is not analyzed yet it may be an
4325 -- indexed component rather than a function call.
4327 function Has_Dereference
(Nod
: Node_Id
) return Boolean;
4328 -- Check whether prefix includes a dereference at any level.
4330 --------------------------------
4331 -- Find_Component_In_Instance --
4332 --------------------------------
4334 procedure Find_Component_In_Instance
(Rec
: Entity_Id
) is
4340 while Present
(Typ
) loop
4341 Comp
:= First_Component
(Typ
);
4342 while Present
(Comp
) loop
4343 if Chars
(Comp
) = Chars
(Sel
) then
4344 Set_Entity_With_Checks
(Sel
, Comp
);
4345 Set_Etype
(Sel
, Etype
(Comp
));
4346 Set_Etype
(N
, Etype
(Comp
));
4350 Next_Component
(Comp
);
4353 -- If not found, the component may be declared in the parent
4354 -- type or its full view, if any.
4356 if Is_Derived_Type
(Typ
) then
4359 if Is_Private_Type
(Typ
) then
4360 Typ
:= Full_View
(Typ
);
4368 -- If we fall through, no match, so no changes made
4371 end Find_Component_In_Instance
;
4373 ------------------------------
4374 -- Has_Mode_Conformant_Spec --
4375 ------------------------------
4377 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean is
4378 Comp_Param
: Entity_Id
;
4380 Param_Typ
: Entity_Id
;
4383 Comp_Param
:= First_Formal
(Comp
);
4385 if Nkind
(Parent
(N
)) = N_Indexed_Component
then
4386 Param
:= First
(Expressions
(Parent
(N
)));
4388 Param
:= First
(Parameter_Associations
(Parent
(N
)));
4391 while Present
(Comp_Param
)
4392 and then Present
(Param
)
4394 Param_Typ
:= Find_Parameter_Type
(Param
);
4396 if Present
(Param_Typ
)
4398 not Conforming_Types
4399 (Etype
(Comp_Param
), Param_Typ
, Mode_Conformant
)
4404 Next_Formal
(Comp_Param
);
4408 -- One of the specs has additional formals; there is no match, unless
4409 -- this may be an indexing of a parameterless call.
4411 -- Note that when expansion is disabled, the corresponding record
4412 -- type of synchronized types is not constructed, so that there is
4413 -- no point is attempting an interpretation as a prefixed call, as
4414 -- this is bound to fail because the primitive operations will not
4415 -- be properly located.
4417 if Present
(Comp_Param
) or else Present
(Param
) then
4418 if Needs_No_Actuals
(Comp
)
4419 and then Is_Array_Type
(Etype
(Comp
))
4420 and then not Expander_Active
4429 end Has_Mode_Conformant_Spec
;
4431 ---------------------
4432 -- Has_Dereference --
4433 ---------------------
4435 function Has_Dereference
(Nod
: Node_Id
) return Boolean is
4437 if Nkind
(Nod
) = N_Explicit_Dereference
then
4440 -- When expansion is disabled an explicit dereference may not have
4441 -- been inserted, but if this is an access type the indirection makes
4444 elsif Is_Access_Type
(Etype
(Nod
)) then
4447 elsif Nkind_In
(Nod
, N_Indexed_Component
, N_Selected_Component
) then
4448 return Has_Dereference
(Prefix
(Nod
));
4453 end Has_Dereference
;
4455 -- Start of processing for Analyze_Selected_Component
4458 Set_Etype
(N
, Any_Type
);
4460 if Is_Overloaded
(Name
) then
4461 Analyze_Overloaded_Selected_Component
(N
);
4464 elsif Etype
(Name
) = Any_Type
then
4465 Set_Entity
(Sel
, Any_Id
);
4466 Set_Etype
(Sel
, Any_Type
);
4470 Prefix_Type
:= Etype
(Name
);
4473 if Is_Access_Type
(Prefix_Type
) then
4475 -- A RACW object can never be used as prefix of a selected component
4476 -- since that means it is dereferenced without being a controlling
4477 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
4478 -- reporting an error, we must check whether this is actually a
4479 -- dispatching call in prefix form.
4481 if Is_Remote_Access_To_Class_Wide_Type
(Prefix_Type
)
4482 and then Comes_From_Source
(N
)
4484 if Try_Object_Operation
(N
) then
4488 ("invalid dereference of a remote access-to-class-wide value",
4492 -- Normal case of selected component applied to access type
4495 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4497 if Is_Entity_Name
(Name
) then
4498 Pent
:= Entity
(Name
);
4499 elsif Nkind
(Name
) = N_Selected_Component
4500 and then Is_Entity_Name
(Selector_Name
(Name
))
4502 Pent
:= Entity
(Selector_Name
(Name
));
4505 Prefix_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, Name
);
4508 -- If we have an explicit dereference of a remote access-to-class-wide
4509 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
4510 -- have to check for the case of a prefix that is a controlling operand
4511 -- of a prefixed dispatching call, as the dereference is legal in that
4512 -- case. Normally this condition is checked in Validate_Remote_Access_
4513 -- To_Class_Wide_Type, but we have to defer the checking for selected
4514 -- component prefixes because of the prefixed dispatching call case.
4515 -- Note that implicit dereferences are checked for this just above.
4517 elsif Nkind
(Name
) = N_Explicit_Dereference
4518 and then Is_Remote_Access_To_Class_Wide_Type
(Etype
(Prefix
(Name
)))
4519 and then Comes_From_Source
(N
)
4521 if Try_Object_Operation
(N
) then
4525 ("invalid dereference of a remote access-to-class-wide value",
4530 -- (Ada 2005): if the prefix is the limited view of a type, and
4531 -- the context already includes the full view, use the full view
4532 -- in what follows, either to retrieve a component of to find
4533 -- a primitive operation. If the prefix is an explicit dereference,
4534 -- set the type of the prefix to reflect this transformation.
4535 -- If the non-limited view is itself an incomplete type, get the
4536 -- full view if available.
4538 if From_Limited_With
(Prefix_Type
)
4539 and then Has_Non_Limited_View
(Prefix_Type
)
4541 Prefix_Type
:= Get_Full_View
(Non_Limited_View
(Prefix_Type
));
4543 if Nkind
(N
) = N_Explicit_Dereference
then
4544 Set_Etype
(Prefix
(N
), Prefix_Type
);
4548 if Ekind
(Prefix_Type
) = E_Private_Subtype
then
4549 Prefix_Type
:= Base_Type
(Prefix_Type
);
4552 Type_To_Use
:= Prefix_Type
;
4554 -- For class-wide types, use the entity list of the root type. This
4555 -- indirection is specially important for private extensions because
4556 -- only the root type get switched (not the class-wide type).
4558 if Is_Class_Wide_Type
(Prefix_Type
) then
4559 Type_To_Use
:= Root_Type
(Prefix_Type
);
4562 -- If the prefix is a single concurrent object, use its name in error
4563 -- messages, rather than that of its anonymous type.
4565 Is_Single_Concurrent_Object
:=
4566 Is_Concurrent_Type
(Prefix_Type
)
4567 and then Is_Internal_Name
(Chars
(Prefix_Type
))
4568 and then not Is_Derived_Type
(Prefix_Type
)
4569 and then Is_Entity_Name
(Name
);
4571 Comp
:= First_Entity
(Type_To_Use
);
4573 -- If the selector has an original discriminant, the node appears in
4574 -- an instance. Replace the discriminant with the corresponding one
4575 -- in the current discriminated type. For nested generics, this must
4576 -- be done transitively, so note the new original discriminant.
4578 if Nkind
(Sel
) = N_Identifier
4579 and then In_Instance
4580 and then Present
(Original_Discriminant
(Sel
))
4582 Comp
:= Find_Corresponding_Discriminant
(Sel
, Prefix_Type
);
4584 -- Mark entity before rewriting, for completeness and because
4585 -- subsequent semantic checks might examine the original node.
4587 Set_Entity
(Sel
, Comp
);
4588 Rewrite
(Selector_Name
(N
), New_Occurrence_Of
(Comp
, Sloc
(N
)));
4589 Set_Original_Discriminant
(Selector_Name
(N
), Comp
);
4590 Set_Etype
(N
, Etype
(Comp
));
4591 Check_Implicit_Dereference
(N
, Etype
(Comp
));
4593 if Is_Access_Type
(Etype
(Name
)) then
4594 Insert_Explicit_Dereference
(Name
);
4595 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4598 elsif Is_Record_Type
(Prefix_Type
) then
4600 -- Find component with given name. In an instance, if the node is
4601 -- known as a prefixed call, do not examine components whose
4602 -- visibility may be accidental.
4604 while Present
(Comp
) and then not Is_Prefixed_Call
(N
) loop
4605 if Chars
(Comp
) = Chars
(Sel
)
4606 and then Is_Visible_Component
(Comp
, N
)
4608 Set_Entity_With_Checks
(Sel
, Comp
);
4609 Set_Etype
(Sel
, Etype
(Comp
));
4611 if Ekind
(Comp
) = E_Discriminant
then
4612 if Is_Unchecked_Union
(Base_Type
(Prefix_Type
)) then
4614 ("cannot reference discriminant of unchecked union",
4618 if Is_Generic_Type
(Prefix_Type
)
4620 Is_Generic_Type
(Root_Type
(Prefix_Type
))
4622 Set_Original_Discriminant
(Sel
, Comp
);
4626 -- Resolve the prefix early otherwise it is not possible to
4627 -- build the actual subtype of the component: it may need
4628 -- to duplicate this prefix and duplication is only allowed
4629 -- on fully resolved expressions.
4633 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
4634 -- subtypes in a package specification.
4637 -- limited with Pkg;
4639 -- type Acc_Inc is access Pkg.T;
4641 -- N : Natural := X.all.Comp; -- ERROR, limited view
4642 -- end Pkg; -- Comp is not visible
4644 if Nkind
(Name
) = N_Explicit_Dereference
4645 and then From_Limited_With
(Etype
(Prefix
(Name
)))
4646 and then not Is_Potentially_Use_Visible
(Etype
(Name
))
4647 and then Nkind
(Parent
(Cunit_Entity
(Current_Sem_Unit
))) =
4648 N_Package_Specification
4651 ("premature usage of incomplete}", Prefix
(Name
),
4652 Etype
(Prefix
(Name
)));
4655 -- We never need an actual subtype for the case of a selection
4656 -- for a indexed component of a non-packed array, since in
4657 -- this case gigi generates all the checks and can find the
4658 -- necessary bounds information.
4660 -- We also do not need an actual subtype for the case of a
4661 -- first, last, length, or range attribute applied to a
4662 -- non-packed array, since gigi can again get the bounds in
4663 -- these cases (gigi cannot handle the packed case, since it
4664 -- has the bounds of the packed array type, not the original
4665 -- bounds of the type). However, if the prefix is itself a
4666 -- selected component, as in a.b.c (i), gigi may regard a.b.c
4667 -- as a dynamic-sized temporary, so we do generate an actual
4668 -- subtype for this case.
4670 Parent_N
:= Parent
(N
);
4672 if not Is_Packed
(Etype
(Comp
))
4674 ((Nkind
(Parent_N
) = N_Indexed_Component
4675 and then Nkind
(Name
) /= N_Selected_Component
)
4677 (Nkind
(Parent_N
) = N_Attribute_Reference
4679 Nam_In
(Attribute_Name
(Parent_N
), Name_First
,
4684 Set_Etype
(N
, Etype
(Comp
));
4686 -- If full analysis is not enabled, we do not generate an
4687 -- actual subtype, because in the absence of expansion
4688 -- reference to a formal of a protected type, for example,
4689 -- will not be properly transformed, and will lead to
4690 -- out-of-scope references in gigi.
4692 -- In all other cases, we currently build an actual subtype.
4693 -- It seems likely that many of these cases can be avoided,
4694 -- but right now, the front end makes direct references to the
4695 -- bounds (e.g. in generating a length check), and if we do
4696 -- not make an actual subtype, we end up getting a direct
4697 -- reference to a discriminant, which will not do.
4699 elsif Full_Analysis
then
4701 Build_Actual_Subtype_Of_Component
(Etype
(Comp
), N
);
4702 Insert_Action
(N
, Act_Decl
);
4704 if No
(Act_Decl
) then
4705 Set_Etype
(N
, Etype
(Comp
));
4708 -- Component type depends on discriminants. Enter the
4709 -- main attributes of the subtype.
4712 Subt
: constant Entity_Id
:=
4713 Defining_Identifier
(Act_Decl
);
4716 Set_Etype
(Subt
, Base_Type
(Etype
(Comp
)));
4717 Set_Ekind
(Subt
, Ekind
(Etype
(Comp
)));
4718 Set_Etype
(N
, Subt
);
4722 -- If Full_Analysis not enabled, just set the Etype
4725 Set_Etype
(N
, Etype
(Comp
));
4728 Check_Implicit_Dereference
(N
, Etype
(N
));
4732 -- If the prefix is a private extension, check only the visible
4733 -- components of the partial view. This must include the tag,
4734 -- which can appear in expanded code in a tag check.
4736 if Ekind
(Type_To_Use
) = E_Record_Type_With_Private
4737 and then Chars
(Selector_Name
(N
)) /= Name_uTag
4739 exit when Comp
= Last_Entity
(Type_To_Use
);
4745 -- Ada 2005 (AI-252): The selected component can be interpreted as
4746 -- a prefixed view of a subprogram. Depending on the context, this is
4747 -- either a name that can appear in a renaming declaration, or part
4748 -- of an enclosing call given in prefix form.
4750 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
4751 -- selected component should resolve to a name.
4753 if Ada_Version
>= Ada_2005
4754 and then Is_Tagged_Type
(Prefix_Type
)
4755 and then not Is_Concurrent_Type
(Prefix_Type
)
4757 if Nkind
(Parent
(N
)) = N_Generic_Association
4758 or else Nkind
(Parent
(N
)) = N_Requeue_Statement
4759 or else Nkind
(Parent
(N
)) = N_Subprogram_Renaming_Declaration
4761 if Find_Primitive_Operation
(N
) then
4765 elsif Try_Object_Operation
(N
) then
4769 -- If the transformation fails, it will be necessary to redo the
4770 -- analysis with all errors enabled, to indicate candidate
4771 -- interpretations and reasons for each failure ???
4775 elsif Is_Private_Type
(Prefix_Type
) then
4777 -- Allow access only to discriminants of the type. If the type has
4778 -- no full view, gigi uses the parent type for the components, so we
4779 -- do the same here.
4781 if No
(Full_View
(Prefix_Type
)) then
4782 Type_To_Use
:= Root_Type
(Base_Type
(Prefix_Type
));
4783 Comp
:= First_Entity
(Type_To_Use
);
4786 while Present
(Comp
) loop
4787 if Chars
(Comp
) = Chars
(Sel
) then
4788 if Ekind
(Comp
) = E_Discriminant
then
4789 Set_Entity_With_Checks
(Sel
, Comp
);
4790 Generate_Reference
(Comp
, Sel
);
4792 Set_Etype
(Sel
, Etype
(Comp
));
4793 Set_Etype
(N
, Etype
(Comp
));
4794 Check_Implicit_Dereference
(N
, Etype
(N
));
4796 if Is_Generic_Type
(Prefix_Type
)
4797 or else Is_Generic_Type
(Root_Type
(Prefix_Type
))
4799 Set_Original_Discriminant
(Sel
, Comp
);
4802 -- Before declaring an error, check whether this is tagged
4803 -- private type and a call to a primitive operation.
4805 elsif Ada_Version
>= Ada_2005
4806 and then Is_Tagged_Type
(Prefix_Type
)
4807 and then Try_Object_Operation
(N
)
4812 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4813 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
4814 Set_Entity
(Sel
, Any_Id
);
4815 Set_Etype
(N
, Any_Type
);
4824 elsif Is_Concurrent_Type
(Prefix_Type
) then
4826 -- Find visible operation with given name. For a protected type,
4827 -- the possible candidates are discriminants, entries or protected
4828 -- procedures. For a task type, the set can only include entries or
4829 -- discriminants if the task type is not an enclosing scope. If it
4830 -- is an enclosing scope (e.g. in an inner task) then all entities
4831 -- are visible, but the prefix must denote the enclosing scope, i.e.
4832 -- can only be a direct name or an expanded name.
4834 Set_Etype
(Sel
, Any_Type
);
4835 In_Scope
:= In_Open_Scopes
(Prefix_Type
);
4837 while Present
(Comp
) loop
4839 -- Do not examine private operations of the type if not within
4842 if Chars
(Comp
) = Chars
(Sel
) then
4843 if Is_Overloadable
(Comp
)
4845 or else Comp
/= First_Private_Entity
(Type_To_Use
))
4847 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
4849 -- If the prefix is tagged, the correct interpretation may
4850 -- lie in the primitive or class-wide operations of the
4851 -- type. Perform a simple conformance check to determine
4852 -- whether Try_Object_Operation should be invoked even if
4853 -- a visible entity is found.
4855 if Is_Tagged_Type
(Prefix_Type
)
4856 and then Nkind_In
(Parent
(N
), N_Function_Call
,
4857 N_Indexed_Component
,
4858 N_Procedure_Call_Statement
)
4859 and then Has_Mode_Conformant_Spec
(Comp
)
4861 Has_Candidate
:= True;
4864 -- Note: a selected component may not denote a component of a
4865 -- protected type (4.1.3(7)).
4867 elsif Ekind_In
(Comp
, E_Discriminant
, E_Entry_Family
)
4869 and then not Is_Protected_Type
(Prefix_Type
)
4870 and then Is_Entity_Name
(Name
))
4872 Set_Entity_With_Checks
(Sel
, Comp
);
4873 Generate_Reference
(Comp
, Sel
);
4875 -- The selector is not overloadable, so we have a candidate
4878 Has_Candidate
:= True;
4884 Set_Etype
(Sel
, Etype
(Comp
));
4885 Set_Etype
(N
, Etype
(Comp
));
4887 if Ekind
(Comp
) = E_Discriminant
then
4888 Set_Original_Discriminant
(Sel
, Comp
);
4891 -- For access type case, introduce explicit dereference for
4892 -- more uniform treatment of entry calls.
4894 if Is_Access_Type
(Etype
(Name
)) then
4895 Insert_Explicit_Dereference
(Name
);
4897 (Warn_On_Dereference
, "?d?implicit dereference", N
);
4903 exit when not In_Scope
4905 Comp
= First_Private_Entity
(Base_Type
(Prefix_Type
));
4908 -- If the scope is a current instance, the prefix cannot be an
4909 -- expression of the same type, unless the selector designates a
4910 -- public operation (otherwise that would represent an attempt to
4911 -- reach an internal entity of another synchronized object).
4912 -- This is legal if prefix is an access to such type and there is
4913 -- a dereference, or is a component with a dereferenced prefix.
4914 -- It is also legal if the prefix is a component of a task type,
4915 -- and the selector is one of the task operations.
4918 and then not Is_Entity_Name
(Name
)
4919 and then not Has_Dereference
(Name
)
4921 if Is_Task_Type
(Prefix_Type
)
4922 and then Present
(Entity
(Sel
))
4923 and then Ekind_In
(Entity
(Sel
), E_Entry
, E_Entry_Family
)
4929 ("invalid reference to internal operation of some object of "
4930 & "type &", N
, Type_To_Use
);
4931 Set_Entity
(Sel
, Any_Id
);
4932 Set_Etype
(Sel
, Any_Type
);
4937 -- If there is no visible entity with the given name or none of the
4938 -- visible entities are plausible interpretations, check whether
4939 -- there is some other primitive operation with that name.
4941 if Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Prefix_Type
) then
4942 if (Etype
(N
) = Any_Type
4943 or else not Has_Candidate
)
4944 and then Try_Object_Operation
(N
)
4948 -- If the context is not syntactically a procedure call, it
4949 -- may be a call to a primitive function declared outside of
4950 -- the synchronized type.
4952 -- If the context is a procedure call, there might still be
4953 -- an overloading between an entry and a primitive procedure
4954 -- declared outside of the synchronized type, called in prefix
4955 -- notation. This is harder to disambiguate because in one case
4956 -- the controlling formal is implicit ???
4958 elsif Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
4959 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
4960 and then Try_Object_Operation
(N
)
4965 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
4966 -- entry or procedure of a tagged concurrent type we must check
4967 -- if there are class-wide subprograms covering the primitive. If
4968 -- true then Try_Object_Operation reports the error.
4971 and then Is_Concurrent_Type
(Prefix_Type
)
4972 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
4974 -- Duplicate the call. This is required to avoid problems with
4975 -- the tree transformations performed by Try_Object_Operation.
4976 -- Set properly the parent of the copied call, because it is
4977 -- about to be reanalyzed.
4980 Par
: constant Node_Id
:= New_Copy_Tree
(Parent
(N
));
4983 Set_Parent
(Par
, Parent
(Parent
(N
)));
4985 if Try_Object_Operation
4986 (Sinfo
.Name
(Par
), CW_Test_Only
=> True)
4994 if Etype
(N
) = Any_Type
and then Is_Protected_Type
(Prefix_Type
) then
4996 -- Case of a prefix of a protected type: selector might denote
4997 -- an invisible private component.
4999 Comp
:= First_Private_Entity
(Base_Type
(Prefix_Type
));
5000 while Present
(Comp
) and then Chars
(Comp
) /= Chars
(Sel
) loop
5004 if Present
(Comp
) then
5005 if Is_Single_Concurrent_Object
then
5006 Error_Msg_Node_2
:= Entity
(Name
);
5007 Error_Msg_NE
("invisible selector& for &", N
, Sel
);
5010 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
5011 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
5017 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
5022 Error_Msg_NE
("invalid prefix in selected component&", N
, Sel
);
5025 -- If N still has no type, the component is not defined in the prefix
5027 if Etype
(N
) = Any_Type
then
5029 if Is_Single_Concurrent_Object
then
5030 Error_Msg_Node_2
:= Entity
(Name
);
5031 Error_Msg_NE
("no selector& for&", N
, Sel
);
5033 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
5035 -- If this is a derived formal type, the parent may have different
5036 -- visibility at this point. Try for an inherited component before
5037 -- reporting an error.
5039 elsif Is_Generic_Type
(Prefix_Type
)
5040 and then Ekind
(Prefix_Type
) = E_Record_Type_With_Private
5041 and then Prefix_Type
/= Etype
(Prefix_Type
)
5042 and then Is_Record_Type
(Etype
(Prefix_Type
))
5044 Set_Etype
(Prefix
(N
), Etype
(Prefix_Type
));
5045 Analyze_Selected_Component
(N
);
5048 -- Similarly, if this is the actual for a formal derived type, or
5049 -- a derived type thereof, the component inherited from the generic
5050 -- parent may not be visible in the actual, but the selected
5051 -- component is legal. Climb up the derivation chain of the generic
5052 -- parent type until we find the proper ancestor type.
5054 elsif In_Instance
and then Is_Tagged_Type
(Prefix_Type
) then
5056 Par
: Entity_Id
:= Prefix_Type
;
5058 -- Climb up derivation chain to generic actual subtype
5060 while not Is_Generic_Actual_Type
(Par
) loop
5061 if Ekind
(Par
) = E_Record_Type
then
5062 Par
:= Parent_Subtype
(Par
);
5065 exit when Par
= Etype
(Par
);
5070 if Present
(Par
) and then Is_Generic_Actual_Type
(Par
) then
5072 -- Now look for component in ancestor types
5074 Par
:= Generic_Parent_Type
(Declaration_Node
(Par
));
5076 Find_Component_In_Instance
(Par
);
5077 exit when Present
(Entity
(Sel
))
5078 or else Par
= Etype
(Par
);
5082 -- Another special case: the type is an extension of a private
5083 -- type T, is an actual in an instance, and we are in the body
5084 -- of the instance, so the generic body had a full view of the
5085 -- type declaration for T or of some ancestor that defines the
5086 -- component in question.
5088 elsif Is_Derived_Type
(Type_To_Use
)
5089 and then Used_As_Generic_Actual
(Type_To_Use
)
5090 and then In_Instance_Body
5092 Find_Component_In_Instance
(Parent_Subtype
(Type_To_Use
));
5094 -- In ASIS mode the generic parent type may be absent. Examine
5095 -- the parent type directly for a component that may have been
5096 -- visible in a parent generic unit.
5098 elsif Is_Derived_Type
(Prefix_Type
) then
5099 Par
:= Etype
(Prefix_Type
);
5100 Find_Component_In_Instance
(Par
);
5104 -- The search above must have eventually succeeded, since the
5105 -- selected component was legal in the generic.
5107 if No
(Entity
(Sel
)) then
5108 raise Program_Error
;
5113 -- Component not found, specialize error message when appropriate
5116 if Ekind
(Prefix_Type
) = E_Record_Subtype
then
5118 -- Check whether this is a component of the base type which
5119 -- is absent from a statically constrained subtype. This will
5120 -- raise constraint error at run time, but is not a compile-
5121 -- time error. When the selector is illegal for base type as
5122 -- well fall through and generate a compilation error anyway.
5124 Comp
:= First_Component
(Base_Type
(Prefix_Type
));
5125 while Present
(Comp
) loop
5126 if Chars
(Comp
) = Chars
(Sel
)
5127 and then Is_Visible_Component
(Comp
)
5129 Set_Entity_With_Checks
(Sel
, Comp
);
5130 Generate_Reference
(Comp
, Sel
);
5131 Set_Etype
(Sel
, Etype
(Comp
));
5132 Set_Etype
(N
, Etype
(Comp
));
5134 -- Emit appropriate message. The node will be replaced
5135 -- by an appropriate raise statement.
5137 -- Note that in SPARK mode, as with all calls to apply a
5138 -- compile time constraint error, this will be made into
5139 -- an error to simplify the processing of the formal
5140 -- verification backend.
5142 Apply_Compile_Time_Constraint_Error
5143 (N
, "component not present in }??",
5144 CE_Discriminant_Check_Failed
,
5145 Ent
=> Prefix_Type
, Rep
=> False);
5147 Set_Raises_Constraint_Error
(N
);
5151 Next_Component
(Comp
);
5156 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
5157 Error_Msg_NE
("no selector& for}", N
, Sel
);
5159 -- Add information in the case of an incomplete prefix
5161 if Is_Incomplete_Type
(Type_To_Use
) then
5163 Inc
: constant Entity_Id
:= First_Subtype
(Type_To_Use
);
5166 if From_Limited_With
(Scope
(Type_To_Use
)) then
5168 ("\limited view of& has no components", N
, Inc
);
5172 ("\premature usage of incomplete type&", N
, Inc
);
5174 if Nkind
(Parent
(Inc
)) =
5175 N_Incomplete_Type_Declaration
5177 -- Record location of premature use in entity so that
5178 -- a continuation message is generated when the
5179 -- completion is seen.
5181 Set_Premature_Use
(Parent
(Inc
), N
);
5187 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
5190 Set_Entity
(Sel
, Any_Id
);
5191 Set_Etype
(Sel
, Any_Type
);
5193 end Analyze_Selected_Component
;
5195 ---------------------------
5196 -- Analyze_Short_Circuit --
5197 ---------------------------
5199 procedure Analyze_Short_Circuit
(N
: Node_Id
) is
5200 L
: constant Node_Id
:= Left_Opnd
(N
);
5201 R
: constant Node_Id
:= Right_Opnd
(N
);
5206 Analyze_Expression
(L
);
5207 Analyze_Expression
(R
);
5208 Set_Etype
(N
, Any_Type
);
5210 if not Is_Overloaded
(L
) then
5211 if Root_Type
(Etype
(L
)) = Standard_Boolean
5212 and then Has_Compatible_Type
(R
, Etype
(L
))
5214 Add_One_Interp
(N
, Etype
(L
), Etype
(L
));
5218 Get_First_Interp
(L
, Ind
, It
);
5219 while Present
(It
.Typ
) loop
5220 if Root_Type
(It
.Typ
) = Standard_Boolean
5221 and then Has_Compatible_Type
(R
, It
.Typ
)
5223 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
5226 Get_Next_Interp
(Ind
, It
);
5230 -- Here we have failed to find an interpretation. Clearly we know that
5231 -- it is not the case that both operands can have an interpretation of
5232 -- Boolean, but this is by far the most likely intended interpretation.
5233 -- So we simply resolve both operands as Booleans, and at least one of
5234 -- these resolutions will generate an error message, and we do not need
5235 -- to give another error message on the short circuit operation itself.
5237 if Etype
(N
) = Any_Type
then
5238 Resolve
(L
, Standard_Boolean
);
5239 Resolve
(R
, Standard_Boolean
);
5240 Set_Etype
(N
, Standard_Boolean
);
5242 end Analyze_Short_Circuit
;
5248 procedure Analyze_Slice
(N
: Node_Id
) is
5249 D
: constant Node_Id
:= Discrete_Range
(N
);
5250 P
: constant Node_Id
:= Prefix
(N
);
5251 Array_Type
: Entity_Id
;
5252 Index_Type
: Entity_Id
;
5254 procedure Analyze_Overloaded_Slice
;
5255 -- If the prefix is overloaded, select those interpretations that
5256 -- yield a one-dimensional array type.
5258 ------------------------------
5259 -- Analyze_Overloaded_Slice --
5260 ------------------------------
5262 procedure Analyze_Overloaded_Slice
is
5268 Set_Etype
(N
, Any_Type
);
5270 Get_First_Interp
(P
, I
, It
);
5271 while Present
(It
.Nam
) loop
5274 if Is_Access_Type
(Typ
) then
5275 Typ
:= Designated_Type
(Typ
);
5277 (Warn_On_Dereference
, "?d?implicit dereference", N
);
5280 if Is_Array_Type
(Typ
)
5281 and then Number_Dimensions
(Typ
) = 1
5282 and then Has_Compatible_Type
(D
, Etype
(First_Index
(Typ
)))
5284 Add_One_Interp
(N
, Typ
, Typ
);
5287 Get_Next_Interp
(I
, It
);
5290 if Etype
(N
) = Any_Type
then
5291 Error_Msg_N
("expect array type in prefix of slice", N
);
5293 end Analyze_Overloaded_Slice
;
5295 -- Start of processing for Analyze_Slice
5298 if Comes_From_Source
(N
) then
5299 Check_SPARK_05_Restriction
("slice is not allowed", N
);
5305 if Is_Overloaded
(P
) then
5306 Analyze_Overloaded_Slice
;
5309 Array_Type
:= Etype
(P
);
5310 Set_Etype
(N
, Any_Type
);
5312 if Is_Access_Type
(Array_Type
) then
5313 Array_Type
:= Designated_Type
(Array_Type
);
5314 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
5317 if not Is_Array_Type
(Array_Type
) then
5318 Wrong_Type
(P
, Any_Array
);
5320 elsif Number_Dimensions
(Array_Type
) > 1 then
5322 ("type is not one-dimensional array in slice prefix", N
);
5325 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
5326 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
5328 Index_Type
:= Etype
(First_Index
(Array_Type
));
5331 if not Has_Compatible_Type
(D
, Index_Type
) then
5332 Wrong_Type
(D
, Index_Type
);
5334 Set_Etype
(N
, Array_Type
);
5340 -----------------------------
5341 -- Analyze_Type_Conversion --
5342 -----------------------------
5344 procedure Analyze_Type_Conversion
(N
: Node_Id
) is
5345 Expr
: constant Node_Id
:= Expression
(N
);
5349 -- If Conversion_OK is set, then the Etype is already set, and the only
5350 -- processing required is to analyze the expression. This is used to
5351 -- construct certain "illegal" conversions which are not allowed by Ada
5352 -- semantics, but can be handled by Gigi, see Sinfo for further details.
5354 if Conversion_OK
(N
) then
5359 -- Otherwise full type analysis is required, as well as some semantic
5360 -- checks to make sure the argument of the conversion is appropriate.
5362 Find_Type
(Subtype_Mark
(N
));
5363 Typ
:= Entity
(Subtype_Mark
(N
));
5365 Check_Fully_Declared
(Typ
, N
);
5366 Analyze_Expression
(Expr
);
5367 Validate_Remote_Type_Type_Conversion
(N
);
5369 -- Only remaining step is validity checks on the argument. These
5370 -- are skipped if the conversion does not come from the source.
5372 if not Comes_From_Source
(N
) then
5375 -- If there was an error in a generic unit, no need to replicate the
5376 -- error message. Conversely, constant-folding in the generic may
5377 -- transform the argument of a conversion into a string literal, which
5378 -- is legal. Therefore the following tests are not performed in an
5379 -- instance. The same applies to an inlined body.
5381 elsif In_Instance
or In_Inlined_Body
then
5384 elsif Nkind
(Expr
) = N_Null
then
5385 Error_Msg_N
("argument of conversion cannot be null", N
);
5386 Error_Msg_N
("\use qualified expression instead", N
);
5387 Set_Etype
(N
, Any_Type
);
5389 elsif Nkind
(Expr
) = N_Aggregate
then
5390 Error_Msg_N
("argument of conversion cannot be aggregate", N
);
5391 Error_Msg_N
("\use qualified expression instead", N
);
5393 elsif Nkind
(Expr
) = N_Allocator
then
5394 Error_Msg_N
("argument of conversion cannot be an allocator", N
);
5395 Error_Msg_N
("\use qualified expression instead", N
);
5397 elsif Nkind
(Expr
) = N_String_Literal
then
5398 Error_Msg_N
("argument of conversion cannot be string literal", N
);
5399 Error_Msg_N
("\use qualified expression instead", N
);
5401 elsif Nkind
(Expr
) = N_Character_Literal
then
5402 if Ada_Version
= Ada_83
then
5403 Resolve
(Expr
, Typ
);
5405 Error_Msg_N
("argument of conversion cannot be character literal",
5407 Error_Msg_N
("\use qualified expression instead", N
);
5410 elsif Nkind
(Expr
) = N_Attribute_Reference
5411 and then Nam_In
(Attribute_Name
(Expr
), Name_Access
,
5412 Name_Unchecked_Access
,
5413 Name_Unrestricted_Access
)
5415 Error_Msg_N
("argument of conversion cannot be access", N
);
5416 Error_Msg_N
("\use qualified expression instead", N
);
5419 -- A formal parameter of a specific tagged type whose related subprogram
5420 -- is subject to pragma Extensions_Visible with value "False" cannot
5421 -- appear in a class-wide conversion (SPARK RM 6.1.7(3)). Do not check
5422 -- internally generated expressions.
5424 if Is_Class_Wide_Type
(Typ
)
5425 and then Comes_From_Source
(Expr
)
5426 and then Is_EVF_Expression
(Expr
)
5429 ("formal parameter cannot be converted to class-wide type when "
5430 & "Extensions_Visible is False", Expr
);
5432 end Analyze_Type_Conversion
;
5434 ----------------------
5435 -- Analyze_Unary_Op --
5436 ----------------------
5438 procedure Analyze_Unary_Op
(N
: Node_Id
) is
5439 R
: constant Node_Id
:= Right_Opnd
(N
);
5440 Op_Id
: Entity_Id
:= Entity
(N
);
5443 Set_Etype
(N
, Any_Type
);
5444 Candidate_Type
:= Empty
;
5446 Analyze_Expression
(R
);
5448 if Present
(Op_Id
) then
5449 if Ekind
(Op_Id
) = E_Operator
then
5450 Find_Unary_Types
(R
, Op_Id
, N
);
5452 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5456 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
5457 while Present
(Op_Id
) loop
5458 if Ekind
(Op_Id
) = E_Operator
then
5459 if No
(Next_Entity
(First_Entity
(Op_Id
))) then
5460 Find_Unary_Types
(R
, Op_Id
, N
);
5463 elsif Is_Overloadable
(Op_Id
) then
5464 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
5467 Op_Id
:= Homonym
(Op_Id
);
5472 end Analyze_Unary_Op
;
5474 ----------------------------------
5475 -- Analyze_Unchecked_Expression --
5476 ----------------------------------
5478 procedure Analyze_Unchecked_Expression
(N
: Node_Id
) is
5480 Analyze
(Expression
(N
), Suppress
=> All_Checks
);
5481 Set_Etype
(N
, Etype
(Expression
(N
)));
5482 Save_Interps
(Expression
(N
), N
);
5483 end Analyze_Unchecked_Expression
;
5485 ---------------------------------------
5486 -- Analyze_Unchecked_Type_Conversion --
5487 ---------------------------------------
5489 procedure Analyze_Unchecked_Type_Conversion
(N
: Node_Id
) is
5491 Find_Type
(Subtype_Mark
(N
));
5492 Analyze_Expression
(Expression
(N
));
5493 Set_Etype
(N
, Entity
(Subtype_Mark
(N
)));
5494 end Analyze_Unchecked_Type_Conversion
;
5496 ------------------------------------
5497 -- Analyze_User_Defined_Binary_Op --
5498 ------------------------------------
5500 procedure Analyze_User_Defined_Binary_Op
5505 -- Only do analysis if the operator Comes_From_Source, since otherwise
5506 -- the operator was generated by the expander, and all such operators
5507 -- always refer to the operators in package Standard.
5509 if Comes_From_Source
(N
) then
5511 F1
: constant Entity_Id
:= First_Formal
(Op_Id
);
5512 F2
: constant Entity_Id
:= Next_Formal
(F1
);
5515 -- Verify that Op_Id is a visible binary function. Note that since
5516 -- we know Op_Id is overloaded, potentially use visible means use
5517 -- visible for sure (RM 9.4(11)).
5519 if Ekind
(Op_Id
) = E_Function
5520 and then Present
(F2
)
5521 and then (Is_Immediately_Visible
(Op_Id
)
5522 or else Is_Potentially_Use_Visible
(Op_Id
))
5523 and then Has_Compatible_Type
(Left_Opnd
(N
), Etype
(F1
))
5524 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F2
))
5526 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5528 -- If the left operand is overloaded, indicate that the current
5529 -- type is a viable candidate. This is redundant in most cases,
5530 -- but for equality and comparison operators where the context
5531 -- does not impose a type on the operands, setting the proper
5532 -- type is necessary to avoid subsequent ambiguities during
5533 -- resolution, when both user-defined and predefined operators
5534 -- may be candidates.
5536 if Is_Overloaded
(Left_Opnd
(N
)) then
5537 Set_Etype
(Left_Opnd
(N
), Etype
(F1
));
5540 if Debug_Flag_E
then
5541 Write_Str
("user defined operator ");
5542 Write_Name
(Chars
(Op_Id
));
5543 Write_Str
(" on node ");
5544 Write_Int
(Int
(N
));
5550 end Analyze_User_Defined_Binary_Op
;
5552 -----------------------------------
5553 -- Analyze_User_Defined_Unary_Op --
5554 -----------------------------------
5556 procedure Analyze_User_Defined_Unary_Op
5561 -- Only do analysis if the operator Comes_From_Source, since otherwise
5562 -- the operator was generated by the expander, and all such operators
5563 -- always refer to the operators in package Standard.
5565 if Comes_From_Source
(N
) then
5567 F
: constant Entity_Id
:= First_Formal
(Op_Id
);
5570 -- Verify that Op_Id is a visible unary function. Note that since
5571 -- we know Op_Id is overloaded, potentially use visible means use
5572 -- visible for sure (RM 9.4(11)).
5574 if Ekind
(Op_Id
) = E_Function
5575 and then No
(Next_Formal
(F
))
5576 and then (Is_Immediately_Visible
(Op_Id
)
5577 or else Is_Potentially_Use_Visible
(Op_Id
))
5578 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F
))
5580 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5584 end Analyze_User_Defined_Unary_Op
;
5586 ---------------------------
5587 -- Check_Arithmetic_Pair --
5588 ---------------------------
5590 procedure Check_Arithmetic_Pair
5591 (T1
, T2
: Entity_Id
;
5595 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
5597 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean;
5598 -- Check whether the fixed-point type Typ has a user-defined operator
5599 -- (multiplication or division) that should hide the corresponding
5600 -- predefined operator. Used to implement Ada 2005 AI-264, to make
5601 -- such operators more visible and therefore useful.
5603 -- If the name of the operation is an expanded name with prefix
5604 -- Standard, the predefined universal fixed operator is available,
5605 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
5607 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
;
5608 -- Get specific type (i.e. non-universal type if there is one)
5614 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean is
5615 Bas
: constant Entity_Id
:= Base_Type
(Typ
);
5621 -- If the universal_fixed operation is given explicitly the rule
5622 -- concerning primitive operations of the type do not apply.
5624 if Nkind
(N
) = N_Function_Call
5625 and then Nkind
(Name
(N
)) = N_Expanded_Name
5626 and then Entity
(Prefix
(Name
(N
))) = Standard_Standard
5631 -- The operation is treated as primitive if it is declared in the
5632 -- same scope as the type, and therefore on the same entity chain.
5634 Ent
:= Next_Entity
(Typ
);
5635 while Present
(Ent
) loop
5636 if Chars
(Ent
) = Chars
(Op
) then
5637 F1
:= First_Formal
(Ent
);
5638 F2
:= Next_Formal
(F1
);
5640 -- The operation counts as primitive if either operand or
5641 -- result are of the given base type, and both operands are
5642 -- fixed point types.
5644 if (Base_Type
(Etype
(F1
)) = Bas
5645 and then Is_Fixed_Point_Type
(Etype
(F2
)))
5648 (Base_Type
(Etype
(F2
)) = Bas
5649 and then Is_Fixed_Point_Type
(Etype
(F1
)))
5652 (Base_Type
(Etype
(Ent
)) = Bas
5653 and then Is_Fixed_Point_Type
(Etype
(F1
))
5654 and then Is_Fixed_Point_Type
(Etype
(F2
)))
5670 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
is
5672 if T1
= Universal_Integer
or else T1
= Universal_Real
then
5673 return Base_Type
(T2
);
5675 return Base_Type
(T1
);
5679 -- Start of processing for Check_Arithmetic_Pair
5682 if Nam_In
(Op_Name
, Name_Op_Add
, Name_Op_Subtract
) then
5683 if Is_Numeric_Type
(T1
)
5684 and then Is_Numeric_Type
(T2
)
5685 and then (Covers
(T1
=> T1
, T2
=> T2
)
5687 Covers
(T1
=> T2
, T2
=> T1
))
5689 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5692 elsif Nam_In
(Op_Name
, Name_Op_Multiply
, Name_Op_Divide
) then
5693 if Is_Fixed_Point_Type
(T1
)
5694 and then (Is_Fixed_Point_Type
(T2
) or else T2
= Universal_Real
)
5696 -- If Treat_Fixed_As_Integer is set then the Etype is already set
5697 -- and no further processing is required (this is the case of an
5698 -- operator constructed by Exp_Fixd for a fixed point operation)
5699 -- Otherwise add one interpretation with universal fixed result
5700 -- If the operator is given in functional notation, it comes
5701 -- from source and Fixed_As_Integer cannot apply.
5703 if (Nkind
(N
) not in N_Op
5704 or else not Treat_Fixed_As_Integer
(N
))
5706 (not Has_Fixed_Op
(T1
, Op_Id
)
5707 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
5709 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
5712 elsif Is_Fixed_Point_Type
(T2
)
5713 and then (Nkind
(N
) not in N_Op
5714 or else not Treat_Fixed_As_Integer
(N
))
5715 and then T1
= Universal_Real
5717 (not Has_Fixed_Op
(T1
, Op_Id
)
5718 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
5720 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
5722 elsif Is_Numeric_Type
(T1
)
5723 and then Is_Numeric_Type
(T2
)
5724 and then (Covers
(T1
=> T1
, T2
=> T2
)
5726 Covers
(T1
=> T2
, T2
=> T1
))
5728 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5730 elsif Is_Fixed_Point_Type
(T1
)
5731 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5732 or else T2
= Universal_Integer
)
5734 Add_One_Interp
(N
, Op_Id
, T1
);
5736 elsif T2
= Universal_Real
5737 and then Base_Type
(T1
) = Base_Type
(Standard_Integer
)
5738 and then Op_Name
= Name_Op_Multiply
5740 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
5742 elsif T1
= Universal_Real
5743 and then Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5745 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
5747 elsif Is_Fixed_Point_Type
(T2
)
5748 and then (Base_Type
(T1
) = Base_Type
(Standard_Integer
)
5749 or else T1
= Universal_Integer
)
5750 and then Op_Name
= Name_Op_Multiply
5752 Add_One_Interp
(N
, Op_Id
, T2
);
5754 elsif T1
= Universal_Real
and then T2
= Universal_Integer
then
5755 Add_One_Interp
(N
, Op_Id
, T1
);
5757 elsif T2
= Universal_Real
5758 and then T1
= Universal_Integer
5759 and then Op_Name
= Name_Op_Multiply
5761 Add_One_Interp
(N
, Op_Id
, T2
);
5764 elsif Op_Name
= Name_Op_Mod
or else Op_Name
= Name_Op_Rem
then
5766 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
5767 -- set does not require any special processing, since the Etype is
5768 -- already set (case of operation constructed by Exp_Fixed).
5770 if Is_Integer_Type
(T1
)
5771 and then (Covers
(T1
=> T1
, T2
=> T2
)
5773 Covers
(T1
=> T2
, T2
=> T1
))
5775 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5778 elsif Op_Name
= Name_Op_Expon
then
5779 if Is_Numeric_Type
(T1
)
5780 and then not Is_Fixed_Point_Type
(T1
)
5781 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5782 or else T2
= Universal_Integer
)
5784 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
5787 else pragma Assert
(Nkind
(N
) in N_Op_Shift
);
5789 -- If not one of the predefined operators, the node may be one
5790 -- of the intrinsic functions. Its kind is always specific, and
5791 -- we can use it directly, rather than the name of the operation.
5793 if Is_Integer_Type
(T1
)
5794 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5795 or else T2
= Universal_Integer
)
5797 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
5800 end Check_Arithmetic_Pair
;
5802 -------------------------------
5803 -- Check_Misspelled_Selector --
5804 -------------------------------
5806 procedure Check_Misspelled_Selector
5807 (Prefix
: Entity_Id
;
5810 Max_Suggestions
: constant := 2;
5811 Nr_Of_Suggestions
: Natural := 0;
5813 Suggestion_1
: Entity_Id
:= Empty
;
5814 Suggestion_2
: Entity_Id
:= Empty
;
5819 -- All the components of the prefix of selector Sel are matched against
5820 -- Sel and a count is maintained of possible misspellings. When at
5821 -- the end of the analysis there are one or two (not more) possible
5822 -- misspellings, these misspellings will be suggested as possible
5825 if not (Is_Private_Type
(Prefix
) or else Is_Record_Type
(Prefix
)) then
5827 -- Concurrent types should be handled as well ???
5832 Comp
:= First_Entity
(Prefix
);
5833 while Nr_Of_Suggestions
<= Max_Suggestions
and then Present
(Comp
) loop
5834 if Is_Visible_Component
(Comp
) then
5835 if Is_Bad_Spelling_Of
(Chars
(Comp
), Chars
(Sel
)) then
5836 Nr_Of_Suggestions
:= Nr_Of_Suggestions
+ 1;
5838 case Nr_Of_Suggestions
is
5839 when 1 => Suggestion_1
:= Comp
;
5840 when 2 => Suggestion_2
:= Comp
;
5841 when others => null;
5846 Comp
:= Next_Entity
(Comp
);
5849 -- Report at most two suggestions
5851 if Nr_Of_Suggestions
= 1 then
5852 Error_Msg_NE
-- CODEFIX
5853 ("\possible misspelling of&", Sel
, Suggestion_1
);
5855 elsif Nr_Of_Suggestions
= 2 then
5856 Error_Msg_Node_2
:= Suggestion_2
;
5857 Error_Msg_NE
-- CODEFIX
5858 ("\possible misspelling of& or&", Sel
, Suggestion_1
);
5860 end Check_Misspelled_Selector
;
5862 ----------------------
5863 -- Defined_In_Scope --
5864 ----------------------
5866 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean
5868 S1
: constant Entity_Id
:= Scope
(Base_Type
(T
));
5871 or else (S1
= System_Aux_Id
and then S
= Scope
(S1
));
5872 end Defined_In_Scope
;
5878 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
) is
5884 Void_Interp_Seen
: Boolean := False;
5887 pragma Warnings
(Off
, Boolean);
5890 if Ada_Version
>= Ada_2005
then
5891 Actual
:= First_Actual
(N
);
5892 while Present
(Actual
) loop
5894 -- Ada 2005 (AI-50217): Post an error in case of premature
5895 -- usage of an entity from the limited view.
5897 if not Analyzed
(Etype
(Actual
))
5898 and then From_Limited_With
(Etype
(Actual
))
5900 Error_Msg_Qual_Level
:= 1;
5902 ("missing with_clause for scope of imported type&",
5903 Actual
, Etype
(Actual
));
5904 Error_Msg_Qual_Level
:= 0;
5907 Next_Actual
(Actual
);
5911 -- Before listing the possible candidates, check whether this is
5912 -- a prefix of a selected component that has been rewritten as a
5913 -- parameterless function call because there is a callable candidate
5914 -- interpretation. If there is a hidden package in the list of homonyms
5915 -- of the function name (bad programming style in any case) suggest that
5916 -- this is the intended entity.
5918 if No
(Parameter_Associations
(N
))
5919 and then Nkind
(Parent
(N
)) = N_Selected_Component
5920 and then Nkind
(Parent
(Parent
(N
))) in N_Declaration
5921 and then Is_Overloaded
(Nam
)
5927 Ent
:= Current_Entity
(Nam
);
5928 while Present
(Ent
) loop
5929 if Ekind
(Ent
) = E_Package
then
5931 ("no legal interpretations as function call,!", Nam
);
5932 Error_Msg_NE
("\package& is not visible", N
, Ent
);
5934 Rewrite
(Parent
(N
),
5935 New_Occurrence_Of
(Any_Type
, Sloc
(N
)));
5939 Ent
:= Homonym
(Ent
);
5944 -- Analyze each candidate call again, with full error reporting for
5948 ("no candidate interpretations match the actuals:!", Nam
);
5949 Err_Mode
:= All_Errors_Mode
;
5950 All_Errors_Mode
:= True;
5952 -- If this is a call to an operation of a concurrent type,
5953 -- the failed interpretations have been removed from the
5954 -- name. Recover them to provide full diagnostics.
5956 if Nkind
(Parent
(Nam
)) = N_Selected_Component
then
5957 Set_Entity
(Nam
, Empty
);
5958 New_Nam
:= New_Copy_Tree
(Parent
(Nam
));
5959 Set_Is_Overloaded
(New_Nam
, False);
5960 Set_Is_Overloaded
(Selector_Name
(New_Nam
), False);
5961 Set_Parent
(New_Nam
, Parent
(Parent
(Nam
)));
5962 Analyze_Selected_Component
(New_Nam
);
5963 Get_First_Interp
(Selector_Name
(New_Nam
), X
, It
);
5965 Get_First_Interp
(Nam
, X
, It
);
5968 while Present
(It
.Nam
) loop
5969 if Etype
(It
.Nam
) = Standard_Void_Type
then
5970 Void_Interp_Seen
:= True;
5973 Analyze_One_Call
(N
, It
.Nam
, True, Success
);
5974 Get_Next_Interp
(X
, It
);
5977 if Nkind
(N
) = N_Function_Call
then
5978 Get_First_Interp
(Nam
, X
, It
);
5979 while Present
(It
.Nam
) loop
5980 if Ekind_In
(It
.Nam
, E_Function
, E_Operator
) then
5983 Get_Next_Interp
(X
, It
);
5987 -- If all interpretations are procedures, this deserves a
5988 -- more precise message. Ditto if this appears as the prefix
5989 -- of a selected component, which may be a lexical error.
5992 ("\context requires function call, found procedure name", Nam
);
5994 if Nkind
(Parent
(N
)) = N_Selected_Component
5995 and then N
= Prefix
(Parent
(N
))
5997 Error_Msg_N
-- CODEFIX
5998 ("\period should probably be semicolon", Parent
(N
));
6001 elsif Nkind
(N
) = N_Procedure_Call_Statement
6002 and then not Void_Interp_Seen
6005 "\function name found in procedure call", Nam
);
6008 All_Errors_Mode
:= Err_Mode
;
6011 ---------------------------
6012 -- Find_Arithmetic_Types --
6013 ---------------------------
6015 procedure Find_Arithmetic_Types
6020 Index1
: Interp_Index
;
6021 Index2
: Interp_Index
;
6025 procedure Check_Right_Argument
(T
: Entity_Id
);
6026 -- Check right operand of operator
6028 --------------------------
6029 -- Check_Right_Argument --
6030 --------------------------
6032 procedure Check_Right_Argument
(T
: Entity_Id
) is
6034 if not Is_Overloaded
(R
) then
6035 Check_Arithmetic_Pair
(T
, Etype
(R
), Op_Id
, N
);
6037 Get_First_Interp
(R
, Index2
, It2
);
6038 while Present
(It2
.Typ
) loop
6039 Check_Arithmetic_Pair
(T
, It2
.Typ
, Op_Id
, N
);
6040 Get_Next_Interp
(Index2
, It2
);
6043 end Check_Right_Argument
;
6045 -- Start of processing for Find_Arithmetic_Types
6048 if not Is_Overloaded
(L
) then
6049 Check_Right_Argument
(Etype
(L
));
6052 Get_First_Interp
(L
, Index1
, It1
);
6053 while Present
(It1
.Typ
) loop
6054 Check_Right_Argument
(It1
.Typ
);
6055 Get_Next_Interp
(Index1
, It1
);
6059 end Find_Arithmetic_Types
;
6061 ------------------------
6062 -- Find_Boolean_Types --
6063 ------------------------
6065 procedure Find_Boolean_Types
6070 Index
: Interp_Index
;
6073 procedure Check_Numeric_Argument
(T
: Entity_Id
);
6074 -- Special case for logical operations one of whose operands is an
6075 -- integer literal. If both are literal the result is any modular type.
6077 ----------------------------
6078 -- Check_Numeric_Argument --
6079 ----------------------------
6081 procedure Check_Numeric_Argument
(T
: Entity_Id
) is
6083 if T
= Universal_Integer
then
6084 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
6086 elsif Is_Modular_Integer_Type
(T
) then
6087 Add_One_Interp
(N
, Op_Id
, T
);
6089 end Check_Numeric_Argument
;
6091 -- Start of processing for Find_Boolean_Types
6094 if not Is_Overloaded
(L
) then
6095 if Etype
(L
) = Universal_Integer
6096 or else Etype
(L
) = Any_Modular
6098 if not Is_Overloaded
(R
) then
6099 Check_Numeric_Argument
(Etype
(R
));
6102 Get_First_Interp
(R
, Index
, It
);
6103 while Present
(It
.Typ
) loop
6104 Check_Numeric_Argument
(It
.Typ
);
6105 Get_Next_Interp
(Index
, It
);
6109 -- If operands are aggregates, we must assume that they may be
6110 -- boolean arrays, and leave disambiguation for the second pass.
6111 -- If only one is an aggregate, verify that the other one has an
6112 -- interpretation as a boolean array
6114 elsif Nkind
(L
) = N_Aggregate
then
6115 if Nkind
(R
) = N_Aggregate
then
6116 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
6118 elsif not Is_Overloaded
(R
) then
6119 if Valid_Boolean_Arg
(Etype
(R
)) then
6120 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
6124 Get_First_Interp
(R
, Index
, It
);
6125 while Present
(It
.Typ
) loop
6126 if Valid_Boolean_Arg
(It
.Typ
) then
6127 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
6130 Get_Next_Interp
(Index
, It
);
6134 elsif Valid_Boolean_Arg
(Etype
(L
))
6135 and then Has_Compatible_Type
(R
, Etype
(L
))
6137 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
6141 Get_First_Interp
(L
, Index
, It
);
6142 while Present
(It
.Typ
) loop
6143 if Valid_Boolean_Arg
(It
.Typ
)
6144 and then Has_Compatible_Type
(R
, It
.Typ
)
6146 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
6149 Get_Next_Interp
(Index
, It
);
6152 end Find_Boolean_Types
;
6154 ---------------------------
6155 -- Find_Comparison_Types --
6156 ---------------------------
6158 procedure Find_Comparison_Types
6163 Index
: Interp_Index
;
6165 Found
: Boolean := False;
6168 Scop
: Entity_Id
:= Empty
;
6170 procedure Try_One_Interp
(T1
: Entity_Id
);
6171 -- Routine to try one proposed interpretation. Note that the context
6172 -- of the operator plays no role in resolving the arguments, so that
6173 -- if there is more than one interpretation of the operands that is
6174 -- compatible with comparison, the operation is ambiguous.
6176 --------------------
6177 -- Try_One_Interp --
6178 --------------------
6180 procedure Try_One_Interp
(T1
: Entity_Id
) is
6183 -- If the operator is an expanded name, then the type of the operand
6184 -- must be defined in the corresponding scope. If the type is
6185 -- universal, the context will impose the correct type.
6188 and then not Defined_In_Scope
(T1
, Scop
)
6189 and then T1
/= Universal_Integer
6190 and then T1
/= Universal_Real
6191 and then T1
/= Any_String
6192 and then T1
/= Any_Composite
6197 if Valid_Comparison_Arg
(T1
) and then Has_Compatible_Type
(R
, T1
) then
6198 if Found
and then Base_Type
(T1
) /= Base_Type
(T_F
) then
6199 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
6201 if It
= No_Interp
then
6202 Ambiguous_Operands
(N
);
6203 Set_Etype
(L
, Any_Type
);
6217 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
6222 -- Start of processing for Find_Comparison_Types
6225 -- If left operand is aggregate, the right operand has to
6226 -- provide a usable type for it.
6228 if Nkind
(L
) = N_Aggregate
and then Nkind
(R
) /= N_Aggregate
then
6229 Find_Comparison_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
6233 if Nkind
(N
) = N_Function_Call
6234 and then Nkind
(Name
(N
)) = N_Expanded_Name
6236 Scop
:= Entity
(Prefix
(Name
(N
)));
6238 -- The prefix may be a package renaming, and the subsequent test
6239 -- requires the original package.
6241 if Ekind
(Scop
) = E_Package
6242 and then Present
(Renamed_Entity
(Scop
))
6244 Scop
:= Renamed_Entity
(Scop
);
6245 Set_Entity
(Prefix
(Name
(N
)), Scop
);
6249 if not Is_Overloaded
(L
) then
6250 Try_One_Interp
(Etype
(L
));
6253 Get_First_Interp
(L
, Index
, It
);
6254 while Present
(It
.Typ
) loop
6255 Try_One_Interp
(It
.Typ
);
6256 Get_Next_Interp
(Index
, It
);
6259 end Find_Comparison_Types
;
6261 ----------------------------------------
6262 -- Find_Non_Universal_Interpretations --
6263 ----------------------------------------
6265 procedure Find_Non_Universal_Interpretations
6271 Index
: Interp_Index
;
6275 if T1
= Universal_Integer
or else T1
= Universal_Real
6277 -- If the left operand of an equality operator is null, the visibility
6278 -- of the operator must be determined from the interpretation of the
6279 -- right operand. This processing must be done for Any_Access, which
6280 -- is the internal representation of the type of the literal null.
6282 or else T1
= Any_Access
6284 if not Is_Overloaded
(R
) then
6285 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(Etype
(R
)));
6287 Get_First_Interp
(R
, Index
, It
);
6288 while Present
(It
.Typ
) loop
6289 if Covers
(It
.Typ
, T1
) then
6291 (N
, Op_Id
, Standard_Boolean
, Base_Type
(It
.Typ
));
6294 Get_Next_Interp
(Index
, It
);
6298 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(T1
));
6300 end Find_Non_Universal_Interpretations
;
6302 ------------------------------
6303 -- Find_Concatenation_Types --
6304 ------------------------------
6306 procedure Find_Concatenation_Types
6311 Op_Type
: constant Entity_Id
:= Etype
(Op_Id
);
6314 if Is_Array_Type
(Op_Type
)
6315 and then not Is_Limited_Type
(Op_Type
)
6317 and then (Has_Compatible_Type
(L
, Op_Type
)
6319 Has_Compatible_Type
(L
, Component_Type
(Op_Type
)))
6321 and then (Has_Compatible_Type
(R
, Op_Type
)
6323 Has_Compatible_Type
(R
, Component_Type
(Op_Type
)))
6325 Add_One_Interp
(N
, Op_Id
, Op_Type
);
6327 end Find_Concatenation_Types
;
6329 -------------------------
6330 -- Find_Equality_Types --
6331 -------------------------
6333 procedure Find_Equality_Types
6338 Index
: Interp_Index
;
6340 Found
: Boolean := False;
6343 Scop
: Entity_Id
:= Empty
;
6345 procedure Try_One_Interp
(T1
: Entity_Id
);
6346 -- The context of the equality operator plays no role in resolving the
6347 -- arguments, so that if there is more than one interpretation of the
6348 -- operands that is compatible with equality, the construct is ambiguous
6349 -- and an error can be emitted now, after trying to disambiguate, i.e.
6350 -- applying preference rules.
6352 --------------------
6353 -- Try_One_Interp --
6354 --------------------
6356 procedure Try_One_Interp
(T1
: Entity_Id
) is
6357 Bas
: constant Entity_Id
:= Base_Type
(T1
);
6360 -- If the operator is an expanded name, then the type of the operand
6361 -- must be defined in the corresponding scope. If the type is
6362 -- universal, the context will impose the correct type. An anonymous
6363 -- type for a 'Access reference is also universal in this sense, as
6364 -- the actual type is obtained from context.
6366 -- In Ada 2005, the equality operator for anonymous access types
6367 -- is declared in Standard, and preference rules apply to it.
6369 if Present
(Scop
) then
6370 if Defined_In_Scope
(T1
, Scop
)
6371 or else T1
= Universal_Integer
6372 or else T1
= Universal_Real
6373 or else T1
= Any_Access
6374 or else T1
= Any_String
6375 or else T1
= Any_Composite
6376 or else (Ekind
(T1
) = E_Access_Subprogram_Type
6377 and then not Comes_From_Source
(T1
))
6381 elsif Ekind
(T1
) = E_Anonymous_Access_Type
6382 and then Scop
= Standard_Standard
6387 -- The scope does not contain an operator for the type
6392 -- If we have infix notation, the operator must be usable. Within
6393 -- an instance, if the type is already established we know it is
6394 -- correct. If an operand is universal it is compatible with any
6397 elsif In_Open_Scopes
(Scope
(Bas
))
6398 or else Is_Potentially_Use_Visible
(Bas
)
6399 or else In_Use
(Bas
)
6400 or else (In_Use
(Scope
(Bas
)) and then not Is_Hidden
(Bas
))
6402 -- In an instance, the type may have been immediately visible.
6403 -- Either the types are compatible, or one operand is universal
6404 -- (numeric or null).
6406 or else (In_Instance
6408 (First_Subtype
(T1
) = First_Subtype
(Etype
(R
))
6409 or else Nkind
(R
) = N_Null
6411 (Is_Numeric_Type
(T1
)
6412 and then Is_Universal_Numeric_Type
(Etype
(R
)))))
6414 -- In Ada 2005, the equality on anonymous access types is declared
6415 -- in Standard, and is always visible.
6417 or else Ekind
(T1
) = E_Anonymous_Access_Type
6422 -- Save candidate type for subsequent error message, if any
6424 if not Is_Limited_Type
(T1
) then
6425 Candidate_Type
:= T1
;
6431 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
6432 -- Do not allow anonymous access types in equality operators.
6434 if Ada_Version
< Ada_2005
6435 and then Ekind
(T1
) = E_Anonymous_Access_Type
6440 -- If the right operand has a type compatible with T1, check for an
6441 -- acceptable interpretation, unless T1 is limited (no predefined
6442 -- equality available), or this is use of a "/=" for a tagged type.
6443 -- In the latter case, possible interpretations of equality need
6444 -- to be considered, we don't want the default inequality declared
6445 -- in Standard to be chosen, and the "/=" will be rewritten as a
6446 -- negation of "=" (see the end of Analyze_Equality_Op). This ensures
6447 -- that rewriting happens during analysis rather than being
6448 -- delayed until expansion (this is needed for ASIS, which only sees
6449 -- the unexpanded tree). Note that if the node is N_Op_Ne, but Op_Id
6450 -- is Name_Op_Eq then we still proceed with the interpretation,
6451 -- because that indicates the potential rewriting case where the
6452 -- interpretation to consider is actually "=" and the node may be
6453 -- about to be rewritten by Analyze_Equality_Op.
6455 if T1
/= Standard_Void_Type
6456 and then Has_Compatible_Type
(R
, T1
)
6459 ((not Is_Limited_Type
(T1
)
6460 and then not Is_Limited_Composite
(T1
))
6464 and then not Is_Limited_Type
(Component_Type
(T1
))
6465 and then Available_Full_View_Of_Component
(T1
)))
6468 (Nkind
(N
) /= N_Op_Ne
6469 or else not Is_Tagged_Type
(T1
)
6470 or else Chars
(Op_Id
) = Name_Op_Eq
)
6473 and then Base_Type
(T1
) /= Base_Type
(T_F
)
6475 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
6477 if It
= No_Interp
then
6478 Ambiguous_Operands
(N
);
6479 Set_Etype
(L
, Any_Type
);
6492 if not Analyzed
(L
) then
6496 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
6498 -- Case of operator was not visible, Etype still set to Any_Type
6500 if Etype
(N
) = Any_Type
then
6504 elsif Scop
= Standard_Standard
6505 and then Ekind
(T1
) = E_Anonymous_Access_Type
6511 -- Start of processing for Find_Equality_Types
6514 -- If left operand is aggregate, the right operand has to
6515 -- provide a usable type for it.
6517 if Nkind
(L
) = N_Aggregate
6518 and then Nkind
(R
) /= N_Aggregate
6520 Find_Equality_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
6524 if Nkind
(N
) = N_Function_Call
6525 and then Nkind
(Name
(N
)) = N_Expanded_Name
6527 Scop
:= Entity
(Prefix
(Name
(N
)));
6529 -- The prefix may be a package renaming, and the subsequent test
6530 -- requires the original package.
6532 if Ekind
(Scop
) = E_Package
6533 and then Present
(Renamed_Entity
(Scop
))
6535 Scop
:= Renamed_Entity
(Scop
);
6536 Set_Entity
(Prefix
(Name
(N
)), Scop
);
6540 if not Is_Overloaded
(L
) then
6541 Try_One_Interp
(Etype
(L
));
6544 Get_First_Interp
(L
, Index
, It
);
6545 while Present
(It
.Typ
) loop
6546 Try_One_Interp
(It
.Typ
);
6547 Get_Next_Interp
(Index
, It
);
6550 end Find_Equality_Types
;
6552 -------------------------
6553 -- Find_Negation_Types --
6554 -------------------------
6556 procedure Find_Negation_Types
6561 Index
: Interp_Index
;
6565 if not Is_Overloaded
(R
) then
6566 if Etype
(R
) = Universal_Integer
then
6567 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
6568 elsif Valid_Boolean_Arg
(Etype
(R
)) then
6569 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
6573 Get_First_Interp
(R
, Index
, It
);
6574 while Present
(It
.Typ
) loop
6575 if Valid_Boolean_Arg
(It
.Typ
) then
6576 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
6579 Get_Next_Interp
(Index
, It
);
6582 end Find_Negation_Types
;
6584 ------------------------------
6585 -- Find_Primitive_Operation --
6586 ------------------------------
6588 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean is
6589 Obj
: constant Node_Id
:= Prefix
(N
);
6590 Op
: constant Node_Id
:= Selector_Name
(N
);
6597 Set_Etype
(Op
, Any_Type
);
6599 if Is_Access_Type
(Etype
(Obj
)) then
6600 Typ
:= Designated_Type
(Etype
(Obj
));
6605 if Is_Class_Wide_Type
(Typ
) then
6606 Typ
:= Root_Type
(Typ
);
6609 Prims
:= Primitive_Operations
(Typ
);
6611 Prim
:= First_Elmt
(Prims
);
6612 while Present
(Prim
) loop
6613 if Chars
(Node
(Prim
)) = Chars
(Op
) then
6614 Add_One_Interp
(Op
, Node
(Prim
), Etype
(Node
(Prim
)));
6615 Set_Etype
(N
, Etype
(Node
(Prim
)));
6621 -- Now look for class-wide operations of the type or any of its
6622 -- ancestors by iterating over the homonyms of the selector.
6625 Cls_Type
: constant Entity_Id
:= Class_Wide_Type
(Typ
);
6629 Hom
:= Current_Entity
(Op
);
6630 while Present
(Hom
) loop
6631 if (Ekind
(Hom
) = E_Procedure
6633 Ekind
(Hom
) = E_Function
)
6634 and then Scope
(Hom
) = Scope
(Typ
)
6635 and then Present
(First_Formal
(Hom
))
6637 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
6639 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
6641 Ekind
(Etype
(First_Formal
(Hom
))) =
6642 E_Anonymous_Access_Type
6645 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
6648 Add_One_Interp
(Op
, Hom
, Etype
(Hom
));
6649 Set_Etype
(N
, Etype
(Hom
));
6652 Hom
:= Homonym
(Hom
);
6656 return Etype
(Op
) /= Any_Type
;
6657 end Find_Primitive_Operation
;
6659 ----------------------
6660 -- Find_Unary_Types --
6661 ----------------------
6663 procedure Find_Unary_Types
6668 Index
: Interp_Index
;
6672 if not Is_Overloaded
(R
) then
6673 if Is_Numeric_Type
(Etype
(R
)) then
6675 -- In an instance a generic actual may be a numeric type even if
6676 -- the formal in the generic unit was not. In that case, the
6677 -- predefined operator was not a possible interpretation in the
6678 -- generic, and cannot be one in the instance, unless the operator
6679 -- is an actual of an instance.
6683 not Is_Numeric_Type
(Corresponding_Generic_Type
(Etype
(R
)))
6687 Add_One_Interp
(N
, Op_Id
, Base_Type
(Etype
(R
)));
6692 Get_First_Interp
(R
, Index
, It
);
6693 while Present
(It
.Typ
) loop
6694 if Is_Numeric_Type
(It
.Typ
) then
6698 (Corresponding_Generic_Type
(Etype
(It
.Typ
)))
6703 Add_One_Interp
(N
, Op_Id
, Base_Type
(It
.Typ
));
6707 Get_Next_Interp
(Index
, It
);
6710 end Find_Unary_Types
;
6716 function Junk_Operand
(N
: Node_Id
) return Boolean is
6720 if Error_Posted
(N
) then
6724 -- Get entity to be tested
6726 if Is_Entity_Name
(N
)
6727 and then Present
(Entity
(N
))
6731 -- An odd case, a procedure name gets converted to a very peculiar
6732 -- function call, and here is where we detect this happening.
6734 elsif Nkind
(N
) = N_Function_Call
6735 and then Is_Entity_Name
(Name
(N
))
6736 and then Present
(Entity
(Name
(N
)))
6740 -- Another odd case, there are at least some cases of selected
6741 -- components where the selected component is not marked as having
6742 -- an entity, even though the selector does have an entity
6744 elsif Nkind
(N
) = N_Selected_Component
6745 and then Present
(Entity
(Selector_Name
(N
)))
6747 Enode
:= Selector_Name
(N
);
6753 -- Now test the entity we got to see if it is a bad case
6755 case Ekind
(Entity
(Enode
)) is
6758 ("package name cannot be used as operand", Enode
);
6760 when Generic_Unit_Kind
=>
6762 ("generic unit name cannot be used as operand", Enode
);
6766 ("subtype name cannot be used as operand", Enode
);
6770 ("entry name cannot be used as operand", Enode
);
6774 ("procedure name cannot be used as operand", Enode
);
6778 ("exception name cannot be used as operand", Enode
);
6785 ("label name cannot be used as operand", Enode
);
6794 --------------------
6795 -- Operator_Check --
6796 --------------------
6798 procedure Operator_Check
(N
: Node_Id
) is
6800 Remove_Abstract_Operations
(N
);
6802 -- Test for case of no interpretation found for operator
6804 if Etype
(N
) = Any_Type
then
6808 Op_Id
: Entity_Id
:= Empty
;
6811 R
:= Right_Opnd
(N
);
6813 if Nkind
(N
) in N_Binary_Op
then
6819 -- If either operand has no type, then don't complain further,
6820 -- since this simply means that we have a propagated error.
6823 or else Etype
(R
) = Any_Type
6824 or else (Nkind
(N
) in N_Binary_Op
and then Etype
(L
) = Any_Type
)
6826 -- For the rather unusual case where one of the operands is
6827 -- a Raise_Expression, whose initial type is Any_Type, use
6828 -- the type of the other operand.
6830 if Nkind
(L
) = N_Raise_Expression
then
6831 Set_Etype
(L
, Etype
(R
));
6832 Set_Etype
(N
, Etype
(R
));
6834 elsif Nkind
(R
) = N_Raise_Expression
then
6835 Set_Etype
(R
, Etype
(L
));
6836 Set_Etype
(N
, Etype
(L
));
6841 -- We explicitly check for the case of concatenation of component
6842 -- with component to avoid reporting spurious matching array types
6843 -- that might happen to be lurking in distant packages (such as
6844 -- run-time packages). This also prevents inconsistencies in the
6845 -- messages for certain ACVC B tests, which can vary depending on
6846 -- types declared in run-time interfaces. Another improvement when
6847 -- aggregates are present is to look for a well-typed operand.
6849 elsif Present
(Candidate_Type
)
6850 and then (Nkind
(N
) /= N_Op_Concat
6851 or else Is_Array_Type
(Etype
(L
))
6852 or else Is_Array_Type
(Etype
(R
)))
6854 if Nkind
(N
) = N_Op_Concat
then
6855 if Etype
(L
) /= Any_Composite
6856 and then Is_Array_Type
(Etype
(L
))
6858 Candidate_Type
:= Etype
(L
);
6860 elsif Etype
(R
) /= Any_Composite
6861 and then Is_Array_Type
(Etype
(R
))
6863 Candidate_Type
:= Etype
(R
);
6867 Error_Msg_NE
-- CODEFIX
6868 ("operator for} is not directly visible!",
6869 N
, First_Subtype
(Candidate_Type
));
6872 U
: constant Node_Id
:=
6873 Cunit
(Get_Source_Unit
(Candidate_Type
));
6875 if Unit_Is_Visible
(U
) then
6876 Error_Msg_N
-- CODEFIX
6877 ("use clause would make operation legal!", N
);
6879 Error_Msg_NE
-- CODEFIX
6880 ("add with_clause and use_clause for&!",
6881 N
, Defining_Entity
(Unit
(U
)));
6886 -- If either operand is a junk operand (e.g. package name), then
6887 -- post appropriate error messages, but do not complain further.
6889 -- Note that the use of OR in this test instead of OR ELSE is
6890 -- quite deliberate, we may as well check both operands in the
6891 -- binary operator case.
6893 elsif Junk_Operand
(R
)
6894 or -- really mean OR here and not OR ELSE, see above
6895 (Nkind
(N
) in N_Binary_Op
and then Junk_Operand
(L
))
6899 -- If we have a logical operator, one of whose operands is
6900 -- Boolean, then we know that the other operand cannot resolve to
6901 -- Boolean (since we got no interpretations), but in that case we
6902 -- pretty much know that the other operand should be Boolean, so
6903 -- resolve it that way (generating an error).
6905 elsif Nkind_In
(N
, N_Op_And
, N_Op_Or
, N_Op_Xor
) then
6906 if Etype
(L
) = Standard_Boolean
then
6907 Resolve
(R
, Standard_Boolean
);
6909 elsif Etype
(R
) = Standard_Boolean
then
6910 Resolve
(L
, Standard_Boolean
);
6914 -- For an arithmetic operator or comparison operator, if one
6915 -- of the operands is numeric, then we know the other operand
6916 -- is not the same numeric type. If it is a non-numeric type,
6917 -- then probably it is intended to match the other operand.
6919 elsif Nkind_In
(N
, N_Op_Add
,
6925 Nkind_In
(N
, N_Op_Lt
,
6931 -- If Allow_Integer_Address is active, check whether the
6932 -- operation becomes legal after converting an operand.
6934 if Is_Numeric_Type
(Etype
(L
))
6935 and then not Is_Numeric_Type
(Etype
(R
))
6937 if Address_Integer_Convert_OK
(Etype
(R
), Etype
(L
)) then
6939 Unchecked_Convert_To
(Etype
(L
), Relocate_Node
(R
)));
6941 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6942 Analyze_Comparison_Op
(N
);
6944 Analyze_Arithmetic_Op
(N
);
6947 Resolve
(R
, Etype
(L
));
6952 elsif Is_Numeric_Type
(Etype
(R
))
6953 and then not Is_Numeric_Type
(Etype
(L
))
6955 if Address_Integer_Convert_OK
(Etype
(L
), Etype
(R
)) then
6957 Unchecked_Convert_To
(Etype
(R
), Relocate_Node
(L
)));
6959 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6960 Analyze_Comparison_Op
(N
);
6962 Analyze_Arithmetic_Op
(N
);
6968 Resolve
(L
, Etype
(R
));
6973 elsif Allow_Integer_Address
6974 and then Is_Descendant_Of_Address
(Etype
(L
))
6975 and then Is_Descendant_Of_Address
(Etype
(R
))
6976 and then not Error_Posted
(N
)
6979 Addr_Type
: constant Entity_Id
:= Etype
(L
);
6983 Unchecked_Convert_To
(
6984 Standard_Integer
, Relocate_Node
(L
)));
6986 Unchecked_Convert_To
(
6987 Standard_Integer
, Relocate_Node
(R
)));
6989 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6990 Analyze_Comparison_Op
(N
);
6992 Analyze_Arithmetic_Op
(N
);
6995 -- If this is an operand in an enclosing arithmetic
6996 -- operation, Convert the result as an address so that
6997 -- arithmetic folding of address can continue.
6999 if Nkind
(Parent
(N
)) in N_Op
then
7001 Unchecked_Convert_To
(Addr_Type
, Relocate_Node
(N
)));
7007 -- Under relaxed RM semantics silently replace occurrences of
7008 -- null by System.Address_Null.
7010 elsif Null_To_Null_Address_Convert_OK
(N
) then
7011 Replace_Null_By_Null_Address
(N
);
7013 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
7014 Analyze_Comparison_Op
(N
);
7016 Analyze_Arithmetic_Op
(N
);
7022 -- Comparisons on A'Access are common enough to deserve a
7025 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
)
7026 and then Ekind
(Etype
(L
)) = E_Access_Attribute_Type
7027 and then Ekind
(Etype
(R
)) = E_Access_Attribute_Type
7030 ("two access attributes cannot be compared directly", N
);
7032 ("\use qualified expression for one of the operands",
7036 -- Another one for C programmers
7038 elsif Nkind
(N
) = N_Op_Concat
7039 and then Valid_Boolean_Arg
(Etype
(L
))
7040 and then Valid_Boolean_Arg
(Etype
(R
))
7042 Error_Msg_N
("invalid operands for concatenation", N
);
7043 Error_Msg_N
-- CODEFIX
7044 ("\maybe AND was meant", N
);
7047 -- A special case for comparison of access parameter with null
7049 elsif Nkind
(N
) = N_Op_Eq
7050 and then Is_Entity_Name
(L
)
7051 and then Nkind
(Parent
(Entity
(L
))) = N_Parameter_Specification
7052 and then Nkind
(Parameter_Type
(Parent
(Entity
(L
)))) =
7054 and then Nkind
(R
) = N_Null
7056 Error_Msg_N
("access parameter is not allowed to be null", L
);
7057 Error_Msg_N
("\(call would raise Constraint_Error)", L
);
7060 -- Another special case for exponentiation, where the right
7061 -- operand must be Natural, independently of the base.
7063 elsif Nkind
(N
) = N_Op_Expon
7064 and then Is_Numeric_Type
(Etype
(L
))
7065 and then not Is_Overloaded
(R
)
7067 First_Subtype
(Base_Type
(Etype
(R
))) /= Standard_Integer
7068 and then Base_Type
(Etype
(R
)) /= Universal_Integer
7070 if Ada_Version
>= Ada_2012
7071 and then Has_Dimension_System
(Etype
(L
))
7074 ("exponent for dimensioned type must be a rational" &
7075 ", found}", R
, Etype
(R
));
7078 ("exponent must be of type Natural, found}", R
, Etype
(R
));
7083 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
) then
7084 if Address_Integer_Convert_OK
(Etype
(R
), Etype
(L
)) then
7086 Unchecked_Convert_To
(Etype
(L
), Relocate_Node
(R
)));
7087 Analyze_Equality_Op
(N
);
7090 -- Under relaxed RM semantics silently replace occurrences of
7091 -- null by System.Address_Null.
7093 elsif Null_To_Null_Address_Convert_OK
(N
) then
7094 Replace_Null_By_Null_Address
(N
);
7095 Analyze_Equality_Op
(N
);
7100 -- If we fall through then just give general message. Note that in
7101 -- the following messages, if the operand is overloaded we choose
7102 -- an arbitrary type to complain about, but that is probably more
7103 -- useful than not giving a type at all.
7105 if Nkind
(N
) in N_Unary_Op
then
7106 Error_Msg_Node_2
:= Etype
(R
);
7107 Error_Msg_N
("operator& not defined for}", N
);
7111 if Nkind
(N
) in N_Binary_Op
then
7112 if not Is_Overloaded
(L
)
7113 and then not Is_Overloaded
(R
)
7114 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
7116 Error_Msg_Node_2
:= First_Subtype
(Etype
(R
));
7117 Error_Msg_N
("there is no applicable operator& for}", N
);
7120 -- Another attempt to find a fix: one of the candidate
7121 -- interpretations may not be use-visible. This has
7122 -- already been checked for predefined operators, so
7123 -- we examine only user-defined functions.
7125 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
7127 while Present
(Op_Id
) loop
7128 if Ekind
(Op_Id
) /= E_Operator
7129 and then Is_Overloadable
(Op_Id
)
7131 if not Is_Immediately_Visible
(Op_Id
)
7132 and then not In_Use
(Scope
(Op_Id
))
7133 and then not Is_Abstract_Subprogram
(Op_Id
)
7134 and then not Is_Hidden
(Op_Id
)
7135 and then Ekind
(Scope
(Op_Id
)) = E_Package
7138 (L
, Etype
(First_Formal
(Op_Id
)))
7140 (Next_Formal
(First_Formal
(Op_Id
)))
7144 Etype
(Next_Formal
(First_Formal
(Op_Id
))))
7147 ("No legal interpretation for operator&", N
);
7149 ("\use clause on& would make operation legal",
7155 Op_Id
:= Homonym
(Op_Id
);
7159 Error_Msg_N
("invalid operand types for operator&", N
);
7161 if Nkind
(N
) /= N_Op_Concat
then
7162 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
7163 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
7165 -- For concatenation operators it is more difficult to
7166 -- determine which is the wrong operand. It is worth
7167 -- flagging explicitly an access type, for those who
7168 -- might think that a dereference happens here.
7170 elsif Is_Access_Type
(Etype
(L
)) then
7171 Error_Msg_N
("\left operand is access type", N
);
7173 elsif Is_Access_Type
(Etype
(R
)) then
7174 Error_Msg_N
("\right operand is access type", N
);
7184 -----------------------------------------
7185 -- Process_Implicit_Dereference_Prefix --
7186 -----------------------------------------
7188 function Process_Implicit_Dereference_Prefix
7190 P
: Entity_Id
) return Entity_Id
7193 Typ
: constant Entity_Id
:= Designated_Type
(Etype
(P
));
7197 and then (Operating_Mode
= Check_Semantics
or else not Expander_Active
)
7199 -- We create a dummy reference to E to ensure that the reference is
7200 -- not considered as part of an assignment (an implicit dereference
7201 -- can never assign to its prefix). The Comes_From_Source attribute
7202 -- needs to be propagated for accurate warnings.
7204 Ref
:= New_Occurrence_Of
(E
, Sloc
(P
));
7205 Set_Comes_From_Source
(Ref
, Comes_From_Source
(P
));
7206 Generate_Reference
(E
, Ref
);
7209 -- An implicit dereference is a legal occurrence of an incomplete type
7210 -- imported through a limited_with clause, if the full view is visible.
7212 if From_Limited_With
(Typ
)
7213 and then not From_Limited_With
(Scope
(Typ
))
7215 (Is_Immediately_Visible
(Scope
(Typ
))
7217 (Is_Child_Unit
(Scope
(Typ
))
7218 and then Is_Visible_Lib_Unit
(Scope
(Typ
))))
7220 return Available_View
(Typ
);
7224 end Process_Implicit_Dereference_Prefix
;
7226 --------------------------------
7227 -- Remove_Abstract_Operations --
7228 --------------------------------
7230 procedure Remove_Abstract_Operations
(N
: Node_Id
) is
7231 Abstract_Op
: Entity_Id
:= Empty
;
7232 Address_Descendant
: Boolean := False;
7236 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
7237 -- activate this if either extensions are enabled, or if the abstract
7238 -- operation in question comes from a predefined file. This latter test
7239 -- allows us to use abstract to make operations invisible to users. In
7240 -- particular, if type Address is non-private and abstract subprograms
7241 -- are used to hide its operators, they will be truly hidden.
7243 type Operand_Position
is (First_Op
, Second_Op
);
7244 Univ_Type
: constant Entity_Id
:= Universal_Interpretation
(N
);
7246 procedure Remove_Address_Interpretations
(Op
: Operand_Position
);
7247 -- Ambiguities may arise when the operands are literal and the address
7248 -- operations in s-auxdec are visible. In that case, remove the
7249 -- interpretation of a literal as Address, to retain the semantics
7250 -- of Address as a private type.
7252 ------------------------------------
7253 -- Remove_Address_Interpretations --
7254 ------------------------------------
7256 procedure Remove_Address_Interpretations
(Op
: Operand_Position
) is
7260 if Is_Overloaded
(N
) then
7261 Get_First_Interp
(N
, I
, It
);
7262 while Present
(It
.Nam
) loop
7263 Formal
:= First_Entity
(It
.Nam
);
7265 if Op
= Second_Op
then
7266 Formal
:= Next_Entity
(Formal
);
7269 if Is_Descendant_Of_Address
(Etype
(Formal
)) then
7270 Address_Descendant
:= True;
7274 Get_Next_Interp
(I
, It
);
7277 end Remove_Address_Interpretations
;
7279 -- Start of processing for Remove_Abstract_Operations
7282 if Is_Overloaded
(N
) then
7283 if Debug_Flag_V
then
7284 Write_Str
("Remove_Abstract_Operations: ");
7285 Write_Overloads
(N
);
7288 Get_First_Interp
(N
, I
, It
);
7290 while Present
(It
.Nam
) loop
7291 if Is_Overloadable
(It
.Nam
)
7292 and then Is_Abstract_Subprogram
(It
.Nam
)
7293 and then not Is_Dispatching_Operation
(It
.Nam
)
7295 Abstract_Op
:= It
.Nam
;
7297 if Is_Descendant_Of_Address
(It
.Typ
) then
7298 Address_Descendant
:= True;
7302 -- In Ada 2005, this operation does not participate in overload
7303 -- resolution. If the operation is defined in a predefined
7304 -- unit, it is one of the operations declared abstract in some
7305 -- variants of System, and it must be removed as well.
7307 elsif Ada_Version
>= Ada_2005
7308 or else Is_Predefined_File_Name
7309 (Unit_File_Name
(Get_Source_Unit
(It
.Nam
)))
7316 Get_Next_Interp
(I
, It
);
7319 if No
(Abstract_Op
) then
7321 -- If some interpretation yields an integer type, it is still
7322 -- possible that there are address interpretations. Remove them
7323 -- if one operand is a literal, to avoid spurious ambiguities
7324 -- on systems where Address is a visible integer type.
7326 if Is_Overloaded
(N
)
7327 and then Nkind
(N
) in N_Op
7328 and then Is_Integer_Type
(Etype
(N
))
7330 if Nkind
(N
) in N_Binary_Op
then
7331 if Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
7332 Remove_Address_Interpretations
(Second_Op
);
7334 elsif Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
7335 Remove_Address_Interpretations
(First_Op
);
7340 elsif Nkind
(N
) in N_Op
then
7342 -- Remove interpretations that treat literals as addresses. This
7343 -- is never appropriate, even when Address is defined as a visible
7344 -- Integer type. The reason is that we would really prefer Address
7345 -- to behave as a private type, even in this case. If Address is a
7346 -- visible integer type, we get lots of overload ambiguities.
7348 if Nkind
(N
) in N_Binary_Op
then
7350 U1
: constant Boolean :=
7351 Present
(Universal_Interpretation
(Right_Opnd
(N
)));
7352 U2
: constant Boolean :=
7353 Present
(Universal_Interpretation
(Left_Opnd
(N
)));
7357 Remove_Address_Interpretations
(Second_Op
);
7361 Remove_Address_Interpretations
(First_Op
);
7364 if not (U1
and U2
) then
7366 -- Remove corresponding predefined operator, which is
7367 -- always added to the overload set.
7369 Get_First_Interp
(N
, I
, It
);
7370 while Present
(It
.Nam
) loop
7371 if Scope
(It
.Nam
) = Standard_Standard
7372 and then Base_Type
(It
.Typ
) =
7373 Base_Type
(Etype
(Abstract_Op
))
7378 Get_Next_Interp
(I
, It
);
7381 elsif Is_Overloaded
(N
)
7382 and then Present
(Univ_Type
)
7384 -- If both operands have a universal interpretation,
7385 -- it is still necessary to remove interpretations that
7386 -- yield Address. Any remaining ambiguities will be
7387 -- removed in Disambiguate.
7389 Get_First_Interp
(N
, I
, It
);
7390 while Present
(It
.Nam
) loop
7391 if Is_Descendant_Of_Address
(It
.Typ
) then
7394 elsif not Is_Type
(It
.Nam
) then
7395 Set_Entity
(N
, It
.Nam
);
7398 Get_Next_Interp
(I
, It
);
7404 elsif Nkind
(N
) = N_Function_Call
7406 (Nkind
(Name
(N
)) = N_Operator_Symbol
7408 (Nkind
(Name
(N
)) = N_Expanded_Name
7410 Nkind
(Selector_Name
(Name
(N
))) = N_Operator_Symbol
))
7414 Arg1
: constant Node_Id
:= First
(Parameter_Associations
(N
));
7415 U1
: constant Boolean :=
7416 Present
(Universal_Interpretation
(Arg1
));
7417 U2
: constant Boolean :=
7418 Present
(Next
(Arg1
)) and then
7419 Present
(Universal_Interpretation
(Next
(Arg1
)));
7423 Remove_Address_Interpretations
(First_Op
);
7427 Remove_Address_Interpretations
(Second_Op
);
7430 if not (U1
and U2
) then
7431 Get_First_Interp
(N
, I
, It
);
7432 while Present
(It
.Nam
) loop
7433 if Scope
(It
.Nam
) = Standard_Standard
7434 and then It
.Typ
= Base_Type
(Etype
(Abstract_Op
))
7439 Get_Next_Interp
(I
, It
);
7445 -- If the removal has left no valid interpretations, emit an error
7446 -- message now and label node as illegal.
7448 if Present
(Abstract_Op
) then
7449 Get_First_Interp
(N
, I
, It
);
7453 -- Removal of abstract operation left no viable candidate
7455 Set_Etype
(N
, Any_Type
);
7456 Error_Msg_Sloc
:= Sloc
(Abstract_Op
);
7458 ("cannot call abstract operation& declared#", N
, Abstract_Op
);
7460 -- In Ada 2005, an abstract operation may disable predefined
7461 -- operators. Since the context is not yet known, we mark the
7462 -- predefined operators as potentially hidden. Do not include
7463 -- predefined operators when addresses are involved since this
7464 -- case is handled separately.
7466 elsif Ada_Version
>= Ada_2005
and then not Address_Descendant
then
7467 while Present
(It
.Nam
) loop
7468 if Is_Numeric_Type
(It
.Typ
)
7469 and then Scope
(It
.Typ
) = Standard_Standard
7471 Set_Abstract_Op
(I
, Abstract_Op
);
7474 Get_Next_Interp
(I
, It
);
7479 if Debug_Flag_V
then
7480 Write_Str
("Remove_Abstract_Operations done: ");
7481 Write_Overloads
(N
);
7484 end Remove_Abstract_Operations
;
7486 ----------------------------
7487 -- Try_Container_Indexing --
7488 ----------------------------
7490 function Try_Container_Indexing
7493 Exprs
: List_Id
) return Boolean
7495 Pref_Typ
: constant Entity_Id
:= Etype
(Prefix
);
7497 function Constant_Indexing_OK
return Boolean;
7498 -- Constant_Indexing is legal if there is no Variable_Indexing defined
7499 -- for the type, or else node not a target of assignment, or an actual
7500 -- for an IN OUT or OUT formal (RM 4.1.6 (11)).
7502 function Find_Indexing_Operations
7505 Is_Constant
: Boolean) return Node_Id
;
7506 -- Return a reference to the primitive operation of type T denoted by
7507 -- name Nam. If the operation is overloaded, the reference carries all
7508 -- interpretations. Flag Is_Constant should be set when the context is
7509 -- constant indexing.
7511 --------------------------
7512 -- Constant_Indexing_OK --
7513 --------------------------
7515 function Constant_Indexing_OK
return Boolean is
7519 if No
(Find_Value_Of_Aspect
(Pref_Typ
, Aspect_Variable_Indexing
)) then
7522 elsif not Is_Variable
(Prefix
) then
7527 while Present
(Par
) loop
7528 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
7529 and then Par
= Name
(Parent
(Par
))
7533 -- The call may be overloaded, in which case we assume that its
7534 -- resolution does not depend on the type of the parameter that
7535 -- includes the indexing operation.
7537 elsif Nkind_In
(Parent
(Par
), N_Function_Call
,
7538 N_Procedure_Call_Statement
)
7539 and then Is_Entity_Name
(Name
(Parent
(Par
)))
7547 -- We should look for an interpretation with the proper
7548 -- number of formals, and determine whether it is an
7549 -- In_Parameter, but for now we examine the formal that
7550 -- corresponds to the indexing, and assume that variable
7551 -- indexing is required if some interpretation has an
7552 -- assignable formal at that position. Still does not
7553 -- cover the most complex cases ???
7555 if Is_Overloaded
(Name
(Parent
(Par
))) then
7557 Proc
: constant Node_Id
:= Name
(Parent
(Par
));
7564 Get_First_Interp
(Proc
, I
, It
);
7565 while Present
(It
.Nam
) loop
7566 F
:= First_Formal
(It
.Nam
);
7567 A
:= First
(Parameter_Associations
(Parent
(Par
)));
7569 while Present
(F
) and then Present
(A
) loop
7571 if Ekind
(F
) /= E_In_Parameter
then
7574 exit; -- interpretation is safe
7582 Get_Next_Interp
(I
, It
);
7589 Proc
:= Entity
(Name
(Parent
(Par
)));
7591 -- If this is an indirect call, get formals from
7594 if Is_Access_Subprogram_Type
(Etype
(Proc
)) then
7595 Proc
:= Designated_Type
(Etype
(Proc
));
7599 Formal
:= First_Formal
(Proc
);
7600 Actual
:= First_Actual
(Parent
(Par
));
7602 -- Find corresponding actual
7604 while Present
(Actual
) loop
7605 exit when Actual
= Par
;
7606 Next_Actual
(Actual
);
7608 if Present
(Formal
) then
7609 Next_Formal
(Formal
);
7611 -- Otherwise this is a parameter mismatch, the error is
7612 -- reported elsewhere.
7619 return Ekind
(Formal
) = E_In_Parameter
;
7622 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
7625 -- If the indexed component is a prefix it may be the first actual
7626 -- of a prefixed call. Retrieve the called entity, if any, and
7627 -- check its first formal. Determine if the context is a procedure
7628 -- or function call.
7630 elsif Nkind
(Parent
(Par
)) = N_Selected_Component
then
7632 Sel
: constant Node_Id
:= Selector_Name
(Parent
(Par
));
7633 Nam
: constant Entity_Id
:= Current_Entity
(Sel
);
7636 if Present
(Nam
) and then Is_Overloadable
(Nam
) then
7637 if Nkind
(Parent
(Parent
(Par
))) =
7638 N_Procedure_Call_Statement
7642 elsif Ekind
(Nam
) = E_Function
7643 and then Present
(First_Formal
(Nam
))
7645 return Ekind
(First_Formal
(Nam
)) = E_In_Parameter
;
7650 elsif Nkind
(Par
) in N_Op
then
7654 Par
:= Parent
(Par
);
7657 -- In all other cases, constant indexing is legal
7660 end Constant_Indexing_OK
;
7662 ------------------------------
7663 -- Find_Indexing_Operations --
7664 ------------------------------
7666 function Find_Indexing_Operations
7669 Is_Constant
: Boolean) return Node_Id
7671 procedure Inspect_Declarations
7673 Ref
: in out Node_Id
);
7674 -- Traverse the declarative list where type Typ resides and collect
7675 -- all suitable interpretations in node Ref.
7677 procedure Inspect_Primitives
7679 Ref
: in out Node_Id
);
7680 -- Traverse the list of primitive operations of type Typ and collect
7681 -- all suitable interpretations in node Ref.
7683 function Is_OK_Candidate
7684 (Subp_Id
: Entity_Id
;
7685 Typ
: Entity_Id
) return Boolean;
7686 -- Determine whether subprogram Subp_Id is a suitable indexing
7687 -- operation for type Typ. To qualify as such, the subprogram must
7688 -- be a function, have at least two parameters, and the type of the
7689 -- first parameter must be either Typ, or Typ'Class, or access [to
7690 -- constant] with designated type Typ or Typ'Class.
7692 procedure Record_Interp
(Subp_Id
: Entity_Id
; Ref
: in out Node_Id
);
7693 -- Store subprogram Subp_Id as an interpretation in node Ref
7695 --------------------------
7696 -- Inspect_Declarations --
7697 --------------------------
7699 procedure Inspect_Declarations
7701 Ref
: in out Node_Id
)
7703 Typ_Decl
: constant Node_Id
:= Declaration_Node
(Typ
);
7705 Subp_Id
: Entity_Id
;
7708 -- Ensure that the routine is not called with itypes, which lack a
7709 -- declarative node.
7711 pragma Assert
(Present
(Typ_Decl
));
7712 pragma Assert
(Is_List_Member
(Typ_Decl
));
7714 Decl
:= First
(List_Containing
(Typ_Decl
));
7715 while Present
(Decl
) loop
7716 if Nkind
(Decl
) = N_Subprogram_Declaration
then
7717 Subp_Id
:= Defining_Entity
(Decl
);
7719 if Is_OK_Candidate
(Subp_Id
, Typ
) then
7720 Record_Interp
(Subp_Id
, Ref
);
7726 end Inspect_Declarations
;
7728 ------------------------
7729 -- Inspect_Primitives --
7730 ------------------------
7732 procedure Inspect_Primitives
7734 Ref
: in out Node_Id
)
7736 Prim_Elmt
: Elmt_Id
;
7737 Prim_Id
: Entity_Id
;
7740 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7741 while Present
(Prim_Elmt
) loop
7742 Prim_Id
:= Node
(Prim_Elmt
);
7744 if Is_OK_Candidate
(Prim_Id
, Typ
) then
7745 Record_Interp
(Prim_Id
, Ref
);
7748 Next_Elmt
(Prim_Elmt
);
7750 end Inspect_Primitives
;
7752 ---------------------
7753 -- Is_OK_Candidate --
7754 ---------------------
7756 function Is_OK_Candidate
7757 (Subp_Id
: Entity_Id
;
7758 Typ
: Entity_Id
) return Boolean
7761 Formal_Typ
: Entity_Id
;
7762 Param_Typ
: Node_Id
;
7765 -- To classify as a suitable candidate, the subprogram must be a
7766 -- function whose name matches the argument of aspect Constant or
7767 -- Variable_Indexing.
7769 if Ekind
(Subp_Id
) = E_Function
and then Chars
(Subp_Id
) = Nam
then
7770 Formal
:= First_Formal
(Subp_Id
);
7772 -- The candidate requires at least two parameters
7774 if Present
(Formal
) and then Present
(Next_Formal
(Formal
)) then
7775 Formal_Typ
:= Empty
;
7776 Param_Typ
:= Parameter_Type
(Parent
(Formal
));
7778 -- Use the designated type when the first parameter is of an
7781 if Nkind
(Param_Typ
) = N_Access_Definition
7782 and then Present
(Subtype_Mark
(Param_Typ
))
7784 -- When the context is a constant indexing, the access
7785 -- definition must be access-to-constant. This does not
7786 -- apply to variable indexing.
7789 or else Constant_Present
(Param_Typ
)
7791 Formal_Typ
:= Etype
(Subtype_Mark
(Param_Typ
));
7794 -- Otherwise use the parameter type
7797 Formal_Typ
:= Etype
(Param_Typ
);
7800 if Present
(Formal_Typ
) then
7802 -- Use the specific type when the parameter type is
7805 if Is_Class_Wide_Type
(Formal_Typ
) then
7806 Formal_Typ
:= Etype
(Base_Type
(Formal_Typ
));
7809 -- Use the full view when the parameter type is private
7812 if Is_Incomplete_Or_Private_Type
(Formal_Typ
)
7813 and then Present
(Full_View
(Formal_Typ
))
7815 Formal_Typ
:= Full_View
(Formal_Typ
);
7818 -- The type of the first parameter must denote the type
7819 -- of the container or acts as its ancestor type.
7823 or else Is_Ancestor
(Formal_Typ
, Typ
);
7829 end Is_OK_Candidate
;
7835 procedure Record_Interp
(Subp_Id
: Entity_Id
; Ref
: in out Node_Id
) is
7837 if Present
(Ref
) then
7838 Add_One_Interp
(Ref
, Subp_Id
, Etype
(Subp_Id
));
7840 -- Otherwise this is the first interpretation. Create a reference
7841 -- where all remaining interpretations will be collected.
7844 Ref
:= New_Occurrence_Of
(Subp_Id
, Sloc
(T
));
7853 -- Start of processing for Find_Indexing_Operations
7858 -- Use the specific type when the parameter type is class-wide
7860 if Is_Class_Wide_Type
(Typ
) then
7861 Typ
:= Root_Type
(Typ
);
7865 Typ
:= Underlying_Type
(Base_Type
(Typ
));
7867 Inspect_Primitives
(Typ
, Ref
);
7869 -- Now look for explicit declarations of an indexing operation.
7870 -- If the type is private the operation may be declared in the
7871 -- visible part that contains the partial view.
7873 if Is_Private_Type
(T
) then
7874 Inspect_Declarations
(T
, Ref
);
7877 Inspect_Declarations
(Typ
, Ref
);
7880 end Find_Indexing_Operations
;
7884 Loc
: constant Source_Ptr
:= Sloc
(N
);
7888 Func_Name
: Node_Id
;
7891 Is_Constant_Indexing
: Boolean := False;
7892 -- This flag reflects the nature of the container indexing. Note that
7893 -- the context may be suited for constant indexing, but the type may
7894 -- lack a Constant_Indexing annotation.
7896 -- Start of processing for Try_Container_Indexing
7899 -- Node may have been analyzed already when testing for a prefixed
7900 -- call, in which case do not redo analysis.
7902 if Present
(Generalized_Indexing
(N
)) then
7908 -- If indexing a class-wide container, obtain indexing primitive from
7911 if Is_Class_Wide_Type
(C_Type
) then
7912 C_Type
:= Etype
(Base_Type
(C_Type
));
7915 -- Check whether the type has a specified indexing aspect
7919 -- The context is suitable for constant indexing, so obtain the name of
7920 -- the indexing function from aspect Constant_Indexing.
7922 if Constant_Indexing_OK
then
7924 Find_Value_Of_Aspect
(Pref_Typ
, Aspect_Constant_Indexing
);
7927 if Present
(Func_Name
) then
7928 Is_Constant_Indexing
:= True;
7930 -- Otherwise attempt variable indexing
7934 Find_Value_Of_Aspect
(Pref_Typ
, Aspect_Variable_Indexing
);
7937 -- The type is not subject to either form of indexing, therefore the
7938 -- indexed component does not denote container indexing. If this is a
7939 -- true error, it is diagnosed by the caller.
7941 if No
(Func_Name
) then
7943 -- The prefix itself may be an indexing of a container. Rewrite it
7944 -- as such and retry.
7946 if Has_Implicit_Dereference
(Pref_Typ
) then
7947 Build_Explicit_Dereference
(Prefix
, First_Discriminant
(Pref_Typ
));
7948 return Try_Container_Indexing
(N
, Prefix
, Exprs
);
7950 -- Otherwise this is definitely not container indexing
7956 -- If the container type is derived from another container type, the
7957 -- value of the inherited aspect is the Reference operation declared
7958 -- for the parent type.
7960 -- However, Reference is also a primitive operation of the type, and the
7961 -- inherited operation has a different signature. We retrieve the right
7962 -- ones (the function may be overloaded) from the list of primitive
7963 -- operations of the derived type.
7965 -- Note that predefined containers are typically all derived from one of
7966 -- the Controlled types. The code below is motivated by containers that
7967 -- are derived from other types with a Reference aspect.
7969 elsif Is_Derived_Type
(C_Type
)
7970 and then Etype
(First_Formal
(Entity
(Func_Name
))) /= Pref_Typ
7973 Find_Indexing_Operations
7975 Nam
=> Chars
(Func_Name
),
7976 Is_Constant
=> Is_Constant_Indexing
);
7979 Assoc
:= New_List
(Relocate_Node
(Prefix
));
7981 -- A generalized indexing may have nore than one index expression, so
7982 -- transfer all of them to the argument list to be used in the call.
7983 -- Note that there may be named associations, in which case the node
7984 -- was rewritten earlier as a call, and has been transformed back into
7985 -- an indexed expression to share the following processing.
7987 -- The generalized indexing node is the one on which analysis and
7988 -- resolution take place. Before expansion the original node is replaced
7989 -- with the generalized indexing node, which is a call, possibly with a
7990 -- dereference operation.
7992 if Comes_From_Source
(N
) then
7993 Check_Compiler_Unit
("generalized indexing", N
);
7996 -- Create argument list for function call that represents generalized
7997 -- indexing. Note that indices (i.e. actuals) may themselves be
8005 Arg
:= First
(Exprs
);
8006 while Present
(Arg
) loop
8007 New_Arg
:= Relocate_Node
(Arg
);
8009 -- The arguments can be parameter associations, in which case the
8010 -- explicit actual parameter carries the overloadings.
8012 if Nkind
(New_Arg
) /= N_Parameter_Association
then
8013 Save_Interps
(Arg
, New_Arg
);
8016 Append
(New_Arg
, Assoc
);
8021 if not Is_Overloaded
(Func_Name
) then
8022 Func
:= Entity
(Func_Name
);
8025 Make_Function_Call
(Loc
,
8026 Name
=> New_Occurrence_Of
(Func
, Loc
),
8027 Parameter_Associations
=> Assoc
);
8029 Set_Parent
(Indexing
, Parent
(N
));
8030 Set_Generalized_Indexing
(N
, Indexing
);
8032 Set_Etype
(N
, Etype
(Indexing
));
8034 -- If the return type of the indexing function is a reference type,
8035 -- add the dereference as a possible interpretation. Note that the
8036 -- indexing aspect may be a function that returns the element type
8037 -- with no intervening implicit dereference, and that the reference
8038 -- discriminant is not the first discriminant.
8040 if Has_Discriminants
(Etype
(Func
)) then
8041 Check_Implicit_Dereference
(N
, Etype
(Func
));
8045 -- If there are multiple indexing functions, build a function call
8046 -- and analyze it for each of the possible interpretations.
8049 Make_Function_Call
(Loc
,
8051 Make_Identifier
(Loc
, Chars
(Func_Name
)),
8052 Parameter_Associations
=> Assoc
);
8053 Set_Parent
(Indexing
, Parent
(N
));
8054 Set_Generalized_Indexing
(N
, Indexing
);
8055 Set_Etype
(N
, Any_Type
);
8056 Set_Etype
(Name
(Indexing
), Any_Type
);
8064 Get_First_Interp
(Func_Name
, I
, It
);
8065 Set_Etype
(Indexing
, Any_Type
);
8067 -- Analyze each candidate function with the given actuals
8069 while Present
(It
.Nam
) loop
8070 Analyze_One_Call
(Indexing
, It
.Nam
, False, Success
);
8071 Get_Next_Interp
(I
, It
);
8074 -- If there are several successful candidates, resolution will
8075 -- be by result. Mark the interpretations of the function name
8078 if Is_Overloaded
(Indexing
) then
8079 Get_First_Interp
(Indexing
, I
, It
);
8081 while Present
(It
.Nam
) loop
8082 Add_One_Interp
(Name
(Indexing
), It
.Nam
, It
.Typ
);
8083 Get_Next_Interp
(I
, It
);
8087 Set_Etype
(Name
(Indexing
), Etype
(Indexing
));
8090 -- Now add the candidate interpretations to the indexing node
8091 -- itself, to be replaced later by the function call.
8093 if Is_Overloaded
(Name
(Indexing
)) then
8094 Get_First_Interp
(Name
(Indexing
), I
, It
);
8096 while Present
(It
.Nam
) loop
8097 Add_One_Interp
(N
, It
.Nam
, It
.Typ
);
8099 -- Add dereference interpretation if the result type has
8100 -- implicit reference discriminants.
8102 if Has_Discriminants
(Etype
(It
.Nam
)) then
8103 Check_Implicit_Dereference
(N
, Etype
(It
.Nam
));
8106 Get_Next_Interp
(I
, It
);
8110 Set_Etype
(N
, Etype
(Name
(Indexing
)));
8111 if Has_Discriminants
(Etype
(N
)) then
8112 Check_Implicit_Dereference
(N
, Etype
(N
));
8118 if Etype
(Indexing
) = Any_Type
then
8120 ("container cannot be indexed with&", N
, Etype
(First
(Exprs
)));
8121 Rewrite
(N
, New_Occurrence_Of
(Any_Id
, Loc
));
8125 end Try_Container_Indexing
;
8127 -----------------------
8128 -- Try_Indirect_Call --
8129 -----------------------
8131 function Try_Indirect_Call
8134 Typ
: Entity_Id
) return Boolean
8140 pragma Warnings
(Off
, Call_OK
);
8143 Normalize_Actuals
(N
, Designated_Type
(Typ
), False, Call_OK
);
8145 Actual
:= First_Actual
(N
);
8146 Formal
:= First_Formal
(Designated_Type
(Typ
));
8147 while Present
(Actual
) and then Present
(Formal
) loop
8148 if not Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
8153 Next_Formal
(Formal
);
8156 if No
(Actual
) and then No
(Formal
) then
8157 Add_One_Interp
(N
, Nam
, Etype
(Designated_Type
(Typ
)));
8159 -- Nam is a candidate interpretation for the name in the call,
8160 -- if it is not an indirect call.
8162 if not Is_Type
(Nam
)
8163 and then Is_Entity_Name
(Name
(N
))
8165 Set_Entity
(Name
(N
), Nam
);
8173 end Try_Indirect_Call
;
8175 ----------------------
8176 -- Try_Indexed_Call --
8177 ----------------------
8179 function Try_Indexed_Call
8183 Skip_First
: Boolean) return Boolean
8185 Loc
: constant Source_Ptr
:= Sloc
(N
);
8186 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
8191 Actual
:= First
(Actuals
);
8193 -- If the call was originally written in prefix form, skip the first
8194 -- actual, which is obviously not defaulted.
8200 Index
:= First_Index
(Typ
);
8201 while Present
(Actual
) and then Present
(Index
) loop
8203 -- If the parameter list has a named association, the expression
8204 -- is definitely a call and not an indexed component.
8206 if Nkind
(Actual
) = N_Parameter_Association
then
8210 if Is_Entity_Name
(Actual
)
8211 and then Is_Type
(Entity
(Actual
))
8212 and then No
(Next
(Actual
))
8214 -- A single actual that is a type name indicates a slice if the
8215 -- type is discrete, and an error otherwise.
8217 if Is_Discrete_Type
(Entity
(Actual
)) then
8221 Make_Function_Call
(Loc
,
8222 Name
=> Relocate_Node
(Name
(N
))),
8224 New_Occurrence_Of
(Entity
(Actual
), Sloc
(Actual
))));
8229 Error_Msg_N
("invalid use of type in expression", Actual
);
8230 Set_Etype
(N
, Any_Type
);
8235 elsif not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
8243 if No
(Actual
) and then No
(Index
) then
8244 Add_One_Interp
(N
, Nam
, Component_Type
(Typ
));
8246 -- Nam is a candidate interpretation for the name in the call,
8247 -- if it is not an indirect call.
8249 if not Is_Type
(Nam
)
8250 and then Is_Entity_Name
(Name
(N
))
8252 Set_Entity
(Name
(N
), Nam
);
8259 end Try_Indexed_Call
;
8261 --------------------------
8262 -- Try_Object_Operation --
8263 --------------------------
8265 function Try_Object_Operation
8266 (N
: Node_Id
; CW_Test_Only
: Boolean := False) return Boolean
8268 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
8269 Is_Subprg_Call
: constant Boolean := K
in N_Subprogram_Call
;
8270 Loc
: constant Source_Ptr
:= Sloc
(N
);
8271 Obj
: constant Node_Id
:= Prefix
(N
);
8273 Subprog
: constant Node_Id
:=
8274 Make_Identifier
(Sloc
(Selector_Name
(N
)),
8275 Chars
=> Chars
(Selector_Name
(N
)));
8276 -- Identifier on which possible interpretations will be collected
8278 Report_Error
: Boolean := False;
8279 -- If no candidate interpretation matches the context, redo analysis
8280 -- with Report_Error True to provide additional information.
8283 Candidate
: Entity_Id
:= Empty
;
8284 New_Call_Node
: Node_Id
:= Empty
;
8285 Node_To_Replace
: Node_Id
;
8286 Obj_Type
: Entity_Id
:= Etype
(Obj
);
8287 Success
: Boolean := False;
8289 function Valid_Candidate
8292 Subp
: Entity_Id
) return Entity_Id
;
8293 -- If the subprogram is a valid interpretation, record it, and add
8294 -- to the list of interpretations of Subprog. Otherwise return Empty.
8296 procedure Complete_Object_Operation
8297 (Call_Node
: Node_Id
;
8298 Node_To_Replace
: Node_Id
);
8299 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
8300 -- Call_Node, insert the object (or its dereference) as the first actual
8301 -- in the call, and complete the analysis of the call.
8303 procedure Report_Ambiguity
(Op
: Entity_Id
);
8304 -- If a prefixed procedure call is ambiguous, indicate whether the
8305 -- call includes an implicit dereference or an implicit 'Access.
8307 procedure Transform_Object_Operation
8308 (Call_Node
: out Node_Id
;
8309 Node_To_Replace
: out Node_Id
);
8310 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
8311 -- Call_Node is the resulting subprogram call, Node_To_Replace is
8312 -- either N or the parent of N, and Subprog is a reference to the
8313 -- subprogram we are trying to match.
8315 function Try_Class_Wide_Operation
8316 (Call_Node
: Node_Id
;
8317 Node_To_Replace
: Node_Id
) return Boolean;
8318 -- Traverse all ancestor types looking for a class-wide subprogram
8319 -- for which the current operation is a valid non-dispatching call.
8321 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
);
8322 -- If prefix is overloaded, its interpretation may include different
8323 -- tagged types, and we must examine the primitive operations and
8324 -- the class-wide operations of each in order to find candidate
8325 -- interpretations for the call as a whole.
8327 function Try_Primitive_Operation
8328 (Call_Node
: Node_Id
;
8329 Node_To_Replace
: Node_Id
) return Boolean;
8330 -- Traverse the list of primitive subprograms looking for a dispatching
8331 -- operation for which the current node is a valid call .
8333 ---------------------
8334 -- Valid_Candidate --
8335 ---------------------
8337 function Valid_Candidate
8340 Subp
: Entity_Id
) return Entity_Id
8342 Arr_Type
: Entity_Id
;
8343 Comp_Type
: Entity_Id
;
8346 -- If the subprogram is a valid interpretation, record it in global
8347 -- variable Subprog, to collect all possible overloadings.
8350 if Subp
/= Entity
(Subprog
) then
8351 Add_One_Interp
(Subprog
, Subp
, Etype
(Subp
));
8355 -- If the call may be an indexed call, retrieve component type of
8356 -- resulting expression, and add possible interpretation.
8361 if Nkind
(Call
) = N_Function_Call
8362 and then Nkind
(Parent
(N
)) = N_Indexed_Component
8363 and then Needs_One_Actual
(Subp
)
8365 if Is_Array_Type
(Etype
(Subp
)) then
8366 Arr_Type
:= Etype
(Subp
);
8368 elsif Is_Access_Type
(Etype
(Subp
))
8369 and then Is_Array_Type
(Designated_Type
(Etype
(Subp
)))
8371 Arr_Type
:= Designated_Type
(Etype
(Subp
));
8375 if Present
(Arr_Type
) then
8377 -- Verify that the actuals (excluding the object) match the types
8385 Actual
:= Next
(First_Actual
(Call
));
8386 Index
:= First_Index
(Arr_Type
);
8387 while Present
(Actual
) and then Present
(Index
) loop
8388 if not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
8393 Next_Actual
(Actual
);
8399 and then Present
(Arr_Type
)
8401 Comp_Type
:= Component_Type
(Arr_Type
);
8405 if Present
(Comp_Type
)
8406 and then Etype
(Subprog
) /= Comp_Type
8408 Add_One_Interp
(Subprog
, Subp
, Comp_Type
);
8412 if Etype
(Call
) /= Any_Type
then
8417 end Valid_Candidate
;
8419 -------------------------------
8420 -- Complete_Object_Operation --
8421 -------------------------------
8423 procedure Complete_Object_Operation
8424 (Call_Node
: Node_Id
;
8425 Node_To_Replace
: Node_Id
)
8427 Control
: constant Entity_Id
:= First_Formal
(Entity
(Subprog
));
8428 Formal_Type
: constant Entity_Id
:= Etype
(Control
);
8429 First_Actual
: Node_Id
;
8432 -- Place the name of the operation, with its interpretations,
8433 -- on the rewritten call.
8435 Set_Name
(Call_Node
, Subprog
);
8437 First_Actual
:= First
(Parameter_Associations
(Call_Node
));
8439 -- For cross-reference purposes, treat the new node as being in the
8440 -- source if the original one is. Set entity and type, even though
8441 -- they may be overwritten during resolution if overloaded.
8443 Set_Comes_From_Source
(Subprog
, Comes_From_Source
(N
));
8444 Set_Comes_From_Source
(Call_Node
, Comes_From_Source
(N
));
8446 if Nkind
(N
) = N_Selected_Component
8447 and then not Inside_A_Generic
8449 Set_Entity
(Selector_Name
(N
), Entity
(Subprog
));
8450 Set_Etype
(Selector_Name
(N
), Etype
(Entity
(Subprog
)));
8453 -- If need be, rewrite first actual as an explicit dereference. If
8454 -- the call is overloaded, the rewriting can only be done once the
8455 -- primitive operation is identified.
8457 if Is_Overloaded
(Subprog
) then
8459 -- The prefix itself may be overloaded, and its interpretations
8460 -- must be propagated to the new actual in the call.
8462 if Is_Overloaded
(Obj
) then
8463 Save_Interps
(Obj
, First_Actual
);
8466 Rewrite
(First_Actual
, Obj
);
8468 elsif not Is_Access_Type
(Formal_Type
)
8469 and then Is_Access_Type
(Etype
(Obj
))
8471 Rewrite
(First_Actual
,
8472 Make_Explicit_Dereference
(Sloc
(Obj
), Obj
));
8473 Analyze
(First_Actual
);
8475 -- If we need to introduce an explicit dereference, verify that
8476 -- the resulting actual is compatible with the mode of the formal.
8478 if Ekind
(First_Formal
(Entity
(Subprog
))) /= E_In_Parameter
8479 and then Is_Access_Constant
(Etype
(Obj
))
8482 ("expect variable in call to&", Prefix
(N
), Entity
(Subprog
));
8485 -- Conversely, if the formal is an access parameter and the object
8486 -- is not, replace the actual with a 'Access reference. Its analysis
8487 -- will check that the object is aliased.
8489 elsif Is_Access_Type
(Formal_Type
)
8490 and then not Is_Access_Type
(Etype
(Obj
))
8492 -- A special case: A.all'access is illegal if A is an access to a
8493 -- constant and the context requires an access to a variable.
8495 if not Is_Access_Constant
(Formal_Type
) then
8496 if (Nkind
(Obj
) = N_Explicit_Dereference
8497 and then Is_Access_Constant
(Etype
(Prefix
(Obj
))))
8498 or else not Is_Variable
(Obj
)
8501 ("actual for & must be a variable", Obj
, Control
);
8505 Rewrite
(First_Actual
,
8506 Make_Attribute_Reference
(Loc
,
8507 Attribute_Name
=> Name_Access
,
8508 Prefix
=> Relocate_Node
(Obj
)));
8510 if not Is_Aliased_View
(Obj
) then
8512 ("object in prefixed call to & must be aliased "
8513 & "(RM 4.1.3 (13 1/2))", Prefix
(First_Actual
), Subprog
);
8516 Analyze
(First_Actual
);
8519 if Is_Overloaded
(Obj
) then
8520 Save_Interps
(Obj
, First_Actual
);
8523 Rewrite
(First_Actual
, Obj
);
8526 -- The operation is obtained from the dispatch table and not by
8527 -- visibility, and may be declared in a unit that is not explicitly
8528 -- referenced in the source, but is nevertheless required in the
8529 -- context of the current unit. Indicate that operation and its scope
8530 -- are referenced, to prevent spurious and misleading warnings. If
8531 -- the operation is overloaded, all primitives are in the same scope
8532 -- and we can use any of them.
8534 Set_Referenced
(Entity
(Subprog
), True);
8535 Set_Referenced
(Scope
(Entity
(Subprog
)), True);
8537 Rewrite
(Node_To_Replace
, Call_Node
);
8539 -- Propagate the interpretations collected in subprog to the new
8540 -- function call node, to be resolved from context.
8542 if Is_Overloaded
(Subprog
) then
8543 Save_Interps
(Subprog
, Node_To_Replace
);
8546 -- The type of the subprogram may be a limited view obtained
8547 -- transitively from another unit. If full view is available,
8548 -- use it to analyze call.
8551 T
: constant Entity_Id
:= Etype
(Subprog
);
8553 if From_Limited_With
(T
) then
8554 Set_Etype
(Entity
(Subprog
), Available_View
(T
));
8558 Analyze
(Node_To_Replace
);
8560 -- If the operation has been rewritten into a call, which may get
8561 -- subsequently an explicit dereference, preserve the type on the
8562 -- original node (selected component or indexed component) for
8563 -- subsequent legality tests, e.g. Is_Variable. which examines
8564 -- the original node.
8566 if Nkind
(Node_To_Replace
) = N_Function_Call
then
8568 (Original_Node
(Node_To_Replace
), Etype
(Node_To_Replace
));
8571 end Complete_Object_Operation
;
8573 ----------------------
8574 -- Report_Ambiguity --
8575 ----------------------
8577 procedure Report_Ambiguity
(Op
: Entity_Id
) is
8578 Access_Actual
: constant Boolean :=
8579 Is_Access_Type
(Etype
(Prefix
(N
)));
8580 Access_Formal
: Boolean := False;
8583 Error_Msg_Sloc
:= Sloc
(Op
);
8585 if Present
(First_Formal
(Op
)) then
8586 Access_Formal
:= Is_Access_Type
(Etype
(First_Formal
(Op
)));
8589 if Access_Formal
and then not Access_Actual
then
8590 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
8592 ("\possible interpretation "
8593 & "(inherited, with implicit 'Access) #", N
);
8596 ("\possible interpretation (with implicit 'Access) #", N
);
8599 elsif not Access_Formal
and then Access_Actual
then
8600 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
8602 ("\possible interpretation "
8603 & "(inherited, with implicit dereference) #", N
);
8606 ("\possible interpretation (with implicit dereference) #", N
);
8610 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
8611 Error_Msg_N
("\possible interpretation (inherited)#", N
);
8613 Error_Msg_N
-- CODEFIX
8614 ("\possible interpretation#", N
);
8617 end Report_Ambiguity
;
8619 --------------------------------
8620 -- Transform_Object_Operation --
8621 --------------------------------
8623 procedure Transform_Object_Operation
8624 (Call_Node
: out Node_Id
;
8625 Node_To_Replace
: out Node_Id
)
8627 Dummy
: constant Node_Id
:= New_Copy
(Obj
);
8628 -- Placeholder used as a first parameter in the call, replaced
8629 -- eventually by the proper object.
8631 Parent_Node
: constant Node_Id
:= Parent
(N
);
8637 -- Common case covering 1) Call to a procedure and 2) Call to a
8638 -- function that has some additional actuals.
8640 if Nkind
(Parent_Node
) in N_Subprogram_Call
8642 -- N is a selected component node containing the name of the
8643 -- subprogram. If N is not the name of the parent node we must
8644 -- not replace the parent node by the new construct. This case
8645 -- occurs when N is a parameterless call to a subprogram that
8646 -- is an actual parameter of a call to another subprogram. For
8648 -- Some_Subprogram (..., Obj.Operation, ...)
8650 and then Name
(Parent_Node
) = N
8652 Node_To_Replace
:= Parent_Node
;
8654 Actuals
:= Parameter_Associations
(Parent_Node
);
8656 if Present
(Actuals
) then
8657 Prepend
(Dummy
, Actuals
);
8659 Actuals
:= New_List
(Dummy
);
8662 if Nkind
(Parent_Node
) = N_Procedure_Call_Statement
then
8664 Make_Procedure_Call_Statement
(Loc
,
8665 Name
=> New_Copy
(Subprog
),
8666 Parameter_Associations
=> Actuals
);
8670 Make_Function_Call
(Loc
,
8671 Name
=> New_Copy
(Subprog
),
8672 Parameter_Associations
=> Actuals
);
8675 -- Before analysis, a function call appears as an indexed component
8676 -- if there are no named associations.
8678 elsif Nkind
(Parent_Node
) = N_Indexed_Component
8679 and then N
= Prefix
(Parent_Node
)
8681 Node_To_Replace
:= Parent_Node
;
8682 Actuals
:= Expressions
(Parent_Node
);
8684 Actual
:= First
(Actuals
);
8685 while Present
(Actual
) loop
8690 Prepend
(Dummy
, Actuals
);
8693 Make_Function_Call
(Loc
,
8694 Name
=> New_Copy
(Subprog
),
8695 Parameter_Associations
=> Actuals
);
8697 -- Parameterless call: Obj.F is rewritten as F (Obj)
8700 Node_To_Replace
:= N
;
8703 Make_Function_Call
(Loc
,
8704 Name
=> New_Copy
(Subprog
),
8705 Parameter_Associations
=> New_List
(Dummy
));
8707 end Transform_Object_Operation
;
8709 ------------------------------
8710 -- Try_Class_Wide_Operation --
8711 ------------------------------
8713 function Try_Class_Wide_Operation
8714 (Call_Node
: Node_Id
;
8715 Node_To_Replace
: Node_Id
) return Boolean
8717 Anc_Type
: Entity_Id
;
8718 Matching_Op
: Entity_Id
:= Empty
;
8721 procedure Traverse_Homonyms
8722 (Anc_Type
: Entity_Id
;
8723 Error
: out Boolean);
8724 -- Traverse the homonym chain of the subprogram searching for those
8725 -- homonyms whose first formal has the Anc_Type's class-wide type,
8726 -- or an anonymous access type designating the class-wide type. If
8727 -- an ambiguity is detected, then Error is set to True.
8729 procedure Traverse_Interfaces
8730 (Anc_Type
: Entity_Id
;
8731 Error
: out Boolean);
8732 -- Traverse the list of interfaces, if any, associated with Anc_Type
8733 -- and search for acceptable class-wide homonyms associated with each
8734 -- interface. If an ambiguity is detected, then Error is set to True.
8736 -----------------------
8737 -- Traverse_Homonyms --
8738 -----------------------
8740 procedure Traverse_Homonyms
8741 (Anc_Type
: Entity_Id
;
8742 Error
: out Boolean)
8744 Cls_Type
: Entity_Id
;
8752 Cls_Type
:= Class_Wide_Type
(Anc_Type
);
8754 Hom
:= Current_Entity
(Subprog
);
8756 -- Find a non-hidden operation whose first parameter is of the
8757 -- class-wide type, a subtype thereof, or an anonymous access
8758 -- to same. If in an instance, the operation can be considered
8759 -- even if hidden (it may be hidden because the instantiation
8760 -- is expanded after the containing package has been analyzed).
8762 while Present
(Hom
) loop
8763 if Ekind_In
(Hom
, E_Procedure
, E_Function
)
8764 and then (not Is_Hidden
(Hom
) or else In_Instance
)
8765 and then Scope
(Hom
) = Scope
(Anc_Type
)
8766 and then Present
(First_Formal
(Hom
))
8768 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
8770 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
8772 Ekind
(Etype
(First_Formal
(Hom
))) =
8773 E_Anonymous_Access_Type
8776 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
8779 -- If the context is a procedure call, ignore functions
8780 -- in the name of the call.
8782 if Ekind
(Hom
) = E_Function
8783 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
8784 and then N
= Name
(Parent
(N
))
8788 -- If the context is a function call, ignore procedures
8789 -- in the name of the call.
8791 elsif Ekind
(Hom
) = E_Procedure
8792 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
8797 Set_Etype
(Call_Node
, Any_Type
);
8798 Set_Is_Overloaded
(Call_Node
, False);
8801 if No
(Matching_Op
) then
8802 Hom_Ref
:= New_Occurrence_Of
(Hom
, Sloc
(Subprog
));
8803 Set_Etype
(Call_Node
, Any_Type
);
8804 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
8806 Set_Name
(Call_Node
, Hom_Ref
);
8811 Report
=> Report_Error
,
8813 Skip_First
=> True);
8816 Valid_Candidate
(Success
, Call_Node
, Hom
);
8822 Report
=> Report_Error
,
8824 Skip_First
=> True);
8826 if Present
(Valid_Candidate
(Success
, Call_Node
, Hom
))
8827 and then Nkind
(Call_Node
) /= N_Function_Call
8829 Error_Msg_NE
("ambiguous call to&", N
, Hom
);
8830 Report_Ambiguity
(Matching_Op
);
8831 Report_Ambiguity
(Hom
);
8839 Hom
:= Homonym
(Hom
);
8841 end Traverse_Homonyms
;
8843 -------------------------
8844 -- Traverse_Interfaces --
8845 -------------------------
8847 procedure Traverse_Interfaces
8848 (Anc_Type
: Entity_Id
;
8849 Error
: out Boolean)
8851 Intface_List
: constant List_Id
:=
8852 Abstract_Interface_List
(Anc_Type
);
8858 if Is_Non_Empty_List
(Intface_List
) then
8859 Intface
:= First
(Intface_List
);
8860 while Present
(Intface
) loop
8862 -- Look for acceptable class-wide homonyms associated with
8865 Traverse_Homonyms
(Etype
(Intface
), Error
);
8871 -- Continue the search by looking at each of the interface's
8872 -- associated interface ancestors.
8874 Traverse_Interfaces
(Etype
(Intface
), Error
);
8883 end Traverse_Interfaces
;
8885 -- Start of processing for Try_Class_Wide_Operation
8888 -- If we are searching only for conflicting class-wide subprograms
8889 -- then initialize directly Matching_Op with the target entity.
8891 if CW_Test_Only
then
8892 Matching_Op
:= Entity
(Selector_Name
(N
));
8895 -- Loop through ancestor types (including interfaces), traversing
8896 -- the homonym chain of the subprogram, trying out those homonyms
8897 -- whose first formal has the class-wide type of the ancestor, or
8898 -- an anonymous access type designating the class-wide type.
8900 Anc_Type
:= Obj_Type
;
8902 -- Look for a match among homonyms associated with the ancestor
8904 Traverse_Homonyms
(Anc_Type
, Error
);
8910 -- Continue the search for matches among homonyms associated with
8911 -- any interfaces implemented by the ancestor.
8913 Traverse_Interfaces
(Anc_Type
, Error
);
8919 exit when Etype
(Anc_Type
) = Anc_Type
;
8920 Anc_Type
:= Etype
(Anc_Type
);
8923 if Present
(Matching_Op
) then
8924 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
8927 return Present
(Matching_Op
);
8928 end Try_Class_Wide_Operation
;
8930 -----------------------------------
8931 -- Try_One_Prefix_Interpretation --
8932 -----------------------------------
8934 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
) is
8936 -- If the interpretation does not have a valid candidate type,
8937 -- preserve current value of Obj_Type for subsequent errors.
8939 Prev_Obj_Type
: constant Entity_Id
:= Obj_Type
;
8944 if Is_Access_Type
(Obj_Type
) then
8945 Obj_Type
:= Designated_Type
(Obj_Type
);
8948 if Ekind
(Obj_Type
) = E_Private_Subtype
then
8949 Obj_Type
:= Base_Type
(Obj_Type
);
8952 if Is_Class_Wide_Type
(Obj_Type
) then
8953 Obj_Type
:= Etype
(Class_Wide_Type
(Obj_Type
));
8956 -- The type may have be obtained through a limited_with clause,
8957 -- in which case the primitive operations are available on its
8958 -- non-limited view. If still incomplete, retrieve full view.
8960 if Ekind
(Obj_Type
) = E_Incomplete_Type
8961 and then From_Limited_With
(Obj_Type
)
8962 and then Has_Non_Limited_View
(Obj_Type
)
8964 Obj_Type
:= Get_Full_View
(Non_Limited_View
(Obj_Type
));
8967 -- If the object is not tagged, or the type is still an incomplete
8968 -- type, this is not a prefixed call.
8970 if not Is_Tagged_Type
(Obj_Type
)
8971 or else Is_Incomplete_Type
(Obj_Type
)
8974 -- Restore previous type if current one is not legal candidate
8976 Obj_Type
:= Prev_Obj_Type
;
8981 Dup_Call_Node
: constant Node_Id
:= New_Copy
(New_Call_Node
);
8982 CW_Result
: Boolean;
8983 Prim_Result
: Boolean;
8984 pragma Unreferenced
(CW_Result
);
8987 if not CW_Test_Only
then
8989 Try_Primitive_Operation
8990 (Call_Node
=> New_Call_Node
,
8991 Node_To_Replace
=> Node_To_Replace
);
8994 -- Check if there is a class-wide subprogram covering the
8995 -- primitive. This check must be done even if a candidate
8996 -- was found in order to report ambiguous calls.
8998 if not (Prim_Result
) then
9000 Try_Class_Wide_Operation
9001 (Call_Node
=> New_Call_Node
,
9002 Node_To_Replace
=> Node_To_Replace
);
9004 -- If we found a primitive we search for class-wide subprograms
9005 -- using a duplicate of the call node (done to avoid missing its
9006 -- decoration if there is no ambiguity).
9010 Try_Class_Wide_Operation
9011 (Call_Node
=> Dup_Call_Node
,
9012 Node_To_Replace
=> Node_To_Replace
);
9015 end Try_One_Prefix_Interpretation
;
9017 -----------------------------
9018 -- Try_Primitive_Operation --
9019 -----------------------------
9021 function Try_Primitive_Operation
9022 (Call_Node
: Node_Id
;
9023 Node_To_Replace
: Node_Id
) return Boolean
9026 Prim_Op
: Entity_Id
;
9027 Matching_Op
: Entity_Id
:= Empty
;
9028 Prim_Op_Ref
: Node_Id
:= Empty
;
9030 Corr_Type
: Entity_Id
:= Empty
;
9031 -- If the prefix is a synchronized type, the controlling type of
9032 -- the primitive operation is the corresponding record type, else
9033 -- this is the object type itself.
9035 Success
: Boolean := False;
9037 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
;
9038 -- For tagged types the candidate interpretations are found in
9039 -- the list of primitive operations of the type and its ancestors.
9040 -- For formal tagged types we have to find the operations declared
9041 -- in the same scope as the type (including in the generic formal
9042 -- part) because the type itself carries no primitive operations,
9043 -- except for formal derived types that inherit the operations of
9044 -- the parent and progenitors.
9046 -- If the context is a generic subprogram body, the generic formals
9047 -- are visible by name, but are not in the entity list of the
9048 -- subprogram because that list starts with the subprogram formals.
9049 -- We retrieve the candidate operations from the generic declaration.
9051 function Extended_Primitive_Ops
(T
: Entity_Id
) return Elist_Id
;
9052 -- Prefix notation can also be used on operations that are not
9053 -- primitives of the type, but are declared in the same immediate
9054 -- declarative part, which can only mean the corresponding package
9055 -- body (See RM 4.1.3 (9.2/3)). If we are in that body we extend the
9056 -- list of primitives with body operations with the same name that
9057 -- may be candidates, so that Try_Primitive_Operations can examine
9058 -- them if no real primitive is found.
9060 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean;
9061 -- An operation that overrides an inherited operation in the private
9062 -- part of its package may be hidden, but if the inherited operation
9063 -- is visible a direct call to it will dispatch to the private one,
9064 -- which is therefore a valid candidate.
9066 function Names_Match
9067 (Obj_Type
: Entity_Id
;
9068 Prim_Op
: Entity_Id
;
9069 Subprog
: Entity_Id
) return Boolean;
9070 -- Return True if the names of Prim_Op and Subprog match. If Obj_Type
9071 -- is a protected type then compare also the original name of Prim_Op
9072 -- with the name of Subprog (since the expander may have added a
9073 -- prefix to its original name --see Exp_Ch9.Build_Selected_Name).
9075 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean;
9076 -- Verify that the prefix, dereferenced if need be, is a valid
9077 -- controlling argument in a call to Op. The remaining actuals
9078 -- are checked in the subsequent call to Analyze_One_Call.
9080 ------------------------------
9081 -- Collect_Generic_Type_Ops --
9082 ------------------------------
9084 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
is
9085 Bas
: constant Entity_Id
:= Base_Type
(T
);
9086 Candidates
: constant Elist_Id
:= New_Elmt_List
;
9090 procedure Check_Candidate
;
9091 -- The operation is a candidate if its first parameter is a
9092 -- controlling operand of the desired type.
9094 -----------------------
9095 -- Check_Candidate; --
9096 -----------------------
9098 procedure Check_Candidate
is
9100 Formal
:= First_Formal
(Subp
);
9103 and then Is_Controlling_Formal
(Formal
)
9105 (Base_Type
(Etype
(Formal
)) = Bas
9107 (Is_Access_Type
(Etype
(Formal
))
9108 and then Designated_Type
(Etype
(Formal
)) = Bas
))
9110 Append_Elmt
(Subp
, Candidates
);
9112 end Check_Candidate
;
9114 -- Start of processing for Collect_Generic_Type_Ops
9117 if Is_Derived_Type
(T
) then
9118 return Primitive_Operations
(T
);
9120 elsif Ekind_In
(Scope
(T
), E_Procedure
, E_Function
) then
9122 -- Scan the list of generic formals to find subprograms
9123 -- that may have a first controlling formal of the type.
9125 if Nkind
(Unit_Declaration_Node
(Scope
(T
))) =
9126 N_Generic_Subprogram_Declaration
9133 First
(Generic_Formal_Declarations
9134 (Unit_Declaration_Node
(Scope
(T
))));
9135 while Present
(Decl
) loop
9136 if Nkind
(Decl
) in N_Formal_Subprogram_Declaration
then
9137 Subp
:= Defining_Entity
(Decl
);
9148 -- Scan the list of entities declared in the same scope as
9149 -- the type. In general this will be an open scope, given that
9150 -- the call we are analyzing can only appear within a generic
9151 -- declaration or body (either the one that declares T, or a
9154 -- For a subtype representing a generic actual type, go to the
9157 if Is_Generic_Actual_Type
(T
) then
9158 Subp
:= First_Entity
(Scope
(Base_Type
(T
)));
9160 Subp
:= First_Entity
(Scope
(T
));
9163 while Present
(Subp
) loop
9164 if Is_Overloadable
(Subp
) then
9173 end Collect_Generic_Type_Ops
;
9175 ----------------------------
9176 -- Extended_Primitive_Ops --
9177 ----------------------------
9179 function Extended_Primitive_Ops
(T
: Entity_Id
) return Elist_Id
is
9180 Type_Scope
: constant Entity_Id
:= Scope
(T
);
9182 Body_Decls
: List_Id
;
9188 Op_List
:= Primitive_Operations
(T
);
9190 if Ekind
(Type_Scope
) = E_Package
9191 and then In_Package_Body
(Type_Scope
)
9192 and then In_Open_Scopes
(Type_Scope
)
9194 -- Retrieve list of declarations of package body.
9198 (Unit_Declaration_Node
9200 (Unit_Declaration_Node
(Type_Scope
))));
9202 Op
:= Current_Entity
(Subprog
);
9204 while Present
(Op
) loop
9205 if Comes_From_Source
(Op
)
9206 and then Is_Overloadable
(Op
)
9208 -- Exclude overriding primitive operations of a type
9209 -- extension declared in the package body, to prevent
9210 -- duplicates in extended list.
9212 and then not Is_Primitive
(Op
)
9213 and then Is_List_Member
(Unit_Declaration_Node
(Op
))
9214 and then List_Containing
(Unit_Declaration_Node
(Op
)) =
9217 if not Op_Found
then
9219 -- Copy list of primitives so it is not affected for
9222 Op_List
:= New_Copy_Elist
(Op_List
);
9226 Append_Elmt
(Op
, Op_List
);
9234 end Extended_Primitive_Ops
;
9236 ---------------------------
9237 -- Is_Private_Overriding --
9238 ---------------------------
9240 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean is
9241 Visible_Op
: constant Entity_Id
:= Homonym
(Op
);
9244 return Present
(Visible_Op
)
9245 and then Scope
(Op
) = Scope
(Visible_Op
)
9246 and then not Comes_From_Source
(Visible_Op
)
9247 and then Alias
(Visible_Op
) = Op
9248 and then not Is_Hidden
(Visible_Op
);
9249 end Is_Private_Overriding
;
9255 function Names_Match
9256 (Obj_Type
: Entity_Id
;
9257 Prim_Op
: Entity_Id
;
9258 Subprog
: Entity_Id
) return Boolean is
9260 -- Common case: exact match
9262 if Chars
(Prim_Op
) = Chars
(Subprog
) then
9265 -- For protected type primitives the expander may have built the
9266 -- name of the dispatching primitive prepending the type name to
9267 -- avoid conflicts with the name of the protected subprogram (see
9268 -- Exp_Ch9.Build_Selected_Name).
9270 elsif Is_Protected_Type
(Obj_Type
) then
9272 Present
(Original_Protected_Subprogram
(Prim_Op
))
9273 and then Chars
(Original_Protected_Subprogram
(Prim_Op
)) =
9280 -----------------------------
9281 -- Valid_First_Argument_Of --
9282 -----------------------------
9284 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean is
9285 Typ
: Entity_Id
:= Etype
(First_Formal
(Op
));
9288 if Is_Concurrent_Type
(Typ
)
9289 and then Present
(Corresponding_Record_Type
(Typ
))
9291 Typ
:= Corresponding_Record_Type
(Typ
);
9294 -- Simple case. Object may be a subtype of the tagged type or may
9295 -- be the corresponding record of a synchronized type.
9297 return Obj_Type
= Typ
9298 or else Base_Type
(Obj_Type
) = Typ
9299 or else Corr_Type
= Typ
9301 -- Object may be of a derived type whose parent has unknown
9302 -- discriminants, in which case the type matches the underlying
9303 -- record view of its base.
9306 (Has_Unknown_Discriminants
(Typ
)
9307 and then Typ
= Underlying_Record_View
(Base_Type
(Obj_Type
)))
9309 -- Prefix can be dereferenced
9312 (Is_Access_Type
(Corr_Type
)
9313 and then Designated_Type
(Corr_Type
) = Typ
)
9315 -- Formal is an access parameter, for which the object can
9316 -- provide an access.
9319 (Ekind
(Typ
) = E_Anonymous_Access_Type
9321 Base_Type
(Designated_Type
(Typ
)) = Base_Type
(Corr_Type
));
9322 end Valid_First_Argument_Of
;
9324 -- Start of processing for Try_Primitive_Operation
9327 -- Look for subprograms in the list of primitive operations. The name
9328 -- must be identical, and the kind of call indicates the expected
9329 -- kind of operation (function or procedure). If the type is a
9330 -- (tagged) synchronized type, the primitive ops are attached to the
9331 -- corresponding record (base) type.
9333 if Is_Concurrent_Type
(Obj_Type
) then
9334 if Present
(Corresponding_Record_Type
(Obj_Type
)) then
9335 Corr_Type
:= Base_Type
(Corresponding_Record_Type
(Obj_Type
));
9336 Elmt
:= First_Elmt
(Primitive_Operations
(Corr_Type
));
9338 Corr_Type
:= Obj_Type
;
9339 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
9342 elsif not Is_Generic_Type
(Obj_Type
) then
9343 Corr_Type
:= Obj_Type
;
9344 Elmt
:= First_Elmt
(Extended_Primitive_Ops
(Obj_Type
));
9347 Corr_Type
:= Obj_Type
;
9348 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
9351 while Present
(Elmt
) loop
9352 Prim_Op
:= Node
(Elmt
);
9354 if Names_Match
(Obj_Type
, Prim_Op
, Subprog
)
9355 and then Present
(First_Formal
(Prim_Op
))
9356 and then Valid_First_Argument_Of
(Prim_Op
)
9358 (Nkind
(Call_Node
) = N_Function_Call
)
9360 (Ekind
(Prim_Op
) = E_Function
)
9362 -- Ada 2005 (AI-251): If this primitive operation corresponds
9363 -- to an immediate ancestor interface there is no need to add
9364 -- it to the list of interpretations; the corresponding aliased
9365 -- primitive is also in this list of primitive operations and
9366 -- will be used instead.
9368 if (Present
(Interface_Alias
(Prim_Op
))
9369 and then Is_Ancestor
(Find_Dispatching_Type
9370 (Alias
(Prim_Op
)), Corr_Type
))
9372 -- Do not consider hidden primitives unless the type is in an
9373 -- open scope or we are within an instance, where visibility
9374 -- is known to be correct, or else if this is an overriding
9375 -- operation in the private part for an inherited operation.
9377 or else (Is_Hidden
(Prim_Op
)
9378 and then not Is_Immediately_Visible
(Obj_Type
)
9379 and then not In_Instance
9380 and then not Is_Private_Overriding
(Prim_Op
))
9385 Set_Etype
(Call_Node
, Any_Type
);
9386 Set_Is_Overloaded
(Call_Node
, False);
9388 if No
(Matching_Op
) then
9389 Prim_Op_Ref
:= New_Occurrence_Of
(Prim_Op
, Sloc
(Subprog
));
9390 Candidate
:= Prim_Op
;
9392 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
9394 Set_Name
(Call_Node
, Prim_Op_Ref
);
9400 Report
=> Report_Error
,
9402 Skip_First
=> True);
9404 Matching_Op
:= Valid_Candidate
(Success
, Call_Node
, Prim_Op
);
9406 -- More than one interpretation, collect for subsequent
9407 -- disambiguation. If this is a procedure call and there
9408 -- is another match, report ambiguity now.
9414 Report
=> Report_Error
,
9416 Skip_First
=> True);
9418 if Present
(Valid_Candidate
(Success
, Call_Node
, Prim_Op
))
9419 and then Nkind
(Call_Node
) /= N_Function_Call
9421 Error_Msg_NE
("ambiguous call to&", N
, Prim_Op
);
9422 Report_Ambiguity
(Matching_Op
);
9423 Report_Ambiguity
(Prim_Op
);
9433 if Present
(Matching_Op
) then
9434 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
9437 return Present
(Matching_Op
);
9438 end Try_Primitive_Operation
;
9440 -- Start of processing for Try_Object_Operation
9443 Analyze_Expression
(Obj
);
9445 -- Analyze the actuals if node is known to be a subprogram call
9447 if Is_Subprg_Call
and then N
= Name
(Parent
(N
)) then
9448 Actual
:= First
(Parameter_Associations
(Parent
(N
)));
9449 while Present
(Actual
) loop
9450 Analyze_Expression
(Actual
);
9455 -- Build a subprogram call node, using a copy of Obj as its first
9456 -- actual. This is a placeholder, to be replaced by an explicit
9457 -- dereference when needed.
9459 Transform_Object_Operation
9460 (Call_Node
=> New_Call_Node
,
9461 Node_To_Replace
=> Node_To_Replace
);
9463 Set_Etype
(New_Call_Node
, Any_Type
);
9464 Set_Etype
(Subprog
, Any_Type
);
9465 Set_Parent
(New_Call_Node
, Parent
(Node_To_Replace
));
9467 if not Is_Overloaded
(Obj
) then
9468 Try_One_Prefix_Interpretation
(Obj_Type
);
9475 Get_First_Interp
(Obj
, I
, It
);
9476 while Present
(It
.Nam
) loop
9477 Try_One_Prefix_Interpretation
(It
.Typ
);
9478 Get_Next_Interp
(I
, It
);
9483 if Etype
(New_Call_Node
) /= Any_Type
then
9485 -- No need to complete the tree transformations if we are only
9486 -- searching for conflicting class-wide subprograms
9488 if CW_Test_Only
then
9491 Complete_Object_Operation
9492 (Call_Node
=> New_Call_Node
,
9493 Node_To_Replace
=> Node_To_Replace
);
9497 elsif Present
(Candidate
) then
9499 -- The argument list is not type correct. Re-analyze with error
9500 -- reporting enabled, and use one of the possible candidates.
9501 -- In All_Errors_Mode, re-analyze all failed interpretations.
9503 if All_Errors_Mode
then
9504 Report_Error
:= True;
9505 if Try_Primitive_Operation
9506 (Call_Node
=> New_Call_Node
,
9507 Node_To_Replace
=> Node_To_Replace
)
9510 Try_Class_Wide_Operation
9511 (Call_Node
=> New_Call_Node
,
9512 Node_To_Replace
=> Node_To_Replace
)
9519 (N
=> New_Call_Node
,
9523 Skip_First
=> True);
9526 -- No need for further errors
9531 -- There was no candidate operation, so report it as an error
9532 -- in the caller: Analyze_Selected_Component.
9536 end Try_Object_Operation
;
9542 procedure wpo
(T
: Entity_Id
) is
9547 if not Is_Tagged_Type
(T
) then
9551 E
:= First_Elmt
(Primitive_Operations
(Base_Type
(T
)));
9552 while Present
(E
) loop
9554 Write_Int
(Int
(Op
));
9555 Write_Str
(" === ");
9556 Write_Name
(Chars
(Op
));
9558 Write_Name
(Chars
(Scope
(Op
)));