1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Util
; use Exp_Util
;
33 with Fname
; use Fname
;
34 with Itypes
; use Itypes
;
36 with Lib
.Xref
; use Lib
.Xref
;
37 with Namet
; use Namet
;
38 with Namet
.Sp
; use Namet
.Sp
;
39 with Nlists
; use Nlists
;
40 with Nmake
; use Nmake
;
42 with Output
; use Output
;
43 with Restrict
; use Restrict
;
44 with Rident
; use Rident
;
46 with Sem_Aux
; use Sem_Aux
;
47 with Sem_Case
; use Sem_Case
;
48 with Sem_Cat
; use Sem_Cat
;
49 with Sem_Ch3
; use Sem_Ch3
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch8
; use Sem_Ch8
;
52 with Sem_Dim
; use Sem_Dim
;
53 with Sem_Disp
; use Sem_Disp
;
54 with Sem_Dist
; use Sem_Dist
;
55 with Sem_Eval
; use Sem_Eval
;
56 with Sem_Res
; use Sem_Res
;
57 with Sem_Type
; use Sem_Type
;
58 with Sem_Util
; use Sem_Util
;
59 with Sem_Warn
; use Sem_Warn
;
60 with Stand
; use Stand
;
61 with Sinfo
; use Sinfo
;
62 with Snames
; use Snames
;
63 with Tbuild
; use Tbuild
;
64 with Uintp
; use Uintp
;
66 package body Sem_Ch4
is
68 -- Tables which speed up the identification of dangerous calls to Ada 2012
69 -- functions with writable actuals (AI05-0144).
71 -- The following table enumerates the Ada constructs which may evaluate in
72 -- arbitrary order. It does not cover all the language constructs which can
73 -- be evaluated in arbitrary order but the subset needed for AI05-0144.
75 Has_Arbitrary_Evaluation_Order
: constant array (Node_Kind
) of Boolean :=
77 N_Assignment_Statement
=> True,
78 N_Entry_Call_Statement
=> True,
79 N_Extension_Aggregate
=> True,
80 N_Full_Type_Declaration
=> True,
81 N_Indexed_Component
=> True,
82 N_Object_Declaration
=> True,
86 N_Array_Type_Definition
=> True,
87 N_Membership_Test
=> True,
89 N_Subprogram_Call
=> True,
92 -- The following table enumerates the nodes on which we stop climbing when
93 -- locating the outermost Ada construct that can be evaluated in arbitrary
96 Stop_Subtree_Climbing
: constant array (Node_Kind
) of Boolean :=
98 N_Assignment_Statement
=> True,
99 N_Entry_Call_Statement
=> True,
100 N_Extended_Return_Statement
=> True,
101 N_Extension_Aggregate
=> True,
102 N_Full_Type_Declaration
=> True,
103 N_Object_Declaration
=> True,
104 N_Object_Renaming_Declaration
=> True,
105 N_Package_Specification
=> True,
107 N_Procedure_Call_Statement
=> True,
108 N_Simple_Return_Statement
=> True,
109 N_Has_Condition
=> True,
112 -----------------------
113 -- Local Subprograms --
114 -----------------------
116 procedure Analyze_Concatenation_Rest
(N
: Node_Id
);
117 -- Does the "rest" of the work of Analyze_Concatenation, after the left
118 -- operand has been analyzed. See Analyze_Concatenation for details.
120 procedure Analyze_Expression
(N
: Node_Id
);
121 -- For expressions that are not names, this is just a call to analyze. If
122 -- the expression is a name, it may be a call to a parameterless function,
123 -- and if so must be converted into an explicit call node and analyzed as
124 -- such. This deproceduring must be done during the first pass of overload
125 -- resolution, because otherwise a procedure call with overloaded actuals
126 -- may fail to resolve.
128 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
);
129 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call is an
130 -- operator name or an expanded name whose selector is an operator name,
131 -- and one possible interpretation is as a predefined operator.
133 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
);
134 -- If the prefix of a selected_component is overloaded, the proper
135 -- interpretation that yields a record type with the proper selector
136 -- name must be selected.
138 procedure Analyze_User_Defined_Binary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
139 -- Procedure to analyze a user defined binary operator, which is resolved
140 -- like a function, but instead of a list of actuals it is presented
141 -- with the left and right operands of an operator node.
143 procedure Analyze_User_Defined_Unary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
144 -- Procedure to analyze a user defined unary operator, which is resolved
145 -- like a function, but instead of a list of actuals, it is presented with
146 -- the operand of the operator node.
148 procedure Ambiguous_Operands
(N
: Node_Id
);
149 -- For equality, membership, and comparison operators with overloaded
150 -- arguments, list possible interpretations.
152 procedure Analyze_One_Call
156 Success
: out Boolean;
157 Skip_First
: Boolean := False);
158 -- Check one interpretation of an overloaded subprogram name for
159 -- compatibility with the types of the actuals in a call. If there is a
160 -- single interpretation which does not match, post error if Report is
163 -- Nam is the entity that provides the formals against which the actuals
164 -- are checked. Nam is either the name of a subprogram, or the internal
165 -- subprogram type constructed for an access_to_subprogram. If the actuals
166 -- are compatible with Nam, then Nam is added to the list of candidate
167 -- interpretations for N, and Success is set to True.
169 -- The flag Skip_First is used when analyzing a call that was rewritten
170 -- from object notation. In this case the first actual may have to receive
171 -- an explicit dereference, depending on the first formal of the operation
172 -- being called. The caller will have verified that the object is legal
173 -- for the call. If the remaining parameters match, the first parameter
174 -- will rewritten as a dereference if needed, prior to completing analysis.
176 procedure Check_Misspelled_Selector
179 -- Give possible misspelling message if Sel seems likely to be a mis-
180 -- spelling of one of the selectors of the Prefix. This is called by
181 -- Analyze_Selected_Component after producing an invalid selector error
184 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean;
185 -- Verify that type T is declared in scope S. Used to find interpretations
186 -- for operators given by expanded names. This is abstracted as a separate
187 -- function to handle extensions to System, where S is System, but T is
188 -- declared in the extension.
190 procedure Find_Arithmetic_Types
194 -- L and R are the operands of an arithmetic operator. Find consistent
195 -- pairs of interpretations for L and R that have a numeric type consistent
196 -- with the semantics of the operator.
198 procedure Find_Comparison_Types
202 -- L and R are operands of a comparison operator. Find consistent pairs of
203 -- interpretations for L and R.
205 procedure Find_Concatenation_Types
209 -- For the four varieties of concatenation
211 procedure Find_Equality_Types
215 -- Ditto for equality operators
217 procedure Find_Boolean_Types
221 -- Ditto for binary logical operations
223 procedure Find_Negation_Types
227 -- Find consistent interpretation for operand of negation operator
229 procedure Find_Non_Universal_Interpretations
234 -- For equality and comparison operators, the result is always boolean,
235 -- and the legality of the operation is determined from the visibility
236 -- of the operand types. If one of the operands has a universal interpre-
237 -- tation, the legality check uses some compatible non-universal
238 -- interpretation of the other operand. N can be an operator node, or
239 -- a function call whose name is an operator designator. Any_Access, which
240 -- is the initial type of the literal NULL, is a universal type for the
241 -- purpose of this routine.
243 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean;
244 -- Find candidate interpretations for the name Obj.Proc when it appears
245 -- in a subprogram renaming declaration.
247 procedure Find_Unary_Types
251 -- Unary arithmetic types: plus, minus, abs
253 procedure Check_Arithmetic_Pair
257 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid types
258 -- for left and right operand. Determine whether they constitute a valid
259 -- pair for the given operator, and record the corresponding interpretation
260 -- of the operator node. The node N may be an operator node (the usual
261 -- case) or a function call whose prefix is an operator designator. In
262 -- both cases Op_Id is the operator name itself.
264 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
);
265 -- Give detailed information on overloaded call where none of the
266 -- interpretations match. N is the call node, Nam the designator for
267 -- the overloaded entity being called.
269 function Junk_Operand
(N
: Node_Id
) return Boolean;
270 -- Test for an operand that is an inappropriate entity (e.g. a package
271 -- name or a label). If so, issue an error message and return True. If
272 -- the operand is not an inappropriate entity kind, return False.
274 procedure Operator_Check
(N
: Node_Id
);
275 -- Verify that an operator has received some valid interpretation. If none
276 -- was found, determine whether a use clause would make the operation
277 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
278 -- every type compatible with the operator, even if the operator for the
279 -- type is not directly visible. The routine uses this type to emit a more
280 -- informative message.
282 function Process_Implicit_Dereference_Prefix
284 P
: Node_Id
) return Entity_Id
;
285 -- Called when P is the prefix of an implicit dereference, denoting an
286 -- object E. The function returns the designated type of the prefix, taking
287 -- into account that the designated type of an anonymous access type may be
288 -- a limited view, when the non-limited view is visible.
290 -- If in semantics only mode (-gnatc or generic), the function also records
291 -- that the prefix is a reference to E, if any. Normally, such a reference
292 -- is generated only when the implicit dereference is expanded into an
293 -- explicit one, but for consistency we must generate the reference when
294 -- expansion is disabled as well.
296 procedure Remove_Abstract_Operations
(N
: Node_Id
);
297 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
298 -- operation is not a candidate interpretation.
300 function Try_Container_Indexing
303 Exprs
: List_Id
) return Boolean;
304 -- AI05-0139: Generalized indexing to support iterators over containers
306 function Try_Indexed_Call
310 Skip_First
: Boolean) return Boolean;
311 -- If a function has defaults for all its actuals, a call to it may in fact
312 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
313 -- interpretation as an indexing, prior to analysis as a call. If both are
314 -- possible, the node is overloaded with both interpretations (same symbol
315 -- but two different types). If the call is written in prefix form, the
316 -- prefix becomes the first parameter in the call, and only the remaining
317 -- actuals must be checked for the presence of defaults.
319 function Try_Indirect_Call
322 Typ
: Entity_Id
) return Boolean;
323 -- Similarly, a function F that needs no actuals can return an access to a
324 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
325 -- the call may be overloaded with both interpretations.
327 function Try_Object_Operation
329 CW_Test_Only
: Boolean := False) return Boolean;
330 -- Ada 2005 (AI-252): Support the object.operation notation. If node N
331 -- is a call in this notation, it is transformed into a normal subprogram
332 -- call where the prefix is a parameter, and True is returned. If node
333 -- N is not of this form, it is unchanged, and False is returned. If
334 -- CW_Test_Only is true then N is an N_Selected_Component node which
335 -- is part of a call to an entry or procedure of a tagged concurrent
336 -- type and this routine is invoked to search for class-wide subprograms
337 -- conflicting with the target entity.
339 procedure wpo
(T
: Entity_Id
);
340 pragma Warnings
(Off
, wpo
);
341 -- Used for debugging: obtain list of primitive operations even if
342 -- type is not frozen and dispatch table is not built yet.
344 ------------------------
345 -- Ambiguous_Operands --
346 ------------------------
348 procedure Ambiguous_Operands
(N
: Node_Id
) is
349 procedure List_Operand_Interps
(Opnd
: Node_Id
);
351 --------------------------
352 -- List_Operand_Interps --
353 --------------------------
355 procedure List_Operand_Interps
(Opnd
: Node_Id
) is
360 if Is_Overloaded
(Opnd
) then
361 if Nkind
(Opnd
) in N_Op
then
364 elsif Nkind
(Opnd
) = N_Function_Call
then
367 elsif Ada_Version
>= Ada_2012
then
373 Get_First_Interp
(Opnd
, I
, It
);
374 while Present
(It
.Nam
) loop
375 if Has_Implicit_Dereference
(It
.Typ
) then
377 ("can be interpreted as implicit dereference", Opnd
);
381 Get_Next_Interp
(I
, It
);
392 if Opnd
= Left_Opnd
(N
) then
394 ("\left operand has the following interpretations", N
);
397 ("\right operand has the following interpretations", N
);
401 List_Interps
(Nam
, Err
);
402 end List_Operand_Interps
;
404 -- Start of processing for Ambiguous_Operands
407 if Nkind
(N
) in N_Membership_Test
then
408 Error_Msg_N
("ambiguous operands for membership", N
);
410 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
) then
411 Error_Msg_N
("ambiguous operands for equality", N
);
414 Error_Msg_N
("ambiguous operands for comparison", N
);
417 if All_Errors_Mode
then
418 List_Operand_Interps
(Left_Opnd
(N
));
419 List_Operand_Interps
(Right_Opnd
(N
));
421 Error_Msg_N
("\use -gnatf switch for details", N
);
423 end Ambiguous_Operands
;
425 -----------------------
426 -- Analyze_Aggregate --
427 -----------------------
429 -- Most of the analysis of Aggregates requires that the type be known,
430 -- and is therefore put off until resolution.
432 procedure Analyze_Aggregate
(N
: Node_Id
) is
434 if No
(Etype
(N
)) then
435 Set_Etype
(N
, Any_Composite
);
437 end Analyze_Aggregate
;
439 -----------------------
440 -- Analyze_Allocator --
441 -----------------------
443 procedure Analyze_Allocator
(N
: Node_Id
) is
444 Loc
: constant Source_Ptr
:= Sloc
(N
);
445 Sav_Errs
: constant Nat
:= Serious_Errors_Detected
;
446 E
: Node_Id
:= Expression
(N
);
447 Acc_Type
: Entity_Id
;
454 Check_SPARK_05_Restriction
("allocator is not allowed", N
);
456 -- Deal with allocator restrictions
458 -- In accordance with H.4(7), the No_Allocators restriction only applies
459 -- to user-written allocators. The same consideration applies to the
460 -- No_Standard_Allocators_Before_Elaboration restriction.
462 if Comes_From_Source
(N
) then
463 Check_Restriction
(No_Allocators
, N
);
465 -- Processing for No_Standard_Allocators_After_Elaboration, loop to
466 -- look at enclosing context, checking task/main subprogram case.
470 while Present
(P
) loop
472 -- For the task case we need a handled sequence of statements,
473 -- where the occurrence of the allocator is within the statements
474 -- and the parent is a task body
476 if Nkind
(P
) = N_Handled_Sequence_Of_Statements
477 and then Is_List_Member
(C
)
478 and then List_Containing
(C
) = Statements
(P
)
480 Onode
:= Original_Node
(Parent
(P
));
482 -- Check for allocator within task body, this is a definite
483 -- violation of No_Allocators_After_Elaboration we can detect
486 if Nkind
(Onode
) = N_Task_Body
then
488 (No_Standard_Allocators_After_Elaboration
, N
);
493 -- The other case is appearance in a subprogram body. This is
494 -- a violation if this is a library level subprogram with no
495 -- parameters. Note that this is now a static error even if the
496 -- subprogram is not the main program (this is a change, in an
497 -- earlier version only the main program was affected, and the
498 -- check had to be done in the binder.
500 if Nkind
(P
) = N_Subprogram_Body
501 and then Nkind
(Parent
(P
)) = N_Compilation_Unit
502 and then No
(Parameter_Specifications
(Specification
(P
)))
505 (No_Standard_Allocators_After_Elaboration
, N
);
513 -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
514 -- any. The expected type for the name is any type. A non-overloading
515 -- rule then requires it to be of a type descended from
516 -- System.Storage_Pools.Subpools.Subpool_Handle.
518 -- This isn't exactly what the AI says, but it seems to be the right
519 -- rule. The AI should be fixed.???
522 Subpool
: constant Node_Id
:= Subpool_Handle_Name
(N
);
525 if Present
(Subpool
) then
528 if Is_Overloaded
(Subpool
) then
529 Error_Msg_N
("ambiguous subpool handle", Subpool
);
532 -- Check that Etype (Subpool) is descended from Subpool_Handle
538 -- Analyze the qualified expression or subtype indication
540 if Nkind
(E
) = N_Qualified_Expression
then
541 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
542 Set_Etype
(Acc_Type
, Acc_Type
);
543 Find_Type
(Subtype_Mark
(E
));
545 -- Analyze the qualified expression, and apply the name resolution
546 -- rule given in 4.7(3).
549 Type_Id
:= Etype
(E
);
550 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
552 -- A qualified expression requires an exact match of the type,
553 -- class-wide matching is not allowed.
555 -- if Is_Class_Wide_Type (Type_Id)
556 -- and then Base_Type
557 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
559 -- Wrong_Type (Expression (E), Type_Id);
562 -- We don't analyze the qualified expression itself because it's
563 -- part of the allocator. It is fully analyzed and resolved when
564 -- the allocator is resolved with the context type.
566 Set_Etype
(E
, Type_Id
);
568 -- Case where allocator has a subtype indication
573 Base_Typ
: Entity_Id
;
576 -- If the allocator includes a N_Subtype_Indication then a
577 -- constraint is present, otherwise the node is a subtype mark.
578 -- Introduce an explicit subtype declaration into the tree
579 -- defining some anonymous subtype and rewrite the allocator to
580 -- use this subtype rather than the subtype indication.
582 -- It is important to introduce the explicit subtype declaration
583 -- so that the bounds of the subtype indication are attached to
584 -- the tree in case the allocator is inside a generic unit.
586 -- Finally, if there is no subtype indication and the type is
587 -- a tagged unconstrained type with discriminants, the designated
588 -- object is constrained by their default values, and it is
589 -- simplest to introduce an explicit constraint now. In some cases
590 -- this is done during expansion, but freeze actions are certain
591 -- to be emitted in the proper order if constraint is explicit.
593 if Is_Entity_Name
(E
) and then Expander_Active
then
595 Type_Id
:= Entity
(E
);
597 if Is_Tagged_Type
(Type_Id
)
598 and then Has_Discriminants
(Type_Id
)
599 and then not Is_Constrained
(Type_Id
)
602 (Discriminant_Default_Value
603 (First_Discriminant
(Type_Id
)))
606 Constr
: constant List_Id
:= New_List
;
607 Loc
: constant Source_Ptr
:= Sloc
(E
);
608 Discr
: Entity_Id
:= First_Discriminant
(Type_Id
);
611 if Present
(Discriminant_Default_Value
(Discr
)) then
612 while Present
(Discr
) loop
613 Append
(Discriminant_Default_Value
(Discr
), Constr
);
614 Next_Discriminant
(Discr
);
618 Make_Subtype_Indication
(Loc
,
619 Subtype_Mark
=> New_Occurrence_Of
(Type_Id
, Loc
),
621 Make_Index_Or_Discriminant_Constraint
(Loc
,
622 Constraints
=> Constr
)));
628 if Nkind
(E
) = N_Subtype_Indication
then
630 -- A constraint is only allowed for a composite type in Ada
631 -- 95. In Ada 83, a constraint is also allowed for an
632 -- access-to-composite type, but the constraint is ignored.
634 Find_Type
(Subtype_Mark
(E
));
635 Base_Typ
:= Entity
(Subtype_Mark
(E
));
637 if Is_Elementary_Type
(Base_Typ
) then
638 if not (Ada_Version
= Ada_83
639 and then Is_Access_Type
(Base_Typ
))
641 Error_Msg_N
("constraint not allowed here", E
);
643 if Nkind
(Constraint
(E
)) =
644 N_Index_Or_Discriminant_Constraint
646 Error_Msg_N
-- CODEFIX
647 ("\if qualified expression was meant, " &
648 "use apostrophe", Constraint
(E
));
652 -- Get rid of the bogus constraint:
654 Rewrite
(E
, New_Copy_Tree
(Subtype_Mark
(E
)));
655 Analyze_Allocator
(N
);
659 if Expander_Active
then
660 Def_Id
:= Make_Temporary
(Loc
, 'S');
663 Make_Subtype_Declaration
(Loc
,
664 Defining_Identifier
=> Def_Id
,
665 Subtype_Indication
=> Relocate_Node
(E
)));
667 if Sav_Errs
/= Serious_Errors_Detected
668 and then Nkind
(Constraint
(E
)) =
669 N_Index_Or_Discriminant_Constraint
671 Error_Msg_N
-- CODEFIX
672 ("if qualified expression was meant, "
673 & "use apostrophe!", Constraint
(E
));
676 E
:= New_Occurrence_Of
(Def_Id
, Loc
);
677 Rewrite
(Expression
(N
), E
);
681 Type_Id
:= Process_Subtype
(E
, N
);
682 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
683 Set_Etype
(Acc_Type
, Acc_Type
);
684 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
685 Check_Fully_Declared
(Type_Id
, N
);
687 -- Ada 2005 (AI-231): If the designated type is itself an access
688 -- type that excludes null, its default initialization will
689 -- be a null object, and we can insert an unconditional raise
690 -- before the allocator.
692 -- Ada 2012 (AI-104): A not null indication here is altogether
695 if Can_Never_Be_Null
(Type_Id
) then
697 Not_Null_Check
: constant Node_Id
:=
698 Make_Raise_Constraint_Error
(Sloc
(E
),
699 Reason
=> CE_Null_Not_Allowed
);
702 if Expander_Active
then
703 Insert_Action
(N
, Not_Null_Check
);
704 Analyze
(Not_Null_Check
);
706 elsif Warn_On_Ada_2012_Compatibility
then
708 ("null value not allowed here in Ada 2012?y?", E
);
713 -- Check for missing initialization. Skip this check if we already
714 -- had errors on analyzing the allocator, since in that case these
715 -- are probably cascaded errors.
717 if not Is_Definite_Subtype
(Type_Id
)
718 and then Serious_Errors_Detected
= Sav_Errs
720 -- The build-in-place machinery may produce an allocator when
721 -- the designated type is indefinite but the underlying type is
722 -- not. In this case the unknown discriminants are meaningless
723 -- and should not trigger error messages. Check the parent node
724 -- because the allocator is marked as coming from source.
726 if Present
(Underlying_Type
(Type_Id
))
727 and then Is_Definite_Subtype
(Underlying_Type
(Type_Id
))
728 and then not Comes_From_Source
(Parent
(N
))
732 elsif Is_Class_Wide_Type
(Type_Id
) then
734 ("initialization required in class-wide allocation", N
);
737 if Ada_Version
< Ada_2005
738 and then Is_Limited_Type
(Type_Id
)
740 Error_Msg_N
("unconstrained allocation not allowed", N
);
742 if Is_Array_Type
(Type_Id
) then
744 ("\constraint with array bounds required", N
);
746 elsif Has_Unknown_Discriminants
(Type_Id
) then
749 else pragma Assert
(Has_Discriminants
(Type_Id
));
751 ("\constraint with discriminant values required", N
);
754 -- Limited Ada 2005 and general non-limited case
758 ("uninitialized unconstrained allocation not "
761 if Is_Array_Type
(Type_Id
) then
763 ("\qualified expression or constraint with "
764 & "array bounds required", N
);
766 elsif Has_Unknown_Discriminants
(Type_Id
) then
767 Error_Msg_N
("\qualified expression required", N
);
769 else pragma Assert
(Has_Discriminants
(Type_Id
));
771 ("\qualified expression or constraint with "
772 & "discriminant values required", N
);
780 if Is_Abstract_Type
(Type_Id
) then
781 Error_Msg_N
("cannot allocate abstract object", E
);
784 if Has_Task
(Designated_Type
(Acc_Type
)) then
785 Check_Restriction
(No_Tasking
, N
);
786 Check_Restriction
(Max_Tasks
, N
);
787 Check_Restriction
(No_Task_Allocators
, N
);
790 -- Check restriction against dynamically allocated protected objects
792 if Has_Protected
(Designated_Type
(Acc_Type
)) then
793 Check_Restriction
(No_Protected_Type_Allocators
, N
);
796 -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
797 -- type is nested, and the designated type needs finalization. The rule
798 -- is conservative in that class-wide types need finalization.
800 if Needs_Finalization
(Designated_Type
(Acc_Type
))
801 and then not Is_Library_Level_Entity
(Acc_Type
)
803 Check_Restriction
(No_Nested_Finalization
, N
);
806 -- Check that an allocator of a nested access type doesn't create a
807 -- protected object when restriction No_Local_Protected_Objects applies.
809 if Has_Protected
(Designated_Type
(Acc_Type
))
810 and then not Is_Library_Level_Entity
(Acc_Type
)
812 Check_Restriction
(No_Local_Protected_Objects
, N
);
815 -- Likewise for No_Local_Timing_Events
817 if Has_Timing_Event
(Designated_Type
(Acc_Type
))
818 and then not Is_Library_Level_Entity
(Acc_Type
)
820 Check_Restriction
(No_Local_Timing_Events
, N
);
823 -- If the No_Streams restriction is set, check that the type of the
824 -- object is not, and does not contain, any subtype derived from
825 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
826 -- Has_Stream just for efficiency reasons. There is no point in
827 -- spending time on a Has_Stream check if the restriction is not set.
829 if Restriction_Check_Required
(No_Streams
) then
830 if Has_Stream
(Designated_Type
(Acc_Type
)) then
831 Check_Restriction
(No_Streams
, N
);
835 Set_Etype
(N
, Acc_Type
);
837 if not Is_Library_Level_Entity
(Acc_Type
) then
838 Check_Restriction
(No_Local_Allocators
, N
);
841 if Serious_Errors_Detected
> Sav_Errs
then
842 Set_Error_Posted
(N
);
843 Set_Etype
(N
, Any_Type
);
845 end Analyze_Allocator
;
847 ---------------------------
848 -- Analyze_Arithmetic_Op --
849 ---------------------------
851 procedure Analyze_Arithmetic_Op
(N
: Node_Id
) is
852 L
: constant Node_Id
:= Left_Opnd
(N
);
853 R
: constant Node_Id
:= Right_Opnd
(N
);
857 Candidate_Type
:= Empty
;
858 Analyze_Expression
(L
);
859 Analyze_Expression
(R
);
861 -- If the entity is already set, the node is the instantiation of a
862 -- generic node with a non-local reference, or was manufactured by a
863 -- call to Make_Op_xxx. In either case the entity is known to be valid,
864 -- and we do not need to collect interpretations, instead we just get
865 -- the single possible interpretation.
869 if Present
(Op_Id
) then
870 if Ekind
(Op_Id
) = E_Operator
then
872 if Nkind_In
(N
, N_Op_Divide
, N_Op_Mod
, N_Op_Multiply
, N_Op_Rem
)
873 and then Treat_Fixed_As_Integer
(N
)
877 Set_Etype
(N
, Any_Type
);
878 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
882 Set_Etype
(N
, Any_Type
);
883 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
886 -- Entity is not already set, so we do need to collect interpretations
889 Set_Etype
(N
, Any_Type
);
891 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
892 while Present
(Op_Id
) loop
893 if Ekind
(Op_Id
) = E_Operator
894 and then Present
(Next_Entity
(First_Entity
(Op_Id
)))
896 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
898 -- The following may seem superfluous, because an operator cannot
899 -- be generic, but this ignores the cleverness of the author of
902 elsif Is_Overloadable
(Op_Id
) then
903 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
906 Op_Id
:= Homonym
(Op_Id
);
911 Check_Function_Writable_Actuals
(N
);
912 end Analyze_Arithmetic_Op
;
918 -- Function, procedure, and entry calls are checked here. The Name in
919 -- the call may be overloaded. The actuals have been analyzed and may
920 -- themselves be overloaded. On exit from this procedure, the node N
921 -- may have zero, one or more interpretations. In the first case an
922 -- error message is produced. In the last case, the node is flagged
923 -- as overloaded and the interpretations are collected in All_Interp.
925 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
926 -- the type-checking is similar to that of other calls.
928 procedure Analyze_Call
(N
: Node_Id
) is
929 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
934 Success
: Boolean := False;
936 Deref
: Boolean := False;
937 -- Flag indicates whether an interpretation of the prefix is a
938 -- parameterless call that returns an access_to_subprogram.
940 procedure Check_Mixed_Parameter_And_Named_Associations
;
941 -- Check that parameter and named associations are not mixed. This is
942 -- a restriction in SPARK mode.
944 procedure Check_Writable_Actuals
(N
: Node_Id
);
945 -- If the call has out or in-out parameters then mark its outermost
946 -- enclosing construct as a node on which the writable actuals check
947 -- must be performed.
949 function Name_Denotes_Function
return Boolean;
950 -- If the type of the name is an access to subprogram, this may be the
951 -- type of a name, or the return type of the function being called. If
952 -- the name is not an entity then it can denote a protected function.
953 -- Until we distinguish Etype from Return_Type, we must use this routine
954 -- to resolve the meaning of the name in the call.
956 procedure No_Interpretation
;
957 -- Output error message when no valid interpretation exists
959 --------------------------------------------------
960 -- Check_Mixed_Parameter_And_Named_Associations --
961 --------------------------------------------------
963 procedure Check_Mixed_Parameter_And_Named_Associations
is
965 Named_Seen
: Boolean;
970 Actual
:= First
(Actuals
);
971 while Present
(Actual
) loop
972 case Nkind
(Actual
) is
973 when N_Parameter_Association
=>
975 Check_SPARK_05_Restriction
976 ("named association cannot follow positional one",
987 end Check_Mixed_Parameter_And_Named_Associations
;
989 ----------------------------
990 -- Check_Writable_Actuals --
991 ----------------------------
993 -- The identification of conflicts in calls to functions with writable
994 -- actuals is performed in the analysis phase of the front end to ensure
995 -- that it reports exactly the same errors compiling with and without
996 -- expansion enabled. It is performed in two stages:
998 -- 1) When a call to a function with out-mode parameters is found,
999 -- we climb to the outermost enclosing construct that can be
1000 -- evaluated in arbitrary order and we mark it with the flag
1003 -- 2) When the analysis of the marked node is complete, we traverse
1004 -- its decorated subtree searching for conflicts (see function
1005 -- Sem_Util.Check_Function_Writable_Actuals).
1007 -- The unique exception to this general rule is for aggregates, since
1008 -- their analysis is performed by the front end in the resolution
1009 -- phase. For aggregates we do not climb to their enclosing construct:
1010 -- we restrict the analysis to the subexpressions initializing the
1011 -- aggregate components.
1013 -- This implies that the analysis of expressions containing aggregates
1014 -- is not complete, since there may be conflicts on writable actuals
1015 -- involving subexpressions of the enclosing logical or arithmetic
1016 -- expressions. However, we cannot wait and perform the analysis when
1017 -- the whole subtree is resolved, since the subtrees may be transformed,
1018 -- thus adding extra complexity and computation cost to identify and
1019 -- report exactly the same errors compiling with and without expansion
1022 procedure Check_Writable_Actuals
(N
: Node_Id
) is
1024 if Comes_From_Source
(N
)
1025 and then Present
(Get_Subprogram_Entity
(N
))
1026 and then Has_Out_Or_In_Out_Parameter
(Get_Subprogram_Entity
(N
))
1028 -- For procedures and entries there is no need to climb since
1029 -- we only need to check if the actuals of this call invoke
1030 -- functions whose out-mode parameters overlap.
1032 if Nkind
(N
) /= N_Function_Call
then
1033 Set_Check_Actuals
(N
);
1035 -- For calls to functions we climb to the outermost enclosing
1036 -- construct where the out-mode actuals of this function may
1037 -- introduce conflicts.
1041 Outermost
: Node_Id
;
1045 while Present
(P
) loop
1047 -- For object declarations we can climb to the node from
1048 -- its object definition branch or from its initializing
1049 -- expression. We prefer to mark the child node as the
1050 -- outermost construct to avoid adding further complexity
1051 -- to the routine that will later take care of
1052 -- performing the writable actuals check.
1054 if Has_Arbitrary_Evaluation_Order
(Nkind
(P
))
1055 and then not Nkind_In
(P
, N_Assignment_Statement
,
1056 N_Object_Declaration
)
1061 -- Avoid climbing more than needed!
1063 exit when Stop_Subtree_Climbing
(Nkind
(P
))
1064 or else (Nkind
(P
) = N_Range
1066 Nkind_In
(Parent
(P
), N_In
, N_Not_In
));
1071 Set_Check_Actuals
(Outermost
);
1075 end Check_Writable_Actuals
;
1077 ---------------------------
1078 -- Name_Denotes_Function --
1079 ---------------------------
1081 function Name_Denotes_Function
return Boolean is
1083 if Is_Entity_Name
(Nam
) then
1084 return Ekind
(Entity
(Nam
)) = E_Function
;
1085 elsif Nkind
(Nam
) = N_Selected_Component
then
1086 return Ekind
(Entity
(Selector_Name
(Nam
))) = E_Function
;
1090 end Name_Denotes_Function
;
1092 -----------------------
1093 -- No_Interpretation --
1094 -----------------------
1096 procedure No_Interpretation
is
1097 L
: constant Boolean := Is_List_Member
(N
);
1098 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
1101 -- If the node is in a list whose parent is not an expression then it
1102 -- must be an attempted procedure call.
1104 if L
and then K
not in N_Subexpr
then
1105 if Ekind
(Entity
(Nam
)) = E_Generic_Procedure
then
1107 ("must instantiate generic procedure& before call",
1110 Error_Msg_N
("procedure or entry name expected", Nam
);
1113 -- Check for tasking cases where only an entry call will do
1116 and then Nkind_In
(K
, N_Entry_Call_Alternative
,
1117 N_Triggering_Alternative
)
1119 Error_Msg_N
("entry name expected", Nam
);
1121 -- Otherwise give general error message
1124 Error_Msg_N
("invalid prefix in call", Nam
);
1126 end No_Interpretation
;
1128 -- Start of processing for Analyze_Call
1131 if Restriction_Check_Required
(SPARK_05
) then
1132 Check_Mixed_Parameter_And_Named_Associations
;
1135 -- Initialize the type of the result of the call to the error type,
1136 -- which will be reset if the type is successfully resolved.
1138 Set_Etype
(N
, Any_Type
);
1142 if not Is_Overloaded
(Nam
) then
1144 -- Only one interpretation to check
1146 if Ekind
(Etype
(Nam
)) = E_Subprogram_Type
then
1147 Nam_Ent
:= Etype
(Nam
);
1149 -- If the prefix is an access_to_subprogram, this may be an indirect
1150 -- call. This is the case if the name in the call is not an entity
1151 -- name, or if it is a function name in the context of a procedure
1152 -- call. In this latter case, we have a call to a parameterless
1153 -- function that returns a pointer_to_procedure which is the entity
1154 -- being called. Finally, F (X) may be a call to a parameterless
1155 -- function that returns a pointer to a function with parameters.
1156 -- Note that if F returns an access-to-subprogram whose designated
1157 -- type is an array, F (X) cannot be interpreted as an indirect call
1158 -- through the result of the call to F.
1160 elsif Is_Access_Type
(Etype
(Nam
))
1161 and then Ekind
(Designated_Type
(Etype
(Nam
))) = E_Subprogram_Type
1163 (not Name_Denotes_Function
1164 or else Nkind
(N
) = N_Procedure_Call_Statement
1166 (Nkind
(Parent
(N
)) /= N_Explicit_Dereference
1167 and then Is_Entity_Name
(Nam
)
1168 and then No
(First_Formal
(Entity
(Nam
)))
1170 Is_Array_Type
(Etype
(Designated_Type
(Etype
(Nam
))))
1171 and then Present
(Actuals
)))
1173 Nam_Ent
:= Designated_Type
(Etype
(Nam
));
1174 Insert_Explicit_Dereference
(Nam
);
1176 -- Selected component case. Simple entry or protected operation,
1177 -- where the entry name is given by the selector name.
1179 elsif Nkind
(Nam
) = N_Selected_Component
then
1180 Nam_Ent
:= Entity
(Selector_Name
(Nam
));
1182 if not Ekind_In
(Nam_Ent
, E_Entry
,
1187 Error_Msg_N
("name in call is not a callable entity", Nam
);
1188 Set_Etype
(N
, Any_Type
);
1192 -- If the name is an Indexed component, it can be a call to a member
1193 -- of an entry family. The prefix must be a selected component whose
1194 -- selector is the entry. Analyze_Procedure_Call normalizes several
1195 -- kinds of call into this form.
1197 elsif Nkind
(Nam
) = N_Indexed_Component
then
1198 if Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
1199 Nam_Ent
:= Entity
(Selector_Name
(Prefix
(Nam
)));
1201 Error_Msg_N
("name in call is not a callable entity", Nam
);
1202 Set_Etype
(N
, Any_Type
);
1206 elsif not Is_Entity_Name
(Nam
) then
1207 Error_Msg_N
("name in call is not a callable entity", Nam
);
1208 Set_Etype
(N
, Any_Type
);
1212 Nam_Ent
:= Entity
(Nam
);
1214 -- If not overloadable, this may be a generalized indexing
1215 -- operation with named associations. Rewrite again as an
1216 -- indexed component and analyze as container indexing.
1218 if not Is_Overloadable
(Nam_Ent
) then
1220 (Find_Value_Of_Aspect
1221 (Etype
(Nam_Ent
), Aspect_Constant_Indexing
))
1224 Make_Indexed_Component
(Sloc
(N
),
1226 Expressions
=> Parameter_Associations
(N
)));
1228 if Try_Container_Indexing
(N
, Nam
, Expressions
(N
)) then
1242 -- Operations generated for RACW stub types are called only through
1243 -- dispatching, and can never be the static interpretation of a call.
1245 if Is_RACW_Stub_Type_Operation
(Nam_Ent
) then
1250 Analyze_One_Call
(N
, Nam_Ent
, True, Success
);
1252 -- If this is an indirect call, the return type of the access_to
1253 -- subprogram may be an incomplete type. At the point of the call,
1254 -- use the full type if available, and at the same time update the
1255 -- return type of the access_to_subprogram.
1258 and then Nkind
(Nam
) = N_Explicit_Dereference
1259 and then Ekind
(Etype
(N
)) = E_Incomplete_Type
1260 and then Present
(Full_View
(Etype
(N
)))
1262 Set_Etype
(N
, Full_View
(Etype
(N
)));
1263 Set_Etype
(Nam_Ent
, Etype
(N
));
1269 -- An overloaded selected component must denote overloaded operations
1270 -- of a concurrent type. The interpretations are attached to the
1271 -- simple name of those operations.
1273 if Nkind
(Nam
) = N_Selected_Component
then
1274 Nam
:= Selector_Name
(Nam
);
1277 Get_First_Interp
(Nam
, X
, It
);
1278 while Present
(It
.Nam
) loop
1282 -- Name may be call that returns an access to subprogram, or more
1283 -- generally an overloaded expression one of whose interpretations
1284 -- yields an access to subprogram. If the name is an entity, we do
1285 -- not dereference, because the node is a call that returns the
1286 -- access type: note difference between f(x), where the call may
1287 -- return an access subprogram type, and f(x)(y), where the type
1288 -- returned by the call to f is implicitly dereferenced to analyze
1291 if Is_Access_Type
(Nam_Ent
) then
1292 Nam_Ent
:= Designated_Type
(Nam_Ent
);
1294 elsif Is_Access_Type
(Etype
(Nam_Ent
))
1296 (not Is_Entity_Name
(Nam
)
1297 or else Nkind
(N
) = N_Procedure_Call_Statement
)
1298 and then Ekind
(Designated_Type
(Etype
(Nam_Ent
)))
1301 Nam_Ent
:= Designated_Type
(Etype
(Nam_Ent
));
1303 if Is_Entity_Name
(Nam
) then
1308 -- If the call has been rewritten from a prefixed call, the first
1309 -- parameter has been analyzed, but may need a subsequent
1310 -- dereference, so skip its analysis now.
1312 if N
/= Original_Node
(N
)
1313 and then Nkind
(Original_Node
(N
)) = Nkind
(N
)
1314 and then Nkind
(Name
(N
)) /= Nkind
(Name
(Original_Node
(N
)))
1315 and then Present
(Parameter_Associations
(N
))
1316 and then Present
(Etype
(First
(Parameter_Associations
(N
))))
1319 (N
, Nam_Ent
, False, Success
, Skip_First
=> True);
1321 Analyze_One_Call
(N
, Nam_Ent
, False, Success
);
1324 -- If the interpretation succeeds, mark the proper type of the
1325 -- prefix (any valid candidate will do). If not, remove the
1326 -- candidate interpretation. This only needs to be done for
1327 -- overloaded protected operations, for other entities disambi-
1328 -- guation is done directly in Resolve.
1332 and then Nkind
(Parent
(N
)) /= N_Explicit_Dereference
1334 Set_Entity
(Nam
, It
.Nam
);
1335 Insert_Explicit_Dereference
(Nam
);
1336 Set_Etype
(Nam
, Nam_Ent
);
1339 Set_Etype
(Nam
, It
.Typ
);
1342 elsif Nkind_In
(Name
(N
), N_Selected_Component
,
1348 Get_Next_Interp
(X
, It
);
1351 -- If the name is the result of a function call, it can only be a
1352 -- call to a function returning an access to subprogram. Insert
1353 -- explicit dereference.
1355 if Nkind
(Nam
) = N_Function_Call
then
1356 Insert_Explicit_Dereference
(Nam
);
1359 if Etype
(N
) = Any_Type
then
1361 -- None of the interpretations is compatible with the actuals
1363 Diagnose_Call
(N
, Nam
);
1365 -- Special checks for uninstantiated put routines
1367 if Nkind
(N
) = N_Procedure_Call_Statement
1368 and then Is_Entity_Name
(Nam
)
1369 and then Chars
(Nam
) = Name_Put
1370 and then List_Length
(Actuals
) = 1
1373 Arg
: constant Node_Id
:= First
(Actuals
);
1377 if Nkind
(Arg
) = N_Parameter_Association
then
1378 Typ
:= Etype
(Explicit_Actual_Parameter
(Arg
));
1383 if Is_Signed_Integer_Type
(Typ
) then
1385 ("possible missing instantiation of "
1386 & "'Text_'I'O.'Integer_'I'O!", Nam
);
1388 elsif Is_Modular_Integer_Type
(Typ
) then
1390 ("possible missing instantiation of "
1391 & "'Text_'I'O.'Modular_'I'O!", Nam
);
1393 elsif Is_Floating_Point_Type
(Typ
) then
1395 ("possible missing instantiation of "
1396 & "'Text_'I'O.'Float_'I'O!", Nam
);
1398 elsif Is_Ordinary_Fixed_Point_Type
(Typ
) then
1400 ("possible missing instantiation of "
1401 & "'Text_'I'O.'Fixed_'I'O!", Nam
);
1403 elsif Is_Decimal_Fixed_Point_Type
(Typ
) then
1405 ("possible missing instantiation of "
1406 & "'Text_'I'O.'Decimal_'I'O!", Nam
);
1408 elsif Is_Enumeration_Type
(Typ
) then
1410 ("possible missing instantiation of "
1411 & "'Text_'I'O.'Enumeration_'I'O!", Nam
);
1416 elsif not Is_Overloaded
(N
)
1417 and then Is_Entity_Name
(Nam
)
1419 -- Resolution yields a single interpretation. Verify that the
1420 -- reference has capitalization consistent with the declaration.
1422 Set_Entity_With_Checks
(Nam
, Entity
(Nam
));
1423 Generate_Reference
(Entity
(Nam
), Nam
);
1425 Set_Etype
(Nam
, Etype
(Entity
(Nam
)));
1427 Remove_Abstract_Operations
(N
);
1433 if Ada_Version
>= Ada_2012
then
1435 -- Check if the call contains a function with writable actuals
1437 Check_Writable_Actuals
(N
);
1439 -- If found and the outermost construct that can be evaluated in
1440 -- an arbitrary order is precisely this call, then check all its
1443 Check_Function_Writable_Actuals
(N
);
1447 -----------------------------
1448 -- Analyze_Case_Expression --
1449 -----------------------------
1451 procedure Analyze_Case_Expression
(N
: Node_Id
) is
1452 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
1453 -- Error routine invoked by the generic instantiation below when
1454 -- the case expression has a non static choice.
1456 package Case_Choices_Analysis
is new
1457 Generic_Analyze_Choices
1458 (Process_Associated_Node
=> No_OP
);
1459 use Case_Choices_Analysis
;
1461 package Case_Choices_Checking
is new
1462 Generic_Check_Choices
1463 (Process_Empty_Choice
=> No_OP
,
1464 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
1465 Process_Associated_Node
=> No_OP
);
1466 use Case_Choices_Checking
;
1468 -----------------------------
1469 -- Non_Static_Choice_Error --
1470 -----------------------------
1472 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
1474 Flag_Non_Static_Expr
1475 ("choice given in case expression is not static!", Choice
);
1476 end Non_Static_Choice_Error
;
1480 Expr
: constant Node_Id
:= Expression
(N
);
1482 Exp_Type
: Entity_Id
;
1483 Exp_Btype
: Entity_Id
;
1485 FirstX
: Node_Id
:= Empty
;
1486 -- First expression in the case for which there is some type information
1487 -- available, i.e. it is not Any_Type, which can happen because of some
1488 -- error, or from the use of e.g. raise Constraint_Error.
1490 Others_Present
: Boolean;
1491 -- Indicates if Others was present
1493 Wrong_Alt
: Node_Id
:= Empty
;
1494 -- For error reporting
1496 -- Start of processing for Analyze_Case_Expression
1499 if Comes_From_Source
(N
) then
1500 Check_Compiler_Unit
("case expression", N
);
1503 Analyze_And_Resolve
(Expr
, Any_Discrete
);
1504 Check_Unset_Reference
(Expr
);
1505 Exp_Type
:= Etype
(Expr
);
1506 Exp_Btype
:= Base_Type
(Exp_Type
);
1508 Alt
:= First
(Alternatives
(N
));
1509 while Present
(Alt
) loop
1510 Analyze
(Expression
(Alt
));
1512 if No
(FirstX
) and then Etype
(Expression
(Alt
)) /= Any_Type
then
1513 FirstX
:= Expression
(Alt
);
1519 -- Get our initial type from the first expression for which we got some
1520 -- useful type information from the expression.
1522 if not Is_Overloaded
(FirstX
) then
1523 Set_Etype
(N
, Etype
(FirstX
));
1531 Set_Etype
(N
, Any_Type
);
1533 Get_First_Interp
(FirstX
, I
, It
);
1534 while Present
(It
.Nam
) loop
1536 -- For each interpretation of the first expression, we only
1537 -- add the interpretation if every other expression in the
1538 -- case expression alternatives has a compatible type.
1540 Alt
:= Next
(First
(Alternatives
(N
)));
1541 while Present
(Alt
) loop
1542 exit when not Has_Compatible_Type
(Expression
(Alt
), It
.Typ
);
1547 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
1552 Get_Next_Interp
(I
, It
);
1557 Exp_Btype
:= Base_Type
(Exp_Type
);
1559 -- The expression must be of a discrete type which must be determinable
1560 -- independently of the context in which the expression occurs, but
1561 -- using the fact that the expression must be of a discrete type.
1562 -- Moreover, the type this expression must not be a character literal
1563 -- (which is always ambiguous).
1565 -- If error already reported by Resolve, nothing more to do
1567 if Exp_Btype
= Any_Discrete
or else Exp_Btype
= Any_Type
then
1570 -- Special casee message for character literal
1572 elsif Exp_Btype
= Any_Character
then
1574 ("character literal as case expression is ambiguous", Expr
);
1578 if Etype
(N
) = Any_Type
and then Present
(Wrong_Alt
) then
1580 ("type incompatible with that of previous alternatives",
1581 Expression
(Wrong_Alt
));
1585 -- If the case expression is a formal object of mode in out, then
1586 -- treat it as having a nonstatic subtype by forcing use of the base
1587 -- type (which has to get passed to Check_Case_Choices below). Also
1588 -- use base type when the case expression is parenthesized.
1590 if Paren_Count
(Expr
) > 0
1591 or else (Is_Entity_Name
(Expr
)
1592 and then Ekind
(Entity
(Expr
)) = E_Generic_In_Out_Parameter
)
1594 Exp_Type
:= Exp_Btype
;
1597 -- The case expression alternatives cover the range of a static subtype
1598 -- subject to aspect Static_Predicate. Do not check the choices when the
1599 -- case expression has not been fully analyzed yet because this may lead
1602 if Is_OK_Static_Subtype
(Exp_Type
)
1603 and then Has_Static_Predicate_Aspect
(Exp_Type
)
1604 and then In_Spec_Expression
1608 -- Call Analyze_Choices and Check_Choices to do the rest of the work
1611 Analyze_Choices
(Alternatives
(N
), Exp_Type
);
1612 Check_Choices
(N
, Alternatives
(N
), Exp_Type
, Others_Present
);
1615 if Exp_Type
= Universal_Integer
and then not Others_Present
then
1617 ("case on universal integer requires OTHERS choice", Expr
);
1619 end Analyze_Case_Expression
;
1621 ---------------------------
1622 -- Analyze_Comparison_Op --
1623 ---------------------------
1625 procedure Analyze_Comparison_Op
(N
: Node_Id
) is
1626 L
: constant Node_Id
:= Left_Opnd
(N
);
1627 R
: constant Node_Id
:= Right_Opnd
(N
);
1628 Op_Id
: Entity_Id
:= Entity
(N
);
1631 Set_Etype
(N
, Any_Type
);
1632 Candidate_Type
:= Empty
;
1634 Analyze_Expression
(L
);
1635 Analyze_Expression
(R
);
1637 if Present
(Op_Id
) then
1638 if Ekind
(Op_Id
) = E_Operator
then
1639 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1641 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1644 if Is_Overloaded
(L
) then
1645 Set_Etype
(L
, Intersect_Types
(L
, R
));
1649 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1650 while Present
(Op_Id
) loop
1651 if Ekind
(Op_Id
) = E_Operator
then
1652 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1654 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1657 Op_Id
:= Homonym
(Op_Id
);
1662 Check_Function_Writable_Actuals
(N
);
1663 end Analyze_Comparison_Op
;
1665 ---------------------------
1666 -- Analyze_Concatenation --
1667 ---------------------------
1669 procedure Analyze_Concatenation
(N
: Node_Id
) is
1671 -- We wish to avoid deep recursion, because concatenations are often
1672 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1673 -- operands nonrecursively until we find something that is not a
1674 -- concatenation (A in this case), or has already been analyzed. We
1675 -- analyze that, and then walk back up the tree following Parent
1676 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1677 -- work at each level. The Parent pointers allow us to avoid recursion,
1678 -- and thus avoid running out of memory.
1684 Candidate_Type
:= Empty
;
1686 -- The following code is equivalent to:
1688 -- Set_Etype (N, Any_Type);
1689 -- Analyze_Expression (Left_Opnd (N));
1690 -- Analyze_Concatenation_Rest (N);
1692 -- where the Analyze_Expression call recurses back here if the left
1693 -- operand is a concatenation.
1695 -- Walk down left operands
1698 Set_Etype
(NN
, Any_Type
);
1699 L
:= Left_Opnd
(NN
);
1700 exit when Nkind
(L
) /= N_Op_Concat
or else Analyzed
(L
);
1704 -- Now (given the above example) NN is A&B and L is A
1706 -- First analyze L ...
1708 Analyze_Expression
(L
);
1710 -- ... then walk NN back up until we reach N (where we started), calling
1711 -- Analyze_Concatenation_Rest along the way.
1714 Analyze_Concatenation_Rest
(NN
);
1718 end Analyze_Concatenation
;
1720 --------------------------------
1721 -- Analyze_Concatenation_Rest --
1722 --------------------------------
1724 -- If the only one-dimensional array type in scope is String,
1725 -- this is the resulting type of the operation. Otherwise there
1726 -- will be a concatenation operation defined for each user-defined
1727 -- one-dimensional array.
1729 procedure Analyze_Concatenation_Rest
(N
: Node_Id
) is
1730 L
: constant Node_Id
:= Left_Opnd
(N
);
1731 R
: constant Node_Id
:= Right_Opnd
(N
);
1732 Op_Id
: Entity_Id
:= Entity
(N
);
1737 Analyze_Expression
(R
);
1739 -- If the entity is present, the node appears in an instance, and
1740 -- denotes a predefined concatenation operation. The resulting type is
1741 -- obtained from the arguments when possible. If the arguments are
1742 -- aggregates, the array type and the concatenation type must be
1745 if Present
(Op_Id
) then
1746 if Ekind
(Op_Id
) = E_Operator
then
1747 LT
:= Base_Type
(Etype
(L
));
1748 RT
:= Base_Type
(Etype
(R
));
1750 if Is_Array_Type
(LT
)
1751 and then (RT
= LT
or else RT
= Base_Type
(Component_Type
(LT
)))
1753 Add_One_Interp
(N
, Op_Id
, LT
);
1755 elsif Is_Array_Type
(RT
)
1756 and then LT
= Base_Type
(Component_Type
(RT
))
1758 Add_One_Interp
(N
, Op_Id
, RT
);
1760 -- If one operand is a string type or a user-defined array type,
1761 -- and the other is a literal, result is of the specific type.
1764 (Root_Type
(LT
) = Standard_String
1765 or else Scope
(LT
) /= Standard_Standard
)
1766 and then Etype
(R
) = Any_String
1768 Add_One_Interp
(N
, Op_Id
, LT
);
1771 (Root_Type
(RT
) = Standard_String
1772 or else Scope
(RT
) /= Standard_Standard
)
1773 and then Etype
(L
) = Any_String
1775 Add_One_Interp
(N
, Op_Id
, RT
);
1777 elsif not Is_Generic_Type
(Etype
(Op_Id
)) then
1778 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1781 -- Type and its operations must be visible
1783 Set_Entity
(N
, Empty
);
1784 Analyze_Concatenation
(N
);
1788 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1792 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Concat
);
1793 while Present
(Op_Id
) loop
1794 if Ekind
(Op_Id
) = E_Operator
then
1796 -- Do not consider operators declared in dead code, they can
1797 -- not be part of the resolution.
1799 if Is_Eliminated
(Op_Id
) then
1802 Find_Concatenation_Types
(L
, R
, Op_Id
, N
);
1806 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1809 Op_Id
:= Homonym
(Op_Id
);
1814 end Analyze_Concatenation_Rest
;
1816 -------------------------
1817 -- Analyze_Equality_Op --
1818 -------------------------
1820 procedure Analyze_Equality_Op
(N
: Node_Id
) is
1821 Loc
: constant Source_Ptr
:= Sloc
(N
);
1822 L
: constant Node_Id
:= Left_Opnd
(N
);
1823 R
: constant Node_Id
:= Right_Opnd
(N
);
1827 Set_Etype
(N
, Any_Type
);
1828 Candidate_Type
:= Empty
;
1830 Analyze_Expression
(L
);
1831 Analyze_Expression
(R
);
1833 -- If the entity is set, the node is a generic instance with a non-local
1834 -- reference to the predefined operator or to a user-defined function.
1835 -- It can also be an inequality that is expanded into the negation of a
1836 -- call to a user-defined equality operator.
1838 -- For the predefined case, the result is Boolean, regardless of the
1839 -- type of the operands. The operands may even be limited, if they are
1840 -- generic actuals. If they are overloaded, label the left argument with
1841 -- the common type that must be present, or with the type of the formal
1842 -- of the user-defined function.
1844 if Present
(Entity
(N
)) then
1845 Op_Id
:= Entity
(N
);
1847 if Ekind
(Op_Id
) = E_Operator
then
1848 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
);
1850 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1853 if Is_Overloaded
(L
) then
1854 if Ekind
(Op_Id
) = E_Operator
then
1855 Set_Etype
(L
, Intersect_Types
(L
, R
));
1857 Set_Etype
(L
, Etype
(First_Formal
(Op_Id
)));
1862 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1863 while Present
(Op_Id
) loop
1864 if Ekind
(Op_Id
) = E_Operator
then
1865 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1867 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1870 Op_Id
:= Homonym
(Op_Id
);
1874 -- If there was no match, and the operator is inequality, this may be
1875 -- a case where inequality has not been made explicit, as for tagged
1876 -- types. Analyze the node as the negation of an equality operation.
1877 -- This cannot be done earlier, because before analysis we cannot rule
1878 -- out the presence of an explicit inequality.
1880 if Etype
(N
) = Any_Type
1881 and then Nkind
(N
) = N_Op_Ne
1883 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Eq
);
1884 while Present
(Op_Id
) loop
1885 if Ekind
(Op_Id
) = E_Operator
then
1886 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1888 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1891 Op_Id
:= Homonym
(Op_Id
);
1894 if Etype
(N
) /= Any_Type
then
1895 Op_Id
:= Entity
(N
);
1901 Left_Opnd
=> Left_Opnd
(N
),
1902 Right_Opnd
=> Right_Opnd
(N
))));
1904 Set_Entity
(Right_Opnd
(N
), Op_Id
);
1910 Check_Function_Writable_Actuals
(N
);
1911 end Analyze_Equality_Op
;
1913 ----------------------------------
1914 -- Analyze_Explicit_Dereference --
1915 ----------------------------------
1917 procedure Analyze_Explicit_Dereference
(N
: Node_Id
) is
1918 Loc
: constant Source_Ptr
:= Sloc
(N
);
1919 P
: constant Node_Id
:= Prefix
(N
);
1925 function Is_Function_Type
return Boolean;
1926 -- Check whether node may be interpreted as an implicit function call
1928 ----------------------
1929 -- Is_Function_Type --
1930 ----------------------
1932 function Is_Function_Type
return Boolean is
1937 if not Is_Overloaded
(N
) then
1938 return Ekind
(Base_Type
(Etype
(N
))) = E_Subprogram_Type
1939 and then Etype
(Base_Type
(Etype
(N
))) /= Standard_Void_Type
;
1942 Get_First_Interp
(N
, I
, It
);
1943 while Present
(It
.Nam
) loop
1944 if Ekind
(Base_Type
(It
.Typ
)) /= E_Subprogram_Type
1945 or else Etype
(Base_Type
(It
.Typ
)) = Standard_Void_Type
1950 Get_Next_Interp
(I
, It
);
1955 end Is_Function_Type
;
1957 -- Start of processing for Analyze_Explicit_Dereference
1960 -- If source node, check SPARK restriction. We guard this with the
1961 -- source node check, because ???
1963 if Comes_From_Source
(N
) then
1964 Check_SPARK_05_Restriction
("explicit dereference is not allowed", N
);
1967 -- In formal verification mode, keep track of all reads and writes
1968 -- through explicit dereferences.
1970 if GNATprove_Mode
then
1971 SPARK_Specific
.Generate_Dereference
(N
);
1975 Set_Etype
(N
, Any_Type
);
1977 -- Test for remote access to subprogram type, and if so return
1978 -- after rewriting the original tree.
1980 if Remote_AST_E_Dereference
(P
) then
1984 -- Normal processing for other than remote access to subprogram type
1986 if not Is_Overloaded
(P
) then
1987 if Is_Access_Type
(Etype
(P
)) then
1989 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
1990 -- avoid other problems caused by the Private_Subtype and it is
1991 -- safe to go to the Base_Type because this is the same as
1992 -- converting the access value to its Base_Type.
1995 DT
: Entity_Id
:= Designated_Type
(Etype
(P
));
1998 if Ekind
(DT
) = E_Private_Subtype
1999 and then Is_For_Access_Subtype
(DT
)
2001 DT
:= Base_Type
(DT
);
2004 -- An explicit dereference is a legal occurrence of an
2005 -- incomplete type imported through a limited_with clause, if
2006 -- the full view is visible, or if we are within an instance
2007 -- body, where the enclosing body has a regular with_clause
2010 if From_Limited_With
(DT
)
2011 and then not From_Limited_With
(Scope
(DT
))
2013 (Is_Immediately_Visible
(Scope
(DT
))
2015 (Is_Child_Unit
(Scope
(DT
))
2016 and then Is_Visible_Lib_Unit
(Scope
(DT
)))
2017 or else In_Instance_Body
)
2019 Set_Etype
(N
, Available_View
(DT
));
2026 elsif Etype
(P
) /= Any_Type
then
2027 Error_Msg_N
("prefix of dereference must be an access type", N
);
2032 Get_First_Interp
(P
, I
, It
);
2033 while Present
(It
.Nam
) loop
2036 if Is_Access_Type
(T
) then
2037 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
2040 Get_Next_Interp
(I
, It
);
2043 -- Error if no interpretation of the prefix has an access type
2045 if Etype
(N
) = Any_Type
then
2047 ("access type required in prefix of explicit dereference", P
);
2048 Set_Etype
(N
, Any_Type
);
2054 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
2056 and then (Nkind
(Parent
(N
)) /= N_Function_Call
2057 or else N
/= Name
(Parent
(N
)))
2059 and then (Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
2060 or else N
/= Name
(Parent
(N
)))
2062 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
2063 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
2065 (Attribute_Name
(Parent
(N
)) /= Name_Address
2067 Attribute_Name
(Parent
(N
)) /= Name_Access
))
2069 -- Name is a function call with no actuals, in a context that
2070 -- requires deproceduring (including as an actual in an enclosing
2071 -- function or procedure call). There are some pathological cases
2072 -- where the prefix might include functions that return access to
2073 -- subprograms and others that return a regular type. Disambiguation
2074 -- of those has to take place in Resolve.
2077 Make_Function_Call
(Loc
,
2078 Name
=> Make_Explicit_Dereference
(Loc
, P
),
2079 Parameter_Associations
=> New_List
);
2081 -- If the prefix is overloaded, remove operations that have formals,
2082 -- we know that this is a parameterless call.
2084 if Is_Overloaded
(P
) then
2085 Get_First_Interp
(P
, I
, It
);
2086 while Present
(It
.Nam
) loop
2089 if No
(First_Formal
(Base_Type
(Designated_Type
(T
)))) then
2095 Get_Next_Interp
(I
, It
);
2102 elsif not Is_Function_Type
2103 and then Is_Overloaded
(N
)
2105 -- The prefix may include access to subprograms and other access
2106 -- types. If the context selects the interpretation that is a
2107 -- function call (not a procedure call) we cannot rewrite the node
2108 -- yet, but we include the result of the call interpretation.
2110 Get_First_Interp
(N
, I
, It
);
2111 while Present
(It
.Nam
) loop
2112 if Ekind
(Base_Type
(It
.Typ
)) = E_Subprogram_Type
2113 and then Etype
(Base_Type
(It
.Typ
)) /= Standard_Void_Type
2114 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
2116 Add_One_Interp
(N
, Etype
(It
.Typ
), Etype
(It
.Typ
));
2119 Get_Next_Interp
(I
, It
);
2123 -- A value of remote access-to-class-wide must not be dereferenced
2126 Validate_Remote_Access_To_Class_Wide_Type
(N
);
2127 end Analyze_Explicit_Dereference
;
2129 ------------------------
2130 -- Analyze_Expression --
2131 ------------------------
2133 procedure Analyze_Expression
(N
: Node_Id
) is
2136 -- If the expression is an indexed component that will be rewritten
2137 -- as a container indexing, it has already been analyzed.
2139 if Nkind
(N
) = N_Indexed_Component
2140 and then Present
(Generalized_Indexing
(N
))
2146 Check_Parameterless_Call
(N
);
2148 end Analyze_Expression
;
2150 -------------------------------------
2151 -- Analyze_Expression_With_Actions --
2152 -------------------------------------
2154 procedure Analyze_Expression_With_Actions
(N
: Node_Id
) is
2158 A
:= First
(Actions
(N
));
2159 while Present
(A
) loop
2164 Analyze_Expression
(Expression
(N
));
2165 Set_Etype
(N
, Etype
(Expression
(N
)));
2166 end Analyze_Expression_With_Actions
;
2168 ---------------------------
2169 -- Analyze_If_Expression --
2170 ---------------------------
2172 procedure Analyze_If_Expression
(N
: Node_Id
) is
2173 Condition
: constant Node_Id
:= First
(Expressions
(N
));
2174 Then_Expr
: constant Node_Id
:= Next
(Condition
);
2175 Else_Expr
: Node_Id
;
2178 -- Defend against error of missing expressions from previous error
2180 if No
(Then_Expr
) then
2181 Check_Error_Detected
;
2185 if Comes_From_Source
(N
) then
2186 Check_SPARK_05_Restriction
("if expression is not allowed", N
);
2189 Else_Expr
:= Next
(Then_Expr
);
2191 if Comes_From_Source
(N
) then
2192 Check_Compiler_Unit
("if expression", N
);
2195 -- Analyze and resolve the condition. We need to resolve this now so
2196 -- that it gets folded to True/False if possible, before we analyze
2197 -- the THEN/ELSE branches, because when analyzing these branches, we
2198 -- may call Is_Statically_Unevaluated, which expects the condition of
2199 -- an enclosing IF to have been analyze/resolved/evaluated.
2201 Analyze_Expression
(Condition
);
2202 Resolve
(Condition
, Any_Boolean
);
2204 -- Analyze THEN expression and (if present) ELSE expression. For those
2205 -- we delay resolution in the normal manner, because of overloading etc.
2207 Analyze_Expression
(Then_Expr
);
2209 if Present
(Else_Expr
) then
2210 Analyze_Expression
(Else_Expr
);
2213 -- If then expression not overloaded, then that decides the type
2215 if not Is_Overloaded
(Then_Expr
) then
2216 Set_Etype
(N
, Etype
(Then_Expr
));
2218 -- Case where then expression is overloaded
2226 Set_Etype
(N
, Any_Type
);
2228 -- Loop through interpretations of Then_Expr
2230 Get_First_Interp
(Then_Expr
, I
, It
);
2231 while Present
(It
.Nam
) loop
2233 -- Add possible interpretation of Then_Expr if no Else_Expr, or
2234 -- Else_Expr is present and has a compatible type.
2237 or else Has_Compatible_Type
(Else_Expr
, It
.Typ
)
2239 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
2242 Get_Next_Interp
(I
, It
);
2245 -- If no valid interpretation has been found, then the type of the
2246 -- ELSE expression does not match any interpretation of the THEN
2249 if Etype
(N
) = Any_Type
then
2251 ("type incompatible with that of `THEN` expression",
2257 end Analyze_If_Expression
;
2259 ------------------------------------
2260 -- Analyze_Indexed_Component_Form --
2261 ------------------------------------
2263 procedure Analyze_Indexed_Component_Form
(N
: Node_Id
) is
2264 P
: constant Node_Id
:= Prefix
(N
);
2265 Exprs
: constant List_Id
:= Expressions
(N
);
2271 procedure Process_Function_Call
;
2272 -- Prefix in indexed component form is an overloadable entity, so the
2273 -- node is a function call. Reformat it as such.
2275 procedure Process_Indexed_Component
;
2276 -- Prefix in indexed component form is actually an indexed component.
2277 -- This routine processes it, knowing that the prefix is already
2280 procedure Process_Indexed_Component_Or_Slice
;
2281 -- An indexed component with a single index may designate a slice if
2282 -- the index is a subtype mark. This routine disambiguates these two
2283 -- cases by resolving the prefix to see if it is a subtype mark.
2285 procedure Process_Overloaded_Indexed_Component
;
2286 -- If the prefix of an indexed component is overloaded, the proper
2287 -- interpretation is selected by the index types and the context.
2289 ---------------------------
2290 -- Process_Function_Call --
2291 ---------------------------
2293 procedure Process_Function_Call
is
2294 Loc
: constant Source_Ptr
:= Sloc
(N
);
2298 Change_Node
(N
, N_Function_Call
);
2300 Set_Parameter_Associations
(N
, Exprs
);
2302 -- Analyze actuals prior to analyzing the call itself
2304 Actual
:= First
(Parameter_Associations
(N
));
2305 while Present
(Actual
) loop
2307 Check_Parameterless_Call
(Actual
);
2309 -- Move to next actual. Note that we use Next, not Next_Actual
2310 -- here. The reason for this is a bit subtle. If a function call
2311 -- includes named associations, the parser recognizes the node
2312 -- as a call, and it is analyzed as such. If all associations are
2313 -- positional, the parser builds an indexed_component node, and
2314 -- it is only after analysis of the prefix that the construct
2315 -- is recognized as a call, in which case Process_Function_Call
2316 -- rewrites the node and analyzes the actuals. If the list of
2317 -- actuals is malformed, the parser may leave the node as an
2318 -- indexed component (despite the presence of named associations).
2319 -- The iterator Next_Actual is equivalent to Next if the list is
2320 -- positional, but follows the normalized chain of actuals when
2321 -- named associations are present. In this case normalization has
2322 -- not taken place, and actuals remain unanalyzed, which leads to
2323 -- subsequent crashes or loops if there is an attempt to continue
2324 -- analysis of the program.
2326 -- IF there is a single actual and it is a type name, the node
2327 -- can only be interpreted as a slice of a parameterless call.
2328 -- Rebuild the node as such and analyze.
2330 if No
(Next
(Actual
))
2331 and then Is_Entity_Name
(Actual
)
2332 and then Is_Type
(Entity
(Actual
))
2333 and then Is_Discrete_Type
(Entity
(Actual
))
2339 New_Occurrence_Of
(Entity
(Actual
), Loc
)));
2349 end Process_Function_Call
;
2351 -------------------------------
2352 -- Process_Indexed_Component --
2353 -------------------------------
2355 procedure Process_Indexed_Component
is
2357 Array_Type
: Entity_Id
;
2359 Pent
: Entity_Id
:= Empty
;
2362 Exp
:= First
(Exprs
);
2364 if Is_Overloaded
(P
) then
2365 Process_Overloaded_Indexed_Component
;
2368 Array_Type
:= Etype
(P
);
2370 if Is_Entity_Name
(P
) then
2372 elsif Nkind
(P
) = N_Selected_Component
2373 and then Is_Entity_Name
(Selector_Name
(P
))
2375 Pent
:= Entity
(Selector_Name
(P
));
2378 -- Prefix must be appropriate for an array type, taking into
2379 -- account a possible implicit dereference.
2381 if Is_Access_Type
(Array_Type
) then
2383 (Warn_On_Dereference
, "?d?implicit dereference", N
);
2384 Array_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, P
);
2387 if Is_Array_Type
(Array_Type
) then
2390 elsif Present
(Pent
) and then Ekind
(Pent
) = E_Entry_Family
then
2392 Set_Etype
(N
, Any_Type
);
2394 if not Has_Compatible_Type
2395 (Exp
, Entry_Index_Type
(Pent
))
2397 Error_Msg_N
("invalid index type in entry name", N
);
2399 elsif Present
(Next
(Exp
)) then
2400 Error_Msg_N
("too many subscripts in entry reference", N
);
2403 Set_Etype
(N
, Etype
(P
));
2408 elsif Is_Record_Type
(Array_Type
)
2409 and then Remote_AST_I_Dereference
(P
)
2413 elsif Try_Container_Indexing
(N
, P
, Exprs
) then
2416 elsif Array_Type
= Any_Type
then
2417 Set_Etype
(N
, Any_Type
);
2419 -- In most cases the analysis of the prefix will have emitted
2420 -- an error already, but if the prefix may be interpreted as a
2421 -- call in prefixed notation, the report is left to the caller.
2422 -- To prevent cascaded errors, report only if no previous ones.
2424 if Serious_Errors_Detected
= 0 then
2425 Error_Msg_N
("invalid prefix in indexed component", P
);
2427 if Nkind
(P
) = N_Expanded_Name
then
2428 Error_Msg_NE
("\& is not visible", P
, Selector_Name
(P
));
2434 -- Here we definitely have a bad indexing
2437 if Nkind
(Parent
(N
)) = N_Requeue_Statement
2438 and then Present
(Pent
) and then Ekind
(Pent
) = E_Entry
2441 ("REQUEUE does not permit parameters", First
(Exprs
));
2443 elsif Is_Entity_Name
(P
)
2444 and then Etype
(P
) = Standard_Void_Type
2446 Error_Msg_NE
("incorrect use of &", P
, Entity
(P
));
2449 Error_Msg_N
("array type required in indexed component", P
);
2452 Set_Etype
(N
, Any_Type
);
2456 Index
:= First_Index
(Array_Type
);
2457 while Present
(Index
) and then Present
(Exp
) loop
2458 if not Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2459 Wrong_Type
(Exp
, Etype
(Index
));
2460 Set_Etype
(N
, Any_Type
);
2468 Set_Etype
(N
, Component_Type
(Array_Type
));
2469 Check_Implicit_Dereference
(N
, Etype
(N
));
2471 if Present
(Index
) then
2473 ("too few subscripts in array reference", First
(Exprs
));
2475 elsif Present
(Exp
) then
2476 Error_Msg_N
("too many subscripts in array reference", Exp
);
2479 end Process_Indexed_Component
;
2481 ----------------------------------------
2482 -- Process_Indexed_Component_Or_Slice --
2483 ----------------------------------------
2485 procedure Process_Indexed_Component_Or_Slice
is
2487 Exp
:= First
(Exprs
);
2488 while Present
(Exp
) loop
2489 Analyze_Expression
(Exp
);
2493 Exp
:= First
(Exprs
);
2495 -- If one index is present, and it is a subtype name, then the node
2496 -- denotes a slice (note that the case of an explicit range for a
2497 -- slice was already built as an N_Slice node in the first place,
2498 -- so that case is not handled here).
2500 -- We use a replace rather than a rewrite here because this is one
2501 -- of the cases in which the tree built by the parser is plain wrong.
2504 and then Is_Entity_Name
(Exp
)
2505 and then Is_Type
(Entity
(Exp
))
2508 Make_Slice
(Sloc
(N
),
2510 Discrete_Range
=> New_Copy
(Exp
)));
2513 -- Otherwise (more than one index present, or single index is not
2514 -- a subtype name), then we have the indexed component case.
2517 Process_Indexed_Component
;
2519 end Process_Indexed_Component_Or_Slice
;
2521 ------------------------------------------
2522 -- Process_Overloaded_Indexed_Component --
2523 ------------------------------------------
2525 procedure Process_Overloaded_Indexed_Component
is
2534 Set_Etype
(N
, Any_Type
);
2536 Get_First_Interp
(P
, I
, It
);
2537 while Present
(It
.Nam
) loop
2540 if Is_Access_Type
(Typ
) then
2541 Typ
:= Designated_Type
(Typ
);
2543 (Warn_On_Dereference
, "?d?implicit dereference", N
);
2546 if Is_Array_Type
(Typ
) then
2548 -- Got a candidate: verify that index types are compatible
2550 Index
:= First_Index
(Typ
);
2552 Exp
:= First
(Exprs
);
2553 while Present
(Index
) and then Present
(Exp
) loop
2554 if Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2566 if Found
and then No
(Index
) and then No
(Exp
) then
2568 CT
: constant Entity_Id
:=
2569 Base_Type
(Component_Type
(Typ
));
2571 Add_One_Interp
(N
, CT
, CT
);
2572 Check_Implicit_Dereference
(N
, CT
);
2576 elsif Try_Container_Indexing
(N
, P
, Exprs
) then
2581 Get_Next_Interp
(I
, It
);
2584 if Etype
(N
) = Any_Type
then
2585 Error_Msg_N
("no legal interpretation for indexed component", N
);
2586 Set_Is_Overloaded
(N
, False);
2590 end Process_Overloaded_Indexed_Component
;
2592 -- Start of processing for Analyze_Indexed_Component_Form
2595 -- Get name of array, function or type
2599 -- If P is an explicit dereference whose prefix is of a remote access-
2600 -- to-subprogram type, then N has already been rewritten as a subprogram
2601 -- call and analyzed.
2603 if Nkind
(N
) in N_Subprogram_Call
then
2606 -- When the prefix is attribute 'Loop_Entry and the sole expression of
2607 -- the indexed component denotes a loop name, the indexed form is turned
2608 -- into an attribute reference.
2610 elsif Nkind
(N
) = N_Attribute_Reference
2611 and then Attribute_Name
(N
) = Name_Loop_Entry
2616 pragma Assert
(Nkind
(N
) = N_Indexed_Component
);
2618 P_T
:= Base_Type
(Etype
(P
));
2620 if Is_Entity_Name
(P
) and then Present
(Entity
(P
)) then
2623 if Is_Type
(U_N
) then
2625 -- Reformat node as a type conversion
2627 E
:= Remove_Head
(Exprs
);
2629 if Present
(First
(Exprs
)) then
2631 ("argument of type conversion must be single expression", N
);
2634 Change_Node
(N
, N_Type_Conversion
);
2635 Set_Subtype_Mark
(N
, P
);
2637 Set_Expression
(N
, E
);
2639 -- After changing the node, call for the specific Analysis
2640 -- routine directly, to avoid a double call to the expander.
2642 Analyze_Type_Conversion
(N
);
2646 if Is_Overloadable
(U_N
) then
2647 Process_Function_Call
;
2649 elsif Ekind
(Etype
(P
)) = E_Subprogram_Type
2650 or else (Is_Access_Type
(Etype
(P
))
2652 Ekind
(Designated_Type
(Etype
(P
))) =
2655 -- Call to access_to-subprogram with possible implicit dereference
2657 Process_Function_Call
;
2659 elsif Is_Generic_Subprogram
(U_N
) then
2661 -- A common beginner's (or C++ templates fan) error
2663 Error_Msg_N
("generic subprogram cannot be called", N
);
2664 Set_Etype
(N
, Any_Type
);
2668 Process_Indexed_Component_Or_Slice
;
2671 -- If not an entity name, prefix is an expression that may denote
2672 -- an array or an access-to-subprogram.
2675 if Ekind
(P_T
) = E_Subprogram_Type
2676 or else (Is_Access_Type
(P_T
)
2678 Ekind
(Designated_Type
(P_T
)) = E_Subprogram_Type
)
2680 Process_Function_Call
;
2682 elsif Nkind
(P
) = N_Selected_Component
2683 and then Present
(Entity
(Selector_Name
(P
)))
2684 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
2686 Process_Function_Call
;
2688 -- In ASIS mode within a generic, a prefixed call is analyzed and
2689 -- partially rewritten but the original indexed component has not
2690 -- yet been rewritten as a call. Perform the replacement now.
2692 elsif Nkind
(P
) = N_Selected_Component
2693 and then Nkind
(Parent
(P
)) = N_Function_Call
2696 Rewrite
(N
, Parent
(P
));
2700 -- Indexed component, slice, or a call to a member of a family
2701 -- entry, which will be converted to an entry call later.
2703 Process_Indexed_Component_Or_Slice
;
2707 Analyze_Dimension
(N
);
2708 end Analyze_Indexed_Component_Form
;
2710 ------------------------
2711 -- Analyze_Logical_Op --
2712 ------------------------
2714 procedure Analyze_Logical_Op
(N
: Node_Id
) is
2715 L
: constant Node_Id
:= Left_Opnd
(N
);
2716 R
: constant Node_Id
:= Right_Opnd
(N
);
2717 Op_Id
: Entity_Id
:= Entity
(N
);
2720 Set_Etype
(N
, Any_Type
);
2721 Candidate_Type
:= Empty
;
2723 Analyze_Expression
(L
);
2724 Analyze_Expression
(R
);
2726 if Present
(Op_Id
) then
2728 if Ekind
(Op_Id
) = E_Operator
then
2729 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
2731 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2735 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
2736 while Present
(Op_Id
) loop
2737 if Ekind
(Op_Id
) = E_Operator
then
2738 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
2740 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
2743 Op_Id
:= Homonym
(Op_Id
);
2748 Check_Function_Writable_Actuals
(N
);
2749 end Analyze_Logical_Op
;
2751 ---------------------------
2752 -- Analyze_Membership_Op --
2753 ---------------------------
2755 procedure Analyze_Membership_Op
(N
: Node_Id
) is
2756 Loc
: constant Source_Ptr
:= Sloc
(N
);
2757 L
: constant Node_Id
:= Left_Opnd
(N
);
2758 R
: constant Node_Id
:= Right_Opnd
(N
);
2760 Index
: Interp_Index
;
2762 Found
: Boolean := False;
2766 procedure Try_One_Interp
(T1
: Entity_Id
);
2767 -- Routine to try one proposed interpretation. Note that the context
2768 -- of the operation plays no role in resolving the arguments, so that
2769 -- if there is more than one interpretation of the operands that is
2770 -- compatible with a membership test, the operation is ambiguous.
2772 --------------------
2773 -- Try_One_Interp --
2774 --------------------
2776 procedure Try_One_Interp
(T1
: Entity_Id
) is
2778 if Has_Compatible_Type
(R
, T1
) then
2780 and then Base_Type
(T1
) /= Base_Type
(T_F
)
2782 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
2784 if It
= No_Interp
then
2785 Ambiguous_Operands
(N
);
2786 Set_Etype
(L
, Any_Type
);
2803 procedure Analyze_Set_Membership
;
2804 -- If a set of alternatives is present, analyze each and find the
2805 -- common type to which they must all resolve.
2807 ----------------------------
2808 -- Analyze_Set_Membership --
2809 ----------------------------
2811 procedure Analyze_Set_Membership
is
2813 Index
: Interp_Index
;
2815 Candidate_Interps
: Node_Id
;
2816 Common_Type
: Entity_Id
:= Empty
;
2819 if Comes_From_Source
(N
) then
2820 Check_Compiler_Unit
("set membership", N
);
2824 Candidate_Interps
:= L
;
2826 if not Is_Overloaded
(L
) then
2827 Common_Type
:= Etype
(L
);
2829 Alt
:= First
(Alternatives
(N
));
2830 while Present
(Alt
) loop
2833 if not Has_Compatible_Type
(Alt
, Common_Type
) then
2834 Wrong_Type
(Alt
, Common_Type
);
2841 Alt
:= First
(Alternatives
(N
));
2842 while Present
(Alt
) loop
2844 if not Is_Overloaded
(Alt
) then
2845 Common_Type
:= Etype
(Alt
);
2848 Get_First_Interp
(Alt
, Index
, It
);
2849 while Present
(It
.Typ
) loop
2851 Has_Compatible_Type
(Candidate_Interps
, It
.Typ
)
2853 Remove_Interp
(Index
);
2856 Get_Next_Interp
(Index
, It
);
2859 Get_First_Interp
(Alt
, Index
, It
);
2862 Error_Msg_N
("alternative has no legal type", Alt
);
2866 -- If alternative is not overloaded, we have a unique type
2869 Set_Etype
(Alt
, It
.Typ
);
2870 Get_Next_Interp
(Index
, It
);
2873 Set_Is_Overloaded
(Alt
, False);
2874 Common_Type
:= Etype
(Alt
);
2877 Candidate_Interps
:= Alt
;
2884 Set_Etype
(N
, Standard_Boolean
);
2886 if Present
(Common_Type
) then
2887 Set_Etype
(L
, Common_Type
);
2889 -- The left operand may still be overloaded, to be resolved using
2893 Error_Msg_N
("cannot resolve membership operation", N
);
2895 end Analyze_Set_Membership
;
2897 -- Start of processing for Analyze_Membership_Op
2900 Analyze_Expression
(L
);
2902 if No
(R
) and then Ada_Version
>= Ada_2012
then
2903 Analyze_Set_Membership
;
2904 Check_Function_Writable_Actuals
(N
);
2909 if Nkind
(R
) = N_Range
2910 or else (Nkind
(R
) = N_Attribute_Reference
2911 and then Attribute_Name
(R
) = Name_Range
)
2915 if not Is_Overloaded
(L
) then
2916 Try_One_Interp
(Etype
(L
));
2919 Get_First_Interp
(L
, Index
, It
);
2920 while Present
(It
.Typ
) loop
2921 Try_One_Interp
(It
.Typ
);
2922 Get_Next_Interp
(Index
, It
);
2926 -- If not a range, it can be a subtype mark, or else it is a degenerate
2927 -- membership test with a singleton value, i.e. a test for equality,
2928 -- if the types are compatible.
2933 if Is_Entity_Name
(R
)
2934 and then Is_Type
(Entity
(R
))
2937 Check_Fully_Declared
(Entity
(R
), R
);
2939 elsif Ada_Version
>= Ada_2012
2940 and then Has_Compatible_Type
(R
, Etype
(L
))
2942 if Nkind
(N
) = N_In
then
2958 -- In all versions of the language, if we reach this point there
2959 -- is a previous error that will be diagnosed below.
2965 -- Compatibility between expression and subtype mark or range is
2966 -- checked during resolution. The result of the operation is Boolean
2969 Set_Etype
(N
, Standard_Boolean
);
2971 if Comes_From_Source
(N
)
2972 and then Present
(Right_Opnd
(N
))
2973 and then Is_CPP_Class
(Etype
(Etype
(Right_Opnd
(N
))))
2975 Error_Msg_N
("membership test not applicable to cpp-class types", N
);
2978 Check_Function_Writable_Actuals
(N
);
2979 end Analyze_Membership_Op
;
2985 procedure Analyze_Mod
(N
: Node_Id
) is
2987 -- A special warning check, if we have an expression of the form:
2988 -- expr mod 2 * literal
2989 -- where literal is 64 or less, then probably what was meant was
2990 -- expr mod 2 ** literal
2991 -- so issue an appropriate warning.
2993 if Warn_On_Suspicious_Modulus_Value
2994 and then Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
2995 and then Intval
(Right_Opnd
(N
)) = Uint_2
2996 and then Nkind
(Parent
(N
)) = N_Op_Multiply
2997 and then Nkind
(Right_Opnd
(Parent
(N
))) = N_Integer_Literal
2998 and then Intval
(Right_Opnd
(Parent
(N
))) <= Uint_64
3001 ("suspicious MOD value, was '*'* intended'??M?", Parent
(N
));
3004 -- Remaining processing is same as for other arithmetic operators
3006 Analyze_Arithmetic_Op
(N
);
3009 ----------------------
3010 -- Analyze_Negation --
3011 ----------------------
3013 procedure Analyze_Negation
(N
: Node_Id
) is
3014 R
: constant Node_Id
:= Right_Opnd
(N
);
3015 Op_Id
: Entity_Id
:= Entity
(N
);
3018 Set_Etype
(N
, Any_Type
);
3019 Candidate_Type
:= Empty
;
3021 Analyze_Expression
(R
);
3023 if Present
(Op_Id
) then
3024 if Ekind
(Op_Id
) = E_Operator
then
3025 Find_Negation_Types
(R
, Op_Id
, N
);
3027 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3031 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
3032 while Present
(Op_Id
) loop
3033 if Ekind
(Op_Id
) = E_Operator
then
3034 Find_Negation_Types
(R
, Op_Id
, N
);
3036 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
3039 Op_Id
:= Homonym
(Op_Id
);
3044 end Analyze_Negation
;
3050 procedure Analyze_Null
(N
: Node_Id
) is
3052 Check_SPARK_05_Restriction
("null is not allowed", N
);
3054 Set_Etype
(N
, Any_Access
);
3057 ----------------------
3058 -- Analyze_One_Call --
3059 ----------------------
3061 procedure Analyze_One_Call
3065 Success
: out Boolean;
3066 Skip_First
: Boolean := False)
3068 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
3069 Prev_T
: constant Entity_Id
:= Etype
(N
);
3071 Must_Skip
: constant Boolean := Skip_First
3072 or else Nkind
(Original_Node
(N
)) = N_Selected_Component
3074 (Nkind
(Original_Node
(N
)) = N_Indexed_Component
3075 and then Nkind
(Prefix
(Original_Node
(N
)))
3076 = N_Selected_Component
);
3077 -- The first formal must be omitted from the match when trying to find
3078 -- a primitive operation that is a possible interpretation, and also
3079 -- after the call has been rewritten, because the corresponding actual
3080 -- is already known to be compatible, and because this may be an
3081 -- indexing of a call with default parameters.
3085 Is_Indexed
: Boolean := False;
3086 Is_Indirect
: Boolean := False;
3087 Subp_Type
: constant Entity_Id
:= Etype
(Nam
);
3090 function Compatible_Types_In_Predicate
3092 T2
: Entity_Id
) return Boolean;
3093 -- For an Ada 2012 predicate or invariant, a call may mention an
3094 -- incomplete type, while resolution of the corresponding predicate
3095 -- function may see the full view, as a consequence of the delayed
3096 -- resolution of the corresponding expressions. This may occur in
3097 -- the body of a predicate function, or in a call to such. Anomalies
3098 -- involving private and full views can also happen. In each case,
3099 -- rewrite node or add conversions to remove spurious type errors.
3101 procedure Indicate_Name_And_Type
;
3102 -- If candidate interpretation matches, indicate name and type of result
3105 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean;
3106 -- There may be a user-defined operator that hides the current
3107 -- interpretation. We must check for this independently of the
3108 -- analysis of the call with the user-defined operation, because
3109 -- the parameter names may be wrong and yet the hiding takes place.
3110 -- This fixes a problem with ACATS test B34014O.
3112 -- When the type Address is a visible integer type, and the DEC
3113 -- system extension is visible, the predefined operator may be
3114 -- hidden as well, by one of the address operations in auxdec.
3115 -- Finally, The abstract operations on address do not hide the
3116 -- predefined operator (this is the purpose of making them abstract).
3118 -----------------------------------
3119 -- Compatible_Types_In_Predicate --
3120 -----------------------------------
3122 function Compatible_Types_In_Predicate
3124 T2
: Entity_Id
) return Boolean
3126 function Common_Type
(T
: Entity_Id
) return Entity_Id
;
3127 -- Find non-private full view if any, without going to ancestor type
3128 -- (as opposed to Underlying_Type).
3134 function Common_Type
(T
: Entity_Id
) return Entity_Id
is
3136 if Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
3137 return Base_Type
(Full_View
(T
));
3139 return Base_Type
(T
);
3143 -- Start of processing for Compatible_Types_In_Predicate
3146 if (Ekind
(Current_Scope
) = E_Function
3147 and then Is_Predicate_Function
(Current_Scope
))
3149 (Ekind
(Nam
) = E_Function
3150 and then Is_Predicate_Function
(Nam
))
3152 if Is_Incomplete_Type
(T1
)
3153 and then Present
(Full_View
(T1
))
3154 and then Full_View
(T1
) = T2
3156 Set_Etype
(Formal
, Etype
(Actual
));
3159 elsif Common_Type
(T1
) = Common_Type
(T2
) then
3160 Rewrite
(Actual
, Unchecked_Convert_To
(Etype
(Formal
), Actual
));
3170 end Compatible_Types_In_Predicate
;
3172 ----------------------------
3173 -- Indicate_Name_And_Type --
3174 ----------------------------
3176 procedure Indicate_Name_And_Type
is
3178 Add_One_Interp
(N
, Nam
, Etype
(Nam
));
3179 Check_Implicit_Dereference
(N
, Etype
(Nam
));
3182 -- If the prefix of the call is a name, indicate the entity
3183 -- being called. If it is not a name, it is an expression that
3184 -- denotes an access to subprogram or else an entry or family. In
3185 -- the latter case, the name is a selected component, and the entity
3186 -- being called is noted on the selector.
3188 if not Is_Type
(Nam
) then
3189 if Is_Entity_Name
(Name
(N
)) then
3190 Set_Entity
(Name
(N
), Nam
);
3191 Set_Etype
(Name
(N
), Etype
(Nam
));
3193 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
3194 Set_Entity
(Selector_Name
(Name
(N
)), Nam
);
3198 if Debug_Flag_E
and not Report
then
3199 Write_Str
(" Overloaded call ");
3200 Write_Int
(Int
(N
));
3201 Write_Str
(" compatible with ");
3202 Write_Int
(Int
(Nam
));
3205 end Indicate_Name_And_Type
;
3207 ------------------------
3208 -- Operator_Hidden_By --
3209 ------------------------
3211 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean is
3212 Act1
: constant Node_Id
:= First_Actual
(N
);
3213 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
3214 Form1
: constant Entity_Id
:= First_Formal
(Fun
);
3215 Form2
: constant Entity_Id
:= Next_Formal
(Form1
);
3218 if Ekind
(Fun
) /= E_Function
or else Is_Abstract_Subprogram
(Fun
) then
3221 elsif not Has_Compatible_Type
(Act1
, Etype
(Form1
)) then
3224 elsif Present
(Form2
) then
3226 or else not Has_Compatible_Type
(Act2
, Etype
(Form2
))
3231 elsif Present
(Act2
) then
3235 -- Now we know that the arity of the operator matches the function,
3236 -- and the function call is a valid interpretation. The function
3237 -- hides the operator if it has the right signature, or if one of
3238 -- its operands is a non-abstract operation on Address when this is
3239 -- a visible integer type.
3241 return Hides_Op
(Fun
, Nam
)
3242 or else Is_Descendant_Of_Address
(Etype
(Form1
))
3245 and then Is_Descendant_Of_Address
(Etype
(Form2
)));
3246 end Operator_Hidden_By
;
3248 -- Start of processing for Analyze_One_Call
3253 -- If the subprogram has no formals or if all the formals have defaults,
3254 -- and the return type is an array type, the node may denote an indexing
3255 -- of the result of a parameterless call. In Ada 2005, the subprogram
3256 -- may have one non-defaulted formal, and the call may have been written
3257 -- in prefix notation, so that the rebuilt parameter list has more than
3260 if not Is_Overloadable
(Nam
)
3261 and then Ekind
(Nam
) /= E_Subprogram_Type
3262 and then Ekind
(Nam
) /= E_Entry_Family
3267 -- An indexing requires at least one actual. The name of the call cannot
3268 -- be an implicit indirect call, so it cannot be a generated explicit
3271 if not Is_Empty_List
(Actuals
)
3273 (Needs_No_Actuals
(Nam
)
3275 (Needs_One_Actual
(Nam
)
3276 and then Present
(Next_Actual
(First
(Actuals
)))))
3278 if Is_Array_Type
(Subp_Type
)
3280 (Nkind
(Name
(N
)) /= N_Explicit_Dereference
3281 or else Comes_From_Source
(Name
(N
)))
3283 Is_Indexed
:= Try_Indexed_Call
(N
, Nam
, Subp_Type
, Must_Skip
);
3285 elsif Is_Access_Type
(Subp_Type
)
3286 and then Is_Array_Type
(Designated_Type
(Subp_Type
))
3290 (N
, Nam
, Designated_Type
(Subp_Type
), Must_Skip
);
3292 -- The prefix can also be a parameterless function that returns an
3293 -- access to subprogram, in which case this is an indirect call.
3294 -- If this succeeds, an explicit dereference is added later on,
3295 -- in Analyze_Call or Resolve_Call.
3297 elsif Is_Access_Type
(Subp_Type
)
3298 and then Ekind
(Designated_Type
(Subp_Type
)) = E_Subprogram_Type
3300 Is_Indirect
:= Try_Indirect_Call
(N
, Nam
, Subp_Type
);
3305 -- If the call has been transformed into a slice, it is of the form
3306 -- F (Subtype) where F is parameterless. The node has been rewritten in
3307 -- Try_Indexed_Call and there is nothing else to do.
3310 and then Nkind
(N
) = N_Slice
3316 (N
, Nam
, (Report
and not Is_Indexed
and not Is_Indirect
), Norm_OK
);
3320 -- If an indirect call is a possible interpretation, indicate
3321 -- success to the caller. This may be an indexing of an explicit
3322 -- dereference of a call that returns an access type (see above).
3326 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
3327 and then Comes_From_Source
(Name
(N
)))
3332 -- Mismatch in number or names of parameters
3334 elsif Debug_Flag_E
then
3335 Write_Str
(" normalization fails in call ");
3336 Write_Int
(Int
(N
));
3337 Write_Str
(" with subprogram ");
3338 Write_Int
(Int
(Nam
));
3342 -- If the context expects a function call, discard any interpretation
3343 -- that is a procedure. If the node is not overloaded, leave as is for
3344 -- better error reporting when type mismatch is found.
3346 elsif Nkind
(N
) = N_Function_Call
3347 and then Is_Overloaded
(Name
(N
))
3348 and then Ekind
(Nam
) = E_Procedure
3352 -- Ditto for function calls in a procedure context
3354 elsif Nkind
(N
) = N_Procedure_Call_Statement
3355 and then Is_Overloaded
(Name
(N
))
3356 and then Etype
(Nam
) /= Standard_Void_Type
3360 elsif No
(Actuals
) then
3362 -- If Normalize succeeds, then there are default parameters for
3365 Indicate_Name_And_Type
;
3367 elsif Ekind
(Nam
) = E_Operator
then
3368 if Nkind
(N
) = N_Procedure_Call_Statement
then
3372 -- This can occur when the prefix of the call is an operator
3373 -- name or an expanded name whose selector is an operator name.
3375 Analyze_Operator_Call
(N
, Nam
);
3377 if Etype
(N
) /= Prev_T
then
3379 -- Check that operator is not hidden by a function interpretation
3381 if Is_Overloaded
(Name
(N
)) then
3387 Get_First_Interp
(Name
(N
), I
, It
);
3388 while Present
(It
.Nam
) loop
3389 if Operator_Hidden_By
(It
.Nam
) then
3390 Set_Etype
(N
, Prev_T
);
3394 Get_Next_Interp
(I
, It
);
3399 -- If operator matches formals, record its name on the call.
3400 -- If the operator is overloaded, Resolve will select the
3401 -- correct one from the list of interpretations. The call
3402 -- node itself carries the first candidate.
3404 Set_Entity
(Name
(N
), Nam
);
3407 elsif Report
and then Etype
(N
) = Any_Type
then
3408 Error_Msg_N
("incompatible arguments for operator", N
);
3412 -- Normalize_Actuals has chained the named associations in the
3413 -- correct order of the formals.
3415 Actual
:= First_Actual
(N
);
3416 Formal
:= First_Formal
(Nam
);
3418 -- If we are analyzing a call rewritten from object notation, skip
3419 -- first actual, which may be rewritten later as an explicit
3423 Next_Actual
(Actual
);
3424 Next_Formal
(Formal
);
3427 while Present
(Actual
) and then Present
(Formal
) loop
3428 if Nkind
(Parent
(Actual
)) /= N_Parameter_Association
3429 or else Chars
(Selector_Name
(Parent
(Actual
))) = Chars
(Formal
)
3431 -- The actual can be compatible with the formal, but we must
3432 -- also check that the context is not an address type that is
3433 -- visibly an integer type. In this case the use of literals is
3434 -- illegal, except in the body of descendants of system, where
3435 -- arithmetic operations on address are of course used.
3437 if Has_Compatible_Type
(Actual
, Etype
(Formal
))
3439 (Etype
(Actual
) /= Universal_Integer
3440 or else not Is_Descendant_Of_Address
(Etype
(Formal
))
3442 Is_Predefined_File_Name
3443 (Unit_File_Name
(Get_Source_Unit
(N
))))
3445 Next_Actual
(Actual
);
3446 Next_Formal
(Formal
);
3448 -- In Allow_Integer_Address mode, we allow an actual integer to
3449 -- match a formal address type and vice versa. We only do this
3450 -- if we are certain that an error will otherwise be issued
3452 elsif Address_Integer_Convert_OK
3453 (Etype
(Actual
), Etype
(Formal
))
3454 and then (Report
and not Is_Indexed
and not Is_Indirect
)
3456 -- Handle this case by introducing an unchecked conversion
3459 Unchecked_Convert_To
(Etype
(Formal
),
3460 Relocate_Node
(Actual
)));
3461 Analyze_And_Resolve
(Actual
, Etype
(Formal
));
3462 Next_Actual
(Actual
);
3463 Next_Formal
(Formal
);
3465 -- Under relaxed RM semantics silently replace occurrences of
3466 -- null by System.Address_Null. We only do this if we know that
3467 -- an error will otherwise be issued.
3469 elsif Null_To_Null_Address_Convert_OK
(Actual
, Etype
(Formal
))
3470 and then (Report
and not Is_Indexed
and not Is_Indirect
)
3472 Replace_Null_By_Null_Address
(Actual
);
3473 Analyze_And_Resolve
(Actual
, Etype
(Formal
));
3474 Next_Actual
(Actual
);
3475 Next_Formal
(Formal
);
3477 elsif Compatible_Types_In_Predicate
3478 (Etype
(Formal
), Etype
(Actual
))
3480 Next_Actual
(Actual
);
3481 Next_Formal
(Formal
);
3483 -- In a complex case where an enclosing generic and a nested
3484 -- generic package, both declared with partially parameterized
3485 -- formal subprograms with the same names, are instantiated
3486 -- with the same type, the types of the actual parameter and
3487 -- that of the formal may appear incompatible at first sight.
3490 -- type Outer_T is private;
3491 -- with function Func (Formal : Outer_T)
3492 -- return ... is <>;
3494 -- package Outer_Gen is
3496 -- type Inner_T is private;
3497 -- with function Func (Formal : Inner_T) -- (1)
3498 -- return ... is <>;
3500 -- package Inner_Gen is
3501 -- function Inner_Func (Formal : Inner_T) -- (2)
3502 -- return ... is (Func (Formal));
3504 -- end Outer_Generic;
3506 -- package Outer_Inst is new Outer_Gen (Actual_T);
3507 -- package Inner_Inst is new Outer_Inst.Inner_Gen (Actual_T);
3509 -- In the example above, the type of parameter
3510 -- Inner_Func.Formal at (2) is incompatible with the type of
3511 -- Func.Formal at (1) in the context of instantiations
3512 -- Outer_Inst and Inner_Inst. In reality both types are generic
3513 -- actual subtypes renaming base type Actual_T as part of the
3514 -- generic prologues for the instantiations.
3516 -- Recognize this case and add a type conversion to allow this
3517 -- kind of generic actual subtype conformance. Note that this
3518 -- is done only when the call is non-overloaded because the
3519 -- resolution mechanism already has the means to disambiguate
3522 elsif not Is_Overloaded
(Name
(N
))
3523 and then Is_Type
(Etype
(Actual
))
3524 and then Is_Type
(Etype
(Formal
))
3525 and then Is_Generic_Actual_Type
(Etype
(Actual
))
3526 and then Is_Generic_Actual_Type
(Etype
(Formal
))
3527 and then Base_Type
(Etype
(Actual
)) =
3528 Base_Type
(Etype
(Formal
))
3531 Convert_To
(Etype
(Formal
), Relocate_Node
(Actual
)));
3532 Analyze_And_Resolve
(Actual
, Etype
(Formal
));
3533 Next_Actual
(Actual
);
3534 Next_Formal
(Formal
);
3536 -- Handle failed type check
3539 if Debug_Flag_E
then
3540 Write_Str
(" type checking fails in call ");
3541 Write_Int
(Int
(N
));
3542 Write_Str
(" with formal ");
3543 Write_Int
(Int
(Formal
));
3544 Write_Str
(" in subprogram ");
3545 Write_Int
(Int
(Nam
));
3549 -- Comment needed on the following test???
3551 if Report
and not Is_Indexed
and not Is_Indirect
then
3553 -- Ada 2005 (AI-251): Complete the error notification
3554 -- to help new Ada 2005 users.
3556 if Is_Class_Wide_Type
(Etype
(Formal
))
3557 and then Is_Interface
(Etype
(Etype
(Formal
)))
3558 and then not Interface_Present_In_Ancestor
3559 (Typ
=> Etype
(Actual
),
3560 Iface
=> Etype
(Etype
(Formal
)))
3563 ("(Ada 2005) does not implement interface }",
3564 Actual
, Etype
(Etype
(Formal
)));
3567 Wrong_Type
(Actual
, Etype
(Formal
));
3569 if Nkind
(Actual
) = N_Op_Eq
3570 and then Nkind
(Left_Opnd
(Actual
)) = N_Identifier
3572 Formal
:= First_Formal
(Nam
);
3573 while Present
(Formal
) loop
3574 if Chars
(Left_Opnd
(Actual
)) = Chars
(Formal
) then
3575 Error_Msg_N
-- CODEFIX
3576 ("possible misspelling of `='>`!", Actual
);
3580 Next_Formal
(Formal
);
3584 if All_Errors_Mode
then
3585 Error_Msg_Sloc
:= Sloc
(Nam
);
3587 if Etype
(Formal
) = Any_Type
then
3589 ("there is no legal actual parameter", Actual
);
3592 if Is_Overloadable
(Nam
)
3593 and then Present
(Alias
(Nam
))
3594 and then not Comes_From_Source
(Nam
)
3597 ("\\ =='> in call to inherited operation & #!",
3600 elsif Ekind
(Nam
) = E_Subprogram_Type
then
3602 Access_To_Subprogram_Typ
:
3603 constant Entity_Id
:=
3605 (Associated_Node_For_Itype
(Nam
));
3608 ("\\ =='> in call to dereference of &#!",
3609 Actual
, Access_To_Subprogram_Typ
);
3614 ("\\ =='> in call to &#!", Actual
, Nam
);
3624 -- Normalize_Actuals has verified that a default value exists
3625 -- for this formal. Current actual names a subsequent formal.
3627 Next_Formal
(Formal
);
3631 -- On exit, all actuals match
3633 Indicate_Name_And_Type
;
3635 end Analyze_One_Call
;
3637 ---------------------------
3638 -- Analyze_Operator_Call --
3639 ---------------------------
3641 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
) is
3642 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
3643 Act1
: constant Node_Id
:= First_Actual
(N
);
3644 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
3647 -- Binary operator case
3649 if Present
(Act2
) then
3651 -- If more than two operands, then not binary operator after all
3653 if Present
(Next_Actual
(Act2
)) then
3657 -- Otherwise action depends on operator
3667 Find_Arithmetic_Types
(Act1
, Act2
, Op_Id
, N
);
3672 Find_Boolean_Types
(Act1
, Act2
, Op_Id
, N
);
3678 Find_Comparison_Types
(Act1
, Act2
, Op_Id
, N
);
3682 Find_Equality_Types
(Act1
, Act2
, Op_Id
, N
);
3684 when Name_Op_Concat
=>
3685 Find_Concatenation_Types
(Act1
, Act2
, Op_Id
, N
);
3687 -- Is this when others, or should it be an abort???
3693 -- Unary operator case
3697 when Name_Op_Subtract |
3700 Find_Unary_Types
(Act1
, Op_Id
, N
);
3703 Find_Negation_Types
(Act1
, Op_Id
, N
);
3705 -- Is this when others correct, or should it be an abort???
3711 end Analyze_Operator_Call
;
3713 -------------------------------------------
3714 -- Analyze_Overloaded_Selected_Component --
3715 -------------------------------------------
3717 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
) is
3718 Nam
: constant Node_Id
:= Prefix
(N
);
3719 Sel
: constant Node_Id
:= Selector_Name
(N
);
3726 Set_Etype
(Sel
, Any_Type
);
3728 Get_First_Interp
(Nam
, I
, It
);
3729 while Present
(It
.Typ
) loop
3730 if Is_Access_Type
(It
.Typ
) then
3731 T
:= Designated_Type
(It
.Typ
);
3732 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
3737 -- Locate the component. For a private prefix the selector can denote
3740 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
3742 -- If the prefix is a class-wide type, the visible components are
3743 -- those of the base type.
3745 if Is_Class_Wide_Type
(T
) then
3749 Comp
:= First_Entity
(T
);
3750 while Present
(Comp
) loop
3751 if Chars
(Comp
) = Chars
(Sel
)
3752 and then Is_Visible_Component
(Comp
)
3755 -- AI05-105: if the context is an object renaming with
3756 -- an anonymous access type, the expected type of the
3757 -- object must be anonymous. This is a name resolution rule.
3759 if Nkind
(Parent
(N
)) /= N_Object_Renaming_Declaration
3760 or else No
(Access_Definition
(Parent
(N
)))
3761 or else Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Type
3763 Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Subprogram_Type
3765 Set_Entity
(Sel
, Comp
);
3766 Set_Etype
(Sel
, Etype
(Comp
));
3767 Add_One_Interp
(N
, Etype
(Comp
), Etype
(Comp
));
3768 Check_Implicit_Dereference
(N
, Etype
(Comp
));
3770 -- This also specifies a candidate to resolve the name.
3771 -- Further overloading will be resolved from context.
3772 -- The selector name itself does not carry overloading
3775 Set_Etype
(Nam
, It
.Typ
);
3778 -- Named access type in the context of a renaming
3779 -- declaration with an access definition. Remove
3780 -- inapplicable candidate.
3789 elsif Is_Concurrent_Type
(T
) then
3790 Comp
:= First_Entity
(T
);
3791 while Present
(Comp
)
3792 and then Comp
/= First_Private_Entity
(T
)
3794 if Chars
(Comp
) = Chars
(Sel
) then
3795 if Is_Overloadable
(Comp
) then
3796 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
3798 Set_Entity_With_Checks
(Sel
, Comp
);
3799 Generate_Reference
(Comp
, Sel
);
3802 Set_Etype
(Sel
, Etype
(Comp
));
3803 Set_Etype
(N
, Etype
(Comp
));
3804 Set_Etype
(Nam
, It
.Typ
);
3806 -- For access type case, introduce explicit dereference for
3807 -- more uniform treatment of entry calls. Do this only once
3808 -- if several interpretations yield an access type.
3810 if Is_Access_Type
(Etype
(Nam
))
3811 and then Nkind
(Nam
) /= N_Explicit_Dereference
3813 Insert_Explicit_Dereference
(Nam
);
3815 (Warn_On_Dereference
, "?d?implicit dereference", N
);
3822 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
3825 Get_Next_Interp
(I
, It
);
3828 if Etype
(N
) = Any_Type
3829 and then not Try_Object_Operation
(N
)
3831 Error_Msg_NE
("undefined selector& for overloaded prefix", N
, Sel
);
3832 Set_Entity
(Sel
, Any_Id
);
3833 Set_Etype
(Sel
, Any_Type
);
3835 end Analyze_Overloaded_Selected_Component
;
3837 ----------------------------------
3838 -- Analyze_Qualified_Expression --
3839 ----------------------------------
3841 procedure Analyze_Qualified_Expression
(N
: Node_Id
) is
3842 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
3843 Expr
: constant Node_Id
:= Expression
(N
);
3849 Analyze_Expression
(Expr
);
3851 Set_Etype
(N
, Any_Type
);
3856 if T
= Any_Type
then
3860 Check_Fully_Declared
(T
, N
);
3862 -- If expected type is class-wide, check for exact match before
3863 -- expansion, because if the expression is a dispatching call it
3864 -- may be rewritten as explicit dereference with class-wide result.
3865 -- If expression is overloaded, retain only interpretations that
3866 -- will yield exact matches.
3868 if Is_Class_Wide_Type
(T
) then
3869 if not Is_Overloaded
(Expr
) then
3870 if Base_Type
(Etype
(Expr
)) /= Base_Type
(T
) then
3871 if Nkind
(Expr
) = N_Aggregate
then
3872 Error_Msg_N
("type of aggregate cannot be class-wide", Expr
);
3874 Wrong_Type
(Expr
, T
);
3879 Get_First_Interp
(Expr
, I
, It
);
3881 while Present
(It
.Nam
) loop
3882 if Base_Type
(It
.Typ
) /= Base_Type
(T
) then
3886 Get_Next_Interp
(I
, It
);
3892 end Analyze_Qualified_Expression
;
3894 -----------------------------------
3895 -- Analyze_Quantified_Expression --
3896 -----------------------------------
3898 procedure Analyze_Quantified_Expression
(N
: Node_Id
) is
3899 function Is_Empty_Range
(Typ
: Entity_Id
) return Boolean;
3900 -- If the iterator is part of a quantified expression, and the range is
3901 -- known to be statically empty, emit a warning and replace expression
3902 -- with its static value. Returns True if the replacement occurs.
3904 function No_Else_Or_Trivial_True
(If_Expr
: Node_Id
) return Boolean;
3905 -- Determine whether if expression If_Expr lacks an else part or if it
3906 -- has one, it evaluates to True.
3908 --------------------
3909 -- Is_Empty_Range --
3910 --------------------
3912 function Is_Empty_Range
(Typ
: Entity_Id
) return Boolean is
3913 Loc
: constant Source_Ptr
:= Sloc
(N
);
3916 if Is_Array_Type
(Typ
)
3917 and then Compile_Time_Known_Bounds
(Typ
)
3919 (Expr_Value
(Type_Low_Bound
(Etype
(First_Index
(Typ
)))) >
3920 Expr_Value
(Type_High_Bound
(Etype
(First_Index
(Typ
)))))
3922 Preanalyze_And_Resolve
(Condition
(N
), Standard_Boolean
);
3924 if All_Present
(N
) then
3926 ("??quantified expression with ALL "
3927 & "over a null range has value True", N
);
3928 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
3932 ("??quantified expression with SOME "
3933 & "over a null range has value False", N
);
3934 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
3945 -----------------------------
3946 -- No_Else_Or_Trivial_True --
3947 -----------------------------
3949 function No_Else_Or_Trivial_True
(If_Expr
: Node_Id
) return Boolean is
3950 Else_Expr
: constant Node_Id
:=
3951 Next
(Next
(First
(Expressions
(If_Expr
))));
3955 or else (Compile_Time_Known_Value
(Else_Expr
)
3956 and then Is_True
(Expr_Value
(Else_Expr
)));
3957 end No_Else_Or_Trivial_True
;
3961 Cond
: constant Node_Id
:= Condition
(N
);
3962 Loop_Id
: Entity_Id
;
3963 QE_Scop
: Entity_Id
;
3965 -- Start of processing for Analyze_Quantified_Expression
3968 Check_SPARK_05_Restriction
("quantified expression is not allowed", N
);
3970 -- Create a scope to emulate the loop-like behavior of the quantified
3971 -- expression. The scope is needed to provide proper visibility of the
3974 QE_Scop
:= New_Internal_Entity
(E_Loop
, Current_Scope
, Sloc
(N
), 'L');
3975 Set_Etype
(QE_Scop
, Standard_Void_Type
);
3976 Set_Scope
(QE_Scop
, Current_Scope
);
3977 Set_Parent
(QE_Scop
, N
);
3979 Push_Scope
(QE_Scop
);
3981 -- All constituents are preanalyzed and resolved to avoid untimely
3982 -- generation of various temporaries and types. Full analysis and
3983 -- expansion is carried out when the quantified expression is
3984 -- transformed into an expression with actions.
3986 if Present
(Iterator_Specification
(N
)) then
3987 Preanalyze
(Iterator_Specification
(N
));
3989 -- Do not proceed with the analysis when the range of iteration is
3990 -- empty. The appropriate error is issued by Is_Empty_Range.
3992 if Is_Entity_Name
(Name
(Iterator_Specification
(N
)))
3993 and then Is_Empty_Range
(Etype
(Name
(Iterator_Specification
(N
))))
3998 else pragma Assert
(Present
(Loop_Parameter_Specification
(N
)));
4000 Loop_Par
: constant Node_Id
:= Loop_Parameter_Specification
(N
);
4003 Preanalyze
(Loop_Par
);
4005 if Nkind
(Discrete_Subtype_Definition
(Loop_Par
)) = N_Function_Call
4006 and then Parent
(Loop_Par
) /= N
4008 -- The parser cannot distinguish between a loop specification
4009 -- and an iterator specification. If after pre-analysis the
4010 -- proper form has been recognized, rewrite the expression to
4011 -- reflect the right kind. This is needed for proper ASIS
4012 -- navigation. If expansion is enabled, the transformation is
4013 -- performed when the expression is rewritten as a loop.
4015 Set_Iterator_Specification
(N
,
4016 New_Copy_Tree
(Iterator_Specification
(Parent
(Loop_Par
))));
4018 Set_Defining_Identifier
(Iterator_Specification
(N
),
4019 Relocate_Node
(Defining_Identifier
(Loop_Par
)));
4020 Set_Name
(Iterator_Specification
(N
),
4021 Relocate_Node
(Discrete_Subtype_Definition
(Loop_Par
)));
4022 Set_Comes_From_Source
(Iterator_Specification
(N
),
4023 Comes_From_Source
(Loop_Parameter_Specification
(N
)));
4024 Set_Loop_Parameter_Specification
(N
, Empty
);
4029 Preanalyze_And_Resolve
(Cond
, Standard_Boolean
);
4032 Set_Etype
(N
, Standard_Boolean
);
4034 -- Verify that the loop variable is used within the condition of the
4035 -- quantified expression.
4037 if Present
(Iterator_Specification
(N
)) then
4038 Loop_Id
:= Defining_Identifier
(Iterator_Specification
(N
));
4040 Loop_Id
:= Defining_Identifier
(Loop_Parameter_Specification
(N
));
4043 if Warn_On_Suspicious_Contract
4044 and then not Referenced
(Loop_Id
, Cond
)
4046 -- Generating C, this check causes spurious warnings on inlined
4047 -- postconditions; we can safely disable it because this check
4048 -- was previously performed when analyzing the internally built
4049 -- postconditions procedure.
4051 if Modify_Tree_For_C
and then In_Inlined_Body
then
4054 Error_Msg_N
("?T?unused variable &", Loop_Id
);
4058 -- Diagnose a possible misuse of the SOME existential quantifier. When
4059 -- we have a quantified expression of the form:
4061 -- for some X => (if P then Q [else True])
4063 -- any value for X that makes P False results in the if expression being
4064 -- trivially True, and so also results in the quantified expression
4065 -- being trivially True.
4067 if Warn_On_Suspicious_Contract
4068 and then not All_Present
(N
)
4069 and then Nkind
(Cond
) = N_If_Expression
4070 and then No_Else_Or_Trivial_True
(Cond
)
4072 Error_Msg_N
("?T?suspicious expression", N
);
4073 Error_Msg_N
("\\did you mean (for all X ='> (if P then Q))", N
);
4074 Error_Msg_N
("\\or (for some X ='> P and then Q) instead'?", N
);
4076 end Analyze_Quantified_Expression
;
4082 procedure Analyze_Range
(N
: Node_Id
) is
4083 L
: constant Node_Id
:= Low_Bound
(N
);
4084 H
: constant Node_Id
:= High_Bound
(N
);
4085 I1
, I2
: Interp_Index
;
4088 procedure Check_Common_Type
(T1
, T2
: Entity_Id
);
4089 -- Verify the compatibility of two types, and choose the
4090 -- non universal one if the other is universal.
4092 procedure Check_High_Bound
(T
: Entity_Id
);
4093 -- Test one interpretation of the low bound against all those
4094 -- of the high bound.
4096 procedure Check_Universal_Expression
(N
: Node_Id
);
4097 -- In Ada 83, reject bounds of a universal range that are not literals
4100 -----------------------
4101 -- Check_Common_Type --
4102 -----------------------
4104 procedure Check_Common_Type
(T1
, T2
: Entity_Id
) is
4106 if Covers
(T1
=> T1
, T2
=> T2
)
4108 Covers
(T1
=> T2
, T2
=> T1
)
4110 if T1
= Universal_Integer
4111 or else T1
= Universal_Real
4112 or else T1
= Any_Character
4114 Add_One_Interp
(N
, Base_Type
(T2
), Base_Type
(T2
));
4117 Add_One_Interp
(N
, T1
, T1
);
4120 Add_One_Interp
(N
, Base_Type
(T1
), Base_Type
(T1
));
4123 end Check_Common_Type
;
4125 ----------------------
4126 -- Check_High_Bound --
4127 ----------------------
4129 procedure Check_High_Bound
(T
: Entity_Id
) is
4131 if not Is_Overloaded
(H
) then
4132 Check_Common_Type
(T
, Etype
(H
));
4134 Get_First_Interp
(H
, I2
, It2
);
4135 while Present
(It2
.Typ
) loop
4136 Check_Common_Type
(T
, It2
.Typ
);
4137 Get_Next_Interp
(I2
, It2
);
4140 end Check_High_Bound
;
4142 -----------------------------
4143 -- Is_Universal_Expression --
4144 -----------------------------
4146 procedure Check_Universal_Expression
(N
: Node_Id
) is
4148 if Etype
(N
) = Universal_Integer
4149 and then Nkind
(N
) /= N_Integer_Literal
4150 and then not Is_Entity_Name
(N
)
4151 and then Nkind
(N
) /= N_Attribute_Reference
4153 Error_Msg_N
("illegal bound in discrete range", N
);
4155 end Check_Universal_Expression
;
4157 -- Start of processing for Analyze_Range
4160 Set_Etype
(N
, Any_Type
);
4161 Analyze_Expression
(L
);
4162 Analyze_Expression
(H
);
4164 if Etype
(L
) = Any_Type
or else Etype
(H
) = Any_Type
then
4168 if not Is_Overloaded
(L
) then
4169 Check_High_Bound
(Etype
(L
));
4171 Get_First_Interp
(L
, I1
, It1
);
4172 while Present
(It1
.Typ
) loop
4173 Check_High_Bound
(It1
.Typ
);
4174 Get_Next_Interp
(I1
, It1
);
4178 -- If result is Any_Type, then we did not find a compatible pair
4180 if Etype
(N
) = Any_Type
then
4181 Error_Msg_N
("incompatible types in range ", N
);
4185 if Ada_Version
= Ada_83
4187 (Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
4188 or else Nkind
(Parent
(N
)) = N_Constrained_Array_Definition
)
4190 Check_Universal_Expression
(L
);
4191 Check_Universal_Expression
(H
);
4194 Check_Function_Writable_Actuals
(N
);
4197 -----------------------
4198 -- Analyze_Reference --
4199 -----------------------
4201 procedure Analyze_Reference
(N
: Node_Id
) is
4202 P
: constant Node_Id
:= Prefix
(N
);
4205 Acc_Type
: Entity_Id
;
4210 -- An interesting error check, if we take the 'Ref of an object for
4211 -- which a pragma Atomic or Volatile has been given, and the type of the
4212 -- object is not Atomic or Volatile, then we are in trouble. The problem
4213 -- is that no trace of the atomic/volatile status will remain for the
4214 -- backend to respect when it deals with the resulting pointer, since
4215 -- the pointer type will not be marked atomic (it is a pointer to the
4216 -- base type of the object).
4218 -- It is not clear if that can ever occur, but in case it does, we will
4219 -- generate an error message. Not clear if this message can ever be
4220 -- generated, and pretty clear that it represents a bug if it is, still
4221 -- seems worth checking, except in CodePeer mode where we do not really
4222 -- care and don't want to bother the user.
4226 if Is_Entity_Name
(P
)
4227 and then Is_Object_Reference
(P
)
4228 and then not CodePeer_Mode
4233 if (Has_Atomic_Components
(E
)
4234 and then not Has_Atomic_Components
(T
))
4236 (Has_Volatile_Components
(E
)
4237 and then not Has_Volatile_Components
(T
))
4238 or else (Is_Atomic
(E
) and then not Is_Atomic
(T
))
4239 or else (Is_Volatile
(E
) and then not Is_Volatile
(T
))
4241 Error_Msg_N
("cannot take reference to Atomic/Volatile object", N
);
4245 -- Carry on with normal processing
4247 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
4248 Set_Etype
(Acc_Type
, Acc_Type
);
4249 Set_Directly_Designated_Type
(Acc_Type
, Etype
(P
));
4250 Set_Etype
(N
, Acc_Type
);
4251 end Analyze_Reference
;
4253 --------------------------------
4254 -- Analyze_Selected_Component --
4255 --------------------------------
4257 -- Prefix is a record type or a task or protected type. In the latter case,
4258 -- the selector must denote a visible entry.
4260 procedure Analyze_Selected_Component
(N
: Node_Id
) is
4261 Name
: constant Node_Id
:= Prefix
(N
);
4262 Sel
: constant Node_Id
:= Selector_Name
(N
);
4265 Has_Candidate
: Boolean := False;
4268 Pent
: Entity_Id
:= Empty
;
4269 Prefix_Type
: Entity_Id
;
4271 Type_To_Use
: Entity_Id
;
4272 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
4273 -- a class-wide type, we use its root type, whose components are
4274 -- present in the class-wide type.
4276 Is_Single_Concurrent_Object
: Boolean;
4277 -- Set True if the prefix is a single task or a single protected object
4279 procedure Find_Component_In_Instance
(Rec
: Entity_Id
);
4280 -- In an instance, a component of a private extension may not be visible
4281 -- while it was visible in the generic. Search candidate scope for a
4282 -- component with the proper identifier. This is only done if all other
4283 -- searches have failed. If a match is found, the Etype of both N and
4284 -- Sel are set from this component, and the entity of Sel is set to
4285 -- reference this component. If no match is found, Entity (Sel) remains
4286 -- unset. For a derived type that is an actual of the instance, the
4287 -- desired component may be found in any ancestor.
4289 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean;
4290 -- It is known that the parent of N denotes a subprogram call. Comp
4291 -- is an overloadable component of the concurrent type of the prefix.
4292 -- Determine whether all formals of the parent of N and Comp are mode
4293 -- conformant. If the parent node is not analyzed yet it may be an
4294 -- indexed component rather than a function call.
4296 function Has_Dereference
(Nod
: Node_Id
) return Boolean;
4297 -- Check whether prefix includes a dereference at any level.
4299 --------------------------------
4300 -- Find_Component_In_Instance --
4301 --------------------------------
4303 procedure Find_Component_In_Instance
(Rec
: Entity_Id
) is
4309 while Present
(Typ
) loop
4310 Comp
:= First_Component
(Typ
);
4311 while Present
(Comp
) loop
4312 if Chars
(Comp
) = Chars
(Sel
) then
4313 Set_Entity_With_Checks
(Sel
, Comp
);
4314 Set_Etype
(Sel
, Etype
(Comp
));
4315 Set_Etype
(N
, Etype
(Comp
));
4319 Next_Component
(Comp
);
4322 -- If not found, the component may be declared in the parent
4323 -- type or its full view, if any.
4325 if Is_Derived_Type
(Typ
) then
4328 if Is_Private_Type
(Typ
) then
4329 Typ
:= Full_View
(Typ
);
4337 -- If we fall through, no match, so no changes made
4340 end Find_Component_In_Instance
;
4342 ------------------------------
4343 -- Has_Mode_Conformant_Spec --
4344 ------------------------------
4346 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean is
4347 Comp_Param
: Entity_Id
;
4349 Param_Typ
: Entity_Id
;
4352 Comp_Param
:= First_Formal
(Comp
);
4354 if Nkind
(Parent
(N
)) = N_Indexed_Component
then
4355 Param
:= First
(Expressions
(Parent
(N
)));
4357 Param
:= First
(Parameter_Associations
(Parent
(N
)));
4360 while Present
(Comp_Param
)
4361 and then Present
(Param
)
4363 Param_Typ
:= Find_Parameter_Type
(Param
);
4365 if Present
(Param_Typ
)
4367 not Conforming_Types
4368 (Etype
(Comp_Param
), Param_Typ
, Mode_Conformant
)
4373 Next_Formal
(Comp_Param
);
4377 -- One of the specs has additional formals; there is no match, unless
4378 -- this may be an indexing of a parameterless call.
4380 -- Note that when expansion is disabled, the corresponding record
4381 -- type of synchronized types is not constructed, so that there is
4382 -- no point is attempting an interpretation as a prefixed call, as
4383 -- this is bound to fail because the primitive operations will not
4384 -- be properly located.
4386 if Present
(Comp_Param
) or else Present
(Param
) then
4387 if Needs_No_Actuals
(Comp
)
4388 and then Is_Array_Type
(Etype
(Comp
))
4389 and then not Expander_Active
4398 end Has_Mode_Conformant_Spec
;
4400 ---------------------
4401 -- Has_Dereference --
4402 ---------------------
4404 function Has_Dereference
(Nod
: Node_Id
) return Boolean is
4406 if Nkind
(Nod
) = N_Explicit_Dereference
then
4409 -- When expansion is disabled an explicit dereference may not have
4410 -- been inserted, but if this is an access type the indirection makes
4413 elsif Is_Access_Type
(Etype
(Nod
)) then
4416 elsif Nkind_In
(Nod
, N_Indexed_Component
, N_Selected_Component
) then
4417 return Has_Dereference
(Prefix
(Nod
));
4422 end Has_Dereference
;
4424 -- Start of processing for Analyze_Selected_Component
4427 Set_Etype
(N
, Any_Type
);
4429 if Is_Overloaded
(Name
) then
4430 Analyze_Overloaded_Selected_Component
(N
);
4433 elsif Etype
(Name
) = Any_Type
then
4434 Set_Entity
(Sel
, Any_Id
);
4435 Set_Etype
(Sel
, Any_Type
);
4439 Prefix_Type
:= Etype
(Name
);
4442 if Is_Access_Type
(Prefix_Type
) then
4444 -- A RACW object can never be used as prefix of a selected component
4445 -- since that means it is dereferenced without being a controlling
4446 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
4447 -- reporting an error, we must check whether this is actually a
4448 -- dispatching call in prefix form.
4450 if Is_Remote_Access_To_Class_Wide_Type
(Prefix_Type
)
4451 and then Comes_From_Source
(N
)
4453 if Try_Object_Operation
(N
) then
4457 ("invalid dereference of a remote access-to-class-wide value",
4461 -- Normal case of selected component applied to access type
4464 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4466 if Is_Entity_Name
(Name
) then
4467 Pent
:= Entity
(Name
);
4468 elsif Nkind
(Name
) = N_Selected_Component
4469 and then Is_Entity_Name
(Selector_Name
(Name
))
4471 Pent
:= Entity
(Selector_Name
(Name
));
4474 Prefix_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, Name
);
4477 -- If we have an explicit dereference of a remote access-to-class-wide
4478 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
4479 -- have to check for the case of a prefix that is a controlling operand
4480 -- of a prefixed dispatching call, as the dereference is legal in that
4481 -- case. Normally this condition is checked in Validate_Remote_Access_
4482 -- To_Class_Wide_Type, but we have to defer the checking for selected
4483 -- component prefixes because of the prefixed dispatching call case.
4484 -- Note that implicit dereferences are checked for this just above.
4486 elsif Nkind
(Name
) = N_Explicit_Dereference
4487 and then Is_Remote_Access_To_Class_Wide_Type
(Etype
(Prefix
(Name
)))
4488 and then Comes_From_Source
(N
)
4490 if Try_Object_Operation
(N
) then
4494 ("invalid dereference of a remote access-to-class-wide value",
4499 -- (Ada 2005): if the prefix is the limited view of a type, and
4500 -- the context already includes the full view, use the full view
4501 -- in what follows, either to retrieve a component of to find
4502 -- a primitive operation. If the prefix is an explicit dereference,
4503 -- set the type of the prefix to reflect this transformation.
4504 -- If the non-limited view is itself an incomplete type, get the
4505 -- full view if available.
4507 if From_Limited_With
(Prefix_Type
)
4508 and then Has_Non_Limited_View
(Prefix_Type
)
4510 Prefix_Type
:= Get_Full_View
(Non_Limited_View
(Prefix_Type
));
4512 if Nkind
(N
) = N_Explicit_Dereference
then
4513 Set_Etype
(Prefix
(N
), Prefix_Type
);
4517 if Ekind
(Prefix_Type
) = E_Private_Subtype
then
4518 Prefix_Type
:= Base_Type
(Prefix_Type
);
4521 Type_To_Use
:= Prefix_Type
;
4523 -- For class-wide types, use the entity list of the root type. This
4524 -- indirection is specially important for private extensions because
4525 -- only the root type get switched (not the class-wide type).
4527 if Is_Class_Wide_Type
(Prefix_Type
) then
4528 Type_To_Use
:= Root_Type
(Prefix_Type
);
4531 -- If the prefix is a single concurrent object, use its name in error
4532 -- messages, rather than that of its anonymous type.
4534 Is_Single_Concurrent_Object
:=
4535 Is_Concurrent_Type
(Prefix_Type
)
4536 and then Is_Internal_Name
(Chars
(Prefix_Type
))
4537 and then not Is_Derived_Type
(Prefix_Type
)
4538 and then Is_Entity_Name
(Name
);
4540 Comp
:= First_Entity
(Type_To_Use
);
4542 -- If the selector has an original discriminant, the node appears in
4543 -- an instance. Replace the discriminant with the corresponding one
4544 -- in the current discriminated type. For nested generics, this must
4545 -- be done transitively, so note the new original discriminant.
4547 if Nkind
(Sel
) = N_Identifier
4548 and then In_Instance
4549 and then Present
(Original_Discriminant
(Sel
))
4551 Comp
:= Find_Corresponding_Discriminant
(Sel
, Prefix_Type
);
4553 -- Mark entity before rewriting, for completeness and because
4554 -- subsequent semantic checks might examine the original node.
4556 Set_Entity
(Sel
, Comp
);
4557 Rewrite
(Selector_Name
(N
), New_Occurrence_Of
(Comp
, Sloc
(N
)));
4558 Set_Original_Discriminant
(Selector_Name
(N
), Comp
);
4559 Set_Etype
(N
, Etype
(Comp
));
4560 Check_Implicit_Dereference
(N
, Etype
(Comp
));
4562 if Is_Access_Type
(Etype
(Name
)) then
4563 Insert_Explicit_Dereference
(Name
);
4564 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4567 elsif Is_Record_Type
(Prefix_Type
) then
4569 -- Find component with given name. In an instance, if the node is
4570 -- known as a prefixed call, do not examine components whose
4571 -- visibility may be accidental.
4573 while Present
(Comp
) and then not Is_Prefixed_Call
(N
) loop
4574 if Chars
(Comp
) = Chars
(Sel
)
4575 and then Is_Visible_Component
(Comp
, N
)
4577 Set_Entity_With_Checks
(Sel
, Comp
);
4578 Set_Etype
(Sel
, Etype
(Comp
));
4580 if Ekind
(Comp
) = E_Discriminant
then
4581 if Is_Unchecked_Union
(Base_Type
(Prefix_Type
)) then
4583 ("cannot reference discriminant of unchecked union",
4587 if Is_Generic_Type
(Prefix_Type
)
4589 Is_Generic_Type
(Root_Type
(Prefix_Type
))
4591 Set_Original_Discriminant
(Sel
, Comp
);
4595 -- Resolve the prefix early otherwise it is not possible to
4596 -- build the actual subtype of the component: it may need
4597 -- to duplicate this prefix and duplication is only allowed
4598 -- on fully resolved expressions.
4602 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
4603 -- subtypes in a package specification.
4606 -- limited with Pkg;
4608 -- type Acc_Inc is access Pkg.T;
4610 -- N : Natural := X.all.Comp; -- ERROR, limited view
4611 -- end Pkg; -- Comp is not visible
4613 if Nkind
(Name
) = N_Explicit_Dereference
4614 and then From_Limited_With
(Etype
(Prefix
(Name
)))
4615 and then not Is_Potentially_Use_Visible
(Etype
(Name
))
4616 and then Nkind
(Parent
(Cunit_Entity
(Current_Sem_Unit
))) =
4617 N_Package_Specification
4620 ("premature usage of incomplete}", Prefix
(Name
),
4621 Etype
(Prefix
(Name
)));
4624 -- We never need an actual subtype for the case of a selection
4625 -- for a indexed component of a non-packed array, since in
4626 -- this case gigi generates all the checks and can find the
4627 -- necessary bounds information.
4629 -- We also do not need an actual subtype for the case of a
4630 -- first, last, length, or range attribute applied to a
4631 -- non-packed array, since gigi can again get the bounds in
4632 -- these cases (gigi cannot handle the packed case, since it
4633 -- has the bounds of the packed array type, not the original
4634 -- bounds of the type). However, if the prefix is itself a
4635 -- selected component, as in a.b.c (i), gigi may regard a.b.c
4636 -- as a dynamic-sized temporary, so we do generate an actual
4637 -- subtype for this case.
4639 Parent_N
:= Parent
(N
);
4641 if not Is_Packed
(Etype
(Comp
))
4643 ((Nkind
(Parent_N
) = N_Indexed_Component
4644 and then Nkind
(Name
) /= N_Selected_Component
)
4646 (Nkind
(Parent_N
) = N_Attribute_Reference
4648 Nam_In
(Attribute_Name
(Parent_N
), Name_First
,
4653 Set_Etype
(N
, Etype
(Comp
));
4655 -- If full analysis is not enabled, we do not generate an
4656 -- actual subtype, because in the absence of expansion
4657 -- reference to a formal of a protected type, for example,
4658 -- will not be properly transformed, and will lead to
4659 -- out-of-scope references in gigi.
4661 -- In all other cases, we currently build an actual subtype.
4662 -- It seems likely that many of these cases can be avoided,
4663 -- but right now, the front end makes direct references to the
4664 -- bounds (e.g. in generating a length check), and if we do
4665 -- not make an actual subtype, we end up getting a direct
4666 -- reference to a discriminant, which will not do.
4668 elsif Full_Analysis
then
4670 Build_Actual_Subtype_Of_Component
(Etype
(Comp
), N
);
4671 Insert_Action
(N
, Act_Decl
);
4673 if No
(Act_Decl
) then
4674 Set_Etype
(N
, Etype
(Comp
));
4677 -- Component type depends on discriminants. Enter the
4678 -- main attributes of the subtype.
4681 Subt
: constant Entity_Id
:=
4682 Defining_Identifier
(Act_Decl
);
4685 Set_Etype
(Subt
, Base_Type
(Etype
(Comp
)));
4686 Set_Ekind
(Subt
, Ekind
(Etype
(Comp
)));
4687 Set_Etype
(N
, Subt
);
4691 -- If Full_Analysis not enabled, just set the Etype
4694 Set_Etype
(N
, Etype
(Comp
));
4697 Check_Implicit_Dereference
(N
, Etype
(N
));
4701 -- If the prefix is a private extension, check only the visible
4702 -- components of the partial view. This must include the tag,
4703 -- which can appear in expanded code in a tag check.
4705 if Ekind
(Type_To_Use
) = E_Record_Type_With_Private
4706 and then Chars
(Selector_Name
(N
)) /= Name_uTag
4708 exit when Comp
= Last_Entity
(Type_To_Use
);
4714 -- Ada 2005 (AI-252): The selected component can be interpreted as
4715 -- a prefixed view of a subprogram. Depending on the context, this is
4716 -- either a name that can appear in a renaming declaration, or part
4717 -- of an enclosing call given in prefix form.
4719 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
4720 -- selected component should resolve to a name.
4722 if Ada_Version
>= Ada_2005
4723 and then Is_Tagged_Type
(Prefix_Type
)
4724 and then not Is_Concurrent_Type
(Prefix_Type
)
4726 if Nkind
(Parent
(N
)) = N_Generic_Association
4727 or else Nkind
(Parent
(N
)) = N_Requeue_Statement
4728 or else Nkind
(Parent
(N
)) = N_Subprogram_Renaming_Declaration
4730 if Find_Primitive_Operation
(N
) then
4734 elsif Try_Object_Operation
(N
) then
4738 -- If the transformation fails, it will be necessary to redo the
4739 -- analysis with all errors enabled, to indicate candidate
4740 -- interpretations and reasons for each failure ???
4744 elsif Is_Private_Type
(Prefix_Type
) then
4746 -- Allow access only to discriminants of the type. If the type has
4747 -- no full view, gigi uses the parent type for the components, so we
4748 -- do the same here.
4750 if No
(Full_View
(Prefix_Type
)) then
4751 Type_To_Use
:= Root_Type
(Base_Type
(Prefix_Type
));
4752 Comp
:= First_Entity
(Type_To_Use
);
4755 while Present
(Comp
) loop
4756 if Chars
(Comp
) = Chars
(Sel
) then
4757 if Ekind
(Comp
) = E_Discriminant
then
4758 Set_Entity_With_Checks
(Sel
, Comp
);
4759 Generate_Reference
(Comp
, Sel
);
4761 Set_Etype
(Sel
, Etype
(Comp
));
4762 Set_Etype
(N
, Etype
(Comp
));
4763 Check_Implicit_Dereference
(N
, Etype
(N
));
4765 if Is_Generic_Type
(Prefix_Type
)
4766 or else Is_Generic_Type
(Root_Type
(Prefix_Type
))
4768 Set_Original_Discriminant
(Sel
, Comp
);
4771 -- Before declaring an error, check whether this is tagged
4772 -- private type and a call to a primitive operation.
4774 elsif Ada_Version
>= Ada_2005
4775 and then Is_Tagged_Type
(Prefix_Type
)
4776 and then Try_Object_Operation
(N
)
4781 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4782 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
4783 Set_Entity
(Sel
, Any_Id
);
4784 Set_Etype
(N
, Any_Type
);
4793 elsif Is_Concurrent_Type
(Prefix_Type
) then
4795 -- Find visible operation with given name. For a protected type,
4796 -- the possible candidates are discriminants, entries or protected
4797 -- procedures. For a task type, the set can only include entries or
4798 -- discriminants if the task type is not an enclosing scope. If it
4799 -- is an enclosing scope (e.g. in an inner task) then all entities
4800 -- are visible, but the prefix must denote the enclosing scope, i.e.
4801 -- can only be a direct name or an expanded name.
4803 Set_Etype
(Sel
, Any_Type
);
4804 In_Scope
:= In_Open_Scopes
(Prefix_Type
);
4806 while Present
(Comp
) loop
4807 -- Do not examine private operations of the type if not within
4810 if Chars
(Comp
) = Chars
(Sel
) then
4811 if Is_Overloadable
(Comp
)
4813 or else Comp
/= First_Private_Entity
(Type_To_Use
))
4815 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
4817 -- If the prefix is tagged, the correct interpretation may
4818 -- lie in the primitive or class-wide operations of the
4819 -- type. Perform a simple conformance check to determine
4820 -- whether Try_Object_Operation should be invoked even if
4821 -- a visible entity is found.
4823 if Is_Tagged_Type
(Prefix_Type
)
4825 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
4827 N_Indexed_Component
)
4828 and then Has_Mode_Conformant_Spec
(Comp
)
4830 Has_Candidate
:= True;
4833 -- Note: a selected component may not denote a component of a
4834 -- protected type (4.1.3(7)).
4836 elsif Ekind_In
(Comp
, E_Discriminant
, E_Entry_Family
)
4838 and then not Is_Protected_Type
(Prefix_Type
)
4839 and then Is_Entity_Name
(Name
))
4841 Set_Entity_With_Checks
(Sel
, Comp
);
4842 Generate_Reference
(Comp
, Sel
);
4844 -- The selector is not overloadable, so we have a candidate
4847 Has_Candidate
:= True;
4853 Set_Etype
(Sel
, Etype
(Comp
));
4854 Set_Etype
(N
, Etype
(Comp
));
4856 if Ekind
(Comp
) = E_Discriminant
then
4857 Set_Original_Discriminant
(Sel
, Comp
);
4860 -- For access type case, introduce explicit dereference for
4861 -- more uniform treatment of entry calls.
4863 if Is_Access_Type
(Etype
(Name
)) then
4864 Insert_Explicit_Dereference
(Name
);
4866 (Warn_On_Dereference
, "?d?implicit dereference", N
);
4872 exit when not In_Scope
4874 Comp
= First_Private_Entity
(Base_Type
(Prefix_Type
));
4877 -- If the scope is a current instance, the prefix cannot be an
4878 -- expression of the same type, unless the selector designates a
4879 -- public operation (otherwise that would represent an attempt to
4880 -- reach an internal entity of another synchronized object).
4881 -- This is legal if prefix is an access to such type and there is
4882 -- a dereference, or is a component with a dereferenced prefix.
4883 -- It is also legal if the prefix is a component of a task type,
4884 -- and the selector is one of the task operations.
4887 and then not Is_Entity_Name
(Name
)
4888 and then not Has_Dereference
(Name
)
4890 if Is_Task_Type
(Prefix_Type
)
4891 and then Present
(Entity
(Sel
))
4892 and then Ekind_In
(Entity
(Sel
), E_Entry
, E_Entry_Family
)
4898 ("invalid reference to internal operation of some object of "
4899 & "type &", N
, Type_To_Use
);
4900 Set_Entity
(Sel
, Any_Id
);
4901 Set_Etype
(Sel
, Any_Type
);
4906 -- If there is no visible entity with the given name or none of the
4907 -- visible entities are plausible interpretations, check whether
4908 -- there is some other primitive operation with that name.
4910 if Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Prefix_Type
) then
4911 if (Etype
(N
) = Any_Type
4912 or else not Has_Candidate
)
4913 and then Try_Object_Operation
(N
)
4917 -- If the context is not syntactically a procedure call, it
4918 -- may be a call to a primitive function declared outside of
4919 -- the synchronized type.
4921 -- If the context is a procedure call, there might still be
4922 -- an overloading between an entry and a primitive procedure
4923 -- declared outside of the synchronized type, called in prefix
4924 -- notation. This is harder to disambiguate because in one case
4925 -- the controlling formal is implicit ???
4927 elsif Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
4928 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
4929 and then Try_Object_Operation
(N
)
4934 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
4935 -- entry or procedure of a tagged concurrent type we must check
4936 -- if there are class-wide subprograms covering the primitive. If
4937 -- true then Try_Object_Operation reports the error.
4940 and then Is_Concurrent_Type
(Prefix_Type
)
4941 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
4943 -- Duplicate the call. This is required to avoid problems with
4944 -- the tree transformations performed by Try_Object_Operation.
4945 -- Set properly the parent of the copied call, because it is
4946 -- about to be reanalyzed.
4949 Par
: constant Node_Id
:= New_Copy_Tree
(Parent
(N
));
4952 Set_Parent
(Par
, Parent
(Parent
(N
)));
4954 if Try_Object_Operation
4955 (Sinfo
.Name
(Par
), CW_Test_Only
=> True)
4963 if Etype
(N
) = Any_Type
and then Is_Protected_Type
(Prefix_Type
) then
4965 -- Case of a prefix of a protected type: selector might denote
4966 -- an invisible private component.
4968 Comp
:= First_Private_Entity
(Base_Type
(Prefix_Type
));
4969 while Present
(Comp
) and then Chars
(Comp
) /= Chars
(Sel
) loop
4973 if Present
(Comp
) then
4974 if Is_Single_Concurrent_Object
then
4975 Error_Msg_Node_2
:= Entity
(Name
);
4976 Error_Msg_NE
("invisible selector& for &", N
, Sel
);
4979 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4980 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
4986 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
4991 Error_Msg_NE
("invalid prefix in selected component&", N
, Sel
);
4994 -- If N still has no type, the component is not defined in the prefix
4996 if Etype
(N
) = Any_Type
then
4998 if Is_Single_Concurrent_Object
then
4999 Error_Msg_Node_2
:= Entity
(Name
);
5000 Error_Msg_NE
("no selector& for&", N
, Sel
);
5002 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
5004 -- If this is a derived formal type, the parent may have different
5005 -- visibility at this point. Try for an inherited component before
5006 -- reporting an error.
5008 elsif Is_Generic_Type
(Prefix_Type
)
5009 and then Ekind
(Prefix_Type
) = E_Record_Type_With_Private
5010 and then Prefix_Type
/= Etype
(Prefix_Type
)
5011 and then Is_Record_Type
(Etype
(Prefix_Type
))
5013 Set_Etype
(Prefix
(N
), Etype
(Prefix_Type
));
5014 Analyze_Selected_Component
(N
);
5017 -- Similarly, if this is the actual for a formal derived type, or
5018 -- a derived type thereof, the component inherited from the generic
5019 -- parent may not be visible in the actual, but the selected
5020 -- component is legal. Climb up the derivation chain of the generic
5021 -- parent type until we find the proper ancestor type.
5023 elsif In_Instance
and then Is_Tagged_Type
(Prefix_Type
) then
5025 Par
: Entity_Id
:= Prefix_Type
;
5027 -- Climb up derivation chain to generic actual subtype
5029 while not Is_Generic_Actual_Type
(Par
) loop
5030 if Ekind
(Par
) = E_Record_Type
then
5031 Par
:= Parent_Subtype
(Par
);
5034 exit when Par
= Etype
(Par
);
5039 if Present
(Par
) and then Is_Generic_Actual_Type
(Par
) then
5041 -- Now look for component in ancestor types
5043 Par
:= Generic_Parent_Type
(Declaration_Node
(Par
));
5045 Find_Component_In_Instance
(Par
);
5046 exit when Present
(Entity
(Sel
))
5047 or else Par
= Etype
(Par
);
5051 -- Another special case: the type is an extension of a private
5052 -- type T, is an actual in an instance, and we are in the body
5053 -- of the instance, so the generic body had a full view of the
5054 -- type declaration for T or of some ancestor that defines the
5055 -- component in question.
5057 elsif Is_Derived_Type
(Type_To_Use
)
5058 and then Used_As_Generic_Actual
(Type_To_Use
)
5059 and then In_Instance_Body
5061 Find_Component_In_Instance
(Parent_Subtype
(Type_To_Use
));
5063 -- In ASIS mode the generic parent type may be absent. Examine
5064 -- the parent type directly for a component that may have been
5065 -- visible in a parent generic unit.
5067 elsif Is_Derived_Type
(Prefix_Type
) then
5068 Par
:= Etype
(Prefix_Type
);
5069 Find_Component_In_Instance
(Par
);
5073 -- The search above must have eventually succeeded, since the
5074 -- selected component was legal in the generic.
5076 if No
(Entity
(Sel
)) then
5077 raise Program_Error
;
5082 -- Component not found, specialize error message when appropriate
5085 if Ekind
(Prefix_Type
) = E_Record_Subtype
then
5087 -- Check whether this is a component of the base type which
5088 -- is absent from a statically constrained subtype. This will
5089 -- raise constraint error at run time, but is not a compile-
5090 -- time error. When the selector is illegal for base type as
5091 -- well fall through and generate a compilation error anyway.
5093 Comp
:= First_Component
(Base_Type
(Prefix_Type
));
5094 while Present
(Comp
) loop
5095 if Chars
(Comp
) = Chars
(Sel
)
5096 and then Is_Visible_Component
(Comp
)
5098 Set_Entity_With_Checks
(Sel
, Comp
);
5099 Generate_Reference
(Comp
, Sel
);
5100 Set_Etype
(Sel
, Etype
(Comp
));
5101 Set_Etype
(N
, Etype
(Comp
));
5103 -- Emit appropriate message. The node will be replaced
5104 -- by an appropriate raise statement.
5106 -- Note that in SPARK mode, as with all calls to apply a
5107 -- compile time constraint error, this will be made into
5108 -- an error to simplify the processing of the formal
5109 -- verification backend.
5111 Apply_Compile_Time_Constraint_Error
5112 (N
, "component not present in }??",
5113 CE_Discriminant_Check_Failed
,
5114 Ent
=> Prefix_Type
, Rep
=> False);
5116 Set_Raises_Constraint_Error
(N
);
5120 Next_Component
(Comp
);
5125 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
5126 Error_Msg_NE
("no selector& for}", N
, Sel
);
5128 -- Add information in the case of an incomplete prefix
5130 if Is_Incomplete_Type
(Type_To_Use
) then
5132 Inc
: constant Entity_Id
:= First_Subtype
(Type_To_Use
);
5135 if From_Limited_With
(Scope
(Type_To_Use
)) then
5137 ("\limited view of& has no components", N
, Inc
);
5141 ("\premature usage of incomplete type&", N
, Inc
);
5143 if Nkind
(Parent
(Inc
)) =
5144 N_Incomplete_Type_Declaration
5146 -- Record location of premature use in entity so that
5147 -- a continuation message is generated when the
5148 -- completion is seen.
5150 Set_Premature_Use
(Parent
(Inc
), N
);
5156 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
5159 Set_Entity
(Sel
, Any_Id
);
5160 Set_Etype
(Sel
, Any_Type
);
5162 end Analyze_Selected_Component
;
5164 ---------------------------
5165 -- Analyze_Short_Circuit --
5166 ---------------------------
5168 procedure Analyze_Short_Circuit
(N
: Node_Id
) is
5169 L
: constant Node_Id
:= Left_Opnd
(N
);
5170 R
: constant Node_Id
:= Right_Opnd
(N
);
5175 Analyze_Expression
(L
);
5176 Analyze_Expression
(R
);
5177 Set_Etype
(N
, Any_Type
);
5179 if not Is_Overloaded
(L
) then
5180 if Root_Type
(Etype
(L
)) = Standard_Boolean
5181 and then Has_Compatible_Type
(R
, Etype
(L
))
5183 Add_One_Interp
(N
, Etype
(L
), Etype
(L
));
5187 Get_First_Interp
(L
, Ind
, It
);
5188 while Present
(It
.Typ
) loop
5189 if Root_Type
(It
.Typ
) = Standard_Boolean
5190 and then Has_Compatible_Type
(R
, It
.Typ
)
5192 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
5195 Get_Next_Interp
(Ind
, It
);
5199 -- Here we have failed to find an interpretation. Clearly we know that
5200 -- it is not the case that both operands can have an interpretation of
5201 -- Boolean, but this is by far the most likely intended interpretation.
5202 -- So we simply resolve both operands as Booleans, and at least one of
5203 -- these resolutions will generate an error message, and we do not need
5204 -- to give another error message on the short circuit operation itself.
5206 if Etype
(N
) = Any_Type
then
5207 Resolve
(L
, Standard_Boolean
);
5208 Resolve
(R
, Standard_Boolean
);
5209 Set_Etype
(N
, Standard_Boolean
);
5211 end Analyze_Short_Circuit
;
5217 procedure Analyze_Slice
(N
: Node_Id
) is
5218 D
: constant Node_Id
:= Discrete_Range
(N
);
5219 P
: constant Node_Id
:= Prefix
(N
);
5220 Array_Type
: Entity_Id
;
5221 Index_Type
: Entity_Id
;
5223 procedure Analyze_Overloaded_Slice
;
5224 -- If the prefix is overloaded, select those interpretations that
5225 -- yield a one-dimensional array type.
5227 ------------------------------
5228 -- Analyze_Overloaded_Slice --
5229 ------------------------------
5231 procedure Analyze_Overloaded_Slice
is
5237 Set_Etype
(N
, Any_Type
);
5239 Get_First_Interp
(P
, I
, It
);
5240 while Present
(It
.Nam
) loop
5243 if Is_Access_Type
(Typ
) then
5244 Typ
:= Designated_Type
(Typ
);
5246 (Warn_On_Dereference
, "?d?implicit dereference", N
);
5249 if Is_Array_Type
(Typ
)
5250 and then Number_Dimensions
(Typ
) = 1
5251 and then Has_Compatible_Type
(D
, Etype
(First_Index
(Typ
)))
5253 Add_One_Interp
(N
, Typ
, Typ
);
5256 Get_Next_Interp
(I
, It
);
5259 if Etype
(N
) = Any_Type
then
5260 Error_Msg_N
("expect array type in prefix of slice", N
);
5262 end Analyze_Overloaded_Slice
;
5264 -- Start of processing for Analyze_Slice
5267 if Comes_From_Source
(N
) then
5268 Check_SPARK_05_Restriction
("slice is not allowed", N
);
5274 if Is_Overloaded
(P
) then
5275 Analyze_Overloaded_Slice
;
5278 Array_Type
:= Etype
(P
);
5279 Set_Etype
(N
, Any_Type
);
5281 if Is_Access_Type
(Array_Type
) then
5282 Array_Type
:= Designated_Type
(Array_Type
);
5283 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
5286 if not Is_Array_Type
(Array_Type
) then
5287 Wrong_Type
(P
, Any_Array
);
5289 elsif Number_Dimensions
(Array_Type
) > 1 then
5291 ("type is not one-dimensional array in slice prefix", N
);
5294 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
5295 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
5297 Index_Type
:= Etype
(First_Index
(Array_Type
));
5300 if not Has_Compatible_Type
(D
, Index_Type
) then
5301 Wrong_Type
(D
, Index_Type
);
5303 Set_Etype
(N
, Array_Type
);
5309 -----------------------------
5310 -- Analyze_Type_Conversion --
5311 -----------------------------
5313 procedure Analyze_Type_Conversion
(N
: Node_Id
) is
5314 Expr
: constant Node_Id
:= Expression
(N
);
5318 -- If Conversion_OK is set, then the Etype is already set, and the only
5319 -- processing required is to analyze the expression. This is used to
5320 -- construct certain "illegal" conversions which are not allowed by Ada
5321 -- semantics, but can be handled by Gigi, see Sinfo for further details.
5323 if Conversion_OK
(N
) then
5328 -- Otherwise full type analysis is required, as well as some semantic
5329 -- checks to make sure the argument of the conversion is appropriate.
5331 Find_Type
(Subtype_Mark
(N
));
5332 Typ
:= Entity
(Subtype_Mark
(N
));
5334 Check_Fully_Declared
(Typ
, N
);
5335 Analyze_Expression
(Expr
);
5336 Validate_Remote_Type_Type_Conversion
(N
);
5338 -- Only remaining step is validity checks on the argument. These
5339 -- are skipped if the conversion does not come from the source.
5341 if not Comes_From_Source
(N
) then
5344 -- If there was an error in a generic unit, no need to replicate the
5345 -- error message. Conversely, constant-folding in the generic may
5346 -- transform the argument of a conversion into a string literal, which
5347 -- is legal. Therefore the following tests are not performed in an
5348 -- instance. The same applies to an inlined body.
5350 elsif In_Instance
or In_Inlined_Body
then
5353 elsif Nkind
(Expr
) = N_Null
then
5354 Error_Msg_N
("argument of conversion cannot be null", N
);
5355 Error_Msg_N
("\use qualified expression instead", N
);
5356 Set_Etype
(N
, Any_Type
);
5358 elsif Nkind
(Expr
) = N_Aggregate
then
5359 Error_Msg_N
("argument of conversion cannot be aggregate", N
);
5360 Error_Msg_N
("\use qualified expression instead", N
);
5362 elsif Nkind
(Expr
) = N_Allocator
then
5363 Error_Msg_N
("argument of conversion cannot be an allocator", N
);
5364 Error_Msg_N
("\use qualified expression instead", N
);
5366 elsif Nkind
(Expr
) = N_String_Literal
then
5367 Error_Msg_N
("argument of conversion cannot be string literal", N
);
5368 Error_Msg_N
("\use qualified expression instead", N
);
5370 elsif Nkind
(Expr
) = N_Character_Literal
then
5371 if Ada_Version
= Ada_83
then
5372 Resolve
(Expr
, Typ
);
5374 Error_Msg_N
("argument of conversion cannot be character literal",
5376 Error_Msg_N
("\use qualified expression instead", N
);
5379 elsif Nkind
(Expr
) = N_Attribute_Reference
5380 and then Nam_In
(Attribute_Name
(Expr
), Name_Access
,
5381 Name_Unchecked_Access
,
5382 Name_Unrestricted_Access
)
5384 Error_Msg_N
("argument of conversion cannot be access", N
);
5385 Error_Msg_N
("\use qualified expression instead", N
);
5388 -- A formal parameter of a specific tagged type whose related subprogram
5389 -- is subject to pragma Extensions_Visible with value "False" cannot
5390 -- appear in a class-wide conversion (SPARK RM 6.1.7(3)). Do not check
5391 -- internally generated expressions.
5393 if Is_Class_Wide_Type
(Typ
)
5394 and then Comes_From_Source
(Expr
)
5395 and then Is_EVF_Expression
(Expr
)
5398 ("formal parameter cannot be converted to class-wide type when "
5399 & "Extensions_Visible is False", Expr
);
5401 end Analyze_Type_Conversion
;
5403 ----------------------
5404 -- Analyze_Unary_Op --
5405 ----------------------
5407 procedure Analyze_Unary_Op
(N
: Node_Id
) is
5408 R
: constant Node_Id
:= Right_Opnd
(N
);
5409 Op_Id
: Entity_Id
:= Entity
(N
);
5412 Set_Etype
(N
, Any_Type
);
5413 Candidate_Type
:= Empty
;
5415 Analyze_Expression
(R
);
5417 if Present
(Op_Id
) then
5418 if Ekind
(Op_Id
) = E_Operator
then
5419 Find_Unary_Types
(R
, Op_Id
, N
);
5421 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5425 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
5426 while Present
(Op_Id
) loop
5427 if Ekind
(Op_Id
) = E_Operator
then
5428 if No
(Next_Entity
(First_Entity
(Op_Id
))) then
5429 Find_Unary_Types
(R
, Op_Id
, N
);
5432 elsif Is_Overloadable
(Op_Id
) then
5433 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
5436 Op_Id
:= Homonym
(Op_Id
);
5441 end Analyze_Unary_Op
;
5443 ----------------------------------
5444 -- Analyze_Unchecked_Expression --
5445 ----------------------------------
5447 procedure Analyze_Unchecked_Expression
(N
: Node_Id
) is
5449 Analyze
(Expression
(N
), Suppress
=> All_Checks
);
5450 Set_Etype
(N
, Etype
(Expression
(N
)));
5451 Save_Interps
(Expression
(N
), N
);
5452 end Analyze_Unchecked_Expression
;
5454 ---------------------------------------
5455 -- Analyze_Unchecked_Type_Conversion --
5456 ---------------------------------------
5458 procedure Analyze_Unchecked_Type_Conversion
(N
: Node_Id
) is
5460 Find_Type
(Subtype_Mark
(N
));
5461 Analyze_Expression
(Expression
(N
));
5462 Set_Etype
(N
, Entity
(Subtype_Mark
(N
)));
5463 end Analyze_Unchecked_Type_Conversion
;
5465 ------------------------------------
5466 -- Analyze_User_Defined_Binary_Op --
5467 ------------------------------------
5469 procedure Analyze_User_Defined_Binary_Op
5474 -- Only do analysis if the operator Comes_From_Source, since otherwise
5475 -- the operator was generated by the expander, and all such operators
5476 -- always refer to the operators in package Standard.
5478 if Comes_From_Source
(N
) then
5480 F1
: constant Entity_Id
:= First_Formal
(Op_Id
);
5481 F2
: constant Entity_Id
:= Next_Formal
(F1
);
5484 -- Verify that Op_Id is a visible binary function. Note that since
5485 -- we know Op_Id is overloaded, potentially use visible means use
5486 -- visible for sure (RM 9.4(11)).
5488 if Ekind
(Op_Id
) = E_Function
5489 and then Present
(F2
)
5490 and then (Is_Immediately_Visible
(Op_Id
)
5491 or else Is_Potentially_Use_Visible
(Op_Id
))
5492 and then Has_Compatible_Type
(Left_Opnd
(N
), Etype
(F1
))
5493 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F2
))
5495 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5497 -- If the left operand is overloaded, indicate that the current
5498 -- type is a viable candidate. This is redundant in most cases,
5499 -- but for equality and comparison operators where the context
5500 -- does not impose a type on the operands, setting the proper
5501 -- type is necessary to avoid subsequent ambiguities during
5502 -- resolution, when both user-defined and predefined operators
5503 -- may be candidates.
5505 if Is_Overloaded
(Left_Opnd
(N
)) then
5506 Set_Etype
(Left_Opnd
(N
), Etype
(F1
));
5509 if Debug_Flag_E
then
5510 Write_Str
("user defined operator ");
5511 Write_Name
(Chars
(Op_Id
));
5512 Write_Str
(" on node ");
5513 Write_Int
(Int
(N
));
5519 end Analyze_User_Defined_Binary_Op
;
5521 -----------------------------------
5522 -- Analyze_User_Defined_Unary_Op --
5523 -----------------------------------
5525 procedure Analyze_User_Defined_Unary_Op
5530 -- Only do analysis if the operator Comes_From_Source, since otherwise
5531 -- the operator was generated by the expander, and all such operators
5532 -- always refer to the operators in package Standard.
5534 if Comes_From_Source
(N
) then
5536 F
: constant Entity_Id
:= First_Formal
(Op_Id
);
5539 -- Verify that Op_Id is a visible unary function. Note that since
5540 -- we know Op_Id is overloaded, potentially use visible means use
5541 -- visible for sure (RM 9.4(11)).
5543 if Ekind
(Op_Id
) = E_Function
5544 and then No
(Next_Formal
(F
))
5545 and then (Is_Immediately_Visible
(Op_Id
)
5546 or else Is_Potentially_Use_Visible
(Op_Id
))
5547 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F
))
5549 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5553 end Analyze_User_Defined_Unary_Op
;
5555 ---------------------------
5556 -- Check_Arithmetic_Pair --
5557 ---------------------------
5559 procedure Check_Arithmetic_Pair
5560 (T1
, T2
: Entity_Id
;
5564 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
5566 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean;
5567 -- Check whether the fixed-point type Typ has a user-defined operator
5568 -- (multiplication or division) that should hide the corresponding
5569 -- predefined operator. Used to implement Ada 2005 AI-264, to make
5570 -- such operators more visible and therefore useful.
5572 -- If the name of the operation is an expanded name with prefix
5573 -- Standard, the predefined universal fixed operator is available,
5574 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
5576 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
;
5577 -- Get specific type (i.e. non-universal type if there is one)
5583 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean is
5584 Bas
: constant Entity_Id
:= Base_Type
(Typ
);
5590 -- If the universal_fixed operation is given explicitly the rule
5591 -- concerning primitive operations of the type do not apply.
5593 if Nkind
(N
) = N_Function_Call
5594 and then Nkind
(Name
(N
)) = N_Expanded_Name
5595 and then Entity
(Prefix
(Name
(N
))) = Standard_Standard
5600 -- The operation is treated as primitive if it is declared in the
5601 -- same scope as the type, and therefore on the same entity chain.
5603 Ent
:= Next_Entity
(Typ
);
5604 while Present
(Ent
) loop
5605 if Chars
(Ent
) = Chars
(Op
) then
5606 F1
:= First_Formal
(Ent
);
5607 F2
:= Next_Formal
(F1
);
5609 -- The operation counts as primitive if either operand or
5610 -- result are of the given base type, and both operands are
5611 -- fixed point types.
5613 if (Base_Type
(Etype
(F1
)) = Bas
5614 and then Is_Fixed_Point_Type
(Etype
(F2
)))
5617 (Base_Type
(Etype
(F2
)) = Bas
5618 and then Is_Fixed_Point_Type
(Etype
(F1
)))
5621 (Base_Type
(Etype
(Ent
)) = Bas
5622 and then Is_Fixed_Point_Type
(Etype
(F1
))
5623 and then Is_Fixed_Point_Type
(Etype
(F2
)))
5639 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
is
5641 if T1
= Universal_Integer
or else T1
= Universal_Real
then
5642 return Base_Type
(T2
);
5644 return Base_Type
(T1
);
5648 -- Start of processing for Check_Arithmetic_Pair
5651 if Nam_In
(Op_Name
, Name_Op_Add
, Name_Op_Subtract
) then
5652 if Is_Numeric_Type
(T1
)
5653 and then Is_Numeric_Type
(T2
)
5654 and then (Covers
(T1
=> T1
, T2
=> T2
)
5656 Covers
(T1
=> T2
, T2
=> T1
))
5658 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5661 elsif Nam_In
(Op_Name
, Name_Op_Multiply
, Name_Op_Divide
) then
5662 if Is_Fixed_Point_Type
(T1
)
5663 and then (Is_Fixed_Point_Type
(T2
) or else T2
= Universal_Real
)
5665 -- If Treat_Fixed_As_Integer is set then the Etype is already set
5666 -- and no further processing is required (this is the case of an
5667 -- operator constructed by Exp_Fixd for a fixed point operation)
5668 -- Otherwise add one interpretation with universal fixed result
5669 -- If the operator is given in functional notation, it comes
5670 -- from source and Fixed_As_Integer cannot apply.
5672 if (Nkind
(N
) not in N_Op
5673 or else not Treat_Fixed_As_Integer
(N
))
5675 (not Has_Fixed_Op
(T1
, Op_Id
)
5676 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
5678 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
5681 elsif Is_Fixed_Point_Type
(T2
)
5682 and then (Nkind
(N
) not in N_Op
5683 or else not Treat_Fixed_As_Integer
(N
))
5684 and then T1
= Universal_Real
5686 (not Has_Fixed_Op
(T1
, Op_Id
)
5687 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
5689 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
5691 elsif Is_Numeric_Type
(T1
)
5692 and then Is_Numeric_Type
(T2
)
5693 and then (Covers
(T1
=> T1
, T2
=> T2
)
5695 Covers
(T1
=> T2
, T2
=> T1
))
5697 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5699 elsif Is_Fixed_Point_Type
(T1
)
5700 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5701 or else T2
= Universal_Integer
)
5703 Add_One_Interp
(N
, Op_Id
, T1
);
5705 elsif T2
= Universal_Real
5706 and then Base_Type
(T1
) = Base_Type
(Standard_Integer
)
5707 and then Op_Name
= Name_Op_Multiply
5709 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
5711 elsif T1
= Universal_Real
5712 and then Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5714 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
5716 elsif Is_Fixed_Point_Type
(T2
)
5717 and then (Base_Type
(T1
) = Base_Type
(Standard_Integer
)
5718 or else T1
= Universal_Integer
)
5719 and then Op_Name
= Name_Op_Multiply
5721 Add_One_Interp
(N
, Op_Id
, T2
);
5723 elsif T1
= Universal_Real
and then T2
= Universal_Integer
then
5724 Add_One_Interp
(N
, Op_Id
, T1
);
5726 elsif T2
= Universal_Real
5727 and then T1
= Universal_Integer
5728 and then Op_Name
= Name_Op_Multiply
5730 Add_One_Interp
(N
, Op_Id
, T2
);
5733 elsif Op_Name
= Name_Op_Mod
or else Op_Name
= Name_Op_Rem
then
5735 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
5736 -- set does not require any special processing, since the Etype is
5737 -- already set (case of operation constructed by Exp_Fixed).
5739 if Is_Integer_Type
(T1
)
5740 and then (Covers
(T1
=> T1
, T2
=> T2
)
5742 Covers
(T1
=> T2
, T2
=> T1
))
5744 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5747 elsif Op_Name
= Name_Op_Expon
then
5748 if Is_Numeric_Type
(T1
)
5749 and then not Is_Fixed_Point_Type
(T1
)
5750 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5751 or else T2
= Universal_Integer
)
5753 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
5756 else pragma Assert
(Nkind
(N
) in N_Op_Shift
);
5758 -- If not one of the predefined operators, the node may be one
5759 -- of the intrinsic functions. Its kind is always specific, and
5760 -- we can use it directly, rather than the name of the operation.
5762 if Is_Integer_Type
(T1
)
5763 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5764 or else T2
= Universal_Integer
)
5766 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
5769 end Check_Arithmetic_Pair
;
5771 -------------------------------
5772 -- Check_Misspelled_Selector --
5773 -------------------------------
5775 procedure Check_Misspelled_Selector
5776 (Prefix
: Entity_Id
;
5779 Max_Suggestions
: constant := 2;
5780 Nr_Of_Suggestions
: Natural := 0;
5782 Suggestion_1
: Entity_Id
:= Empty
;
5783 Suggestion_2
: Entity_Id
:= Empty
;
5788 -- All the components of the prefix of selector Sel are matched against
5789 -- Sel and a count is maintained of possible misspellings. When at
5790 -- the end of the analysis there are one or two (not more) possible
5791 -- misspellings, these misspellings will be suggested as possible
5794 if not (Is_Private_Type
(Prefix
) or else Is_Record_Type
(Prefix
)) then
5796 -- Concurrent types should be handled as well ???
5801 Comp
:= First_Entity
(Prefix
);
5802 while Nr_Of_Suggestions
<= Max_Suggestions
and then Present
(Comp
) loop
5803 if Is_Visible_Component
(Comp
) then
5804 if Is_Bad_Spelling_Of
(Chars
(Comp
), Chars
(Sel
)) then
5805 Nr_Of_Suggestions
:= Nr_Of_Suggestions
+ 1;
5807 case Nr_Of_Suggestions
is
5808 when 1 => Suggestion_1
:= Comp
;
5809 when 2 => Suggestion_2
:= Comp
;
5810 when others => null;
5815 Comp
:= Next_Entity
(Comp
);
5818 -- Report at most two suggestions
5820 if Nr_Of_Suggestions
= 1 then
5821 Error_Msg_NE
-- CODEFIX
5822 ("\possible misspelling of&", Sel
, Suggestion_1
);
5824 elsif Nr_Of_Suggestions
= 2 then
5825 Error_Msg_Node_2
:= Suggestion_2
;
5826 Error_Msg_NE
-- CODEFIX
5827 ("\possible misspelling of& or&", Sel
, Suggestion_1
);
5829 end Check_Misspelled_Selector
;
5831 ----------------------
5832 -- Defined_In_Scope --
5833 ----------------------
5835 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean
5837 S1
: constant Entity_Id
:= Scope
(Base_Type
(T
));
5840 or else (S1
= System_Aux_Id
and then S
= Scope
(S1
));
5841 end Defined_In_Scope
;
5847 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
) is
5853 Void_Interp_Seen
: Boolean := False;
5856 pragma Warnings
(Off
, Boolean);
5859 if Ada_Version
>= Ada_2005
then
5860 Actual
:= First_Actual
(N
);
5861 while Present
(Actual
) loop
5863 -- Ada 2005 (AI-50217): Post an error in case of premature
5864 -- usage of an entity from the limited view.
5866 if not Analyzed
(Etype
(Actual
))
5867 and then From_Limited_With
(Etype
(Actual
))
5869 Error_Msg_Qual_Level
:= 1;
5871 ("missing with_clause for scope of imported type&",
5872 Actual
, Etype
(Actual
));
5873 Error_Msg_Qual_Level
:= 0;
5876 Next_Actual
(Actual
);
5880 -- Analyze each candidate call again, with full error reporting
5884 ("no candidate interpretations match the actuals:!", Nam
);
5885 Err_Mode
:= All_Errors_Mode
;
5886 All_Errors_Mode
:= True;
5888 -- If this is a call to an operation of a concurrent type,
5889 -- the failed interpretations have been removed from the
5890 -- name. Recover them to provide full diagnostics.
5892 if Nkind
(Parent
(Nam
)) = N_Selected_Component
then
5893 Set_Entity
(Nam
, Empty
);
5894 New_Nam
:= New_Copy_Tree
(Parent
(Nam
));
5895 Set_Is_Overloaded
(New_Nam
, False);
5896 Set_Is_Overloaded
(Selector_Name
(New_Nam
), False);
5897 Set_Parent
(New_Nam
, Parent
(Parent
(Nam
)));
5898 Analyze_Selected_Component
(New_Nam
);
5899 Get_First_Interp
(Selector_Name
(New_Nam
), X
, It
);
5901 Get_First_Interp
(Nam
, X
, It
);
5904 while Present
(It
.Nam
) loop
5905 if Etype
(It
.Nam
) = Standard_Void_Type
then
5906 Void_Interp_Seen
:= True;
5909 Analyze_One_Call
(N
, It
.Nam
, True, Success
);
5910 Get_Next_Interp
(X
, It
);
5913 if Nkind
(N
) = N_Function_Call
then
5914 Get_First_Interp
(Nam
, X
, It
);
5915 while Present
(It
.Nam
) loop
5916 if Ekind_In
(It
.Nam
, E_Function
, E_Operator
) then
5919 Get_Next_Interp
(X
, It
);
5923 -- If all interpretations are procedures, this deserves a
5924 -- more precise message. Ditto if this appears as the prefix
5925 -- of a selected component, which may be a lexical error.
5928 ("\context requires function call, found procedure name", Nam
);
5930 if Nkind
(Parent
(N
)) = N_Selected_Component
5931 and then N
= Prefix
(Parent
(N
))
5933 Error_Msg_N
-- CODEFIX
5934 ("\period should probably be semicolon", Parent
(N
));
5937 elsif Nkind
(N
) = N_Procedure_Call_Statement
5938 and then not Void_Interp_Seen
5941 "\function name found in procedure call", Nam
);
5944 All_Errors_Mode
:= Err_Mode
;
5947 ---------------------------
5948 -- Find_Arithmetic_Types --
5949 ---------------------------
5951 procedure Find_Arithmetic_Types
5956 Index1
: Interp_Index
;
5957 Index2
: Interp_Index
;
5961 procedure Check_Right_Argument
(T
: Entity_Id
);
5962 -- Check right operand of operator
5964 --------------------------
5965 -- Check_Right_Argument --
5966 --------------------------
5968 procedure Check_Right_Argument
(T
: Entity_Id
) is
5970 if not Is_Overloaded
(R
) then
5971 Check_Arithmetic_Pair
(T
, Etype
(R
), Op_Id
, N
);
5973 Get_First_Interp
(R
, Index2
, It2
);
5974 while Present
(It2
.Typ
) loop
5975 Check_Arithmetic_Pair
(T
, It2
.Typ
, Op_Id
, N
);
5976 Get_Next_Interp
(Index2
, It2
);
5979 end Check_Right_Argument
;
5981 -- Start of processing for Find_Arithmetic_Types
5984 if not Is_Overloaded
(L
) then
5985 Check_Right_Argument
(Etype
(L
));
5988 Get_First_Interp
(L
, Index1
, It1
);
5989 while Present
(It1
.Typ
) loop
5990 Check_Right_Argument
(It1
.Typ
);
5991 Get_Next_Interp
(Index1
, It1
);
5995 end Find_Arithmetic_Types
;
5997 ------------------------
5998 -- Find_Boolean_Types --
5999 ------------------------
6001 procedure Find_Boolean_Types
6006 Index
: Interp_Index
;
6009 procedure Check_Numeric_Argument
(T
: Entity_Id
);
6010 -- Special case for logical operations one of whose operands is an
6011 -- integer literal. If both are literal the result is any modular type.
6013 ----------------------------
6014 -- Check_Numeric_Argument --
6015 ----------------------------
6017 procedure Check_Numeric_Argument
(T
: Entity_Id
) is
6019 if T
= Universal_Integer
then
6020 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
6022 elsif Is_Modular_Integer_Type
(T
) then
6023 Add_One_Interp
(N
, Op_Id
, T
);
6025 end Check_Numeric_Argument
;
6027 -- Start of processing for Find_Boolean_Types
6030 if not Is_Overloaded
(L
) then
6031 if Etype
(L
) = Universal_Integer
6032 or else Etype
(L
) = Any_Modular
6034 if not Is_Overloaded
(R
) then
6035 Check_Numeric_Argument
(Etype
(R
));
6038 Get_First_Interp
(R
, Index
, It
);
6039 while Present
(It
.Typ
) loop
6040 Check_Numeric_Argument
(It
.Typ
);
6041 Get_Next_Interp
(Index
, It
);
6045 -- If operands are aggregates, we must assume that they may be
6046 -- boolean arrays, and leave disambiguation for the second pass.
6047 -- If only one is an aggregate, verify that the other one has an
6048 -- interpretation as a boolean array
6050 elsif Nkind
(L
) = N_Aggregate
then
6051 if Nkind
(R
) = N_Aggregate
then
6052 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
6054 elsif not Is_Overloaded
(R
) then
6055 if Valid_Boolean_Arg
(Etype
(R
)) then
6056 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
6060 Get_First_Interp
(R
, Index
, It
);
6061 while Present
(It
.Typ
) loop
6062 if Valid_Boolean_Arg
(It
.Typ
) then
6063 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
6066 Get_Next_Interp
(Index
, It
);
6070 elsif Valid_Boolean_Arg
(Etype
(L
))
6071 and then Has_Compatible_Type
(R
, Etype
(L
))
6073 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
6077 Get_First_Interp
(L
, Index
, It
);
6078 while Present
(It
.Typ
) loop
6079 if Valid_Boolean_Arg
(It
.Typ
)
6080 and then Has_Compatible_Type
(R
, It
.Typ
)
6082 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
6085 Get_Next_Interp
(Index
, It
);
6088 end Find_Boolean_Types
;
6090 ---------------------------
6091 -- Find_Comparison_Types --
6092 ---------------------------
6094 procedure Find_Comparison_Types
6099 Index
: Interp_Index
;
6101 Found
: Boolean := False;
6104 Scop
: Entity_Id
:= Empty
;
6106 procedure Try_One_Interp
(T1
: Entity_Id
);
6107 -- Routine to try one proposed interpretation. Note that the context
6108 -- of the operator plays no role in resolving the arguments, so that
6109 -- if there is more than one interpretation of the operands that is
6110 -- compatible with comparison, the operation is ambiguous.
6112 --------------------
6113 -- Try_One_Interp --
6114 --------------------
6116 procedure Try_One_Interp
(T1
: Entity_Id
) is
6119 -- If the operator is an expanded name, then the type of the operand
6120 -- must be defined in the corresponding scope. If the type is
6121 -- universal, the context will impose the correct type.
6124 and then not Defined_In_Scope
(T1
, Scop
)
6125 and then T1
/= Universal_Integer
6126 and then T1
/= Universal_Real
6127 and then T1
/= Any_String
6128 and then T1
/= Any_Composite
6133 if Valid_Comparison_Arg
(T1
) and then Has_Compatible_Type
(R
, T1
) then
6134 if Found
and then Base_Type
(T1
) /= Base_Type
(T_F
) then
6135 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
6137 if It
= No_Interp
then
6138 Ambiguous_Operands
(N
);
6139 Set_Etype
(L
, Any_Type
);
6153 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
6158 -- Start of processing for Find_Comparison_Types
6161 -- If left operand is aggregate, the right operand has to
6162 -- provide a usable type for it.
6164 if Nkind
(L
) = N_Aggregate
and then Nkind
(R
) /= N_Aggregate
then
6165 Find_Comparison_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
6169 if Nkind
(N
) = N_Function_Call
6170 and then Nkind
(Name
(N
)) = N_Expanded_Name
6172 Scop
:= Entity
(Prefix
(Name
(N
)));
6174 -- The prefix may be a package renaming, and the subsequent test
6175 -- requires the original package.
6177 if Ekind
(Scop
) = E_Package
6178 and then Present
(Renamed_Entity
(Scop
))
6180 Scop
:= Renamed_Entity
(Scop
);
6181 Set_Entity
(Prefix
(Name
(N
)), Scop
);
6185 if not Is_Overloaded
(L
) then
6186 Try_One_Interp
(Etype
(L
));
6189 Get_First_Interp
(L
, Index
, It
);
6190 while Present
(It
.Typ
) loop
6191 Try_One_Interp
(It
.Typ
);
6192 Get_Next_Interp
(Index
, It
);
6195 end Find_Comparison_Types
;
6197 ----------------------------------------
6198 -- Find_Non_Universal_Interpretations --
6199 ----------------------------------------
6201 procedure Find_Non_Universal_Interpretations
6207 Index
: Interp_Index
;
6211 if T1
= Universal_Integer
or else T1
= Universal_Real
6213 -- If the left operand of an equality operator is null, the visibility
6214 -- of the operator must be determined from the interpretation of the
6215 -- right operand. This processing must be done for Any_Access, which
6216 -- is the internal representation of the type of the literal null.
6218 or else T1
= Any_Access
6220 if not Is_Overloaded
(R
) then
6221 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(Etype
(R
)));
6223 Get_First_Interp
(R
, Index
, It
);
6224 while Present
(It
.Typ
) loop
6225 if Covers
(It
.Typ
, T1
) then
6227 (N
, Op_Id
, Standard_Boolean
, Base_Type
(It
.Typ
));
6230 Get_Next_Interp
(Index
, It
);
6234 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(T1
));
6236 end Find_Non_Universal_Interpretations
;
6238 ------------------------------
6239 -- Find_Concatenation_Types --
6240 ------------------------------
6242 procedure Find_Concatenation_Types
6247 Op_Type
: constant Entity_Id
:= Etype
(Op_Id
);
6250 if Is_Array_Type
(Op_Type
)
6251 and then not Is_Limited_Type
(Op_Type
)
6253 and then (Has_Compatible_Type
(L
, Op_Type
)
6255 Has_Compatible_Type
(L
, Component_Type
(Op_Type
)))
6257 and then (Has_Compatible_Type
(R
, Op_Type
)
6259 Has_Compatible_Type
(R
, Component_Type
(Op_Type
)))
6261 Add_One_Interp
(N
, Op_Id
, Op_Type
);
6263 end Find_Concatenation_Types
;
6265 -------------------------
6266 -- Find_Equality_Types --
6267 -------------------------
6269 procedure Find_Equality_Types
6274 Index
: Interp_Index
;
6276 Found
: Boolean := False;
6279 Scop
: Entity_Id
:= Empty
;
6281 procedure Try_One_Interp
(T1
: Entity_Id
);
6282 -- The context of the equality operator plays no role in resolving the
6283 -- arguments, so that if there is more than one interpretation of the
6284 -- operands that is compatible with equality, the construct is ambiguous
6285 -- and an error can be emitted now, after trying to disambiguate, i.e.
6286 -- applying preference rules.
6288 --------------------
6289 -- Try_One_Interp --
6290 --------------------
6292 procedure Try_One_Interp
(T1
: Entity_Id
) is
6293 Bas
: constant Entity_Id
:= Base_Type
(T1
);
6296 -- If the operator is an expanded name, then the type of the operand
6297 -- must be defined in the corresponding scope. If the type is
6298 -- universal, the context will impose the correct type. An anonymous
6299 -- type for a 'Access reference is also universal in this sense, as
6300 -- the actual type is obtained from context.
6302 -- In Ada 2005, the equality operator for anonymous access types
6303 -- is declared in Standard, and preference rules apply to it.
6305 if Present
(Scop
) then
6306 if Defined_In_Scope
(T1
, Scop
)
6307 or else T1
= Universal_Integer
6308 or else T1
= Universal_Real
6309 or else T1
= Any_Access
6310 or else T1
= Any_String
6311 or else T1
= Any_Composite
6312 or else (Ekind
(T1
) = E_Access_Subprogram_Type
6313 and then not Comes_From_Source
(T1
))
6317 elsif Ekind
(T1
) = E_Anonymous_Access_Type
6318 and then Scop
= Standard_Standard
6323 -- The scope does not contain an operator for the type
6328 -- If we have infix notation, the operator must be usable. Within
6329 -- an instance, if the type is already established we know it is
6330 -- correct. If an operand is universal it is compatible with any
6333 elsif In_Open_Scopes
(Scope
(Bas
))
6334 or else Is_Potentially_Use_Visible
(Bas
)
6335 or else In_Use
(Bas
)
6336 or else (In_Use
(Scope
(Bas
)) and then not Is_Hidden
(Bas
))
6338 -- In an instance, the type may have been immediately visible.
6339 -- Either the types are compatible, or one operand is universal
6340 -- (numeric or null).
6342 or else (In_Instance
6344 (First_Subtype
(T1
) = First_Subtype
(Etype
(R
))
6345 or else Nkind
(R
) = N_Null
6347 (Is_Numeric_Type
(T1
)
6348 and then Is_Universal_Numeric_Type
(Etype
(R
)))))
6350 -- In Ada 2005, the equality on anonymous access types is declared
6351 -- in Standard, and is always visible.
6353 or else Ekind
(T1
) = E_Anonymous_Access_Type
6358 -- Save candidate type for subsequent error message, if any
6360 if not Is_Limited_Type
(T1
) then
6361 Candidate_Type
:= T1
;
6367 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
6368 -- Do not allow anonymous access types in equality operators.
6370 if Ada_Version
< Ada_2005
6371 and then Ekind
(T1
) = E_Anonymous_Access_Type
6376 -- If the right operand has a type compatible with T1, check for an
6377 -- acceptable interpretation, unless T1 is limited (no predefined
6378 -- equality available), or this is use of a "/=" for a tagged type.
6379 -- In the latter case, possible interpretations of equality need
6380 -- to be considered, we don't want the default inequality declared
6381 -- in Standard to be chosen, and the "/=" will be rewritten as a
6382 -- negation of "=" (see the end of Analyze_Equality_Op). This ensures
6383 -- that rewriting happens during analysis rather than being
6384 -- delayed until expansion (this is needed for ASIS, which only sees
6385 -- the unexpanded tree). Note that if the node is N_Op_Ne, but Op_Id
6386 -- is Name_Op_Eq then we still proceed with the interpretation,
6387 -- because that indicates the potential rewriting case where the
6388 -- interpretation to consider is actually "=" and the node may be
6389 -- about to be rewritten by Analyze_Equality_Op.
6391 if T1
/= Standard_Void_Type
6392 and then Has_Compatible_Type
(R
, T1
)
6395 ((not Is_Limited_Type
(T1
)
6396 and then not Is_Limited_Composite
(T1
))
6400 and then not Is_Limited_Type
(Component_Type
(T1
))
6401 and then Available_Full_View_Of_Component
(T1
)))
6404 (Nkind
(N
) /= N_Op_Ne
6405 or else not Is_Tagged_Type
(T1
)
6406 or else Chars
(Op_Id
) = Name_Op_Eq
)
6409 and then Base_Type
(T1
) /= Base_Type
(T_F
)
6411 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
6413 if It
= No_Interp
then
6414 Ambiguous_Operands
(N
);
6415 Set_Etype
(L
, Any_Type
);
6428 if not Analyzed
(L
) then
6432 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
6434 -- Case of operator was not visible, Etype still set to Any_Type
6436 if Etype
(N
) = Any_Type
then
6440 elsif Scop
= Standard_Standard
6441 and then Ekind
(T1
) = E_Anonymous_Access_Type
6447 -- Start of processing for Find_Equality_Types
6450 -- If left operand is aggregate, the right operand has to
6451 -- provide a usable type for it.
6453 if Nkind
(L
) = N_Aggregate
6454 and then Nkind
(R
) /= N_Aggregate
6456 Find_Equality_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
6460 if Nkind
(N
) = N_Function_Call
6461 and then Nkind
(Name
(N
)) = N_Expanded_Name
6463 Scop
:= Entity
(Prefix
(Name
(N
)));
6465 -- The prefix may be a package renaming, and the subsequent test
6466 -- requires the original package.
6468 if Ekind
(Scop
) = E_Package
6469 and then Present
(Renamed_Entity
(Scop
))
6471 Scop
:= Renamed_Entity
(Scop
);
6472 Set_Entity
(Prefix
(Name
(N
)), Scop
);
6476 if not Is_Overloaded
(L
) then
6477 Try_One_Interp
(Etype
(L
));
6480 Get_First_Interp
(L
, Index
, It
);
6481 while Present
(It
.Typ
) loop
6482 Try_One_Interp
(It
.Typ
);
6483 Get_Next_Interp
(Index
, It
);
6486 end Find_Equality_Types
;
6488 -------------------------
6489 -- Find_Negation_Types --
6490 -------------------------
6492 procedure Find_Negation_Types
6497 Index
: Interp_Index
;
6501 if not Is_Overloaded
(R
) then
6502 if Etype
(R
) = Universal_Integer
then
6503 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
6504 elsif Valid_Boolean_Arg
(Etype
(R
)) then
6505 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
6509 Get_First_Interp
(R
, Index
, It
);
6510 while Present
(It
.Typ
) loop
6511 if Valid_Boolean_Arg
(It
.Typ
) then
6512 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
6515 Get_Next_Interp
(Index
, It
);
6518 end Find_Negation_Types
;
6520 ------------------------------
6521 -- Find_Primitive_Operation --
6522 ------------------------------
6524 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean is
6525 Obj
: constant Node_Id
:= Prefix
(N
);
6526 Op
: constant Node_Id
:= Selector_Name
(N
);
6533 Set_Etype
(Op
, Any_Type
);
6535 if Is_Access_Type
(Etype
(Obj
)) then
6536 Typ
:= Designated_Type
(Etype
(Obj
));
6541 if Is_Class_Wide_Type
(Typ
) then
6542 Typ
:= Root_Type
(Typ
);
6545 Prims
:= Primitive_Operations
(Typ
);
6547 Prim
:= First_Elmt
(Prims
);
6548 while Present
(Prim
) loop
6549 if Chars
(Node
(Prim
)) = Chars
(Op
) then
6550 Add_One_Interp
(Op
, Node
(Prim
), Etype
(Node
(Prim
)));
6551 Set_Etype
(N
, Etype
(Node
(Prim
)));
6557 -- Now look for class-wide operations of the type or any of its
6558 -- ancestors by iterating over the homonyms of the selector.
6561 Cls_Type
: constant Entity_Id
:= Class_Wide_Type
(Typ
);
6565 Hom
:= Current_Entity
(Op
);
6566 while Present
(Hom
) loop
6567 if (Ekind
(Hom
) = E_Procedure
6569 Ekind
(Hom
) = E_Function
)
6570 and then Scope
(Hom
) = Scope
(Typ
)
6571 and then Present
(First_Formal
(Hom
))
6573 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
6575 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
6577 Ekind
(Etype
(First_Formal
(Hom
))) =
6578 E_Anonymous_Access_Type
6581 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
6584 Add_One_Interp
(Op
, Hom
, Etype
(Hom
));
6585 Set_Etype
(N
, Etype
(Hom
));
6588 Hom
:= Homonym
(Hom
);
6592 return Etype
(Op
) /= Any_Type
;
6593 end Find_Primitive_Operation
;
6595 ----------------------
6596 -- Find_Unary_Types --
6597 ----------------------
6599 procedure Find_Unary_Types
6604 Index
: Interp_Index
;
6608 if not Is_Overloaded
(R
) then
6609 if Is_Numeric_Type
(Etype
(R
)) then
6611 -- In an instance a generic actual may be a numeric type even if
6612 -- the formal in the generic unit was not. In that case, the
6613 -- predefined operator was not a possible interpretation in the
6614 -- generic, and cannot be one in the instance, unless the operator
6615 -- is an actual of an instance.
6619 not Is_Numeric_Type
(Corresponding_Generic_Type
(Etype
(R
)))
6623 Add_One_Interp
(N
, Op_Id
, Base_Type
(Etype
(R
)));
6628 Get_First_Interp
(R
, Index
, It
);
6629 while Present
(It
.Typ
) loop
6630 if Is_Numeric_Type
(It
.Typ
) then
6634 (Corresponding_Generic_Type
(Etype
(It
.Typ
)))
6639 Add_One_Interp
(N
, Op_Id
, Base_Type
(It
.Typ
));
6643 Get_Next_Interp
(Index
, It
);
6646 end Find_Unary_Types
;
6652 function Junk_Operand
(N
: Node_Id
) return Boolean is
6656 if Error_Posted
(N
) then
6660 -- Get entity to be tested
6662 if Is_Entity_Name
(N
)
6663 and then Present
(Entity
(N
))
6667 -- An odd case, a procedure name gets converted to a very peculiar
6668 -- function call, and here is where we detect this happening.
6670 elsif Nkind
(N
) = N_Function_Call
6671 and then Is_Entity_Name
(Name
(N
))
6672 and then Present
(Entity
(Name
(N
)))
6676 -- Another odd case, there are at least some cases of selected
6677 -- components where the selected component is not marked as having
6678 -- an entity, even though the selector does have an entity
6680 elsif Nkind
(N
) = N_Selected_Component
6681 and then Present
(Entity
(Selector_Name
(N
)))
6683 Enode
:= Selector_Name
(N
);
6689 -- Now test the entity we got to see if it is a bad case
6691 case Ekind
(Entity
(Enode
)) is
6695 ("package name cannot be used as operand", Enode
);
6697 when Generic_Unit_Kind
=>
6699 ("generic unit name cannot be used as operand", Enode
);
6703 ("subtype name cannot be used as operand", Enode
);
6707 ("entry name cannot be used as operand", Enode
);
6711 ("procedure name cannot be used as operand", Enode
);
6715 ("exception name cannot be used as operand", Enode
);
6717 when E_Block | E_Label | E_Loop
=>
6719 ("label name cannot be used as operand", Enode
);
6729 --------------------
6730 -- Operator_Check --
6731 --------------------
6733 procedure Operator_Check
(N
: Node_Id
) is
6735 Remove_Abstract_Operations
(N
);
6737 -- Test for case of no interpretation found for operator
6739 if Etype
(N
) = Any_Type
then
6743 Op_Id
: Entity_Id
:= Empty
;
6746 R
:= Right_Opnd
(N
);
6748 if Nkind
(N
) in N_Binary_Op
then
6754 -- If either operand has no type, then don't complain further,
6755 -- since this simply means that we have a propagated error.
6758 or else Etype
(R
) = Any_Type
6759 or else (Nkind
(N
) in N_Binary_Op
and then Etype
(L
) = Any_Type
)
6761 -- For the rather unusual case where one of the operands is
6762 -- a Raise_Expression, whose initial type is Any_Type, use
6763 -- the type of the other operand.
6765 if Nkind
(L
) = N_Raise_Expression
then
6766 Set_Etype
(L
, Etype
(R
));
6767 Set_Etype
(N
, Etype
(R
));
6769 elsif Nkind
(R
) = N_Raise_Expression
then
6770 Set_Etype
(R
, Etype
(L
));
6771 Set_Etype
(N
, Etype
(L
));
6776 -- We explicitly check for the case of concatenation of component
6777 -- with component to avoid reporting spurious matching array types
6778 -- that might happen to be lurking in distant packages (such as
6779 -- run-time packages). This also prevents inconsistencies in the
6780 -- messages for certain ACVC B tests, which can vary depending on
6781 -- types declared in run-time interfaces. Another improvement when
6782 -- aggregates are present is to look for a well-typed operand.
6784 elsif Present
(Candidate_Type
)
6785 and then (Nkind
(N
) /= N_Op_Concat
6786 or else Is_Array_Type
(Etype
(L
))
6787 or else Is_Array_Type
(Etype
(R
)))
6789 if Nkind
(N
) = N_Op_Concat
then
6790 if Etype
(L
) /= Any_Composite
6791 and then Is_Array_Type
(Etype
(L
))
6793 Candidate_Type
:= Etype
(L
);
6795 elsif Etype
(R
) /= Any_Composite
6796 and then Is_Array_Type
(Etype
(R
))
6798 Candidate_Type
:= Etype
(R
);
6802 Error_Msg_NE
-- CODEFIX
6803 ("operator for} is not directly visible!",
6804 N
, First_Subtype
(Candidate_Type
));
6807 U
: constant Node_Id
:=
6808 Cunit
(Get_Source_Unit
(Candidate_Type
));
6810 if Unit_Is_Visible
(U
) then
6811 Error_Msg_N
-- CODEFIX
6812 ("use clause would make operation legal!", N
);
6814 Error_Msg_NE
-- CODEFIX
6815 ("add with_clause and use_clause for&!",
6816 N
, Defining_Entity
(Unit
(U
)));
6821 -- If either operand is a junk operand (e.g. package name), then
6822 -- post appropriate error messages, but do not complain further.
6824 -- Note that the use of OR in this test instead of OR ELSE is
6825 -- quite deliberate, we may as well check both operands in the
6826 -- binary operator case.
6828 elsif Junk_Operand
(R
)
6829 or -- really mean OR here and not OR ELSE, see above
6830 (Nkind
(N
) in N_Binary_Op
and then Junk_Operand
(L
))
6834 -- If we have a logical operator, one of whose operands is
6835 -- Boolean, then we know that the other operand cannot resolve to
6836 -- Boolean (since we got no interpretations), but in that case we
6837 -- pretty much know that the other operand should be Boolean, so
6838 -- resolve it that way (generating an error).
6840 elsif Nkind_In
(N
, N_Op_And
, N_Op_Or
, N_Op_Xor
) then
6841 if Etype
(L
) = Standard_Boolean
then
6842 Resolve
(R
, Standard_Boolean
);
6844 elsif Etype
(R
) = Standard_Boolean
then
6845 Resolve
(L
, Standard_Boolean
);
6849 -- For an arithmetic operator or comparison operator, if one
6850 -- of the operands is numeric, then we know the other operand
6851 -- is not the same numeric type. If it is a non-numeric type,
6852 -- then probably it is intended to match the other operand.
6854 elsif Nkind_In
(N
, N_Op_Add
,
6860 Nkind_In
(N
, N_Op_Lt
,
6866 -- If Allow_Integer_Address is active, check whether the
6867 -- operation becomes legal after converting an operand.
6869 if Is_Numeric_Type
(Etype
(L
))
6870 and then not Is_Numeric_Type
(Etype
(R
))
6872 if Address_Integer_Convert_OK
(Etype
(R
), Etype
(L
)) then
6874 Unchecked_Convert_To
(Etype
(L
), Relocate_Node
(R
)));
6876 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6877 Analyze_Comparison_Op
(N
);
6879 Analyze_Arithmetic_Op
(N
);
6882 Resolve
(R
, Etype
(L
));
6887 elsif Is_Numeric_Type
(Etype
(R
))
6888 and then not Is_Numeric_Type
(Etype
(L
))
6890 if Address_Integer_Convert_OK
(Etype
(L
), Etype
(R
)) then
6892 Unchecked_Convert_To
(Etype
(R
), Relocate_Node
(L
)));
6894 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6895 Analyze_Comparison_Op
(N
);
6897 Analyze_Arithmetic_Op
(N
);
6903 Resolve
(L
, Etype
(R
));
6908 elsif Allow_Integer_Address
6909 and then Is_Descendant_Of_Address
(Etype
(L
))
6910 and then Is_Descendant_Of_Address
(Etype
(R
))
6911 and then not Error_Posted
(N
)
6914 Addr_Type
: constant Entity_Id
:= Etype
(L
);
6918 Unchecked_Convert_To
(
6919 Standard_Integer
, Relocate_Node
(L
)));
6921 Unchecked_Convert_To
(
6922 Standard_Integer
, Relocate_Node
(R
)));
6924 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6925 Analyze_Comparison_Op
(N
);
6927 Analyze_Arithmetic_Op
(N
);
6930 -- If this is an operand in an enclosing arithmetic
6931 -- operation, Convert the result as an address so that
6932 -- arithmetic folding of address can continue.
6934 if Nkind
(Parent
(N
)) in N_Op
then
6936 Unchecked_Convert_To
(Addr_Type
, Relocate_Node
(N
)));
6942 -- Under relaxed RM semantics silently replace occurrences of
6943 -- null by System.Address_Null.
6945 elsif Null_To_Null_Address_Convert_OK
(N
) then
6946 Replace_Null_By_Null_Address
(N
);
6948 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6949 Analyze_Comparison_Op
(N
);
6951 Analyze_Arithmetic_Op
(N
);
6957 -- Comparisons on A'Access are common enough to deserve a
6960 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
)
6961 and then Ekind
(Etype
(L
)) = E_Access_Attribute_Type
6962 and then Ekind
(Etype
(R
)) = E_Access_Attribute_Type
6965 ("two access attributes cannot be compared directly", N
);
6967 ("\use qualified expression for one of the operands",
6971 -- Another one for C programmers
6973 elsif Nkind
(N
) = N_Op_Concat
6974 and then Valid_Boolean_Arg
(Etype
(L
))
6975 and then Valid_Boolean_Arg
(Etype
(R
))
6977 Error_Msg_N
("invalid operands for concatenation", N
);
6978 Error_Msg_N
-- CODEFIX
6979 ("\maybe AND was meant", N
);
6982 -- A special case for comparison of access parameter with null
6984 elsif Nkind
(N
) = N_Op_Eq
6985 and then Is_Entity_Name
(L
)
6986 and then Nkind
(Parent
(Entity
(L
))) = N_Parameter_Specification
6987 and then Nkind
(Parameter_Type
(Parent
(Entity
(L
)))) =
6989 and then Nkind
(R
) = N_Null
6991 Error_Msg_N
("access parameter is not allowed to be null", L
);
6992 Error_Msg_N
("\(call would raise Constraint_Error)", L
);
6995 -- Another special case for exponentiation, where the right
6996 -- operand must be Natural, independently of the base.
6998 elsif Nkind
(N
) = N_Op_Expon
6999 and then Is_Numeric_Type
(Etype
(L
))
7000 and then not Is_Overloaded
(R
)
7002 First_Subtype
(Base_Type
(Etype
(R
))) /= Standard_Integer
7003 and then Base_Type
(Etype
(R
)) /= Universal_Integer
7005 if Ada_Version
>= Ada_2012
7006 and then Has_Dimension_System
(Etype
(L
))
7009 ("exponent for dimensioned type must be a rational" &
7010 ", found}", R
, Etype
(R
));
7013 ("exponent must be of type Natural, found}", R
, Etype
(R
));
7018 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
) then
7019 if Address_Integer_Convert_OK
(Etype
(R
), Etype
(L
)) then
7021 Unchecked_Convert_To
(Etype
(L
), Relocate_Node
(R
)));
7022 Analyze_Equality_Op
(N
);
7025 -- Under relaxed RM semantics silently replace occurrences of
7026 -- null by System.Address_Null.
7028 elsif Null_To_Null_Address_Convert_OK
(N
) then
7029 Replace_Null_By_Null_Address
(N
);
7030 Analyze_Equality_Op
(N
);
7035 -- If we fall through then just give general message. Note that in
7036 -- the following messages, if the operand is overloaded we choose
7037 -- an arbitrary type to complain about, but that is probably more
7038 -- useful than not giving a type at all.
7040 if Nkind
(N
) in N_Unary_Op
then
7041 Error_Msg_Node_2
:= Etype
(R
);
7042 Error_Msg_N
("operator& not defined for}", N
);
7046 if Nkind
(N
) in N_Binary_Op
then
7047 if not Is_Overloaded
(L
)
7048 and then not Is_Overloaded
(R
)
7049 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
7051 Error_Msg_Node_2
:= First_Subtype
(Etype
(R
));
7052 Error_Msg_N
("there is no applicable operator& for}", N
);
7055 -- Another attempt to find a fix: one of the candidate
7056 -- interpretations may not be use-visible. This has
7057 -- already been checked for predefined operators, so
7058 -- we examine only user-defined functions.
7060 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
7062 while Present
(Op_Id
) loop
7063 if Ekind
(Op_Id
) /= E_Operator
7064 and then Is_Overloadable
(Op_Id
)
7066 if not Is_Immediately_Visible
(Op_Id
)
7067 and then not In_Use
(Scope
(Op_Id
))
7068 and then not Is_Abstract_Subprogram
(Op_Id
)
7069 and then not Is_Hidden
(Op_Id
)
7070 and then Ekind
(Scope
(Op_Id
)) = E_Package
7073 (L
, Etype
(First_Formal
(Op_Id
)))
7075 (Next_Formal
(First_Formal
(Op_Id
)))
7079 Etype
(Next_Formal
(First_Formal
(Op_Id
))))
7082 ("No legal interpretation for operator&", N
);
7084 ("\use clause on& would make operation legal",
7090 Op_Id
:= Homonym
(Op_Id
);
7094 Error_Msg_N
("invalid operand types for operator&", N
);
7096 if Nkind
(N
) /= N_Op_Concat
then
7097 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
7098 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
7100 -- For concatenation operators it is more difficult to
7101 -- determine which is the wrong operand. It is worth
7102 -- flagging explicitly an access type, for those who
7103 -- might think that a dereference happens here.
7105 elsif Is_Access_Type
(Etype
(L
)) then
7106 Error_Msg_N
("\left operand is access type", N
);
7108 elsif Is_Access_Type
(Etype
(R
)) then
7109 Error_Msg_N
("\right operand is access type", N
);
7119 -----------------------------------------
7120 -- Process_Implicit_Dereference_Prefix --
7121 -----------------------------------------
7123 function Process_Implicit_Dereference_Prefix
7125 P
: Entity_Id
) return Entity_Id
7128 Typ
: constant Entity_Id
:= Designated_Type
(Etype
(P
));
7132 and then (Operating_Mode
= Check_Semantics
or else not Expander_Active
)
7134 -- We create a dummy reference to E to ensure that the reference is
7135 -- not considered as part of an assignment (an implicit dereference
7136 -- can never assign to its prefix). The Comes_From_Source attribute
7137 -- needs to be propagated for accurate warnings.
7139 Ref
:= New_Occurrence_Of
(E
, Sloc
(P
));
7140 Set_Comes_From_Source
(Ref
, Comes_From_Source
(P
));
7141 Generate_Reference
(E
, Ref
);
7144 -- An implicit dereference is a legal occurrence of an incomplete type
7145 -- imported through a limited_with clause, if the full view is visible.
7147 if From_Limited_With
(Typ
)
7148 and then not From_Limited_With
(Scope
(Typ
))
7150 (Is_Immediately_Visible
(Scope
(Typ
))
7152 (Is_Child_Unit
(Scope
(Typ
))
7153 and then Is_Visible_Lib_Unit
(Scope
(Typ
))))
7155 return Available_View
(Typ
);
7159 end Process_Implicit_Dereference_Prefix
;
7161 --------------------------------
7162 -- Remove_Abstract_Operations --
7163 --------------------------------
7165 procedure Remove_Abstract_Operations
(N
: Node_Id
) is
7166 Abstract_Op
: Entity_Id
:= Empty
;
7167 Address_Descendant
: Boolean := False;
7171 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
7172 -- activate this if either extensions are enabled, or if the abstract
7173 -- operation in question comes from a predefined file. This latter test
7174 -- allows us to use abstract to make operations invisible to users. In
7175 -- particular, if type Address is non-private and abstract subprograms
7176 -- are used to hide its operators, they will be truly hidden.
7178 type Operand_Position
is (First_Op
, Second_Op
);
7179 Univ_Type
: constant Entity_Id
:= Universal_Interpretation
(N
);
7181 procedure Remove_Address_Interpretations
(Op
: Operand_Position
);
7182 -- Ambiguities may arise when the operands are literal and the address
7183 -- operations in s-auxdec are visible. In that case, remove the
7184 -- interpretation of a literal as Address, to retain the semantics
7185 -- of Address as a private type.
7187 ------------------------------------
7188 -- Remove_Address_Interpretations --
7189 ------------------------------------
7191 procedure Remove_Address_Interpretations
(Op
: Operand_Position
) is
7195 if Is_Overloaded
(N
) then
7196 Get_First_Interp
(N
, I
, It
);
7197 while Present
(It
.Nam
) loop
7198 Formal
:= First_Entity
(It
.Nam
);
7200 if Op
= Second_Op
then
7201 Formal
:= Next_Entity
(Formal
);
7204 if Is_Descendant_Of_Address
(Etype
(Formal
)) then
7205 Address_Descendant
:= True;
7209 Get_Next_Interp
(I
, It
);
7212 end Remove_Address_Interpretations
;
7214 -- Start of processing for Remove_Abstract_Operations
7217 if Is_Overloaded
(N
) then
7218 if Debug_Flag_V
then
7219 Write_Str
("Remove_Abstract_Operations: ");
7220 Write_Overloads
(N
);
7223 Get_First_Interp
(N
, I
, It
);
7225 while Present
(It
.Nam
) loop
7226 if Is_Overloadable
(It
.Nam
)
7227 and then Is_Abstract_Subprogram
(It
.Nam
)
7228 and then not Is_Dispatching_Operation
(It
.Nam
)
7230 Abstract_Op
:= It
.Nam
;
7232 if Is_Descendant_Of_Address
(It
.Typ
) then
7233 Address_Descendant
:= True;
7237 -- In Ada 2005, this operation does not participate in overload
7238 -- resolution. If the operation is defined in a predefined
7239 -- unit, it is one of the operations declared abstract in some
7240 -- variants of System, and it must be removed as well.
7242 elsif Ada_Version
>= Ada_2005
7243 or else Is_Predefined_File_Name
7244 (Unit_File_Name
(Get_Source_Unit
(It
.Nam
)))
7251 Get_Next_Interp
(I
, It
);
7254 if No
(Abstract_Op
) then
7256 -- If some interpretation yields an integer type, it is still
7257 -- possible that there are address interpretations. Remove them
7258 -- if one operand is a literal, to avoid spurious ambiguities
7259 -- on systems where Address is a visible integer type.
7261 if Is_Overloaded
(N
)
7262 and then Nkind
(N
) in N_Op
7263 and then Is_Integer_Type
(Etype
(N
))
7265 if Nkind
(N
) in N_Binary_Op
then
7266 if Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
7267 Remove_Address_Interpretations
(Second_Op
);
7269 elsif Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
7270 Remove_Address_Interpretations
(First_Op
);
7275 elsif Nkind
(N
) in N_Op
then
7277 -- Remove interpretations that treat literals as addresses. This
7278 -- is never appropriate, even when Address is defined as a visible
7279 -- Integer type. The reason is that we would really prefer Address
7280 -- to behave as a private type, even in this case. If Address is a
7281 -- visible integer type, we get lots of overload ambiguities.
7283 if Nkind
(N
) in N_Binary_Op
then
7285 U1
: constant Boolean :=
7286 Present
(Universal_Interpretation
(Right_Opnd
(N
)));
7287 U2
: constant Boolean :=
7288 Present
(Universal_Interpretation
(Left_Opnd
(N
)));
7292 Remove_Address_Interpretations
(Second_Op
);
7296 Remove_Address_Interpretations
(First_Op
);
7299 if not (U1
and U2
) then
7301 -- Remove corresponding predefined operator, which is
7302 -- always added to the overload set.
7304 Get_First_Interp
(N
, I
, It
);
7305 while Present
(It
.Nam
) loop
7306 if Scope
(It
.Nam
) = Standard_Standard
7307 and then Base_Type
(It
.Typ
) =
7308 Base_Type
(Etype
(Abstract_Op
))
7313 Get_Next_Interp
(I
, It
);
7316 elsif Is_Overloaded
(N
)
7317 and then Present
(Univ_Type
)
7319 -- If both operands have a universal interpretation,
7320 -- it is still necessary to remove interpretations that
7321 -- yield Address. Any remaining ambiguities will be
7322 -- removed in Disambiguate.
7324 Get_First_Interp
(N
, I
, It
);
7325 while Present
(It
.Nam
) loop
7326 if Is_Descendant_Of_Address
(It
.Typ
) then
7329 elsif not Is_Type
(It
.Nam
) then
7330 Set_Entity
(N
, It
.Nam
);
7333 Get_Next_Interp
(I
, It
);
7339 elsif Nkind
(N
) = N_Function_Call
7341 (Nkind
(Name
(N
)) = N_Operator_Symbol
7343 (Nkind
(Name
(N
)) = N_Expanded_Name
7345 Nkind
(Selector_Name
(Name
(N
))) = N_Operator_Symbol
))
7349 Arg1
: constant Node_Id
:= First
(Parameter_Associations
(N
));
7350 U1
: constant Boolean :=
7351 Present
(Universal_Interpretation
(Arg1
));
7352 U2
: constant Boolean :=
7353 Present
(Next
(Arg1
)) and then
7354 Present
(Universal_Interpretation
(Next
(Arg1
)));
7358 Remove_Address_Interpretations
(First_Op
);
7362 Remove_Address_Interpretations
(Second_Op
);
7365 if not (U1
and U2
) then
7366 Get_First_Interp
(N
, I
, It
);
7367 while Present
(It
.Nam
) loop
7368 if Scope
(It
.Nam
) = Standard_Standard
7369 and then It
.Typ
= Base_Type
(Etype
(Abstract_Op
))
7374 Get_Next_Interp
(I
, It
);
7380 -- If the removal has left no valid interpretations, emit an error
7381 -- message now and label node as illegal.
7383 if Present
(Abstract_Op
) then
7384 Get_First_Interp
(N
, I
, It
);
7388 -- Removal of abstract operation left no viable candidate
7390 Set_Etype
(N
, Any_Type
);
7391 Error_Msg_Sloc
:= Sloc
(Abstract_Op
);
7393 ("cannot call abstract operation& declared#", N
, Abstract_Op
);
7395 -- In Ada 2005, an abstract operation may disable predefined
7396 -- operators. Since the context is not yet known, we mark the
7397 -- predefined operators as potentially hidden. Do not include
7398 -- predefined operators when addresses are involved since this
7399 -- case is handled separately.
7401 elsif Ada_Version
>= Ada_2005
and then not Address_Descendant
then
7402 while Present
(It
.Nam
) loop
7403 if Is_Numeric_Type
(It
.Typ
)
7404 and then Scope
(It
.Typ
) = Standard_Standard
7406 Set_Abstract_Op
(I
, Abstract_Op
);
7409 Get_Next_Interp
(I
, It
);
7414 if Debug_Flag_V
then
7415 Write_Str
("Remove_Abstract_Operations done: ");
7416 Write_Overloads
(N
);
7419 end Remove_Abstract_Operations
;
7421 ----------------------------
7422 -- Try_Container_Indexing --
7423 ----------------------------
7425 function Try_Container_Indexing
7428 Exprs
: List_Id
) return Boolean
7430 Pref_Typ
: constant Entity_Id
:= Etype
(Prefix
);
7432 function Constant_Indexing_OK
return Boolean;
7433 -- Constant_Indexing is legal if there is no Variable_Indexing defined
7434 -- for the type, or else node not a target of assignment, or an actual
7435 -- for an IN OUT or OUT formal (RM 4.1.6 (11)).
7437 function Find_Indexing_Operations
7440 Is_Constant
: Boolean) return Node_Id
;
7441 -- Return a reference to the primitive operation of type T denoted by
7442 -- name Nam. If the operation is overloaded, the reference carries all
7443 -- interpretations. Flag Is_Constant should be set when the context is
7444 -- constant indexing.
7446 --------------------------
7447 -- Constant_Indexing_OK --
7448 --------------------------
7450 function Constant_Indexing_OK
return Boolean is
7454 if No
(Find_Value_Of_Aspect
(Pref_Typ
, Aspect_Variable_Indexing
)) then
7457 elsif not Is_Variable
(Prefix
) then
7462 while Present
(Par
) loop
7463 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
7464 and then Par
= Name
(Parent
(Par
))
7468 -- The call may be overloaded, in which case we assume that its
7469 -- resolution does not depend on the type of the parameter that
7470 -- includes the indexing operation.
7472 elsif Nkind_In
(Parent
(Par
), N_Function_Call
,
7473 N_Procedure_Call_Statement
)
7474 and then Is_Entity_Name
(Name
(Parent
(Par
)))
7482 -- We should look for an interpretation with the proper
7483 -- number of formals, and determine whether it is an
7484 -- In_Parameter, but for now we examine the formal that
7485 -- corresponds to the indexing, and assume that variable
7486 -- indexing is required if some interpretation has an
7487 -- assignable formal at that position. Still does not
7488 -- cover the most complex cases ???
7490 if Is_Overloaded
(Name
(Parent
(Par
))) then
7492 Proc
: constant Node_Id
:= Name
(Parent
(Par
));
7499 Get_First_Interp
(Proc
, I
, It
);
7500 while Present
(It
.Nam
) loop
7501 F
:= First_Formal
(It
.Nam
);
7502 A
:= First
(Parameter_Associations
(Parent
(Par
)));
7504 while Present
(F
) and then Present
(A
) loop
7506 if Ekind
(F
) /= E_In_Parameter
then
7509 exit; -- interpretation is safe
7517 Get_Next_Interp
(I
, It
);
7524 Proc
:= Entity
(Name
(Parent
(Par
)));
7526 -- If this is an indirect call, get formals from
7529 if Is_Access_Subprogram_Type
(Etype
(Proc
)) then
7530 Proc
:= Designated_Type
(Etype
(Proc
));
7534 Formal
:= First_Formal
(Proc
);
7535 Actual
:= First_Actual
(Parent
(Par
));
7537 -- Find corresponding actual
7539 while Present
(Actual
) loop
7540 exit when Actual
= Par
;
7541 Next_Actual
(Actual
);
7543 if Present
(Formal
) then
7544 Next_Formal
(Formal
);
7546 -- Otherwise this is a parameter mismatch, the error is
7547 -- reported elsewhere.
7554 return Ekind
(Formal
) = E_In_Parameter
;
7557 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
7560 -- If the indexed component is a prefix it may be the first actual
7561 -- of a prefixed call. Retrieve the called entity, if any, and
7562 -- check its first formal. Determine if the context is a procedure
7563 -- or function call.
7565 elsif Nkind
(Parent
(Par
)) = N_Selected_Component
then
7567 Sel
: constant Node_Id
:= Selector_Name
(Parent
(Par
));
7568 Nam
: constant Entity_Id
:= Current_Entity
(Sel
);
7571 if Present
(Nam
) and then Is_Overloadable
(Nam
) then
7572 if Nkind
(Parent
(Parent
(Par
))) =
7573 N_Procedure_Call_Statement
7577 elsif Ekind
(Nam
) = E_Function
7578 and then Present
(First_Formal
(Nam
))
7580 return Ekind
(First_Formal
(Nam
)) = E_In_Parameter
;
7585 elsif Nkind
(Par
) in N_Op
then
7589 Par
:= Parent
(Par
);
7592 -- In all other cases, constant indexing is legal
7595 end Constant_Indexing_OK
;
7597 ------------------------------
7598 -- Find_Indexing_Operations --
7599 ------------------------------
7601 function Find_Indexing_Operations
7604 Is_Constant
: Boolean) return Node_Id
7606 procedure Inspect_Declarations
7608 Ref
: in out Node_Id
);
7609 -- Traverse the declarative list where type Typ resides and collect
7610 -- all suitable interpretations in node Ref.
7612 procedure Inspect_Primitives
7614 Ref
: in out Node_Id
);
7615 -- Traverse the list of primitive operations of type Typ and collect
7616 -- all suitable interpretations in node Ref.
7618 function Is_OK_Candidate
7619 (Subp_Id
: Entity_Id
;
7620 Typ
: Entity_Id
) return Boolean;
7621 -- Determine whether subprogram Subp_Id is a suitable indexing
7622 -- operation for type Typ. To qualify as such, the subprogram must
7623 -- be a function, have at least two parameters, and the type of the
7624 -- first parameter must be either Typ, or Typ'Class, or access [to
7625 -- constant] with designated type Typ or Typ'Class.
7627 procedure Record_Interp
(Subp_Id
: Entity_Id
; Ref
: in out Node_Id
);
7628 -- Store subprogram Subp_Id as an interpretation in node Ref
7630 --------------------------
7631 -- Inspect_Declarations --
7632 --------------------------
7634 procedure Inspect_Declarations
7636 Ref
: in out Node_Id
)
7638 Typ_Decl
: constant Node_Id
:= Declaration_Node
(Typ
);
7640 Subp_Id
: Entity_Id
;
7643 -- Ensure that the routine is not called with itypes, which lack a
7644 -- declarative node.
7646 pragma Assert
(Present
(Typ_Decl
));
7647 pragma Assert
(Is_List_Member
(Typ_Decl
));
7649 Decl
:= First
(List_Containing
(Typ_Decl
));
7650 while Present
(Decl
) loop
7651 if Nkind
(Decl
) = N_Subprogram_Declaration
then
7652 Subp_Id
:= Defining_Entity
(Decl
);
7654 if Is_OK_Candidate
(Subp_Id
, Typ
) then
7655 Record_Interp
(Subp_Id
, Ref
);
7661 end Inspect_Declarations
;
7663 ------------------------
7664 -- Inspect_Primitives --
7665 ------------------------
7667 procedure Inspect_Primitives
7669 Ref
: in out Node_Id
)
7671 Prim_Elmt
: Elmt_Id
;
7672 Prim_Id
: Entity_Id
;
7675 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7676 while Present
(Prim_Elmt
) loop
7677 Prim_Id
:= Node
(Prim_Elmt
);
7679 if Is_OK_Candidate
(Prim_Id
, Typ
) then
7680 Record_Interp
(Prim_Id
, Ref
);
7683 Next_Elmt
(Prim_Elmt
);
7685 end Inspect_Primitives
;
7687 ---------------------
7688 -- Is_OK_Candidate --
7689 ---------------------
7691 function Is_OK_Candidate
7692 (Subp_Id
: Entity_Id
;
7693 Typ
: Entity_Id
) return Boolean
7696 Formal_Typ
: Entity_Id
;
7697 Param_Typ
: Node_Id
;
7700 -- To classify as a suitable candidate, the subprogram must be a
7701 -- function whose name matches the argument of aspect Constant or
7702 -- Variable_Indexing.
7704 if Ekind
(Subp_Id
) = E_Function
and then Chars
(Subp_Id
) = Nam
then
7705 Formal
:= First_Formal
(Subp_Id
);
7707 -- The candidate requires at least two parameters
7709 if Present
(Formal
) and then Present
(Next_Formal
(Formal
)) then
7710 Formal_Typ
:= Empty
;
7711 Param_Typ
:= Parameter_Type
(Parent
(Formal
));
7713 -- Use the designated type when the first parameter is of an
7716 if Nkind
(Param_Typ
) = N_Access_Definition
7717 and then Present
(Subtype_Mark
(Param_Typ
))
7719 -- When the context is a constant indexing, the access
7720 -- definition must be access-to-constant. This does not
7721 -- apply to variable indexing.
7724 or else Constant_Present
(Param_Typ
)
7726 Formal_Typ
:= Etype
(Subtype_Mark
(Param_Typ
));
7729 -- Otherwise use the parameter type
7732 Formal_Typ
:= Etype
(Param_Typ
);
7735 if Present
(Formal_Typ
) then
7737 -- Use the specific type when the parameter type is
7740 if Is_Class_Wide_Type
(Formal_Typ
) then
7741 Formal_Typ
:= Etype
(Base_Type
(Formal_Typ
));
7744 -- Use the full view when the parameter type is private
7747 if Is_Incomplete_Or_Private_Type
(Formal_Typ
)
7748 and then Present
(Full_View
(Formal_Typ
))
7750 Formal_Typ
:= Full_View
(Formal_Typ
);
7753 -- The type of the first parameter must denote the type
7754 -- of the container or acts as its ancestor type.
7758 or else Is_Ancestor
(Formal_Typ
, Typ
);
7764 end Is_OK_Candidate
;
7770 procedure Record_Interp
(Subp_Id
: Entity_Id
; Ref
: in out Node_Id
) is
7772 if Present
(Ref
) then
7773 Add_One_Interp
(Ref
, Subp_Id
, Etype
(Subp_Id
));
7775 -- Otherwise this is the first interpretation. Create a reference
7776 -- where all remaining interpretations will be collected.
7779 Ref
:= New_Occurrence_Of
(Subp_Id
, Sloc
(T
));
7788 -- Start of processing for Find_Indexing_Operations
7793 -- Use the specific type when the parameter type is class-wide
7795 if Is_Class_Wide_Type
(Typ
) then
7796 Typ
:= Root_Type
(Typ
);
7800 Typ
:= Underlying_Type
(Base_Type
(Typ
));
7802 Inspect_Primitives
(Typ
, Ref
);
7803 Inspect_Declarations
(Typ
, Ref
);
7806 end Find_Indexing_Operations
;
7810 Loc
: constant Source_Ptr
:= Sloc
(N
);
7814 Func_Name
: Node_Id
;
7817 Is_Constant_Indexing
: Boolean := False;
7818 -- This flag reflects the nature of the container indexing. Note that
7819 -- the context may be suited for constant indexing, but the type may
7820 -- lack a Constant_Indexing annotation.
7822 -- Start of processing for Try_Container_Indexing
7825 -- Node may have been analyzed already when testing for a prefixed
7826 -- call, in which case do not redo analysis.
7828 if Present
(Generalized_Indexing
(N
)) then
7834 -- If indexing a class-wide container, obtain indexing primitive from
7837 if Is_Class_Wide_Type
(C_Type
) then
7838 C_Type
:= Etype
(Base_Type
(C_Type
));
7841 -- Check whether the type has a specified indexing aspect
7845 -- The context is suitable for constant indexing, so obtain the name of
7846 -- the indexing function from aspect Constant_Indexing.
7848 if Constant_Indexing_OK
then
7850 Find_Value_Of_Aspect
(Pref_Typ
, Aspect_Constant_Indexing
);
7853 if Present
(Func_Name
) then
7854 Is_Constant_Indexing
:= True;
7856 -- Otherwise attempt variable indexing
7860 Find_Value_Of_Aspect
(Pref_Typ
, Aspect_Variable_Indexing
);
7863 -- The type is not subject to either form of indexing, therefore the
7864 -- indexed component does not denote container indexing. If this is a
7865 -- true error, it is diagnosed by the caller.
7867 if No
(Func_Name
) then
7869 -- The prefix itself may be an indexing of a container. Rewrite it
7870 -- as such and retry.
7872 if Has_Implicit_Dereference
(Pref_Typ
) then
7873 Build_Explicit_Dereference
(Prefix
, First_Discriminant
(Pref_Typ
));
7874 return Try_Container_Indexing
(N
, Prefix
, Exprs
);
7876 -- Otherwise this is definitely not container indexing
7882 -- If the container type is derived from another container type, the
7883 -- value of the inherited aspect is the Reference operation declared
7884 -- for the parent type.
7886 -- However, Reference is also a primitive operation of the type, and the
7887 -- inherited operation has a different signature. We retrieve the right
7888 -- ones (the function may be overloaded) from the list of primitive
7889 -- operations of the derived type.
7891 -- Note that predefined containers are typically all derived from one of
7892 -- the Controlled types. The code below is motivated by containers that
7893 -- are derived from other types with a Reference aspect.
7895 elsif Is_Derived_Type
(C_Type
)
7896 and then Etype
(First_Formal
(Entity
(Func_Name
))) /= Pref_Typ
7899 Find_Indexing_Operations
7901 Nam
=> Chars
(Func_Name
),
7902 Is_Constant
=> Is_Constant_Indexing
);
7905 Assoc
:= New_List
(Relocate_Node
(Prefix
));
7907 -- A generalized indexing may have nore than one index expression, so
7908 -- transfer all of them to the argument list to be used in the call.
7909 -- Note that there may be named associations, in which case the node
7910 -- was rewritten earlier as a call, and has been transformed back into
7911 -- an indexed expression to share the following processing.
7913 -- The generalized indexing node is the one on which analysis and
7914 -- resolution take place. Before expansion the original node is replaced
7915 -- with the generalized indexing node, which is a call, possibly with a
7916 -- dereference operation.
7918 if Comes_From_Source
(N
) then
7919 Check_Compiler_Unit
("generalized indexing", N
);
7922 -- Create argument list for function call that represents generalized
7923 -- indexing. Note that indices (i.e. actuals) may themselves be
7931 Arg
:= First
(Exprs
);
7932 while Present
(Arg
) loop
7933 New_Arg
:= Relocate_Node
(Arg
);
7935 -- The arguments can be parameter associations, in which case the
7936 -- explicit actual parameter carries the overloadings.
7938 if Nkind
(New_Arg
) /= N_Parameter_Association
then
7939 Save_Interps
(Arg
, New_Arg
);
7942 Append
(New_Arg
, Assoc
);
7947 if not Is_Overloaded
(Func_Name
) then
7948 Func
:= Entity
(Func_Name
);
7950 Make_Function_Call
(Loc
,
7951 Name
=> New_Occurrence_Of
(Func
, Loc
),
7952 Parameter_Associations
=> Assoc
);
7953 Set_Parent
(Indexing
, Parent
(N
));
7954 Set_Generalized_Indexing
(N
, Indexing
);
7956 Set_Etype
(N
, Etype
(Indexing
));
7958 -- If the return type of the indexing function is a reference type,
7959 -- add the dereference as a possible interpretation. Note that the
7960 -- indexing aspect may be a function that returns the element type
7961 -- with no intervening implicit dereference, and that the reference
7962 -- discriminant is not the first discriminant.
7964 if Has_Discriminants
(Etype
(Func
)) then
7965 Check_Implicit_Dereference
(N
, Etype
(Func
));
7969 -- If there are multiple indexing functions, build a function call
7970 -- and analyze it for each of the possible interpretations.
7973 Make_Function_Call
(Loc
,
7975 Make_Identifier
(Loc
, Chars
(Func_Name
)),
7976 Parameter_Associations
=> Assoc
);
7978 Set_Parent
(Indexing
, Parent
(N
));
7979 Set_Generalized_Indexing
(N
, Indexing
);
7980 Set_Etype
(N
, Any_Type
);
7981 Set_Etype
(Name
(Indexing
), Any_Type
);
7989 Get_First_Interp
(Func_Name
, I
, It
);
7990 Set_Etype
(Indexing
, Any_Type
);
7992 -- Analyze eacn candidae function with the given actuals
7994 while Present
(It
.Nam
) loop
7995 Analyze_One_Call
(Indexing
, It
.Nam
, False, Success
);
7996 Get_Next_Interp
(I
, It
);
7999 -- If there are several successful candidates, resolution will
8000 -- be by result. Mark the interpretations of the function name
8003 if Is_Overloaded
(Indexing
) then
8004 Get_First_Interp
(Indexing
, I
, It
);
8006 while Present
(It
.Nam
) loop
8007 Add_One_Interp
(Name
(Indexing
), It
.Nam
, It
.Typ
);
8008 Get_Next_Interp
(I
, It
);
8012 Set_Etype
(Name
(Indexing
), Etype
(Indexing
));
8015 -- Now add the candidate interpretations to the indexing node
8016 -- itself, to be replaced later by the function call.
8018 if Is_Overloaded
(Name
(Indexing
)) then
8019 Get_First_Interp
(Name
(Indexing
), I
, It
);
8021 while Present
(It
.Nam
) loop
8022 Add_One_Interp
(N
, It
.Nam
, It
.Typ
);
8024 -- Add dereference interpretation if the result type has
8025 -- implicit reference discriminants.
8027 if Has_Discriminants
(Etype
(It
.Nam
)) then
8028 Check_Implicit_Dereference
(N
, Etype
(It
.Nam
));
8031 Get_Next_Interp
(I
, It
);
8035 Set_Etype
(N
, Etype
(Name
(Indexing
)));
8036 if Has_Discriminants
(Etype
(N
)) then
8037 Check_Implicit_Dereference
(N
, Etype
(N
));
8043 if Etype
(Indexing
) = Any_Type
then
8045 ("container cannot be indexed with&", N
, Etype
(First
(Exprs
)));
8046 Rewrite
(N
, New_Occurrence_Of
(Any_Id
, Loc
));
8050 end Try_Container_Indexing
;
8052 -----------------------
8053 -- Try_Indirect_Call --
8054 -----------------------
8056 function Try_Indirect_Call
8059 Typ
: Entity_Id
) return Boolean
8065 pragma Warnings
(Off
, Call_OK
);
8068 Normalize_Actuals
(N
, Designated_Type
(Typ
), False, Call_OK
);
8070 Actual
:= First_Actual
(N
);
8071 Formal
:= First_Formal
(Designated_Type
(Typ
));
8072 while Present
(Actual
) and then Present
(Formal
) loop
8073 if not Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
8078 Next_Formal
(Formal
);
8081 if No
(Actual
) and then No
(Formal
) then
8082 Add_One_Interp
(N
, Nam
, Etype
(Designated_Type
(Typ
)));
8084 -- Nam is a candidate interpretation for the name in the call,
8085 -- if it is not an indirect call.
8087 if not Is_Type
(Nam
)
8088 and then Is_Entity_Name
(Name
(N
))
8090 Set_Entity
(Name
(N
), Nam
);
8098 end Try_Indirect_Call
;
8100 ----------------------
8101 -- Try_Indexed_Call --
8102 ----------------------
8104 function Try_Indexed_Call
8108 Skip_First
: Boolean) return Boolean
8110 Loc
: constant Source_Ptr
:= Sloc
(N
);
8111 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
8116 Actual
:= First
(Actuals
);
8118 -- If the call was originally written in prefix form, skip the first
8119 -- actual, which is obviously not defaulted.
8125 Index
:= First_Index
(Typ
);
8126 while Present
(Actual
) and then Present
(Index
) loop
8128 -- If the parameter list has a named association, the expression
8129 -- is definitely a call and not an indexed component.
8131 if Nkind
(Actual
) = N_Parameter_Association
then
8135 if Is_Entity_Name
(Actual
)
8136 and then Is_Type
(Entity
(Actual
))
8137 and then No
(Next
(Actual
))
8139 -- A single actual that is a type name indicates a slice if the
8140 -- type is discrete, and an error otherwise.
8142 if Is_Discrete_Type
(Entity
(Actual
)) then
8146 Make_Function_Call
(Loc
,
8147 Name
=> Relocate_Node
(Name
(N
))),
8149 New_Occurrence_Of
(Entity
(Actual
), Sloc
(Actual
))));
8154 Error_Msg_N
("invalid use of type in expression", Actual
);
8155 Set_Etype
(N
, Any_Type
);
8160 elsif not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
8168 if No
(Actual
) and then No
(Index
) then
8169 Add_One_Interp
(N
, Nam
, Component_Type
(Typ
));
8171 -- Nam is a candidate interpretation for the name in the call,
8172 -- if it is not an indirect call.
8174 if not Is_Type
(Nam
)
8175 and then Is_Entity_Name
(Name
(N
))
8177 Set_Entity
(Name
(N
), Nam
);
8184 end Try_Indexed_Call
;
8186 --------------------------
8187 -- Try_Object_Operation --
8188 --------------------------
8190 function Try_Object_Operation
8191 (N
: Node_Id
; CW_Test_Only
: Boolean := False) return Boolean
8193 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
8194 Is_Subprg_Call
: constant Boolean := K
in N_Subprogram_Call
;
8195 Loc
: constant Source_Ptr
:= Sloc
(N
);
8196 Obj
: constant Node_Id
:= Prefix
(N
);
8198 Subprog
: constant Node_Id
:=
8199 Make_Identifier
(Sloc
(Selector_Name
(N
)),
8200 Chars
=> Chars
(Selector_Name
(N
)));
8201 -- Identifier on which possible interpretations will be collected
8203 Report_Error
: Boolean := False;
8204 -- If no candidate interpretation matches the context, redo analysis
8205 -- with Report_Error True to provide additional information.
8208 Candidate
: Entity_Id
:= Empty
;
8209 New_Call_Node
: Node_Id
:= Empty
;
8210 Node_To_Replace
: Node_Id
;
8211 Obj_Type
: Entity_Id
:= Etype
(Obj
);
8212 Success
: Boolean := False;
8214 function Valid_Candidate
8217 Subp
: Entity_Id
) return Entity_Id
;
8218 -- If the subprogram is a valid interpretation, record it, and add
8219 -- to the list of interpretations of Subprog. Otherwise return Empty.
8221 procedure Complete_Object_Operation
8222 (Call_Node
: Node_Id
;
8223 Node_To_Replace
: Node_Id
);
8224 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
8225 -- Call_Node, insert the object (or its dereference) as the first actual
8226 -- in the call, and complete the analysis of the call.
8228 procedure Report_Ambiguity
(Op
: Entity_Id
);
8229 -- If a prefixed procedure call is ambiguous, indicate whether the
8230 -- call includes an implicit dereference or an implicit 'Access.
8232 procedure Transform_Object_Operation
8233 (Call_Node
: out Node_Id
;
8234 Node_To_Replace
: out Node_Id
);
8235 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
8236 -- Call_Node is the resulting subprogram call, Node_To_Replace is
8237 -- either N or the parent of N, and Subprog is a reference to the
8238 -- subprogram we are trying to match.
8240 function Try_Class_Wide_Operation
8241 (Call_Node
: Node_Id
;
8242 Node_To_Replace
: Node_Id
) return Boolean;
8243 -- Traverse all ancestor types looking for a class-wide subprogram
8244 -- for which the current operation is a valid non-dispatching call.
8246 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
);
8247 -- If prefix is overloaded, its interpretation may include different
8248 -- tagged types, and we must examine the primitive operations and
8249 -- the class-wide operations of each in order to find candidate
8250 -- interpretations for the call as a whole.
8252 function Try_Primitive_Operation
8253 (Call_Node
: Node_Id
;
8254 Node_To_Replace
: Node_Id
) return Boolean;
8255 -- Traverse the list of primitive subprograms looking for a dispatching
8256 -- operation for which the current node is a valid call .
8258 ---------------------
8259 -- Valid_Candidate --
8260 ---------------------
8262 function Valid_Candidate
8265 Subp
: Entity_Id
) return Entity_Id
8267 Arr_Type
: Entity_Id
;
8268 Comp_Type
: Entity_Id
;
8271 -- If the subprogram is a valid interpretation, record it in global
8272 -- variable Subprog, to collect all possible overloadings.
8275 if Subp
/= Entity
(Subprog
) then
8276 Add_One_Interp
(Subprog
, Subp
, Etype
(Subp
));
8280 -- If the call may be an indexed call, retrieve component type of
8281 -- resulting expression, and add possible interpretation.
8286 if Nkind
(Call
) = N_Function_Call
8287 and then Nkind
(Parent
(N
)) = N_Indexed_Component
8288 and then Needs_One_Actual
(Subp
)
8290 if Is_Array_Type
(Etype
(Subp
)) then
8291 Arr_Type
:= Etype
(Subp
);
8293 elsif Is_Access_Type
(Etype
(Subp
))
8294 and then Is_Array_Type
(Designated_Type
(Etype
(Subp
)))
8296 Arr_Type
:= Designated_Type
(Etype
(Subp
));
8300 if Present
(Arr_Type
) then
8302 -- Verify that the actuals (excluding the object) match the types
8310 Actual
:= Next
(First_Actual
(Call
));
8311 Index
:= First_Index
(Arr_Type
);
8312 while Present
(Actual
) and then Present
(Index
) loop
8313 if not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
8318 Next_Actual
(Actual
);
8324 and then Present
(Arr_Type
)
8326 Comp_Type
:= Component_Type
(Arr_Type
);
8330 if Present
(Comp_Type
)
8331 and then Etype
(Subprog
) /= Comp_Type
8333 Add_One_Interp
(Subprog
, Subp
, Comp_Type
);
8337 if Etype
(Call
) /= Any_Type
then
8342 end Valid_Candidate
;
8344 -------------------------------
8345 -- Complete_Object_Operation --
8346 -------------------------------
8348 procedure Complete_Object_Operation
8349 (Call_Node
: Node_Id
;
8350 Node_To_Replace
: Node_Id
)
8352 Control
: constant Entity_Id
:= First_Formal
(Entity
(Subprog
));
8353 Formal_Type
: constant Entity_Id
:= Etype
(Control
);
8354 First_Actual
: Node_Id
;
8357 -- Place the name of the operation, with its interpretations,
8358 -- on the rewritten call.
8360 Set_Name
(Call_Node
, Subprog
);
8362 First_Actual
:= First
(Parameter_Associations
(Call_Node
));
8364 -- For cross-reference purposes, treat the new node as being in the
8365 -- source if the original one is. Set entity and type, even though
8366 -- they may be overwritten during resolution if overloaded.
8368 Set_Comes_From_Source
(Subprog
, Comes_From_Source
(N
));
8369 Set_Comes_From_Source
(Call_Node
, Comes_From_Source
(N
));
8371 if Nkind
(N
) = N_Selected_Component
8372 and then not Inside_A_Generic
8374 Set_Entity
(Selector_Name
(N
), Entity
(Subprog
));
8375 Set_Etype
(Selector_Name
(N
), Etype
(Entity
(Subprog
)));
8378 -- If need be, rewrite first actual as an explicit dereference. If
8379 -- the call is overloaded, the rewriting can only be done once the
8380 -- primitive operation is identified.
8382 if Is_Overloaded
(Subprog
) then
8384 -- The prefix itself may be overloaded, and its interpretations
8385 -- must be propagated to the new actual in the call.
8387 if Is_Overloaded
(Obj
) then
8388 Save_Interps
(Obj
, First_Actual
);
8391 Rewrite
(First_Actual
, Obj
);
8393 elsif not Is_Access_Type
(Formal_Type
)
8394 and then Is_Access_Type
(Etype
(Obj
))
8396 Rewrite
(First_Actual
,
8397 Make_Explicit_Dereference
(Sloc
(Obj
), Obj
));
8398 Analyze
(First_Actual
);
8400 -- If we need to introduce an explicit dereference, verify that
8401 -- the resulting actual is compatible with the mode of the formal.
8403 if Ekind
(First_Formal
(Entity
(Subprog
))) /= E_In_Parameter
8404 and then Is_Access_Constant
(Etype
(Obj
))
8407 ("expect variable in call to&", Prefix
(N
), Entity
(Subprog
));
8410 -- Conversely, if the formal is an access parameter and the object
8411 -- is not, replace the actual with a 'Access reference. Its analysis
8412 -- will check that the object is aliased.
8414 elsif Is_Access_Type
(Formal_Type
)
8415 and then not Is_Access_Type
(Etype
(Obj
))
8417 -- A special case: A.all'access is illegal if A is an access to a
8418 -- constant and the context requires an access to a variable.
8420 if not Is_Access_Constant
(Formal_Type
) then
8421 if (Nkind
(Obj
) = N_Explicit_Dereference
8422 and then Is_Access_Constant
(Etype
(Prefix
(Obj
))))
8423 or else not Is_Variable
(Obj
)
8426 ("actual for & must be a variable", Obj
, Control
);
8430 Rewrite
(First_Actual
,
8431 Make_Attribute_Reference
(Loc
,
8432 Attribute_Name
=> Name_Access
,
8433 Prefix
=> Relocate_Node
(Obj
)));
8435 if not Is_Aliased_View
(Obj
) then
8437 ("object in prefixed call to & must be aliased "
8438 & "(RM 4.1.3 (13 1/2))", Prefix
(First_Actual
), Subprog
);
8441 Analyze
(First_Actual
);
8444 if Is_Overloaded
(Obj
) then
8445 Save_Interps
(Obj
, First_Actual
);
8448 Rewrite
(First_Actual
, Obj
);
8451 -- The operation is obtained from the dispatch table and not by
8452 -- visibility, and may be declared in a unit that is not explicitly
8453 -- referenced in the source, but is nevertheless required in the
8454 -- context of the current unit. Indicate that operation and its scope
8455 -- are referenced, to prevent spurious and misleading warnings. If
8456 -- the operation is overloaded, all primitives are in the same scope
8457 -- and we can use any of them.
8459 Set_Referenced
(Entity
(Subprog
), True);
8460 Set_Referenced
(Scope
(Entity
(Subprog
)), True);
8462 Rewrite
(Node_To_Replace
, Call_Node
);
8464 -- Propagate the interpretations collected in subprog to the new
8465 -- function call node, to be resolved from context.
8467 if Is_Overloaded
(Subprog
) then
8468 Save_Interps
(Subprog
, Node_To_Replace
);
8471 -- The type of the subprogram may be a limited view obtained
8472 -- transitively from another unit. If full view is available,
8473 -- use it to analyze call.
8476 T
: constant Entity_Id
:= Etype
(Subprog
);
8478 if From_Limited_With
(T
) then
8479 Set_Etype
(Entity
(Subprog
), Available_View
(T
));
8483 Analyze
(Node_To_Replace
);
8485 -- If the operation has been rewritten into a call, which may get
8486 -- subsequently an explicit dereference, preserve the type on the
8487 -- original node (selected component or indexed component) for
8488 -- subsequent legality tests, e.g. Is_Variable. which examines
8489 -- the original node.
8491 if Nkind
(Node_To_Replace
) = N_Function_Call
then
8493 (Original_Node
(Node_To_Replace
), Etype
(Node_To_Replace
));
8496 end Complete_Object_Operation
;
8498 ----------------------
8499 -- Report_Ambiguity --
8500 ----------------------
8502 procedure Report_Ambiguity
(Op
: Entity_Id
) is
8503 Access_Actual
: constant Boolean :=
8504 Is_Access_Type
(Etype
(Prefix
(N
)));
8505 Access_Formal
: Boolean := False;
8508 Error_Msg_Sloc
:= Sloc
(Op
);
8510 if Present
(First_Formal
(Op
)) then
8511 Access_Formal
:= Is_Access_Type
(Etype
(First_Formal
(Op
)));
8514 if Access_Formal
and then not Access_Actual
then
8515 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
8517 ("\possible interpretation "
8518 & "(inherited, with implicit 'Access) #", N
);
8521 ("\possible interpretation (with implicit 'Access) #", N
);
8524 elsif not Access_Formal
and then Access_Actual
then
8525 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
8527 ("\possible interpretation "
8528 & "(inherited, with implicit dereference) #", N
);
8531 ("\possible interpretation (with implicit dereference) #", N
);
8535 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
8536 Error_Msg_N
("\possible interpretation (inherited)#", N
);
8538 Error_Msg_N
-- CODEFIX
8539 ("\possible interpretation#", N
);
8542 end Report_Ambiguity
;
8544 --------------------------------
8545 -- Transform_Object_Operation --
8546 --------------------------------
8548 procedure Transform_Object_Operation
8549 (Call_Node
: out Node_Id
;
8550 Node_To_Replace
: out Node_Id
)
8552 Dummy
: constant Node_Id
:= New_Copy
(Obj
);
8553 -- Placeholder used as a first parameter in the call, replaced
8554 -- eventually by the proper object.
8556 Parent_Node
: constant Node_Id
:= Parent
(N
);
8562 -- Common case covering 1) Call to a procedure and 2) Call to a
8563 -- function that has some additional actuals.
8565 if Nkind
(Parent_Node
) in N_Subprogram_Call
8567 -- N is a selected component node containing the name of the
8568 -- subprogram. If N is not the name of the parent node we must
8569 -- not replace the parent node by the new construct. This case
8570 -- occurs when N is a parameterless call to a subprogram that
8571 -- is an actual parameter of a call to another subprogram. For
8573 -- Some_Subprogram (..., Obj.Operation, ...)
8575 and then Name
(Parent_Node
) = N
8577 Node_To_Replace
:= Parent_Node
;
8579 Actuals
:= Parameter_Associations
(Parent_Node
);
8581 if Present
(Actuals
) then
8582 Prepend
(Dummy
, Actuals
);
8584 Actuals
:= New_List
(Dummy
);
8587 if Nkind
(Parent_Node
) = N_Procedure_Call_Statement
then
8589 Make_Procedure_Call_Statement
(Loc
,
8590 Name
=> New_Copy
(Subprog
),
8591 Parameter_Associations
=> Actuals
);
8595 Make_Function_Call
(Loc
,
8596 Name
=> New_Copy
(Subprog
),
8597 Parameter_Associations
=> Actuals
);
8600 -- Before analysis, a function call appears as an indexed component
8601 -- if there are no named associations.
8603 elsif Nkind
(Parent_Node
) = N_Indexed_Component
8604 and then N
= Prefix
(Parent_Node
)
8606 Node_To_Replace
:= Parent_Node
;
8607 Actuals
:= Expressions
(Parent_Node
);
8609 Actual
:= First
(Actuals
);
8610 while Present
(Actual
) loop
8615 Prepend
(Dummy
, Actuals
);
8618 Make_Function_Call
(Loc
,
8619 Name
=> New_Copy
(Subprog
),
8620 Parameter_Associations
=> Actuals
);
8622 -- Parameterless call: Obj.F is rewritten as F (Obj)
8625 Node_To_Replace
:= N
;
8628 Make_Function_Call
(Loc
,
8629 Name
=> New_Copy
(Subprog
),
8630 Parameter_Associations
=> New_List
(Dummy
));
8632 end Transform_Object_Operation
;
8634 ------------------------------
8635 -- Try_Class_Wide_Operation --
8636 ------------------------------
8638 function Try_Class_Wide_Operation
8639 (Call_Node
: Node_Id
;
8640 Node_To_Replace
: Node_Id
) return Boolean
8642 Anc_Type
: Entity_Id
;
8643 Matching_Op
: Entity_Id
:= Empty
;
8646 procedure Traverse_Homonyms
8647 (Anc_Type
: Entity_Id
;
8648 Error
: out Boolean);
8649 -- Traverse the homonym chain of the subprogram searching for those
8650 -- homonyms whose first formal has the Anc_Type's class-wide type,
8651 -- or an anonymous access type designating the class-wide type. If
8652 -- an ambiguity is detected, then Error is set to True.
8654 procedure Traverse_Interfaces
8655 (Anc_Type
: Entity_Id
;
8656 Error
: out Boolean);
8657 -- Traverse the list of interfaces, if any, associated with Anc_Type
8658 -- and search for acceptable class-wide homonyms associated with each
8659 -- interface. If an ambiguity is detected, then Error is set to True.
8661 -----------------------
8662 -- Traverse_Homonyms --
8663 -----------------------
8665 procedure Traverse_Homonyms
8666 (Anc_Type
: Entity_Id
;
8667 Error
: out Boolean)
8669 Cls_Type
: Entity_Id
;
8677 Cls_Type
:= Class_Wide_Type
(Anc_Type
);
8679 Hom
:= Current_Entity
(Subprog
);
8681 -- Find a non-hidden operation whose first parameter is of the
8682 -- class-wide type, a subtype thereof, or an anonymous access
8683 -- to same. If in an instance, the operation can be considered
8684 -- even if hidden (it may be hidden because the instantiation
8685 -- is expanded after the containing package has been analyzed).
8687 while Present
(Hom
) loop
8688 if Ekind_In
(Hom
, E_Procedure
, E_Function
)
8689 and then (not Is_Hidden
(Hom
) or else In_Instance
)
8690 and then Scope
(Hom
) = Scope
(Anc_Type
)
8691 and then Present
(First_Formal
(Hom
))
8693 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
8695 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
8697 Ekind
(Etype
(First_Formal
(Hom
))) =
8698 E_Anonymous_Access_Type
8701 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
8704 -- If the context is a procedure call, ignore functions
8705 -- in the name of the call.
8707 if Ekind
(Hom
) = E_Function
8708 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
8709 and then N
= Name
(Parent
(N
))
8713 -- If the context is a function call, ignore procedures
8714 -- in the name of the call.
8716 elsif Ekind
(Hom
) = E_Procedure
8717 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
8722 Set_Etype
(Call_Node
, Any_Type
);
8723 Set_Is_Overloaded
(Call_Node
, False);
8726 if No
(Matching_Op
) then
8727 Hom_Ref
:= New_Occurrence_Of
(Hom
, Sloc
(Subprog
));
8728 Set_Etype
(Call_Node
, Any_Type
);
8729 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
8731 Set_Name
(Call_Node
, Hom_Ref
);
8736 Report
=> Report_Error
,
8738 Skip_First
=> True);
8741 Valid_Candidate
(Success
, Call_Node
, Hom
);
8747 Report
=> Report_Error
,
8749 Skip_First
=> True);
8751 if Present
(Valid_Candidate
(Success
, Call_Node
, Hom
))
8752 and then Nkind
(Call_Node
) /= N_Function_Call
8754 Error_Msg_NE
("ambiguous call to&", N
, Hom
);
8755 Report_Ambiguity
(Matching_Op
);
8756 Report_Ambiguity
(Hom
);
8764 Hom
:= Homonym
(Hom
);
8766 end Traverse_Homonyms
;
8768 -------------------------
8769 -- Traverse_Interfaces --
8770 -------------------------
8772 procedure Traverse_Interfaces
8773 (Anc_Type
: Entity_Id
;
8774 Error
: out Boolean)
8776 Intface_List
: constant List_Id
:=
8777 Abstract_Interface_List
(Anc_Type
);
8783 if Is_Non_Empty_List
(Intface_List
) then
8784 Intface
:= First
(Intface_List
);
8785 while Present
(Intface
) loop
8787 -- Look for acceptable class-wide homonyms associated with
8790 Traverse_Homonyms
(Etype
(Intface
), Error
);
8796 -- Continue the search by looking at each of the interface's
8797 -- associated interface ancestors.
8799 Traverse_Interfaces
(Etype
(Intface
), Error
);
8808 end Traverse_Interfaces
;
8810 -- Start of processing for Try_Class_Wide_Operation
8813 -- If we are searching only for conflicting class-wide subprograms
8814 -- then initialize directly Matching_Op with the target entity.
8816 if CW_Test_Only
then
8817 Matching_Op
:= Entity
(Selector_Name
(N
));
8820 -- Loop through ancestor types (including interfaces), traversing
8821 -- the homonym chain of the subprogram, trying out those homonyms
8822 -- whose first formal has the class-wide type of the ancestor, or
8823 -- an anonymous access type designating the class-wide type.
8825 Anc_Type
:= Obj_Type
;
8827 -- Look for a match among homonyms associated with the ancestor
8829 Traverse_Homonyms
(Anc_Type
, Error
);
8835 -- Continue the search for matches among homonyms associated with
8836 -- any interfaces implemented by the ancestor.
8838 Traverse_Interfaces
(Anc_Type
, Error
);
8844 exit when Etype
(Anc_Type
) = Anc_Type
;
8845 Anc_Type
:= Etype
(Anc_Type
);
8848 if Present
(Matching_Op
) then
8849 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
8852 return Present
(Matching_Op
);
8853 end Try_Class_Wide_Operation
;
8855 -----------------------------------
8856 -- Try_One_Prefix_Interpretation --
8857 -----------------------------------
8859 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
) is
8861 -- If the interpretation does not have a valid candidate type,
8862 -- preserve current value of Obj_Type for subsequent errors.
8864 Prev_Obj_Type
: constant Entity_Id
:= Obj_Type
;
8869 if Is_Access_Type
(Obj_Type
) then
8870 Obj_Type
:= Designated_Type
(Obj_Type
);
8873 if Ekind
(Obj_Type
) = E_Private_Subtype
then
8874 Obj_Type
:= Base_Type
(Obj_Type
);
8877 if Is_Class_Wide_Type
(Obj_Type
) then
8878 Obj_Type
:= Etype
(Class_Wide_Type
(Obj_Type
));
8881 -- The type may have be obtained through a limited_with clause,
8882 -- in which case the primitive operations are available on its
8883 -- non-limited view. If still incomplete, retrieve full view.
8885 if Ekind
(Obj_Type
) = E_Incomplete_Type
8886 and then From_Limited_With
(Obj_Type
)
8887 and then Has_Non_Limited_View
(Obj_Type
)
8889 Obj_Type
:= Get_Full_View
(Non_Limited_View
(Obj_Type
));
8892 -- If the object is not tagged, or the type is still an incomplete
8893 -- type, this is not a prefixed call.
8895 if not Is_Tagged_Type
(Obj_Type
)
8896 or else Is_Incomplete_Type
(Obj_Type
)
8899 -- Restore previous type if current one is not legal candidate
8901 Obj_Type
:= Prev_Obj_Type
;
8906 Dup_Call_Node
: constant Node_Id
:= New_Copy
(New_Call_Node
);
8907 CW_Result
: Boolean;
8908 Prim_Result
: Boolean;
8909 pragma Unreferenced
(CW_Result
);
8912 if not CW_Test_Only
then
8914 Try_Primitive_Operation
8915 (Call_Node
=> New_Call_Node
,
8916 Node_To_Replace
=> Node_To_Replace
);
8919 -- Check if there is a class-wide subprogram covering the
8920 -- primitive. This check must be done even if a candidate
8921 -- was found in order to report ambiguous calls.
8923 if not (Prim_Result
) then
8925 Try_Class_Wide_Operation
8926 (Call_Node
=> New_Call_Node
,
8927 Node_To_Replace
=> Node_To_Replace
);
8929 -- If we found a primitive we search for class-wide subprograms
8930 -- using a duplicate of the call node (done to avoid missing its
8931 -- decoration if there is no ambiguity).
8935 Try_Class_Wide_Operation
8936 (Call_Node
=> Dup_Call_Node
,
8937 Node_To_Replace
=> Node_To_Replace
);
8940 end Try_One_Prefix_Interpretation
;
8942 -----------------------------
8943 -- Try_Primitive_Operation --
8944 -----------------------------
8946 function Try_Primitive_Operation
8947 (Call_Node
: Node_Id
;
8948 Node_To_Replace
: Node_Id
) return Boolean
8951 Prim_Op
: Entity_Id
;
8952 Matching_Op
: Entity_Id
:= Empty
;
8953 Prim_Op_Ref
: Node_Id
:= Empty
;
8955 Corr_Type
: Entity_Id
:= Empty
;
8956 -- If the prefix is a synchronized type, the controlling type of
8957 -- the primitive operation is the corresponding record type, else
8958 -- this is the object type itself.
8960 Success
: Boolean := False;
8962 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
;
8963 -- For tagged types the candidate interpretations are found in
8964 -- the list of primitive operations of the type and its ancestors.
8965 -- For formal tagged types we have to find the operations declared
8966 -- in the same scope as the type (including in the generic formal
8967 -- part) because the type itself carries no primitive operations,
8968 -- except for formal derived types that inherit the operations of
8969 -- the parent and progenitors.
8971 -- If the context is a generic subprogram body, the generic formals
8972 -- are visible by name, but are not in the entity list of the
8973 -- subprogram because that list starts with the subprogram formals.
8974 -- We retrieve the candidate operations from the generic declaration.
8976 function Extended_Primitive_Ops
(T
: Entity_Id
) return Elist_Id
;
8977 -- Prefix notation can also be used on operations that are not
8978 -- primitives of the type, but are declared in the same immediate
8979 -- declarative part, which can only mean the corresponding package
8980 -- body (See RM 4.1.3 (9.2/3)). If we are in that body we extend the
8981 -- list of primitives with body operations with the same name that
8982 -- may be candidates, so that Try_Primitive_Operations can examine
8983 -- them if no real primitive is found.
8985 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean;
8986 -- An operation that overrides an inherited operation in the private
8987 -- part of its package may be hidden, but if the inherited operation
8988 -- is visible a direct call to it will dispatch to the private one,
8989 -- which is therefore a valid candidate.
8991 function Names_Match
8992 (Obj_Type
: Entity_Id
;
8993 Prim_Op
: Entity_Id
;
8994 Subprog
: Entity_Id
) return Boolean;
8995 -- Return True if the names of Prim_Op and Subprog match. If Obj_Type
8996 -- is a protected type then compare also the original name of Prim_Op
8997 -- with the name of Subprog (since the expander may have added a
8998 -- prefix to its original name --see Exp_Ch9.Build_Selected_Name).
9000 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean;
9001 -- Verify that the prefix, dereferenced if need be, is a valid
9002 -- controlling argument in a call to Op. The remaining actuals
9003 -- are checked in the subsequent call to Analyze_One_Call.
9005 ------------------------------
9006 -- Collect_Generic_Type_Ops --
9007 ------------------------------
9009 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
is
9010 Bas
: constant Entity_Id
:= Base_Type
(T
);
9011 Candidates
: constant Elist_Id
:= New_Elmt_List
;
9015 procedure Check_Candidate
;
9016 -- The operation is a candidate if its first parameter is a
9017 -- controlling operand of the desired type.
9019 -----------------------
9020 -- Check_Candidate; --
9021 -----------------------
9023 procedure Check_Candidate
is
9025 Formal
:= First_Formal
(Subp
);
9028 and then Is_Controlling_Formal
(Formal
)
9030 (Base_Type
(Etype
(Formal
)) = Bas
9032 (Is_Access_Type
(Etype
(Formal
))
9033 and then Designated_Type
(Etype
(Formal
)) = Bas
))
9035 Append_Elmt
(Subp
, Candidates
);
9037 end Check_Candidate
;
9039 -- Start of processing for Collect_Generic_Type_Ops
9042 if Is_Derived_Type
(T
) then
9043 return Primitive_Operations
(T
);
9045 elsif Ekind_In
(Scope
(T
), E_Procedure
, E_Function
) then
9047 -- Scan the list of generic formals to find subprograms
9048 -- that may have a first controlling formal of the type.
9050 if Nkind
(Unit_Declaration_Node
(Scope
(T
))) =
9051 N_Generic_Subprogram_Declaration
9058 First
(Generic_Formal_Declarations
9059 (Unit_Declaration_Node
(Scope
(T
))));
9060 while Present
(Decl
) loop
9061 if Nkind
(Decl
) in N_Formal_Subprogram_Declaration
then
9062 Subp
:= Defining_Entity
(Decl
);
9073 -- Scan the list of entities declared in the same scope as
9074 -- the type. In general this will be an open scope, given that
9075 -- the call we are analyzing can only appear within a generic
9076 -- declaration or body (either the one that declares T, or a
9079 -- For a subtype representing a generic actual type, go to the
9082 if Is_Generic_Actual_Type
(T
) then
9083 Subp
:= First_Entity
(Scope
(Base_Type
(T
)));
9085 Subp
:= First_Entity
(Scope
(T
));
9088 while Present
(Subp
) loop
9089 if Is_Overloadable
(Subp
) then
9098 end Collect_Generic_Type_Ops
;
9100 ----------------------------
9101 -- Extended_Primitive_Ops --
9102 ----------------------------
9104 function Extended_Primitive_Ops
(T
: Entity_Id
) return Elist_Id
is
9105 Type_Scope
: constant Entity_Id
:= Scope
(T
);
9107 Body_Decls
: List_Id
;
9113 Op_List
:= Primitive_Operations
(T
);
9115 if Ekind
(Type_Scope
) = E_Package
9116 and then In_Package_Body
(Type_Scope
)
9117 and then In_Open_Scopes
(Type_Scope
)
9119 -- Retrieve list of declarations of package body.
9123 (Unit_Declaration_Node
9125 (Unit_Declaration_Node
(Type_Scope
))));
9127 Op
:= Current_Entity
(Subprog
);
9129 while Present
(Op
) loop
9130 if Comes_From_Source
(Op
)
9131 and then Is_Overloadable
(Op
)
9133 -- Exclude overriding primitive operations of a type
9134 -- extension declared in the package body, to prevent
9135 -- duplicates in extended list.
9137 and then not Is_Primitive
(Op
)
9138 and then Is_List_Member
(Unit_Declaration_Node
(Op
))
9139 and then List_Containing
(Unit_Declaration_Node
(Op
)) =
9142 if not Op_Found
then
9144 -- Copy list of primitives so it is not affected for
9147 Op_List
:= New_Copy_Elist
(Op_List
);
9151 Append_Elmt
(Op
, Op_List
);
9159 end Extended_Primitive_Ops
;
9161 ---------------------------
9162 -- Is_Private_Overriding --
9163 ---------------------------
9165 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean is
9166 Visible_Op
: constant Entity_Id
:= Homonym
(Op
);
9169 return Present
(Visible_Op
)
9170 and then Scope
(Op
) = Scope
(Visible_Op
)
9171 and then not Comes_From_Source
(Visible_Op
)
9172 and then Alias
(Visible_Op
) = Op
9173 and then not Is_Hidden
(Visible_Op
);
9174 end Is_Private_Overriding
;
9180 function Names_Match
9181 (Obj_Type
: Entity_Id
;
9182 Prim_Op
: Entity_Id
;
9183 Subprog
: Entity_Id
) return Boolean is
9185 -- Common case: exact match
9187 if Chars
(Prim_Op
) = Chars
(Subprog
) then
9190 -- For protected type primitives the expander may have built the
9191 -- name of the dispatching primitive prepending the type name to
9192 -- avoid conflicts with the name of the protected subprogram (see
9193 -- Exp_Ch9.Build_Selected_Name).
9195 elsif Is_Protected_Type
(Obj_Type
) then
9197 Present
(Original_Protected_Subprogram
(Prim_Op
))
9198 and then Chars
(Original_Protected_Subprogram
(Prim_Op
)) =
9205 -----------------------------
9206 -- Valid_First_Argument_Of --
9207 -----------------------------
9209 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean is
9210 Typ
: Entity_Id
:= Etype
(First_Formal
(Op
));
9213 if Is_Concurrent_Type
(Typ
)
9214 and then Present
(Corresponding_Record_Type
(Typ
))
9216 Typ
:= Corresponding_Record_Type
(Typ
);
9219 -- Simple case. Object may be a subtype of the tagged type or
9220 -- may be the corresponding record of a synchronized type.
9222 return Obj_Type
= Typ
9223 or else Base_Type
(Obj_Type
) = Typ
9224 or else Corr_Type
= Typ
9226 -- Prefix can be dereferenced
9229 (Is_Access_Type
(Corr_Type
)
9230 and then Designated_Type
(Corr_Type
) = Typ
)
9232 -- Formal is an access parameter, for which the object
9233 -- can provide an access.
9236 (Ekind
(Typ
) = E_Anonymous_Access_Type
9238 Base_Type
(Designated_Type
(Typ
)) = Base_Type
(Corr_Type
));
9239 end Valid_First_Argument_Of
;
9241 -- Start of processing for Try_Primitive_Operation
9244 -- Look for subprograms in the list of primitive operations. The name
9245 -- must be identical, and the kind of call indicates the expected
9246 -- kind of operation (function or procedure). If the type is a
9247 -- (tagged) synchronized type, the primitive ops are attached to the
9248 -- corresponding record (base) type.
9250 if Is_Concurrent_Type
(Obj_Type
) then
9251 if Present
(Corresponding_Record_Type
(Obj_Type
)) then
9252 Corr_Type
:= Base_Type
(Corresponding_Record_Type
(Obj_Type
));
9253 Elmt
:= First_Elmt
(Primitive_Operations
(Corr_Type
));
9255 Corr_Type
:= Obj_Type
;
9256 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
9259 elsif not Is_Generic_Type
(Obj_Type
) then
9260 Corr_Type
:= Obj_Type
;
9261 Elmt
:= First_Elmt
(Extended_Primitive_Ops
(Obj_Type
));
9264 Corr_Type
:= Obj_Type
;
9265 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
9268 while Present
(Elmt
) loop
9269 Prim_Op
:= Node
(Elmt
);
9271 if Names_Match
(Obj_Type
, Prim_Op
, Subprog
)
9272 and then Present
(First_Formal
(Prim_Op
))
9273 and then Valid_First_Argument_Of
(Prim_Op
)
9275 (Nkind
(Call_Node
) = N_Function_Call
)
9277 (Ekind
(Prim_Op
) = E_Function
)
9279 -- Ada 2005 (AI-251): If this primitive operation corresponds
9280 -- to an immediate ancestor interface there is no need to add
9281 -- it to the list of interpretations; the corresponding aliased
9282 -- primitive is also in this list of primitive operations and
9283 -- will be used instead.
9285 if (Present
(Interface_Alias
(Prim_Op
))
9286 and then Is_Ancestor
(Find_Dispatching_Type
9287 (Alias
(Prim_Op
)), Corr_Type
))
9289 -- Do not consider hidden primitives unless the type is in an
9290 -- open scope or we are within an instance, where visibility
9291 -- is known to be correct, or else if this is an overriding
9292 -- operation in the private part for an inherited operation.
9294 or else (Is_Hidden
(Prim_Op
)
9295 and then not Is_Immediately_Visible
(Obj_Type
)
9296 and then not In_Instance
9297 and then not Is_Private_Overriding
(Prim_Op
))
9302 Set_Etype
(Call_Node
, Any_Type
);
9303 Set_Is_Overloaded
(Call_Node
, False);
9305 if No
(Matching_Op
) then
9306 Prim_Op_Ref
:= New_Occurrence_Of
(Prim_Op
, Sloc
(Subprog
));
9307 Candidate
:= Prim_Op
;
9309 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
9311 Set_Name
(Call_Node
, Prim_Op_Ref
);
9317 Report
=> Report_Error
,
9319 Skip_First
=> True);
9321 Matching_Op
:= Valid_Candidate
(Success
, Call_Node
, Prim_Op
);
9323 -- More than one interpretation, collect for subsequent
9324 -- disambiguation. If this is a procedure call and there
9325 -- is another match, report ambiguity now.
9331 Report
=> Report_Error
,
9333 Skip_First
=> True);
9335 if Present
(Valid_Candidate
(Success
, Call_Node
, Prim_Op
))
9336 and then Nkind
(Call_Node
) /= N_Function_Call
9338 Error_Msg_NE
("ambiguous call to&", N
, Prim_Op
);
9339 Report_Ambiguity
(Matching_Op
);
9340 Report_Ambiguity
(Prim_Op
);
9350 if Present
(Matching_Op
) then
9351 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
9354 return Present
(Matching_Op
);
9355 end Try_Primitive_Operation
;
9357 -- Start of processing for Try_Object_Operation
9360 Analyze_Expression
(Obj
);
9362 -- Analyze the actuals if node is known to be a subprogram call
9364 if Is_Subprg_Call
and then N
= Name
(Parent
(N
)) then
9365 Actual
:= First
(Parameter_Associations
(Parent
(N
)));
9366 while Present
(Actual
) loop
9367 Analyze_Expression
(Actual
);
9372 -- Build a subprogram call node, using a copy of Obj as its first
9373 -- actual. This is a placeholder, to be replaced by an explicit
9374 -- dereference when needed.
9376 Transform_Object_Operation
9377 (Call_Node
=> New_Call_Node
,
9378 Node_To_Replace
=> Node_To_Replace
);
9380 Set_Etype
(New_Call_Node
, Any_Type
);
9381 Set_Etype
(Subprog
, Any_Type
);
9382 Set_Parent
(New_Call_Node
, Parent
(Node_To_Replace
));
9384 if not Is_Overloaded
(Obj
) then
9385 Try_One_Prefix_Interpretation
(Obj_Type
);
9392 Get_First_Interp
(Obj
, I
, It
);
9393 while Present
(It
.Nam
) loop
9394 Try_One_Prefix_Interpretation
(It
.Typ
);
9395 Get_Next_Interp
(I
, It
);
9400 if Etype
(New_Call_Node
) /= Any_Type
then
9402 -- No need to complete the tree transformations if we are only
9403 -- searching for conflicting class-wide subprograms
9405 if CW_Test_Only
then
9408 Complete_Object_Operation
9409 (Call_Node
=> New_Call_Node
,
9410 Node_To_Replace
=> Node_To_Replace
);
9414 elsif Present
(Candidate
) then
9416 -- The argument list is not type correct. Re-analyze with error
9417 -- reporting enabled, and use one of the possible candidates.
9418 -- In All_Errors_Mode, re-analyze all failed interpretations.
9420 if All_Errors_Mode
then
9421 Report_Error
:= True;
9422 if Try_Primitive_Operation
9423 (Call_Node
=> New_Call_Node
,
9424 Node_To_Replace
=> Node_To_Replace
)
9427 Try_Class_Wide_Operation
9428 (Call_Node
=> New_Call_Node
,
9429 Node_To_Replace
=> Node_To_Replace
)
9436 (N
=> New_Call_Node
,
9440 Skip_First
=> True);
9443 -- No need for further errors
9448 -- There was no candidate operation, so report it as an error
9449 -- in the caller: Analyze_Selected_Component.
9453 end Try_Object_Operation
;
9459 procedure wpo
(T
: Entity_Id
) is
9464 if not Is_Tagged_Type
(T
) then
9468 E
:= First_Elmt
(Primitive_Operations
(Base_Type
(T
)));
9469 while Present
(E
) loop
9471 Write_Int
(Int
(Op
));
9472 Write_Str
(" === ");
9473 Write_Name
(Chars
(Op
));
9475 Write_Name
(Chars
(Scope
(Op
)));