1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 Accessibility
; use Accessibility
;
27 with Aspects
; use Aspects
;
28 with Atree
; use Atree
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Einfo
.Entities
; use Einfo
.Entities
;
32 with Einfo
.Utils
; use Einfo
.Utils
;
33 with Elists
; use Elists
;
34 with Errout
; use Errout
;
35 with Exp_Util
; use Exp_Util
;
36 with Itypes
; use Itypes
;
38 with Lib
.Xref
; use Lib
.Xref
;
39 with Namet
; use Namet
;
40 with Namet
.Sp
; use Namet
.Sp
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
44 with Output
; use Output
;
45 with Restrict
; use Restrict
;
46 with Rident
; use Rident
;
47 with Rtsfind
; use Rtsfind
;
49 with Sem_Aux
; use Sem_Aux
;
50 with Sem_Case
; use Sem_Case
;
51 with Sem_Cat
; use Sem_Cat
;
52 with Sem_Ch3
; use Sem_Ch3
;
53 with Sem_Ch6
; use Sem_Ch6
;
54 with Sem_Ch8
; use Sem_Ch8
;
55 with Sem_Dim
; use Sem_Dim
;
56 with Sem_Disp
; use Sem_Disp
;
57 with Sem_Dist
; use Sem_Dist
;
58 with Sem_Eval
; use Sem_Eval
;
59 with Sem_Res
; use Sem_Res
;
60 with Sem_Type
; use Sem_Type
;
61 with Sem_Util
; use Sem_Util
;
62 with Sem_Warn
; use Sem_Warn
;
63 with Stand
; use Stand
;
64 with Sinfo
; use Sinfo
;
65 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
66 with Sinfo
.Utils
; use Sinfo
.Utils
;
67 with Snames
; use Snames
;
68 with Style
; use Style
;
69 with Tbuild
; use Tbuild
;
70 with Uintp
; use Uintp
;
71 with Warnsw
; use Warnsw
;
73 package body Sem_Ch4
is
75 -- Tables which speed up the identification of dangerous calls to Ada 2012
76 -- functions with writable actuals (AI05-0144).
78 -- The following table enumerates the Ada constructs which may evaluate in
79 -- arbitrary order. It does not cover all the language constructs which can
80 -- be evaluated in arbitrary order but the subset needed for AI05-0144.
82 Has_Arbitrary_Evaluation_Order
: constant array (Node_Kind
) of Boolean :=
84 N_Assignment_Statement
=> True,
85 N_Entry_Call_Statement
=> True,
86 N_Extension_Aggregate
=> True,
87 N_Full_Type_Declaration
=> True,
88 N_Indexed_Component
=> True,
89 N_Object_Declaration
=> True,
93 N_Array_Type_Definition
=> True,
94 N_Membership_Test
=> True,
96 N_Subprogram_Call
=> True,
99 -- The following table enumerates the nodes on which we stop climbing when
100 -- locating the outermost Ada construct that can be evaluated in arbitrary
103 Stop_Subtree_Climbing
: constant array (Node_Kind
) of Boolean :=
104 (N_Aggregate
=> True,
105 N_Assignment_Statement
=> True,
106 N_Entry_Call_Statement
=> True,
107 N_Extended_Return_Statement
=> True,
108 N_Extension_Aggregate
=> True,
109 N_Full_Type_Declaration
=> True,
110 N_Object_Declaration
=> True,
111 N_Object_Renaming_Declaration
=> True,
112 N_Package_Specification
=> True,
114 N_Procedure_Call_Statement
=> True,
115 N_Simple_Return_Statement
=> True,
116 N_Has_Condition
=> True,
119 -----------------------
120 -- Local Subprograms --
121 -----------------------
123 procedure Analyze_Concatenation_Rest
(N
: Node_Id
);
124 -- Does the "rest" of the work of Analyze_Concatenation, after the left
125 -- operand has been analyzed. See Analyze_Concatenation for details.
127 procedure Analyze_Expression
(N
: Node_Id
);
128 -- For expressions that are not names, this is just a call to analyze. If
129 -- the expression is a name, it may be a call to a parameterless function,
130 -- and if so must be converted into an explicit call node and analyzed as
131 -- such. This deproceduring must be done during the first pass of overload
132 -- resolution, because otherwise a procedure call with overloaded actuals
133 -- may fail to resolve.
135 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
);
136 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call is an
137 -- operator name or an expanded name whose selector is an operator name,
138 -- and one possible interpretation is as a predefined operator.
140 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
);
141 -- If the prefix of a selected_component is overloaded, the proper
142 -- interpretation that yields a record type with the proper selector
143 -- name must be selected.
145 procedure Analyze_User_Defined_Binary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
146 -- Procedure to analyze a user defined binary operator, which is resolved
147 -- like a function, but instead of a list of actuals it is presented
148 -- with the left and right operands of an operator node.
150 procedure Analyze_User_Defined_Unary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
151 -- Procedure to analyze a user defined unary operator, which is resolved
152 -- like a function, but instead of a list of actuals, it is presented with
153 -- the operand of the operator node.
155 procedure Analyze_One_Call
159 Success
: out Boolean;
160 Skip_First
: Boolean := False);
161 -- Check one interpretation of an overloaded subprogram name for
162 -- compatibility with the types of the actuals in a call. If there is a
163 -- single interpretation which does not match, post error if Report is
166 -- Nam is the entity that provides the formals against which the actuals
167 -- are checked. Nam is either the name of a subprogram, or the internal
168 -- subprogram type constructed for an access_to_subprogram. If the actuals
169 -- are compatible with Nam, then Nam is added to the list of candidate
170 -- interpretations for N, and Success is set to True.
172 -- The flag Skip_First is used when analyzing a call that was rewritten
173 -- from object notation. In this case the first actual may have to receive
174 -- an explicit dereference, depending on the first formal of the operation
175 -- being called. The caller will have verified that the object is legal
176 -- for the call. If the remaining parameters match, the first parameter
177 -- will rewritten as a dereference if needed, prior to completing analysis.
179 procedure Check_Misspelled_Selector
182 -- Give possible misspelling message if Sel seems likely to be a mis-
183 -- spelling of one of the selectors of the Prefix. This is called by
184 -- Analyze_Selected_Component after producing an invalid selector error
187 procedure Find_Arithmetic_Types
191 -- L and R are the operands of an arithmetic operator. Find consistent
192 -- pairs of interpretations for L and R that have a numeric type consistent
193 -- with the semantics of the operator.
195 procedure Find_Comparison_Equality_Types
199 -- L and R are operands of a comparison or equality operator. Find valid
200 -- pairs of interpretations for L and R.
202 procedure Find_Concatenation_Types
206 -- For the four varieties of concatenation
208 procedure Find_Boolean_Types
212 -- Ditto for binary logical operations
214 procedure Find_Negation_Types
218 -- Find consistent interpretation for operand of negation operator
220 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean;
221 -- Find candidate interpretations for the name Obj.Proc when it appears in
222 -- a subprogram renaming declaration.
224 procedure Find_Unary_Types
228 -- Unary arithmetic types: plus, minus, abs
230 procedure Check_Arithmetic_Pair
234 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid types
235 -- for left and right operand. Determine whether they constitute a valid
236 -- pair for the given operator, and record the corresponding interpretation
237 -- of the operator node. The node N may be an operator node (the usual
238 -- case) or a function call whose prefix is an operator designator. In
239 -- both cases Op_Id is the operator name itself.
241 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
);
242 -- Give detailed information on overloaded call where none of the
243 -- interpretations match. N is the call node, Nam the designator for
244 -- the overloaded entity being called.
246 function Junk_Operand
(N
: Node_Id
) return Boolean;
247 -- Test for an operand that is an inappropriate entity (e.g. a package
248 -- name or a label). If so, issue an error message and return True. If
249 -- the operand is not an inappropriate entity kind, return False.
251 procedure Operator_Check
(N
: Node_Id
);
252 -- Verify that an operator has received some valid interpretation. If none
253 -- was found, determine whether a use clause would make the operation
254 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
255 -- every type compatible with the operator, even if the operator for the
256 -- type is not directly visible. The routine uses this type to emit a more
257 -- informative message.
259 function Has_Possible_User_Defined_Literal
(N
: Node_Id
) return Boolean;
260 -- Ada 2022: if an operand is a literal, it may be subject to an
261 -- implicit conversion to a type for which a user-defined literal
262 -- function exists. During the first pass of type resolution we do
263 -- not know the context imposed on the literal, so we assume that
264 -- the literal type is a valid candidate and rely on the second pass
265 -- of resolution to find the type with the proper aspect. We only
266 -- add this interpretation if no other one was found, which may be
267 -- too restrictive but seems sufficient to handle most proper uses
268 -- of the new aspect. It is unclear whether a full implementation of
269 -- these aspects can be achieved without larger modifications to the
270 -- two-pass resolution algorithm.
272 function Possible_Type_For_Conditional_Expression
273 (T1
, T2
: Entity_Id
) return Entity_Id
;
274 -- Given two types T1 and T2 that are _not_ compatible, return a type that
275 -- may still be used as the possible type of a conditional expression whose
276 -- dependent expressions, or part thereof, have type T1 and T2 respectively
277 -- during the first phase of type resolution, or Empty if such a type does
280 -- The typical example is an if_expression whose then_expression is of a
281 -- tagged type and whose else_expresssion is of an extension of this type:
282 -- the types are not compatible but such an if_expression can be legal if
283 -- its expected type is the 'Class of the tagged type, so the function will
284 -- return the tagged type in this case. If the expected type turns out to
285 -- be something else, including the tagged type itself, then an error will
286 -- be given during the second phase of type resolution.
288 procedure Remove_Abstract_Operations
(N
: Node_Id
);
289 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
290 -- operation is not a candidate interpretation.
292 function Try_Container_Indexing
295 Exprs
: List_Id
) return Boolean;
296 -- AI05-0139: Generalized indexing to support iterators over containers
297 -- ??? Need to provide a more detailed spec of what this function does
299 function Try_Indexed_Call
303 Skip_First
: Boolean) return Boolean;
304 -- If a function has defaults for all its actuals, a call to it may in fact
305 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
306 -- interpretation as an indexing, prior to analysis as a call. If both are
307 -- possible, the node is overloaded with both interpretations (same symbol
308 -- but two different types). If the call is written in prefix form, the
309 -- prefix becomes the first parameter in the call, and only the remaining
310 -- actuals must be checked for the presence of defaults.
312 function Try_Indirect_Call
315 Typ
: Entity_Id
) return Boolean;
316 -- Similarly, a function F that needs no actuals can return an access to a
317 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
318 -- the call may be overloaded with both interpretations.
320 procedure wpo
(T
: Entity_Id
);
321 pragma Warnings
(Off
, wpo
);
322 -- Used for debugging: obtain list of primitive operations even if
323 -- type is not frozen and dispatch table is not built yet.
325 ------------------------
326 -- Ambiguous_Operands --
327 ------------------------
329 procedure Ambiguous_Operands
(N
: Node_Id
) is
330 procedure List_Operand_Interps
(Opnd
: Node_Id
);
332 --------------------------
333 -- List_Operand_Interps --
334 --------------------------
336 procedure List_Operand_Interps
(Opnd
: Node_Id
) is
337 Nam
: Node_Id
:= Empty
;
341 if Is_Overloaded
(Opnd
) then
342 if Nkind
(Opnd
) in N_Op
then
345 elsif Nkind
(Opnd
) = N_Function_Call
then
348 elsif Ada_Version
>= Ada_2012
then
354 Get_First_Interp
(Opnd
, I
, It
);
355 while Present
(It
.Nam
) loop
356 if Has_Implicit_Dereference
(It
.Typ
) then
358 ("can be interpreted as implicit dereference", Opnd
);
362 Get_Next_Interp
(I
, It
);
373 if Opnd
= Left_Opnd
(N
) then
375 ("\left operand has the following interpretations", N
);
378 ("\right operand has the following interpretations", N
);
382 List_Interps
(Nam
, Err
);
383 end List_Operand_Interps
;
385 -- Start of processing for Ambiguous_Operands
388 if Nkind
(N
) in N_Membership_Test
then
389 Error_Msg_N
("ambiguous operands for membership", N
);
391 elsif Nkind
(N
) in N_Op_Eq | N_Op_Ne
then
392 Error_Msg_N
("ambiguous operands for equality", N
);
395 Error_Msg_N
("ambiguous operands for comparison", N
);
398 if All_Errors_Mode
then
399 List_Operand_Interps
(Left_Opnd
(N
));
400 List_Operand_Interps
(Right_Opnd
(N
));
402 Error_Msg_N
("\use -gnatf switch for details", N
);
404 end Ambiguous_Operands
;
406 -----------------------
407 -- Analyze_Aggregate --
408 -----------------------
410 -- Most of the analysis of Aggregates requires that the type be known, and
411 -- is therefore put off until resolution of the context. Delta aggregates
412 -- have a base component that determines the enclosing aggregate type so
413 -- its type can be ascertained earlier. This also allows delta aggregates
414 -- to appear in the context of a record type with a private extension, as
415 -- per the latest update of AI12-0127.
417 procedure Analyze_Aggregate
(N
: Node_Id
) is
419 if No
(Etype
(N
)) then
420 if Nkind
(N
) = N_Delta_Aggregate
then
422 Base
: constant Node_Id
:= Expression
(N
);
430 -- If the base is overloaded, propagate interpretations to the
431 -- enclosing aggregate.
433 if Is_Overloaded
(Base
) then
434 Get_First_Interp
(Base
, I
, It
);
435 Set_Etype
(N
, Any_Type
);
437 while Present
(It
.Nam
) loop
438 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
439 Get_Next_Interp
(I
, It
);
443 Set_Etype
(N
, Etype
(Base
));
448 Set_Etype
(N
, Any_Composite
);
451 end Analyze_Aggregate
;
453 -----------------------
454 -- Analyze_Allocator --
455 -----------------------
457 procedure Analyze_Allocator
(N
: Node_Id
) is
458 Loc
: constant Source_Ptr
:= Sloc
(N
);
459 Sav_Errs
: constant Nat
:= Serious_Errors_Detected
;
460 E
: Node_Id
:= Expression
(N
);
461 Acc_Type
: Entity_Id
;
468 -- Deal with allocator restrictions
470 -- In accordance with H.4(7), the No_Allocators restriction only applies
471 -- to user-written allocators. The same consideration applies to the
472 -- No_Standard_Allocators_Before_Elaboration restriction.
474 if Comes_From_Source
(N
) then
475 Check_Restriction
(No_Allocators
, N
);
477 -- Processing for No_Standard_Allocators_After_Elaboration, loop to
478 -- look at enclosing context, checking task/main subprogram case.
482 while Present
(P
) loop
484 -- For the task case we need a handled sequence of statements,
485 -- where the occurrence of the allocator is within the statements
486 -- and the parent is a task body
488 if Nkind
(P
) = N_Handled_Sequence_Of_Statements
489 and then Is_List_Member
(C
)
490 and then List_Containing
(C
) = Statements
(P
)
492 Onode
:= Original_Node
(Parent
(P
));
494 -- Check for allocator within task body, this is a definite
495 -- violation of No_Allocators_After_Elaboration we can detect
498 if Nkind
(Onode
) = N_Task_Body
then
500 (No_Standard_Allocators_After_Elaboration
, N
);
505 -- The other case is appearance in a subprogram body. This is
506 -- a violation if this is a library level subprogram with no
507 -- parameters. Note that this is now a static error even if the
508 -- subprogram is not the main program (this is a change, in an
509 -- earlier version only the main program was affected, and the
510 -- check had to be done in the binder).
512 if Nkind
(P
) = N_Subprogram_Body
513 and then Nkind
(Parent
(P
)) = N_Compilation_Unit
514 and then No
(Parameter_Specifications
(Specification
(P
)))
517 (No_Standard_Allocators_After_Elaboration
, N
);
525 -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
526 -- any. The expected type for the name is any type. A non-overloading
527 -- rule then requires it to be of a type descended from
528 -- System.Storage_Pools.Subpools.Subpool_Handle.
530 -- This isn't exactly what the AI says, but it seems to be the right
531 -- rule. The AI should be fixed.???
534 Subpool
: constant Node_Id
:= Subpool_Handle_Name
(N
);
537 if Present
(Subpool
) then
540 if Is_Overloaded
(Subpool
) then
541 Error_Msg_N
("ambiguous subpool handle", Subpool
);
544 -- Check that Etype (Subpool) is descended from Subpool_Handle
550 -- Analyze the qualified expression or subtype indication
552 if Nkind
(E
) = N_Qualified_Expression
then
553 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
554 Set_Etype
(Acc_Type
, Acc_Type
);
555 Find_Type
(Subtype_Mark
(E
));
557 -- Analyze the qualified expression, and apply the name resolution
558 -- rule given in 4.7(3).
561 Type_Id
:= Etype
(E
);
562 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
564 -- A qualified expression requires an exact match of the type,
565 -- class-wide matching is not allowed.
567 -- if Is_Class_Wide_Type (Type_Id)
568 -- and then Base_Type
569 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
571 -- Wrong_Type (Expression (E), Type_Id);
574 -- We don't analyze the qualified expression itself because it's
575 -- part of the allocator. It is fully analyzed and resolved when
576 -- the allocator is resolved with the context type.
578 Set_Etype
(E
, Type_Id
);
580 -- Case where allocator has a subtype indication
583 -- If the allocator includes a N_Subtype_Indication then a
584 -- constraint is present, otherwise the node is a subtype mark.
585 -- Introduce an explicit subtype declaration into the tree
586 -- defining some anonymous subtype and rewrite the allocator to
587 -- use this subtype rather than the subtype indication.
589 -- It is important to introduce the explicit subtype declaration
590 -- so that the bounds of the subtype indication are attached to
591 -- the tree in case the allocator is inside a generic unit.
593 -- Finally, if there is no subtype indication and the type is
594 -- a tagged unconstrained type with discriminants, the designated
595 -- object is constrained by their default values, and it is
596 -- simplest to introduce an explicit constraint now. In some cases
597 -- this is done during expansion, but freeze actions are certain
598 -- to be emitted in the proper order if constraint is explicit.
600 if Is_Entity_Name
(E
) and then Expander_Active
then
602 Type_Id
:= Entity
(E
);
604 if Is_Tagged_Type
(Type_Id
)
605 and then Has_Defaulted_Discriminants
(Type_Id
)
606 and then not Is_Constrained
(Type_Id
)
609 Constr
: constant List_Id
:= New_List
;
610 Loc
: constant Source_Ptr
:= Sloc
(E
);
611 Discr
: Entity_Id
:= First_Discriminant
(Type_Id
);
614 while Present
(Discr
) loop
615 Append
(Discriminant_Default_Value
(Discr
), Constr
);
616 Next_Discriminant
(Discr
);
620 Make_Subtype_Indication
(Loc
,
621 Subtype_Mark
=> New_Occurrence_Of
(Type_Id
, Loc
),
623 Make_Index_Or_Discriminant_Constraint
(Loc
,
624 Constraints
=> Constr
)));
629 if Nkind
(E
) = N_Subtype_Indication
then
632 Base_Typ
: Entity_Id
;
635 -- A constraint is only allowed for a composite type in Ada
636 -- 95. In Ada 83, a constraint is also allowed for an
637 -- access-to-composite type, but the constraint is ignored.
639 Find_Type
(Subtype_Mark
(E
));
640 Base_Typ
:= Entity
(Subtype_Mark
(E
));
642 if Is_Elementary_Type
(Base_Typ
) then
643 if not (Ada_Version
= Ada_83
644 and then Is_Access_Type
(Base_Typ
))
646 Error_Msg_N
("constraint not allowed here", E
);
648 if Nkind
(Constraint
(E
)) =
649 N_Index_Or_Discriminant_Constraint
651 Error_Msg_N
-- CODEFIX
652 ("\if qualified expression was meant, " &
653 "use apostrophe", Constraint
(E
));
657 -- Get rid of the bogus constraint:
659 Rewrite
(E
, New_Copy_Tree
(Subtype_Mark
(E
)));
660 Analyze_Allocator
(N
);
664 -- In GNATprove mode we need to preserve the link between
665 -- the original subtype indication and the anonymous subtype,
666 -- to extend proofs to constrained access types. We only do
667 -- that outside of spec expressions, otherwise the declaration
668 -- cannot be inserted and analyzed. In such a case, GNATprove
669 -- later rejects the allocator as it is not used here in
670 -- a non-interfering context (SPARK 4.8(2) and 7.1.3(10)).
673 or else (GNATprove_Mode
and then not In_Spec_Expression
)
675 Def_Id
:= Make_Temporary
(Loc
, 'S');
678 Subtype_Decl
: constant Node_Id
:=
679 Make_Subtype_Declaration
(Loc
,
680 Defining_Identifier
=> Def_Id
,
681 Subtype_Indication
=> Relocate_Node
(E
));
683 Insert_Action
(E
, Subtype_Decl
);
685 -- Handle unusual case where Insert_Action does not
686 -- analyze the declaration. Subtype_Decl must be
687 -- preanalyzed before call to Process_Subtype below.
688 Preanalyze
(Subtype_Decl
);
691 if Sav_Errs
/= Serious_Errors_Detected
692 and then Nkind
(Constraint
(E
)) =
693 N_Index_Or_Discriminant_Constraint
695 Error_Msg_N
-- CODEFIX
696 ("if qualified expression was meant, use apostrophe!",
700 E
:= New_Occurrence_Of
(Def_Id
, Loc
);
701 Rewrite
(Expression
(N
), E
);
706 Type_Id
:= Process_Subtype
(E
, N
);
707 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
708 Set_Etype
(Acc_Type
, Acc_Type
);
709 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
710 Check_Fully_Declared
(Type_Id
, N
);
712 -- Ada 2005 (AI-231): If the designated type is itself an access
713 -- type that excludes null, its default initialization will
714 -- be a null object, and we can insert an unconditional raise
715 -- before the allocator.
717 -- Ada 2012 (AI-104): A not null indication here is altogether
720 if Can_Never_Be_Null
(Type_Id
) then
722 Not_Null_Check
: constant Node_Id
:=
723 Make_Raise_Constraint_Error
(Sloc
(E
),
724 Reason
=> CE_Null_Not_Allowed
);
727 if Expander_Active
then
728 Insert_Action
(N
, Not_Null_Check
);
729 Analyze
(Not_Null_Check
);
731 elsif Warn_On_Ada_2012_Compatibility
then
733 ("null value not allowed here in Ada 2012?y?", E
);
738 -- Check for missing initialization. Skip this check if the allocator
739 -- is made for a special return object or if we already had errors on
740 -- analyzing the allocator since, in that case, these are very likely
743 if not Is_Definite_Subtype
(Type_Id
)
744 and then not For_Special_Return_Object
(N
)
745 and then Serious_Errors_Detected
= Sav_Errs
747 if Is_Class_Wide_Type
(Type_Id
) then
749 ("initialization required in class-wide allocation", N
);
752 if Ada_Version
< Ada_2005
753 and then Is_Limited_Type
(Type_Id
)
755 Error_Msg_N
("unconstrained allocation not allowed", N
);
757 if Is_Array_Type
(Type_Id
) then
759 ("\constraint with array bounds required", N
);
761 elsif Has_Unknown_Discriminants
(Type_Id
) then
764 else pragma Assert
(Has_Discriminants
(Type_Id
));
766 ("\constraint with discriminant values required", N
);
769 -- Limited Ada 2005 and general nonlimited case.
770 -- This is an error, except in the case of an
771 -- uninitialized allocator that is generated
772 -- for a build-in-place function return of a
773 -- discriminated but compile-time-known-size
777 if Is_Rewrite_Substitution
(N
)
778 and then Nkind
(Original_Node
(N
)) = N_Allocator
781 Qual
: constant Node_Id
:=
782 Expression
(Original_Node
(N
));
784 (Nkind
(Qual
) = N_Qualified_Expression
);
785 Call
: constant Node_Id
:= Expression
(Qual
);
787 (Is_Expanded_Build_In_Place_Call
(Call
));
794 ("uninitialized unconstrained allocation not "
797 if Is_Array_Type
(Type_Id
) then
799 ("\qualified expression or constraint with "
800 & "array bounds required", N
);
802 elsif Has_Unknown_Discriminants
(Type_Id
) then
803 Error_Msg_N
("\qualified expression required", N
);
805 else pragma Assert
(Has_Discriminants
(Type_Id
));
807 ("\qualified expression or constraint with "
808 & "discriminant values required", N
);
816 if Is_Abstract_Type
(Type_Id
) then
817 Error_Msg_N
("cannot allocate abstract object", E
);
820 Set_Etype
(N
, Acc_Type
);
822 -- If this is an allocator for the return stack, then no restriction may
823 -- be violated since it's just a low-level access to the primary stack.
825 if Nkind
(Parent
(N
)) = N_Object_Declaration
826 and then Is_Entity_Name
(Object_Definition
(Parent
(N
)))
827 and then Is_Access_Type
(Entity
(Object_Definition
(Parent
(N
))))
830 Pool
: constant Entity_Id
:=
831 Associated_Storage_Pool
832 (Root_Type
(Entity
(Object_Definition
(Parent
(N
)))));
835 if Present
(Pool
) and then Is_RTE
(Pool
, RE_RS_Pool
) then
841 if Has_Task
(Designated_Type
(Acc_Type
)) then
842 Check_Restriction
(No_Tasking
, N
);
843 Check_Restriction
(Max_Tasks
, N
);
844 Check_Restriction
(No_Task_Allocators
, N
);
847 -- Check restriction against dynamically allocated protected objects
849 if Has_Protected
(Designated_Type
(Acc_Type
)) then
850 Check_Restriction
(No_Protected_Type_Allocators
, N
);
853 -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
854 -- type is nested, and the designated type needs finalization. The rule
855 -- is conservative in that class-wide types need finalization.
857 if Needs_Finalization
(Designated_Type
(Acc_Type
))
858 and then not Is_Library_Level_Entity
(Acc_Type
)
860 Check_Restriction
(No_Nested_Finalization
, N
);
863 -- Check that an allocator of a nested access type doesn't create a
864 -- protected object when restriction No_Local_Protected_Objects applies.
866 if Has_Protected
(Designated_Type
(Acc_Type
))
867 and then not Is_Library_Level_Entity
(Acc_Type
)
869 Check_Restriction
(No_Local_Protected_Objects
, N
);
872 -- Likewise for No_Local_Timing_Events
874 if Has_Timing_Event
(Designated_Type
(Acc_Type
))
875 and then not Is_Library_Level_Entity
(Acc_Type
)
877 Check_Restriction
(No_Local_Timing_Events
, N
);
880 -- If the No_Streams restriction is set, check that the type of the
881 -- object is not, and does not contain, any subtype derived from
882 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
883 -- Has_Stream just for efficiency reasons. There is no point in
884 -- spending time on a Has_Stream check if the restriction is not set.
886 if Restriction_Check_Required
(No_Streams
) then
887 if Has_Stream
(Designated_Type
(Acc_Type
)) then
888 Check_Restriction
(No_Streams
, N
);
892 if not Is_Library_Level_Entity
(Acc_Type
) then
893 Check_Restriction
(No_Local_Allocators
, N
);
897 if Serious_Errors_Detected
> Sav_Errs
then
898 Set_Error_Posted
(N
);
899 Set_Etype
(N
, Any_Type
);
901 end Analyze_Allocator
;
903 ---------------------------
904 -- Analyze_Arithmetic_Op --
905 ---------------------------
907 procedure Analyze_Arithmetic_Op
(N
: Node_Id
) is
908 L
: constant Node_Id
:= Left_Opnd
(N
);
909 R
: constant Node_Id
:= Right_Opnd
(N
);
914 Set_Etype
(N
, Any_Type
);
915 Candidate_Type
:= Empty
;
917 Analyze_Expression
(L
);
918 Analyze_Expression
(R
);
920 -- If the entity is already set, the node is the instantiation of a
921 -- generic node with a non-local reference, or was manufactured by a
922 -- call to Make_Op_xxx. In either case the entity is known to be valid,
923 -- and we do not need to collect interpretations, instead we just get
924 -- the single possible interpretation.
926 if Present
(Entity
(N
)) then
929 if Ekind
(Op_Id
) = E_Operator
then
930 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
932 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
935 -- Entity is not already set, so we do need to collect interpretations
938 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
939 while Present
(Op_Id
) loop
940 if Ekind
(Op_Id
) = E_Operator
941 and then Present
(Next_Entity
(First_Entity
(Op_Id
)))
943 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
945 -- The following may seem superfluous, because an operator cannot
946 -- be generic, but this ignores the cleverness of the author of
949 elsif Is_Overloadable
(Op_Id
) then
950 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
953 Op_Id
:= Homonym
(Op_Id
);
958 Check_Function_Writable_Actuals
(N
);
959 end Analyze_Arithmetic_Op
;
965 -- Function, procedure, and entry calls are checked here. The Name in
966 -- the call may be overloaded. The actuals have been analyzed and may
967 -- themselves be overloaded. On exit from this procedure, the node N
968 -- may have zero, one or more interpretations. In the first case an
969 -- error message is produced. In the last case, the node is flagged
970 -- as overloaded and the interpretations are collected in All_Interp.
972 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
973 -- the type-checking is similar to that of other calls.
975 procedure Analyze_Call
(N
: Node_Id
) is
976 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
977 Loc
: constant Source_Ptr
:= Sloc
(N
);
981 Nam_Ent
: Entity_Id
:= Empty
;
982 Success
: Boolean := False;
984 Deref
: Boolean := False;
985 -- Flag indicates whether an interpretation of the prefix is a
986 -- parameterless call that returns an access_to_subprogram.
988 procedure Check_Writable_Actuals
(N
: Node_Id
);
989 -- If the call has out or in-out parameters then mark its outermost
990 -- enclosing construct as a node on which the writable actuals check
991 -- must be performed.
993 function Name_Denotes_Function
return Boolean;
994 -- If the type of the name is an access to subprogram, this may be the
995 -- type of a name, or the return type of the function being called. If
996 -- the name is not an entity then it can denote a protected function.
997 -- Until we distinguish Etype from Return_Type, we must use this routine
998 -- to resolve the meaning of the name in the call.
1000 procedure No_Interpretation
;
1001 -- Output error message when no valid interpretation exists
1003 ----------------------------
1004 -- Check_Writable_Actuals --
1005 ----------------------------
1007 -- The identification of conflicts in calls to functions with writable
1008 -- actuals is performed in the analysis phase of the front end to ensure
1009 -- that it reports exactly the same errors compiling with and without
1010 -- expansion enabled. It is performed in two stages:
1012 -- 1) When a call to a function with out-mode parameters is found,
1013 -- we climb to the outermost enclosing construct that can be
1014 -- evaluated in arbitrary order and we mark it with the flag
1017 -- 2) When the analysis of the marked node is complete, we traverse
1018 -- its decorated subtree searching for conflicts (see function
1019 -- Sem_Util.Check_Function_Writable_Actuals).
1021 -- The unique exception to this general rule is for aggregates, since
1022 -- their analysis is performed by the front end in the resolution
1023 -- phase. For aggregates we do not climb to their enclosing construct:
1024 -- we restrict the analysis to the subexpressions initializing the
1025 -- aggregate components.
1027 -- This implies that the analysis of expressions containing aggregates
1028 -- is not complete, since there may be conflicts on writable actuals
1029 -- involving subexpressions of the enclosing logical or arithmetic
1030 -- expressions. However, we cannot wait and perform the analysis when
1031 -- the whole subtree is resolved, since the subtrees may be transformed,
1032 -- thus adding extra complexity and computation cost to identify and
1033 -- report exactly the same errors compiling with and without expansion
1036 procedure Check_Writable_Actuals
(N
: Node_Id
) is
1038 if Comes_From_Source
(N
)
1039 and then Present
(Get_Subprogram_Entity
(N
))
1040 and then Has_Out_Or_In_Out_Parameter
(Get_Subprogram_Entity
(N
))
1042 -- For procedures and entries there is no need to climb since
1043 -- we only need to check if the actuals of this call invoke
1044 -- functions whose out-mode parameters overlap.
1046 if Nkind
(N
) /= N_Function_Call
then
1047 Set_Check_Actuals
(N
);
1049 -- For calls to functions we climb to the outermost enclosing
1050 -- construct where the out-mode actuals of this function may
1051 -- introduce conflicts.
1055 Outermost
: Node_Id
:= Empty
; -- init to avoid warning
1059 while Present
(P
) loop
1060 -- For object declarations we can climb to the node from
1061 -- its object definition branch or from its initializing
1062 -- expression. We prefer to mark the child node as the
1063 -- outermost construct to avoid adding further complexity
1064 -- to the routine that will later take care of
1065 -- performing the writable actuals check.
1067 if Has_Arbitrary_Evaluation_Order
(Nkind
(P
))
1068 and then Nkind
(P
) not in
1069 N_Assignment_Statement | N_Object_Declaration
1074 -- Avoid climbing more than needed
1076 exit when Stop_Subtree_Climbing
(Nkind
(P
))
1077 or else (Nkind
(P
) = N_Range
1079 Nkind
(Parent
(P
)) not in N_In | N_Not_In
);
1084 Set_Check_Actuals
(Outermost
);
1088 end Check_Writable_Actuals
;
1090 ---------------------------
1091 -- Name_Denotes_Function --
1092 ---------------------------
1094 function Name_Denotes_Function
return Boolean is
1096 if Is_Entity_Name
(Nam
) then
1097 return Ekind
(Entity
(Nam
)) = E_Function
;
1098 elsif Nkind
(Nam
) = N_Selected_Component
then
1099 return Ekind
(Entity
(Selector_Name
(Nam
))) = E_Function
;
1103 end Name_Denotes_Function
;
1105 -----------------------
1106 -- No_Interpretation --
1107 -----------------------
1109 procedure No_Interpretation
is
1110 L
: constant Boolean := Is_List_Member
(N
);
1111 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
1114 -- If the node is in a list whose parent is not an expression then it
1115 -- must be an attempted procedure call.
1117 if L
and then K
not in N_Subexpr
then
1118 if Ekind
(Entity
(Nam
)) = E_Generic_Procedure
then
1120 ("must instantiate generic procedure& before call",
1123 Error_Msg_N
("procedure or entry name expected", Nam
);
1126 -- Check for tasking cases where only an entry call will do
1129 and then K
in N_Entry_Call_Alternative | N_Triggering_Alternative
1131 Error_Msg_N
("entry name expected", Nam
);
1133 -- Otherwise give general error message
1136 Error_Msg_N
("invalid prefix in call", Nam
);
1138 end No_Interpretation
;
1140 -- Start of processing for Analyze_Call
1143 -- Initialize the type of the result of the call to the error type,
1144 -- which will be reset if the type is successfully resolved.
1146 Set_Etype
(N
, Any_Type
);
1150 if not Is_Overloaded
(Nam
) then
1152 -- Only one interpretation to check
1154 if Ekind
(Etype
(Nam
)) = E_Subprogram_Type
then
1155 Nam_Ent
:= Etype
(Nam
);
1157 -- If the prefix is an access_to_subprogram, this may be an indirect
1158 -- call. This is the case if the name in the call is not an entity
1159 -- name, or if it is a function name in the context of a procedure
1160 -- call. In this latter case, we have a call to a parameterless
1161 -- function that returns a pointer_to_procedure which is the entity
1162 -- being called. Finally, F (X) may be a call to a parameterless
1163 -- function that returns a pointer to a function with parameters.
1164 -- Note that if F returns an access-to-subprogram whose designated
1165 -- type is an array, F (X) cannot be interpreted as an indirect call
1166 -- through the result of the call to F.
1168 elsif Is_Access_Subprogram_Type
(Base_Type
(Etype
(Nam
)))
1170 (not Name_Denotes_Function
1171 or else Nkind
(N
) = N_Procedure_Call_Statement
1173 (Nkind
(Parent
(N
)) /= N_Explicit_Dereference
1174 and then Is_Entity_Name
(Nam
)
1175 and then No
(First_Formal
(Entity
(Nam
)))
1177 Is_Array_Type
(Etype
(Designated_Type
(Etype
(Nam
))))
1178 and then Present
(Actuals
)))
1180 Nam_Ent
:= Designated_Type
(Etype
(Nam
));
1181 Insert_Explicit_Dereference
(Nam
);
1183 -- Selected component case. Simple entry or protected operation,
1184 -- where the entry name is given by the selector name.
1186 elsif Nkind
(Nam
) = N_Selected_Component
then
1187 Nam_Ent
:= Entity
(Selector_Name
(Nam
));
1189 if Ekind
(Nam_Ent
) not in E_Entry
1194 Error_Msg_N
("name in call is not a callable entity", Nam
);
1195 Set_Etype
(N
, Any_Type
);
1199 -- If the name is an Indexed component, it can be a call to a member
1200 -- of an entry family. The prefix must be a selected component whose
1201 -- selector is the entry. Analyze_Procedure_Call normalizes several
1202 -- kinds of call into this form.
1204 elsif Nkind
(Nam
) = N_Indexed_Component
then
1205 if Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
1206 Nam_Ent
:= Entity
(Selector_Name
(Prefix
(Nam
)));
1208 Error_Msg_N
("name in call is not a callable entity", Nam
);
1209 Set_Etype
(N
, Any_Type
);
1213 elsif not Is_Entity_Name
(Nam
) then
1214 Error_Msg_N
("name in call is not a callable entity", Nam
);
1215 Set_Etype
(N
, Any_Type
);
1219 Nam_Ent
:= Entity
(Nam
);
1221 -- If not overloadable, this may be a generalized indexing
1222 -- operation with named associations. Rewrite again as an
1223 -- indexed component and analyze as container indexing.
1225 if not Is_Overloadable
(Nam_Ent
) then
1227 (Find_Value_Of_Aspect
1228 (Etype
(Nam_Ent
), Aspect_Constant_Indexing
))
1231 Make_Indexed_Component
(Sloc
(N
),
1233 Expressions
=> Parameter_Associations
(N
)));
1235 if Try_Container_Indexing
(N
, Nam
, Expressions
(N
)) then
1249 -- Operations generated for RACW stub types are called only through
1250 -- dispatching, and can never be the static interpretation of a call.
1252 if Is_RACW_Stub_Type_Operation
(Nam_Ent
) then
1257 Analyze_One_Call
(N
, Nam_Ent
, True, Success
);
1259 -- If the nonoverloaded interpretation is a call to an abstract
1260 -- nondispatching operation, then flag an error and return.
1262 if Is_Overloadable
(Nam_Ent
)
1263 and then Is_Abstract_Subprogram
(Nam_Ent
)
1264 and then not Is_Dispatching_Operation
(Nam_Ent
)
1266 Nondispatching_Call_To_Abstract_Operation
(N
, Nam_Ent
);
1270 -- If this is an indirect call, the return type of the access_to
1271 -- subprogram may be an incomplete type. At the point of the call,
1272 -- use the full type if available, and at the same time update the
1273 -- return type of the access_to_subprogram.
1276 and then Nkind
(Nam
) = N_Explicit_Dereference
1277 and then Ekind
(Etype
(N
)) = E_Incomplete_Type
1278 and then Present
(Full_View
(Etype
(N
)))
1280 Set_Etype
(N
, Full_View
(Etype
(N
)));
1281 Set_Etype
(Nam_Ent
, Etype
(N
));
1287 -- An overloaded selected component must denote overloaded operations
1288 -- of a concurrent type. The interpretations are attached to the
1289 -- simple name of those operations.
1291 if Nkind
(Nam
) = N_Selected_Component
then
1292 Nam
:= Selector_Name
(Nam
);
1295 Get_First_Interp
(Nam
, X
, It
);
1296 while Present
(It
.Nam
) loop
1300 -- Name may be call that returns an access to subprogram, or more
1301 -- generally an overloaded expression one of whose interpretations
1302 -- yields an access to subprogram. If the name is an entity, we do
1303 -- not dereference, because the node is a call that returns the
1304 -- access type: note difference between f(x), where the call may
1305 -- return an access subprogram type, and f(x)(y), where the type
1306 -- returned by the call to f is implicitly dereferenced to analyze
1309 if Is_Access_Type
(Nam_Ent
) then
1310 Nam_Ent
:= Designated_Type
(Nam_Ent
);
1312 elsif Is_Access_Type
(Etype
(Nam_Ent
))
1314 (not Is_Entity_Name
(Nam
)
1315 or else Nkind
(N
) = N_Procedure_Call_Statement
)
1316 and then Ekind
(Designated_Type
(Etype
(Nam_Ent
)))
1319 Nam_Ent
:= Designated_Type
(Etype
(Nam_Ent
));
1321 if Is_Entity_Name
(Nam
) then
1326 -- If the call has been rewritten from a prefixed call, the first
1327 -- parameter has been analyzed, but may need a subsequent
1328 -- dereference, so skip its analysis now.
1330 if Is_Rewrite_Substitution
(N
)
1331 and then Nkind
(Original_Node
(N
)) = Nkind
(N
)
1332 and then Nkind
(Name
(N
)) /= Nkind
(Name
(Original_Node
(N
)))
1333 and then Present
(Parameter_Associations
(N
))
1334 and then Present
(Etype
(First
(Parameter_Associations
(N
))))
1337 (N
, Nam_Ent
, False, Success
, Skip_First
=> True);
1339 Analyze_One_Call
(N
, Nam_Ent
, False, Success
);
1342 -- If the interpretation succeeds, mark the proper type of the
1343 -- prefix (any valid candidate will do). If not, remove the
1344 -- candidate interpretation. If this is a parameterless call
1345 -- on an anonymous access to subprogram, X is a variable with
1346 -- an access discriminant D, the entity in the interpretation is
1347 -- D, so rewrite X as X.D.all.
1351 and then Nkind
(Parent
(N
)) /= N_Explicit_Dereference
1353 if Ekind
(It
.Nam
) = E_Discriminant
1354 and then Has_Implicit_Dereference
(It
.Nam
)
1357 Make_Explicit_Dereference
(Loc
,
1359 Make_Selected_Component
(Loc
,
1361 New_Occurrence_Of
(Entity
(Nam
), Loc
),
1363 New_Occurrence_Of
(It
.Nam
, Loc
))));
1369 Set_Entity
(Nam
, It
.Nam
);
1370 Insert_Explicit_Dereference
(Nam
);
1371 Set_Etype
(Nam
, Nam_Ent
);
1375 Set_Etype
(Nam
, It
.Typ
);
1378 elsif Nkind
(Name
(N
)) in N_Function_Call | N_Selected_Component
1383 Get_Next_Interp
(X
, It
);
1386 -- If the name is the result of a function call, it can only be a
1387 -- call to a function returning an access to subprogram. Insert
1388 -- explicit dereference.
1390 if Nkind
(Nam
) = N_Function_Call
then
1391 Insert_Explicit_Dereference
(Nam
);
1394 if Etype
(N
) = Any_Type
then
1396 -- None of the interpretations is compatible with the actuals
1398 Diagnose_Call
(N
, Nam
);
1400 -- Special checks for uninstantiated put routines
1402 if Nkind
(N
) = N_Procedure_Call_Statement
1403 and then Is_Entity_Name
(Nam
)
1404 and then Chars
(Nam
) = Name_Put
1405 and then List_Length
(Actuals
) = 1
1408 Arg
: constant Node_Id
:= First
(Actuals
);
1412 if Nkind
(Arg
) = N_Parameter_Association
then
1413 Typ
:= Etype
(Explicit_Actual_Parameter
(Arg
));
1418 if Is_Signed_Integer_Type
(Typ
) then
1420 ("possible missing instantiation of "
1421 & "'Text_'I'O.'Integer_'I'O!", Nam
);
1423 elsif Is_Modular_Integer_Type
(Typ
) then
1425 ("possible missing instantiation of "
1426 & "'Text_'I'O.'Modular_'I'O!", Nam
);
1428 elsif Is_Floating_Point_Type
(Typ
) then
1430 ("possible missing instantiation of "
1431 & "'Text_'I'O.'Float_'I'O!", Nam
);
1433 elsif Is_Ordinary_Fixed_Point_Type
(Typ
) then
1435 ("possible missing instantiation of "
1436 & "'Text_'I'O.'Fixed_'I'O!", Nam
);
1438 elsif Is_Decimal_Fixed_Point_Type
(Typ
) then
1440 ("possible missing instantiation of "
1441 & "'Text_'I'O.'Decimal_'I'O!", Nam
);
1443 elsif Is_Enumeration_Type
(Typ
) then
1445 ("possible missing instantiation of "
1446 & "'Text_'I'O.'Enumeration_'I'O!", Nam
);
1451 elsif not Is_Overloaded
(N
)
1452 and then Is_Entity_Name
(Nam
)
1454 -- Resolution yields a single interpretation. Verify that the
1455 -- reference has capitalization consistent with the declaration.
1457 Set_Entity_With_Checks
(Nam
, Entity
(Nam
));
1458 Generate_Reference
(Entity
(Nam
), Nam
);
1460 Set_Etype
(Nam
, Etype
(Entity
(Nam
)));
1462 Remove_Abstract_Operations
(N
);
1466 -- Check the accessibility level for actuals for explicitly aliased
1467 -- formals when a function call appears within a return statement.
1468 -- This is only checked if the enclosing subprogram Comes_From_Source,
1469 -- to avoid issuing errors on calls occurring in wrapper subprograms
1470 -- (for example, where the call is part of an expression of an aspect
1471 -- associated with a wrapper, such as Pre'Class).
1473 if Nkind
(N
) = N_Function_Call
1474 and then Comes_From_Source
(N
)
1475 and then Present
(Nam_Ent
)
1476 and then In_Return_Value
(N
)
1477 and then Comes_From_Source
(Current_Subprogram
)
1483 Act
:= First_Actual
(N
);
1484 Form
:= First_Formal
(Nam_Ent
);
1486 while Present
(Form
) and then Present
(Act
) loop
1487 -- Check whether the formal is aliased and if the accessibility
1488 -- level of the actual is deeper than the accessibility level
1489 -- of the enclosing subprogram to which the current return
1490 -- statement applies.
1492 -- Should we be checking Is_Entity_Name on Act? Won't this miss
1495 if Is_Explicitly_Aliased
(Form
)
1496 and then Is_Entity_Name
(Act
)
1497 and then Static_Accessibility_Level
1498 (Act
, Zero_On_Dynamic_Level
)
1499 > Subprogram_Access_Level
(Current_Subprogram
)
1501 Error_Msg_N
("actual for explicitly aliased formal is too"
1502 & " short lived", Act
);
1511 if Ada_Version
>= Ada_2012
then
1513 -- Check if the call contains a function with writable actuals
1515 Check_Writable_Actuals
(N
);
1517 -- If found and the outermost construct that can be evaluated in
1518 -- an arbitrary order is precisely this call, then check all its
1521 Check_Function_Writable_Actuals
(N
);
1523 -- The return type of the function may be incomplete. This can be
1524 -- the case if the type is a generic formal, or a limited view. It
1525 -- can also happen when the function declaration appears before the
1526 -- full view of the type (which is legal in Ada 2012) and the call
1527 -- appears in a different unit, in which case the incomplete view
1528 -- must be replaced with the full view (or the nonlimited view)
1529 -- to prevent subsequent type errors. Note that the usual install/
1530 -- removal of limited_with clauses is not sufficient to handle this
1531 -- case, because the limited view may have been captured in another
1532 -- compilation unit that defines the current function.
1534 if Is_Incomplete_Type
(Etype
(N
)) then
1535 if Present
(Full_View
(Etype
(N
))) then
1536 if Is_Entity_Name
(Nam
) then
1537 Set_Etype
(Nam
, Full_View
(Etype
(N
)));
1538 Set_Etype
(Entity
(Nam
), Full_View
(Etype
(N
)));
1541 Set_Etype
(N
, Full_View
(Etype
(N
)));
1543 -- If the call is within a thunk, the nonlimited view should be
1544 -- analyzed eventually (see also Analyze_Return_Type).
1546 elsif From_Limited_With
(Etype
(N
))
1547 and then Present
(Non_Limited_View
(Etype
(N
)))
1549 (Ekind
(Non_Limited_View
(Etype
(N
))) /= E_Incomplete_Type
1550 or else Is_Thunk
(Current_Scope
))
1552 Set_Etype
(N
, Non_Limited_View
(Etype
(N
)));
1554 -- If there is no completion for the type, this may be because
1555 -- there is only a limited view of it and there is nothing in
1556 -- the context of the current unit that has required a regular
1557 -- compilation of the unit containing the type. We recognize
1558 -- this unusual case by the fact that unit is not analyzed.
1559 -- Note that the call being analyzed is in a different unit from
1560 -- the function declaration, and nothing indicates that the type
1561 -- is a limited view.
1563 elsif Ekind
(Scope
(Etype
(N
))) = E_Package
1564 and then Present
(Limited_View
(Scope
(Etype
(N
))))
1565 and then not Analyzed
(Unit_Declaration_Node
(Scope
(Etype
(N
))))
1568 ("cannot call function that returns limited view of}",
1572 ("\there must be a regular with_clause for package & in the "
1573 & "current unit, or in some unit in its context",
1574 N
, Scope
(Etype
(N
)));
1576 Set_Etype
(N
, Any_Type
);
1582 -----------------------------
1583 -- Analyze_Case_Expression --
1584 -----------------------------
1586 procedure Analyze_Case_Expression
(N
: Node_Id
) is
1587 Expr
: constant Node_Id
:= Expression
(N
);
1588 First_Alt
: constant Node_Id
:= First
(Alternatives
(N
));
1590 First_Expr
: Node_Id
:= Empty
;
1591 -- First expression in the case where there is some type information
1592 -- available, i.e. there is not Any_Type everywhere, which can happen
1593 -- because of some error.
1595 Second_Expr
: Node_Id
:= Empty
;
1596 -- Second expression as above
1598 Wrong_Alt
: Node_Id
:= Empty
;
1599 -- For error reporting
1601 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
1602 -- Error routine invoked by the generic instantiation below when
1603 -- the case expression has a non static choice.
1605 procedure Check_Next_Expression
(T
: Entity_Id
; Alt
: Node_Id
);
1606 -- Check one interpretation of the next expression with type T
1608 procedure Check_Expression_Pair
(T1
, T2
: Entity_Id
; Alt
: Node_Id
);
1609 -- Check first expression with type T1 and next expression with type T2
1611 package Case_Choices_Analysis
is new
1612 Generic_Analyze_Choices
1613 (Process_Associated_Node
=> No_OP
);
1614 use Case_Choices_Analysis
;
1616 package Case_Choices_Checking
is new
1617 Generic_Check_Choices
1618 (Process_Empty_Choice
=> No_OP
,
1619 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
1620 Process_Associated_Node
=> No_OP
);
1621 use Case_Choices_Checking
;
1623 -----------------------------
1624 -- Non_Static_Choice_Error --
1625 -----------------------------
1627 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
1629 Flag_Non_Static_Expr
1630 ("choice given in case expression is not static!", Choice
);
1631 end Non_Static_Choice_Error
;
1633 ---------------------------
1634 -- Check_Next_Expression --
1635 ---------------------------
1637 procedure Check_Next_Expression
(T
: Entity_Id
; Alt
: Node_Id
) is
1638 Next_Expr
: constant Node_Id
:= Expression
(Alt
);
1644 if Next_Expr
= First_Expr
then
1645 Check_Next_Expression
(T
, Next
(Alt
));
1649 -- Loop through the interpretations of the next expression
1651 if not Is_Overloaded
(Next_Expr
) then
1652 Check_Expression_Pair
(T
, Etype
(Next_Expr
), Alt
);
1655 Get_First_Interp
(Next_Expr
, I
, It
);
1656 while Present
(It
.Typ
) loop
1657 Check_Expression_Pair
(T
, It
.Typ
, Alt
);
1658 Get_Next_Interp
(I
, It
);
1661 end Check_Next_Expression
;
1663 ---------------------------
1664 -- Check_Expression_Pair --
1665 ---------------------------
1667 procedure Check_Expression_Pair
(T1
, T2
: Entity_Id
; Alt
: Node_Id
) is
1668 Next_Expr
: constant Node_Id
:= Expression
(Alt
);
1673 if Covers
(T1
=> T1
, T2
=> T2
)
1674 or else Covers
(T1
=> T2
, T2
=> T1
)
1676 T
:= Specific_Type
(T1
, T2
);
1678 elsif Is_User_Defined_Literal
(First_Expr
, T2
) then
1681 elsif Is_User_Defined_Literal
(Next_Expr
, T1
) then
1685 T
:= Possible_Type_For_Conditional_Expression
(T1
, T2
);
1693 if Present
(Next
(Alt
)) then
1694 Check_Next_Expression
(T
, Next
(Alt
));
1696 Add_One_Interp
(N
, T
, T
);
1698 end Check_Expression_Pair
;
1703 Exp_Type
: Entity_Id
;
1704 Exp_Btype
: Entity_Id
;
1707 Others_Present
: Boolean;
1709 -- Start of processing for Analyze_Case_Expression
1712 Analyze_And_Resolve
(Expr
, Any_Discrete
);
1713 Check_Unset_Reference
(Expr
);
1714 Exp_Type
:= Etype
(Expr
);
1715 Exp_Btype
:= Base_Type
(Exp_Type
);
1717 Set_Etype
(N
, Any_Type
);
1720 while Present
(Alt
) loop
1721 if Error_Posted
(Expression
(Alt
)) then
1725 Analyze_Expression
(Expression
(Alt
));
1727 if Etype
(Expression
(Alt
)) /= Any_Type
then
1728 if No
(First_Expr
) then
1729 First_Expr
:= Expression
(Alt
);
1731 elsif No
(Second_Expr
) then
1732 Second_Expr
:= Expression
(Alt
);
1739 -- Get our initial type from the first expression for which we got some
1740 -- useful type information from the expression.
1742 if No
(First_Expr
) then
1746 -- The expression must be of a discrete type which must be determinable
1747 -- independently of the context in which the expression occurs, but
1748 -- using the fact that the expression must be of a discrete type.
1749 -- Moreover, the type this expression must not be a character literal
1750 -- (which is always ambiguous).
1752 -- If error already reported by Resolve, nothing more to do
1754 if Exp_Btype
= Any_Discrete
or else Exp_Btype
= Any_Type
then
1757 -- Special case message for character literal
1759 elsif Exp_Btype
= Any_Character
then
1761 ("character literal as case expression is ambiguous", Expr
);
1765 -- If the case expression is a formal object of mode in out, then
1766 -- treat it as having a nonstatic subtype by forcing use of the base
1767 -- type (which has to get passed to Check_Case_Choices below). Also
1768 -- use base type when the case expression is parenthesized.
1770 if Paren_Count
(Expr
) > 0
1771 or else (Is_Entity_Name
(Expr
)
1772 and then Ekind
(Entity
(Expr
)) = E_Generic_In_Out_Parameter
)
1774 Exp_Type
:= Exp_Btype
;
1777 -- The case expression alternatives cover the range of a static subtype
1778 -- subject to aspect Static_Predicate. Do not check the choices when the
1779 -- case expression has not been fully analyzed yet because this may lead
1782 if Is_OK_Static_Subtype
(Exp_Type
)
1783 and then Has_Static_Predicate_Aspect
(Exp_Type
)
1784 and then In_Spec_Expression
1788 -- Call Analyze_Choices and Check_Choices to do the rest of the work
1791 Analyze_Choices
(Alternatives
(N
), Exp_Type
);
1792 Check_Choices
(N
, Alternatives
(N
), Exp_Type
, Others_Present
);
1794 if Exp_Type
= Universal_Integer
and then not Others_Present
then
1796 ("case on universal integer requires OTHERS choice", Expr
);
1801 -- RM 4.5.7(10/3): If the case_expression is the operand of a type
1802 -- conversion, the type of the case_expression is the target type
1803 -- of the conversion.
1805 if Nkind
(Parent
(N
)) = N_Type_Conversion
then
1806 Set_Etype
(N
, Etype
(Parent
(N
)));
1810 -- Loop through the interpretations of the first expression and check
1811 -- the other expressions if present.
1813 if not Is_Overloaded
(First_Expr
) then
1814 if Present
(Second_Expr
) then
1815 Check_Next_Expression
(Etype
(First_Expr
), First_Alt
);
1817 Set_Etype
(N
, Etype
(First_Expr
));
1821 Get_First_Interp
(First_Expr
, I
, It
);
1822 while Present
(It
.Typ
) loop
1823 if Present
(Second_Expr
) then
1824 Check_Next_Expression
(It
.Typ
, First_Alt
);
1826 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
1829 Get_Next_Interp
(I
, It
);
1833 -- If no possible interpretation has been found, the type of the wrong
1834 -- alternative doesn't match any interpretation of the FIRST expression.
1836 if Etype
(N
) = Any_Type
and then Present
(Wrong_Alt
) then
1837 Second_Expr
:= Expression
(Wrong_Alt
);
1839 if Is_Overloaded
(First_Expr
) then
1840 if Is_Overloaded
(Second_Expr
) then
1842 ("no interpretation compatible with those of previous "
1847 ("type incompatible with interpretations of previous "
1851 ("\this alternative has}!",
1853 Etype
(Second_Expr
));
1857 if Is_Overloaded
(Second_Expr
) then
1859 ("no interpretation compatible with type of previous "
1863 ("\previous alternative has}!",
1865 Etype
(First_Expr
));
1868 ("type incompatible with that of previous alternative",
1871 ("\previous alternative has}!",
1873 Etype
(First_Expr
));
1875 ("\this alternative has}!",
1877 Etype
(Second_Expr
));
1881 end Analyze_Case_Expression
;
1883 ---------------------------
1884 -- Analyze_Concatenation --
1885 ---------------------------
1887 procedure Analyze_Concatenation
(N
: Node_Id
) is
1889 -- We wish to avoid deep recursion, because concatenations are often
1890 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1891 -- operands nonrecursively until we find something that is not a
1892 -- concatenation (A in this case), or has already been analyzed. We
1893 -- analyze that, and then walk back up the tree following Parent
1894 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1895 -- work at each level. The Parent pointers allow us to avoid recursion,
1896 -- and thus avoid running out of memory.
1902 Candidate_Type
:= Empty
;
1904 -- The following code is equivalent to:
1906 -- Set_Etype (N, Any_Type);
1907 -- Analyze_Expression (Left_Opnd (N));
1908 -- Analyze_Concatenation_Rest (N);
1910 -- where the Analyze_Expression call recurses back here if the left
1911 -- operand is a concatenation.
1913 -- Walk down left operands
1916 Set_Etype
(NN
, Any_Type
);
1917 L
:= Left_Opnd
(NN
);
1918 exit when Nkind
(L
) /= N_Op_Concat
or else Analyzed
(L
);
1922 -- Now (given the above example) NN is A&B and L is A
1924 -- First analyze L ...
1926 Analyze_Expression
(L
);
1928 -- ... then walk NN back up until we reach N (where we started), calling
1929 -- Analyze_Concatenation_Rest along the way.
1932 Analyze_Concatenation_Rest
(NN
);
1936 end Analyze_Concatenation
;
1938 --------------------------------
1939 -- Analyze_Concatenation_Rest --
1940 --------------------------------
1942 -- If the only one-dimensional array type in scope is String,
1943 -- this is the resulting type of the operation. Otherwise there
1944 -- will be a concatenation operation defined for each user-defined
1945 -- one-dimensional array.
1947 procedure Analyze_Concatenation_Rest
(N
: Node_Id
) is
1948 L
: constant Node_Id
:= Left_Opnd
(N
);
1949 R
: constant Node_Id
:= Right_Opnd
(N
);
1950 Op_Id
: Entity_Id
:= Entity
(N
);
1955 Analyze_Expression
(R
);
1957 -- If the entity is present, the node appears in an instance, and
1958 -- denotes a predefined concatenation operation. The resulting type is
1959 -- obtained from the arguments when possible. If the arguments are
1960 -- aggregates, the array type and the concatenation type must be
1963 if Present
(Op_Id
) then
1964 if Ekind
(Op_Id
) = E_Operator
then
1965 LT
:= Base_Type
(Etype
(L
));
1966 RT
:= Base_Type
(Etype
(R
));
1968 if Is_Array_Type
(LT
)
1969 and then (RT
= LT
or else RT
= Base_Type
(Component_Type
(LT
)))
1971 Add_One_Interp
(N
, Op_Id
, LT
);
1973 elsif Is_Array_Type
(RT
)
1974 and then LT
= Base_Type
(Component_Type
(RT
))
1976 Add_One_Interp
(N
, Op_Id
, RT
);
1978 -- If one operand is a string type or a user-defined array type,
1979 -- and the other is a literal, result is of the specific type.
1982 (Root_Type
(LT
) = Standard_String
1983 or else Scope
(LT
) /= Standard_Standard
)
1984 and then Etype
(R
) = Any_String
1986 Add_One_Interp
(N
, Op_Id
, LT
);
1989 (Root_Type
(RT
) = Standard_String
1990 or else Scope
(RT
) /= Standard_Standard
)
1991 and then Etype
(L
) = Any_String
1993 Add_One_Interp
(N
, Op_Id
, RT
);
1995 elsif not Is_Generic_Type
(Etype
(Op_Id
)) then
1996 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1999 -- Type and its operations must be visible
2001 Set_Entity
(N
, Empty
);
2002 Analyze_Concatenation
(N
);
2006 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2010 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Concat
);
2011 while Present
(Op_Id
) loop
2012 if Ekind
(Op_Id
) = E_Operator
then
2014 -- Do not consider operators declared in dead code, they
2015 -- cannot be part of the resolution.
2017 if Is_Eliminated
(Op_Id
) then
2020 Find_Concatenation_Types
(L
, R
, Op_Id
, N
);
2024 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
2027 Op_Id
:= Homonym
(Op_Id
);
2032 end Analyze_Concatenation_Rest
;
2034 ------------------------------------
2035 -- Analyze_Comparison_Equality_Op --
2036 ------------------------------------
2038 procedure Analyze_Comparison_Equality_Op
(N
: Node_Id
) is
2039 Loc
: constant Source_Ptr
:= Sloc
(N
);
2040 L
: constant Node_Id
:= Left_Opnd
(N
);
2041 R
: constant Node_Id
:= Right_Opnd
(N
);
2046 Set_Etype
(N
, Any_Type
);
2047 Candidate_Type
:= Empty
;
2049 Analyze_Expression
(L
);
2050 Analyze_Expression
(R
);
2052 -- If the entity is set, the node is a generic instance with a non-local
2053 -- reference to the predefined operator or to a user-defined function.
2054 -- It can also be an inequality that is expanded into the negation of a
2055 -- call to a user-defined equality operator.
2057 -- For the predefined case, the result is Boolean, regardless of the
2058 -- type of the operands. The operands may even be limited, if they are
2059 -- generic actuals. If they are overloaded, label the operands with the
2060 -- compare type if it is present, typically because it is a global type
2061 -- in a generic instance, or with the common type that must be present,
2062 -- or with the type of the formal of the user-defined function.
2064 if Present
(Entity
(N
)) then
2065 Op_Id
:= Entity
(N
);
2067 if Ekind
(Op_Id
) = E_Operator
then
2068 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
);
2070 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2073 if Is_Overloaded
(L
) then
2074 if Ekind
(Op_Id
) = E_Operator
then
2076 (if Present
(Compare_Type
(N
))
2077 then Compare_Type
(N
)
2078 else Intersect_Types
(L
, R
)));
2080 Set_Etype
(L
, Etype
(First_Formal
(Op_Id
)));
2084 if Is_Overloaded
(R
) then
2085 if Ekind
(Op_Id
) = E_Operator
then
2087 (if Present
(Compare_Type
(N
))
2088 then Compare_Type
(N
)
2089 else Intersect_Types
(L
, R
)));
2091 Set_Etype
(R
, Etype
(Next_Formal
(First_Formal
(Op_Id
))));
2096 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
2098 while Present
(Op_Id
) loop
2099 if Ekind
(Op_Id
) = E_Operator
then
2100 Find_Comparison_Equality_Types
(L
, R
, Op_Id
, N
);
2102 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
2105 Op_Id
:= Homonym
(Op_Id
);
2109 -- If there was no match and the operator is inequality, this may be
2110 -- a case where inequality has not been made explicit, as for tagged
2111 -- types. Analyze the node as the negation of an equality operation.
2112 -- This cannot be done earlier because, before analysis, we cannot rule
2113 -- out the presence of an explicit inequality.
2115 if Etype
(N
) = Any_Type
and then Nkind
(N
) = N_Op_Ne
then
2116 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Eq
);
2118 while Present
(Op_Id
) loop
2119 if Ekind
(Op_Id
) = E_Operator
then
2120 Find_Comparison_Equality_Types
(L
, R
, Op_Id
, N
);
2122 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
2125 Op_Id
:= Homonym
(Op_Id
);
2128 if Etype
(N
) /= Any_Type
then
2129 Op_Id
:= Entity
(N
);
2135 Left_Opnd
=> Left_Opnd
(N
),
2136 Right_Opnd
=> Right_Opnd
(N
))));
2138 Set_Entity
(Right_Opnd
(N
), Op_Id
);
2144 Check_Function_Writable_Actuals
(N
);
2145 end Analyze_Comparison_Equality_Op
;
2147 ----------------------------------
2148 -- Analyze_Explicit_Dereference --
2149 ----------------------------------
2151 procedure Analyze_Explicit_Dereference
(N
: Node_Id
) is
2152 Loc
: constant Source_Ptr
:= Sloc
(N
);
2153 P
: constant Node_Id
:= Prefix
(N
);
2159 function Is_Function_Type
return Boolean;
2160 -- Check whether node may be interpreted as an implicit function call
2162 ----------------------
2163 -- Is_Function_Type --
2164 ----------------------
2166 function Is_Function_Type
return Boolean is
2171 if not Is_Overloaded
(N
) then
2172 return Ekind
(Base_Type
(Etype
(N
))) = E_Subprogram_Type
2173 and then Etype
(Base_Type
(Etype
(N
))) /= Standard_Void_Type
;
2176 Get_First_Interp
(N
, I
, It
);
2177 while Present
(It
.Nam
) loop
2178 if Ekind
(Base_Type
(It
.Typ
)) /= E_Subprogram_Type
2179 or else Etype
(Base_Type
(It
.Typ
)) = Standard_Void_Type
2184 Get_Next_Interp
(I
, It
);
2189 end Is_Function_Type
;
2191 -- Start of processing for Analyze_Explicit_Dereference
2194 -- In formal verification mode, keep track of all reads and writes
2195 -- through explicit dereferences.
2197 if GNATprove_Mode
then
2198 SPARK_Specific
.Generate_Dereference
(N
);
2202 Set_Etype
(N
, Any_Type
);
2204 -- Test for remote access to subprogram type, and if so return
2205 -- after rewriting the original tree.
2207 if Remote_AST_E_Dereference
(P
) then
2211 -- Normal processing for other than remote access to subprogram type
2213 if not Is_Overloaded
(P
) then
2214 if Is_Access_Type
(Etype
(P
)) then
2219 DT
: constant Entity_Id
:= Designated_Type
(Etype
(P
));
2222 -- An explicit dereference is a legal occurrence of an
2223 -- incomplete type imported through a limited_with clause, if
2224 -- the full view is visible, or if we are within an instance
2225 -- body, where the enclosing body has a regular with_clause
2228 if From_Limited_With
(DT
)
2229 and then not From_Limited_With
(Scope
(DT
))
2231 (Is_Immediately_Visible
(Scope
(DT
))
2233 (Is_Child_Unit
(Scope
(DT
))
2234 and then Is_Visible_Lib_Unit
(Scope
(DT
)))
2235 or else In_Instance_Body
)
2237 Set_Etype
(N
, Available_View
(DT
));
2244 elsif Etype
(P
) /= Any_Type
then
2245 Error_Msg_N
("prefix of dereference must be an access type", N
);
2250 Get_First_Interp
(P
, I
, It
);
2251 while Present
(It
.Nam
) loop
2254 if Is_Access_Type
(T
) then
2255 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
2258 Get_Next_Interp
(I
, It
);
2261 -- Error if no interpretation of the prefix has an access type
2263 if Etype
(N
) = Any_Type
then
2265 ("access type required in prefix of explicit dereference", P
);
2266 Set_Etype
(N
, Any_Type
);
2272 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
2274 and then (Nkind
(Parent
(N
)) /= N_Function_Call
2275 or else N
/= Name
(Parent
(N
)))
2277 and then (Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
2278 or else N
/= Name
(Parent
(N
)))
2280 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
2281 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
2283 (Attribute_Name
(Parent
(N
)) /= Name_Address
2285 Attribute_Name
(Parent
(N
)) /= Name_Access
))
2287 -- Name is a function call with no actuals, in a context that
2288 -- requires deproceduring (including as an actual in an enclosing
2289 -- function or procedure call). There are some pathological cases
2290 -- where the prefix might include functions that return access to
2291 -- subprograms and others that return a regular type. Disambiguation
2292 -- of those has to take place in Resolve.
2295 Make_Function_Call
(Loc
,
2296 Name
=> Make_Explicit_Dereference
(Loc
, P
),
2297 Parameter_Associations
=> New_List
);
2299 -- If the prefix is overloaded, remove operations that have formals,
2300 -- we know that this is a parameterless call.
2302 if Is_Overloaded
(P
) then
2303 Get_First_Interp
(P
, I
, It
);
2304 while Present
(It
.Nam
) loop
2307 if No
(First_Formal
(Base_Type
(Designated_Type
(T
)))) then
2313 Get_Next_Interp
(I
, It
);
2320 elsif not Is_Function_Type
2321 and then Is_Overloaded
(N
)
2323 -- The prefix may include access to subprograms and other access
2324 -- types. If the context selects the interpretation that is a
2325 -- function call (not a procedure call) we cannot rewrite the node
2326 -- yet, but we include the result of the call interpretation.
2328 Get_First_Interp
(N
, I
, It
);
2329 while Present
(It
.Nam
) loop
2330 if Ekind
(Base_Type
(It
.Typ
)) = E_Subprogram_Type
2331 and then Etype
(Base_Type
(It
.Typ
)) /= Standard_Void_Type
2332 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
2334 Add_One_Interp
(N
, Etype
(It
.Typ
), Etype
(It
.Typ
));
2337 Get_Next_Interp
(I
, It
);
2341 -- A value of remote access-to-class-wide must not be dereferenced
2344 Validate_Remote_Access_To_Class_Wide_Type
(N
);
2345 end Analyze_Explicit_Dereference
;
2347 ------------------------
2348 -- Analyze_Expression --
2349 ------------------------
2351 procedure Analyze_Expression
(N
: Node_Id
) is
2353 -- If the expression is an indexed component that will be rewritten
2354 -- as a container indexing, it has already been analyzed.
2356 if Nkind
(N
) = N_Indexed_Component
2357 and then Present
(Generalized_Indexing
(N
))
2363 Check_Parameterless_Call
(N
);
2365 end Analyze_Expression
;
2367 -------------------------------------
2368 -- Analyze_Expression_With_Actions --
2369 -------------------------------------
2371 procedure Analyze_Expression_With_Actions
(N
: Node_Id
) is
2373 procedure Check_Action_OK
(A
: Node_Id
);
2374 -- Check that the action A is allowed as a declare_item of a declare
2375 -- expression if N and A come from source.
2377 ---------------------
2378 -- Check_Action_OK --
2379 ---------------------
2381 procedure Check_Action_OK
(A
: Node_Id
) is
2383 if not Comes_From_Source
(N
) or else not Comes_From_Source
(A
) then
2385 -- If, for example, an (illegal) expression function is
2386 -- transformed into a "vanilla" function then we don't want to
2387 -- allow it just because Comes_From_Source is now False. So look
2388 -- at the Original_Node.
2390 if Is_Rewrite_Substitution
(A
) then
2391 Check_Action_OK
(Original_Node
(A
));
2394 return; -- Allow anything in generated code
2398 when N_Object_Declaration
=>
2399 if Nkind
(Object_Definition
(A
)) = N_Access_Definition
then
2401 ("anonymous access type not allowed in declare_expression",
2402 Object_Definition
(A
));
2405 if Aliased_Present
(A
) then
2406 Error_Msg_N
("ALIASED not allowed in declare_expression", A
);
2409 if Constant_Present
(A
)
2410 and then not Is_Limited_Type
(Etype
(Defining_Identifier
(A
)))
2412 return; -- nonlimited constants are OK
2415 when N_Object_Renaming_Declaration
=>
2416 if Present
(Access_Definition
(A
)) then
2418 ("anonymous access type not allowed in declare_expression",
2419 Access_Definition
(A
));
2422 if not Is_Limited_Type
(Etype
(Defining_Identifier
(A
))) then
2423 return; -- ???For now; the RM rule is a bit more complicated
2428 -- See AI22-0045 pragma categorization.
2429 subtype Executable_Pragma_Id
is Pragma_Id
2430 with Predicate
=> Executable_Pragma_Id
in
2431 -- language-defined executable pragmas
2432 Pragma_Assert | Pragma_Inspection_Point
2434 -- GNAT-defined executable pragmas
2435 | Pragma_Assume | Pragma_Debug
;
2437 if Get_Pragma_Id
(A
) in Executable_Pragma_Id
then
2443 null; -- Nothing else allowed
2446 -- We could mention pragmas in the message text; let's not.
2447 Error_Msg_N
("object renaming or constant declaration expected", A
);
2448 end Check_Action_OK
;
2451 EWA_Scop
: Entity_Id
;
2453 -- Start of processing for Analyze_Expression_With_Actions
2456 -- Create a scope, which is needed to provide proper visibility of the
2459 EWA_Scop
:= New_Internal_Entity
(E_Block
, Current_Scope
, Sloc
(N
), 'B');
2460 Set_Etype
(EWA_Scop
, Standard_Void_Type
);
2461 Set_Scope
(EWA_Scop
, Current_Scope
);
2462 Set_Parent
(EWA_Scop
, N
);
2463 Push_Scope
(EWA_Scop
);
2465 -- If this Expression_With_Actions node comes from source, then it
2466 -- represents a declare_expression; increment the counter to take note
2469 if Comes_From_Source
(N
) then
2470 In_Declare_Expr
:= In_Declare_Expr
+ 1;
2473 A
:= First
(Actions
(N
));
2474 while Present
(A
) loop
2476 Check_Action_OK
(A
);
2480 Analyze_Expression
(Expression
(N
));
2481 Set_Etype
(N
, Etype
(Expression
(N
)));
2484 if Comes_From_Source
(N
) then
2485 In_Declare_Expr
:= In_Declare_Expr
- 1;
2487 end Analyze_Expression_With_Actions
;
2489 ---------------------------
2490 -- Analyze_If_Expression --
2491 ---------------------------
2493 procedure Analyze_If_Expression
(N
: Node_Id
) is
2494 Condition
: constant Node_Id
:= First
(Expressions
(N
));
2496 Then_Expr
: Node_Id
;
2497 Else_Expr
: Node_Id
;
2499 procedure Check_Else_Expression
(T
: Entity_Id
);
2500 -- Check one interpretation of the THEN expression with type T
2502 procedure Check_Expression_Pair
(T1
, T2
: Entity_Id
);
2503 -- Check THEN expression with type T1 and ELSE expression with type T2
2505 ---------------------------
2506 -- Check_Else_Expression --
2507 ---------------------------
2509 procedure Check_Else_Expression
(T
: Entity_Id
) is
2514 -- Loop through the interpretations of the ELSE expression
2516 if not Is_Overloaded
(Else_Expr
) then
2517 Check_Expression_Pair
(T
, Etype
(Else_Expr
));
2520 Get_First_Interp
(Else_Expr
, I
, It
);
2521 while Present
(It
.Typ
) loop
2522 Check_Expression_Pair
(T
, It
.Typ
);
2523 Get_Next_Interp
(I
, It
);
2526 end Check_Else_Expression
;
2528 ---------------------------
2529 -- Check_Expression_Pair --
2530 ---------------------------
2532 procedure Check_Expression_Pair
(T1
, T2
: Entity_Id
) is
2536 if Covers
(T1
=> T1
, T2
=> T2
)
2537 or else Covers
(T1
=> T2
, T2
=> T1
)
2539 T
:= Specific_Type
(T1
, T2
);
2541 elsif Is_User_Defined_Literal
(Then_Expr
, T2
) then
2544 elsif Is_User_Defined_Literal
(Else_Expr
, T1
) then
2548 T
:= Possible_Type_For_Conditional_Expression
(T1
, T2
);
2555 Add_One_Interp
(N
, T
, T
);
2556 end Check_Expression_Pair
;
2563 -- Start of processing for Analyze_If_Expression
2566 -- Defend against error of missing expressions from previous error
2568 if No
(Condition
) then
2569 Check_Error_Detected
;
2573 Set_Etype
(N
, Any_Type
);
2575 Then_Expr
:= Next
(Condition
);
2577 if No
(Then_Expr
) then
2578 Check_Error_Detected
;
2582 Else_Expr
:= Next
(Then_Expr
);
2584 -- Analyze and resolve the condition. We need to resolve this now so
2585 -- that it gets folded to True/False if possible, before we analyze
2586 -- the THEN/ELSE branches, because when analyzing these branches, we
2587 -- may call Is_Statically_Unevaluated, which expects the condition of
2588 -- an enclosing IF to have been analyze/resolved/evaluated.
2590 Analyze_Expression
(Condition
);
2591 Resolve
(Condition
, Any_Boolean
);
2593 -- Analyze the THEN expression and (if present) the ELSE expression. For
2594 -- them we delay resolution in the normal manner because of overloading.
2596 Analyze_Expression
(Then_Expr
);
2598 if Present
(Else_Expr
) then
2599 Analyze_Expression
(Else_Expr
);
2602 -- RM 4.5.7(10/3): If the if_expression is the operand of a type
2603 -- conversion, the type of the if_expression is the target type
2604 -- of the conversion.
2606 if Nkind
(Parent
(N
)) = N_Type_Conversion
then
2607 Set_Etype
(N
, Etype
(Parent
(N
)));
2611 -- Loop through the interpretations of the THEN expression and check the
2612 -- ELSE expression if present.
2614 if not Is_Overloaded
(Then_Expr
) then
2615 if Present
(Else_Expr
) then
2616 Check_Else_Expression
(Etype
(Then_Expr
));
2618 Set_Etype
(N
, Etype
(Then_Expr
));
2622 Get_First_Interp
(Then_Expr
, I
, It
);
2623 while Present
(It
.Typ
) loop
2624 if Present
(Else_Expr
) then
2625 Check_Else_Expression
(It
.Typ
);
2627 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
2630 Get_Next_Interp
(I
, It
);
2634 -- If no possible interpretation has been found, the type of the
2635 -- ELSE expression does not match any interpretation of the THEN
2638 if Etype
(N
) = Any_Type
then
2639 if Is_Overloaded
(Then_Expr
) then
2640 if Is_Overloaded
(Else_Expr
) then
2642 ("no interpretation compatible with those of THEN expression",
2646 ("type of ELSE incompatible with interpretations of THEN "
2650 ("\ELSE expression has}!", Else_Expr
, Etype
(Else_Expr
));
2654 if Is_Overloaded
(Else_Expr
) then
2656 ("no interpretation compatible with type of THEN expression",
2659 ("\THEN expression has}!", Else_Expr
, Etype
(Then_Expr
));
2662 ("type of ELSE incompatible with that of THEN expression",
2665 ("\THEN expression has}!", Else_Expr
, Etype
(Then_Expr
));
2667 ("\ELSE expression has}!", Else_Expr
, Etype
(Else_Expr
));
2671 end Analyze_If_Expression
;
2673 ------------------------------------
2674 -- Analyze_Indexed_Component_Form --
2675 ------------------------------------
2677 procedure Analyze_Indexed_Component_Form
(N
: Node_Id
) is
2678 P
: constant Node_Id
:= Prefix
(N
);
2679 Exprs
: constant List_Id
:= Expressions
(N
);
2685 procedure Process_Function_Call
;
2686 -- Prefix in indexed component form is an overloadable entity, so the
2687 -- node is very likely a function call; reformat it as such. The only
2688 -- exception is a call to a parameterless function that returns an
2689 -- array type, or an access type thereof, in which case this will be
2690 -- undone later by Resolve_Call or Resolve_Entry_Call.
2692 procedure Process_Indexed_Component
;
2693 -- Prefix in indexed component form is actually an indexed component.
2694 -- This routine processes it, knowing that the prefix is already
2697 procedure Process_Indexed_Component_Or_Slice
;
2698 -- An indexed component with a single index may designate a slice if
2699 -- the index is a subtype mark. This routine disambiguates these two
2700 -- cases by resolving the prefix to see if it is a subtype mark.
2702 procedure Process_Overloaded_Indexed_Component
;
2703 -- If the prefix of an indexed component is overloaded, the proper
2704 -- interpretation is selected by the index types and the context.
2706 ---------------------------
2707 -- Process_Function_Call --
2708 ---------------------------
2710 procedure Process_Function_Call
is
2711 Loc
: constant Source_Ptr
:= Sloc
(N
);
2715 Change_Node
(N
, N_Function_Call
);
2717 Set_Parameter_Associations
(N
, Exprs
);
2719 -- Analyze actuals prior to analyzing the call itself
2721 Actual
:= First
(Parameter_Associations
(N
));
2722 while Present
(Actual
) loop
2724 Check_Parameterless_Call
(Actual
);
2726 -- Move to next actual. Note that we use Next, not Next_Actual
2727 -- here. The reason for this is a bit subtle. If a function call
2728 -- includes named associations, the parser recognizes the node
2729 -- as a call, and it is analyzed as such. If all associations are
2730 -- positional, the parser builds an indexed_component node, and
2731 -- it is only after analysis of the prefix that the construct
2732 -- is recognized as a call, in which case Process_Function_Call
2733 -- rewrites the node and analyzes the actuals. If the list of
2734 -- actuals is malformed, the parser may leave the node as an
2735 -- indexed component (despite the presence of named associations).
2736 -- The iterator Next_Actual is equivalent to Next if the list is
2737 -- positional, but follows the normalized chain of actuals when
2738 -- named associations are present. In this case normalization has
2739 -- not taken place, and actuals remain unanalyzed, which leads to
2740 -- subsequent crashes or loops if there is an attempt to continue
2741 -- analysis of the program.
2743 -- IF there is a single actual and it is a type name, the node
2744 -- can only be interpreted as a slice of a parameterless call.
2745 -- Rebuild the node as such and analyze.
2747 if No
(Next
(Actual
))
2748 and then Is_Entity_Name
(Actual
)
2749 and then Is_Type
(Entity
(Actual
))
2750 and then Is_Discrete_Type
(Entity
(Actual
))
2751 and then not Is_Current_Instance
(Actual
)
2757 New_Occurrence_Of
(Entity
(Actual
), Loc
)));
2767 end Process_Function_Call
;
2769 -------------------------------
2770 -- Process_Indexed_Component --
2771 -------------------------------
2773 procedure Process_Indexed_Component
is
2775 Array_Type
: Entity_Id
;
2777 Pent
: Entity_Id
:= Empty
;
2780 Exp
:= First
(Exprs
);
2782 if Is_Overloaded
(P
) then
2783 Process_Overloaded_Indexed_Component
;
2786 Array_Type
:= Etype
(P
);
2788 if Is_Entity_Name
(P
) then
2790 elsif Nkind
(P
) = N_Selected_Component
2791 and then Is_Entity_Name
(Selector_Name
(P
))
2793 Pent
:= Entity
(Selector_Name
(P
));
2796 -- Prefix must be appropriate for an array type, taking into
2797 -- account a possible implicit dereference.
2799 if Is_Access_Type
(Array_Type
) then
2801 (Warn_On_Dereference
, "?d?implicit dereference", N
);
2802 Array_Type
:= Implicitly_Designated_Type
(Array_Type
);
2805 if Is_Array_Type
(Array_Type
) then
2807 -- In order to correctly access First_Index component later,
2808 -- replace string literal subtype by its parent type.
2810 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
2811 Array_Type
:= Etype
(Array_Type
);
2814 elsif Present
(Pent
) and then Ekind
(Pent
) = E_Entry_Family
then
2816 Set_Etype
(N
, Any_Type
);
2818 if not Has_Compatible_Type
(Exp
, Entry_Index_Type
(Pent
)) then
2819 Error_Msg_N
("invalid index type in entry name", N
);
2821 elsif Present
(Next
(Exp
)) then
2822 Error_Msg_N
("too many subscripts in entry reference", N
);
2825 Set_Etype
(N
, Etype
(P
));
2830 elsif Is_Record_Type
(Array_Type
)
2831 and then Remote_AST_I_Dereference
(P
)
2835 elsif Try_Container_Indexing
(N
, P
, Exprs
) then
2838 elsif Array_Type
= Any_Type
then
2839 Set_Etype
(N
, Any_Type
);
2841 -- In most cases the analysis of the prefix will have emitted
2842 -- an error already, but if the prefix may be interpreted as a
2843 -- call in prefixed notation, the report is left to the caller.
2844 -- To prevent cascaded errors, report only if no previous ones.
2846 if Serious_Errors_Detected
= 0 then
2847 Error_Msg_N
("invalid prefix in indexed component", P
);
2849 if Nkind
(P
) = N_Expanded_Name
then
2850 Error_Msg_NE
("\& is not visible", P
, Selector_Name
(P
));
2856 -- Here we definitely have a bad indexing
2859 if Nkind
(Parent
(N
)) = N_Requeue_Statement
2860 and then Present
(Pent
) and then Ekind
(Pent
) = E_Entry
2863 ("REQUEUE does not permit parameters", First
(Exprs
));
2865 elsif Is_Entity_Name
(P
)
2866 and then Etype
(P
) = Standard_Void_Type
2868 Error_Msg_NE
("incorrect use of &", P
, Entity
(P
));
2871 Error_Msg_N
("array type required in indexed component", P
);
2874 Set_Etype
(N
, Any_Type
);
2878 Index
:= First_Index
(Array_Type
);
2879 while Present
(Index
) and then Present
(Exp
) loop
2880 if not Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2881 Wrong_Type
(Exp
, Etype
(Index
));
2882 Set_Etype
(N
, Any_Type
);
2890 Set_Etype
(N
, Component_Type
(Array_Type
));
2891 Check_Implicit_Dereference
(N
, Etype
(N
));
2893 if Present
(Index
) then
2895 ("too few subscripts in array reference", First
(Exprs
));
2897 elsif Present
(Exp
) then
2898 Error_Msg_N
("too many subscripts in array reference", Exp
);
2901 end Process_Indexed_Component
;
2903 ----------------------------------------
2904 -- Process_Indexed_Component_Or_Slice --
2905 ----------------------------------------
2907 procedure Process_Indexed_Component_Or_Slice
is
2909 Exp
:= First
(Exprs
);
2910 while Present
(Exp
) loop
2911 Analyze_Expression
(Exp
);
2915 Exp
:= First
(Exprs
);
2917 -- If one index is present, and it is a subtype name, then the node
2918 -- denotes a slice (note that the case of an explicit range for a
2919 -- slice was already built as an N_Slice node in the first place,
2920 -- so that case is not handled here).
2922 -- We use a replace rather than a rewrite here because this is one
2923 -- of the cases in which the tree built by the parser is plain wrong.
2926 and then Is_Entity_Name
(Exp
)
2927 and then Is_Type
(Entity
(Exp
))
2930 Make_Slice
(Sloc
(N
),
2932 Discrete_Range
=> New_Copy
(Exp
)));
2935 -- Otherwise (more than one index present, or single index is not
2936 -- a subtype name), then we have the indexed component case.
2939 Process_Indexed_Component
;
2941 end Process_Indexed_Component_Or_Slice
;
2943 ------------------------------------------
2944 -- Process_Overloaded_Indexed_Component --
2945 ------------------------------------------
2947 procedure Process_Overloaded_Indexed_Component
is
2956 Set_Etype
(N
, Any_Type
);
2958 Get_First_Interp
(P
, I
, It
);
2959 while Present
(It
.Nam
) loop
2962 if Is_Access_Type
(Typ
) then
2963 Typ
:= Designated_Type
(Typ
);
2965 (Warn_On_Dereference
, "?d?implicit dereference", N
);
2968 if Is_Array_Type
(Typ
) then
2970 -- Got a candidate: verify that index types are compatible
2972 Index
:= First_Index
(Typ
);
2974 Exp
:= First
(Exprs
);
2975 while Present
(Index
) and then Present
(Exp
) loop
2976 if Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2988 if Found
and then No
(Index
) and then No
(Exp
) then
2990 CT
: constant Entity_Id
:=
2991 Base_Type
(Component_Type
(Typ
));
2993 Add_One_Interp
(N
, CT
, CT
);
2994 Check_Implicit_Dereference
(N
, CT
);
2998 elsif Try_Container_Indexing
(N
, P
, Exprs
) then
3003 Get_Next_Interp
(I
, It
);
3006 if Etype
(N
) = Any_Type
then
3007 Error_Msg_N
("no legal interpretation for indexed component", N
);
3008 Set_Is_Overloaded
(N
, False);
3010 end Process_Overloaded_Indexed_Component
;
3012 -- Start of processing for Analyze_Indexed_Component_Form
3015 -- Get name of array, function or type
3019 -- If P is an explicit dereference whose prefix is of a remote access-
3020 -- to-subprogram type, then N has already been rewritten as a subprogram
3021 -- call and analyzed.
3023 if Nkind
(N
) in N_Subprogram_Call
then
3026 -- When the prefix is attribute 'Loop_Entry and the sole expression of
3027 -- the indexed component denotes a loop name, the indexed form is turned
3028 -- into an attribute reference.
3030 elsif Nkind
(N
) = N_Attribute_Reference
3031 and then Attribute_Name
(N
) = Name_Loop_Entry
3036 pragma Assert
(Nkind
(N
) = N_Indexed_Component
);
3038 P_T
:= Base_Type
(Etype
(P
));
3040 if Is_Entity_Name
(P
) and then Present
(Entity
(P
)) then
3043 if Is_Type
(U_N
) then
3045 -- Reformat node as a type conversion
3047 E
:= Remove_Head
(Exprs
);
3049 if Present
(First
(Exprs
)) then
3051 ("argument of type conversion must be single expression", N
);
3054 Change_Node
(N
, N_Type_Conversion
);
3055 Set_Subtype_Mark
(N
, P
);
3057 Set_Expression
(N
, E
);
3059 -- After changing the node, call for the specific Analysis
3060 -- routine directly, to avoid a double call to the expander.
3062 Analyze_Type_Conversion
(N
);
3066 if Is_Overloadable
(U_N
) then
3067 Process_Function_Call
;
3069 elsif Ekind
(Etype
(P
)) = E_Subprogram_Type
3070 or else (Is_Access_Type
(Etype
(P
))
3072 Ekind
(Designated_Type
(Etype
(P
))) =
3075 -- Call to access_to-subprogram with possible implicit dereference
3077 Process_Function_Call
;
3079 elsif Is_Generic_Subprogram
(U_N
) then
3081 -- A common beginner's (or C++ templates fan) error
3083 Error_Msg_N
("generic subprogram cannot be called", N
);
3084 Set_Etype
(N
, Any_Type
);
3088 Process_Indexed_Component_Or_Slice
;
3091 -- If not an entity name, prefix is an expression that may denote
3092 -- an array or an access-to-subprogram.
3095 if Ekind
(P_T
) = E_Subprogram_Type
3096 or else (Is_Access_Type
(P_T
)
3098 Ekind
(Designated_Type
(P_T
)) = E_Subprogram_Type
)
3100 Process_Function_Call
;
3102 elsif Nkind
(P
) = N_Selected_Component
3103 and then Present
(Entity
(Selector_Name
(P
)))
3104 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
3106 Process_Function_Call
;
3108 -- Indexed component, slice, or a call to a member of a family
3109 -- entry, which will be converted to an entry call later.
3111 Process_Indexed_Component_Or_Slice
;
3115 Analyze_Dimension
(N
);
3116 end Analyze_Indexed_Component_Form
;
3118 ------------------------
3119 -- Analyze_Logical_Op --
3120 ------------------------
3122 procedure Analyze_Logical_Op
(N
: Node_Id
) is
3123 L
: constant Node_Id
:= Left_Opnd
(N
);
3124 R
: constant Node_Id
:= Right_Opnd
(N
);
3129 Set_Etype
(N
, Any_Type
);
3130 Candidate_Type
:= Empty
;
3132 Analyze_Expression
(L
);
3133 Analyze_Expression
(R
);
3135 -- If the entity is already set, the node is the instantiation of a
3136 -- generic node with a non-local reference, or was manufactured by a
3137 -- call to Make_Op_xxx. In either case the entity is known to be valid,
3138 -- and we do not need to collect interpretations, instead we just get
3139 -- the single possible interpretation.
3141 if Present
(Entity
(N
)) then
3142 Op_Id
:= Entity
(N
);
3144 if Ekind
(Op_Id
) = E_Operator
then
3145 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
3147 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3150 -- Entity is not already set, so we do need to collect interpretations
3153 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
3154 while Present
(Op_Id
) loop
3155 if Ekind
(Op_Id
) = E_Operator
then
3156 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
3158 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
3161 Op_Id
:= Homonym
(Op_Id
);
3166 Check_Function_Writable_Actuals
(N
);
3169 if Nkind
(L
) not in N_Short_Circuit | N_Op_And | N_Op_Or | N_Op_Xor
3170 and then Is_Boolean_Type
(Etype
(L
))
3172 Check_Xtra_Parens_Precedence
(L
);
3175 if Nkind
(R
) not in N_Short_Circuit | N_Op_And | N_Op_Or | N_Op_Xor
3176 and then Is_Boolean_Type
(Etype
(R
))
3178 Check_Xtra_Parens_Precedence
(R
);
3181 end Analyze_Logical_Op
;
3183 ---------------------------
3184 -- Analyze_Membership_Op --
3185 ---------------------------
3187 procedure Analyze_Membership_Op
(N
: Node_Id
) is
3188 Loc
: constant Source_Ptr
:= Sloc
(N
);
3189 L
: constant Node_Id
:= Left_Opnd
(N
);
3190 R
: constant Node_Id
:= Right_Opnd
(N
);
3192 procedure Analyze_Set_Membership
;
3193 -- If a set of alternatives is present, analyze each and find the
3194 -- common type to which they must all resolve.
3196 function Find_Interp
return Boolean;
3197 -- Find a valid interpretation of the test. Note that the context of the
3198 -- operation plays no role in resolving the operands, so that if there
3199 -- is more than one interpretation of the operands that is compatible
3200 -- with the test, the operation is ambiguous.
3202 function Try_Left_Interp
(T
: Entity_Id
) return Boolean;
3203 -- Try an interpretation of the left operand with type T. Return true if
3204 -- one interpretation (at least) of the right operand making up a valid
3205 -- operand pair exists, otherwise false if no such pair exists.
3207 function Is_Valid_Pair
(T1
, T2
: Entity_Id
) return Boolean;
3208 -- Return true if T1 and T2 constitute a valid pair of operand types for
3209 -- L and R respectively.
3211 ----------------------------
3212 -- Analyze_Set_Membership --
3213 ----------------------------
3215 procedure Analyze_Set_Membership
is
3217 Index
: Interp_Index
;
3219 Candidate_Interps
: Node_Id
;
3220 Common_Type
: Entity_Id
:= Empty
;
3224 Candidate_Interps
:= L
;
3226 if not Is_Overloaded
(L
) then
3227 Common_Type
:= Etype
(L
);
3229 Alt
:= First
(Alternatives
(N
));
3230 while Present
(Alt
) loop
3233 if not Has_Compatible_Type
(Alt
, Common_Type
) then
3234 Wrong_Type
(Alt
, Common_Type
);
3241 Alt
:= First
(Alternatives
(N
));
3242 while Present
(Alt
) loop
3244 if not Is_Overloaded
(Alt
) then
3245 Common_Type
:= Etype
(Alt
);
3248 Get_First_Interp
(Alt
, Index
, It
);
3249 while Present
(It
.Typ
) loop
3251 Has_Compatible_Type
(Candidate_Interps
, It
.Typ
)
3253 Remove_Interp
(Index
);
3256 Get_Next_Interp
(Index
, It
);
3259 Get_First_Interp
(Alt
, Index
, It
);
3262 Error_Msg_N
("alternative has no legal type", Alt
);
3266 -- If alternative is not overloaded, we have a unique type
3269 Set_Etype
(Alt
, It
.Typ
);
3271 -- If the alternative is an enumeration literal, use the one
3272 -- for this interpretation.
3274 if Is_Entity_Name
(Alt
) then
3275 Set_Entity
(Alt
, It
.Nam
);
3278 Get_Next_Interp
(Index
, It
);
3281 Set_Is_Overloaded
(Alt
, False);
3282 Common_Type
:= Etype
(Alt
);
3285 Candidate_Interps
:= Alt
;
3292 if Present
(Common_Type
) then
3293 Set_Etype
(L
, Common_Type
);
3295 -- The left operand may still be overloaded, to be resolved using
3299 Error_Msg_N
("cannot resolve membership operation", N
);
3301 end Analyze_Set_Membership
;
3307 function Find_Interp
return Boolean is
3312 Valid_I
: Interp_Index
;
3315 -- Loop through the interpretations of the left operand
3317 if not Is_Overloaded
(L
) then
3318 Found
:= Try_Left_Interp
(Etype
(L
));
3325 Get_First_Interp
(L
, I
, It
);
3326 while Present
(It
.Typ
) loop
3327 if Try_Left_Interp
(It
.Typ
) then
3328 -- If several interpretations are possible, disambiguate
3331 and then Base_Type
(It
.Typ
) /= Base_Type
(L_Typ
)
3333 It
:= Disambiguate
(L
, Valid_I
, I
, Any_Type
);
3335 if It
= No_Interp
then
3336 Ambiguous_Operands
(N
);
3337 Set_Etype
(L
, Any_Type
);
3346 Set_Etype
(L
, L_Typ
);
3350 Get_Next_Interp
(I
, It
);
3357 ---------------------
3358 -- Try_Left_Interp --
3359 ---------------------
3361 function Try_Left_Interp
(T
: Entity_Id
) return Boolean is
3366 Valid_I
: Interp_Index
;
3369 -- Defend against previous error
3371 if Nkind
(R
) = N_Error
then
3374 -- Loop through the interpretations of the right operand
3376 elsif not Is_Overloaded
(R
) then
3377 Found
:= Is_Valid_Pair
(T
, Etype
(R
));
3384 Get_First_Interp
(R
, I
, It
);
3385 while Present
(It
.Typ
) loop
3386 if Is_Valid_Pair
(T
, It
.Typ
) then
3387 -- If several interpretations are possible, disambiguate
3390 and then Base_Type
(It
.Typ
) /= Base_Type
(R_Typ
)
3392 It
:= Disambiguate
(R
, Valid_I
, I
, Any_Type
);
3394 if It
= No_Interp
then
3395 Ambiguous_Operands
(N
);
3396 Set_Etype
(R
, Any_Type
);
3408 Get_Next_Interp
(I
, It
);
3413 end Try_Left_Interp
;
3419 function Is_Valid_Pair
(T1
, T2
: Entity_Id
) return Boolean is
3421 return Covers
(T1
=> T1
, T2
=> T2
)
3422 or else Covers
(T1
=> T2
, T2
=> T1
)
3423 or else Is_User_Defined_Literal
(L
, T2
)
3424 or else Is_User_Defined_Literal
(R
, T1
);
3432 -- Start of processing for Analyze_Membership_Op
3435 Analyze_Expression
(L
);
3438 pragma Assert
(Ada_Version
>= Ada_2012
);
3440 Analyze_Set_Membership
;
3445 Alt
:= First
(Alternatives
(N
));
3446 while Present
(Alt
) loop
3447 if Is_Entity_Name
(Alt
) and then Is_Type
(Entity
(Alt
)) then
3448 Check_Fully_Declared
(Entity
(Alt
), Alt
);
3450 if Has_Ghost_Predicate_Aspect
(Entity
(Alt
)) then
3452 ("subtype& has ghost predicate, "
3453 & "not allowed in membership test",
3462 elsif Nkind
(R
) = N_Range
3463 or else (Nkind
(R
) = N_Attribute_Reference
3464 and then Attribute_Name
(R
) = Name_Range
)
3466 Analyze_Expression
(R
);
3468 Dummy
:= Find_Interp
;
3470 -- If not a range, it can be a subtype mark, or else it is a degenerate
3471 -- membership test with a singleton value, i.e. a test for equality,
3472 -- if the types are compatible.
3475 Analyze_Expression
(R
);
3477 if Is_Entity_Name
(R
) and then Is_Type
(Entity
(R
)) then
3479 Check_Fully_Declared
(Entity
(R
), R
);
3481 if Has_Ghost_Predicate_Aspect
(Entity
(R
)) then
3483 ("subtype& has ghost predicate, "
3484 & "not allowed in membership test",
3488 elsif Ada_Version
>= Ada_2012
and then Find_Interp
then
3489 Op
:= Make_Op_Eq
(Loc
, Left_Opnd
=> L
, Right_Opnd
=> R
);
3490 Resolve_Membership_Equality
(Op
, Etype
(L
));
3492 if Nkind
(N
) = N_Not_In
then
3493 Op
:= Make_Op_Not
(Loc
, Op
);
3501 -- In all versions of the language, if we reach this point there
3502 -- is a previous error that will be diagnosed below.
3508 -- Compatibility between expression and subtype mark or range is
3509 -- checked during resolution. The result of the operation is Boolean
3512 Set_Etype
(N
, Standard_Boolean
);
3514 if Comes_From_Source
(N
)
3515 and then Present
(Right_Opnd
(N
))
3516 and then Is_CPP_Class
(Etype
(Etype
(Right_Opnd
(N
))))
3518 Error_Msg_N
("membership test not applicable to cpp-class types", N
);
3521 Check_Function_Writable_Actuals
(N
);
3522 end Analyze_Membership_Op
;
3528 procedure Analyze_Mod
(N
: Node_Id
) is
3530 -- A special warning check, if we have an expression of the form:
3531 -- expr mod 2 * literal
3532 -- where literal is 128 or less, then probably what was meant was
3533 -- expr mod 2 ** literal
3534 -- so issue an appropriate warning.
3536 if Warn_On_Suspicious_Modulus_Value
3537 and then Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
3538 and then Intval
(Right_Opnd
(N
)) = Uint_2
3539 and then Nkind
(Parent
(N
)) = N_Op_Multiply
3540 and then Nkind
(Right_Opnd
(Parent
(N
))) = N_Integer_Literal
3541 and then Intval
(Right_Opnd
(Parent
(N
))) <= Uint_128
3544 ("suspicious MOD value, was '*'* intended'??.m?", Parent
(N
));
3547 -- Remaining processing is same as for other arithmetic operators
3549 Analyze_Arithmetic_Op
(N
);
3552 ----------------------
3553 -- Analyze_Negation --
3554 ----------------------
3556 procedure Analyze_Negation
(N
: Node_Id
) is
3557 R
: constant Node_Id
:= Right_Opnd
(N
);
3562 Set_Etype
(N
, Any_Type
);
3563 Candidate_Type
:= Empty
;
3565 Analyze_Expression
(R
);
3567 -- If the entity is already set, the node is the instantiation of a
3568 -- generic node with a non-local reference, or was manufactured by a
3569 -- call to Make_Op_xxx. In either case the entity is known to be valid,
3570 -- and we do not need to collect interpretations, instead we just get
3571 -- the single possible interpretation.
3573 if Present
(Entity
(N
)) then
3574 Op_Id
:= Entity
(N
);
3576 if Ekind
(Op_Id
) = E_Operator
then
3577 Find_Negation_Types
(R
, Op_Id
, N
);
3579 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3583 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
3584 while Present
(Op_Id
) loop
3585 if Ekind
(Op_Id
) = E_Operator
then
3586 Find_Negation_Types
(R
, Op_Id
, N
);
3588 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
3591 Op_Id
:= Homonym
(Op_Id
);
3596 end Analyze_Negation
;
3602 procedure Analyze_Null
(N
: Node_Id
) is
3604 Set_Etype
(N
, Universal_Access
);
3607 ----------------------
3608 -- Analyze_One_Call --
3609 ----------------------
3611 procedure Analyze_One_Call
3615 Success
: out Boolean;
3616 Skip_First
: Boolean := False)
3618 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
3619 Prev_T
: constant Entity_Id
:= Etype
(N
);
3621 -- Recognize cases of prefixed calls that have been rewritten in
3622 -- various ways. The simplest case is a rewritten selected component,
3623 -- but it can also be an already-examined indexed component, or a
3624 -- prefix that is itself a rewritten prefixed call that is in turn
3625 -- an indexed call (the syntactic ambiguity involving the indexing of
3626 -- a function with defaulted parameters that returns an array).
3627 -- A flag Maybe_Indexed_Call might be useful here ???
3629 Must_Skip
: constant Boolean := Skip_First
3630 or else Nkind
(Original_Node
(N
)) = N_Selected_Component
3632 (Nkind
(Original_Node
(N
)) = N_Indexed_Component
3633 and then Nkind
(Prefix
(Original_Node
(N
))) =
3634 N_Selected_Component
)
3636 (Nkind
(Parent
(N
)) = N_Function_Call
3637 and then Is_Array_Type
(Etype
(Name
(N
)))
3638 and then Etype
(Original_Node
(N
)) =
3639 Component_Type
(Etype
(Name
(N
)))
3640 and then Nkind
(Original_Node
(Parent
(N
))) =
3641 N_Selected_Component
);
3643 -- The first formal must be omitted from the match when trying to find
3644 -- a primitive operation that is a possible interpretation, and also
3645 -- after the call has been rewritten, because the corresponding actual
3646 -- is already known to be compatible, and because this may be an
3647 -- indexing of a call with default parameters.
3649 First_Form
: Entity_Id
;
3652 Is_Indexed
: Boolean := False;
3653 Is_Indirect
: Boolean := False;
3654 Subp_Type
: constant Entity_Id
:= Etype
(Nam
);
3657 function Compatible_Types_In_Predicate
3659 T2
: Entity_Id
) return Boolean;
3660 -- For an Ada 2012 predicate or invariant, a call may mention an
3661 -- incomplete type, while resolution of the corresponding predicate
3662 -- function may see the full view, as a consequence of the delayed
3663 -- resolution of the corresponding expressions. This may occur in
3664 -- the body of a predicate function, or in a call to such. Anomalies
3665 -- involving private and full views can also happen. In each case,
3666 -- rewrite node or add conversions to remove spurious type errors.
3668 procedure Indicate_Name_And_Type
;
3669 -- If candidate interpretation matches, indicate name and type of result
3672 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean;
3673 -- There may be a user-defined operator that hides the current
3674 -- interpretation. We must check for this independently of the
3675 -- analysis of the call with the user-defined operation, because
3676 -- the parameter names may be wrong and yet the hiding takes place.
3677 -- This fixes a problem with ACATS test B34014O.
3679 -- When the type Address is a visible integer type, and the DEC
3680 -- system extension is visible, the predefined operator may be
3681 -- hidden as well, by one of the address operations in auxdec.
3682 -- Finally, the abstract operations on address do not hide the
3683 -- predefined operator (this is the purpose of making them abstract).
3685 -----------------------------------
3686 -- Compatible_Types_In_Predicate --
3687 -----------------------------------
3689 function Compatible_Types_In_Predicate
3691 T2
: Entity_Id
) return Boolean
3693 function Common_Type
(T
: Entity_Id
) return Entity_Id
;
3694 -- Find non-private underlying full view if any, without going to
3695 -- ancestor type (as opposed to Underlying_Type).
3701 function Common_Type
(T
: Entity_Id
) return Entity_Id
is
3707 if Is_Private_Type
(CT
) and then Present
(Full_View
(CT
)) then
3708 CT
:= Full_View
(CT
);
3711 if Is_Private_Type
(CT
)
3712 and then Present
(Underlying_Full_View
(CT
))
3714 CT
:= Underlying_Full_View
(CT
);
3717 return Base_Type
(CT
);
3720 -- Start of processing for Compatible_Types_In_Predicate
3723 if (Ekind
(Current_Scope
) = E_Function
3724 and then Is_Predicate_Function
(Current_Scope
))
3726 (Ekind
(Nam
) = E_Function
3727 and then Is_Predicate_Function
(Nam
))
3729 if Is_Incomplete_Type
(T1
)
3730 and then Present
(Full_View
(T1
))
3731 and then Full_View
(T1
) = T2
3733 Set_Etype
(Formal
, Etype
(Actual
));
3736 elsif Common_Type
(T1
) = Common_Type
(T2
) then
3737 Rewrite
(Actual
, Unchecked_Convert_To
(Etype
(Formal
), Actual
));
3747 end Compatible_Types_In_Predicate
;
3749 ----------------------------
3750 -- Indicate_Name_And_Type --
3751 ----------------------------
3753 procedure Indicate_Name_And_Type
is
3755 Add_One_Interp
(N
, Nam
, Etype
(Nam
));
3756 Check_Implicit_Dereference
(N
, Etype
(Nam
));
3759 -- If the prefix of the call is a name, indicate the entity
3760 -- being called. If it is not a name, it is an expression that
3761 -- denotes an access to subprogram or else an entry or family. In
3762 -- the latter case, the name is a selected component, and the entity
3763 -- being called is noted on the selector.
3765 if not Is_Type
(Nam
) then
3766 if Is_Entity_Name
(Name
(N
)) then
3767 Set_Entity
(Name
(N
), Nam
);
3768 Set_Etype
(Name
(N
), Etype
(Nam
));
3770 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
3771 Set_Entity
(Selector_Name
(Name
(N
)), Nam
);
3775 if Debug_Flag_E
and not Report
then
3776 Write_Str
(" Overloaded call ");
3777 Write_Int
(Int
(N
));
3778 Write_Str
(" compatible with ");
3779 Write_Int
(Int
(Nam
));
3782 end Indicate_Name_And_Type
;
3784 ------------------------
3785 -- Operator_Hidden_By --
3786 ------------------------
3788 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean is
3789 Act1
: constant Node_Id
:= First_Actual
(N
);
3790 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
3791 Form1
: constant Entity_Id
:= First_Formal
(Fun
);
3792 Form2
: constant Entity_Id
:= Next_Formal
(Form1
);
3795 if Ekind
(Fun
) /= E_Function
or else Is_Abstract_Subprogram
(Fun
) then
3798 elsif not Has_Compatible_Type
(Act1
, Etype
(Form1
)) then
3801 elsif Present
(Form2
) then
3803 or else not Has_Compatible_Type
(Act2
, Etype
(Form2
))
3808 elsif Present
(Act2
) then
3812 -- Now we know that the arity of the operator matches the function,
3813 -- and the function call is a valid interpretation. The function
3814 -- hides the operator if it has the right signature, or if one of
3815 -- its operands is a non-abstract operation on Address when this is
3816 -- a visible integer type.
3818 return Hides_Op
(Fun
, Nam
)
3819 or else Is_Descendant_Of_Address
(Etype
(Form1
))
3822 and then Is_Descendant_Of_Address
(Etype
(Form2
)));
3823 end Operator_Hidden_By
;
3825 -- Start of processing for Analyze_One_Call
3830 -- If the subprogram has no formals or if all the formals have defaults,
3831 -- and the return type is an array type, the node may denote an indexing
3832 -- of the result of a parameterless call. In Ada 2005, the subprogram
3833 -- may have one non-defaulted formal, and the call may have been written
3834 -- in prefix notation, so that the rebuilt parameter list has more than
3837 if not Is_Overloadable
(Nam
)
3838 and then Ekind
(Nam
) /= E_Subprogram_Type
3839 and then Ekind
(Nam
) /= E_Entry_Family
3844 -- An indexing requires at least one actual. The name of the call cannot
3845 -- be an implicit indirect call, so it cannot be a generated explicit
3848 if not Is_Empty_List
(Actuals
)
3850 (Needs_No_Actuals
(Nam
)
3852 (Needs_One_Actual
(Nam
)
3853 and then Present
(Next_Actual
(First
(Actuals
)))))
3855 if Is_Array_Type
(Subp_Type
)
3857 (Nkind
(Name
(N
)) /= N_Explicit_Dereference
3858 or else Comes_From_Source
(Name
(N
)))
3860 Is_Indexed
:= Try_Indexed_Call
(N
, Nam
, Subp_Type
, Must_Skip
);
3862 elsif Is_Access_Type
(Subp_Type
)
3863 and then Is_Array_Type
(Designated_Type
(Subp_Type
))
3867 (N
, Nam
, Designated_Type
(Subp_Type
), Must_Skip
);
3869 -- The prefix can also be a parameterless function that returns an
3870 -- access to subprogram, in which case this is an indirect call.
3871 -- If this succeeds, an explicit dereference is added later on,
3872 -- in Analyze_Call or Resolve_Call.
3874 elsif Is_Access_Type
(Subp_Type
)
3875 and then Ekind
(Designated_Type
(Subp_Type
)) = E_Subprogram_Type
3877 Is_Indirect
:= Try_Indirect_Call
(N
, Nam
, Subp_Type
);
3882 -- If the call has been transformed into a slice, it is of the form
3883 -- F (Subtype) where F is parameterless. The node has been rewritten in
3884 -- Try_Indexed_Call and there is nothing else to do.
3887 and then Nkind
(N
) = N_Slice
3893 (N
, Nam
, (Report
and not Is_Indexed
and not Is_Indirect
), Norm_OK
);
3897 -- If an indirect call is a possible interpretation, indicate
3898 -- success to the caller. This may be an indexing of an explicit
3899 -- dereference of a call that returns an access type (see above).
3903 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
3904 and then Comes_From_Source
(Name
(N
)))
3909 -- Mismatch in number or names of parameters
3911 elsif Debug_Flag_E
then
3912 Write_Str
(" normalization fails in call ");
3913 Write_Int
(Int
(N
));
3914 Write_Str
(" with subprogram ");
3915 Write_Int
(Int
(Nam
));
3919 -- If the context expects a function call, discard any interpretation
3920 -- that is a procedure. If the node is not overloaded, leave as is for
3921 -- better error reporting when type mismatch is found.
3923 elsif Nkind
(N
) = N_Function_Call
3924 and then Is_Overloaded
(Name
(N
))
3925 and then Ekind
(Nam
) = E_Procedure
3929 -- Ditto for function calls in a procedure context
3931 elsif Nkind
(N
) = N_Procedure_Call_Statement
3932 and then Is_Overloaded
(Name
(N
))
3933 and then Etype
(Nam
) /= Standard_Void_Type
3937 elsif No
(Actuals
) then
3939 -- If Normalize succeeds, then there are default parameters for
3942 Indicate_Name_And_Type
;
3944 elsif Ekind
(Nam
) = E_Operator
then
3945 if Nkind
(N
) = N_Procedure_Call_Statement
then
3949 -- This occurs when the prefix of the call is an operator name
3950 -- or an expanded name whose selector is an operator name.
3952 Analyze_Operator_Call
(N
, Nam
);
3954 if Etype
(N
) /= Prev_T
then
3956 -- Check that operator is not hidden by a function interpretation
3958 if Is_Overloaded
(Name
(N
)) then
3964 Get_First_Interp
(Name
(N
), I
, It
);
3965 while Present
(It
.Nam
) loop
3966 if Operator_Hidden_By
(It
.Nam
) then
3967 Set_Etype
(N
, Prev_T
);
3971 Get_Next_Interp
(I
, It
);
3976 -- If operator matches formals, record its name on the call.
3977 -- If the operator is overloaded, Resolve will select the
3978 -- correct one from the list of interpretations. The call
3979 -- node itself carries the first candidate.
3981 Set_Entity
(Name
(N
), Nam
);
3984 elsif Report
and then Etype
(N
) = Any_Type
then
3985 Error_Msg_N
("incompatible arguments for operator", N
);
3989 -- Normalize_Actuals has chained the named associations in the
3990 -- correct order of the formals.
3992 Actual
:= First_Actual
(N
);
3993 Formal
:= First_Formal
(Nam
);
3994 First_Form
:= Formal
;
3996 -- If we are analyzing a call rewritten from object notation, skip
3997 -- first actual, which may be rewritten later as an explicit
4001 Next_Actual
(Actual
);
4002 Next_Formal
(Formal
);
4005 while Present
(Actual
) and then Present
(Formal
) loop
4006 if Nkind
(Parent
(Actual
)) /= N_Parameter_Association
4007 or else Chars
(Selector_Name
(Parent
(Actual
))) = Chars
(Formal
)
4009 -- The actual can be compatible with the formal, but we must
4010 -- also check that the context is not an address type that is
4011 -- visibly an integer type. In this case the use of literals is
4012 -- illegal, except in the body of descendants of system, where
4013 -- arithmetic operations on address are of course used.
4015 if Has_Compatible_Type
(Actual
, Etype
(Formal
))
4017 (Etype
(Actual
) /= Universal_Integer
4018 or else not Is_Descendant_Of_Address
(Etype
(Formal
))
4019 or else In_Predefined_Unit
(N
))
4021 Next_Actual
(Actual
);
4022 Next_Formal
(Formal
);
4024 -- In Allow_Integer_Address mode, we allow an actual integer to
4025 -- match a formal address type and vice versa. We only do this
4026 -- if we are certain that an error will otherwise be issued
4028 elsif Address_Integer_Convert_OK
4029 (Etype
(Actual
), Etype
(Formal
))
4030 and then (Report
and not Is_Indexed
and not Is_Indirect
)
4032 -- Handle this case by introducing an unchecked conversion
4035 Unchecked_Convert_To
(Etype
(Formal
),
4036 Relocate_Node
(Actual
)));
4037 Analyze_And_Resolve
(Actual
, Etype
(Formal
));
4038 Next_Actual
(Actual
);
4039 Next_Formal
(Formal
);
4041 -- Under relaxed RM semantics silently replace occurrences of
4042 -- null by System.Address_Null. We only do this if we know that
4043 -- an error will otherwise be issued.
4045 elsif Null_To_Null_Address_Convert_OK
(Actual
, Etype
(Formal
))
4046 and then (Report
and not Is_Indexed
and not Is_Indirect
)
4048 Replace_Null_By_Null_Address
(Actual
);
4049 Analyze_And_Resolve
(Actual
, Etype
(Formal
));
4050 Next_Actual
(Actual
);
4051 Next_Formal
(Formal
);
4053 elsif Compatible_Types_In_Predicate
4054 (Etype
(Formal
), Etype
(Actual
))
4056 Next_Actual
(Actual
);
4057 Next_Formal
(Formal
);
4059 -- A current instance used as an actual of a function,
4060 -- whose body has not been seen, may include a formal
4061 -- whose type is an incomplete view of an enclosing
4062 -- type declaration containing the current call (e.g.
4063 -- in the Expression for a component declaration).
4065 -- In this case, update the signature of the subprogram
4066 -- so the formal has the type of the full view.
4068 elsif Inside_Init_Proc
4069 and then Nkind
(Actual
) = N_Identifier
4070 and then Ekind
(Etype
(Formal
)) = E_Incomplete_Type
4071 and then Etype
(Actual
) = Full_View
(Etype
(Formal
))
4073 Set_Etype
(Formal
, Etype
(Actual
));
4074 Next_Actual
(Actual
);
4075 Next_Formal
(Formal
);
4077 -- Handle failed type check
4080 if Debug_Flag_E
then
4081 Write_Str
(" type checking fails in call ");
4082 Write_Int
(Int
(N
));
4083 Write_Str
(" with formal ");
4084 Write_Int
(Int
(Formal
));
4085 Write_Str
(" in subprogram ");
4086 Write_Int
(Int
(Nam
));
4090 -- Comment needed on the following test???
4092 if Report
and not Is_Indexed
and not Is_Indirect
then
4094 -- Ada 2005 (AI-251): Complete the error notification
4095 -- to help new Ada 2005 users.
4097 if Is_Class_Wide_Type
(Etype
(Formal
))
4098 and then Is_Interface
(Etype
(Etype
(Formal
)))
4099 and then not Interface_Present_In_Ancestor
4100 (Typ
=> Etype
(Actual
),
4101 Iface
=> Etype
(Etype
(Formal
)))
4104 ("(Ada 2005) does not implement interface }",
4105 Actual
, Etype
(Etype
(Formal
)));
4108 -- If we are going to output a secondary error message
4109 -- below, we need to have Wrong_Type output the main one.
4112 (Actual
, Etype
(Formal
), Multiple
=> All_Errors_Mode
);
4114 if Nkind
(Actual
) = N_Op_Eq
4115 and then Nkind
(Left_Opnd
(Actual
)) = N_Identifier
4117 Formal
:= First_Formal
(Nam
);
4118 while Present
(Formal
) loop
4119 if Chars
(Left_Opnd
(Actual
)) = Chars
(Formal
) then
4120 Error_Msg_N
-- CODEFIX
4121 ("possible misspelling of `='>`!", Actual
);
4125 Next_Formal
(Formal
);
4129 if All_Errors_Mode
then
4130 Error_Msg_Sloc
:= Sloc
(Nam
);
4132 if Etype
(Formal
) = Any_Type
then
4134 ("there is no legal actual parameter", Actual
);
4137 if Is_Overloadable
(Nam
)
4138 and then Present
(Alias
(Nam
))
4139 and then not Comes_From_Source
(Nam
)
4142 ("\\ =='> in call to inherited operation & #!",
4145 elsif Ekind
(Nam
) = E_Subprogram_Type
then
4147 Access_To_Subprogram_Typ
:
4148 constant Entity_Id
:=
4150 (Associated_Node_For_Itype
(Nam
));
4153 ("\\ =='> in call to dereference of &#!",
4154 Actual
, Access_To_Subprogram_Typ
);
4159 ("\\ =='> in call to &#!", Actual
, Nam
);
4169 -- Normalize_Actuals has verified that a default value exists
4170 -- for this formal. Current actual names a subsequent formal.
4172 Next_Formal
(Formal
);
4176 -- Due to our current model of controlled type expansion we may
4177 -- have resolved a user call to a non-visible controlled primitive
4178 -- since these inherited subprograms may be generated in the current
4179 -- scope. This is a side effect of the need for the expander to be
4180 -- able to resolve internally generated calls.
4182 -- Specifically, the issue appears when predefined controlled
4183 -- operations get called on a type extension whose parent is a
4184 -- private extension completed with a controlled extension - see
4188 -- type Par_Typ is tagged private;
4190 -- type Par_Typ is new Controlled with null record;
4193 -- procedure Main is
4194 -- type Ext_Typ is new Par_Typ with null record;
4197 -- Finalize (Obj); -- Will improperly resolve
4200 -- To avoid breaking privacy, Is_Hidden gets set elsewhere on such
4201 -- primitives, but we still need to verify that Nam is indeed a
4202 -- non-visible controlled subprogram. So, we do that here and issue
4203 -- the appropriate error.
4206 and then not In_Instance
4207 and then not Comes_From_Source
(Nam
)
4208 and then Comes_From_Source
(N
)
4210 -- Verify Nam is a non-visible controlled primitive
4212 and then Chars
(Nam
) in Name_Adjust
4215 and then Ekind
(Nam
) = E_Procedure
4216 and then Is_Controlled
(Etype
(First_Form
))
4217 and then No
(Next_Formal
(First_Form
))
4218 and then not Is_Visibly_Controlled
(Etype
(First_Form
))
4220 Error_Msg_Node_2
:= Etype
(First_Form
);
4221 Error_Msg_NE
("call to non-visible controlled primitive & on type"
4225 -- On exit, all actuals match
4227 Indicate_Name_And_Type
;
4229 end Analyze_One_Call
;
4231 ---------------------------
4232 -- Analyze_Operator_Call --
4233 ---------------------------
4235 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
) is
4236 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
4237 Act1
: constant Node_Id
:= First_Actual
(N
);
4238 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
4241 -- Binary operator case
4243 if Present
(Act2
) then
4245 -- If more than two operands, then not binary operator after all
4247 if Present
(Next_Actual
(Act2
)) then
4251 -- Otherwise action depends on operator
4262 Find_Arithmetic_Types
(Act1
, Act2
, Op_Id
, N
);
4268 Find_Boolean_Types
(Act1
, Act2
, Op_Id
, N
);
4277 Find_Comparison_Equality_Types
(Act1
, Act2
, Op_Id
, N
);
4279 when Name_Op_Concat
=>
4280 Find_Concatenation_Types
(Act1
, Act2
, Op_Id
, N
);
4282 -- Is this when others, or should it be an abort???
4288 -- Unary operator case
4296 Find_Unary_Types
(Act1
, Op_Id
, N
);
4299 Find_Negation_Types
(Act1
, Op_Id
, N
);
4301 -- Is this when others correct, or should it be an abort???
4307 end Analyze_Operator_Call
;
4309 -------------------------------------------
4310 -- Analyze_Overloaded_Selected_Component --
4311 -------------------------------------------
4313 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
) is
4314 Nam
: constant Node_Id
:= Prefix
(N
);
4315 Sel
: constant Node_Id
:= Selector_Name
(N
);
4322 Set_Etype
(Sel
, Any_Type
);
4324 Get_First_Interp
(Nam
, I
, It
);
4325 while Present
(It
.Typ
) loop
4326 if Is_Access_Type
(It
.Typ
) then
4327 T
:= Designated_Type
(It
.Typ
);
4328 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4333 -- Locate the component. For a private prefix the selector can denote
4336 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
4338 -- If the prefix is a class-wide type, the visible components are
4339 -- those of the base type.
4341 if Is_Class_Wide_Type
(T
) then
4345 Comp
:= First_Entity
(T
);
4346 while Present
(Comp
) loop
4347 if Chars
(Comp
) = Chars
(Sel
)
4348 and then Is_Visible_Component
(Comp
, Sel
)
4351 -- AI05-105: if the context is an object renaming with
4352 -- an anonymous access type, the expected type of the
4353 -- object must be anonymous. This is a name resolution rule.
4355 if Nkind
(Parent
(N
)) /= N_Object_Renaming_Declaration
4356 or else No
(Access_Definition
(Parent
(N
)))
4357 or else Is_Anonymous_Access_Type
(Etype
(Comp
))
4359 Set_Entity
(Sel
, Comp
);
4360 Set_Etype
(Sel
, Etype
(Comp
));
4361 Add_One_Interp
(N
, Etype
(Comp
), Etype
(Comp
));
4362 Check_Implicit_Dereference
(N
, Etype
(Comp
));
4364 -- This also specifies a candidate to resolve the name.
4365 -- Further overloading will be resolved from context.
4366 -- The selector name itself does not carry overloading
4369 Set_Etype
(Nam
, It
.Typ
);
4372 -- Named access type in the context of a renaming
4373 -- declaration with an access definition. Remove
4374 -- inapplicable candidate.
4383 elsif Is_Concurrent_Type
(T
) then
4384 Comp
:= First_Entity
(T
);
4385 while Present
(Comp
)
4386 and then Comp
/= First_Private_Entity
(T
)
4388 if Chars
(Comp
) = Chars
(Sel
) then
4389 if Is_Overloadable
(Comp
) then
4390 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
4392 Set_Entity_With_Checks
(Sel
, Comp
);
4393 Generate_Reference
(Comp
, Sel
);
4396 Set_Etype
(Sel
, Etype
(Comp
));
4397 Set_Etype
(N
, Etype
(Comp
));
4398 Set_Etype
(Nam
, It
.Typ
);
4404 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
4407 Get_Next_Interp
(I
, It
);
4410 if Etype
(N
) = Any_Type
4411 and then not Try_Object_Operation
(N
)
4413 Error_Msg_NE
("undefined selector& for overloaded prefix", N
, Sel
);
4414 Set_Entity
(Sel
, Any_Id
);
4415 Set_Etype
(Sel
, Any_Type
);
4417 end Analyze_Overloaded_Selected_Component
;
4419 ----------------------------------
4420 -- Analyze_Qualified_Expression --
4421 ----------------------------------
4423 procedure Analyze_Qualified_Expression
(N
: Node_Id
) is
4424 Expr
: constant Node_Id
:= Expression
(N
);
4425 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
4435 if Nkind
(Enclosing_Declaration
(N
)) in
4436 N_Formal_Type_Declaration |
4437 N_Full_Type_Declaration |
4438 N_Incomplete_Type_Declaration |
4439 N_Protected_Type_Declaration |
4440 N_Private_Extension_Declaration |
4441 N_Private_Type_Declaration |
4442 N_Subtype_Declaration |
4443 N_Task_Type_Declaration
4444 and then T
= Defining_Identifier
(Enclosing_Declaration
(N
))
4446 Error_Msg_N
("current instance not allowed", Mark
);
4452 Analyze_Expression
(Expr
);
4454 if T
= Any_Type
then
4458 Check_Fully_Declared
(T
, N
);
4460 -- If expected type is class-wide, check for exact match before
4461 -- expansion, because if the expression is a dispatching call it
4462 -- may be rewritten as explicit dereference with class-wide result.
4463 -- If expression is overloaded, retain only interpretations that
4464 -- will yield exact matches.
4466 if Is_Class_Wide_Type
(T
) then
4467 if not Is_Overloaded
(Expr
) then
4468 if Base_Type
(Etype
(Expr
)) /= Base_Type
(T
)
4469 and then Etype
(Expr
) /= Raise_Type
4471 if Nkind
(Expr
) = N_Aggregate
then
4472 Error_Msg_N
("type of aggregate cannot be class-wide", Expr
);
4474 Wrong_Type
(Expr
, T
);
4479 Get_First_Interp
(Expr
, I
, It
);
4481 while Present
(It
.Nam
) loop
4482 if Base_Type
(It
.Typ
) /= Base_Type
(T
) then
4486 Get_Next_Interp
(I
, It
);
4490 end Analyze_Qualified_Expression
;
4492 -----------------------------------
4493 -- Analyze_Quantified_Expression --
4494 -----------------------------------
4496 procedure Analyze_Quantified_Expression
(N
: Node_Id
) is
4497 function Is_Empty_Range
(Typ
: Entity_Id
) return Boolean;
4498 -- Return True if the iterator is part of a quantified expression and
4499 -- the range is known to be statically empty.
4501 function No_Else_Or_Trivial_True
(If_Expr
: Node_Id
) return Boolean;
4502 -- Determine whether if expression If_Expr lacks an else part or if it
4503 -- has one, it evaluates to True.
4505 --------------------
4506 -- Is_Empty_Range --
4507 --------------------
4509 function Is_Empty_Range
(Typ
: Entity_Id
) return Boolean is
4511 return Is_Array_Type
(Typ
)
4512 and then Compile_Time_Known_Bounds
(Typ
)
4514 Expr_Value
(Type_Low_Bound
(Etype
(First_Index
(Typ
)))) >
4515 Expr_Value
(Type_High_Bound
(Etype
(First_Index
(Typ
))));
4518 -----------------------------
4519 -- No_Else_Or_Trivial_True --
4520 -----------------------------
4522 function No_Else_Or_Trivial_True
(If_Expr
: Node_Id
) return Boolean is
4523 Else_Expr
: constant Node_Id
:=
4524 Next
(Next
(First
(Expressions
(If_Expr
))));
4528 or else (Compile_Time_Known_Value
(Else_Expr
)
4529 and then Is_True
(Expr_Value
(Else_Expr
)));
4530 end No_Else_Or_Trivial_True
;
4534 Cond
: constant Node_Id
:= Condition
(N
);
4535 Loc
: constant Source_Ptr
:= Sloc
(N
);
4536 Loop_Id
: Entity_Id
;
4537 QE_Scop
: Entity_Id
;
4539 -- Start of processing for Analyze_Quantified_Expression
4542 -- Create a scope to emulate the loop-like behavior of the quantified
4543 -- expression. The scope is needed to provide proper visibility of the
4546 QE_Scop
:= New_Internal_Entity
(E_Loop
, Current_Scope
, Loc
, 'L');
4547 Set_Etype
(QE_Scop
, Standard_Void_Type
);
4548 Set_Scope
(QE_Scop
, Current_Scope
);
4549 Set_Parent
(QE_Scop
, N
);
4551 Push_Scope
(QE_Scop
);
4553 -- All constituents are preanalyzed and resolved to avoid untimely
4554 -- generation of various temporaries and types. Full analysis and
4555 -- expansion is carried out when the quantified expression is
4556 -- transformed into an expression with actions.
4558 if Present
(Iterator_Specification
(N
)) then
4559 Preanalyze
(Iterator_Specification
(N
));
4561 -- Do not proceed with the analysis when the range of iteration is
4564 if Is_Entity_Name
(Name
(Iterator_Specification
(N
)))
4565 and then Is_Empty_Range
(Etype
(Name
(Iterator_Specification
(N
))))
4567 Preanalyze_And_Resolve
(Condition
(N
), Standard_Boolean
);
4570 -- Emit a warning and replace expression with its static value
4572 if All_Present
(N
) then
4574 ("??quantified expression with ALL "
4575 & "over a null range has value True", N
);
4576 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
4580 ("??quantified expression with SOME "
4581 & "over a null range has value False", N
);
4582 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
4589 else pragma Assert
(Present
(Loop_Parameter_Specification
(N
)));
4591 Loop_Par
: constant Node_Id
:= Loop_Parameter_Specification
(N
);
4594 Preanalyze
(Loop_Par
);
4596 if Nkind
(Discrete_Subtype_Definition
(Loop_Par
)) = N_Function_Call
4597 and then Parent
(Loop_Par
) /= N
4599 -- The parser cannot distinguish between a loop specification
4600 -- and an iterator specification. If after preanalysis the
4601 -- proper form has been recognized, rewrite the expression to
4602 -- reflect the right kind. This is needed for proper ASIS
4603 -- navigation. If expansion is enabled, the transformation is
4604 -- performed when the expression is rewritten as a loop.
4605 -- Is this still needed???
4607 Set_Iterator_Specification
(N
,
4608 New_Copy_Tree
(Iterator_Specification
(Parent
(Loop_Par
))));
4610 Set_Defining_Identifier
(Iterator_Specification
(N
),
4611 Relocate_Node
(Defining_Identifier
(Loop_Par
)));
4612 Set_Name
(Iterator_Specification
(N
),
4613 Relocate_Node
(Discrete_Subtype_Definition
(Loop_Par
)));
4614 Set_Comes_From_Source
(Iterator_Specification
(N
),
4615 Comes_From_Source
(Loop_Parameter_Specification
(N
)));
4616 Set_Loop_Parameter_Specification
(N
, Empty
);
4621 Preanalyze_And_Resolve
(Cond
, Standard_Boolean
);
4624 Set_Etype
(N
, Standard_Boolean
);
4626 -- Verify that the loop variable is used within the condition of the
4627 -- quantified expression.
4629 if Present
(Iterator_Specification
(N
)) then
4630 Loop_Id
:= Defining_Identifier
(Iterator_Specification
(N
));
4632 Loop_Id
:= Defining_Identifier
(Loop_Parameter_Specification
(N
));
4636 type Subexpr_Kind
is (Full
, Conjunct
, Disjunct
);
4638 procedure Check_Subexpr
(Expr
: Node_Id
; Kind
: Subexpr_Kind
);
4639 -- Check that the quantified variable appears in every sub-expression
4640 -- of the quantified expression. If Kind is Full, Expr is the full
4641 -- expression. If Kind is Conjunct (resp. Disjunct), Expr is a
4642 -- conjunct (resp. disjunct) of the full expression.
4648 procedure Check_Subexpr
(Expr
: Node_Id
; Kind
: Subexpr_Kind
) is
4650 if Nkind
(Expr
) in N_Op_And | N_And_Then
4651 and then Kind
/= Disjunct
4653 Check_Subexpr
(Left_Opnd
(Expr
), Conjunct
);
4654 Check_Subexpr
(Right_Opnd
(Expr
), Conjunct
);
4656 elsif Nkind
(Expr
) in N_Op_Or | N_Or_Else
4657 and then Kind
/= Conjunct
4659 Check_Subexpr
(Left_Opnd
(Expr
), Disjunct
);
4660 Check_Subexpr
(Right_Opnd
(Expr
), Disjunct
);
4663 and then not Referenced
(Loop_Id
, Expr
)
4666 Sub
: constant String :=
4667 (if Kind
= Conjunct
then "conjunct" else "disjunct");
4670 ("?.t?unused variable & in " & Sub
, Expr
, Loop_Id
);
4672 ("\consider extracting " & Sub
& " from quantified "
4673 & "expression", Expr
, Loop_Id
);
4679 if Warn_On_Suspicious_Contract
4680 and then not Is_Internal_Name
(Chars
(Loop_Id
))
4682 -- Generating C, this check causes spurious warnings on inlined
4683 -- postconditions; we can safely disable it because this check
4684 -- was previously performed when analyzing the internally built
4685 -- postconditions procedure.
4687 and then not (Modify_Tree_For_C
and In_Inlined_Body
)
4689 if not Referenced
(Loop_Id
, Cond
) then
4690 Error_Msg_N
("?.t?unused variable &", Loop_Id
);
4692 Check_Subexpr
(Cond
, Kind
=> Full
);
4697 -- Diagnose a possible misuse of the SOME existential quantifier. When
4698 -- we have a quantified expression of the form:
4700 -- for some X => (if P then Q [else True])
4702 -- any value for X that makes P False results in the if expression being
4703 -- trivially True, and so also results in the quantified expression
4704 -- being trivially True.
4706 if Warn_On_Suspicious_Contract
4707 and then not All_Present
(N
)
4708 and then Nkind
(Cond
) = N_If_Expression
4709 and then No_Else_Or_Trivial_True
(Cond
)
4711 Error_Msg_N
("?.t?suspicious expression", N
);
4712 Error_Msg_N
("\\did you mean (for all X ='> (if P then Q))", N
);
4713 Error_Msg_N
("\\or (for some X ='> P and then Q) instead'?", N
);
4715 end Analyze_Quantified_Expression
;
4721 procedure Analyze_Range
(N
: Node_Id
) is
4722 L
: constant Node_Id
:= Low_Bound
(N
);
4723 H
: constant Node_Id
:= High_Bound
(N
);
4724 I1
, I2
: Interp_Index
;
4727 procedure Check_Common_Type
(T1
, T2
: Entity_Id
);
4728 -- Verify the compatibility of two types, and choose the
4729 -- non universal one if the other is universal.
4731 procedure Check_High_Bound
(T
: Entity_Id
);
4732 -- Test one interpretation of the low bound against all those
4733 -- of the high bound.
4735 procedure Check_Universal_Expression
(N
: Node_Id
);
4736 -- In Ada 83, reject bounds of a universal range that are not literals
4739 -----------------------
4740 -- Check_Common_Type --
4741 -----------------------
4743 procedure Check_Common_Type
(T1
, T2
: Entity_Id
) is
4745 if Covers
(T1
=> T1
, T2
=> T2
)
4747 Covers
(T1
=> T2
, T2
=> T1
)
4749 if Is_Universal_Numeric_Type
(T1
)
4750 or else T1
= Any_Character
4752 Add_One_Interp
(N
, Base_Type
(T2
), Base_Type
(T2
));
4755 Add_One_Interp
(N
, T1
, T1
);
4758 Add_One_Interp
(N
, Base_Type
(T1
), Base_Type
(T1
));
4761 end Check_Common_Type
;
4763 ----------------------
4764 -- Check_High_Bound --
4765 ----------------------
4767 procedure Check_High_Bound
(T
: Entity_Id
) is
4769 if not Is_Overloaded
(H
) then
4770 Check_Common_Type
(T
, Etype
(H
));
4772 Get_First_Interp
(H
, I2
, It2
);
4773 while Present
(It2
.Typ
) loop
4774 Check_Common_Type
(T
, It2
.Typ
);
4775 Get_Next_Interp
(I2
, It2
);
4778 end Check_High_Bound
;
4780 --------------------------------
4781 -- Check_Universal_Expression --
4782 --------------------------------
4784 procedure Check_Universal_Expression
(N
: Node_Id
) is
4786 if Etype
(N
) = Universal_Integer
4787 and then Nkind
(N
) /= N_Integer_Literal
4788 and then not Is_Entity_Name
(N
)
4789 and then Nkind
(N
) /= N_Attribute_Reference
4791 Error_Msg_N
("illegal bound in discrete range", N
);
4793 end Check_Universal_Expression
;
4795 -- Start of processing for Analyze_Range
4798 Set_Etype
(N
, Any_Type
);
4799 Analyze_Expression
(L
);
4800 Analyze_Expression
(H
);
4802 if Etype
(L
) = Any_Type
or else Etype
(H
) = Any_Type
then
4806 if not Is_Overloaded
(L
) then
4807 Check_High_Bound
(Etype
(L
));
4809 Get_First_Interp
(L
, I1
, It1
);
4810 while Present
(It1
.Typ
) loop
4811 Check_High_Bound
(It1
.Typ
);
4812 Get_Next_Interp
(I1
, It1
);
4816 -- If result is Any_Type, then we did not find a compatible pair
4818 if Etype
(N
) = Any_Type
then
4819 Error_Msg_N
("incompatible types in range", N
);
4823 if Ada_Version
= Ada_83
4825 (Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
4826 or else Nkind
(Parent
(N
)) = N_Constrained_Array_Definition
)
4828 Check_Universal_Expression
(L
);
4829 Check_Universal_Expression
(H
);
4832 Check_Function_Writable_Actuals
(N
);
4835 -----------------------
4836 -- Analyze_Reference --
4837 -----------------------
4839 procedure Analyze_Reference
(N
: Node_Id
) is
4840 P
: constant Node_Id
:= Prefix
(N
);
4843 Acc_Type
: Entity_Id
;
4848 -- An interesting error check, if we take the 'Ref of an object for
4849 -- which a pragma Atomic or Volatile has been given, and the type of the
4850 -- object is not Atomic or Volatile, then we are in trouble. The problem
4851 -- is that no trace of the atomic/volatile status will remain for the
4852 -- backend to respect when it deals with the resulting pointer, since
4853 -- the pointer type will not be marked atomic (it is a pointer to the
4854 -- base type of the object).
4856 -- It is not clear if that can ever occur, but in case it does, we will
4857 -- generate an error message. Not clear if this message can ever be
4858 -- generated, and pretty clear that it represents a bug if it is, still
4859 -- seems worth checking, except in CodePeer mode where we do not really
4860 -- care and don't want to bother the user.
4864 if Is_Entity_Name
(P
)
4865 and then Is_Object_Reference
(P
)
4866 and then not CodePeer_Mode
4871 if (Has_Atomic_Components
(E
)
4872 and then not Has_Atomic_Components
(T
))
4874 (Has_Volatile_Components
(E
)
4875 and then not Has_Volatile_Components
(T
))
4876 or else (Is_Atomic
(E
) and then not Is_Atomic
(T
))
4877 or else (Is_Volatile
(E
) and then not Is_Volatile
(T
))
4879 Error_Msg_N
("cannot take reference to Atomic/Volatile object", N
);
4883 -- Carry on with normal processing
4885 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
4886 Set_Etype
(Acc_Type
, Acc_Type
);
4887 Set_Directly_Designated_Type
(Acc_Type
, Etype
(P
));
4888 Set_Etype
(N
, Acc_Type
);
4889 end Analyze_Reference
;
4891 --------------------------------
4892 -- Analyze_Selected_Component --
4893 --------------------------------
4895 -- Prefix is a record type or a task or protected type. In the latter case,
4896 -- the selector must denote a visible entry.
4898 procedure Analyze_Selected_Component
(N
: Node_Id
) is
4899 Name
: constant Node_Id
:= Prefix
(N
);
4900 Sel
: constant Node_Id
:= Selector_Name
(N
);
4902 Comp
: Entity_Id
:= Empty
;
4903 Has_Candidate
: Boolean := False;
4904 Hidden_Comp
: Entity_Id
;
4906 Is_Private_Op
: Boolean;
4908 Prefix_Type
: Entity_Id
;
4910 Type_To_Use
: Entity_Id
;
4911 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
4912 -- a class-wide type, we use its root type, whose components are
4913 -- present in the class-wide type.
4915 Is_Single_Concurrent_Object
: Boolean;
4916 -- Set True if the prefix is a single task or a single protected object
4918 function Constraint_Has_Unprefixed_Discriminant_Reference
4919 (Typ
: Entity_Id
) return Boolean;
4920 -- Given a subtype that is subject to a discriminant-dependent
4921 -- constraint, returns True if any of the values of the constraint
4922 -- (i.e., any of the index values for an index constraint, any of
4923 -- the discriminant values for a discriminant constraint)
4924 -- are unprefixed discriminant names.
4926 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean;
4927 -- It is known that the parent of N denotes a subprogram call. Comp
4928 -- is an overloadable component of the concurrent type of the prefix.
4929 -- Determine whether all formals of the parent of N and Comp are mode
4930 -- conformant. If the parent node is not analyzed yet it may be an
4931 -- indexed component rather than a function call.
4933 function Has_Dereference
(Nod
: Node_Id
) return Boolean;
4934 -- Check whether prefix includes a dereference, explicit or implicit,
4935 -- at any recursive level.
4937 function Try_By_Protected_Procedure_Prefixed_View
return Boolean;
4938 -- Return True if N is an access attribute whose prefix is a prefixed
4939 -- class-wide (synchronized or protected) interface view for which some
4940 -- interpretation is a procedure with synchronization kind By_Protected
4941 -- _Procedure, and collect all its interpretations (since it may be an
4942 -- overloaded interface primitive); otherwise return False.
4944 function Try_Selected_Component_In_Instance
4945 (Typ
: Entity_Id
) return Boolean;
4946 -- If Typ is the actual for a formal derived type, or a derived type
4947 -- thereof, the component inherited from the generic parent may not
4948 -- be visible in the actual, but the selected component is legal. Climb
4949 -- up the derivation chain of the generic parent type and return True if
4950 -- we find the proper ancestor type; otherwise return False.
4952 ------------------------------------------------------
4953 -- Constraint_Has_Unprefixed_Discriminant_Reference --
4954 ------------------------------------------------------
4956 function Constraint_Has_Unprefixed_Discriminant_Reference
4957 (Typ
: Entity_Id
) return Boolean
4959 function Is_Discriminant_Name
(N
: Node_Id
) return Boolean is
4960 (Nkind
(N
) = N_Identifier
4961 and then Ekind
(Entity
(N
)) = E_Discriminant
);
4963 if Is_Array_Type
(Typ
) then
4965 Index
: Node_Id
:= First_Index
(Typ
);
4968 while Present
(Index
) loop
4970 if Nkind
(Rng
) = N_Subtype_Indication
then
4971 Rng
:= Range_Expression
(Constraint
(Rng
));
4974 if Nkind
(Rng
) = N_Range
then
4975 if Is_Discriminant_Name
(Low_Bound
(Rng
))
4976 or else Is_Discriminant_Name
(High_Bound
(Rng
))
4987 Elmt
: Elmt_Id
:= First_Elmt
(Discriminant_Constraint
(Typ
));
4989 while Present
(Elmt
) loop
4990 if Is_Discriminant_Name
(Node
(Elmt
)) then
4999 end Constraint_Has_Unprefixed_Discriminant_Reference
;
5001 ------------------------------
5002 -- Has_Mode_Conformant_Spec --
5003 ------------------------------
5005 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean is
5006 Comp_Param
: Entity_Id
;
5008 Param_Typ
: Entity_Id
;
5011 Comp_Param
:= First_Formal
(Comp
);
5013 if Nkind
(Parent
(N
)) = N_Indexed_Component
then
5014 Param
:= First
(Expressions
(Parent
(N
)));
5016 Param
:= First
(Parameter_Associations
(Parent
(N
)));
5019 while Present
(Comp_Param
)
5020 and then Present
(Param
)
5022 Param_Typ
:= Find_Parameter_Type
(Param
);
5024 if Present
(Param_Typ
)
5026 not Conforming_Types
5027 (Etype
(Comp_Param
), Param_Typ
, Mode_Conformant
)
5032 Next_Formal
(Comp_Param
);
5036 -- One of the specs has additional formals; there is no match, unless
5037 -- this may be an indexing of a parameterless call.
5039 -- Note that when expansion is disabled, the corresponding record
5040 -- type of synchronized types is not constructed, so that there is
5041 -- no point is attempting an interpretation as a prefixed call, as
5042 -- this is bound to fail because the primitive operations will not
5043 -- be properly located.
5045 if Present
(Comp_Param
) or else Present
(Param
) then
5046 if Needs_No_Actuals
(Comp
)
5047 and then Is_Array_Type
(Etype
(Comp
))
5048 and then not Expander_Active
5057 end Has_Mode_Conformant_Spec
;
5059 ---------------------
5060 -- Has_Dereference --
5061 ---------------------
5063 function Has_Dereference
(Nod
: Node_Id
) return Boolean is
5065 if Nkind
(Nod
) = N_Explicit_Dereference
then
5068 elsif Is_Access_Type
(Etype
(Nod
)) then
5071 elsif Nkind
(Nod
) in N_Indexed_Component | N_Selected_Component
then
5072 return Has_Dereference
(Prefix
(Nod
));
5077 end Has_Dereference
;
5079 ----------------------------------------------
5080 -- Try_By_Protected_Procedure_Prefixed_View --
5081 ----------------------------------------------
5083 function Try_By_Protected_Procedure_Prefixed_View
return Boolean is
5084 Candidate
: Node_Id
:= Empty
;
5089 if Nkind
(Parent
(N
)) = N_Attribute_Reference
5090 and then Attribute_Name
(Parent
(N
)) in
5092 | Name_Unchecked_Access
5093 | Name_Unrestricted_Access
5094 and then Is_Class_Wide_Type
(Prefix_Type
)
5095 and then (Is_Synchronized_Interface
(Prefix_Type
)
5096 or else Is_Protected_Interface
(Prefix_Type
))
5098 -- If we have not found yet any interpretation then mark this
5099 -- one as the first interpretation (cf. Add_One_Interp).
5101 if No
(Etype
(Sel
)) then
5102 Set_Etype
(Sel
, Any_Type
);
5105 Elmt
:= First_Elmt
(Primitive_Operations
(Etype
(Prefix_Type
)));
5106 while Present
(Elmt
) loop
5107 Prim
:= Node
(Elmt
);
5109 if Chars
(Prim
) = Chars
(Sel
)
5110 and then Is_By_Protected_Procedure
(Prim
)
5112 Candidate
:= New_Copy
(Prim
);
5114 -- Skip the controlling formal; required to check type
5115 -- conformance of the target access to protected type
5116 -- (see Conforming_Types).
5118 Set_First_Entity
(Candidate
,
5119 Next_Entity
(First_Entity
(Prim
)));
5121 Add_One_Interp
(Sel
, Candidate
, Etype
(Prim
));
5122 Set_Etype
(N
, Etype
(Prim
));
5129 -- Propagate overloaded attribute
5131 if Present
(Candidate
) and then Is_Overloaded
(Sel
) then
5132 Set_Is_Overloaded
(N
);
5135 return Present
(Candidate
);
5136 end Try_By_Protected_Procedure_Prefixed_View
;
5138 ----------------------------------------
5139 -- Try_Selected_Component_In_Instance --
5140 ----------------------------------------
5142 function Try_Selected_Component_In_Instance
5143 (Typ
: Entity_Id
) return Boolean
5145 procedure Find_Component_In_Instance
(Rec
: Entity_Id
);
5146 -- In an instance, a component of a private extension may not be
5147 -- visible while it was visible in the generic. Search candidate
5148 -- scope for a component with the proper identifier. If a match is
5149 -- found, the Etype of both N and Sel are set from this component,
5150 -- and the entity of Sel is set to reference this component. If no
5151 -- match is found, Entity (Sel) remains unset. For a derived type
5152 -- that is an actual of the instance, the desired component may be
5153 -- found in any ancestor.
5155 --------------------------------
5156 -- Find_Component_In_Instance --
5157 --------------------------------
5159 procedure Find_Component_In_Instance
(Rec
: Entity_Id
) is
5165 while Present
(Typ
) loop
5166 Comp
:= First_Component
(Typ
);
5167 while Present
(Comp
) loop
5168 if Chars
(Comp
) = Chars
(Sel
) then
5169 Set_Entity_With_Checks
(Sel
, Comp
);
5170 Set_Etype
(Sel
, Etype
(Comp
));
5171 Set_Etype
(N
, Etype
(Comp
));
5175 Next_Component
(Comp
);
5178 -- If not found, the component may be declared in the parent
5179 -- type or its full view, if any.
5181 if Is_Derived_Type
(Typ
) then
5184 if Is_Private_Type
(Typ
) then
5185 Typ
:= Full_View
(Typ
);
5193 -- If we fall through, no match, so no changes made
5196 end Find_Component_In_Instance
;
5202 -- Start of processing for Try_Selected_Component_In_Instance
5205 pragma Assert
(In_Instance
and then Is_Tagged_Type
(Typ
));
5206 pragma Assert
(Etype
(N
) = Any_Type
);
5208 -- Climb up derivation chain to generic actual subtype
5211 while not Is_Generic_Actual_Type
(Par
) loop
5212 if Ekind
(Par
) = E_Record_Type
then
5213 Par
:= Parent_Subtype
(Par
);
5216 exit when Par
= Etype
(Par
);
5221 -- If Par is a generic actual, look for component in ancestor types.
5222 -- Skip this if we have no Declaration_Node, as is the case for
5226 and then Is_Generic_Actual_Type
(Par
)
5227 and then Present
(Declaration_Node
(Par
))
5229 Par
:= Generic_Parent_Type
(Declaration_Node
(Par
));
5231 Find_Component_In_Instance
(Par
);
5232 exit when Present
(Entity
(Sel
))
5233 or else Par
= Etype
(Par
);
5237 -- Another special case: the type is an extension of a private
5238 -- type T, either is an actual in an instance or is immediately
5239 -- visible, and we are in the body of the instance, which means
5240 -- the generic body had a full view of the type declaration for
5241 -- T or some ancestor that defines the component in question.
5242 -- This happens because Is_Visible_Component returned False on
5243 -- this component, as T or the ancestor is still private since
5244 -- the Has_Private_View mechanism is bypassed because T or the
5245 -- ancestor is not directly referenced in the generic body.
5247 elsif Is_Derived_Type
(Typ
)
5248 and then (Used_As_Generic_Actual
(Typ
)
5249 or else Is_Immediately_Visible
(Typ
))
5250 and then In_Instance_Body
5252 Find_Component_In_Instance
(Parent_Subtype
(Typ
));
5255 return Etype
(N
) /= Any_Type
;
5256 end Try_Selected_Component_In_Instance
;
5258 -- Start of processing for Analyze_Selected_Component
5261 Set_Etype
(N
, Any_Type
);
5263 if Is_Overloaded
(Name
) then
5264 Analyze_Overloaded_Selected_Component
(N
);
5267 elsif Etype
(Name
) = Any_Type
then
5268 Set_Entity
(Sel
, Any_Id
);
5269 Set_Etype
(Sel
, Any_Type
);
5273 Prefix_Type
:= Etype
(Name
);
5276 if Is_Access_Type
(Prefix_Type
) then
5278 -- A RACW object can never be used as prefix of a selected component
5279 -- since that means it is dereferenced without being a controlling
5280 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
5281 -- reporting an error, we must check whether this is actually a
5282 -- dispatching call in prefix form.
5284 if Is_Remote_Access_To_Class_Wide_Type
(Prefix_Type
)
5285 and then Comes_From_Source
(N
)
5287 if Try_Object_Operation
(N
) then
5291 ("invalid dereference of a remote access-to-class-wide value",
5295 -- Normal case of selected component applied to access type
5298 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
5299 Prefix_Type
:= Implicitly_Designated_Type
(Prefix_Type
);
5302 -- If we have an explicit dereference of a remote access-to-class-wide
5303 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
5304 -- have to check for the case of a prefix that is a controlling operand
5305 -- of a prefixed dispatching call, as the dereference is legal in that
5306 -- case. Normally this condition is checked in Validate_Remote_Access_
5307 -- To_Class_Wide_Type, but we have to defer the checking for selected
5308 -- component prefixes because of the prefixed dispatching call case.
5309 -- Note that implicit dereferences are checked for this just above.
5311 elsif Nkind
(Name
) = N_Explicit_Dereference
5312 and then Is_Remote_Access_To_Class_Wide_Type
(Etype
(Prefix
(Name
)))
5313 and then Comes_From_Source
(N
)
5315 if Try_Object_Operation
(N
) then
5319 ("invalid dereference of a remote access-to-class-wide value",
5324 -- (Ada 2005): if the prefix is the limited view of a type, and
5325 -- the context already includes the full view, use the full view
5326 -- in what follows, either to retrieve a component of to find
5327 -- a primitive operation. If the prefix is an explicit dereference,
5328 -- set the type of the prefix to reflect this transformation.
5329 -- If the nonlimited view is itself an incomplete type, get the
5330 -- full view if available.
5332 if From_Limited_With
(Prefix_Type
)
5333 and then Has_Non_Limited_View
(Prefix_Type
)
5335 Prefix_Type
:= Get_Full_View
(Non_Limited_View
(Prefix_Type
));
5337 if Nkind
(N
) = N_Explicit_Dereference
then
5338 Set_Etype
(Prefix
(N
), Prefix_Type
);
5342 if Ekind
(Prefix_Type
) = E_Private_Subtype
then
5343 Prefix_Type
:= Base_Type
(Prefix_Type
);
5346 Type_To_Use
:= Prefix_Type
;
5348 -- For class-wide types, use the entity list of the root type. This
5349 -- indirection is specially important for private extensions because
5350 -- only the root type get switched (not the class-wide type).
5352 if Is_Class_Wide_Type
(Prefix_Type
) then
5353 Type_To_Use
:= Root_Type
(Prefix_Type
);
5356 -- If the prefix is a single concurrent object, use its name in error
5357 -- messages, rather than that of its anonymous type.
5359 Is_Single_Concurrent_Object
:=
5360 Is_Concurrent_Type
(Prefix_Type
)
5361 and then Is_Internal_Name
(Chars
(Prefix_Type
))
5362 and then not Is_Derived_Type
(Prefix_Type
)
5363 and then Is_Entity_Name
(Name
);
5365 -- Avoid initializing Comp if that initialization is not needed
5366 -- (and, more importantly, if the call to First_Entity could fail).
5368 if Has_Discriminants
(Type_To_Use
)
5369 or else Is_Record_Type
(Type_To_Use
)
5370 or else Is_Private_Type
(Type_To_Use
)
5371 or else Is_Concurrent_Type
(Type_To_Use
)
5373 Comp
:= First_Entity
(Type_To_Use
);
5376 -- If the selector has an original discriminant, the node appears in
5377 -- an instance. Replace the discriminant with the corresponding one
5378 -- in the current discriminated type. For nested generics, this must
5379 -- be done transitively, so note the new original discriminant.
5381 if Nkind
(Sel
) = N_Identifier
5382 and then In_Instance
5383 and then Present
(Original_Discriminant
(Sel
))
5385 Comp
:= Find_Corresponding_Discriminant
(Sel
, Prefix_Type
);
5387 -- Mark entity before rewriting, for completeness and because
5388 -- subsequent semantic checks might examine the original node.
5390 Set_Entity
(Sel
, Comp
);
5391 Rewrite
(Selector_Name
(N
), New_Occurrence_Of
(Comp
, Sloc
(N
)));
5392 Set_Original_Discriminant
(Selector_Name
(N
), Comp
);
5393 Set_Etype
(N
, Etype
(Comp
));
5394 Check_Implicit_Dereference
(N
, Etype
(Comp
));
5396 elsif Is_Record_Type
(Prefix_Type
) then
5398 -- Find a component with the given name. If the node is a prefixed
5399 -- call, do not examine components whose visibility may be
5402 while Present
(Comp
)
5403 and then not Is_Prefixed_Call
(N
)
5405 -- When the selector has been resolved to a function then we may be
5406 -- looking at a prefixed call which has been preanalyzed already as
5407 -- part of a class condition. In such cases it is possible for a
5408 -- derived type to declare a component which has the same name as
5409 -- a primitive used in a parent's class condition.
5411 -- Avoid seeing components as possible interpretations of the
5412 -- selected component when this is true.
5414 and then not (Inside_Class_Condition_Preanalysis
5415 and then Present
(Entity
(Sel
))
5416 and then Ekind
(Entity
(Sel
)) = E_Function
)
5418 if Chars
(Comp
) = Chars
(Sel
)
5419 and then Is_Visible_Component
(Comp
, N
)
5421 Set_Entity_With_Checks
(Sel
, Comp
);
5422 Set_Etype
(Sel
, Etype
(Comp
));
5424 if Ekind
(Comp
) = E_Discriminant
then
5425 if Is_Unchecked_Union
(Base_Type
(Prefix_Type
)) then
5427 ("cannot reference discriminant of unchecked union",
5431 if Is_Generic_Type
(Prefix_Type
)
5433 Is_Generic_Type
(Root_Type
(Prefix_Type
))
5435 Set_Original_Discriminant
(Sel
, Comp
);
5439 -- Resolve the prefix early otherwise it is not possible to
5440 -- build the actual subtype of the component: it may need
5441 -- to duplicate this prefix and duplication is only allowed
5442 -- on fully resolved expressions.
5446 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
5447 -- subtypes in a package specification.
5450 -- limited with Pkg;
5452 -- type Acc_Inc is access Pkg.T;
5454 -- N : Natural := X.all.Comp; -- ERROR, limited view
5455 -- end Pkg; -- Comp is not visible
5457 if Nkind
(Name
) = N_Explicit_Dereference
5458 and then From_Limited_With
(Etype
(Prefix
(Name
)))
5459 and then not Is_Potentially_Use_Visible
(Etype
(Name
))
5460 and then Nkind
(Parent
(Cunit_Entity
(Current_Sem_Unit
))) =
5461 N_Package_Specification
5464 ("premature usage of incomplete}", Prefix
(Name
),
5465 Etype
(Prefix
(Name
)));
5468 -- We never need an actual subtype for the case of a selection
5469 -- for a indexed component of a non-packed array, since in
5470 -- this case gigi generates all the checks and can find the
5471 -- necessary bounds information.
5473 -- We also do not need an actual subtype for the case of a
5474 -- first, last, length, or range attribute applied to a
5475 -- non-packed array, since gigi can again get the bounds in
5476 -- these cases (gigi cannot handle the packed case, since it
5477 -- has the bounds of the packed array type, not the original
5478 -- bounds of the type). However, if the prefix is itself a
5479 -- selected component, as in a.b.c (i), gigi may regard a.b.c
5480 -- as a dynamic-sized temporary, so we do generate an actual
5481 -- subtype for this case.
5483 Parent_N
:= Parent
(N
);
5485 if not Is_Packed
(Etype
(Comp
))
5487 ((Nkind
(Parent_N
) = N_Indexed_Component
5488 and then Nkind
(Name
) /= N_Selected_Component
)
5490 (Nkind
(Parent_N
) = N_Attribute_Reference
5492 Attribute_Name
(Parent_N
) in Name_First
5497 Set_Etype
(N
, Etype
(Comp
));
5499 -- If full analysis is not enabled, we do not generate an
5500 -- actual subtype, because in the absence of expansion
5501 -- reference to a formal of a protected type, for example,
5502 -- will not be properly transformed, and will lead to
5503 -- out-of-scope references in gigi.
5505 -- In all other cases, we currently build an actual subtype.
5506 -- It seems likely that many of these cases can be avoided,
5507 -- but right now, the front end makes direct references to the
5508 -- bounds (e.g. in generating a length check), and if we do
5509 -- not make an actual subtype, we end up getting a direct
5510 -- reference to a discriminant, which will not do.
5512 elsif Full_Analysis
then
5514 Build_Actual_Subtype_Of_Component
(Etype
(Comp
), N
);
5515 Insert_Action
(N
, Act_Decl
);
5517 if No
(Act_Decl
) then
5518 Set_Etype
(N
, Etype
(Comp
));
5521 -- If discriminants were present in the component
5522 -- declaration, they have been replaced by the
5523 -- actual values in the prefix object.
5526 Subt
: constant Entity_Id
:=
5527 Defining_Identifier
(Act_Decl
);
5529 Set_Etype
(Subt
, Base_Type
(Etype
(Comp
)));
5530 Set_Etype
(N
, Subt
);
5534 -- If Etype (Comp) is an access type whose designated subtype
5535 -- is constrained by an unprefixed discriminant value,
5536 -- then ideally we would build a new subtype with an
5537 -- appropriately prefixed discriminant value and use that
5538 -- instead, as is done in Build_Actual_Subtype_Of_Component.
5539 -- That turns out to be difficult in this context (with
5540 -- Full_Analysis = False, we could be processing a selected
5541 -- component that occurs in a Postcondition pragma;
5542 -- PPC pragmas are odd because they can contain references
5543 -- to formal parameters that occur outside the subprogram).
5544 -- So instead we punt on building a new subtype and we
5545 -- use the base type instead. This might introduce
5546 -- correctness problems if N were the target of an
5547 -- assignment (because a required check might be omitted);
5548 -- fortunately, that's impossible because a reference to the
5549 -- current instance of a type does not denote a variable view
5550 -- when the reference occurs within an aspect_specification.
5551 -- GNAT's Precondition and Postcondition pragmas follow the
5552 -- same rules as a Pre or Post aspect_specification.
5554 elsif Has_Discriminant_Dependent_Constraint
(Comp
)
5555 and then Ekind
(Etype
(Comp
)) = E_Access_Subtype
5556 and then Constraint_Has_Unprefixed_Discriminant_Reference
5557 (Designated_Type
(Etype
(Comp
)))
5559 Set_Etype
(N
, Base_Type
(Etype
(Comp
)));
5561 -- If Full_Analysis not enabled, just set the Etype
5564 Set_Etype
(N
, Etype
(Comp
));
5567 Check_Implicit_Dereference
(N
, Etype
(N
));
5571 -- If the prefix is a private extension, check only the visible
5572 -- components of the partial view. This must include the tag,
5573 -- which can appear in expanded code in a tag check.
5575 if Ekind
(Type_To_Use
) = E_Record_Type_With_Private
5576 and then Chars
(Selector_Name
(N
)) /= Name_uTag
5578 exit when Comp
= Last_Entity
(Type_To_Use
);
5584 -- Ada 2005 (AI-252): The selected component can be interpreted as
5585 -- a prefixed view of a subprogram. Depending on the context, this is
5586 -- either a name that can appear in a renaming declaration, or part
5587 -- of an enclosing call given in prefix form.
5589 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
5590 -- selected component should resolve to a name.
5592 -- Extension feature: Also support calls with prefixed views for
5593 -- untagged record types.
5595 if Ada_Version
>= Ada_2005
5596 and then (Is_Tagged_Type
(Prefix_Type
)
5597 or else Core_Extensions_Allowed
)
5598 and then not Is_Concurrent_Type
(Prefix_Type
)
5600 if Nkind
(Parent
(N
)) = N_Generic_Association
5601 or else Nkind
(Parent
(N
)) = N_Requeue_Statement
5602 or else Nkind
(Parent
(N
)) = N_Subprogram_Renaming_Declaration
5604 if Find_Primitive_Operation
(N
) then
5608 elsif Try_By_Protected_Procedure_Prefixed_View
then
5611 -- If the prefix type is the actual for a formal derived type,
5612 -- or a derived type thereof, the component inherited from the
5613 -- generic parent may not be visible in the actual, but the
5614 -- selected component is legal. This case must be handled before
5615 -- trying the object.operation notation to avoid reporting
5616 -- spurious errors, but must be skipped when Is_Prefixed_Call has
5617 -- been set (because that means that this node was resolved to an
5618 -- Object.Operation call when the generic unit was analyzed).
5621 and then not Is_Prefixed_Call
(N
)
5622 and then Is_Tagged_Type
(Prefix_Type
)
5623 and then Try_Selected_Component_In_Instance
(Type_To_Use
)
5627 elsif Try_Object_Operation
(N
) then
5631 -- If the transformation fails, it will be necessary to redo the
5632 -- analysis with all errors enabled, to indicate candidate
5633 -- interpretations and reasons for each failure ???
5637 elsif Is_Private_Type
(Prefix_Type
) then
5639 -- Allow access only to discriminants of the type. If the type has
5640 -- no full view, gigi uses the parent type for the components, so we
5641 -- do the same here.
5643 if No
(Full_View
(Prefix_Type
)) then
5644 Type_To_Use
:= Root_Type
(Base_Type
(Prefix_Type
));
5645 Comp
:= First_Entity
(Type_To_Use
);
5648 while Present
(Comp
) loop
5649 if Chars
(Comp
) = Chars
(Sel
) then
5650 if Ekind
(Comp
) = E_Discriminant
then
5651 Set_Entity_With_Checks
(Sel
, Comp
);
5652 Generate_Reference
(Comp
, Sel
);
5654 Set_Etype
(Sel
, Etype
(Comp
));
5655 Set_Etype
(N
, Etype
(Comp
));
5656 Check_Implicit_Dereference
(N
, Etype
(N
));
5658 if Is_Generic_Type
(Prefix_Type
)
5659 or else Is_Generic_Type
(Root_Type
(Prefix_Type
))
5661 Set_Original_Discriminant
(Sel
, Comp
);
5664 -- Before declaring an error, check whether this is tagged
5665 -- private type and a call to a primitive operation.
5667 elsif Ada_Version
>= Ada_2005
5668 and then Is_Tagged_Type
(Prefix_Type
)
5669 and then Try_Object_Operation
(N
)
5674 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
5675 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
5676 Set_Entity
(Sel
, Any_Id
);
5677 Set_Etype
(N
, Any_Type
);
5686 -- Extension feature: Also support calls with prefixed views for
5687 -- untagged private types.
5689 if Core_Extensions_Allowed
then
5690 if Try_Object_Operation
(N
) then
5695 elsif Is_Concurrent_Type
(Prefix_Type
) then
5697 -- Find visible operation with given name. For a protected type,
5698 -- the possible candidates are discriminants, entries or protected
5699 -- subprograms. For a task type, the set can only include entries or
5700 -- discriminants if the task type is not an enclosing scope. If it
5701 -- is an enclosing scope (e.g. in an inner task) then all entities
5702 -- are visible, but the prefix must denote the enclosing scope, i.e.
5703 -- can only be a direct name or an expanded name.
5705 Set_Etype
(Sel
, Any_Type
);
5706 Hidden_Comp
:= Empty
;
5707 In_Scope
:= In_Open_Scopes
(Prefix_Type
);
5708 Is_Private_Op
:= False;
5710 while Present
(Comp
) loop
5712 -- Do not examine private operations of the type if not within
5715 if Chars
(Comp
) = Chars
(Sel
) then
5716 if Is_Overloadable
(Comp
)
5718 or else Comp
/= First_Private_Entity
(Type_To_Use
))
5720 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
5721 if Comp
= First_Private_Entity
(Type_To_Use
) then
5722 Is_Private_Op
:= True;
5725 -- If the prefix is tagged, the correct interpretation may
5726 -- lie in the primitive or class-wide operations of the
5727 -- type. Perform a simple conformance check to determine
5728 -- whether Try_Object_Operation should be invoked even if
5729 -- a visible entity is found.
5731 if Is_Tagged_Type
(Prefix_Type
)
5732 and then Nkind
(Parent
(N
)) in N_Function_Call
5733 | N_Indexed_Component
5734 | N_Procedure_Call_Statement
5735 and then Has_Mode_Conformant_Spec
(Comp
)
5737 Has_Candidate
:= True;
5740 -- Note: a selected component may not denote a component of a
5741 -- protected type (4.1.3(7)).
5743 elsif Ekind
(Comp
) in E_Discriminant | E_Entry_Family
5745 and then not Is_Protected_Type
(Prefix_Type
)
5746 and then Is_Entity_Name
(Name
))
5748 Set_Entity_With_Checks
(Sel
, Comp
);
5749 Generate_Reference
(Comp
, Sel
);
5751 -- The selector is not overloadable, so we have a candidate
5754 Has_Candidate
:= True;
5757 if Ekind
(Comp
) = E_Component
then
5758 Hidden_Comp
:= Comp
;
5764 Set_Etype
(Sel
, Etype
(Comp
));
5765 Set_Etype
(N
, Etype
(Comp
));
5767 if Ekind
(Comp
) = E_Discriminant
then
5768 Set_Original_Discriminant
(Sel
, Comp
);
5773 if Comp
= First_Private_Entity
(Type_To_Use
) then
5774 if Etype
(Sel
) /= Any_Type
then
5776 -- If the first private entity's name matches, then treat
5777 -- it as a private op: needed for the error check for
5778 -- illegal selection of private entities further below.
5780 if Chars
(Comp
) = Chars
(Sel
) then
5781 Is_Private_Op
:= True;
5784 -- We have a candidate, so exit the loop
5789 -- Indicate that subsequent operations are private,
5790 -- for better error reporting.
5792 Is_Private_Op
:= True;
5796 -- Do not examine private operations if not within scope of
5797 -- the synchronized type.
5799 exit when not In_Scope
5801 Comp
= First_Private_Entity
(Base_Type
(Prefix_Type
));
5805 -- If the scope is a current instance, the prefix cannot be an
5806 -- expression of the same type, unless the selector designates a
5807 -- public operation (otherwise that would represent an attempt to
5808 -- reach an internal entity of another synchronized object).
5810 -- This is legal if prefix is an access to such type and there is
5811 -- a dereference, or is a component with a dereferenced prefix.
5812 -- It is also legal if the prefix is a component of a task type,
5813 -- and the selector is one of the task operations.
5816 and then not Is_Entity_Name
(Name
)
5817 and then not Has_Dereference
(Name
)
5819 if Is_Task_Type
(Prefix_Type
)
5820 and then Present
(Entity
(Sel
))
5821 and then Is_Entry
(Entity
(Sel
))
5825 elsif Is_Protected_Type
(Prefix_Type
)
5826 and then Is_Overloadable
(Entity
(Sel
))
5827 and then not Is_Private_Op
5833 ("invalid reference to internal operation of some object of "
5834 & "type &", N
, Type_To_Use
);
5835 Set_Entity
(Sel
, Any_Id
);
5836 Set_Etype
(Sel
, Any_Type
);
5840 -- Another special case: the prefix may denote an object of the type
5841 -- (but not a type) in which case this is an external call and the
5842 -- operation must be public.
5845 and then Is_Object_Reference
(Original_Node
(Prefix
(N
)))
5846 and then Comes_From_Source
(N
)
5847 and then Is_Private_Op
5849 if Present
(Hidden_Comp
) then
5851 ("invalid reference to private component of object of type "
5852 & "&", N
, Type_To_Use
);
5856 ("invalid reference to private operation of some object of "
5857 & "type &", N
, Type_To_Use
);
5860 Set_Entity
(Sel
, Any_Id
);
5861 Set_Etype
(Sel
, Any_Type
);
5865 -- If there is no visible entity with the given name or none of the
5866 -- visible entities are plausible interpretations, check whether
5867 -- there is some other primitive operation with that name.
5869 if Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Prefix_Type
) then
5870 if (Etype
(N
) = Any_Type
5871 or else not Has_Candidate
)
5872 and then Try_Object_Operation
(N
)
5876 -- If the context is not syntactically a procedure call, it
5877 -- may be a call to a primitive function declared outside of
5878 -- the synchronized type.
5880 -- If the context is a procedure call, there might still be
5881 -- an overloading between an entry and a primitive procedure
5882 -- declared outside of the synchronized type, called in prefix
5883 -- notation. This is harder to disambiguate because in one case
5884 -- the controlling formal is implicit ???
5886 elsif Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
5887 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
5888 and then Try_Object_Operation
(N
)
5893 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
5894 -- entry or procedure of a tagged concurrent type we must check
5895 -- if there are class-wide subprograms covering the primitive. If
5896 -- true then Try_Object_Operation reports the error.
5899 and then Is_Concurrent_Type
(Prefix_Type
)
5900 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
5902 -- Duplicate the call. This is required to avoid problems with
5903 -- the tree transformations performed by Try_Object_Operation.
5904 -- Set properly the parent of the copied call, because it is
5905 -- about to be reanalyzed.
5908 Par
: constant Node_Id
:= New_Copy_Tree
(Parent
(N
));
5911 Set_Parent
(Par
, Parent
(Parent
(N
)));
5913 if Try_Object_Operation
5914 (Sinfo
.Nodes
.Name
(Par
), CW_Test_Only
=> True)
5922 if Etype
(N
) = Any_Type
and then Is_Protected_Type
(Prefix_Type
) then
5924 -- Case of a prefix of a protected type: selector might denote
5925 -- an invisible private component.
5927 Comp
:= First_Private_Entity
(Base_Type
(Prefix_Type
));
5928 while Present
(Comp
) and then Chars
(Comp
) /= Chars
(Sel
) loop
5932 if Present
(Comp
) then
5933 if Is_Single_Concurrent_Object
then
5934 Error_Msg_Node_2
:= Entity
(Name
);
5935 Error_Msg_NE
("invisible selector& for &", N
, Sel
);
5938 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
5939 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
5945 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
5947 -- Extension feature: Also support calls with prefixed views for
5950 elsif Core_Extensions_Allowed
5951 and then Try_Object_Operation
(N
)
5958 Error_Msg_NE
("invalid prefix in selected component&", N
, Sel
);
5961 -- If N still has no type, the component is not defined in the prefix
5963 if Etype
(N
) = Any_Type
then
5965 if Is_Single_Concurrent_Object
then
5966 Error_Msg_Node_2
:= Entity
(Name
);
5967 Error_Msg_NE
("no selector& for&", N
, Sel
);
5969 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
5971 -- If this is a derived formal type, the parent may have different
5972 -- visibility at this point. Try for an inherited component before
5973 -- reporting an error.
5975 elsif Is_Generic_Type
(Prefix_Type
)
5976 and then Ekind
(Prefix_Type
) = E_Record_Type_With_Private
5977 and then Prefix_Type
/= Etype
(Prefix_Type
)
5978 and then Is_Record_Type
(Etype
(Prefix_Type
))
5980 Set_Etype
(Prefix
(N
), Etype
(Prefix_Type
));
5981 Analyze_Selected_Component
(N
);
5984 -- Similarly, if this is the actual for a formal derived type, or
5985 -- a derived type thereof, the component inherited from the generic
5986 -- parent may not be visible in the actual, but the selected
5987 -- component is legal.
5989 elsif In_Instance
and then Is_Tagged_Type
(Prefix_Type
) then
5991 -- Climb up the derivation chain of the generic parent type until
5992 -- we find the proper ancestor type.
5994 if Try_Selected_Component_In_Instance
(Type_To_Use
) then
5997 -- The search above must have eventually succeeded, since the
5998 -- selected component was legal in the generic.
6001 raise Program_Error
;
6004 -- Component not found, specialize error message when appropriate
6007 if Ekind
(Prefix_Type
) = E_Record_Subtype
then
6009 -- Check whether this is a component of the base type which
6010 -- is absent from a statically constrained subtype. This will
6011 -- raise constraint error at run time, but is not a compile-
6012 -- time error. When the selector is illegal for base type as
6013 -- well fall through and generate a compilation error anyway.
6015 Comp
:= First_Component
(Base_Type
(Prefix_Type
));
6016 while Present
(Comp
) loop
6017 if Chars
(Comp
) = Chars
(Sel
)
6018 and then Is_Visible_Component
(Comp
, Sel
)
6020 Set_Entity_With_Checks
(Sel
, Comp
);
6021 Generate_Reference
(Comp
, Sel
);
6022 Set_Etype
(Sel
, Etype
(Comp
));
6023 Set_Etype
(N
, Etype
(Comp
));
6025 -- Emit appropriate message. The node will be replaced
6026 -- by an appropriate raise statement.
6028 -- Note that in GNATprove mode, as with all calls to
6029 -- apply a compile time constraint error, this will be
6030 -- made into an error to simplify the processing of the
6031 -- formal verification backend.
6033 Apply_Compile_Time_Constraint_Error
6034 (N
, "component not present in }??",
6035 CE_Discriminant_Check_Failed
,
6038 GNATprove_Mode
or not In_Instance_Not_Visible
);
6042 Next_Component
(Comp
);
6047 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
6048 Error_Msg_NE
("no selector& for}", N
, Sel
);
6050 -- Add information in the case of an incomplete prefix
6052 if Is_Incomplete_Type
(Type_To_Use
) then
6054 Inc
: constant Entity_Id
:= First_Subtype
(Type_To_Use
);
6057 if From_Limited_With
(Scope
(Type_To_Use
)) then
6059 ("\limited view of& has no components", N
, Inc
);
6063 ("\premature usage of incomplete type&", N
, Inc
);
6065 if Nkind
(Parent
(Inc
)) =
6066 N_Incomplete_Type_Declaration
6068 -- Record location of premature use in entity so that
6069 -- a continuation message is generated when the
6070 -- completion is seen.
6072 Set_Premature_Use
(Parent
(Inc
), N
);
6078 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
6081 Set_Entity
(Sel
, Any_Id
);
6082 Set_Etype
(Sel
, Any_Type
);
6084 end Analyze_Selected_Component
;
6086 ---------------------------
6087 -- Analyze_Short_Circuit --
6088 ---------------------------
6090 procedure Analyze_Short_Circuit
(N
: Node_Id
) is
6091 L
: constant Node_Id
:= Left_Opnd
(N
);
6092 R
: constant Node_Id
:= Right_Opnd
(N
);
6097 Set_Etype
(N
, Any_Type
);
6098 Analyze_Expression
(L
);
6099 Analyze_Expression
(R
);
6101 if not Is_Overloaded
(L
) then
6102 if Root_Type
(Etype
(L
)) = Standard_Boolean
6103 and then Has_Compatible_Type
(R
, Etype
(L
))
6105 Add_One_Interp
(N
, Etype
(L
), Etype
(L
));
6109 Get_First_Interp
(L
, Ind
, It
);
6110 while Present
(It
.Typ
) loop
6111 if Root_Type
(It
.Typ
) = Standard_Boolean
6112 and then Has_Compatible_Type
(R
, It
.Typ
)
6114 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
6117 Get_Next_Interp
(Ind
, It
);
6121 -- Here we have failed to find an interpretation. Clearly we know that
6122 -- it is not the case that both operands can have an interpretation of
6123 -- Boolean, but this is by far the most likely intended interpretation.
6124 -- So we simply resolve both operands as Booleans, and at least one of
6125 -- these resolutions will generate an error message, and we do not need
6126 -- to give another error message on the short circuit operation itself.
6128 if Etype
(N
) = Any_Type
then
6129 Resolve
(L
, Standard_Boolean
);
6130 Resolve
(R
, Standard_Boolean
);
6131 Set_Etype
(N
, Standard_Boolean
);
6135 if Nkind
(L
) not in N_Short_Circuit | N_Op_And | N_Op_Or | N_Op_Xor
6137 Check_Xtra_Parens_Precedence
(L
);
6140 if Nkind
(R
) not in N_Short_Circuit | N_Op_And | N_Op_Or | N_Op_Xor
6142 Check_Xtra_Parens_Precedence
(R
);
6145 end Analyze_Short_Circuit
;
6151 procedure Analyze_Slice
(N
: Node_Id
) is
6152 D
: constant Node_Id
:= Discrete_Range
(N
);
6153 P
: constant Node_Id
:= Prefix
(N
);
6154 Array_Type
: Entity_Id
;
6155 Index_Type
: Entity_Id
;
6157 procedure Analyze_Overloaded_Slice
;
6158 -- If the prefix is overloaded, select those interpretations that
6159 -- yield a one-dimensional array type.
6161 ------------------------------
6162 -- Analyze_Overloaded_Slice --
6163 ------------------------------
6165 procedure Analyze_Overloaded_Slice
is
6171 Set_Etype
(N
, Any_Type
);
6173 Get_First_Interp
(P
, I
, It
);
6174 while Present
(It
.Nam
) loop
6177 if Is_Access_Type
(Typ
) then
6178 Typ
:= Designated_Type
(Typ
);
6180 (Warn_On_Dereference
, "?d?implicit dereference", N
);
6183 if Is_Array_Type
(Typ
)
6184 and then Number_Dimensions
(Typ
) = 1
6185 and then Has_Compatible_Type
(D
, Etype
(First_Index
(Typ
)))
6187 Add_One_Interp
(N
, Typ
, Typ
);
6190 Get_Next_Interp
(I
, It
);
6193 if Etype
(N
) = Any_Type
then
6194 Error_Msg_N
("expect array type in prefix of slice", N
);
6196 end Analyze_Overloaded_Slice
;
6198 -- Start of processing for Analyze_Slice
6204 if Is_Overloaded
(P
) then
6205 Analyze_Overloaded_Slice
;
6208 Array_Type
:= Etype
(P
);
6209 Set_Etype
(N
, Any_Type
);
6211 if Is_Access_Type
(Array_Type
) then
6212 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
6213 Array_Type
:= Implicitly_Designated_Type
(Array_Type
);
6216 if not Is_Array_Type
(Array_Type
) then
6217 Wrong_Type
(P
, Any_Array
);
6219 elsif Number_Dimensions
(Array_Type
) > 1 then
6221 ("type is not one-dimensional array in slice prefix", N
);
6224 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
6225 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
6227 Index_Type
:= Etype
(First_Index
(Array_Type
));
6230 if not Has_Compatible_Type
(D
, Index_Type
) then
6231 Wrong_Type
(D
, Index_Type
);
6233 Set_Etype
(N
, Array_Type
);
6239 -----------------------------
6240 -- Analyze_Type_Conversion --
6241 -----------------------------
6243 procedure Analyze_Type_Conversion
(N
: Node_Id
) is
6244 Expr
: constant Node_Id
:= Expression
(N
);
6245 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
6250 -- If Conversion_OK is set, then the Etype is already set, and the only
6251 -- processing required is to analyze the expression. This is used to
6252 -- construct certain "illegal" conversions which are not allowed by Ada
6253 -- semantics, but can be handled by Gigi, see Sinfo for further details.
6255 if Conversion_OK
(N
) then
6260 -- Otherwise full type analysis is required, as well as some semantic
6261 -- checks to make sure the argument of the conversion is appropriate.
6264 Typ
:= Entity
(Mark
);
6267 Analyze_Expression
(Expr
);
6269 Check_Fully_Declared
(Typ
, N
);
6270 Validate_Remote_Type_Type_Conversion
(N
);
6272 -- Only remaining step is validity checks on the argument. These
6273 -- are skipped if the conversion does not come from the source.
6275 if not Comes_From_Source
(N
) then
6278 -- If there was an error in a generic unit, no need to replicate the
6279 -- error message. Conversely, constant-folding in the generic may
6280 -- transform the argument of a conversion into a string literal, which
6281 -- is legal. Therefore the following tests are not performed in an
6282 -- instance. The same applies to an inlined body.
6284 elsif In_Instance
or In_Inlined_Body
then
6287 elsif Nkind
(Expr
) = N_Null
then
6288 Error_Msg_N
("argument of conversion cannot be null", N
);
6289 Error_Msg_N
("\use qualified expression instead", N
);
6290 Set_Etype
(N
, Any_Type
);
6292 elsif Nkind
(Expr
) = N_Aggregate
then
6293 Error_Msg_N
("argument of conversion cannot be aggregate", N
);
6294 Error_Msg_N
("\use qualified expression instead", N
);
6296 elsif Nkind
(Expr
) = N_Allocator
then
6297 Error_Msg_N
("argument of conversion cannot be allocator", N
);
6298 Error_Msg_N
("\use qualified expression instead", N
);
6300 elsif Nkind
(Expr
) = N_String_Literal
then
6301 Error_Msg_N
("argument of conversion cannot be string literal", N
);
6302 Error_Msg_N
("\use qualified expression instead", N
);
6304 elsif Nkind
(Expr
) = N_Character_Literal
then
6305 if Ada_Version
= Ada_83
then
6306 Resolve
(Expr
, Typ
);
6309 ("argument of conversion cannot be character literal", N
);
6310 Error_Msg_N
("\use qualified expression instead", N
);
6313 elsif Nkind
(Expr
) = N_Attribute_Reference
6314 and then Attribute_Name
(Expr
) in Name_Access
6315 | Name_Unchecked_Access
6316 | Name_Unrestricted_Access
6319 ("argument of conversion cannot be access attribute", N
);
6320 Error_Msg_N
("\use qualified expression instead", N
);
6323 -- A formal parameter of a specific tagged type whose related subprogram
6324 -- is subject to pragma Extensions_Visible with value "False" cannot
6325 -- appear in a class-wide conversion (SPARK RM 6.1.7(3)). Do not check
6326 -- internally generated expressions.
6328 if Is_Class_Wide_Type
(Typ
)
6329 and then Comes_From_Source
(Expr
)
6330 and then Is_EVF_Expression
(Expr
)
6333 ("formal parameter cannot be converted to class-wide type when "
6334 & "Extensions_Visible is False", Expr
);
6336 end Analyze_Type_Conversion
;
6338 ----------------------
6339 -- Analyze_Unary_Op --
6340 ----------------------
6342 procedure Analyze_Unary_Op
(N
: Node_Id
) is
6343 R
: constant Node_Id
:= Right_Opnd
(N
);
6348 Set_Etype
(N
, Any_Type
);
6349 Candidate_Type
:= Empty
;
6351 Analyze_Expression
(R
);
6353 -- If the entity is already set, the node is the instantiation of a
6354 -- generic node with a non-local reference, or was manufactured by a
6355 -- call to Make_Op_xxx. In either case the entity is known to be valid,
6356 -- and we do not need to collect interpretations, instead we just get
6357 -- the single possible interpretation.
6359 if Present
(Entity
(N
)) then
6360 Op_Id
:= Entity
(N
);
6362 if Ekind
(Op_Id
) = E_Operator
then
6363 Find_Unary_Types
(R
, Op_Id
, N
);
6365 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
6369 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
6370 while Present
(Op_Id
) loop
6371 if Ekind
(Op_Id
) = E_Operator
then
6372 if No
(Next_Entity
(First_Entity
(Op_Id
))) then
6373 Find_Unary_Types
(R
, Op_Id
, N
);
6376 elsif Is_Overloadable
(Op_Id
) then
6377 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
6380 Op_Id
:= Homonym
(Op_Id
);
6385 end Analyze_Unary_Op
;
6387 ----------------------------------
6388 -- Analyze_Unchecked_Expression --
6389 ----------------------------------
6391 procedure Analyze_Unchecked_Expression
(N
: Node_Id
) is
6392 Expr
: constant Node_Id
:= Expression
(N
);
6395 Analyze
(Expr
, Suppress
=> All_Checks
);
6396 Set_Etype
(N
, Etype
(Expr
));
6397 Save_Interps
(Expr
, N
);
6398 end Analyze_Unchecked_Expression
;
6400 ---------------------------------------
6401 -- Analyze_Unchecked_Type_Conversion --
6402 ---------------------------------------
6404 procedure Analyze_Unchecked_Type_Conversion
(N
: Node_Id
) is
6405 Expr
: constant Node_Id
:= Expression
(N
);
6406 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
6410 Set_Etype
(N
, Entity
(Mark
));
6411 Analyze_Expression
(Expr
);
6412 end Analyze_Unchecked_Type_Conversion
;
6414 ------------------------------------
6415 -- Analyze_User_Defined_Binary_Op --
6416 ------------------------------------
6418 procedure Analyze_User_Defined_Binary_Op
6420 Op_Id
: Entity_Id
) is
6423 F1
: constant Entity_Id
:= First_Formal
(Op_Id
);
6424 F2
: constant Entity_Id
:= Next_Formal
(F1
);
6427 -- Verify that Op_Id is a visible binary function. Note that since
6428 -- we know Op_Id is overloaded, potentially use visible means use
6429 -- visible for sure (RM 9.4(11)). Be prepared for previous errors.
6431 if Ekind
(Op_Id
) = E_Function
6432 and then Present
(F2
)
6433 and then (Is_Immediately_Visible
(Op_Id
)
6434 or else Is_Potentially_Use_Visible
(Op_Id
))
6435 and then (Has_Compatible_Type
(Left_Opnd
(N
), Etype
(F1
))
6436 or else Etype
(F1
) = Any_Type
)
6437 and then (Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F2
))
6438 or else Etype
(F2
) = Any_Type
)
6440 Add_One_Interp
(N
, Op_Id
, Base_Type
(Etype
(Op_Id
)));
6442 -- If the operands are overloaded, indicate that the current
6443 -- type is a viable candidate. This is redundant in most cases,
6444 -- but for equality and comparison operators where the context
6445 -- does not impose a type on the operands, setting the proper
6446 -- type is necessary to avoid subsequent ambiguities during
6447 -- resolution, when both user-defined and predefined operators
6448 -- may be candidates.
6450 if Is_Overloaded
(Left_Opnd
(N
)) then
6451 Set_Etype
(Left_Opnd
(N
), Etype
(F1
));
6454 if Is_Overloaded
(Right_Opnd
(N
)) then
6455 Set_Etype
(Right_Opnd
(N
), Etype
(F2
));
6458 if Debug_Flag_E
then
6459 Write_Str
("user defined operator ");
6460 Write_Name
(Chars
(Op_Id
));
6461 Write_Str
(" on node ");
6462 Write_Int
(Int
(N
));
6467 end Analyze_User_Defined_Binary_Op
;
6469 -----------------------------------
6470 -- Analyze_User_Defined_Unary_Op --
6471 -----------------------------------
6473 procedure Analyze_User_Defined_Unary_Op
6478 -- Only do analysis if the operator Comes_From_Source, since otherwise
6479 -- the operator was generated by the expander, and all such operators
6480 -- always refer to the operators in package Standard.
6482 if Comes_From_Source
(N
) then
6484 F
: constant Entity_Id
:= First_Formal
(Op_Id
);
6487 -- Verify that Op_Id is a visible unary function. Note that since
6488 -- we know Op_Id is overloaded, potentially use visible means use
6489 -- visible for sure (RM 9.4(11)).
6491 if Ekind
(Op_Id
) = E_Function
6492 and then No
(Next_Formal
(F
))
6493 and then (Is_Immediately_Visible
(Op_Id
)
6494 or else Is_Potentially_Use_Visible
(Op_Id
))
6495 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F
))
6497 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
6501 end Analyze_User_Defined_Unary_Op
;
6503 ---------------------------
6504 -- Check_Arithmetic_Pair --
6505 ---------------------------
6507 procedure Check_Arithmetic_Pair
6508 (T1
, T2
: Entity_Id
;
6512 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
6514 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean;
6515 -- Check whether the fixed-point type Typ has a user-defined operator
6516 -- (multiplication or division) that should hide the corresponding
6517 -- predefined operator. Used to implement Ada 2005 AI-264, to make
6518 -- such operators more visible and therefore useful.
6520 -- If the name of the operation is an expanded name with prefix
6521 -- Standard, the predefined universal fixed operator is available,
6522 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
6528 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean is
6529 Bas
: constant Entity_Id
:= Base_Type
(Typ
);
6535 -- If the universal_fixed operation is given explicitly the rule
6536 -- concerning primitive operations of the type do not apply.
6538 if Nkind
(N
) = N_Function_Call
6539 and then Nkind
(Name
(N
)) = N_Expanded_Name
6540 and then Entity
(Prefix
(Name
(N
))) = Standard_Standard
6545 -- The operation is treated as primitive if it is declared in the
6546 -- same scope as the type, and therefore on the same entity chain.
6548 Ent
:= Next_Entity
(Typ
);
6549 while Present
(Ent
) loop
6550 if Chars
(Ent
) = Chars
(Op
) then
6551 F1
:= First_Formal
(Ent
);
6552 F2
:= Next_Formal
(F1
);
6554 -- The operation counts as primitive if either operand or
6555 -- result are of the given base type, and both operands are
6556 -- fixed point types.
6558 if (Base_Type
(Etype
(F1
)) = Bas
6559 and then Is_Fixed_Point_Type
(Etype
(F2
)))
6562 (Base_Type
(Etype
(F2
)) = Bas
6563 and then Is_Fixed_Point_Type
(Etype
(F1
)))
6566 (Base_Type
(Etype
(Ent
)) = Bas
6567 and then Is_Fixed_Point_Type
(Etype
(F1
))
6568 and then Is_Fixed_Point_Type
(Etype
(F2
)))
6580 -- Start of processing for Check_Arithmetic_Pair
6583 if Op_Name
in Name_Op_Add | Name_Op_Subtract
then
6584 if Is_Numeric_Type
(T1
)
6585 and then Is_Numeric_Type
(T2
)
6586 and then (Covers
(T1
=> T1
, T2
=> T2
)
6588 Covers
(T1
=> T2
, T2
=> T1
))
6590 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
6593 elsif Op_Name
in Name_Op_Multiply | Name_Op_Divide
then
6594 if Is_Fixed_Point_Type
(T1
)
6595 and then (Is_Fixed_Point_Type
(T2
) or else T2
= Universal_Real
)
6597 -- Add one interpretation with universal fixed result
6599 if not Has_Fixed_Op
(T1
, Op_Id
)
6600 or else Nkind
(Parent
(N
)) = N_Type_Conversion
6602 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
6605 elsif Is_Fixed_Point_Type
(T2
)
6606 and then T1
= Universal_Real
6608 (not Has_Fixed_Op
(T1
, Op_Id
)
6609 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
6611 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
6613 elsif Is_Numeric_Type
(T1
)
6614 and then Is_Numeric_Type
(T2
)
6615 and then (Covers
(T1
=> T1
, T2
=> T2
)
6617 Covers
(T1
=> T2
, T2
=> T1
))
6619 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
6621 elsif Is_Fixed_Point_Type
(T1
)
6622 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
6623 or else T2
= Universal_Integer
)
6625 Add_One_Interp
(N
, Op_Id
, T1
);
6627 elsif T2
= Universal_Real
6628 and then Base_Type
(T1
) = Base_Type
(Standard_Integer
)
6629 and then Op_Name
= Name_Op_Multiply
6631 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
6633 elsif T1
= Universal_Real
6634 and then Base_Type
(T2
) = Base_Type
(Standard_Integer
)
6636 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
6638 elsif Is_Fixed_Point_Type
(T2
)
6639 and then (Base_Type
(T1
) = Base_Type
(Standard_Integer
)
6640 or else T1
= Universal_Integer
)
6641 and then Op_Name
= Name_Op_Multiply
6643 Add_One_Interp
(N
, Op_Id
, T2
);
6645 elsif T1
= Universal_Real
and then T2
= Universal_Integer
then
6646 Add_One_Interp
(N
, Op_Id
, T1
);
6648 elsif T2
= Universal_Real
6649 and then T1
= Universal_Integer
6650 and then Op_Name
= Name_Op_Multiply
6652 Add_One_Interp
(N
, Op_Id
, T2
);
6655 elsif Op_Name
= Name_Op_Mod
or else Op_Name
= Name_Op_Rem
then
6657 if Is_Integer_Type
(T1
)
6658 and then (Covers
(T1
=> T1
, T2
=> T2
)
6660 Covers
(T1
=> T2
, T2
=> T1
))
6662 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
6665 elsif Op_Name
= Name_Op_Expon
then
6666 if Is_Numeric_Type
(T1
)
6667 and then not Is_Fixed_Point_Type
(T1
)
6668 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
6669 or else T2
= Universal_Integer
)
6671 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
6674 else pragma Assert
(Nkind
(N
) in N_Op_Shift
);
6676 -- If not one of the predefined operators, the node may be one
6677 -- of the intrinsic functions. Its kind is always specific, and
6678 -- we can use it directly, rather than the name of the operation.
6680 if Is_Integer_Type
(T1
)
6681 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
6682 or else T2
= Universal_Integer
)
6684 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
6687 end Check_Arithmetic_Pair
;
6689 -------------------------------
6690 -- Check_Misspelled_Selector --
6691 -------------------------------
6693 procedure Check_Misspelled_Selector
6694 (Prefix
: Entity_Id
;
6697 Max_Suggestions
: constant := 2;
6698 Nr_Of_Suggestions
: Natural := 0;
6700 Suggestion_1
: Entity_Id
:= Empty
;
6701 Suggestion_2
: Entity_Id
:= Empty
;
6706 -- All the components of the prefix of selector Sel are matched against
6707 -- Sel and a count is maintained of possible misspellings. When at
6708 -- the end of the analysis there are one or two (not more) possible
6709 -- misspellings, these misspellings will be suggested as possible
6712 if not (Is_Private_Type
(Prefix
) or else Is_Record_Type
(Prefix
)) then
6714 -- Concurrent types should be handled as well ???
6719 Comp
:= First_Entity
(Prefix
);
6720 while Nr_Of_Suggestions
<= Max_Suggestions
and then Present
(Comp
) loop
6721 if Is_Visible_Component
(Comp
, Sel
) then
6722 if Is_Bad_Spelling_Of
(Chars
(Comp
), Chars
(Sel
)) then
6723 Nr_Of_Suggestions
:= Nr_Of_Suggestions
+ 1;
6725 case Nr_Of_Suggestions
is
6726 when 1 => Suggestion_1
:= Comp
;
6727 when 2 => Suggestion_2
:= Comp
;
6728 when others => null;
6736 -- Report at most two suggestions
6738 if Nr_Of_Suggestions
= 1 then
6739 Error_Msg_NE
-- CODEFIX
6740 ("\possible misspelling of&", Sel
, Suggestion_1
);
6742 elsif Nr_Of_Suggestions
= 2 then
6743 Error_Msg_Node_2
:= Suggestion_2
;
6744 Error_Msg_NE
-- CODEFIX
6745 ("\possible misspelling of& or&", Sel
, Suggestion_1
);
6747 end Check_Misspelled_Selector
;
6753 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
) is
6759 Num_Actuals
: Natural;
6760 Num_Interps
: Natural;
6761 Void_Interp_Seen
: Boolean := False;
6764 pragma Warnings
(Off
, Boolean);
6768 Actual
:= First_Actual
(N
);
6770 while Present
(Actual
) loop
6771 -- Ada 2005 (AI-50217): Post an error in case of premature
6772 -- usage of an entity from the limited view.
6774 if not Analyzed
(Etype
(Actual
))
6775 and then From_Limited_With
(Etype
(Actual
))
6776 and then Ada_Version
>= Ada_2005
6778 Error_Msg_Qual_Level
:= 1;
6780 ("missing with_clause for scope of imported type&",
6781 Actual
, Etype
(Actual
));
6782 Error_Msg_Qual_Level
:= 0;
6785 Num_Actuals
:= Num_Actuals
+ 1;
6786 Next_Actual
(Actual
);
6789 -- Before listing the possible candidates, check whether this is
6790 -- a prefix of a selected component that has been rewritten as a
6791 -- parameterless function call because there is a callable candidate
6792 -- interpretation. If there is a hidden package in the list of homonyms
6793 -- of the function name (bad programming style in any case) suggest that
6794 -- this is the intended entity.
6796 if No
(Parameter_Associations
(N
))
6797 and then Nkind
(Parent
(N
)) = N_Selected_Component
6798 and then Nkind
(Parent
(Parent
(N
))) in N_Declaration
6799 and then Is_Overloaded
(Nam
)
6805 Ent
:= Current_Entity
(Nam
);
6806 while Present
(Ent
) loop
6807 if Ekind
(Ent
) = E_Package
then
6809 ("no legal interpretations as function call,!", Nam
);
6810 Error_Msg_NE
("\package& is not visible", N
, Ent
);
6812 Rewrite
(Parent
(N
),
6813 New_Occurrence_Of
(Any_Type
, Sloc
(N
)));
6817 Ent
:= Homonym
(Ent
);
6822 -- If this is a call to an operation of a concurrent type, the failed
6823 -- interpretations have been removed from the name. Recover them now
6824 -- in order to provide full diagnostics.
6826 if Nkind
(Parent
(Nam
)) = N_Selected_Component
then
6827 Set_Entity
(Nam
, Empty
);
6828 New_Nam
:= New_Copy_Tree
(Parent
(Nam
));
6829 Set_Is_Overloaded
(New_Nam
, False);
6830 Set_Is_Overloaded
(Selector_Name
(New_Nam
), False);
6831 Set_Parent
(New_Nam
, Parent
(Parent
(Nam
)));
6832 Analyze_Selected_Component
(New_Nam
);
6833 Get_First_Interp
(Selector_Name
(New_Nam
), X
, It
);
6835 Get_First_Interp
(Nam
, X
, It
);
6838 -- If the number of actuals is 2, then remove interpretations involving
6839 -- a unary "+" operator as they might yield confusing errors downstream.
6842 and then Nkind
(Parent
(Nam
)) /= N_Selected_Component
6846 while Present
(It
.Nam
) loop
6847 if Ekind
(It
.Nam
) = E_Operator
6848 and then Chars
(It
.Nam
) = Name_Op_Add
6849 and then (No
(First_Formal
(It
.Nam
))
6850 or else No
(Next_Formal
(First_Formal
(It
.Nam
))))
6854 Num_Interps
:= Num_Interps
+ 1;
6857 Get_Next_Interp
(X
, It
);
6860 if Num_Interps
= 0 then
6861 Error_Msg_N
("!too many arguments in call to&", Nam
);
6865 Get_First_Interp
(Nam
, X
, It
);
6868 Num_Interps
:= 2; -- at least
6871 -- Analyze each candidate call again with full error reporting for each
6873 if Num_Interps
> 1 then
6874 Error_Msg_N
("!no candidate interpretations match the actuals:", Nam
);
6877 Err_Mode
:= All_Errors_Mode
;
6878 All_Errors_Mode
:= True;
6880 while Present
(It
.Nam
) loop
6881 if Etype
(It
.Nam
) = Standard_Void_Type
then
6882 Void_Interp_Seen
:= True;
6885 Analyze_One_Call
(N
, It
.Nam
, True, Success
);
6886 Get_Next_Interp
(X
, It
);
6889 if Nkind
(N
) = N_Function_Call
then
6890 Get_First_Interp
(Nam
, X
, It
);
6893 and then Ekind
(Entity
(Name
(N
))) = E_Function
6894 and then Present
(Homonym
(Entity
(Name
(N
))))
6896 -- A name may appear overloaded if it has a homonym, even if that
6897 -- homonym is non-overloadable, in which case the overload list is
6898 -- in fact empty. This specialized case deserves a special message
6899 -- if the homonym is a child package.
6902 Nam
: constant Node_Id
:= Name
(N
);
6903 H
: constant Entity_Id
:= Homonym
(Entity
(Nam
));
6906 if Ekind
(H
) = E_Package
and then Is_Child_Unit
(H
) then
6907 Error_Msg_Qual_Level
:= 2;
6908 Error_Msg_NE
("if an entity in package& is meant, ", Nam
, H
);
6909 Error_Msg_NE
("\use a fully qualified name", Nam
, H
);
6910 Error_Msg_Qual_Level
:= 0;
6915 while Present
(It
.Nam
) loop
6916 if Ekind
(It
.Nam
) in E_Function | E_Operator
then
6919 Get_Next_Interp
(X
, It
);
6923 -- If all interpretations are procedures, this deserves a more
6924 -- precise message. Ditto if this appears as the prefix of a
6925 -- selected component, which may be a lexical error.
6928 ("\context requires function call, found procedure name", Nam
);
6930 if Nkind
(Parent
(N
)) = N_Selected_Component
6931 and then N
= Prefix
(Parent
(N
))
6933 Error_Msg_N
-- CODEFIX
6934 ("\period should probably be semicolon", Parent
(N
));
6938 elsif Nkind
(N
) = N_Procedure_Call_Statement
6939 and then not Void_Interp_Seen
6941 Error_Msg_N
("\function name found in procedure call", Nam
);
6944 All_Errors_Mode
:= Err_Mode
;
6947 ---------------------------
6948 -- Find_Arithmetic_Types --
6949 ---------------------------
6951 procedure Find_Arithmetic_Types
6956 procedure Check_Right_Argument
(T
: Entity_Id
);
6957 -- Check right operand of operator
6959 --------------------------
6960 -- Check_Right_Argument --
6961 --------------------------
6963 procedure Check_Right_Argument
(T
: Entity_Id
) is
6968 if not Is_Overloaded
(R
) then
6969 Check_Arithmetic_Pair
(T
, Etype
(R
), Op_Id
, N
);
6972 Get_First_Interp
(R
, I
, It
);
6973 while Present
(It
.Typ
) loop
6974 Check_Arithmetic_Pair
(T
, It
.Typ
, Op_Id
, N
);
6975 Get_Next_Interp
(I
, It
);
6978 end Check_Right_Argument
;
6985 -- Start of processing for Find_Arithmetic_Types
6988 if not Is_Overloaded
(L
) then
6989 Check_Right_Argument
(Etype
(L
));
6992 Get_First_Interp
(L
, I
, It
);
6993 while Present
(It
.Typ
) loop
6994 Check_Right_Argument
(It
.Typ
);
6995 Get_Next_Interp
(I
, It
);
6998 end Find_Arithmetic_Types
;
7000 ------------------------
7001 -- Find_Boolean_Types --
7002 ------------------------
7004 procedure Find_Boolean_Types
7009 procedure Check_Boolean_Pair
(T1
, T2
: Entity_Id
);
7010 -- Check operand pair of operator
7012 procedure Check_Right_Argument
(T
: Entity_Id
);
7013 -- Check right operand of operator
7015 ------------------------
7016 -- Check_Boolean_Pair --
7017 ------------------------
7019 procedure Check_Boolean_Pair
(T1
, T2
: Entity_Id
) is
7023 if Valid_Boolean_Arg
(T1
)
7024 and then Valid_Boolean_Arg
(T2
)
7025 and then (Covers
(T1
=> T1
, T2
=> T2
)
7026 or else Covers
(T1
=> T2
, T2
=> T1
))
7028 T
:= Specific_Type
(T1
, T2
);
7030 if T
= Universal_Integer
then
7034 Add_One_Interp
(N
, Op_Id
, T
);
7036 end Check_Boolean_Pair
;
7038 --------------------------
7039 -- Check_Right_Argument --
7040 --------------------------
7042 procedure Check_Right_Argument
(T
: Entity_Id
) is
7047 -- Defend against previous error
7049 if Nkind
(R
) = N_Error
then
7052 elsif not Is_Overloaded
(R
) then
7053 Check_Boolean_Pair
(T
, Etype
(R
));
7056 Get_First_Interp
(R
, I
, It
);
7057 while Present
(It
.Typ
) loop
7058 Check_Boolean_Pair
(T
, It
.Typ
);
7059 Get_Next_Interp
(I
, It
);
7062 end Check_Right_Argument
;
7069 -- Start of processing for Find_Boolean_Types
7072 if not Is_Overloaded
(L
) then
7073 Check_Right_Argument
(Etype
(L
));
7076 Get_First_Interp
(L
, I
, It
);
7077 while Present
(It
.Typ
) loop
7078 Check_Right_Argument
(It
.Typ
);
7079 Get_Next_Interp
(I
, It
);
7082 end Find_Boolean_Types
;
7084 ------------------------------------
7085 -- Find_Comparison_Equality_Types --
7086 ------------------------------------
7088 -- The context of the operator plays no role in resolving the operands,
7089 -- so that if there is more than one interpretation of the operands that
7090 -- is compatible with the comparison or equality, then the operation is
7091 -- ambiguous, but this cannot be reported at this point because there is
7092 -- no guarantee that the operation will be resolved to this operator yet.
7094 procedure Find_Comparison_Equality_Types
7099 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
7100 Op_Typ
: Entity_Id
renames Standard_Boolean
;
7102 function Try_Left_Interp
(T
: Entity_Id
) return Entity_Id
;
7103 -- Try an interpretation of the left operand with type T. Return the
7104 -- type of the interpretation of the right operand making up a valid
7105 -- operand pair, or else Any_Type if the right operand is ambiguous,
7106 -- otherwise Empty if no such pair exists.
7108 function Is_Valid_Comparison_Type
(T
: Entity_Id
) return Boolean;
7109 -- Return true if T is a valid comparison type
7111 function Is_Valid_Equality_Type
7113 Anon_Access
: Boolean) return Boolean;
7114 -- Return true if T is a valid equality type
7116 function Is_Valid_Pair
(T1
, T2
: Entity_Id
) return Boolean;
7117 -- Return true if T1 and T2 constitute a valid pair of operand types for
7118 -- L and R respectively.
7120 ---------------------
7121 -- Try_Left_Interp --
7122 ---------------------
7124 function Try_Left_Interp
(T
: Entity_Id
) return Entity_Id
is
7128 Valid_I
: Interp_Index
;
7131 -- Defend against previous error
7133 if Nkind
(R
) = N_Error
then
7136 -- Loop through the interpretations of the right operand
7138 elsif not Is_Overloaded
(R
) then
7139 if Is_Valid_Pair
(T
, Etype
(R
)) then
7147 Get_First_Interp
(R
, I
, It
);
7148 while Present
(It
.Typ
) loop
7149 if Is_Valid_Pair
(T
, It
.Typ
) then
7150 -- If several interpretations are possible, disambiguate
7153 and then Base_Type
(It
.Typ
) /= Base_Type
(R_Typ
)
7155 It
:= Disambiguate
(R
, Valid_I
, I
, Any_Type
);
7157 if It
= No_Interp
then
7169 Get_Next_Interp
(I
, It
);
7172 if Present
(R_Typ
) then
7178 end Try_Left_Interp
;
7180 ------------------------------
7181 -- Is_Valid_Comparison_Type --
7182 ------------------------------
7184 function Is_Valid_Comparison_Type
(T
: Entity_Id
) return Boolean is
7186 -- The operation must be performed in a context where the operators
7187 -- of the base type are visible.
7189 if Is_Visible_Operator
(N
, Base_Type
(T
)) then
7192 -- Save candidate type for subsequent error message, if any
7195 if Valid_Comparison_Arg
(T
) then
7196 Candidate_Type
:= T
;
7202 -- Defer to the common implementation for the rest
7204 return Valid_Comparison_Arg
(T
);
7205 end Is_Valid_Comparison_Type
;
7207 ----------------------------
7208 -- Is_Valid_Equality_Type --
7209 ----------------------------
7211 function Is_Valid_Equality_Type
7213 Anon_Access
: Boolean) return Boolean
7216 -- The operation must be performed in a context where the operators
7217 -- of the base type are visible. Deal with special types used with
7218 -- access types before type resolution is done.
7220 if Ekind
(T
) = E_Access_Attribute_Type
7221 or else (Ekind
(T
) in E_Access_Subprogram_Type
7222 | E_Access_Protected_Subprogram_Type
7224 Ekind
(Designated_Type
(T
)) /= E_Subprogram_Type
)
7225 or else Is_Visible_Operator
(N
, Base_Type
(T
))
7229 -- AI95-0230: Keep restriction imposed by Ada 83 and 95, do not allow
7230 -- anonymous access types in universal_access equality operators.
7232 elsif Anon_Access
then
7233 if Ada_Version
< Ada_2005
then
7237 -- Save candidate type for subsequent error message, if any
7240 if Valid_Equality_Arg
(T
) then
7241 Candidate_Type
:= T
;
7247 -- For the use of a "/=" operator on a tagged type, several possible
7248 -- interpretations of equality need to be considered, we don't want
7249 -- the default inequality declared in Standard to be chosen, and the
7250 -- "/=" operator will be rewritten as a negation of "=" (see the end
7251 -- of Analyze_Comparison_Equality_Op). This ensures the rewriting
7252 -- occurs during analysis rather than being delayed until expansion.
7253 -- Note that, if the node is N_Op_Ne but Op_Id is Name_Op_Eq, then we
7254 -- still proceed with the interpretation, because this indicates
7255 -- the aforementioned rewriting case where the interpretation to be
7256 -- considered is actually that of the "=" operator.
7258 if Nkind
(N
) = N_Op_Ne
7259 and then Op_Name
/= Name_Op_Eq
7260 and then Is_Tagged_Type
(T
)
7264 -- Defer to the common implementation for the rest
7267 return Valid_Equality_Arg
(T
);
7269 end Is_Valid_Equality_Type
;
7275 function Is_Valid_Pair
(T1
, T2
: Entity_Id
) return Boolean is
7277 if Op_Name
= Name_Op_Eq
or else Op_Name
= Name_Op_Ne
then
7279 Anon_Access
: constant Boolean :=
7280 Is_Anonymous_Access_Type
(T1
)
7281 or else Is_Anonymous_Access_Type
(T2
);
7282 -- RM 4.5.2(9.1/2): At least one of the operands of an equality
7283 -- operator for universal_access shall be of specific anonymous
7287 if not Is_Valid_Equality_Type
(T1
, Anon_Access
)
7288 or else not Is_Valid_Equality_Type
(T2
, Anon_Access
)
7295 if not Is_Valid_Comparison_Type
(T1
)
7296 or else not Is_Valid_Comparison_Type
(T2
)
7302 return Covers
(T1
=> T1
, T2
=> T2
)
7303 or else Covers
(T1
=> T2
, T2
=> T1
)
7304 or else Is_User_Defined_Literal
(L
, T2
)
7305 or else Is_User_Defined_Literal
(R
, T1
);
7315 Valid_I
: Interp_Index
;
7317 -- Start of processing for Find_Comparison_Equality_Types
7320 -- Loop through the interpretations of the left operand
7322 if not Is_Overloaded
(L
) then
7323 T
:= Try_Left_Interp
(Etype
(L
));
7327 Add_One_Interp
(N
, Op_Id
, Op_Typ
, Find_Unique_Type
(L
, R
));
7335 Get_First_Interp
(L
, I
, It
);
7336 while Present
(It
.Typ
) loop
7337 T
:= Try_Left_Interp
(It
.Typ
);
7340 -- If several interpretations are possible, disambiguate
7343 and then Base_Type
(It
.Typ
) /= Base_Type
(L_Typ
)
7345 It
:= Disambiguate
(L
, Valid_I
, I
, Any_Type
);
7347 if It
= No_Interp
then
7361 Get_Next_Interp
(I
, It
);
7364 if Present
(L_Typ
) then
7365 Set_Etype
(L
, L_Typ
);
7366 Set_Etype
(R
, R_Typ
);
7367 Add_One_Interp
(N
, Op_Id
, Op_Typ
, Find_Unique_Type
(L
, R
));
7370 end Find_Comparison_Equality_Types
;
7372 ------------------------------
7373 -- Find_Concatenation_Types --
7374 ------------------------------
7376 procedure Find_Concatenation_Types
7381 Is_String
: constant Boolean := Nkind
(L
) = N_String_Literal
7383 Nkind
(R
) = N_String_Literal
;
7384 Op_Type
: constant Entity_Id
:= Etype
(Op_Id
);
7387 if Is_Array_Type
(Op_Type
)
7389 -- Small but very effective optimization: if at least one operand is a
7390 -- string literal, then the type of the operator must be either array
7391 -- of characters or array of strings.
7393 and then (not Is_String
7395 Is_Character_Type
(Component_Type
(Op_Type
))
7397 Is_String_Type
(Component_Type
(Op_Type
)))
7399 and then not Is_Limited_Type
(Op_Type
)
7401 and then (Has_Compatible_Type
(L
, Op_Type
)
7403 Has_Compatible_Type
(L
, Component_Type
(Op_Type
)))
7405 and then (Has_Compatible_Type
(R
, Op_Type
)
7407 Has_Compatible_Type
(R
, Component_Type
(Op_Type
)))
7409 Add_One_Interp
(N
, Op_Id
, Op_Type
);
7411 end Find_Concatenation_Types
;
7413 -------------------------
7414 -- Find_Negation_Types --
7415 -------------------------
7417 procedure Find_Negation_Types
7422 Index
: Interp_Index
;
7426 if not Is_Overloaded
(R
) then
7427 if Etype
(R
) = Universal_Integer
then
7428 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
7429 elsif Valid_Boolean_Arg
(Etype
(R
)) then
7430 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
7434 Get_First_Interp
(R
, Index
, It
);
7435 while Present
(It
.Typ
) loop
7436 if Valid_Boolean_Arg
(It
.Typ
) then
7437 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
7440 Get_Next_Interp
(Index
, It
);
7443 end Find_Negation_Types
;
7445 ------------------------------
7446 -- Find_Primitive_Operation --
7447 ------------------------------
7449 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean is
7450 Obj
: constant Node_Id
:= Prefix
(N
);
7451 Op
: constant Node_Id
:= Selector_Name
(N
);
7458 Set_Etype
(Op
, Any_Type
);
7460 if Is_Access_Type
(Etype
(Obj
)) then
7461 Typ
:= Designated_Type
(Etype
(Obj
));
7466 if Is_Class_Wide_Type
(Typ
) then
7467 Typ
:= Root_Type
(Typ
);
7470 Prims
:= Primitive_Operations
(Typ
);
7472 Prim
:= First_Elmt
(Prims
);
7473 while Present
(Prim
) loop
7474 if Chars
(Node
(Prim
)) = Chars
(Op
) then
7475 Add_One_Interp
(Op
, Node
(Prim
), Etype
(Node
(Prim
)));
7476 Set_Etype
(N
, Etype
(Node
(Prim
)));
7482 -- Now look for class-wide operations of the type or any of its
7483 -- ancestors by iterating over the homonyms of the selector.
7486 Cls_Type
: constant Entity_Id
:= Class_Wide_Type
(Typ
);
7490 Hom
:= Current_Entity
(Op
);
7491 while Present
(Hom
) loop
7492 if (Ekind
(Hom
) = E_Procedure
7494 Ekind
(Hom
) = E_Function
)
7495 and then Scope
(Hom
) = Scope
(Typ
)
7496 and then Present
(First_Formal
(Hom
))
7498 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
7500 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
7502 Ekind
(Etype
(First_Formal
(Hom
))) =
7503 E_Anonymous_Access_Type
7506 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
7509 Add_One_Interp
(Op
, Hom
, Etype
(Hom
));
7510 Set_Etype
(N
, Etype
(Hom
));
7513 Hom
:= Homonym
(Hom
);
7517 return Etype
(Op
) /= Any_Type
;
7518 end Find_Primitive_Operation
;
7520 ----------------------
7521 -- Find_Unary_Types --
7522 ----------------------
7524 procedure Find_Unary_Types
7529 Index
: Interp_Index
;
7533 if not Is_Overloaded
(R
) then
7534 if Is_Numeric_Type
(Etype
(R
)) then
7536 -- In an instance a generic actual may be a numeric type even if
7537 -- the formal in the generic unit was not. In that case, the
7538 -- predefined operator was not a possible interpretation in the
7539 -- generic, and cannot be one in the instance, unless the operator
7540 -- is an actual of an instance.
7544 not Is_Numeric_Type
(Corresponding_Generic_Type
(Etype
(R
)))
7548 Add_One_Interp
(N
, Op_Id
, Base_Type
(Etype
(R
)));
7553 Get_First_Interp
(R
, Index
, It
);
7554 while Present
(It
.Typ
) loop
7555 if Is_Numeric_Type
(It
.Typ
) then
7559 (Corresponding_Generic_Type
(Etype
(It
.Typ
)))
7564 Add_One_Interp
(N
, Op_Id
, Base_Type
(It
.Typ
));
7568 Get_Next_Interp
(Index
, It
);
7571 end Find_Unary_Types
;
7577 function Junk_Operand
(N
: Node_Id
) return Boolean is
7581 if Error_Posted
(N
) then
7585 -- Get entity to be tested
7587 if Is_Entity_Name
(N
)
7588 and then Present
(Entity
(N
))
7592 -- An odd case, a procedure name gets converted to a very peculiar
7593 -- function call, and here is where we detect this happening.
7595 elsif Nkind
(N
) = N_Function_Call
7596 and then Is_Entity_Name
(Name
(N
))
7597 and then Present
(Entity
(Name
(N
)))
7601 -- Another odd case, there are at least some cases of selected
7602 -- components where the selected component is not marked as having
7603 -- an entity, even though the selector does have an entity
7605 elsif Nkind
(N
) = N_Selected_Component
7606 and then Present
(Entity
(Selector_Name
(N
)))
7608 Enode
:= Selector_Name
(N
);
7614 -- Now test the entity we got to see if it is a bad case
7616 case Ekind
(Entity
(Enode
)) is
7619 ("package name cannot be used as operand", Enode
);
7621 when Generic_Unit_Kind
=>
7623 ("generic unit name cannot be used as operand", Enode
);
7627 ("subtype name cannot be used as operand", Enode
);
7631 ("entry name cannot be used as operand", Enode
);
7635 ("procedure name cannot be used as operand", Enode
);
7639 ("exception name cannot be used as operand", Enode
);
7646 ("label name cannot be used as operand", Enode
);
7655 --------------------
7656 -- Operator_Check --
7657 --------------------
7659 procedure Operator_Check
(N
: Node_Id
) is
7661 Remove_Abstract_Operations
(N
);
7663 -- Test for case of no interpretation found for operator
7665 if Etype
(N
) = Any_Type
then
7667 L
: constant Node_Id
:=
7668 (if Nkind
(N
) in N_Binary_Op
then Left_Opnd
(N
) else Empty
);
7669 R
: constant Node_Id
:= Right_Opnd
(N
);
7672 -- If either operand has no type, then don't complain further,
7673 -- since this simply means that we have a propagated error.
7676 or else Etype
(R
) = Any_Type
7677 or else (Nkind
(N
) in N_Binary_Op
and then Etype
(L
) = Any_Type
)
7679 -- For the rather unusual case where one of the operands is
7680 -- a Raise_Expression, whose initial type is Any_Type, use
7681 -- the type of the other operand.
7683 if Nkind
(L
) = N_Raise_Expression
then
7684 Set_Etype
(L
, Etype
(R
));
7685 Set_Etype
(N
, Etype
(R
));
7687 elsif Nkind
(R
) = N_Raise_Expression
then
7688 Set_Etype
(R
, Etype
(L
));
7689 Set_Etype
(N
, Etype
(L
));
7694 -- We explicitly check for the case of concatenation of component
7695 -- with component to avoid reporting spurious matching array types
7696 -- that might happen to be lurking in distant packages (such as
7697 -- run-time packages). This also prevents inconsistencies in the
7698 -- messages for certain ACVC B tests, which can vary depending on
7699 -- types declared in run-time interfaces. Another improvement when
7700 -- aggregates are present is to look for a well-typed operand.
7702 elsif Present
(Candidate_Type
)
7703 and then (Nkind
(N
) /= N_Op_Concat
7704 or else Is_Array_Type
(Etype
(L
))
7705 or else Is_Array_Type
(Etype
(R
)))
7707 if Nkind
(N
) = N_Op_Concat
then
7708 if Etype
(L
) /= Any_Composite
7709 and then Is_Array_Type
(Etype
(L
))
7711 Candidate_Type
:= Etype
(L
);
7713 elsif Etype
(R
) /= Any_Composite
7714 and then Is_Array_Type
(Etype
(R
))
7716 Candidate_Type
:= Etype
(R
);
7720 Error_Msg_NE
-- CODEFIX
7721 ("operator for} is not directly visible!",
7722 N
, First_Subtype
(Candidate_Type
));
7725 U
: constant Node_Id
:=
7726 Cunit
(Get_Source_Unit
(Candidate_Type
));
7728 if Unit_Is_Visible
(U
) then
7729 Error_Msg_N
-- CODEFIX
7730 ("use clause would make operation legal!", N
);
7732 Error_Msg_NE
-- CODEFIX
7733 ("add with_clause and use_clause for&!",
7734 N
, Defining_Entity
(Unit
(U
)));
7739 -- If either operand is a junk operand (e.g. package name), then
7740 -- post appropriate error messages, but do not complain further.
7742 -- Note that the use of OR in this test instead of OR ELSE is
7743 -- quite deliberate, we may as well check both operands in the
7744 -- binary operator case.
7746 elsif Junk_Operand
(R
)
7747 or -- really mean OR here and not OR ELSE, see above
7748 (Nkind
(N
) in N_Binary_Op
and then Junk_Operand
(L
))
7752 -- The handling of user-defined literals is deferred to the second
7753 -- pass of resolution.
7755 elsif Has_Possible_User_Defined_Literal
(N
) then
7758 -- If we have a logical operator, one of whose operands is
7759 -- Boolean, then we know that the other operand cannot resolve to
7760 -- Boolean (since we got no interpretations), but in that case we
7761 -- pretty much know that the other operand should be Boolean, so
7762 -- resolve it that way (generating an error).
7764 elsif Nkind
(N
) in N_Op_And | N_Op_Or | N_Op_Xor
then
7765 if Etype
(L
) = Standard_Boolean
then
7766 Resolve
(R
, Standard_Boolean
);
7768 elsif Etype
(R
) = Standard_Boolean
then
7769 Resolve
(L
, Standard_Boolean
);
7773 -- For an arithmetic operator or comparison operator, if one
7774 -- of the operands is numeric, then we know the other operand
7775 -- is not the same numeric type. If it is a non-numeric type,
7776 -- then probably it is intended to match the other operand.
7778 elsif Nkind
(N
) in N_Op_Add
7789 -- If Allow_Integer_Address is active, check whether the
7790 -- operation becomes legal after converting an operand.
7792 if Is_Numeric_Type
(Etype
(L
))
7793 and then not Is_Numeric_Type
(Etype
(R
))
7795 if Address_Integer_Convert_OK
(Etype
(R
), Etype
(L
)) then
7797 Unchecked_Convert_To
(
7798 Standard_Address
, Relocate_Node
(L
)));
7800 Unchecked_Convert_To
(
7801 Standard_Address
, Relocate_Node
(R
)));
7803 if Nkind
(N
) in N_Op_Ge | N_Op_Gt | N_Op_Le | N_Op_Lt
then
7804 Analyze_Comparison_Equality_Op
(N
);
7806 Analyze_Arithmetic_Op
(N
);
7809 Resolve
(R
, Etype
(L
));
7814 elsif Is_Numeric_Type
(Etype
(R
))
7815 and then not Is_Numeric_Type
(Etype
(L
))
7817 if Address_Integer_Convert_OK
(Etype
(L
), Etype
(R
)) then
7819 Unchecked_Convert_To
(
7820 Standard_Address
, Relocate_Node
(L
)));
7822 Unchecked_Convert_To
(
7823 Standard_Address
, Relocate_Node
(R
)));
7825 if Nkind
(N
) in N_Op_Ge | N_Op_Gt | N_Op_Le | N_Op_Lt
then
7826 Analyze_Comparison_Equality_Op
(N
);
7828 Analyze_Arithmetic_Op
(N
);
7834 Resolve
(L
, Etype
(R
));
7839 elsif Allow_Integer_Address
7840 and then Is_Descendant_Of_Address
(Etype
(L
))
7841 and then Is_Descendant_Of_Address
(Etype
(R
))
7842 and then not Error_Posted
(N
)
7845 Addr_Type
: constant Entity_Id
:= Etype
(L
);
7849 Unchecked_Convert_To
(
7850 Standard_Address
, Relocate_Node
(L
)));
7852 Unchecked_Convert_To
(
7853 Standard_Address
, Relocate_Node
(R
)));
7855 if Nkind
(N
) in N_Op_Ge | N_Op_Gt | N_Op_Le | N_Op_Lt
then
7856 Analyze_Comparison_Equality_Op
(N
);
7858 Analyze_Arithmetic_Op
(N
);
7861 -- If this is an operand in an enclosing arithmetic
7862 -- operation, Convert the result as an address so that
7863 -- arithmetic folding of address can continue.
7865 if Nkind
(Parent
(N
)) in N_Op
then
7867 Unchecked_Convert_To
(Addr_Type
, Relocate_Node
(N
)));
7873 -- Under relaxed RM semantics silently replace occurrences of
7874 -- null by System.Address_Null.
7876 elsif Null_To_Null_Address_Convert_OK
(N
) then
7877 Replace_Null_By_Null_Address
(N
);
7879 if Nkind
(N
) in N_Op_Ge | N_Op_Gt | N_Op_Le | N_Op_Lt
then
7880 Analyze_Comparison_Equality_Op
(N
);
7882 Analyze_Arithmetic_Op
(N
);
7888 -- Comparisons on A'Access are common enough to deserve a
7891 elsif Nkind
(N
) in N_Op_Eq | N_Op_Ne
7892 and then Ekind
(Etype
(L
)) = E_Access_Attribute_Type
7893 and then Ekind
(Etype
(R
)) = E_Access_Attribute_Type
7896 ("two access attributes cannot be compared directly", N
);
7898 ("\use qualified expression for one of the operands",
7902 -- Another one for C programmers
7904 elsif Nkind
(N
) = N_Op_Concat
7905 and then Valid_Boolean_Arg
(Etype
(L
))
7906 and then Valid_Boolean_Arg
(Etype
(R
))
7908 Error_Msg_N
("invalid operands for concatenation", N
);
7909 Error_Msg_N
-- CODEFIX
7910 ("\maybe AND was meant", N
);
7913 -- A special case for comparison of access parameter with null
7915 elsif Nkind
(N
) = N_Op_Eq
7916 and then Is_Entity_Name
(L
)
7917 and then Nkind
(Parent
(Entity
(L
))) = N_Parameter_Specification
7918 and then Nkind
(Parameter_Type
(Parent
(Entity
(L
)))) =
7920 and then Nkind
(R
) = N_Null
7922 Error_Msg_N
("access parameter is not allowed to be null", L
);
7923 Error_Msg_N
("\(call would raise Constraint_Error)", L
);
7926 -- Another special case for exponentiation, where the right
7927 -- operand must be Natural, independently of the base.
7929 elsif Nkind
(N
) = N_Op_Expon
7930 and then Is_Numeric_Type
(Etype
(L
))
7931 and then not Is_Overloaded
(R
)
7933 First_Subtype
(Base_Type
(Etype
(R
))) /= Standard_Integer
7934 and then Base_Type
(Etype
(R
)) /= Universal_Integer
7936 if Ada_Version
>= Ada_2012
7937 and then Has_Dimension_System
(Etype
(L
))
7940 ("exponent for dimensioned type must be a rational" &
7941 ", found}", R
, Etype
(R
));
7944 ("exponent must be of type Natural, found}", R
, Etype
(R
));
7949 elsif Nkind
(N
) in N_Op_Eq | N_Op_Ne
then
7950 if Address_Integer_Convert_OK
(Etype
(R
), Etype
(L
)) then
7952 Unchecked_Convert_To
(
7953 Standard_Address
, Relocate_Node
(L
)));
7955 Unchecked_Convert_To
(
7956 Standard_Address
, Relocate_Node
(R
)));
7957 Analyze_Comparison_Equality_Op
(N
);
7960 -- Under relaxed RM semantics silently replace occurrences of
7961 -- null by System.Address_Null.
7963 elsif Null_To_Null_Address_Convert_OK
(N
) then
7964 Replace_Null_By_Null_Address
(N
);
7965 Analyze_Comparison_Equality_Op
(N
);
7970 -- If we fall through then just give general message
7972 Unresolved_Operator
(N
);
7977 ---------------------------------------
7978 -- Has_Possible_User_Defined_Literal --
7979 ---------------------------------------
7981 function Has_Possible_User_Defined_Literal
(N
: Node_Id
) return Boolean is
7982 R
: constant Node_Id
:= Right_Opnd
(N
);
7984 procedure Check_Literal_Opnd
(Opnd
: Node_Id
);
7985 -- If an operand is a literal to which an aspect may apply,
7986 -- add the corresponding type to operator node.
7988 ------------------------
7989 -- Check_Literal_Opnd --
7990 ------------------------
7992 procedure Check_Literal_Opnd
(Opnd
: Node_Id
) is
7994 if Nkind
(Opnd
) in N_Numeric_Or_String_Literal
7995 or else (Is_Entity_Name
(Opnd
)
7996 and then Present
(Entity
(Opnd
))
7997 and then Is_Named_Number
(Entity
(Opnd
)))
7999 Add_One_Interp
(N
, Etype
(Opnd
), Etype
(Opnd
));
8001 end Check_Literal_Opnd
;
8003 -- Start of processing for Has_Possible_User_Defined_Literal
8006 if Ada_Version
< Ada_2022
then
8010 Check_Literal_Opnd
(R
);
8012 -- Check left operand only if right one did not provide a
8013 -- possible interpretation. Note that literal types are not
8014 -- overloadable, in the sense that there is no overloadable
8015 -- entity name whose several interpretations can be used to
8016 -- indicate possible resulting types, so there is no way to
8017 -- provide more than one interpretation to the operator node.
8018 -- The choice of one operand over the other is arbitrary at
8019 -- this point, and may lead to spurious resolution when both
8020 -- operands are literals of different kinds, but the second
8021 -- pass of resolution will examine anew both operands to
8022 -- determine whether a user-defined literal may apply to
8025 if Nkind
(N
) in N_Binary_Op
and then Etype
(N
) = Any_Type
then
8026 Check_Literal_Opnd
(Left_Opnd
(N
));
8029 return Etype
(N
) /= Any_Type
;
8030 end Has_Possible_User_Defined_Literal
;
8032 -----------------------------------------------
8033 -- Nondispatching_Call_To_Abstract_Operation --
8034 -----------------------------------------------
8036 procedure Nondispatching_Call_To_Abstract_Operation
8038 Abstract_Op
: Entity_Id
)
8040 Typ
: constant Entity_Id
:= Etype
(N
);
8043 -- In an instance body, this is a runtime check, but one we know will
8044 -- fail, so give an appropriate warning. As usual this kind of warning
8045 -- is an error in SPARK mode.
8047 Error_Msg_Sloc
:= Sloc
(Abstract_Op
);
8049 if In_Instance_Body
and then SPARK_Mode
/= On
then
8051 ("??cannot call abstract operation& declared#",
8053 Error_Msg_N
("\Program_Error [??", N
);
8055 Make_Raise_Program_Error
(Sloc
(N
),
8056 Reason
=> PE_Explicit_Raise
));
8062 ("cannot call abstract operation& declared#",
8064 Set_Etype
(N
, Any_Type
);
8066 end Nondispatching_Call_To_Abstract_Operation
;
8068 ----------------------------------------------
8069 -- Possible_Type_For_Conditional_Expression --
8070 ----------------------------------------------
8072 function Possible_Type_For_Conditional_Expression
8073 (T1
, T2
: Entity_Id
) return Entity_Id
8075 function Is_Access_Protected_Subprogram_Attribute
8076 (T
: Entity_Id
) return Boolean;
8077 -- Return true if T is the type of an access-to-protected-subprogram
8080 function Is_Access_Subprogram_Attribute
(T
: Entity_Id
) return Boolean;
8081 -- Return true if T is the type of an access-to-subprogram attribute
8083 ----------------------------------------------
8084 -- Is_Access_Protected_Subprogram_Attribute --
8085 ----------------------------------------------
8087 function Is_Access_Protected_Subprogram_Attribute
8088 (T
: Entity_Id
) return Boolean
8091 return Ekind
(T
) = E_Access_Protected_Subprogram_Type
8092 and then Ekind
(Designated_Type
(T
)) /= E_Subprogram_Type
;
8093 end Is_Access_Protected_Subprogram_Attribute
;
8095 ------------------------------------
8096 -- Is_Access_Subprogram_Attribute --
8097 ------------------------------------
8099 function Is_Access_Subprogram_Attribute
(T
: Entity_Id
) return Boolean is
8101 return Ekind
(T
) = E_Access_Subprogram_Type
8102 and then Ekind
(Designated_Type
(T
)) /= E_Subprogram_Type
;
8103 end Is_Access_Subprogram_Attribute
;
8105 -- Start of processing for Possible_Type_For_Conditional_Expression
8108 -- If both types are those of similar access attributes or allocators,
8109 -- pick one of them, for example the first.
8111 if Ekind
(T1
) in E_Access_Attribute_Type | E_Allocator_Type
8112 and then Ekind
(T2
) in E_Access_Attribute_Type | E_Allocator_Type
8116 elsif Is_Access_Subprogram_Attribute
(T1
)
8117 and then Is_Access_Subprogram_Attribute
(T2
)
8119 Subtype_Conformant
(Designated_Type
(T1
), Designated_Type
(T2
))
8123 elsif Is_Access_Protected_Subprogram_Attribute
(T1
)
8124 and then Is_Access_Protected_Subprogram_Attribute
(T2
)
8126 Subtype_Conformant
(Designated_Type
(T1
), Designated_Type
(T2
))
8130 -- The other case to be considered is a pair of tagged types
8132 elsif Is_Tagged_Type
(T1
) and then Is_Tagged_Type
(T2
) then
8133 -- Covers performs the same checks when T1 or T2 are a CW type, so
8134 -- we don't need to do them again here.
8136 if not Is_Class_Wide_Type
(T1
) and then Is_Ancestor
(T1
, T2
) then
8139 elsif not Is_Class_Wide_Type
(T2
) and then Is_Ancestor
(T2
, T1
) then
8142 -- Neither type is an ancestor of the other, but they may have one in
8143 -- common, so we pick the first type as above. We could perform here
8144 -- the computation of the nearest common ancestors of T1 and T2, but
8145 -- this would require a significant amount of work and the practical
8146 -- benefit would very likely be negligible.
8152 -- Otherwise no type is possible
8157 end Possible_Type_For_Conditional_Expression
;
8159 --------------------------------
8160 -- Remove_Abstract_Operations --
8161 --------------------------------
8163 procedure Remove_Abstract_Operations
(N
: Node_Id
) is
8164 Abstract_Op
: Entity_Id
:= Empty
;
8165 Address_Descendant
: Boolean := False;
8169 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
8170 -- activate this if either extensions are enabled, or if the abstract
8171 -- operation in question comes from a predefined file. This latter test
8172 -- allows us to use abstract to make operations invisible to users. In
8173 -- particular, if type Address is non-private and abstract subprograms
8174 -- are used to hide its operators, they will be truly hidden.
8176 type Operand_Position
is (First_Op
, Second_Op
);
8177 Univ_Type
: constant Entity_Id
:= Universal_Interpretation
(N
);
8179 procedure Remove_Address_Interpretations
(Op
: Operand_Position
);
8180 -- Ambiguities may arise when the operands are literal and the address
8181 -- operations in s-auxdec are visible. In that case, remove the
8182 -- interpretation of a literal as Address, to retain the semantics
8183 -- of Address as a private type.
8185 ------------------------------------
8186 -- Remove_Address_Interpretations --
8187 ------------------------------------
8189 procedure Remove_Address_Interpretations
(Op
: Operand_Position
) is
8193 if Is_Overloaded
(N
) then
8194 Get_First_Interp
(N
, I
, It
);
8195 while Present
(It
.Nam
) loop
8196 Formal
:= First_Entity
(It
.Nam
);
8198 if Op
= Second_Op
then
8199 Next_Entity
(Formal
);
8202 if Is_Descendant_Of_Address
(Etype
(Formal
)) then
8203 Address_Descendant
:= True;
8207 Get_Next_Interp
(I
, It
);
8210 end Remove_Address_Interpretations
;
8212 -- Start of processing for Remove_Abstract_Operations
8215 if Is_Overloaded
(N
) then
8216 if Debug_Flag_V
then
8217 Write_Line
("Remove_Abstract_Operations: ");
8218 Write_Overloads
(N
);
8221 Get_First_Interp
(N
, I
, It
);
8223 while Present
(It
.Nam
) loop
8224 if Is_Overloadable
(It
.Nam
)
8225 and then Is_Abstract_Subprogram
(It
.Nam
)
8226 and then not Is_Dispatching_Operation
(It
.Nam
)
8228 Abstract_Op
:= It
.Nam
;
8230 if Is_Descendant_Of_Address
(It
.Typ
) then
8231 Address_Descendant
:= True;
8235 -- In Ada 2005, this operation does not participate in overload
8236 -- resolution. If the operation is defined in a predefined
8237 -- unit, it is one of the operations declared abstract in some
8238 -- variants of System, and it must be removed as well.
8240 elsif Ada_Version
>= Ada_2005
8241 or else In_Predefined_Unit
(It
.Nam
)
8248 Get_Next_Interp
(I
, It
);
8251 if No
(Abstract_Op
) then
8253 -- If some interpretation yields an integer type, it is still
8254 -- possible that there are address interpretations. Remove them
8255 -- if one operand is a literal, to avoid spurious ambiguities
8256 -- on systems where Address is a visible integer type.
8258 if Is_Overloaded
(N
)
8259 and then Nkind
(N
) in N_Op
8260 and then Is_Integer_Type
(Etype
(N
))
8262 if Nkind
(N
) in N_Binary_Op
then
8263 if Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
8264 Remove_Address_Interpretations
(Second_Op
);
8266 elsif Nkind
(Left_Opnd
(N
)) = N_Integer_Literal
then
8267 Remove_Address_Interpretations
(First_Op
);
8272 elsif Nkind
(N
) in N_Op
then
8274 -- Remove interpretations that treat literals as addresses. This
8275 -- is never appropriate, even when Address is defined as a visible
8276 -- Integer type. The reason is that we would really prefer Address
8277 -- to behave as a private type, even in this case. If Address is a
8278 -- visible integer type, we get lots of overload ambiguities.
8280 if Nkind
(N
) in N_Binary_Op
then
8282 U1
: constant Boolean :=
8283 Present
(Universal_Interpretation
(Right_Opnd
(N
)));
8284 U2
: constant Boolean :=
8285 Present
(Universal_Interpretation
(Left_Opnd
(N
)));
8289 Remove_Address_Interpretations
(Second_Op
);
8293 Remove_Address_Interpretations
(First_Op
);
8296 if not (U1
and U2
) then
8298 -- Remove corresponding predefined operator, which is
8299 -- always added to the overload set.
8301 Get_First_Interp
(N
, I
, It
);
8302 while Present
(It
.Nam
) loop
8303 if Scope
(It
.Nam
) = Standard_Standard
8304 and then Base_Type
(It
.Typ
) =
8305 Base_Type
(Etype
(Abstract_Op
))
8310 Get_Next_Interp
(I
, It
);
8313 elsif Is_Overloaded
(N
)
8314 and then Present
(Univ_Type
)
8316 -- If both operands have a universal interpretation,
8317 -- it is still necessary to remove interpretations that
8318 -- yield Address. Any remaining ambiguities will be
8319 -- removed in Disambiguate.
8321 Get_First_Interp
(N
, I
, It
);
8322 while Present
(It
.Nam
) loop
8323 if Is_Descendant_Of_Address
(It
.Typ
) then
8326 elsif not Is_Type
(It
.Nam
) then
8327 Set_Entity
(N
, It
.Nam
);
8330 Get_Next_Interp
(I
, It
);
8336 elsif Nkind
(N
) = N_Function_Call
8338 (Nkind
(Name
(N
)) = N_Operator_Symbol
8340 (Nkind
(Name
(N
)) = N_Expanded_Name
8342 Nkind
(Selector_Name
(Name
(N
))) = N_Operator_Symbol
))
8346 Arg1
: constant Node_Id
:= First
(Parameter_Associations
(N
));
8347 U1
: constant Boolean :=
8348 Present
(Universal_Interpretation
(Arg1
));
8349 U2
: constant Boolean :=
8350 Present
(Next
(Arg1
)) and then
8351 Present
(Universal_Interpretation
(Next
(Arg1
)));
8355 Remove_Address_Interpretations
(First_Op
);
8359 Remove_Address_Interpretations
(Second_Op
);
8362 if not (U1
and U2
) then
8363 Get_First_Interp
(N
, I
, It
);
8364 while Present
(It
.Nam
) loop
8365 if Scope
(It
.Nam
) = Standard_Standard
8366 and then It
.Typ
= Base_Type
(Etype
(Abstract_Op
))
8371 Get_Next_Interp
(I
, It
);
8377 -- If the removal has left no valid interpretations, emit an error
8378 -- message now and label node as illegal.
8380 if Present
(Abstract_Op
) then
8381 Get_First_Interp
(N
, I
, It
);
8385 -- Removal of abstract operation left no viable candidate
8387 Nondispatching_Call_To_Abstract_Operation
(N
, Abstract_Op
);
8389 -- In Ada 2005, an abstract operation may disable predefined
8390 -- operators. Since the context is not yet known, we mark the
8391 -- predefined operators as potentially hidden. Do not include
8392 -- predefined operators when addresses are involved since this
8393 -- case is handled separately.
8395 elsif Ada_Version
>= Ada_2005
and then not Address_Descendant
then
8396 while Present
(It
.Nam
) loop
8397 if Is_Numeric_Type
(It
.Typ
)
8398 and then Scope
(It
.Typ
) = Standard_Standard
8399 and then Ekind
(It
.Nam
) = E_Operator
8401 Set_Abstract_Op
(I
, Abstract_Op
);
8404 Get_Next_Interp
(I
, It
);
8409 if Debug_Flag_V
then
8410 Write_Line
("Remove_Abstract_Operations done: ");
8411 Write_Overloads
(N
);
8414 end Remove_Abstract_Operations
;
8416 ----------------------------
8417 -- Try_Container_Indexing --
8418 ----------------------------
8420 function Try_Container_Indexing
8423 Exprs
: List_Id
) return Boolean
8425 Pref_Typ
: Entity_Id
:= Etype
(Prefix
);
8427 function Constant_Indexing_OK
return Boolean;
8428 -- Constant_Indexing is legal if there is no Variable_Indexing defined
8429 -- for the type, or else node not a target of assignment, or an actual
8430 -- for an IN OUT or OUT formal (RM 4.1.6 (11)).
8432 function Expr_Matches_In_Formal
8434 Par
: Node_Id
) return Boolean;
8435 -- Find formal corresponding to given indexed component that is an
8436 -- actual in a call. Note that the enclosing subprogram call has not
8437 -- been analyzed yet, and the parameter list is not normalized, so
8438 -- that if the argument is a parameter association we must match it
8439 -- by name and not by position.
8441 function Find_Indexing_Operations
8444 Is_Constant
: Boolean) return Node_Id
;
8445 -- Return a reference to the primitive operation of type T denoted by
8446 -- name Nam. If the operation is overloaded, the reference carries all
8447 -- interpretations. Flag Is_Constant should be set when the context is
8448 -- constant indexing.
8450 --------------------------
8451 -- Constant_Indexing_OK --
8452 --------------------------
8454 function Constant_Indexing_OK
return Boolean is
8458 if No
(Find_Value_Of_Aspect
(Pref_Typ
, Aspect_Variable_Indexing
)) then
8461 elsif not Is_Variable
(Prefix
) then
8466 while Present
(Par
) loop
8467 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
8468 and then Par
= Name
(Parent
(Par
))
8472 -- The call may be overloaded, in which case we assume that its
8473 -- resolution does not depend on the type of the parameter that
8474 -- includes the indexing operation.
8476 elsif Nkind
(Parent
(Par
)) in N_Subprogram_Call
then
8478 if not Is_Entity_Name
(Name
(Parent
(Par
))) then
8480 -- ??? We don't know what to do with an N_Selected_Component
8481 -- node for a prefixed-notation call to AA.BB where AA's
8482 -- type is known, but BB has not yet been resolved. In that
8483 -- case, the preceding Is_Entity_Name call returns False.
8484 -- Incorrectly returning False here will usually work
8485 -- better than incorrectly returning True, so that's what
8495 -- We should look for an interpretation with the proper
8496 -- number of formals, and determine whether it is an
8497 -- In_Parameter, but for now we examine the formal that
8498 -- corresponds to the indexing, and assume that variable
8499 -- indexing is required if some interpretation has an
8500 -- assignable formal at that position. Still does not
8501 -- cover the most complex cases ???
8503 if Is_Overloaded
(Name
(Parent
(Par
))) then
8505 Proc
: constant Node_Id
:= Name
(Parent
(Par
));
8510 Get_First_Interp
(Proc
, I
, It
);
8511 while Present
(It
.Nam
) loop
8512 if not Expr_Matches_In_Formal
(It
.Nam
, Par
) then
8516 Get_Next_Interp
(I
, It
);
8520 -- All interpretations have a matching in-mode formal
8525 Proc
:= Entity
(Name
(Parent
(Par
)));
8527 -- If this is an indirect call, get formals from
8530 if Is_Access_Subprogram_Type
(Etype
(Proc
)) then
8531 Proc
:= Designated_Type
(Etype
(Proc
));
8535 return Expr_Matches_In_Formal
(Proc
, Par
);
8538 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
8541 -- If the indexed component is a prefix it may be the first actual
8542 -- of a prefixed call. Retrieve the called entity, if any, and
8543 -- check its first formal. Determine if the context is a procedure
8544 -- or function call.
8546 elsif Nkind
(Parent
(Par
)) = N_Selected_Component
then
8548 Sel
: constant Node_Id
:= Selector_Name
(Parent
(Par
));
8549 Nam
: constant Entity_Id
:= Current_Entity
(Sel
);
8552 if Present
(Nam
) and then Is_Overloadable
(Nam
) then
8553 if Nkind
(Parent
(Parent
(Par
))) =
8554 N_Procedure_Call_Statement
8558 elsif Ekind
(Nam
) = E_Function
8559 and then Present
(First_Formal
(Nam
))
8561 return Ekind
(First_Formal
(Nam
)) = E_In_Parameter
;
8566 elsif Nkind
(Par
) in N_Op
then
8570 Par
:= Parent
(Par
);
8573 -- In all other cases, constant indexing is legal
8576 end Constant_Indexing_OK
;
8578 ----------------------------
8579 -- Expr_Matches_In_Formal --
8580 ----------------------------
8582 function Expr_Matches_In_Formal
8584 Par
: Node_Id
) return Boolean
8590 Formal
:= First_Formal
(Subp
);
8591 Actual
:= First
(Parameter_Associations
((Parent
(Par
))));
8593 if Nkind
(Par
) /= N_Parameter_Association
then
8595 -- Match by position
8597 while Present
(Actual
) and then Present
(Formal
) loop
8598 exit when Actual
= Par
;
8601 if Present
(Formal
) then
8602 Next_Formal
(Formal
);
8604 -- Otherwise this is a parameter mismatch, the error is
8605 -- reported elsewhere, or else variable indexing is implied.
8615 while Present
(Formal
) loop
8616 exit when Chars
(Formal
) = Chars
(Selector_Name
(Par
));
8617 Next_Formal
(Formal
);
8625 return Present
(Formal
) and then Ekind
(Formal
) = E_In_Parameter
;
8626 end Expr_Matches_In_Formal
;
8628 ------------------------------
8629 -- Find_Indexing_Operations --
8630 ------------------------------
8632 function Find_Indexing_Operations
8635 Is_Constant
: Boolean) return Node_Id
8637 procedure Inspect_Declarations
8639 Ref
: in out Node_Id
);
8640 -- Traverse the declarative list where type Typ resides and collect
8641 -- all suitable interpretations in node Ref.
8643 procedure Inspect_Primitives
8645 Ref
: in out Node_Id
);
8646 -- Traverse the list of primitive operations of type Typ and collect
8647 -- all suitable interpretations in node Ref.
8649 function Is_OK_Candidate
8650 (Subp_Id
: Entity_Id
;
8651 Typ
: Entity_Id
) return Boolean;
8652 -- Determine whether subprogram Subp_Id is a suitable indexing
8653 -- operation for type Typ. To qualify as such, the subprogram must
8654 -- be a function, have at least two parameters, and the type of the
8655 -- first parameter must be either Typ, or Typ'Class, or access [to
8656 -- constant] with designated type Typ or Typ'Class.
8658 procedure Record_Interp
(Subp_Id
: Entity_Id
; Ref
: in out Node_Id
);
8659 -- Store subprogram Subp_Id as an interpretation in node Ref
8661 --------------------------
8662 -- Inspect_Declarations --
8663 --------------------------
8665 procedure Inspect_Declarations
8667 Ref
: in out Node_Id
)
8669 Typ_Decl
: constant Node_Id
:= Declaration_Node
(Typ
);
8671 Subp_Id
: Entity_Id
;
8674 -- Ensure that the routine is not called with itypes, which lack a
8675 -- declarative node.
8677 pragma Assert
(Present
(Typ_Decl
));
8678 pragma Assert
(Is_List_Member
(Typ_Decl
));
8680 Decl
:= First
(List_Containing
(Typ_Decl
));
8681 while Present
(Decl
) loop
8682 if Nkind
(Decl
) = N_Subprogram_Declaration
then
8683 Subp_Id
:= Defining_Entity
(Decl
);
8685 if Is_OK_Candidate
(Subp_Id
, Typ
) then
8686 Record_Interp
(Subp_Id
, Ref
);
8692 end Inspect_Declarations
;
8694 ------------------------
8695 -- Inspect_Primitives --
8696 ------------------------
8698 procedure Inspect_Primitives
8700 Ref
: in out Node_Id
)
8702 Prim_Elmt
: Elmt_Id
;
8703 Prim_Id
: Entity_Id
;
8706 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
8707 while Present
(Prim_Elmt
) loop
8708 Prim_Id
:= Node
(Prim_Elmt
);
8710 if Is_OK_Candidate
(Prim_Id
, Typ
) then
8711 Record_Interp
(Prim_Id
, Ref
);
8714 Next_Elmt
(Prim_Elmt
);
8716 end Inspect_Primitives
;
8718 ---------------------
8719 -- Is_OK_Candidate --
8720 ---------------------
8722 function Is_OK_Candidate
8723 (Subp_Id
: Entity_Id
;
8724 Typ
: Entity_Id
) return Boolean
8727 Formal_Typ
: Entity_Id
;
8728 Param_Typ
: Node_Id
;
8731 -- To classify as a suitable candidate, the subprogram must be a
8732 -- function whose name matches the argument of aspect Constant or
8733 -- Variable_Indexing.
8735 if Ekind
(Subp_Id
) = E_Function
and then Chars
(Subp_Id
) = Nam
then
8736 Formal
:= First_Formal
(Subp_Id
);
8738 -- The candidate requires at least two parameters
8740 if Present
(Formal
) and then Present
(Next_Formal
(Formal
)) then
8741 Formal_Typ
:= Empty
;
8742 Param_Typ
:= Parameter_Type
(Parent
(Formal
));
8744 -- Use the designated type when the first parameter is of an
8747 if Nkind
(Param_Typ
) = N_Access_Definition
8748 and then Present
(Subtype_Mark
(Param_Typ
))
8750 -- When the context is a constant indexing, the access
8751 -- definition must be access-to-constant. This does not
8752 -- apply to variable indexing.
8755 or else Constant_Present
(Param_Typ
)
8757 Formal_Typ
:= Etype
(Subtype_Mark
(Param_Typ
));
8760 -- Otherwise use the parameter type
8763 Formal_Typ
:= Etype
(Param_Typ
);
8766 if Present
(Formal_Typ
) then
8768 -- Use the specific type when the parameter type is
8771 if Is_Class_Wide_Type
(Formal_Typ
) then
8772 Formal_Typ
:= Etype
(Base_Type
(Formal_Typ
));
8775 -- Use the full view when the parameter type is private
8778 if Is_Incomplete_Or_Private_Type
(Formal_Typ
)
8779 and then Present
(Full_View
(Formal_Typ
))
8781 Formal_Typ
:= Full_View
(Formal_Typ
);
8784 -- The type of the first parameter must denote the type
8785 -- of the container or acts as its ancestor type.
8789 or else Is_Ancestor
(Formal_Typ
, Typ
);
8795 end Is_OK_Candidate
;
8801 procedure Record_Interp
(Subp_Id
: Entity_Id
; Ref
: in out Node_Id
) is
8803 if Present
(Ref
) then
8804 Add_One_Interp
(Ref
, Subp_Id
, Etype
(Subp_Id
));
8806 -- Otherwise this is the first interpretation. Create a reference
8807 -- where all remaining interpretations will be collected.
8810 Ref
:= New_Occurrence_Of
(Subp_Id
, Sloc
(T
));
8819 -- Start of processing for Find_Indexing_Operations
8824 -- Use the specific type when the parameter type is class-wide
8826 if Is_Class_Wide_Type
(Typ
) then
8827 Typ
:= Root_Type
(Typ
);
8831 Typ
:= Underlying_Type
(Base_Type
(Typ
));
8833 Inspect_Primitives
(Typ
, Ref
);
8835 -- Now look for explicit declarations of an indexing operation.
8836 -- If the type is private the operation may be declared in the
8837 -- visible part that contains the partial view.
8839 if Is_Private_Type
(T
) then
8840 Inspect_Declarations
(T
, Ref
);
8843 Inspect_Declarations
(Typ
, Ref
);
8846 end Find_Indexing_Operations
;
8850 Loc
: constant Source_Ptr
:= Sloc
(N
);
8854 Func_Name
: Node_Id
;
8857 Is_Constant_Indexing
: Boolean := False;
8858 -- This flag reflects the nature of the container indexing. Note that
8859 -- the context may be suited for constant indexing, but the type may
8860 -- lack a Constant_Indexing annotation.
8862 -- Start of processing for Try_Container_Indexing
8865 -- Node may have been analyzed already when testing for a prefixed
8866 -- call, in which case do not redo analysis.
8868 if Present
(Generalized_Indexing
(N
)) then
8872 -- An explicit dereference needs to be created in the case of a prefix
8873 -- that's an access.
8875 -- It seems that this should be done elsewhere, but not clear where that
8876 -- should happen. Normally Insert_Explicit_Dereference is called via
8877 -- Resolve_Implicit_Dereference, called from Resolve_Indexed_Component,
8878 -- but that won't be called in this case because we transform the
8879 -- indexing to a call. Resolve_Call.Check_Prefixed_Call takes care of
8880 -- implicit dereferencing and referencing on prefixed calls, but that
8881 -- would be too late, even if we expanded to a prefix call, because
8882 -- Process_Indexed_Component will flag an error before the resolution
8885 if Is_Access_Type
(Pref_Typ
) then
8886 Pref_Typ
:= Implicitly_Designated_Type
(Pref_Typ
);
8887 Insert_Explicit_Dereference
(Prefix
);
8888 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
8893 -- If indexing a class-wide container, obtain indexing primitive from
8896 if Is_Class_Wide_Type
(C_Type
) then
8897 C_Type
:= Etype
(Base_Type
(C_Type
));
8900 -- Check whether the type has a specified indexing aspect
8904 -- The context is suitable for constant indexing, so obtain the name of
8905 -- the indexing function from aspect Constant_Indexing.
8907 if Constant_Indexing_OK
then
8909 Find_Value_Of_Aspect
(Pref_Typ
, Aspect_Constant_Indexing
);
8912 if Present
(Func_Name
) then
8913 Is_Constant_Indexing
:= True;
8915 -- Otherwise attempt variable indexing
8919 Find_Value_Of_Aspect
(Pref_Typ
, Aspect_Variable_Indexing
);
8922 -- The type is not subject to either form of indexing, therefore the
8923 -- indexed component does not denote container indexing. If this is a
8924 -- true error, it is diagnosed by the caller.
8926 if No
(Func_Name
) then
8928 -- The prefix itself may be an indexing of a container. Rewrite it
8929 -- as such and retry.
8931 if Has_Implicit_Dereference
(Pref_Typ
) then
8932 Build_Explicit_Dereference
8933 (Prefix
, Get_Reference_Discriminant
(Pref_Typ
));
8934 return Try_Container_Indexing
(N
, Prefix
, Exprs
);
8936 -- Otherwise this is definitely not container indexing
8942 -- If the container type is derived from another container type, the
8943 -- value of the inherited aspect is the Reference operation declared
8944 -- for the parent type.
8946 -- However, Reference is also a primitive operation of the type, and the
8947 -- inherited operation has a different signature. We retrieve the right
8948 -- ones (the function may be overloaded) from the list of primitive
8949 -- operations of the derived type.
8951 -- Note that predefined containers are typically all derived from one of
8952 -- the Controlled types. The code below is motivated by containers that
8953 -- are derived from other types with a Reference aspect.
8954 -- Note as well that we need to examine the base type, given that
8955 -- the container object may be a constrained subtype or itype that
8956 -- does not have an explicit declaration.
8958 elsif Is_Derived_Type
(C_Type
)
8959 and then Etype
(First_Formal
(Entity
(Func_Name
))) /= Pref_Typ
8962 Find_Indexing_Operations
8963 (T
=> Base_Type
(C_Type
),
8964 Nam
=> Chars
(Func_Name
),
8965 Is_Constant
=> Is_Constant_Indexing
);
8968 Assoc
:= New_List
(Relocate_Node
(Prefix
));
8970 -- A generalized indexing may have nore than one index expression, so
8971 -- transfer all of them to the argument list to be used in the call.
8972 -- Note that there may be named associations, in which case the node
8973 -- was rewritten earlier as a call, and has been transformed back into
8974 -- an indexed expression to share the following processing.
8976 -- The generalized indexing node is the one on which analysis and
8977 -- resolution take place. Before expansion the original node is replaced
8978 -- with the generalized indexing node, which is a call, possibly with a
8979 -- dereference operation.
8981 -- Create argument list for function call that represents generalized
8982 -- indexing. Note that indices (i.e. actuals) may themselves be
8990 Arg
:= First
(Exprs
);
8991 while Present
(Arg
) loop
8992 New_Arg
:= Relocate_Node
(Arg
);
8994 -- The arguments can be parameter associations, in which case the
8995 -- explicit actual parameter carries the overloadings.
8997 if Nkind
(New_Arg
) /= N_Parameter_Association
then
8998 Save_Interps
(Arg
, New_Arg
);
9001 Append
(New_Arg
, Assoc
);
9006 if not Is_Overloaded
(Func_Name
) then
9007 Func
:= Entity
(Func_Name
);
9009 -- Can happen in case of e.g. cascaded errors
9016 Make_Function_Call
(Loc
,
9017 Name
=> New_Occurrence_Of
(Func
, Loc
),
9018 Parameter_Associations
=> Assoc
);
9020 Set_Parent
(Indexing
, Parent
(N
));
9021 Set_Generalized_Indexing
(N
, Indexing
);
9023 Set_Etype
(N
, Etype
(Indexing
));
9025 -- If the return type of the indexing function is a reference type,
9026 -- add the dereference as a possible interpretation. Note that the
9027 -- indexing aspect may be a function that returns the element type
9028 -- with no intervening implicit dereference, and that the reference
9029 -- discriminant is not the first discriminant.
9031 if Has_Discriminants
(Etype
(Func
)) then
9032 Check_Implicit_Dereference
(N
, Etype
(Func
));
9036 -- If there are multiple indexing functions, build a function call
9037 -- and analyze it for each of the possible interpretations.
9040 Make_Function_Call
(Loc
,
9042 Make_Identifier
(Loc
, Chars
(Func_Name
)),
9043 Parameter_Associations
=> Assoc
);
9044 Set_Parent
(Indexing
, Parent
(N
));
9045 Set_Generalized_Indexing
(N
, Indexing
);
9046 Set_Etype
(N
, Any_Type
);
9047 Set_Etype
(Name
(Indexing
), Any_Type
);
9055 Get_First_Interp
(Func_Name
, I
, It
);
9056 Set_Etype
(Indexing
, Any_Type
);
9058 -- Analyze each candidate function with the given actuals
9060 while Present
(It
.Nam
) loop
9061 Analyze_One_Call
(Indexing
, It
.Nam
, False, Success
);
9062 Get_Next_Interp
(I
, It
);
9065 -- If there are several successful candidates, resolution will
9066 -- be by result. Mark the interpretations of the function name
9069 if Is_Overloaded
(Indexing
) then
9070 Get_First_Interp
(Indexing
, I
, It
);
9072 while Present
(It
.Nam
) loop
9073 Add_One_Interp
(Name
(Indexing
), It
.Nam
, It
.Typ
);
9074 Get_Next_Interp
(I
, It
);
9078 Set_Etype
(Name
(Indexing
), Etype
(Indexing
));
9081 -- Now add the candidate interpretations to the indexing node
9082 -- itself, to be replaced later by the function call.
9084 if Is_Overloaded
(Name
(Indexing
)) then
9085 Get_First_Interp
(Name
(Indexing
), I
, It
);
9087 while Present
(It
.Nam
) loop
9088 Add_One_Interp
(N
, It
.Nam
, It
.Typ
);
9090 -- Add dereference interpretation if the result type has
9091 -- implicit reference discriminants.
9093 if Has_Discriminants
(Etype
(It
.Nam
)) then
9094 Check_Implicit_Dereference
(N
, Etype
(It
.Nam
));
9097 Get_Next_Interp
(I
, It
);
9101 Set_Etype
(N
, Etype
(Name
(Indexing
)));
9102 if Has_Discriminants
(Etype
(N
)) then
9103 Check_Implicit_Dereference
(N
, Etype
(N
));
9109 if Etype
(Indexing
) = Any_Type
then
9111 ("container cannot be indexed with&", N
, Etype
(First
(Exprs
)));
9112 Rewrite
(N
, New_Occurrence_Of
(Any_Id
, Loc
));
9116 end Try_Container_Indexing
;
9118 -----------------------
9119 -- Try_Indirect_Call --
9120 -----------------------
9122 function Try_Indirect_Call
9125 Typ
: Entity_Id
) return Boolean
9131 pragma Warnings
(Off
, Call_OK
);
9134 Normalize_Actuals
(N
, Designated_Type
(Typ
), False, Call_OK
);
9136 Actual
:= First_Actual
(N
);
9137 Formal
:= First_Formal
(Designated_Type
(Typ
));
9138 while Present
(Actual
) and then Present
(Formal
) loop
9139 if not Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
9144 Next_Formal
(Formal
);
9147 if No
(Actual
) and then No
(Formal
) then
9148 Add_One_Interp
(N
, Nam
, Etype
(Designated_Type
(Typ
)));
9150 -- Nam is a candidate interpretation for the name in the call,
9151 -- if it is not an indirect call.
9153 if not Is_Type
(Nam
)
9154 and then Is_Entity_Name
(Name
(N
))
9156 Set_Entity
(Name
(N
), Nam
);
9164 end Try_Indirect_Call
;
9166 ----------------------
9167 -- Try_Indexed_Call --
9168 ----------------------
9170 function Try_Indexed_Call
9174 Skip_First
: Boolean) return Boolean
9176 Loc
: constant Source_Ptr
:= Sloc
(N
);
9177 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
9182 Actual
:= First
(Actuals
);
9184 -- If the call was originally written in prefix form, skip the first
9185 -- actual, which is obviously not defaulted.
9191 Index
:= First_Index
(Typ
);
9192 while Present
(Actual
) and then Present
(Index
) loop
9194 -- If the parameter list has a named association, the expression
9195 -- is definitely a call and not an indexed component.
9197 if Nkind
(Actual
) = N_Parameter_Association
then
9201 if Is_Entity_Name
(Actual
)
9202 and then Is_Type
(Entity
(Actual
))
9203 and then No
(Next
(Actual
))
9205 -- A single actual that is a type name indicates a slice if the
9206 -- type is discrete, and an error otherwise.
9208 if Is_Discrete_Type
(Entity
(Actual
)) then
9212 Make_Function_Call
(Loc
,
9213 Name
=> Relocate_Node
(Name
(N
))),
9215 New_Occurrence_Of
(Entity
(Actual
), Sloc
(Actual
))));
9220 Error_Msg_N
("invalid use of type in expression", Actual
);
9221 Set_Etype
(N
, Any_Type
);
9226 elsif not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
9234 if No
(Actual
) and then No
(Index
) then
9235 Add_One_Interp
(N
, Nam
, Component_Type
(Typ
));
9237 -- Nam is a candidate interpretation for the name in the call,
9238 -- if it is not an indirect call.
9240 if not Is_Type
(Nam
)
9241 and then Is_Entity_Name
(Name
(N
))
9243 Set_Entity
(Name
(N
), Nam
);
9250 end Try_Indexed_Call
;
9252 --------------------------
9253 -- Try_Object_Operation --
9254 --------------------------
9256 function Try_Object_Operation
9258 CW_Test_Only
: Boolean := False;
9259 Allow_Extensions
: Boolean := False) return Boolean
9261 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
9262 Is_Subprg_Call
: constant Boolean := K
in N_Subprogram_Call
;
9263 Loc
: constant Source_Ptr
:= Sloc
(N
);
9264 Obj
: constant Node_Id
:= Prefix
(N
);
9266 Subprog
: constant Node_Id
:=
9267 Make_Identifier
(Sloc
(Selector_Name
(N
)),
9268 Chars
=> Chars
(Selector_Name
(N
)));
9269 -- Identifier on which possible interpretations will be collected
9271 Report_Error
: Boolean := False;
9272 -- If no candidate interpretation matches the context, redo analysis
9273 -- with Report_Error True to provide additional information.
9276 Candidate
: Entity_Id
:= Empty
;
9277 New_Call_Node
: Node_Id
:= Empty
;
9278 Node_To_Replace
: Node_Id
;
9279 Obj_Type
: Entity_Id
:= Etype
(Obj
);
9280 Success
: Boolean := False;
9282 procedure Complete_Object_Operation
9283 (Call_Node
: Node_Id
;
9284 Node_To_Replace
: Node_Id
);
9285 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
9286 -- Call_Node, insert the object (or its dereference) as the first actual
9287 -- in the call, and complete the analysis of the call.
9289 procedure Report_Ambiguity
(Op
: Entity_Id
);
9290 -- If a prefixed procedure call is ambiguous, indicate whether the call
9291 -- includes an implicit dereference or an implicit 'Access.
9293 procedure Transform_Object_Operation
9294 (Call_Node
: out Node_Id
;
9295 Node_To_Replace
: out Node_Id
);
9296 -- Transform Obj.Operation (X, Y, ...) into Operation (Obj, X, Y ...).
9297 -- Call_Node is the resulting subprogram call, Node_To_Replace is
9298 -- either N or the parent of N, and Subprog is a reference to the
9299 -- subprogram we are trying to match. Note that the transformation
9300 -- may be partially destructive for the parent of N, so it needs to
9301 -- be undone in the case where Try_Object_Operation returns false.
9303 function Try_Class_Wide_Operation
9304 (Call_Node
: Node_Id
;
9305 Node_To_Replace
: Node_Id
) return Boolean;
9306 -- Traverse all ancestor types looking for a class-wide subprogram for
9307 -- which the current operation is a valid non-dispatching call.
9309 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
);
9310 -- If prefix is overloaded, its interpretation may include different
9311 -- tagged types, and we must examine the primitive operations and the
9312 -- class-wide operations of each in order to find candidate
9313 -- interpretations for the call as a whole.
9315 function Try_Primitive_Operation
9316 (Call_Node
: Node_Id
;
9317 Node_To_Replace
: Node_Id
) return Boolean;
9318 -- Traverse the list of primitive subprograms looking for a dispatching
9319 -- operation for which the current node is a valid call.
9321 function Valid_Candidate
9324 Subp
: Entity_Id
) return Entity_Id
;
9325 -- If the subprogram is a valid interpretation, record it, and add to
9326 -- the list of interpretations of Subprog. Otherwise return Empty.
9328 -------------------------------
9329 -- Complete_Object_Operation --
9330 -------------------------------
9332 procedure Complete_Object_Operation
9333 (Call_Node
: Node_Id
;
9334 Node_To_Replace
: Node_Id
)
9336 Control
: constant Entity_Id
:= First_Formal
(Entity
(Subprog
));
9337 Formal_Type
: constant Entity_Id
:= Etype
(Control
);
9338 First_Actual
: Node_Id
;
9341 -- Place the name of the operation, with its interpretations,
9342 -- on the rewritten call.
9344 Set_Name
(Call_Node
, Subprog
);
9346 First_Actual
:= First
(Parameter_Associations
(Call_Node
));
9348 -- For cross-reference purposes, treat the new node as being in the
9349 -- source if the original one is. Set entity and type, even though
9350 -- they may be overwritten during resolution if overloaded.
9352 Set_Comes_From_Source
(Subprog
, Comes_From_Source
(N
));
9353 Set_Comes_From_Source
(Call_Node
, Comes_From_Source
(N
));
9355 if Nkind
(N
) = N_Selected_Component
9356 and then not Inside_A_Generic
9358 Set_Entity
(Selector_Name
(N
), Entity
(Subprog
));
9359 Set_Etype
(Selector_Name
(N
), Etype
(Entity
(Subprog
)));
9362 -- If need be, rewrite first actual as an explicit dereference. If
9363 -- the call is overloaded, the rewriting can only be done once the
9364 -- primitive operation is identified.
9366 if Is_Overloaded
(Subprog
) then
9368 -- The prefix itself may be overloaded, and its interpretations
9369 -- must be propagated to the new actual in the call.
9371 if Is_Overloaded
(Obj
) then
9372 Save_Interps
(Obj
, First_Actual
);
9375 Rewrite
(First_Actual
, Obj
);
9377 elsif not Is_Access_Type
(Formal_Type
)
9378 and then Is_Access_Type
(Etype
(Obj
))
9380 Rewrite
(First_Actual
,
9381 Make_Explicit_Dereference
(Sloc
(Obj
), Obj
));
9382 Analyze
(First_Actual
);
9384 -- If we need to introduce an explicit dereference, verify that
9385 -- the resulting actual is compatible with the mode of the formal.
9387 if Ekind
(First_Formal
(Entity
(Subprog
))) /= E_In_Parameter
9388 and then Is_Access_Constant
(Etype
(Obj
))
9391 ("expect variable in call to&", Prefix
(N
), Entity
(Subprog
));
9394 -- Conversely, if the formal is an access parameter and the object is
9395 -- not an access type or a reference type (i.e. a type with the
9396 -- Implicit_Dereference aspect specified), replace the actual with a
9397 -- 'Access reference. Its analysis will check that the object is
9400 elsif Is_Access_Type
(Formal_Type
)
9401 and then not Is_Access_Type
(Etype
(Obj
))
9403 (not Has_Implicit_Dereference
(Etype
(Obj
))
9405 not Is_Access_Type
(Designated_Type
(Etype
9406 (Get_Reference_Discriminant
(Etype
(Obj
))))))
9408 -- A special case: A.all'Access is illegal if A is an access to a
9409 -- constant and the context requires an access to a variable.
9411 if not Is_Access_Constant
(Formal_Type
) then
9412 if (Nkind
(Obj
) = N_Explicit_Dereference
9413 and then Is_Access_Constant
(Etype
(Prefix
(Obj
))))
9414 or else not Is_Variable
(Obj
)
9417 ("actual for & must be a variable", Obj
, Control
);
9421 Rewrite
(First_Actual
,
9422 Make_Attribute_Reference
(Loc
,
9423 Attribute_Name
=> Name_Access
,
9424 Prefix
=> Relocate_Node
(Obj
)));
9426 -- If the object is not overloaded verify that taking access of
9427 -- it is legal. Otherwise check is made during resolution.
9429 if not Is_Overloaded
(Obj
)
9430 and then not Is_Aliased_View
(Obj
)
9433 ("object in prefixed call to & must be aliased "
9434 & "(RM 4.1.3 (13 1/2))", Prefix
(First_Actual
), Subprog
);
9437 Analyze
(First_Actual
);
9440 if Is_Overloaded
(Obj
) then
9441 Save_Interps
(Obj
, First_Actual
);
9444 Rewrite
(First_Actual
, Obj
);
9447 if In_Extended_Main_Source_Unit
(Current_Scope
) then
9448 -- The operation is obtained from the dispatch table and not by
9449 -- visibility, and may be declared in a unit that is not
9450 -- explicitly referenced in the source, but is nevertheless
9451 -- required in the context of the current unit. Indicate that
9452 -- operation and its scope are referenced, to prevent spurious and
9453 -- misleading warnings. If the operation is overloaded, all
9454 -- primitives are in the same scope and we can use any of them.
9455 -- Don't do that outside the main unit since otherwise this will
9456 -- e.g. prevent the detection of some unused with clauses.
9458 Set_Referenced
(Entity
(Subprog
), True);
9459 Set_Referenced
(Scope
(Entity
(Subprog
)), True);
9462 Rewrite
(Node_To_Replace
, Call_Node
);
9464 -- Propagate the interpretations collected in subprog to the new
9465 -- function call node, to be resolved from context.
9467 if Is_Overloaded
(Subprog
) then
9468 Save_Interps
(Subprog
, Node_To_Replace
);
9471 Analyze
(Node_To_Replace
);
9473 -- If the operation has been rewritten into a call, which may get
9474 -- subsequently an explicit dereference, preserve the type on the
9475 -- original node (selected component or indexed component) for
9476 -- subsequent legality tests, e.g. Is_Variable. which examines
9477 -- the original node.
9479 if Nkind
(Node_To_Replace
) = N_Function_Call
then
9481 (Original_Node
(Node_To_Replace
), Etype
(Node_To_Replace
));
9484 end Complete_Object_Operation
;
9486 ----------------------
9487 -- Report_Ambiguity --
9488 ----------------------
9490 procedure Report_Ambiguity
(Op
: Entity_Id
) is
9491 Access_Actual
: constant Boolean :=
9492 Is_Access_Type
(Etype
(Prefix
(N
)));
9493 Access_Formal
: Boolean := False;
9496 Error_Msg_Sloc
:= Sloc
(Op
);
9498 if Present
(First_Formal
(Op
)) then
9499 Access_Formal
:= Is_Access_Type
(Etype
(First_Formal
(Op
)));
9502 if Access_Formal
and then not Access_Actual
then
9503 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
9505 ("\possible interpretation "
9506 & "(inherited, with implicit 'Access) #", N
);
9509 ("\possible interpretation (with implicit 'Access) #", N
);
9512 elsif not Access_Formal
and then Access_Actual
then
9513 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
9515 ("\possible interpretation "
9516 & "(inherited, with implicit dereference) #", N
);
9519 ("\possible interpretation (with implicit dereference) #", N
);
9523 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
9524 Error_Msg_N
("\possible interpretation (inherited)#", N
);
9526 Error_Msg_N
-- CODEFIX
9527 ("\possible interpretation#", N
);
9530 end Report_Ambiguity
;
9532 --------------------------------
9533 -- Transform_Object_Operation --
9534 --------------------------------
9536 procedure Transform_Object_Operation
9537 (Call_Node
: out Node_Id
;
9538 Node_To_Replace
: out Node_Id
)
9540 Dummy
: constant Node_Id
:= New_Copy
(Obj
);
9541 -- Placeholder used as a first parameter in the call, replaced
9542 -- eventually by the proper object.
9544 Parent_Node
: constant Node_Id
:= Parent
(N
);
9550 -- Common case covering 1) Call to a procedure and 2) Call to a
9551 -- function that has some additional actuals.
9553 if Nkind
(Parent_Node
) in N_Subprogram_Call
9555 -- N is a selected component node containing the name of the
9556 -- subprogram. If N is not the name of the parent node we must
9557 -- not replace the parent node by the new construct. This case
9558 -- occurs when N is a parameterless call to a subprogram that
9559 -- is an actual parameter of a call to another subprogram. For
9561 -- Some_Subprogram (..., Obj.Operation, ...)
9563 and then N
= Name
(Parent_Node
)
9565 Node_To_Replace
:= Parent_Node
;
9567 Actuals
:= Parameter_Associations
(Parent_Node
);
9569 if Present
(Actuals
) then
9570 Prepend
(Dummy
, Actuals
);
9572 Actuals
:= New_List
(Dummy
);
9575 if Nkind
(Parent_Node
) = N_Procedure_Call_Statement
then
9577 Make_Procedure_Call_Statement
(Loc
,
9578 Name
=> New_Copy
(Subprog
),
9579 Parameter_Associations
=> Actuals
);
9583 Make_Function_Call
(Loc
,
9584 Name
=> New_Copy
(Subprog
),
9585 Parameter_Associations
=> Actuals
);
9588 -- Before analysis, a function call appears as an indexed component
9589 -- if there are no named associations.
9591 elsif Nkind
(Parent_Node
) = N_Indexed_Component
9592 and then N
= Prefix
(Parent_Node
)
9594 Node_To_Replace
:= Parent_Node
;
9595 Actuals
:= Expressions
(Parent_Node
);
9597 Actual
:= First
(Actuals
);
9598 while Present
(Actual
) loop
9603 Prepend
(Dummy
, Actuals
);
9606 Make_Function_Call
(Loc
,
9607 Name
=> New_Copy
(Subprog
),
9608 Parameter_Associations
=> Actuals
);
9610 -- Parameterless call: Obj.F is rewritten as F (Obj)
9613 Node_To_Replace
:= N
;
9616 Make_Function_Call
(Loc
,
9617 Name
=> New_Copy
(Subprog
),
9618 Parameter_Associations
=> New_List
(Dummy
));
9620 end Transform_Object_Operation
;
9622 ------------------------------
9623 -- Try_Class_Wide_Operation --
9624 ------------------------------
9626 function Try_Class_Wide_Operation
9627 (Call_Node
: Node_Id
;
9628 Node_To_Replace
: Node_Id
) return Boolean
9630 Anc_Type
: Entity_Id
;
9631 Matching_Op
: Entity_Id
:= Empty
;
9634 procedure Traverse_Homonyms
9635 (Anc_Type
: Entity_Id
;
9636 Error
: out Boolean);
9637 -- Traverse the homonym chain of the subprogram searching for those
9638 -- homonyms whose first formal has the Anc_Type's class-wide type,
9639 -- or an anonymous access type designating the class-wide type. If
9640 -- an ambiguity is detected, then Error is set to True.
9642 procedure Traverse_Interfaces
9643 (Anc_Type
: Entity_Id
;
9644 Error
: out Boolean);
9645 -- Traverse the list of interfaces, if any, associated with Anc_Type
9646 -- and search for acceptable class-wide homonyms associated with each
9647 -- interface. If an ambiguity is detected, then Error is set to True.
9649 -----------------------
9650 -- Traverse_Homonyms --
9651 -----------------------
9653 procedure Traverse_Homonyms
9654 (Anc_Type
: Entity_Id
;
9655 Error
: out Boolean)
9657 function First_Formal_Match
9658 (Subp_Id
: Entity_Id
;
9659 Typ
: Entity_Id
) return Boolean;
9660 -- Predicate to verify that the first foramal of class-wide
9661 -- subprogram Subp_Id matches type Typ of the prefix.
9663 ------------------------
9664 -- First_Formal_Match --
9665 ------------------------
9667 function First_Formal_Match
9668 (Subp_Id
: Entity_Id
;
9669 Typ
: Entity_Id
) return Boolean
9671 Ctrl
: constant Entity_Id
:= First_Formal
(Subp_Id
);
9677 (Base_Type
(Etype
(Ctrl
)) = Typ
9679 (Ekind
(Etype
(Ctrl
)) = E_Anonymous_Access_Type
9681 Base_Type
(Designated_Type
(Etype
(Ctrl
))) =
9683 end First_Formal_Match
;
9687 CW_Typ
: constant Entity_Id
:= Class_Wide_Type
(Anc_Type
);
9689 Candidate
: Entity_Id
;
9690 -- If homonym is a renaming, examine the renamed program
9696 -- Start of processing for Traverse_Homonyms
9701 -- Find a non-hidden operation whose first parameter is of the
9702 -- class-wide type, a subtype thereof, or an anonymous access
9703 -- to same. If in an instance, the operation can be considered
9704 -- even if hidden (it may be hidden because the instantiation
9705 -- is expanded after the containing package has been analyzed).
9706 -- If the subprogram is a generic actual in an enclosing instance,
9707 -- it appears as a renaming that is a candidate interpretation as
9710 Hom
:= Current_Entity
(Subprog
);
9711 while Present
(Hom
) loop
9712 if Ekind
(Hom
) in E_Procedure | E_Function
9713 and then Present
(Renamed_Entity
(Hom
))
9714 and then Is_Generic_Actual_Subprogram
(Hom
)
9715 and then In_Open_Scopes
(Scope
(Hom
))
9717 Candidate
:= Renamed_Entity
(Hom
);
9722 if Ekind
(Candidate
) in E_Function | E_Procedure
9723 and then (not Is_Hidden
(Candidate
) or else In_Instance
)
9724 and then Scope
(Candidate
) = Scope
(Base_Type
(Anc_Type
))
9725 and then First_Formal_Match
(Candidate
, CW_Typ
)
9727 -- If the context is a procedure call, ignore functions
9728 -- in the name of the call.
9730 if Ekind
(Candidate
) = E_Function
9731 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
9732 and then N
= Name
(Parent
(N
))
9736 -- If the context is a function call, ignore procedures
9737 -- in the name of the call.
9739 elsif Ekind
(Candidate
) = E_Procedure
9740 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
9745 Set_Etype
(Call_Node
, Any_Type
);
9746 Set_Is_Overloaded
(Call_Node
, False);
9749 if No
(Matching_Op
) then
9750 Hom_Ref
:= New_Occurrence_Of
(Candidate
, Sloc
(Subprog
));
9752 Set_Etype
(Call_Node
, Any_Type
);
9753 Set_Name
(Call_Node
, Hom_Ref
);
9754 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
9759 Report
=> Report_Error
,
9761 Skip_First
=> True);
9764 Valid_Candidate
(Success
, Call_Node
, Candidate
);
9770 Report
=> Report_Error
,
9772 Skip_First
=> True);
9774 -- The same operation may be encountered on two homonym
9775 -- traversals, before and after looking at interfaces.
9776 -- Check for this case before reporting a real ambiguity.
9779 (Valid_Candidate
(Success
, Call_Node
, Candidate
))
9780 and then Nkind
(Call_Node
) /= N_Function_Call
9781 and then Candidate
/= Matching_Op
9783 Error_Msg_NE
("ambiguous call to&", N
, Hom
);
9784 Report_Ambiguity
(Matching_Op
);
9785 Report_Ambiguity
(Hom
);
9786 Check_Ambiguous_Aggregate
(New_Call_Node
);
9794 Hom
:= Homonym
(Hom
);
9796 end Traverse_Homonyms
;
9798 -------------------------
9799 -- Traverse_Interfaces --
9800 -------------------------
9802 procedure Traverse_Interfaces
9803 (Anc_Type
: Entity_Id
;
9804 Error
: out Boolean)
9806 Intface_List
: constant List_Id
:=
9807 Abstract_Interface_List
(Anc_Type
);
9813 Intface
:= First
(Intface_List
);
9814 while Present
(Intface
) loop
9816 -- Look for acceptable class-wide homonyms associated with the
9819 Traverse_Homonyms
(Etype
(Intface
), Error
);
9825 -- Continue the search by looking at each of the interface's
9826 -- associated interface ancestors.
9828 Traverse_Interfaces
(Etype
(Intface
), Error
);
9836 end Traverse_Interfaces
;
9838 -- Start of processing for Try_Class_Wide_Operation
9841 -- If we are searching only for conflicting class-wide subprograms
9842 -- then initialize directly Matching_Op with the target entity.
9844 if CW_Test_Only
then
9845 Matching_Op
:= Entity
(Selector_Name
(N
));
9848 -- Loop through ancestor types (including interfaces), traversing
9849 -- the homonym chain of the subprogram, trying out those homonyms
9850 -- whose first formal has the class-wide type of the ancestor, or
9851 -- an anonymous access type designating the class-wide type.
9853 Anc_Type
:= Obj_Type
;
9855 -- Look for a match among homonyms associated with the ancestor
9857 Traverse_Homonyms
(Anc_Type
, Error
);
9863 -- Continue the search for matches among homonyms associated with
9864 -- any interfaces implemented by the ancestor.
9866 Traverse_Interfaces
(Anc_Type
, Error
);
9872 exit when Etype
(Anc_Type
) = Anc_Type
;
9873 Anc_Type
:= Etype
(Anc_Type
);
9876 if Present
(Matching_Op
) then
9877 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
9880 return Present
(Matching_Op
);
9881 end Try_Class_Wide_Operation
;
9883 -----------------------------------
9884 -- Try_One_Prefix_Interpretation --
9885 -----------------------------------
9887 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
) is
9888 Prev_Obj_Type
: constant Entity_Id
:= Obj_Type
;
9889 -- If the interpretation does not have a valid candidate type,
9890 -- preserve current value of Obj_Type for subsequent errors.
9895 if Is_Access_Type
(Obj_Type
) then
9896 Obj_Type
:= Designated_Type
(Obj_Type
);
9900 in E_Private_Subtype | E_Record_Subtype_With_Private
9902 Obj_Type
:= Base_Type
(Obj_Type
);
9905 if Is_Class_Wide_Type
(Obj_Type
) then
9906 Obj_Type
:= Etype
(Class_Wide_Type
(Obj_Type
));
9909 -- The type may have be obtained through a limited_with clause,
9910 -- in which case the primitive operations are available on its
9911 -- nonlimited view. If still incomplete, retrieve full view.
9913 if Ekind
(Obj_Type
) = E_Incomplete_Type
9914 and then From_Limited_With
(Obj_Type
)
9915 and then Has_Non_Limited_View
(Obj_Type
)
9917 Obj_Type
:= Get_Full_View
(Non_Limited_View
(Obj_Type
));
9920 -- If the object is not tagged, or the type is still an incomplete
9921 -- type, this is not a prefixed call. Restore the previous type as
9922 -- the current one is not a legal candidate.
9924 -- Extension feature: Calls with prefixed views are also supported
9925 -- for untagged types, so skip the early return when extensions are
9926 -- enabled, unless the type doesn't have a primitive operations list
9927 -- (such as in the case of predefined types).
9929 if (not Is_Tagged_Type
(Obj_Type
)
9931 (not (Core_Extensions_Allowed
or Allow_Extensions
)
9932 or else No
(Primitive_Operations
(Obj_Type
))))
9933 or else Is_Incomplete_Type
(Obj_Type
)
9935 Obj_Type
:= Prev_Obj_Type
;
9940 Dup_Call_Node
: constant Node_Id
:= New_Copy
(New_Call_Node
);
9942 Prim_Result
: Boolean := False;
9945 if not CW_Test_Only
then
9947 Try_Primitive_Operation
9948 (Call_Node
=> New_Call_Node
,
9949 Node_To_Replace
=> Node_To_Replace
);
9951 -- Extension feature: In the case where the prefix is of an
9952 -- access type, and a primitive wasn't found for the designated
9953 -- type, then if the access type has primitives we attempt a
9954 -- prefixed call using one of its primitives. (It seems that
9955 -- this isn't quite right to give preference to the designated
9956 -- type in the case where both the access and designated types
9957 -- have homographic prefixed-view operations that could result
9958 -- in an ambiguity, but handling properly may be tricky. ???)
9960 if (Core_Extensions_Allowed
or Allow_Extensions
)
9961 and then not Prim_Result
9962 and then Is_Named_Access_Type
(Prev_Obj_Type
)
9963 and then Present
(Direct_Primitive_Operations
(Prev_Obj_Type
))
9965 -- Temporarily reset Obj_Type to the original access type
9967 Obj_Type
:= Prev_Obj_Type
;
9970 Try_Primitive_Operation
9971 (Call_Node
=> New_Call_Node
,
9972 Node_To_Replace
=> Node_To_Replace
);
9974 -- Restore Obj_Type to the designated type (is this really
9975 -- necessary, or should it only be done when Prim_Result is
9978 Obj_Type
:= Designated_Type
(Obj_Type
);
9982 -- Check if there is a class-wide subprogram covering the
9983 -- primitive. This check must be done even if a candidate
9984 -- was found in order to report ambiguous calls.
9986 if not Prim_Result
then
9988 Try_Class_Wide_Operation
9989 (Call_Node
=> New_Call_Node
,
9990 Node_To_Replace
=> Node_To_Replace
);
9992 -- If we found a primitive we search for class-wide subprograms
9993 -- using a duplicate of the call node (done to avoid missing its
9994 -- decoration if there is no ambiguity).
9998 Try_Class_Wide_Operation
9999 (Call_Node
=> Dup_Call_Node
,
10000 Node_To_Replace
=> Node_To_Replace
);
10003 end Try_One_Prefix_Interpretation
;
10005 -----------------------------
10006 -- Try_Primitive_Operation --
10007 -----------------------------
10009 function Try_Primitive_Operation
10010 (Call_Node
: Node_Id
;
10011 Node_To_Replace
: Node_Id
) return Boolean
10014 Prim_Op
: Entity_Id
;
10015 Matching_Op
: Entity_Id
:= Empty
;
10016 Prim_Op_Ref
: Node_Id
:= Empty
;
10018 Corr_Type
: Entity_Id
:= Empty
;
10019 -- If the prefix is a synchronized type, the controlling type of
10020 -- the primitive operation is the corresponding record type, else
10021 -- this is the object type itself.
10023 Success
: Boolean := False;
10025 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
;
10026 -- For tagged types the candidate interpretations are found in
10027 -- the list of primitive operations of the type and its ancestors.
10028 -- For formal tagged types we have to find the operations declared
10029 -- in the same scope as the type (including in the generic formal
10030 -- part) because the type itself carries no primitive operations,
10031 -- except for formal derived types that inherit the operations of
10032 -- the parent and progenitors.
10034 -- If the context is a generic subprogram body, the generic formals
10035 -- are visible by name, but are not in the entity list of the
10036 -- subprogram because that list starts with the subprogram formals.
10037 -- We retrieve the candidate operations from the generic declaration.
10039 function Extended_Primitive_Ops
(T
: Entity_Id
) return Elist_Id
;
10040 -- Prefix notation can also be used on operations that are not
10041 -- primitives of the type, but are declared in the same immediate
10042 -- declarative part, which can only mean the corresponding package
10043 -- body (see RM 4.1.3 (9.2/3)). If we are in that body we extend the
10044 -- list of primitives with body operations with the same name that
10045 -- may be candidates, so that Try_Primitive_Operations can examine
10046 -- them if no real primitive is found.
10048 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean;
10049 -- An operation that overrides an inherited operation in the private
10050 -- part of its package may be hidden, but if the inherited operation
10051 -- is visible a direct call to it will dispatch to the private one,
10052 -- which is therefore a valid candidate.
10054 function Names_Match
10055 (Obj_Type
: Entity_Id
;
10056 Prim_Op
: Entity_Id
;
10057 Subprog
: Entity_Id
) return Boolean;
10058 -- Return True if the names of Prim_Op and Subprog match. If Obj_Type
10059 -- is a protected type then compare also the original name of Prim_Op
10060 -- with the name of Subprog (since the expander may have added a
10061 -- prefix to its original name --see Exp_Ch9.Build_Selected_Name).
10063 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean;
10064 -- Verify that the prefix, dereferenced if need be, is a valid
10065 -- controlling argument in a call to Op. The remaining actuals
10066 -- are checked in the subsequent call to Analyze_One_Call.
10068 ------------------------------
10069 -- Collect_Generic_Type_Ops --
10070 ------------------------------
10072 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
is
10073 Bas
: constant Entity_Id
:= Base_Type
(T
);
10074 Candidates
: constant Elist_Id
:= New_Elmt_List
;
10076 Formal
: Entity_Id
;
10078 procedure Check_Candidate
;
10079 -- The operation is a candidate if its first parameter is a
10080 -- controlling operand of the desired type.
10082 -----------------------
10083 -- Check_Candidate; --
10084 -----------------------
10086 procedure Check_Candidate
is
10088 Formal
:= First_Formal
(Subp
);
10090 if Present
(Formal
)
10091 and then Is_Controlling_Formal
(Formal
)
10093 (Base_Type
(Etype
(Formal
)) = Bas
10095 (Is_Access_Type
(Etype
(Formal
))
10096 and then Designated_Type
(Etype
(Formal
)) = Bas
))
10098 Append_Elmt
(Subp
, Candidates
);
10100 end Check_Candidate
;
10102 -- Start of processing for Collect_Generic_Type_Ops
10105 if Is_Derived_Type
(T
) then
10106 return Primitive_Operations
(T
);
10108 elsif Ekind
(Scope
(T
)) in E_Procedure | E_Function
then
10110 -- Scan the list of generic formals to find subprograms
10111 -- that may have a first controlling formal of the type.
10113 if Nkind
(Unit_Declaration_Node
(Scope
(T
))) =
10114 N_Generic_Subprogram_Declaration
10121 First
(Generic_Formal_Declarations
10122 (Unit_Declaration_Node
(Scope
(T
))));
10123 while Present
(Decl
) loop
10124 if Nkind
(Decl
) in N_Formal_Subprogram_Declaration
then
10125 Subp
:= Defining_Entity
(Decl
);
10136 -- Scan the list of entities declared in the same scope as
10137 -- the type. In general this will be an open scope, given that
10138 -- the call we are analyzing can only appear within a generic
10139 -- declaration or body (either the one that declares T, or a
10142 -- For a subtype representing a generic actual type, go to the
10145 if Is_Generic_Actual_Type
(T
) then
10146 Subp
:= First_Entity
(Scope
(Base_Type
(T
)));
10148 Subp
:= First_Entity
(Scope
(T
));
10151 while Present
(Subp
) loop
10152 if Is_Overloadable
(Subp
) then
10156 Next_Entity
(Subp
);
10161 end Collect_Generic_Type_Ops
;
10163 ----------------------------
10164 -- Extended_Primitive_Ops --
10165 ----------------------------
10167 function Extended_Primitive_Ops
(T
: Entity_Id
) return Elist_Id
is
10168 Type_Scope
: constant Entity_Id
:= Scope
(T
);
10169 Op_List
: Elist_Id
:= Primitive_Operations
(T
);
10171 if Is_Package_Or_Generic_Package
(Type_Scope
)
10172 and then ((In_Package_Body
(Type_Scope
)
10173 and then In_Open_Scopes
(Type_Scope
)) or else In_Instance_Body
)
10175 -- Retrieve list of declarations of package body if possible
10178 The_Body
: constant Node_Id
:=
10179 Corresponding_Body
(Unit_Declaration_Node
(Type_Scope
));
10181 if Present
(The_Body
) then
10183 Body_Decls
: constant List_Id
:=
10184 Declarations
(Unit_Declaration_Node
(The_Body
));
10185 Op_Found
: Boolean := False;
10186 Op
: Entity_Id
:= Current_Entity
(Subprog
);
10188 while Present
(Op
) loop
10189 if Comes_From_Source
(Op
)
10190 and then Is_Overloadable
(Op
)
10192 -- Exclude overriding primitive operations of a
10193 -- type extension declared in the package body,
10194 -- to prevent duplicates in extended list.
10196 and then not Is_Primitive
(Op
)
10197 and then Is_List_Member
10198 (Unit_Declaration_Node
(Op
))
10199 and then List_Containing
10200 (Unit_Declaration_Node
(Op
)) = Body_Decls
10202 if not Op_Found
then
10203 -- Copy list of primitives so it is not
10204 -- affected for other uses.
10206 Op_List
:= New_Copy_Elist
(Op_List
);
10210 Append_Elmt
(Op
, Op_List
);
10213 Op
:= Homonym
(Op
);
10221 end Extended_Primitive_Ops
;
10223 ---------------------------
10224 -- Is_Private_Overriding --
10225 ---------------------------
10227 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean is
10228 Visible_Op
: Entity_Id
;
10231 -- The subprogram may be overloaded with both visible and private
10232 -- entities with the same name. We have to scan the chain of
10233 -- homonyms to determine whether there is a previous implicit
10234 -- declaration in the same scope that is overridden by the
10235 -- private candidate.
10237 Visible_Op
:= Homonym
(Op
);
10238 while Present
(Visible_Op
) loop
10239 if Scope
(Op
) /= Scope
(Visible_Op
) then
10242 elsif not Comes_From_Source
(Visible_Op
)
10243 and then Alias
(Visible_Op
) = Op
10245 -- If Visible_Op or what it overrides is not hidden, then we
10246 -- have found what we're looking for.
10248 if not Is_Hidden
(Visible_Op
)
10249 or else not Is_Hidden
(Overridden_Operation
(Op
))
10255 Visible_Op
:= Homonym
(Visible_Op
);
10259 end Is_Private_Overriding
;
10265 function Names_Match
10266 (Obj_Type
: Entity_Id
;
10267 Prim_Op
: Entity_Id
;
10268 Subprog
: Entity_Id
) return Boolean is
10270 -- Common case: exact match
10272 if Chars
(Prim_Op
) = Chars
(Subprog
) then
10275 -- For protected type primitives the expander may have built the
10276 -- name of the dispatching primitive prepending the type name to
10277 -- avoid conflicts with the name of the protected subprogram (see
10278 -- Exp_Ch9.Build_Selected_Name).
10280 elsif Is_Protected_Type
(Obj_Type
) then
10282 Present
(Original_Protected_Subprogram
(Prim_Op
))
10283 and then Chars
(Original_Protected_Subprogram
(Prim_Op
)) =
10286 -- In an instance, the selector name may be a generic actual that
10287 -- renames a primitive operation of the type of the prefix.
10289 elsif In_Instance
and then Present
(Current_Entity
(Subprog
)) then
10291 Subp
: constant Entity_Id
:= Current_Entity
(Subprog
);
10294 and then Is_Subprogram
(Subp
)
10295 and then Present
(Renamed_Entity
(Subp
))
10296 and then Is_Generic_Actual_Subprogram
(Subp
)
10297 and then Chars
(Renamed_Entity
(Subp
)) = Chars
(Prim_Op
)
10307 -----------------------------
10308 -- Valid_First_Argument_Of --
10309 -----------------------------
10311 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean is
10312 Typ
: Entity_Id
:= Etype
(First_Formal
(Op
));
10315 if Is_Concurrent_Type
(Typ
)
10316 and then Present
(Corresponding_Record_Type
(Typ
))
10318 Typ
:= Corresponding_Record_Type
(Typ
);
10321 -- Simple case. Object may be a subtype of the tagged type or may
10322 -- be the corresponding record of a synchronized type.
10324 return Obj_Type
= Typ
10325 or else Base_Type
(Obj_Type
) = Base_Type
(Typ
)
10326 or else Corr_Type
= Typ
10328 -- Object may be of a derived type whose parent has unknown
10329 -- discriminants, in which case the type matches the underlying
10330 -- record view of its base.
10333 (Has_Unknown_Discriminants
(Typ
)
10334 and then Typ
= Underlying_Record_View
(Base_Type
(Obj_Type
)))
10336 -- Prefix can be dereferenced
10339 (Is_Access_Type
(Corr_Type
)
10340 and then Designated_Type
(Corr_Type
) = Typ
)
10342 -- Formal is an access parameter, for which the object can
10343 -- provide an access.
10346 (Ekind
(Typ
) = E_Anonymous_Access_Type
10348 Base_Type
(Designated_Type
(Typ
)) = Base_Type
(Corr_Type
));
10349 end Valid_First_Argument_Of
;
10351 -- Start of processing for Try_Primitive_Operation
10354 -- Look for subprograms in the list of primitive operations. The name
10355 -- must be identical, and the kind of call indicates the expected
10356 -- kind of operation (function or procedure). If the type is a
10357 -- (tagged) synchronized type, the primitive ops are attached to the
10358 -- corresponding record (base) type.
10360 if Is_Concurrent_Type
(Obj_Type
) then
10361 if Present
(Corresponding_Record_Type
(Obj_Type
)) then
10362 Corr_Type
:= Base_Type
(Corresponding_Record_Type
(Obj_Type
));
10363 Elmt
:= First_Elmt
(Primitive_Operations
(Corr_Type
));
10365 Corr_Type
:= Obj_Type
;
10366 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
10369 elsif not Is_Generic_Type
(Obj_Type
) then
10370 Corr_Type
:= Obj_Type
;
10371 Elmt
:= First_Elmt
(Extended_Primitive_Ops
(Obj_Type
));
10374 Corr_Type
:= Obj_Type
;
10375 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
10378 while Present
(Elmt
) loop
10379 Prim_Op
:= Node
(Elmt
);
10381 if Names_Match
(Obj_Type
, Prim_Op
, Subprog
)
10382 and then Present
(First_Formal
(Prim_Op
))
10383 and then Valid_First_Argument_Of
(Prim_Op
)
10385 (Nkind
(Call_Node
) = N_Function_Call
)
10387 (Ekind
(Prim_Op
) = E_Function
)
10389 -- Ada 2005 (AI-251): If this primitive operation corresponds
10390 -- to an immediate ancestor interface there is no need to add
10391 -- it to the list of interpretations; the corresponding aliased
10392 -- primitive is also in this list of primitive operations and
10393 -- will be used instead.
10395 if (Present
(Interface_Alias
(Prim_Op
))
10396 and then Is_Ancestor
(Find_Dispatching_Type
10397 (Alias
(Prim_Op
)), Corr_Type
))
10399 -- Do not consider hidden primitives unless the type is in an
10400 -- open scope or we are within an instance, where visibility
10401 -- is known to be correct, or else if this is an overriding
10402 -- operation in the private part for an inherited operation.
10404 or else (Is_Hidden
(Prim_Op
)
10405 and then not Is_Immediately_Visible
(Obj_Type
)
10406 and then not In_Instance
10407 and then not Is_Private_Overriding
(Prim_Op
))
10412 Set_Etype
(Call_Node
, Any_Type
);
10413 Set_Is_Overloaded
(Call_Node
, False);
10415 if No
(Matching_Op
) then
10416 Prim_Op_Ref
:= New_Occurrence_Of
(Prim_Op
, Sloc
(Subprog
));
10417 Candidate
:= Prim_Op
;
10419 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
10421 Set_Name
(Call_Node
, Prim_Op_Ref
);
10427 Report
=> Report_Error
,
10428 Success
=> Success
,
10429 Skip_First
=> True);
10431 Matching_Op
:= Valid_Candidate
(Success
, Call_Node
, Prim_Op
);
10433 -- More than one interpretation, collect for subsequent
10434 -- disambiguation. If this is a procedure call and there
10435 -- is another match, report ambiguity now.
10441 Report
=> Report_Error
,
10442 Success
=> Success
,
10443 Skip_First
=> True);
10445 if Present
(Valid_Candidate
(Success
, Call_Node
, Prim_Op
))
10446 and then Nkind
(Call_Node
) /= N_Function_Call
10448 Error_Msg_NE
("ambiguous call to&", N
, Prim_Op
);
10449 Report_Ambiguity
(Matching_Op
);
10450 Report_Ambiguity
(Prim_Op
);
10451 Check_Ambiguous_Aggregate
(Call_Node
);
10461 if Present
(Matching_Op
) then
10462 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
10465 return Present
(Matching_Op
);
10466 end Try_Primitive_Operation
;
10468 ---------------------
10469 -- Valid_Candidate --
10470 ---------------------
10472 function Valid_Candidate
10473 (Success
: Boolean;
10475 Subp
: Entity_Id
) return Entity_Id
10477 Arr_Type
: Entity_Id
;
10478 Comp_Type
: Entity_Id
;
10481 -- If the subprogram is a valid interpretation, record it in global
10482 -- variable Subprog, to collect all possible overloadings.
10485 if Subp
/= Entity
(Subprog
) then
10486 Add_One_Interp
(Subprog
, Subp
, Etype
(Subp
));
10490 -- If the call may be an indexed call, retrieve component type of
10491 -- resulting expression, and add possible interpretation.
10494 Comp_Type
:= Empty
;
10496 if Nkind
(Call
) = N_Function_Call
10497 and then Nkind
(Parent
(N
)) = N_Indexed_Component
10498 and then Needs_One_Actual
(Subp
)
10500 if Is_Array_Type
(Etype
(Subp
)) then
10501 Arr_Type
:= Etype
(Subp
);
10503 elsif Is_Access_Type
(Etype
(Subp
))
10504 and then Is_Array_Type
(Designated_Type
(Etype
(Subp
)))
10506 Arr_Type
:= Designated_Type
(Etype
(Subp
));
10510 if Present
(Arr_Type
) then
10512 -- Verify that the actuals (excluding the object) match the types
10520 Actual
:= Next
(First_Actual
(Call
));
10521 Index
:= First_Index
(Arr_Type
);
10522 while Present
(Actual
) and then Present
(Index
) loop
10523 if not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
10528 Next_Actual
(Actual
);
10529 Next_Index
(Index
);
10533 and then No
(Index
)
10534 and then Present
(Arr_Type
)
10536 Comp_Type
:= Component_Type
(Arr_Type
);
10540 if Present
(Comp_Type
)
10541 and then Etype
(Subprog
) /= Comp_Type
10543 Add_One_Interp
(Subprog
, Subp
, Comp_Type
);
10547 if Etype
(Call
) /= Any_Type
then
10552 end Valid_Candidate
;
10554 -- Start of processing for Try_Object_Operation
10557 Analyze_Expression
(Obj
);
10559 -- Analyze the actuals if node is known to be a subprogram call
10561 if Is_Subprg_Call
and then N
= Name
(Parent
(N
)) then
10562 Actual
:= First
(Parameter_Associations
(Parent
(N
)));
10563 while Present
(Actual
) loop
10564 Analyze_Expression
(Actual
);
10569 -- Build a subprogram call node, using a copy of Obj as its first
10570 -- actual. This is a placeholder, to be replaced by an explicit
10571 -- dereference when needed.
10573 Transform_Object_Operation
10574 (Call_Node
=> New_Call_Node
,
10575 Node_To_Replace
=> Node_To_Replace
);
10577 Set_Etype
(New_Call_Node
, Any_Type
);
10578 Set_Etype
(Subprog
, Any_Type
);
10579 Set_Parent
(New_Call_Node
, Parent
(Node_To_Replace
));
10581 if not Is_Overloaded
(Obj
) then
10582 Try_One_Prefix_Interpretation
(Obj_Type
);
10589 Get_First_Interp
(Obj
, I
, It
);
10590 while Present
(It
.Nam
) loop
10591 Try_One_Prefix_Interpretation
(It
.Typ
);
10592 Get_Next_Interp
(I
, It
);
10597 if Etype
(New_Call_Node
) /= Any_Type
then
10599 -- No need to complete the tree transformations if we are only
10600 -- searching for conflicting class-wide subprograms
10602 if CW_Test_Only
then
10605 Complete_Object_Operation
10606 (Call_Node
=> New_Call_Node
,
10607 Node_To_Replace
=> Node_To_Replace
);
10611 elsif Present
(Candidate
) then
10613 -- The argument list is not type correct. Re-analyze with error
10614 -- reporting enabled, and use one of the possible candidates.
10615 -- In All_Errors_Mode, re-analyze all failed interpretations.
10617 if All_Errors_Mode
then
10618 Report_Error
:= True;
10619 if Try_Primitive_Operation
10620 (Call_Node
=> New_Call_Node
,
10621 Node_To_Replace
=> Node_To_Replace
)
10624 Try_Class_Wide_Operation
10625 (Call_Node
=> New_Call_Node
,
10626 Node_To_Replace
=> Node_To_Replace
)
10633 (N
=> New_Call_Node
,
10636 Success
=> Success
,
10637 Skip_First
=> True);
10639 -- The error may hot have been reported yet for overloaded
10640 -- prefixed calls, depending on the non-matching candidate,
10641 -- in which case provide a concise error now.
10643 if Serious_Errors_Detected
= 0 then
10645 ("cannot resolve prefixed call to primitive operation of&",
10650 -- No need for further errors
10655 -- There was no candidate operation, but Analyze_Selected_Component
10656 -- may continue the analysis so we need to undo the change possibly
10657 -- made to the Parent of N earlier by Transform_Object_Operation.
10660 Parent_Node
: constant Node_Id
:= Parent
(N
);
10663 if Node_To_Replace
= Parent_Node
then
10664 Remove
(First
(Parameter_Associations
(New_Call_Node
)));
10666 (Parameter_Associations
(New_Call_Node
), Parent_Node
);
10672 end Try_Object_Operation
;
10674 -------------------------
10675 -- Unresolved_Operator --
10676 -------------------------
10678 procedure Unresolved_Operator
(N
: Node_Id
) is
10679 L
: constant Node_Id
:=
10680 (if Nkind
(N
) in N_Binary_Op
then Left_Opnd
(N
) else Empty
);
10681 R
: constant Node_Id
:= Right_Opnd
(N
);
10686 -- Note that in the following messages, if the operand is overloaded we
10687 -- choose an arbitrary type to complain about, but that is probably more
10688 -- useful than not giving a type at all.
10690 if Nkind
(N
) in N_Unary_Op
then
10691 Error_Msg_Node_2
:= Etype
(R
);
10692 Error_Msg_N
("operator& not defined for}", N
);
10694 elsif Nkind
(N
) in N_Binary_Op
then
10695 if not Is_Overloaded
(L
)
10696 and then not Is_Overloaded
(R
)
10697 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
10699 Error_Msg_Node_2
:= First_Subtype
(Etype
(R
));
10700 Error_Msg_N
("there is no applicable operator& for}", N
);
10703 -- Another attempt to find a fix: one of the candidate
10704 -- interpretations may not be use-visible. This has
10705 -- already been checked for predefined operators, so
10706 -- we examine only user-defined functions.
10708 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
10710 while Present
(Op_Id
) loop
10711 if Ekind
(Op_Id
) /= E_Operator
10712 and then Is_Overloadable
(Op_Id
)
10713 and then not Is_Immediately_Visible
(Op_Id
)
10714 and then not In_Use
(Scope
(Op_Id
))
10715 and then not Is_Abstract_Subprogram
(Op_Id
)
10716 and then not Is_Hidden
(Op_Id
)
10717 and then Ekind
(Scope
(Op_Id
)) = E_Package
10718 and then Has_Compatible_Type
(L
, Etype
(First_Formal
(Op_Id
)))
10719 and then Present
(Next_Formal
(First_Formal
(Op_Id
)))
10721 Has_Compatible_Type
10722 (R
, Etype
(Next_Formal
(First_Formal
(Op_Id
))))
10724 Error_Msg_N
("no legal interpretation for operator&", N
);
10725 Error_Msg_NE
("\use clause on& would make operation legal",
10730 Op_Id
:= Homonym
(Op_Id
);
10734 Error_Msg_N
("invalid operand types for operator&", N
);
10736 if Nkind
(N
) /= N_Op_Concat
then
10737 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
10738 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
10740 -- For multiplication and division operators with
10741 -- a fixed-point operand and an integer operand,
10742 -- indicate that the integer operand should be of
10745 if Nkind
(N
) in N_Op_Multiply | N_Op_Divide
10746 and then Is_Fixed_Point_Type
(Etype
(L
))
10747 and then Is_Integer_Type
(Etype
(R
))
10749 Error_Msg_N
("\convert right operand to `Integer`", N
);
10751 elsif Nkind
(N
) = N_Op_Multiply
10752 and then Is_Fixed_Point_Type
(Etype
(R
))
10753 and then Is_Integer_Type
(Etype
(L
))
10755 Error_Msg_N
("\convert left operand to `Integer`", N
);
10758 -- For concatenation operators it is more difficult to
10759 -- determine which is the wrong operand. It is worth
10760 -- flagging explicitly an access type, for those who
10761 -- might think that a dereference happens here.
10763 elsif Is_Access_Type
(Etype
(L
)) then
10764 Error_Msg_N
("\left operand is access type", N
);
10766 elsif Is_Access_Type
(Etype
(R
)) then
10767 Error_Msg_N
("\right operand is access type", N
);
10772 end Unresolved_Operator
;
10778 procedure wpo
(T
: Entity_Id
) is
10783 if not Is_Tagged_Type
(T
) then
10787 E
:= First_Elmt
(Primitive_Operations
(Base_Type
(T
)));
10788 while Present
(E
) loop
10790 Write_Int
(Int
(Op
));
10791 Write_Str
(" === ");
10792 Write_Name
(Chars
(Op
));
10793 Write_Str
(" in ");
10794 Write_Name
(Chars
(Scope
(Op
)));