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 -- If the No_Streams restriction is set, check that the type of the
816 -- object is not, and does not contain, any subtype derived from
817 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
818 -- Has_Stream just for efficiency reasons. There is no point in
819 -- spending time on a Has_Stream check if the restriction is not set.
821 if Restriction_Check_Required
(No_Streams
) then
822 if Has_Stream
(Designated_Type
(Acc_Type
)) then
823 Check_Restriction
(No_Streams
, N
);
827 Set_Etype
(N
, Acc_Type
);
829 if not Is_Library_Level_Entity
(Acc_Type
) then
830 Check_Restriction
(No_Local_Allocators
, N
);
833 if Serious_Errors_Detected
> Sav_Errs
then
834 Set_Error_Posted
(N
);
835 Set_Etype
(N
, Any_Type
);
837 end Analyze_Allocator
;
839 ---------------------------
840 -- Analyze_Arithmetic_Op --
841 ---------------------------
843 procedure Analyze_Arithmetic_Op
(N
: Node_Id
) is
844 L
: constant Node_Id
:= Left_Opnd
(N
);
845 R
: constant Node_Id
:= Right_Opnd
(N
);
849 Candidate_Type
:= Empty
;
850 Analyze_Expression
(L
);
851 Analyze_Expression
(R
);
853 -- If the entity is already set, the node is the instantiation of a
854 -- generic node with a non-local reference, or was manufactured by a
855 -- call to Make_Op_xxx. In either case the entity is known to be valid,
856 -- and we do not need to collect interpretations, instead we just get
857 -- the single possible interpretation.
861 if Present
(Op_Id
) then
862 if Ekind
(Op_Id
) = E_Operator
then
864 if Nkind_In
(N
, N_Op_Divide
, N_Op_Mod
, N_Op_Multiply
, N_Op_Rem
)
865 and then Treat_Fixed_As_Integer
(N
)
869 Set_Etype
(N
, Any_Type
);
870 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
874 Set_Etype
(N
, Any_Type
);
875 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
878 -- Entity is not already set, so we do need to collect interpretations
881 Set_Etype
(N
, Any_Type
);
883 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
884 while Present
(Op_Id
) loop
885 if Ekind
(Op_Id
) = E_Operator
886 and then Present
(Next_Entity
(First_Entity
(Op_Id
)))
888 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
890 -- The following may seem superfluous, because an operator cannot
891 -- be generic, but this ignores the cleverness of the author of
894 elsif Is_Overloadable
(Op_Id
) then
895 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
898 Op_Id
:= Homonym
(Op_Id
);
903 Check_Function_Writable_Actuals
(N
);
904 end Analyze_Arithmetic_Op
;
910 -- Function, procedure, and entry calls are checked here. The Name in
911 -- the call may be overloaded. The actuals have been analyzed and may
912 -- themselves be overloaded. On exit from this procedure, the node N
913 -- may have zero, one or more interpretations. In the first case an
914 -- error message is produced. In the last case, the node is flagged
915 -- as overloaded and the interpretations are collected in All_Interp.
917 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
918 -- the type-checking is similar to that of other calls.
920 procedure Analyze_Call
(N
: Node_Id
) is
921 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
926 Success
: Boolean := False;
928 Deref
: Boolean := False;
929 -- Flag indicates whether an interpretation of the prefix is a
930 -- parameterless call that returns an access_to_subprogram.
932 procedure Check_Mixed_Parameter_And_Named_Associations
;
933 -- Check that parameter and named associations are not mixed. This is
934 -- a restriction in SPARK mode.
936 procedure Check_Writable_Actuals
(N
: Node_Id
);
937 -- If the call has out or in-out parameters then mark its outermost
938 -- enclosing construct as a node on which the writable actuals check
939 -- must be performed.
941 function Name_Denotes_Function
return Boolean;
942 -- If the type of the name is an access to subprogram, this may be the
943 -- type of a name, or the return type of the function being called. If
944 -- the name is not an entity then it can denote a protected function.
945 -- Until we distinguish Etype from Return_Type, we must use this routine
946 -- to resolve the meaning of the name in the call.
948 procedure No_Interpretation
;
949 -- Output error message when no valid interpretation exists
951 --------------------------------------------------
952 -- Check_Mixed_Parameter_And_Named_Associations --
953 --------------------------------------------------
955 procedure Check_Mixed_Parameter_And_Named_Associations
is
957 Named_Seen
: Boolean;
962 Actual
:= First
(Actuals
);
963 while Present
(Actual
) loop
964 case Nkind
(Actual
) is
965 when N_Parameter_Association
=>
967 Check_SPARK_05_Restriction
968 ("named association cannot follow positional one",
979 end Check_Mixed_Parameter_And_Named_Associations
;
981 ----------------------------
982 -- Check_Writable_Actuals --
983 ----------------------------
985 -- The identification of conflicts in calls to functions with writable
986 -- actuals is performed in the analysis phase of the front end to ensure
987 -- that it reports exactly the same errors compiling with and without
988 -- expansion enabled. It is performed in two stages:
990 -- 1) When a call to a function with out-mode parameters is found,
991 -- we climb to the outermost enclosing construct that can be
992 -- evaluated in arbitrary order and we mark it with the flag
995 -- 2) When the analysis of the marked node is complete, we traverse
996 -- its decorated subtree searching for conflicts (see function
997 -- Sem_Util.Check_Function_Writable_Actuals).
999 -- The unique exception to this general rule is for aggregates, since
1000 -- their analysis is performed by the front end in the resolution
1001 -- phase. For aggregates we do not climb to their enclosing construct:
1002 -- we restrict the analysis to the subexpressions initializing the
1003 -- aggregate components.
1005 -- This implies that the analysis of expressions containing aggregates
1006 -- is not complete, since there may be conflicts on writable actuals
1007 -- involving subexpressions of the enclosing logical or arithmetic
1008 -- expressions. However, we cannot wait and perform the analysis when
1009 -- the whole subtree is resolved, since the subtrees may be transformed,
1010 -- thus adding extra complexity and computation cost to identify and
1011 -- report exactly the same errors compiling with and without expansion
1014 procedure Check_Writable_Actuals
(N
: Node_Id
) is
1016 if Comes_From_Source
(N
)
1017 and then Present
(Get_Subprogram_Entity
(N
))
1018 and then Has_Out_Or_In_Out_Parameter
(Get_Subprogram_Entity
(N
))
1020 -- For procedures and entries there is no need to climb since
1021 -- we only need to check if the actuals of this call invoke
1022 -- functions whose out-mode parameters overlap.
1024 if Nkind
(N
) /= N_Function_Call
then
1025 Set_Check_Actuals
(N
);
1027 -- For calls to functions we climb to the outermost enclosing
1028 -- construct where the out-mode actuals of this function may
1029 -- introduce conflicts.
1033 Outermost
: Node_Id
;
1037 while Present
(P
) loop
1039 -- For object declarations we can climb to the node from
1040 -- its object definition branch or from its initializing
1041 -- expression. We prefer to mark the child node as the
1042 -- outermost construct to avoid adding further complexity
1043 -- to the routine that will later take care of
1044 -- performing the writable actuals check.
1046 if Has_Arbitrary_Evaluation_Order
(Nkind
(P
))
1047 and then not Nkind_In
(P
, N_Assignment_Statement
,
1048 N_Object_Declaration
)
1053 -- Avoid climbing more than needed!
1055 exit when Stop_Subtree_Climbing
(Nkind
(P
))
1056 or else (Nkind
(P
) = N_Range
1058 Nkind_In
(Parent
(P
), N_In
, N_Not_In
));
1063 Set_Check_Actuals
(Outermost
);
1067 end Check_Writable_Actuals
;
1069 ---------------------------
1070 -- Name_Denotes_Function --
1071 ---------------------------
1073 function Name_Denotes_Function
return Boolean is
1075 if Is_Entity_Name
(Nam
) then
1076 return Ekind
(Entity
(Nam
)) = E_Function
;
1077 elsif Nkind
(Nam
) = N_Selected_Component
then
1078 return Ekind
(Entity
(Selector_Name
(Nam
))) = E_Function
;
1082 end Name_Denotes_Function
;
1084 -----------------------
1085 -- No_Interpretation --
1086 -----------------------
1088 procedure No_Interpretation
is
1089 L
: constant Boolean := Is_List_Member
(N
);
1090 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
1093 -- If the node is in a list whose parent is not an expression then it
1094 -- must be an attempted procedure call.
1096 if L
and then K
not in N_Subexpr
then
1097 if Ekind
(Entity
(Nam
)) = E_Generic_Procedure
then
1099 ("must instantiate generic procedure& before call",
1102 Error_Msg_N
("procedure or entry name expected", Nam
);
1105 -- Check for tasking cases where only an entry call will do
1108 and then Nkind_In
(K
, N_Entry_Call_Alternative
,
1109 N_Triggering_Alternative
)
1111 Error_Msg_N
("entry name expected", Nam
);
1113 -- Otherwise give general error message
1116 Error_Msg_N
("invalid prefix in call", Nam
);
1118 end No_Interpretation
;
1120 -- Start of processing for Analyze_Call
1123 if Restriction_Check_Required
(SPARK_05
) then
1124 Check_Mixed_Parameter_And_Named_Associations
;
1127 -- Initialize the type of the result of the call to the error type,
1128 -- which will be reset if the type is successfully resolved.
1130 Set_Etype
(N
, Any_Type
);
1134 if not Is_Overloaded
(Nam
) then
1136 -- Only one interpretation to check
1138 if Ekind
(Etype
(Nam
)) = E_Subprogram_Type
then
1139 Nam_Ent
:= Etype
(Nam
);
1141 -- If the prefix is an access_to_subprogram, this may be an indirect
1142 -- call. This is the case if the name in the call is not an entity
1143 -- name, or if it is a function name in the context of a procedure
1144 -- call. In this latter case, we have a call to a parameterless
1145 -- function that returns a pointer_to_procedure which is the entity
1146 -- being called. Finally, F (X) may be a call to a parameterless
1147 -- function that returns a pointer to a function with parameters.
1148 -- Note that if F returns an access-to-subprogram whose designated
1149 -- type is an array, F (X) cannot be interpreted as an indirect call
1150 -- through the result of the call to F.
1152 elsif Is_Access_Type
(Etype
(Nam
))
1153 and then Ekind
(Designated_Type
(Etype
(Nam
))) = E_Subprogram_Type
1155 (not Name_Denotes_Function
1156 or else Nkind
(N
) = N_Procedure_Call_Statement
1158 (Nkind
(Parent
(N
)) /= N_Explicit_Dereference
1159 and then Is_Entity_Name
(Nam
)
1160 and then No
(First_Formal
(Entity
(Nam
)))
1162 Is_Array_Type
(Etype
(Designated_Type
(Etype
(Nam
))))
1163 and then Present
(Actuals
)))
1165 Nam_Ent
:= Designated_Type
(Etype
(Nam
));
1166 Insert_Explicit_Dereference
(Nam
);
1168 -- Selected component case. Simple entry or protected operation,
1169 -- where the entry name is given by the selector name.
1171 elsif Nkind
(Nam
) = N_Selected_Component
then
1172 Nam_Ent
:= Entity
(Selector_Name
(Nam
));
1174 if not Ekind_In
(Nam_Ent
, E_Entry
,
1179 Error_Msg_N
("name in call is not a callable entity", Nam
);
1180 Set_Etype
(N
, Any_Type
);
1184 -- If the name is an Indexed component, it can be a call to a member
1185 -- of an entry family. The prefix must be a selected component whose
1186 -- selector is the entry. Analyze_Procedure_Call normalizes several
1187 -- kinds of call into this form.
1189 elsif Nkind
(Nam
) = N_Indexed_Component
then
1190 if Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
1191 Nam_Ent
:= Entity
(Selector_Name
(Prefix
(Nam
)));
1193 Error_Msg_N
("name in call is not a callable entity", Nam
);
1194 Set_Etype
(N
, Any_Type
);
1198 elsif not Is_Entity_Name
(Nam
) then
1199 Error_Msg_N
("name in call is not a callable entity", Nam
);
1200 Set_Etype
(N
, Any_Type
);
1204 Nam_Ent
:= Entity
(Nam
);
1206 -- If not overloadable, this may be a generalized indexing
1207 -- operation with named associations. Rewrite again as an
1208 -- indexed component and analyze as container indexing.
1210 if not Is_Overloadable
(Nam_Ent
) then
1212 (Find_Value_Of_Aspect
1213 (Etype
(Nam_Ent
), Aspect_Constant_Indexing
))
1216 Make_Indexed_Component
(Sloc
(N
),
1218 Expressions
=> Parameter_Associations
(N
)));
1220 if Try_Container_Indexing
(N
, Nam
, Expressions
(N
)) then
1234 -- Operations generated for RACW stub types are called only through
1235 -- dispatching, and can never be the static interpretation of a call.
1237 if Is_RACW_Stub_Type_Operation
(Nam_Ent
) then
1242 Analyze_One_Call
(N
, Nam_Ent
, True, Success
);
1244 -- If this is an indirect call, the return type of the access_to
1245 -- subprogram may be an incomplete type. At the point of the call,
1246 -- use the full type if available, and at the same time update the
1247 -- return type of the access_to_subprogram.
1250 and then Nkind
(Nam
) = N_Explicit_Dereference
1251 and then Ekind
(Etype
(N
)) = E_Incomplete_Type
1252 and then Present
(Full_View
(Etype
(N
)))
1254 Set_Etype
(N
, Full_View
(Etype
(N
)));
1255 Set_Etype
(Nam_Ent
, Etype
(N
));
1261 -- An overloaded selected component must denote overloaded operations
1262 -- of a concurrent type. The interpretations are attached to the
1263 -- simple name of those operations.
1265 if Nkind
(Nam
) = N_Selected_Component
then
1266 Nam
:= Selector_Name
(Nam
);
1269 Get_First_Interp
(Nam
, X
, It
);
1270 while Present
(It
.Nam
) loop
1274 -- Name may be call that returns an access to subprogram, or more
1275 -- generally an overloaded expression one of whose interpretations
1276 -- yields an access to subprogram. If the name is an entity, we do
1277 -- not dereference, because the node is a call that returns the
1278 -- access type: note difference between f(x), where the call may
1279 -- return an access subprogram type, and f(x)(y), where the type
1280 -- returned by the call to f is implicitly dereferenced to analyze
1283 if Is_Access_Type
(Nam_Ent
) then
1284 Nam_Ent
:= Designated_Type
(Nam_Ent
);
1286 elsif Is_Access_Type
(Etype
(Nam_Ent
))
1288 (not Is_Entity_Name
(Nam
)
1289 or else Nkind
(N
) = N_Procedure_Call_Statement
)
1290 and then Ekind
(Designated_Type
(Etype
(Nam_Ent
)))
1293 Nam_Ent
:= Designated_Type
(Etype
(Nam_Ent
));
1295 if Is_Entity_Name
(Nam
) then
1300 -- If the call has been rewritten from a prefixed call, the first
1301 -- parameter has been analyzed, but may need a subsequent
1302 -- dereference, so skip its analysis now.
1304 if N
/= Original_Node
(N
)
1305 and then Nkind
(Original_Node
(N
)) = Nkind
(N
)
1306 and then Nkind
(Name
(N
)) /= Nkind
(Name
(Original_Node
(N
)))
1307 and then Present
(Parameter_Associations
(N
))
1308 and then Present
(Etype
(First
(Parameter_Associations
(N
))))
1311 (N
, Nam_Ent
, False, Success
, Skip_First
=> True);
1313 Analyze_One_Call
(N
, Nam_Ent
, False, Success
);
1316 -- If the interpretation succeeds, mark the proper type of the
1317 -- prefix (any valid candidate will do). If not, remove the
1318 -- candidate interpretation. This only needs to be done for
1319 -- overloaded protected operations, for other entities disambi-
1320 -- guation is done directly in Resolve.
1324 and then Nkind
(Parent
(N
)) /= N_Explicit_Dereference
1326 Set_Entity
(Nam
, It
.Nam
);
1327 Insert_Explicit_Dereference
(Nam
);
1328 Set_Etype
(Nam
, Nam_Ent
);
1331 Set_Etype
(Nam
, It
.Typ
);
1334 elsif Nkind_In
(Name
(N
), N_Selected_Component
,
1340 Get_Next_Interp
(X
, It
);
1343 -- If the name is the result of a function call, it can only be a
1344 -- call to a function returning an access to subprogram. Insert
1345 -- explicit dereference.
1347 if Nkind
(Nam
) = N_Function_Call
then
1348 Insert_Explicit_Dereference
(Nam
);
1351 if Etype
(N
) = Any_Type
then
1353 -- None of the interpretations is compatible with the actuals
1355 Diagnose_Call
(N
, Nam
);
1357 -- Special checks for uninstantiated put routines
1359 if Nkind
(N
) = N_Procedure_Call_Statement
1360 and then Is_Entity_Name
(Nam
)
1361 and then Chars
(Nam
) = Name_Put
1362 and then List_Length
(Actuals
) = 1
1365 Arg
: constant Node_Id
:= First
(Actuals
);
1369 if Nkind
(Arg
) = N_Parameter_Association
then
1370 Typ
:= Etype
(Explicit_Actual_Parameter
(Arg
));
1375 if Is_Signed_Integer_Type
(Typ
) then
1377 ("possible missing instantiation of "
1378 & "'Text_'I'O.'Integer_'I'O!", Nam
);
1380 elsif Is_Modular_Integer_Type
(Typ
) then
1382 ("possible missing instantiation of "
1383 & "'Text_'I'O.'Modular_'I'O!", Nam
);
1385 elsif Is_Floating_Point_Type
(Typ
) then
1387 ("possible missing instantiation of "
1388 & "'Text_'I'O.'Float_'I'O!", Nam
);
1390 elsif Is_Ordinary_Fixed_Point_Type
(Typ
) then
1392 ("possible missing instantiation of "
1393 & "'Text_'I'O.'Fixed_'I'O!", Nam
);
1395 elsif Is_Decimal_Fixed_Point_Type
(Typ
) then
1397 ("possible missing instantiation of "
1398 & "'Text_'I'O.'Decimal_'I'O!", Nam
);
1400 elsif Is_Enumeration_Type
(Typ
) then
1402 ("possible missing instantiation of "
1403 & "'Text_'I'O.'Enumeration_'I'O!", Nam
);
1408 elsif not Is_Overloaded
(N
)
1409 and then Is_Entity_Name
(Nam
)
1411 -- Resolution yields a single interpretation. Verify that the
1412 -- reference has capitalization consistent with the declaration.
1414 Set_Entity_With_Checks
(Nam
, Entity
(Nam
));
1415 Generate_Reference
(Entity
(Nam
), Nam
);
1417 Set_Etype
(Nam
, Etype
(Entity
(Nam
)));
1419 Remove_Abstract_Operations
(N
);
1425 if Ada_Version
>= Ada_2012
then
1427 -- Check if the call contains a function with writable actuals
1429 Check_Writable_Actuals
(N
);
1431 -- If found and the outermost construct that can be evaluated in
1432 -- an arbitrary order is precisely this call, then check all its
1435 Check_Function_Writable_Actuals
(N
);
1439 -----------------------------
1440 -- Analyze_Case_Expression --
1441 -----------------------------
1443 procedure Analyze_Case_Expression
(N
: Node_Id
) is
1444 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
1445 -- Error routine invoked by the generic instantiation below when
1446 -- the case expression has a non static choice.
1448 package Case_Choices_Analysis
is new
1449 Generic_Analyze_Choices
1450 (Process_Associated_Node
=> No_OP
);
1451 use Case_Choices_Analysis
;
1453 package Case_Choices_Checking
is new
1454 Generic_Check_Choices
1455 (Process_Empty_Choice
=> No_OP
,
1456 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
1457 Process_Associated_Node
=> No_OP
);
1458 use Case_Choices_Checking
;
1460 -----------------------------
1461 -- Non_Static_Choice_Error --
1462 -----------------------------
1464 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
1466 Flag_Non_Static_Expr
1467 ("choice given in case expression is not static!", Choice
);
1468 end Non_Static_Choice_Error
;
1472 Expr
: constant Node_Id
:= Expression
(N
);
1474 Exp_Type
: Entity_Id
;
1475 Exp_Btype
: Entity_Id
;
1477 FirstX
: Node_Id
:= Empty
;
1478 -- First expression in the case for which there is some type information
1479 -- available, i.e. it is not Any_Type, which can happen because of some
1480 -- error, or from the use of e.g. raise Constraint_Error.
1482 Others_Present
: Boolean;
1483 -- Indicates if Others was present
1485 Wrong_Alt
: Node_Id
;
1486 -- For error reporting
1488 -- Start of processing for Analyze_Case_Expression
1491 if Comes_From_Source
(N
) then
1492 Check_Compiler_Unit
("case expression", N
);
1495 Analyze_And_Resolve
(Expr
, Any_Discrete
);
1496 Check_Unset_Reference
(Expr
);
1497 Exp_Type
:= Etype
(Expr
);
1498 Exp_Btype
:= Base_Type
(Exp_Type
);
1500 Alt
:= First
(Alternatives
(N
));
1501 while Present
(Alt
) loop
1502 Analyze
(Expression
(Alt
));
1504 if No
(FirstX
) and then Etype
(Expression
(Alt
)) /= Any_Type
then
1505 FirstX
:= Expression
(Alt
);
1511 -- Get our initial type from the first expression for which we got some
1512 -- useful type information from the expression.
1514 if not Is_Overloaded
(FirstX
) then
1515 Set_Etype
(N
, Etype
(FirstX
));
1523 Set_Etype
(N
, Any_Type
);
1525 Get_First_Interp
(FirstX
, I
, It
);
1526 while Present
(It
.Nam
) loop
1528 -- For each interpretation of the first expression, we only
1529 -- add the interpretation if every other expression in the
1530 -- case expression alternatives has a compatible type.
1532 Alt
:= Next
(First
(Alternatives
(N
)));
1533 while Present
(Alt
) loop
1534 exit when not Has_Compatible_Type
(Expression
(Alt
), It
.Typ
);
1539 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
1544 Get_Next_Interp
(I
, It
);
1549 Exp_Btype
:= Base_Type
(Exp_Type
);
1551 -- The expression must be of a discrete type which must be determinable
1552 -- independently of the context in which the expression occurs, but
1553 -- using the fact that the expression must be of a discrete type.
1554 -- Moreover, the type this expression must not be a character literal
1555 -- (which is always ambiguous).
1557 -- If error already reported by Resolve, nothing more to do
1559 if Exp_Btype
= Any_Discrete
or else Exp_Btype
= Any_Type
then
1562 -- Special casee message for character literal
1564 elsif Exp_Btype
= Any_Character
then
1566 ("character literal as case expression is ambiguous", Expr
);
1570 if Etype
(N
) = Any_Type
and then Present
(Wrong_Alt
) then
1572 ("type incompatible with that of previous alternatives",
1573 Expression
(Wrong_Alt
));
1577 -- If the case expression is a formal object of mode in out, then
1578 -- treat it as having a nonstatic subtype by forcing use of the base
1579 -- type (which has to get passed to Check_Case_Choices below). Also
1580 -- use base type when the case expression is parenthesized.
1582 if Paren_Count
(Expr
) > 0
1583 or else (Is_Entity_Name
(Expr
)
1584 and then Ekind
(Entity
(Expr
)) = E_Generic_In_Out_Parameter
)
1586 Exp_Type
:= Exp_Btype
;
1589 -- The case expression alternatives cover the range of a static subtype
1590 -- subject to aspect Static_Predicate. Do not check the choices when the
1591 -- case expression has not been fully analyzed yet because this may lead
1594 if Is_OK_Static_Subtype
(Exp_Type
)
1595 and then Has_Static_Predicate_Aspect
(Exp_Type
)
1596 and then In_Spec_Expression
1600 -- Call Analyze_Choices and Check_Choices to do the rest of the work
1603 Analyze_Choices
(Alternatives
(N
), Exp_Type
);
1604 Check_Choices
(N
, Alternatives
(N
), Exp_Type
, Others_Present
);
1607 if Exp_Type
= Universal_Integer
and then not Others_Present
then
1609 ("case on universal integer requires OTHERS choice", Expr
);
1611 end Analyze_Case_Expression
;
1613 ---------------------------
1614 -- Analyze_Comparison_Op --
1615 ---------------------------
1617 procedure Analyze_Comparison_Op
(N
: Node_Id
) is
1618 L
: constant Node_Id
:= Left_Opnd
(N
);
1619 R
: constant Node_Id
:= Right_Opnd
(N
);
1620 Op_Id
: Entity_Id
:= Entity
(N
);
1623 Set_Etype
(N
, Any_Type
);
1624 Candidate_Type
:= Empty
;
1626 Analyze_Expression
(L
);
1627 Analyze_Expression
(R
);
1629 if Present
(Op_Id
) then
1630 if Ekind
(Op_Id
) = E_Operator
then
1631 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1633 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1636 if Is_Overloaded
(L
) then
1637 Set_Etype
(L
, Intersect_Types
(L
, R
));
1641 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1642 while Present
(Op_Id
) loop
1643 if Ekind
(Op_Id
) = E_Operator
then
1644 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1646 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1649 Op_Id
:= Homonym
(Op_Id
);
1654 Check_Function_Writable_Actuals
(N
);
1655 end Analyze_Comparison_Op
;
1657 ---------------------------
1658 -- Analyze_Concatenation --
1659 ---------------------------
1661 procedure Analyze_Concatenation
(N
: Node_Id
) is
1663 -- We wish to avoid deep recursion, because concatenations are often
1664 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1665 -- operands nonrecursively until we find something that is not a
1666 -- concatenation (A in this case), or has already been analyzed. We
1667 -- analyze that, and then walk back up the tree following Parent
1668 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1669 -- work at each level. The Parent pointers allow us to avoid recursion,
1670 -- and thus avoid running out of memory.
1676 Candidate_Type
:= Empty
;
1678 -- The following code is equivalent to:
1680 -- Set_Etype (N, Any_Type);
1681 -- Analyze_Expression (Left_Opnd (N));
1682 -- Analyze_Concatenation_Rest (N);
1684 -- where the Analyze_Expression call recurses back here if the left
1685 -- operand is a concatenation.
1687 -- Walk down left operands
1690 Set_Etype
(NN
, Any_Type
);
1691 L
:= Left_Opnd
(NN
);
1692 exit when Nkind
(L
) /= N_Op_Concat
or else Analyzed
(L
);
1696 -- Now (given the above example) NN is A&B and L is A
1698 -- First analyze L ...
1700 Analyze_Expression
(L
);
1702 -- ... then walk NN back up until we reach N (where we started), calling
1703 -- Analyze_Concatenation_Rest along the way.
1706 Analyze_Concatenation_Rest
(NN
);
1710 end Analyze_Concatenation
;
1712 --------------------------------
1713 -- Analyze_Concatenation_Rest --
1714 --------------------------------
1716 -- If the only one-dimensional array type in scope is String,
1717 -- this is the resulting type of the operation. Otherwise there
1718 -- will be a concatenation operation defined for each user-defined
1719 -- one-dimensional array.
1721 procedure Analyze_Concatenation_Rest
(N
: Node_Id
) is
1722 L
: constant Node_Id
:= Left_Opnd
(N
);
1723 R
: constant Node_Id
:= Right_Opnd
(N
);
1724 Op_Id
: Entity_Id
:= Entity
(N
);
1729 Analyze_Expression
(R
);
1731 -- If the entity is present, the node appears in an instance, and
1732 -- denotes a predefined concatenation operation. The resulting type is
1733 -- obtained from the arguments when possible. If the arguments are
1734 -- aggregates, the array type and the concatenation type must be
1737 if Present
(Op_Id
) then
1738 if Ekind
(Op_Id
) = E_Operator
then
1739 LT
:= Base_Type
(Etype
(L
));
1740 RT
:= Base_Type
(Etype
(R
));
1742 if Is_Array_Type
(LT
)
1743 and then (RT
= LT
or else RT
= Base_Type
(Component_Type
(LT
)))
1745 Add_One_Interp
(N
, Op_Id
, LT
);
1747 elsif Is_Array_Type
(RT
)
1748 and then LT
= Base_Type
(Component_Type
(RT
))
1750 Add_One_Interp
(N
, Op_Id
, RT
);
1752 -- If one operand is a string type or a user-defined array type,
1753 -- and the other is a literal, result is of the specific type.
1756 (Root_Type
(LT
) = Standard_String
1757 or else Scope
(LT
) /= Standard_Standard
)
1758 and then Etype
(R
) = Any_String
1760 Add_One_Interp
(N
, Op_Id
, LT
);
1763 (Root_Type
(RT
) = Standard_String
1764 or else Scope
(RT
) /= Standard_Standard
)
1765 and then Etype
(L
) = Any_String
1767 Add_One_Interp
(N
, Op_Id
, RT
);
1769 elsif not Is_Generic_Type
(Etype
(Op_Id
)) then
1770 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1773 -- Type and its operations must be visible
1775 Set_Entity
(N
, Empty
);
1776 Analyze_Concatenation
(N
);
1780 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1784 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Concat
);
1785 while Present
(Op_Id
) loop
1786 if Ekind
(Op_Id
) = E_Operator
then
1788 -- Do not consider operators declared in dead code, they can
1789 -- not be part of the resolution.
1791 if Is_Eliminated
(Op_Id
) then
1794 Find_Concatenation_Types
(L
, R
, Op_Id
, N
);
1798 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1801 Op_Id
:= Homonym
(Op_Id
);
1806 end Analyze_Concatenation_Rest
;
1808 -------------------------
1809 -- Analyze_Equality_Op --
1810 -------------------------
1812 procedure Analyze_Equality_Op
(N
: Node_Id
) is
1813 Loc
: constant Source_Ptr
:= Sloc
(N
);
1814 L
: constant Node_Id
:= Left_Opnd
(N
);
1815 R
: constant Node_Id
:= Right_Opnd
(N
);
1819 Set_Etype
(N
, Any_Type
);
1820 Candidate_Type
:= Empty
;
1822 Analyze_Expression
(L
);
1823 Analyze_Expression
(R
);
1825 -- If the entity is set, the node is a generic instance with a non-local
1826 -- reference to the predefined operator or to a user-defined function.
1827 -- It can also be an inequality that is expanded into the negation of a
1828 -- call to a user-defined equality operator.
1830 -- For the predefined case, the result is Boolean, regardless of the
1831 -- type of the operands. The operands may even be limited, if they are
1832 -- generic actuals. If they are overloaded, label the left argument with
1833 -- the common type that must be present, or with the type of the formal
1834 -- of the user-defined function.
1836 if Present
(Entity
(N
)) then
1837 Op_Id
:= Entity
(N
);
1839 if Ekind
(Op_Id
) = E_Operator
then
1840 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
);
1842 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1845 if Is_Overloaded
(L
) then
1846 if Ekind
(Op_Id
) = E_Operator
then
1847 Set_Etype
(L
, Intersect_Types
(L
, R
));
1849 Set_Etype
(L
, Etype
(First_Formal
(Op_Id
)));
1854 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1855 while Present
(Op_Id
) loop
1856 if Ekind
(Op_Id
) = E_Operator
then
1857 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1859 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1862 Op_Id
:= Homonym
(Op_Id
);
1866 -- If there was no match, and the operator is inequality, this may be
1867 -- a case where inequality has not been made explicit, as for tagged
1868 -- types. Analyze the node as the negation of an equality operation.
1869 -- This cannot be done earlier, because before analysis we cannot rule
1870 -- out the presence of an explicit inequality.
1872 if Etype
(N
) = Any_Type
1873 and then Nkind
(N
) = N_Op_Ne
1875 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Eq
);
1876 while Present
(Op_Id
) loop
1877 if Ekind
(Op_Id
) = E_Operator
then
1878 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1880 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1883 Op_Id
:= Homonym
(Op_Id
);
1886 if Etype
(N
) /= Any_Type
then
1887 Op_Id
:= Entity
(N
);
1893 Left_Opnd
=> Left_Opnd
(N
),
1894 Right_Opnd
=> Right_Opnd
(N
))));
1896 Set_Entity
(Right_Opnd
(N
), Op_Id
);
1902 Check_Function_Writable_Actuals
(N
);
1903 end Analyze_Equality_Op
;
1905 ----------------------------------
1906 -- Analyze_Explicit_Dereference --
1907 ----------------------------------
1909 procedure Analyze_Explicit_Dereference
(N
: Node_Id
) is
1910 Loc
: constant Source_Ptr
:= Sloc
(N
);
1911 P
: constant Node_Id
:= Prefix
(N
);
1917 function Is_Function_Type
return Boolean;
1918 -- Check whether node may be interpreted as an implicit function call
1920 ----------------------
1921 -- Is_Function_Type --
1922 ----------------------
1924 function Is_Function_Type
return Boolean is
1929 if not Is_Overloaded
(N
) then
1930 return Ekind
(Base_Type
(Etype
(N
))) = E_Subprogram_Type
1931 and then Etype
(Base_Type
(Etype
(N
))) /= Standard_Void_Type
;
1934 Get_First_Interp
(N
, I
, It
);
1935 while Present
(It
.Nam
) loop
1936 if Ekind
(Base_Type
(It
.Typ
)) /= E_Subprogram_Type
1937 or else Etype
(Base_Type
(It
.Typ
)) = Standard_Void_Type
1942 Get_Next_Interp
(I
, It
);
1947 end Is_Function_Type
;
1949 -- Start of processing for Analyze_Explicit_Dereference
1952 -- If source node, check SPARK restriction. We guard this with the
1953 -- source node check, because ???
1955 if Comes_From_Source
(N
) then
1956 Check_SPARK_05_Restriction
("explicit dereference is not allowed", N
);
1959 -- In formal verification mode, keep track of all reads and writes
1960 -- through explicit dereferences.
1962 if GNATprove_Mode
then
1963 SPARK_Specific
.Generate_Dereference
(N
);
1967 Set_Etype
(N
, Any_Type
);
1969 -- Test for remote access to subprogram type, and if so return
1970 -- after rewriting the original tree.
1972 if Remote_AST_E_Dereference
(P
) then
1976 -- Normal processing for other than remote access to subprogram type
1978 if not Is_Overloaded
(P
) then
1979 if Is_Access_Type
(Etype
(P
)) then
1981 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
1982 -- avoid other problems caused by the Private_Subtype and it is
1983 -- safe to go to the Base_Type because this is the same as
1984 -- converting the access value to its Base_Type.
1987 DT
: Entity_Id
:= Designated_Type
(Etype
(P
));
1990 if Ekind
(DT
) = E_Private_Subtype
1991 and then Is_For_Access_Subtype
(DT
)
1993 DT
:= Base_Type
(DT
);
1996 -- An explicit dereference is a legal occurrence of an
1997 -- incomplete type imported through a limited_with clause, if
1998 -- the full view is visible, or if we are within an instance
1999 -- body, where the enclosing body has a regular with_clause
2002 if From_Limited_With
(DT
)
2003 and then not From_Limited_With
(Scope
(DT
))
2005 (Is_Immediately_Visible
(Scope
(DT
))
2007 (Is_Child_Unit
(Scope
(DT
))
2008 and then Is_Visible_Lib_Unit
(Scope
(DT
)))
2009 or else In_Instance_Body
)
2011 Set_Etype
(N
, Available_View
(DT
));
2018 elsif Etype
(P
) /= Any_Type
then
2019 Error_Msg_N
("prefix of dereference must be an access type", N
);
2024 Get_First_Interp
(P
, I
, It
);
2025 while Present
(It
.Nam
) loop
2028 if Is_Access_Type
(T
) then
2029 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
2032 Get_Next_Interp
(I
, It
);
2035 -- Error if no interpretation of the prefix has an access type
2037 if Etype
(N
) = Any_Type
then
2039 ("access type required in prefix of explicit dereference", P
);
2040 Set_Etype
(N
, Any_Type
);
2046 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
2048 and then (Nkind
(Parent
(N
)) /= N_Function_Call
2049 or else N
/= Name
(Parent
(N
)))
2051 and then (Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
2052 or else N
/= Name
(Parent
(N
)))
2054 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
2055 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
2057 (Attribute_Name
(Parent
(N
)) /= Name_Address
2059 Attribute_Name
(Parent
(N
)) /= Name_Access
))
2061 -- Name is a function call with no actuals, in a context that
2062 -- requires deproceduring (including as an actual in an enclosing
2063 -- function or procedure call). There are some pathological cases
2064 -- where the prefix might include functions that return access to
2065 -- subprograms and others that return a regular type. Disambiguation
2066 -- of those has to take place in Resolve.
2069 Make_Function_Call
(Loc
,
2070 Name
=> Make_Explicit_Dereference
(Loc
, P
),
2071 Parameter_Associations
=> New_List
);
2073 -- If the prefix is overloaded, remove operations that have formals,
2074 -- we know that this is a parameterless call.
2076 if Is_Overloaded
(P
) then
2077 Get_First_Interp
(P
, I
, It
);
2078 while Present
(It
.Nam
) loop
2081 if No
(First_Formal
(Base_Type
(Designated_Type
(T
)))) then
2087 Get_Next_Interp
(I
, It
);
2094 elsif not Is_Function_Type
2095 and then Is_Overloaded
(N
)
2097 -- The prefix may include access to subprograms and other access
2098 -- types. If the context selects the interpretation that is a
2099 -- function call (not a procedure call) we cannot rewrite the node
2100 -- yet, but we include the result of the call interpretation.
2102 Get_First_Interp
(N
, I
, It
);
2103 while Present
(It
.Nam
) loop
2104 if Ekind
(Base_Type
(It
.Typ
)) = E_Subprogram_Type
2105 and then Etype
(Base_Type
(It
.Typ
)) /= Standard_Void_Type
2106 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
2108 Add_One_Interp
(N
, Etype
(It
.Typ
), Etype
(It
.Typ
));
2111 Get_Next_Interp
(I
, It
);
2115 -- A value of remote access-to-class-wide must not be dereferenced
2118 Validate_Remote_Access_To_Class_Wide_Type
(N
);
2119 end Analyze_Explicit_Dereference
;
2121 ------------------------
2122 -- Analyze_Expression --
2123 ------------------------
2125 procedure Analyze_Expression
(N
: Node_Id
) is
2128 -- If the expression is an indexed component that will be rewritten
2129 -- as a container indexing, it has already been analyzed.
2131 if Nkind
(N
) = N_Indexed_Component
2132 and then Present
(Generalized_Indexing
(N
))
2138 Check_Parameterless_Call
(N
);
2140 end Analyze_Expression
;
2142 -------------------------------------
2143 -- Analyze_Expression_With_Actions --
2144 -------------------------------------
2146 procedure Analyze_Expression_With_Actions
(N
: Node_Id
) is
2150 A
:= First
(Actions
(N
));
2151 while Present
(A
) loop
2156 Analyze_Expression
(Expression
(N
));
2157 Set_Etype
(N
, Etype
(Expression
(N
)));
2158 end Analyze_Expression_With_Actions
;
2160 ---------------------------
2161 -- Analyze_If_Expression --
2162 ---------------------------
2164 procedure Analyze_If_Expression
(N
: Node_Id
) is
2165 Condition
: constant Node_Id
:= First
(Expressions
(N
));
2166 Then_Expr
: constant Node_Id
:= Next
(Condition
);
2167 Else_Expr
: Node_Id
;
2170 -- Defend against error of missing expressions from previous error
2172 if No
(Then_Expr
) then
2173 Check_Error_Detected
;
2177 if Comes_From_Source
(N
) then
2178 Check_SPARK_05_Restriction
("if expression is not allowed", N
);
2181 Else_Expr
:= Next
(Then_Expr
);
2183 if Comes_From_Source
(N
) then
2184 Check_Compiler_Unit
("if expression", N
);
2187 -- Analyze and resolve the condition. We need to resolve this now so
2188 -- that it gets folded to True/False if possible, before we analyze
2189 -- the THEN/ELSE branches, because when analyzing these branches, we
2190 -- may call Is_Statically_Unevaluated, which expects the condition of
2191 -- an enclosing IF to have been analyze/resolved/evaluated.
2193 Analyze_Expression
(Condition
);
2194 Resolve
(Condition
, Any_Boolean
);
2196 -- Analyze THEN expression and (if present) ELSE expression. For those
2197 -- we delay resolution in the normal manner, because of overloading etc.
2199 Analyze_Expression
(Then_Expr
);
2201 if Present
(Else_Expr
) then
2202 Analyze_Expression
(Else_Expr
);
2205 -- If then expression not overloaded, then that decides the type
2207 if not Is_Overloaded
(Then_Expr
) then
2208 Set_Etype
(N
, Etype
(Then_Expr
));
2210 -- Case where then expression is overloaded
2218 Set_Etype
(N
, Any_Type
);
2220 -- Loop through interpretations of Then_Expr
2222 Get_First_Interp
(Then_Expr
, I
, It
);
2223 while Present
(It
.Nam
) loop
2225 -- Add possible interpretation of Then_Expr if no Else_Expr, or
2226 -- Else_Expr is present and has a compatible type.
2229 or else Has_Compatible_Type
(Else_Expr
, It
.Typ
)
2231 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
2234 Get_Next_Interp
(I
, It
);
2237 -- If no valid interpretation has been found, then the type of the
2238 -- ELSE expression does not match any interpretation of the THEN
2241 if Etype
(N
) = Any_Type
then
2243 ("type incompatible with that of `THEN` expression",
2249 end Analyze_If_Expression
;
2251 ------------------------------------
2252 -- Analyze_Indexed_Component_Form --
2253 ------------------------------------
2255 procedure Analyze_Indexed_Component_Form
(N
: Node_Id
) is
2256 P
: constant Node_Id
:= Prefix
(N
);
2257 Exprs
: constant List_Id
:= Expressions
(N
);
2263 procedure Process_Function_Call
;
2264 -- Prefix in indexed component form is an overloadable entity, so the
2265 -- node is a function call. Reformat it as such.
2267 procedure Process_Indexed_Component
;
2268 -- Prefix in indexed component form is actually an indexed component.
2269 -- This routine processes it, knowing that the prefix is already
2272 procedure Process_Indexed_Component_Or_Slice
;
2273 -- An indexed component with a single index may designate a slice if
2274 -- the index is a subtype mark. This routine disambiguates these two
2275 -- cases by resolving the prefix to see if it is a subtype mark.
2277 procedure Process_Overloaded_Indexed_Component
;
2278 -- If the prefix of an indexed component is overloaded, the proper
2279 -- interpretation is selected by the index types and the context.
2281 ---------------------------
2282 -- Process_Function_Call --
2283 ---------------------------
2285 procedure Process_Function_Call
is
2286 Loc
: constant Source_Ptr
:= Sloc
(N
);
2290 Change_Node
(N
, N_Function_Call
);
2292 Set_Parameter_Associations
(N
, Exprs
);
2294 -- Analyze actuals prior to analyzing the call itself
2296 Actual
:= First
(Parameter_Associations
(N
));
2297 while Present
(Actual
) loop
2299 Check_Parameterless_Call
(Actual
);
2301 -- Move to next actual. Note that we use Next, not Next_Actual
2302 -- here. The reason for this is a bit subtle. If a function call
2303 -- includes named associations, the parser recognizes the node
2304 -- as a call, and it is analyzed as such. If all associations are
2305 -- positional, the parser builds an indexed_component node, and
2306 -- it is only after analysis of the prefix that the construct
2307 -- is recognized as a call, in which case Process_Function_Call
2308 -- rewrites the node and analyzes the actuals. If the list of
2309 -- actuals is malformed, the parser may leave the node as an
2310 -- indexed component (despite the presence of named associations).
2311 -- The iterator Next_Actual is equivalent to Next if the list is
2312 -- positional, but follows the normalized chain of actuals when
2313 -- named associations are present. In this case normalization has
2314 -- not taken place, and actuals remain unanalyzed, which leads to
2315 -- subsequent crashes or loops if there is an attempt to continue
2316 -- analysis of the program.
2318 -- IF there is a single actual and it is a type name, the node
2319 -- can only be interpreted as a slice of a parameterless call.
2320 -- Rebuild the node as such and analyze.
2322 if No
(Next
(Actual
))
2323 and then Is_Entity_Name
(Actual
)
2324 and then Is_Type
(Entity
(Actual
))
2325 and then Is_Discrete_Type
(Entity
(Actual
))
2331 New_Occurrence_Of
(Entity
(Actual
), Loc
)));
2341 end Process_Function_Call
;
2343 -------------------------------
2344 -- Process_Indexed_Component --
2345 -------------------------------
2347 procedure Process_Indexed_Component
is
2349 Array_Type
: Entity_Id
;
2351 Pent
: Entity_Id
:= Empty
;
2354 Exp
:= First
(Exprs
);
2356 if Is_Overloaded
(P
) then
2357 Process_Overloaded_Indexed_Component
;
2360 Array_Type
:= Etype
(P
);
2362 if Is_Entity_Name
(P
) then
2364 elsif Nkind
(P
) = N_Selected_Component
2365 and then Is_Entity_Name
(Selector_Name
(P
))
2367 Pent
:= Entity
(Selector_Name
(P
));
2370 -- Prefix must be appropriate for an array type, taking into
2371 -- account a possible implicit dereference.
2373 if Is_Access_Type
(Array_Type
) then
2375 (Warn_On_Dereference
, "?d?implicit dereference", N
);
2376 Array_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, P
);
2379 if Is_Array_Type
(Array_Type
) then
2382 elsif Present
(Pent
) and then Ekind
(Pent
) = E_Entry_Family
then
2384 Set_Etype
(N
, Any_Type
);
2386 if not Has_Compatible_Type
2387 (Exp
, Entry_Index_Type
(Pent
))
2389 Error_Msg_N
("invalid index type in entry name", N
);
2391 elsif Present
(Next
(Exp
)) then
2392 Error_Msg_N
("too many subscripts in entry reference", N
);
2395 Set_Etype
(N
, Etype
(P
));
2400 elsif Is_Record_Type
(Array_Type
)
2401 and then Remote_AST_I_Dereference
(P
)
2405 elsif Try_Container_Indexing
(N
, P
, Exprs
) then
2408 elsif Array_Type
= Any_Type
then
2409 Set_Etype
(N
, Any_Type
);
2411 -- In most cases the analysis of the prefix will have emitted
2412 -- an error already, but if the prefix may be interpreted as a
2413 -- call in prefixed notation, the report is left to the caller.
2414 -- To prevent cascaded errors, report only if no previous ones.
2416 if Serious_Errors_Detected
= 0 then
2417 Error_Msg_N
("invalid prefix in indexed component", P
);
2419 if Nkind
(P
) = N_Expanded_Name
then
2420 Error_Msg_NE
("\& is not visible", P
, Selector_Name
(P
));
2426 -- Here we definitely have a bad indexing
2429 if Nkind
(Parent
(N
)) = N_Requeue_Statement
2430 and then Present
(Pent
) and then Ekind
(Pent
) = E_Entry
2433 ("REQUEUE does not permit parameters", First
(Exprs
));
2435 elsif Is_Entity_Name
(P
)
2436 and then Etype
(P
) = Standard_Void_Type
2438 Error_Msg_NE
("incorrect use of &", P
, Entity
(P
));
2441 Error_Msg_N
("array type required in indexed component", P
);
2444 Set_Etype
(N
, Any_Type
);
2448 Index
:= First_Index
(Array_Type
);
2449 while Present
(Index
) and then Present
(Exp
) loop
2450 if not Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2451 Wrong_Type
(Exp
, Etype
(Index
));
2452 Set_Etype
(N
, Any_Type
);
2460 Set_Etype
(N
, Component_Type
(Array_Type
));
2461 Check_Implicit_Dereference
(N
, Etype
(N
));
2463 if Present
(Index
) then
2465 ("too few subscripts in array reference", First
(Exprs
));
2467 elsif Present
(Exp
) then
2468 Error_Msg_N
("too many subscripts in array reference", Exp
);
2471 end Process_Indexed_Component
;
2473 ----------------------------------------
2474 -- Process_Indexed_Component_Or_Slice --
2475 ----------------------------------------
2477 procedure Process_Indexed_Component_Or_Slice
is
2479 Exp
:= First
(Exprs
);
2480 while Present
(Exp
) loop
2481 Analyze_Expression
(Exp
);
2485 Exp
:= First
(Exprs
);
2487 -- If one index is present, and it is a subtype name, then the node
2488 -- denotes a slice (note that the case of an explicit range for a
2489 -- slice was already built as an N_Slice node in the first place,
2490 -- so that case is not handled here).
2492 -- We use a replace rather than a rewrite here because this is one
2493 -- of the cases in which the tree built by the parser is plain wrong.
2496 and then Is_Entity_Name
(Exp
)
2497 and then Is_Type
(Entity
(Exp
))
2500 Make_Slice
(Sloc
(N
),
2502 Discrete_Range
=> New_Copy
(Exp
)));
2505 -- Otherwise (more than one index present, or single index is not
2506 -- a subtype name), then we have the indexed component case.
2509 Process_Indexed_Component
;
2511 end Process_Indexed_Component_Or_Slice
;
2513 ------------------------------------------
2514 -- Process_Overloaded_Indexed_Component --
2515 ------------------------------------------
2517 procedure Process_Overloaded_Indexed_Component
is
2526 Set_Etype
(N
, Any_Type
);
2528 Get_First_Interp
(P
, I
, It
);
2529 while Present
(It
.Nam
) loop
2532 if Is_Access_Type
(Typ
) then
2533 Typ
:= Designated_Type
(Typ
);
2535 (Warn_On_Dereference
, "?d?implicit dereference", N
);
2538 if Is_Array_Type
(Typ
) then
2540 -- Got a candidate: verify that index types are compatible
2542 Index
:= First_Index
(Typ
);
2544 Exp
:= First
(Exprs
);
2545 while Present
(Index
) and then Present
(Exp
) loop
2546 if Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2558 if Found
and then No
(Index
) and then No
(Exp
) then
2560 CT
: constant Entity_Id
:=
2561 Base_Type
(Component_Type
(Typ
));
2563 Add_One_Interp
(N
, CT
, CT
);
2564 Check_Implicit_Dereference
(N
, CT
);
2568 elsif Try_Container_Indexing
(N
, P
, Exprs
) then
2573 Get_Next_Interp
(I
, It
);
2576 if Etype
(N
) = Any_Type
then
2577 Error_Msg_N
("no legal interpretation for indexed component", N
);
2578 Set_Is_Overloaded
(N
, False);
2582 end Process_Overloaded_Indexed_Component
;
2584 -- Start of processing for Analyze_Indexed_Component_Form
2587 -- Get name of array, function or type
2591 -- If P is an explicit dereference whose prefix is of a remote access-
2592 -- to-subprogram type, then N has already been rewritten as a subprogram
2593 -- call and analyzed.
2595 if Nkind
(N
) in N_Subprogram_Call
then
2598 -- When the prefix is attribute 'Loop_Entry and the sole expression of
2599 -- the indexed component denotes a loop name, the indexed form is turned
2600 -- into an attribute reference.
2602 elsif Nkind
(N
) = N_Attribute_Reference
2603 and then Attribute_Name
(N
) = Name_Loop_Entry
2608 pragma Assert
(Nkind
(N
) = N_Indexed_Component
);
2610 P_T
:= Base_Type
(Etype
(P
));
2612 if Is_Entity_Name
(P
) and then Present
(Entity
(P
)) then
2615 if Is_Type
(U_N
) then
2617 -- Reformat node as a type conversion
2619 E
:= Remove_Head
(Exprs
);
2621 if Present
(First
(Exprs
)) then
2623 ("argument of type conversion must be single expression", N
);
2626 Change_Node
(N
, N_Type_Conversion
);
2627 Set_Subtype_Mark
(N
, P
);
2629 Set_Expression
(N
, E
);
2631 -- After changing the node, call for the specific Analysis
2632 -- routine directly, to avoid a double call to the expander.
2634 Analyze_Type_Conversion
(N
);
2638 if Is_Overloadable
(U_N
) then
2639 Process_Function_Call
;
2641 elsif Ekind
(Etype
(P
)) = E_Subprogram_Type
2642 or else (Is_Access_Type
(Etype
(P
))
2644 Ekind
(Designated_Type
(Etype
(P
))) =
2647 -- Call to access_to-subprogram with possible implicit dereference
2649 Process_Function_Call
;
2651 elsif Is_Generic_Subprogram
(U_N
) then
2653 -- A common beginner's (or C++ templates fan) error
2655 Error_Msg_N
("generic subprogram cannot be called", N
);
2656 Set_Etype
(N
, Any_Type
);
2660 Process_Indexed_Component_Or_Slice
;
2663 -- If not an entity name, prefix is an expression that may denote
2664 -- an array or an access-to-subprogram.
2667 if Ekind
(P_T
) = E_Subprogram_Type
2668 or else (Is_Access_Type
(P_T
)
2670 Ekind
(Designated_Type
(P_T
)) = E_Subprogram_Type
)
2672 Process_Function_Call
;
2674 elsif Nkind
(P
) = N_Selected_Component
2675 and then Present
(Entity
(Selector_Name
(P
)))
2676 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
2678 Process_Function_Call
;
2680 -- In ASIS mode within a generic, a prefixed call is analyzed and
2681 -- partially rewritten but the original indexed component has not
2682 -- yet been rewritten as a call. Perform the replacement now.
2684 elsif Nkind
(P
) = N_Selected_Component
2685 and then Nkind
(Parent
(P
)) = N_Function_Call
2688 Rewrite
(N
, Parent
(P
));
2692 -- Indexed component, slice, or a call to a member of a family
2693 -- entry, which will be converted to an entry call later.
2695 Process_Indexed_Component_Or_Slice
;
2699 Analyze_Dimension
(N
);
2700 end Analyze_Indexed_Component_Form
;
2702 ------------------------
2703 -- Analyze_Logical_Op --
2704 ------------------------
2706 procedure Analyze_Logical_Op
(N
: Node_Id
) is
2707 L
: constant Node_Id
:= Left_Opnd
(N
);
2708 R
: constant Node_Id
:= Right_Opnd
(N
);
2709 Op_Id
: Entity_Id
:= Entity
(N
);
2712 Set_Etype
(N
, Any_Type
);
2713 Candidate_Type
:= Empty
;
2715 Analyze_Expression
(L
);
2716 Analyze_Expression
(R
);
2718 if Present
(Op_Id
) then
2720 if Ekind
(Op_Id
) = E_Operator
then
2721 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
2723 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2727 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
2728 while Present
(Op_Id
) loop
2729 if Ekind
(Op_Id
) = E_Operator
then
2730 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
2732 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
2735 Op_Id
:= Homonym
(Op_Id
);
2740 Check_Function_Writable_Actuals
(N
);
2741 end Analyze_Logical_Op
;
2743 ---------------------------
2744 -- Analyze_Membership_Op --
2745 ---------------------------
2747 procedure Analyze_Membership_Op
(N
: Node_Id
) is
2748 Loc
: constant Source_Ptr
:= Sloc
(N
);
2749 L
: constant Node_Id
:= Left_Opnd
(N
);
2750 R
: constant Node_Id
:= Right_Opnd
(N
);
2752 Index
: Interp_Index
;
2754 Found
: Boolean := False;
2758 procedure Try_One_Interp
(T1
: Entity_Id
);
2759 -- Routine to try one proposed interpretation. Note that the context
2760 -- of the operation plays no role in resolving the arguments, so that
2761 -- if there is more than one interpretation of the operands that is
2762 -- compatible with a membership test, the operation is ambiguous.
2764 --------------------
2765 -- Try_One_Interp --
2766 --------------------
2768 procedure Try_One_Interp
(T1
: Entity_Id
) is
2770 if Has_Compatible_Type
(R
, T1
) then
2772 and then Base_Type
(T1
) /= Base_Type
(T_F
)
2774 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
2776 if It
= No_Interp
then
2777 Ambiguous_Operands
(N
);
2778 Set_Etype
(L
, Any_Type
);
2795 procedure Analyze_Set_Membership
;
2796 -- If a set of alternatives is present, analyze each and find the
2797 -- common type to which they must all resolve.
2799 ----------------------------
2800 -- Analyze_Set_Membership --
2801 ----------------------------
2803 procedure Analyze_Set_Membership
is
2805 Index
: Interp_Index
;
2807 Candidate_Interps
: Node_Id
;
2808 Common_Type
: Entity_Id
:= Empty
;
2811 if Comes_From_Source
(N
) then
2812 Check_Compiler_Unit
("set membership", N
);
2816 Candidate_Interps
:= L
;
2818 if not Is_Overloaded
(L
) then
2819 Common_Type
:= Etype
(L
);
2821 Alt
:= First
(Alternatives
(N
));
2822 while Present
(Alt
) loop
2825 if not Has_Compatible_Type
(Alt
, Common_Type
) then
2826 Wrong_Type
(Alt
, Common_Type
);
2833 Alt
:= First
(Alternatives
(N
));
2834 while Present
(Alt
) loop
2836 if not Is_Overloaded
(Alt
) then
2837 Common_Type
:= Etype
(Alt
);
2840 Get_First_Interp
(Alt
, Index
, It
);
2841 while Present
(It
.Typ
) loop
2843 Has_Compatible_Type
(Candidate_Interps
, It
.Typ
)
2845 Remove_Interp
(Index
);
2848 Get_Next_Interp
(Index
, It
);
2851 Get_First_Interp
(Alt
, Index
, It
);
2854 Error_Msg_N
("alternative has no legal type", Alt
);
2858 -- If alternative is not overloaded, we have a unique type
2861 Set_Etype
(Alt
, It
.Typ
);
2862 Get_Next_Interp
(Index
, It
);
2865 Set_Is_Overloaded
(Alt
, False);
2866 Common_Type
:= Etype
(Alt
);
2869 Candidate_Interps
:= Alt
;
2876 Set_Etype
(N
, Standard_Boolean
);
2878 if Present
(Common_Type
) then
2879 Set_Etype
(L
, Common_Type
);
2881 -- The left operand may still be overloaded, to be resolved using
2885 Error_Msg_N
("cannot resolve membership operation", N
);
2887 end Analyze_Set_Membership
;
2889 -- Start of processing for Analyze_Membership_Op
2892 Analyze_Expression
(L
);
2894 if No
(R
) and then Ada_Version
>= Ada_2012
then
2895 Analyze_Set_Membership
;
2896 Check_Function_Writable_Actuals
(N
);
2901 if Nkind
(R
) = N_Range
2902 or else (Nkind
(R
) = N_Attribute_Reference
2903 and then Attribute_Name
(R
) = Name_Range
)
2907 if not Is_Overloaded
(L
) then
2908 Try_One_Interp
(Etype
(L
));
2911 Get_First_Interp
(L
, Index
, It
);
2912 while Present
(It
.Typ
) loop
2913 Try_One_Interp
(It
.Typ
);
2914 Get_Next_Interp
(Index
, It
);
2918 -- If not a range, it can be a subtype mark, or else it is a degenerate
2919 -- membership test with a singleton value, i.e. a test for equality,
2920 -- if the types are compatible.
2925 if Is_Entity_Name
(R
)
2926 and then Is_Type
(Entity
(R
))
2929 Check_Fully_Declared
(Entity
(R
), R
);
2931 elsif Ada_Version
>= Ada_2012
2932 and then Has_Compatible_Type
(R
, Etype
(L
))
2934 if Nkind
(N
) = N_In
then
2950 -- In all versions of the language, if we reach this point there
2951 -- is a previous error that will be diagnosed below.
2957 -- Compatibility between expression and subtype mark or range is
2958 -- checked during resolution. The result of the operation is Boolean
2961 Set_Etype
(N
, Standard_Boolean
);
2963 if Comes_From_Source
(N
)
2964 and then Present
(Right_Opnd
(N
))
2965 and then Is_CPP_Class
(Etype
(Etype
(Right_Opnd
(N
))))
2967 Error_Msg_N
("membership test not applicable to cpp-class types", N
);
2970 Check_Function_Writable_Actuals
(N
);
2971 end Analyze_Membership_Op
;
2977 procedure Analyze_Mod
(N
: Node_Id
) is
2979 -- A special warning check, if we have an expression of the form:
2980 -- expr mod 2 * literal
2981 -- where literal is 64 or less, then probably what was meant was
2982 -- expr mod 2 ** literal
2983 -- so issue an appropriate warning.
2985 if Warn_On_Suspicious_Modulus_Value
2986 and then Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
2987 and then Intval
(Right_Opnd
(N
)) = Uint_2
2988 and then Nkind
(Parent
(N
)) = N_Op_Multiply
2989 and then Nkind
(Right_Opnd
(Parent
(N
))) = N_Integer_Literal
2990 and then Intval
(Right_Opnd
(Parent
(N
))) <= Uint_64
2993 ("suspicious MOD value, was '*'* intended'??M?", Parent
(N
));
2996 -- Remaining processing is same as for other arithmetic operators
2998 Analyze_Arithmetic_Op
(N
);
3001 ----------------------
3002 -- Analyze_Negation --
3003 ----------------------
3005 procedure Analyze_Negation
(N
: Node_Id
) is
3006 R
: constant Node_Id
:= Right_Opnd
(N
);
3007 Op_Id
: Entity_Id
:= Entity
(N
);
3010 Set_Etype
(N
, Any_Type
);
3011 Candidate_Type
:= Empty
;
3013 Analyze_Expression
(R
);
3015 if Present
(Op_Id
) then
3016 if Ekind
(Op_Id
) = E_Operator
then
3017 Find_Negation_Types
(R
, Op_Id
, N
);
3019 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3023 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
3024 while Present
(Op_Id
) loop
3025 if Ekind
(Op_Id
) = E_Operator
then
3026 Find_Negation_Types
(R
, Op_Id
, N
);
3028 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
3031 Op_Id
:= Homonym
(Op_Id
);
3036 end Analyze_Negation
;
3042 procedure Analyze_Null
(N
: Node_Id
) is
3044 Check_SPARK_05_Restriction
("null is not allowed", N
);
3046 Set_Etype
(N
, Any_Access
);
3049 ----------------------
3050 -- Analyze_One_Call --
3051 ----------------------
3053 procedure Analyze_One_Call
3057 Success
: out Boolean;
3058 Skip_First
: Boolean := False)
3060 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
3061 Prev_T
: constant Entity_Id
:= Etype
(N
);
3063 Must_Skip
: constant Boolean := Skip_First
3064 or else Nkind
(Original_Node
(N
)) = N_Selected_Component
3066 (Nkind
(Original_Node
(N
)) = N_Indexed_Component
3067 and then Nkind
(Prefix
(Original_Node
(N
)))
3068 = N_Selected_Component
);
3069 -- The first formal must be omitted from the match when trying to find
3070 -- a primitive operation that is a possible interpretation, and also
3071 -- after the call has been rewritten, because the corresponding actual
3072 -- is already known to be compatible, and because this may be an
3073 -- indexing of a call with default parameters.
3077 Is_Indexed
: Boolean := False;
3078 Is_Indirect
: Boolean := False;
3079 Subp_Type
: constant Entity_Id
:= Etype
(Nam
);
3082 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean;
3083 -- There may be a user-defined operator that hides the current
3084 -- interpretation. We must check for this independently of the
3085 -- analysis of the call with the user-defined operation, because
3086 -- the parameter names may be wrong and yet the hiding takes place.
3087 -- This fixes a problem with ACATS test B34014O.
3089 -- When the type Address is a visible integer type, and the DEC
3090 -- system extension is visible, the predefined operator may be
3091 -- hidden as well, by one of the address operations in auxdec.
3092 -- Finally, The abstract operations on address do not hide the
3093 -- predefined operator (this is the purpose of making them abstract).
3095 procedure Indicate_Name_And_Type
;
3096 -- If candidate interpretation matches, indicate name and type of
3097 -- result on call node.
3099 ----------------------------
3100 -- Indicate_Name_And_Type --
3101 ----------------------------
3103 procedure Indicate_Name_And_Type
is
3105 Add_One_Interp
(N
, Nam
, Etype
(Nam
));
3106 Check_Implicit_Dereference
(N
, Etype
(Nam
));
3109 -- If the prefix of the call is a name, indicate the entity
3110 -- being called. If it is not a name, it is an expression that
3111 -- denotes an access to subprogram or else an entry or family. In
3112 -- the latter case, the name is a selected component, and the entity
3113 -- being called is noted on the selector.
3115 if not Is_Type
(Nam
) then
3116 if Is_Entity_Name
(Name
(N
)) then
3117 Set_Entity
(Name
(N
), Nam
);
3118 Set_Etype
(Name
(N
), Etype
(Nam
));
3120 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
3121 Set_Entity
(Selector_Name
(Name
(N
)), Nam
);
3125 if Debug_Flag_E
and not Report
then
3126 Write_Str
(" Overloaded call ");
3127 Write_Int
(Int
(N
));
3128 Write_Str
(" compatible with ");
3129 Write_Int
(Int
(Nam
));
3132 end Indicate_Name_And_Type
;
3134 ------------------------
3135 -- Operator_Hidden_By --
3136 ------------------------
3138 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean is
3139 Act1
: constant Node_Id
:= First_Actual
(N
);
3140 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
3141 Form1
: constant Entity_Id
:= First_Formal
(Fun
);
3142 Form2
: constant Entity_Id
:= Next_Formal
(Form1
);
3145 if Ekind
(Fun
) /= E_Function
or else Is_Abstract_Subprogram
(Fun
) then
3148 elsif not Has_Compatible_Type
(Act1
, Etype
(Form1
)) then
3151 elsif Present
(Form2
) then
3153 or else not Has_Compatible_Type
(Act2
, Etype
(Form2
))
3158 elsif Present
(Act2
) then
3162 -- Now we know that the arity of the operator matches the function,
3163 -- and the function call is a valid interpretation. The function
3164 -- hides the operator if it has the right signature, or if one of
3165 -- its operands is a non-abstract operation on Address when this is
3166 -- a visible integer type.
3168 return Hides_Op
(Fun
, Nam
)
3169 or else Is_Descendant_Of_Address
(Etype
(Form1
))
3172 and then Is_Descendant_Of_Address
(Etype
(Form2
)));
3173 end Operator_Hidden_By
;
3175 -- Start of processing for Analyze_One_Call
3180 -- If the subprogram has no formals or if all the formals have defaults,
3181 -- and the return type is an array type, the node may denote an indexing
3182 -- of the result of a parameterless call. In Ada 2005, the subprogram
3183 -- may have one non-defaulted formal, and the call may have been written
3184 -- in prefix notation, so that the rebuilt parameter list has more than
3187 if not Is_Overloadable
(Nam
)
3188 and then Ekind
(Nam
) /= E_Subprogram_Type
3189 and then Ekind
(Nam
) /= E_Entry_Family
3194 -- An indexing requires at least one actual. The name of the call cannot
3195 -- be an implicit indirect call, so it cannot be a generated explicit
3198 if not Is_Empty_List
(Actuals
)
3200 (Needs_No_Actuals
(Nam
)
3202 (Needs_One_Actual
(Nam
)
3203 and then Present
(Next_Actual
(First
(Actuals
)))))
3205 if Is_Array_Type
(Subp_Type
)
3207 (Nkind
(Name
(N
)) /= N_Explicit_Dereference
3208 or else Comes_From_Source
(Name
(N
)))
3210 Is_Indexed
:= Try_Indexed_Call
(N
, Nam
, Subp_Type
, Must_Skip
);
3212 elsif Is_Access_Type
(Subp_Type
)
3213 and then Is_Array_Type
(Designated_Type
(Subp_Type
))
3217 (N
, Nam
, Designated_Type
(Subp_Type
), Must_Skip
);
3219 -- The prefix can also be a parameterless function that returns an
3220 -- access to subprogram, in which case this is an indirect call.
3221 -- If this succeeds, an explicit dereference is added later on,
3222 -- in Analyze_Call or Resolve_Call.
3224 elsif Is_Access_Type
(Subp_Type
)
3225 and then Ekind
(Designated_Type
(Subp_Type
)) = E_Subprogram_Type
3227 Is_Indirect
:= Try_Indirect_Call
(N
, Nam
, Subp_Type
);
3232 -- If the call has been transformed into a slice, it is of the form
3233 -- F (Subtype) where F is parameterless. The node has been rewritten in
3234 -- Try_Indexed_Call and there is nothing else to do.
3237 and then Nkind
(N
) = N_Slice
3243 (N
, Nam
, (Report
and not Is_Indexed
and not Is_Indirect
), Norm_OK
);
3247 -- If an indirect call is a possible interpretation, indicate
3248 -- success to the caller. This may be an indexing of an explicit
3249 -- dereference of a call that returns an access type (see above).
3253 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
3254 and then Comes_From_Source
(Name
(N
)))
3259 -- Mismatch in number or names of parameters
3261 elsif Debug_Flag_E
then
3262 Write_Str
(" normalization fails in call ");
3263 Write_Int
(Int
(N
));
3264 Write_Str
(" with subprogram ");
3265 Write_Int
(Int
(Nam
));
3269 -- If the context expects a function call, discard any interpretation
3270 -- that is a procedure. If the node is not overloaded, leave as is for
3271 -- better error reporting when type mismatch is found.
3273 elsif Nkind
(N
) = N_Function_Call
3274 and then Is_Overloaded
(Name
(N
))
3275 and then Ekind
(Nam
) = E_Procedure
3279 -- Ditto for function calls in a procedure context
3281 elsif Nkind
(N
) = N_Procedure_Call_Statement
3282 and then Is_Overloaded
(Name
(N
))
3283 and then Etype
(Nam
) /= Standard_Void_Type
3287 elsif No
(Actuals
) then
3289 -- If Normalize succeeds, then there are default parameters for
3292 Indicate_Name_And_Type
;
3294 elsif Ekind
(Nam
) = E_Operator
then
3295 if Nkind
(N
) = N_Procedure_Call_Statement
then
3299 -- This can occur when the prefix of the call is an operator
3300 -- name or an expanded name whose selector is an operator name.
3302 Analyze_Operator_Call
(N
, Nam
);
3304 if Etype
(N
) /= Prev_T
then
3306 -- Check that operator is not hidden by a function interpretation
3308 if Is_Overloaded
(Name
(N
)) then
3314 Get_First_Interp
(Name
(N
), I
, It
);
3315 while Present
(It
.Nam
) loop
3316 if Operator_Hidden_By
(It
.Nam
) then
3317 Set_Etype
(N
, Prev_T
);
3321 Get_Next_Interp
(I
, It
);
3326 -- If operator matches formals, record its name on the call.
3327 -- If the operator is overloaded, Resolve will select the
3328 -- correct one from the list of interpretations. The call
3329 -- node itself carries the first candidate.
3331 Set_Entity
(Name
(N
), Nam
);
3334 elsif Report
and then Etype
(N
) = Any_Type
then
3335 Error_Msg_N
("incompatible arguments for operator", N
);
3339 -- Normalize_Actuals has chained the named associations in the
3340 -- correct order of the formals.
3342 Actual
:= First_Actual
(N
);
3343 Formal
:= First_Formal
(Nam
);
3345 -- If we are analyzing a call rewritten from object notation, skip
3346 -- first actual, which may be rewritten later as an explicit
3350 Next_Actual
(Actual
);
3351 Next_Formal
(Formal
);
3354 while Present
(Actual
) and then Present
(Formal
) loop
3355 if Nkind
(Parent
(Actual
)) /= N_Parameter_Association
3356 or else Chars
(Selector_Name
(Parent
(Actual
))) = Chars
(Formal
)
3358 -- The actual can be compatible with the formal, but we must
3359 -- also check that the context is not an address type that is
3360 -- visibly an integer type. In this case the use of literals is
3361 -- illegal, except in the body of descendants of system, where
3362 -- arithmetic operations on address are of course used.
3364 if Has_Compatible_Type
(Actual
, Etype
(Formal
))
3366 (Etype
(Actual
) /= Universal_Integer
3367 or else not Is_Descendant_Of_Address
(Etype
(Formal
))
3369 Is_Predefined_File_Name
3370 (Unit_File_Name
(Get_Source_Unit
(N
))))
3372 Next_Actual
(Actual
);
3373 Next_Formal
(Formal
);
3375 -- In Allow_Integer_Address mode, we allow an actual integer to
3376 -- match a formal address type and vice versa. We only do this
3377 -- if we are certain that an error will otherwise be issued
3379 elsif Address_Integer_Convert_OK
3380 (Etype
(Actual
), Etype
(Formal
))
3381 and then (Report
and not Is_Indexed
and not Is_Indirect
)
3383 -- Handle this case by introducing an unchecked conversion
3386 Unchecked_Convert_To
(Etype
(Formal
),
3387 Relocate_Node
(Actual
)));
3388 Analyze_And_Resolve
(Actual
, Etype
(Formal
));
3389 Next_Actual
(Actual
);
3390 Next_Formal
(Formal
);
3392 -- For an Ada 2012 predicate or invariant, a call may mention
3393 -- an incomplete type, while resolution of the corresponding
3394 -- predicate function may see the full view, as a consequence
3395 -- of the delayed resolution of the corresponding expressions.
3397 elsif Ekind
(Etype
(Formal
)) = E_Incomplete_Type
3398 and then Full_View
(Etype
(Formal
)) = Etype
(Actual
)
3400 Set_Etype
(Formal
, Etype
(Actual
));
3401 Next_Actual
(Actual
);
3402 Next_Formal
(Formal
);
3405 if Debug_Flag_E
then
3406 Write_Str
(" type checking fails in call ");
3407 Write_Int
(Int
(N
));
3408 Write_Str
(" with formal ");
3409 Write_Int
(Int
(Formal
));
3410 Write_Str
(" in subprogram ");
3411 Write_Int
(Int
(Nam
));
3415 -- Comment needed on the following test???
3417 if Report
and not Is_Indexed
and not Is_Indirect
then
3419 -- Ada 2005 (AI-251): Complete the error notification
3420 -- to help new Ada 2005 users.
3422 if Is_Class_Wide_Type
(Etype
(Formal
))
3423 and then Is_Interface
(Etype
(Etype
(Formal
)))
3424 and then not Interface_Present_In_Ancestor
3425 (Typ
=> Etype
(Actual
),
3426 Iface
=> Etype
(Etype
(Formal
)))
3429 ("(Ada 2005) does not implement interface }",
3430 Actual
, Etype
(Etype
(Formal
)));
3433 Wrong_Type
(Actual
, Etype
(Formal
));
3435 if Nkind
(Actual
) = N_Op_Eq
3436 and then Nkind
(Left_Opnd
(Actual
)) = N_Identifier
3438 Formal
:= First_Formal
(Nam
);
3439 while Present
(Formal
) loop
3440 if Chars
(Left_Opnd
(Actual
)) = Chars
(Formal
) then
3441 Error_Msg_N
-- CODEFIX
3442 ("possible misspelling of `='>`!", Actual
);
3446 Next_Formal
(Formal
);
3450 if All_Errors_Mode
then
3451 Error_Msg_Sloc
:= Sloc
(Nam
);
3453 if Etype
(Formal
) = Any_Type
then
3455 ("there is no legal actual parameter", Actual
);
3458 if Is_Overloadable
(Nam
)
3459 and then Present
(Alias
(Nam
))
3460 and then not Comes_From_Source
(Nam
)
3463 ("\\ =='> in call to inherited operation & #!",
3466 elsif Ekind
(Nam
) = E_Subprogram_Type
then
3468 Access_To_Subprogram_Typ
:
3469 constant Entity_Id
:=
3471 (Associated_Node_For_Itype
(Nam
));
3474 ("\\ =='> in call to dereference of &#!",
3475 Actual
, Access_To_Subprogram_Typ
);
3480 ("\\ =='> in call to &#!", Actual
, Nam
);
3490 -- Normalize_Actuals has verified that a default value exists
3491 -- for this formal. Current actual names a subsequent formal.
3493 Next_Formal
(Formal
);
3497 -- On exit, all actuals match
3499 Indicate_Name_And_Type
;
3501 end Analyze_One_Call
;
3503 ---------------------------
3504 -- Analyze_Operator_Call --
3505 ---------------------------
3507 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
) is
3508 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
3509 Act1
: constant Node_Id
:= First_Actual
(N
);
3510 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
3513 -- Binary operator case
3515 if Present
(Act2
) then
3517 -- If more than two operands, then not binary operator after all
3519 if Present
(Next_Actual
(Act2
)) then
3523 -- Otherwise action depends on operator
3533 Find_Arithmetic_Types
(Act1
, Act2
, Op_Id
, N
);
3538 Find_Boolean_Types
(Act1
, Act2
, Op_Id
, N
);
3544 Find_Comparison_Types
(Act1
, Act2
, Op_Id
, N
);
3548 Find_Equality_Types
(Act1
, Act2
, Op_Id
, N
);
3550 when Name_Op_Concat
=>
3551 Find_Concatenation_Types
(Act1
, Act2
, Op_Id
, N
);
3553 -- Is this when others, or should it be an abort???
3559 -- Unary operator case
3563 when Name_Op_Subtract |
3566 Find_Unary_Types
(Act1
, Op_Id
, N
);
3569 Find_Negation_Types
(Act1
, Op_Id
, N
);
3571 -- Is this when others correct, or should it be an abort???
3577 end Analyze_Operator_Call
;
3579 -------------------------------------------
3580 -- Analyze_Overloaded_Selected_Component --
3581 -------------------------------------------
3583 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
) is
3584 Nam
: constant Node_Id
:= Prefix
(N
);
3585 Sel
: constant Node_Id
:= Selector_Name
(N
);
3592 Set_Etype
(Sel
, Any_Type
);
3594 Get_First_Interp
(Nam
, I
, It
);
3595 while Present
(It
.Typ
) loop
3596 if Is_Access_Type
(It
.Typ
) then
3597 T
:= Designated_Type
(It
.Typ
);
3598 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
3603 -- Locate the component. For a private prefix the selector can denote
3606 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
3608 -- If the prefix is a class-wide type, the visible components are
3609 -- those of the base type.
3611 if Is_Class_Wide_Type
(T
) then
3615 Comp
:= First_Entity
(T
);
3616 while Present
(Comp
) loop
3617 if Chars
(Comp
) = Chars
(Sel
)
3618 and then Is_Visible_Component
(Comp
)
3621 -- AI05-105: if the context is an object renaming with
3622 -- an anonymous access type, the expected type of the
3623 -- object must be anonymous. This is a name resolution rule.
3625 if Nkind
(Parent
(N
)) /= N_Object_Renaming_Declaration
3626 or else No
(Access_Definition
(Parent
(N
)))
3627 or else Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Type
3629 Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Subprogram_Type
3631 Set_Entity
(Sel
, Comp
);
3632 Set_Etype
(Sel
, Etype
(Comp
));
3633 Add_One_Interp
(N
, Etype
(Comp
), Etype
(Comp
));
3634 Check_Implicit_Dereference
(N
, Etype
(Comp
));
3636 -- This also specifies a candidate to resolve the name.
3637 -- Further overloading will be resolved from context.
3638 -- The selector name itself does not carry overloading
3641 Set_Etype
(Nam
, It
.Typ
);
3644 -- Named access type in the context of a renaming
3645 -- declaration with an access definition. Remove
3646 -- inapplicable candidate.
3655 elsif Is_Concurrent_Type
(T
) then
3656 Comp
:= First_Entity
(T
);
3657 while Present
(Comp
)
3658 and then Comp
/= First_Private_Entity
(T
)
3660 if Chars
(Comp
) = Chars
(Sel
) then
3661 if Is_Overloadable
(Comp
) then
3662 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
3664 Set_Entity_With_Checks
(Sel
, Comp
);
3665 Generate_Reference
(Comp
, Sel
);
3668 Set_Etype
(Sel
, Etype
(Comp
));
3669 Set_Etype
(N
, Etype
(Comp
));
3670 Set_Etype
(Nam
, It
.Typ
);
3672 -- For access type case, introduce explicit dereference for
3673 -- more uniform treatment of entry calls. Do this only once
3674 -- if several interpretations yield an access type.
3676 if Is_Access_Type
(Etype
(Nam
))
3677 and then Nkind
(Nam
) /= N_Explicit_Dereference
3679 Insert_Explicit_Dereference
(Nam
);
3681 (Warn_On_Dereference
, "?d?implicit dereference", N
);
3688 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
3691 Get_Next_Interp
(I
, It
);
3694 if Etype
(N
) = Any_Type
3695 and then not Try_Object_Operation
(N
)
3697 Error_Msg_NE
("undefined selector& for overloaded prefix", N
, Sel
);
3698 Set_Entity
(Sel
, Any_Id
);
3699 Set_Etype
(Sel
, Any_Type
);
3701 end Analyze_Overloaded_Selected_Component
;
3703 ----------------------------------
3704 -- Analyze_Qualified_Expression --
3705 ----------------------------------
3707 procedure Analyze_Qualified_Expression
(N
: Node_Id
) is
3708 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
3709 Expr
: constant Node_Id
:= Expression
(N
);
3715 Analyze_Expression
(Expr
);
3717 Set_Etype
(N
, Any_Type
);
3722 if T
= Any_Type
then
3726 Check_Fully_Declared
(T
, N
);
3728 -- If expected type is class-wide, check for exact match before
3729 -- expansion, because if the expression is a dispatching call it
3730 -- may be rewritten as explicit dereference with class-wide result.
3731 -- If expression is overloaded, retain only interpretations that
3732 -- will yield exact matches.
3734 if Is_Class_Wide_Type
(T
) then
3735 if not Is_Overloaded
(Expr
) then
3736 if Base_Type
(Etype
(Expr
)) /= Base_Type
(T
) then
3737 if Nkind
(Expr
) = N_Aggregate
then
3738 Error_Msg_N
("type of aggregate cannot be class-wide", Expr
);
3740 Wrong_Type
(Expr
, T
);
3745 Get_First_Interp
(Expr
, I
, It
);
3747 while Present
(It
.Nam
) loop
3748 if Base_Type
(It
.Typ
) /= Base_Type
(T
) then
3752 Get_Next_Interp
(I
, It
);
3758 end Analyze_Qualified_Expression
;
3760 -----------------------------------
3761 -- Analyze_Quantified_Expression --
3762 -----------------------------------
3764 procedure Analyze_Quantified_Expression
(N
: Node_Id
) is
3765 function Is_Empty_Range
(Typ
: Entity_Id
) return Boolean;
3766 -- If the iterator is part of a quantified expression, and the range is
3767 -- known to be statically empty, emit a warning and replace expression
3768 -- with its static value. Returns True if the replacement occurs.
3770 function No_Else_Or_Trivial_True
(If_Expr
: Node_Id
) return Boolean;
3771 -- Determine whether if expression If_Expr lacks an else part or if it
3772 -- has one, it evaluates to True.
3774 --------------------
3775 -- Is_Empty_Range --
3776 --------------------
3778 function Is_Empty_Range
(Typ
: Entity_Id
) return Boolean is
3779 Loc
: constant Source_Ptr
:= Sloc
(N
);
3782 if Is_Array_Type
(Typ
)
3783 and then Compile_Time_Known_Bounds
(Typ
)
3785 (Expr_Value
(Type_Low_Bound
(Etype
(First_Index
(Typ
)))) >
3786 Expr_Value
(Type_High_Bound
(Etype
(First_Index
(Typ
)))))
3788 Preanalyze_And_Resolve
(Condition
(N
), Standard_Boolean
);
3790 if All_Present
(N
) then
3792 ("??quantified expression with ALL "
3793 & "over a null range has value True", N
);
3794 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
3798 ("??quantified expression with SOME "
3799 & "over a null range has value False", N
);
3800 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
3811 -----------------------------
3812 -- No_Else_Or_Trivial_True --
3813 -----------------------------
3815 function No_Else_Or_Trivial_True
(If_Expr
: Node_Id
) return Boolean is
3816 Else_Expr
: constant Node_Id
:=
3817 Next
(Next
(First
(Expressions
(If_Expr
))));
3821 or else (Compile_Time_Known_Value
(Else_Expr
)
3822 and then Is_True
(Expr_Value
(Else_Expr
)));
3823 end No_Else_Or_Trivial_True
;
3827 Cond
: constant Node_Id
:= Condition
(N
);
3828 Loop_Id
: Entity_Id
;
3829 QE_Scop
: Entity_Id
;
3831 -- Start of processing for Analyze_Quantified_Expression
3834 Check_SPARK_05_Restriction
("quantified expression is not allowed", N
);
3836 -- Create a scope to emulate the loop-like behavior of the quantified
3837 -- expression. The scope is needed to provide proper visibility of the
3840 QE_Scop
:= New_Internal_Entity
(E_Loop
, Current_Scope
, Sloc
(N
), 'L');
3841 Set_Etype
(QE_Scop
, Standard_Void_Type
);
3842 Set_Scope
(QE_Scop
, Current_Scope
);
3843 Set_Parent
(QE_Scop
, N
);
3845 Push_Scope
(QE_Scop
);
3847 -- All constituents are preanalyzed and resolved to avoid untimely
3848 -- generation of various temporaries and types. Full analysis and
3849 -- expansion is carried out when the quantified expression is
3850 -- transformed into an expression with actions.
3852 if Present
(Iterator_Specification
(N
)) then
3853 Preanalyze
(Iterator_Specification
(N
));
3855 -- Do not proceed with the analysis when the range of iteration is
3856 -- empty. The appropriate error is issued by Is_Empty_Range.
3858 if Is_Entity_Name
(Name
(Iterator_Specification
(N
)))
3859 and then Is_Empty_Range
(Etype
(Name
(Iterator_Specification
(N
))))
3864 else pragma Assert
(Present
(Loop_Parameter_Specification
(N
)));
3866 Loop_Par
: constant Node_Id
:= Loop_Parameter_Specification
(N
);
3869 Preanalyze
(Loop_Par
);
3871 if Nkind
(Discrete_Subtype_Definition
(Loop_Par
)) = N_Function_Call
3872 and then Parent
(Loop_Par
) /= N
3874 -- The parser cannot distinguish between a loop specification
3875 -- and an iterator specification. If after pre-analysis the
3876 -- proper form has been recognized, rewrite the expression to
3877 -- reflect the right kind. This is needed for proper ASIS
3878 -- navigation. If expansion is enabled, the transformation is
3879 -- performed when the expression is rewritten as a loop.
3881 Set_Iterator_Specification
(N
,
3882 New_Copy_Tree
(Iterator_Specification
(Parent
(Loop_Par
))));
3884 Set_Defining_Identifier
(Iterator_Specification
(N
),
3885 Relocate_Node
(Defining_Identifier
(Loop_Par
)));
3886 Set_Name
(Iterator_Specification
(N
),
3887 Relocate_Node
(Discrete_Subtype_Definition
(Loop_Par
)));
3888 Set_Comes_From_Source
(Iterator_Specification
(N
),
3889 Comes_From_Source
(Loop_Parameter_Specification
(N
)));
3890 Set_Loop_Parameter_Specification
(N
, Empty
);
3895 Preanalyze_And_Resolve
(Cond
, Standard_Boolean
);
3898 Set_Etype
(N
, Standard_Boolean
);
3900 -- Verify that the loop variable is used within the condition of the
3901 -- quantified expression.
3903 if Present
(Iterator_Specification
(N
)) then
3904 Loop_Id
:= Defining_Identifier
(Iterator_Specification
(N
));
3906 Loop_Id
:= Defining_Identifier
(Loop_Parameter_Specification
(N
));
3909 if Warn_On_Suspicious_Contract
3910 and then not Referenced
(Loop_Id
, Cond
)
3912 Error_Msg_N
("?T?unused variable &", Loop_Id
);
3915 -- Diagnose a possible misuse of the SOME existential quantifier. When
3916 -- we have a quantified expression of the form:
3918 -- for some X => (if P then Q [else True])
3920 -- any value for X that makes P False results in the if expression being
3921 -- trivially True, and so also results in the quantified expression
3922 -- being trivially True.
3924 if Warn_On_Suspicious_Contract
3925 and then not All_Present
(N
)
3926 and then Nkind
(Cond
) = N_If_Expression
3927 and then No_Else_Or_Trivial_True
(Cond
)
3929 Error_Msg_N
("?T?suspicious expression", N
);
3930 Error_Msg_N
("\\did you mean (for all X ='> (if P then Q))", N
);
3931 Error_Msg_N
("\\or (for some X ='> P and then Q) instead'?", N
);
3933 end Analyze_Quantified_Expression
;
3939 procedure Analyze_Range
(N
: Node_Id
) is
3940 L
: constant Node_Id
:= Low_Bound
(N
);
3941 H
: constant Node_Id
:= High_Bound
(N
);
3942 I1
, I2
: Interp_Index
;
3945 procedure Check_Common_Type
(T1
, T2
: Entity_Id
);
3946 -- Verify the compatibility of two types, and choose the
3947 -- non universal one if the other is universal.
3949 procedure Check_High_Bound
(T
: Entity_Id
);
3950 -- Test one interpretation of the low bound against all those
3951 -- of the high bound.
3953 procedure Check_Universal_Expression
(N
: Node_Id
);
3954 -- In Ada 83, reject bounds of a universal range that are not literals
3957 -----------------------
3958 -- Check_Common_Type --
3959 -----------------------
3961 procedure Check_Common_Type
(T1
, T2
: Entity_Id
) is
3963 if Covers
(T1
=> T1
, T2
=> T2
)
3965 Covers
(T1
=> T2
, T2
=> T1
)
3967 if T1
= Universal_Integer
3968 or else T1
= Universal_Real
3969 or else T1
= Any_Character
3971 Add_One_Interp
(N
, Base_Type
(T2
), Base_Type
(T2
));
3974 Add_One_Interp
(N
, T1
, T1
);
3977 Add_One_Interp
(N
, Base_Type
(T1
), Base_Type
(T1
));
3980 end Check_Common_Type
;
3982 ----------------------
3983 -- Check_High_Bound --
3984 ----------------------
3986 procedure Check_High_Bound
(T
: Entity_Id
) is
3988 if not Is_Overloaded
(H
) then
3989 Check_Common_Type
(T
, Etype
(H
));
3991 Get_First_Interp
(H
, I2
, It2
);
3992 while Present
(It2
.Typ
) loop
3993 Check_Common_Type
(T
, It2
.Typ
);
3994 Get_Next_Interp
(I2
, It2
);
3997 end Check_High_Bound
;
3999 -----------------------------
4000 -- Is_Universal_Expression --
4001 -----------------------------
4003 procedure Check_Universal_Expression
(N
: Node_Id
) is
4005 if Etype
(N
) = Universal_Integer
4006 and then Nkind
(N
) /= N_Integer_Literal
4007 and then not Is_Entity_Name
(N
)
4008 and then Nkind
(N
) /= N_Attribute_Reference
4010 Error_Msg_N
("illegal bound in discrete range", N
);
4012 end Check_Universal_Expression
;
4014 -- Start of processing for Analyze_Range
4017 Set_Etype
(N
, Any_Type
);
4018 Analyze_Expression
(L
);
4019 Analyze_Expression
(H
);
4021 if Etype
(L
) = Any_Type
or else Etype
(H
) = Any_Type
then
4025 if not Is_Overloaded
(L
) then
4026 Check_High_Bound
(Etype
(L
));
4028 Get_First_Interp
(L
, I1
, It1
);
4029 while Present
(It1
.Typ
) loop
4030 Check_High_Bound
(It1
.Typ
);
4031 Get_Next_Interp
(I1
, It1
);
4035 -- If result is Any_Type, then we did not find a compatible pair
4037 if Etype
(N
) = Any_Type
then
4038 Error_Msg_N
("incompatible types in range ", N
);
4042 if Ada_Version
= Ada_83
4044 (Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
4045 or else Nkind
(Parent
(N
)) = N_Constrained_Array_Definition
)
4047 Check_Universal_Expression
(L
);
4048 Check_Universal_Expression
(H
);
4051 Check_Function_Writable_Actuals
(N
);
4054 -----------------------
4055 -- Analyze_Reference --
4056 -----------------------
4058 procedure Analyze_Reference
(N
: Node_Id
) is
4059 P
: constant Node_Id
:= Prefix
(N
);
4062 Acc_Type
: Entity_Id
;
4067 -- An interesting error check, if we take the 'Ref of an object for
4068 -- which a pragma Atomic or Volatile has been given, and the type of the
4069 -- object is not Atomic or Volatile, then we are in trouble. The problem
4070 -- is that no trace of the atomic/volatile status will remain for the
4071 -- backend to respect when it deals with the resulting pointer, since
4072 -- the pointer type will not be marked atomic (it is a pointer to the
4073 -- base type of the object).
4075 -- It is not clear if that can ever occur, but in case it does, we will
4076 -- generate an error message. Not clear if this message can ever be
4077 -- generated, and pretty clear that it represents a bug if it is, still
4078 -- seems worth checking, except in CodePeer mode where we do not really
4079 -- care and don't want to bother the user.
4083 if Is_Entity_Name
(P
)
4084 and then Is_Object_Reference
(P
)
4085 and then not CodePeer_Mode
4090 if (Has_Atomic_Components
(E
)
4091 and then not Has_Atomic_Components
(T
))
4093 (Has_Volatile_Components
(E
)
4094 and then not Has_Volatile_Components
(T
))
4095 or else (Is_Atomic
(E
) and then not Is_Atomic
(T
))
4096 or else (Is_Volatile
(E
) and then not Is_Volatile
(T
))
4098 Error_Msg_N
("cannot take reference to Atomic/Volatile object", N
);
4102 -- Carry on with normal processing
4104 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
4105 Set_Etype
(Acc_Type
, Acc_Type
);
4106 Set_Directly_Designated_Type
(Acc_Type
, Etype
(P
));
4107 Set_Etype
(N
, Acc_Type
);
4108 end Analyze_Reference
;
4110 --------------------------------
4111 -- Analyze_Selected_Component --
4112 --------------------------------
4114 -- Prefix is a record type or a task or protected type. In the latter case,
4115 -- the selector must denote a visible entry.
4117 procedure Analyze_Selected_Component
(N
: Node_Id
) is
4118 Name
: constant Node_Id
:= Prefix
(N
);
4119 Sel
: constant Node_Id
:= Selector_Name
(N
);
4122 Has_Candidate
: Boolean := False;
4125 Pent
: Entity_Id
:= Empty
;
4126 Prefix_Type
: Entity_Id
;
4128 Type_To_Use
: Entity_Id
;
4129 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
4130 -- a class-wide type, we use its root type, whose components are
4131 -- present in the class-wide type.
4133 Is_Single_Concurrent_Object
: Boolean;
4134 -- Set True if the prefix is a single task or a single protected object
4136 procedure Find_Component_In_Instance
(Rec
: Entity_Id
);
4137 -- In an instance, a component of a private extension may not be visible
4138 -- while it was visible in the generic. Search candidate scope for a
4139 -- component with the proper identifier. This is only done if all other
4140 -- searches have failed. If a match is found, the Etype of both N and
4141 -- Sel are set from this component, and the entity of Sel is set to
4142 -- reference this component. If no match is found, Entity (Sel) remains
4143 -- unset. For a derived type that is an actual of the instance, the
4144 -- desired component may be found in any ancestor.
4146 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean;
4147 -- It is known that the parent of N denotes a subprogram call. Comp
4148 -- is an overloadable component of the concurrent type of the prefix.
4149 -- Determine whether all formals of the parent of N and Comp are mode
4150 -- conformant. If the parent node is not analyzed yet it may be an
4151 -- indexed component rather than a function call.
4153 function Has_Dereference
(Nod
: Node_Id
) return Boolean;
4154 -- Check whether prefix includes a dereference at any level.
4156 --------------------------------
4157 -- Find_Component_In_Instance --
4158 --------------------------------
4160 procedure Find_Component_In_Instance
(Rec
: Entity_Id
) is
4166 while Present
(Typ
) loop
4167 Comp
:= First_Component
(Typ
);
4168 while Present
(Comp
) loop
4169 if Chars
(Comp
) = Chars
(Sel
) then
4170 Set_Entity_With_Checks
(Sel
, Comp
);
4171 Set_Etype
(Sel
, Etype
(Comp
));
4172 Set_Etype
(N
, Etype
(Comp
));
4176 Next_Component
(Comp
);
4179 -- If not found, the component may be declared in the parent
4180 -- type or its full view, if any.
4182 if Is_Derived_Type
(Typ
) then
4185 if Is_Private_Type
(Typ
) then
4186 Typ
:= Full_View
(Typ
);
4194 -- If we fall through, no match, so no changes made
4197 end Find_Component_In_Instance
;
4199 ------------------------------
4200 -- Has_Mode_Conformant_Spec --
4201 ------------------------------
4203 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean is
4204 Comp_Param
: Entity_Id
;
4206 Param_Typ
: Entity_Id
;
4209 Comp_Param
:= First_Formal
(Comp
);
4211 if Nkind
(Parent
(N
)) = N_Indexed_Component
then
4212 Param
:= First
(Expressions
(Parent
(N
)));
4214 Param
:= First
(Parameter_Associations
(Parent
(N
)));
4217 while Present
(Comp_Param
)
4218 and then Present
(Param
)
4220 Param_Typ
:= Find_Parameter_Type
(Param
);
4222 if Present
(Param_Typ
)
4224 not Conforming_Types
4225 (Etype
(Comp_Param
), Param_Typ
, Mode_Conformant
)
4230 Next_Formal
(Comp_Param
);
4234 -- One of the specs has additional formals; there is no match, unless
4235 -- this may be an indexing of a parameterless call.
4237 -- Note that when expansion is disabled, the corresponding record
4238 -- type of synchronized types is not constructed, so that there is
4239 -- no point is attempting an interpretation as a prefixed call, as
4240 -- this is bound to fail because the primitive operations will not
4241 -- be properly located.
4243 if Present
(Comp_Param
) or else Present
(Param
) then
4244 if Needs_No_Actuals
(Comp
)
4245 and then Is_Array_Type
(Etype
(Comp
))
4246 and then not Expander_Active
4255 end Has_Mode_Conformant_Spec
;
4257 ---------------------
4258 -- Has_Dereference --
4259 ---------------------
4261 function Has_Dereference
(Nod
: Node_Id
) return Boolean is
4263 if Nkind
(Nod
) = N_Explicit_Dereference
then
4266 -- When expansion is disabled an explicit dereference may not have
4267 -- been inserted, but if this is an access type the indirection makes
4270 elsif Is_Access_Type
(Etype
(Nod
)) then
4273 elsif Nkind_In
(Nod
, N_Indexed_Component
, N_Selected_Component
) then
4274 return Has_Dereference
(Prefix
(Nod
));
4279 end Has_Dereference
;
4281 -- Start of processing for Analyze_Selected_Component
4284 Set_Etype
(N
, Any_Type
);
4286 if Is_Overloaded
(Name
) then
4287 Analyze_Overloaded_Selected_Component
(N
);
4290 elsif Etype
(Name
) = Any_Type
then
4291 Set_Entity
(Sel
, Any_Id
);
4292 Set_Etype
(Sel
, Any_Type
);
4296 Prefix_Type
:= Etype
(Name
);
4299 if Is_Access_Type
(Prefix_Type
) then
4301 -- A RACW object can never be used as prefix of a selected component
4302 -- since that means it is dereferenced without being a controlling
4303 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
4304 -- reporting an error, we must check whether this is actually a
4305 -- dispatching call in prefix form.
4307 if Is_Remote_Access_To_Class_Wide_Type
(Prefix_Type
)
4308 and then Comes_From_Source
(N
)
4310 if Try_Object_Operation
(N
) then
4314 ("invalid dereference of a remote access-to-class-wide value",
4318 -- Normal case of selected component applied to access type
4321 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4323 if Is_Entity_Name
(Name
) then
4324 Pent
:= Entity
(Name
);
4325 elsif Nkind
(Name
) = N_Selected_Component
4326 and then Is_Entity_Name
(Selector_Name
(Name
))
4328 Pent
:= Entity
(Selector_Name
(Name
));
4331 Prefix_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, Name
);
4334 -- If we have an explicit dereference of a remote access-to-class-wide
4335 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
4336 -- have to check for the case of a prefix that is a controlling operand
4337 -- of a prefixed dispatching call, as the dereference is legal in that
4338 -- case. Normally this condition is checked in Validate_Remote_Access_
4339 -- To_Class_Wide_Type, but we have to defer the checking for selected
4340 -- component prefixes because of the prefixed dispatching call case.
4341 -- Note that implicit dereferences are checked for this just above.
4343 elsif Nkind
(Name
) = N_Explicit_Dereference
4344 and then Is_Remote_Access_To_Class_Wide_Type
(Etype
(Prefix
(Name
)))
4345 and then Comes_From_Source
(N
)
4347 if Try_Object_Operation
(N
) then
4351 ("invalid dereference of a remote access-to-class-wide value",
4356 -- (Ada 2005): if the prefix is the limited view of a type, and
4357 -- the context already includes the full view, use the full view
4358 -- in what follows, either to retrieve a component of to find
4359 -- a primitive operation. If the prefix is an explicit dereference,
4360 -- set the type of the prefix to reflect this transformation.
4361 -- If the non-limited view is itself an incomplete type, get the
4362 -- full view if available.
4364 if From_Limited_With
(Prefix_Type
)
4365 and then Has_Non_Limited_View
(Prefix_Type
)
4367 Prefix_Type
:= Get_Full_View
(Non_Limited_View
(Prefix_Type
));
4369 if Nkind
(N
) = N_Explicit_Dereference
then
4370 Set_Etype
(Prefix
(N
), Prefix_Type
);
4374 if Ekind
(Prefix_Type
) = E_Private_Subtype
then
4375 Prefix_Type
:= Base_Type
(Prefix_Type
);
4378 Type_To_Use
:= Prefix_Type
;
4380 -- For class-wide types, use the entity list of the root type. This
4381 -- indirection is specially important for private extensions because
4382 -- only the root type get switched (not the class-wide type).
4384 if Is_Class_Wide_Type
(Prefix_Type
) then
4385 Type_To_Use
:= Root_Type
(Prefix_Type
);
4388 -- If the prefix is a single concurrent object, use its name in error
4389 -- messages, rather than that of its anonymous type.
4391 Is_Single_Concurrent_Object
:=
4392 Is_Concurrent_Type
(Prefix_Type
)
4393 and then Is_Internal_Name
(Chars
(Prefix_Type
))
4394 and then not Is_Derived_Type
(Prefix_Type
)
4395 and then Is_Entity_Name
(Name
);
4397 Comp
:= First_Entity
(Type_To_Use
);
4399 -- If the selector has an original discriminant, the node appears in
4400 -- an instance. Replace the discriminant with the corresponding one
4401 -- in the current discriminated type. For nested generics, this must
4402 -- be done transitively, so note the new original discriminant.
4404 if Nkind
(Sel
) = N_Identifier
4405 and then In_Instance
4406 and then Present
(Original_Discriminant
(Sel
))
4408 Comp
:= Find_Corresponding_Discriminant
(Sel
, Prefix_Type
);
4410 -- Mark entity before rewriting, for completeness and because
4411 -- subsequent semantic checks might examine the original node.
4413 Set_Entity
(Sel
, Comp
);
4414 Rewrite
(Selector_Name
(N
), New_Occurrence_Of
(Comp
, Sloc
(N
)));
4415 Set_Original_Discriminant
(Selector_Name
(N
), Comp
);
4416 Set_Etype
(N
, Etype
(Comp
));
4417 Check_Implicit_Dereference
(N
, Etype
(Comp
));
4419 if Is_Access_Type
(Etype
(Name
)) then
4420 Insert_Explicit_Dereference
(Name
);
4421 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4424 elsif Is_Record_Type
(Prefix_Type
) then
4426 -- Find component with given name. In an instance, if the node is
4427 -- known as a prefixed call, do not examine components whose
4428 -- visibility may be accidental.
4430 while Present
(Comp
) and then not Is_Prefixed_Call
(N
) loop
4431 if Chars
(Comp
) = Chars
(Sel
)
4432 and then Is_Visible_Component
(Comp
, N
)
4434 Set_Entity_With_Checks
(Sel
, Comp
);
4435 Set_Etype
(Sel
, Etype
(Comp
));
4437 if Ekind
(Comp
) = E_Discriminant
then
4438 if Is_Unchecked_Union
(Base_Type
(Prefix_Type
)) then
4440 ("cannot reference discriminant of unchecked union",
4444 if Is_Generic_Type
(Prefix_Type
)
4446 Is_Generic_Type
(Root_Type
(Prefix_Type
))
4448 Set_Original_Discriminant
(Sel
, Comp
);
4452 -- Resolve the prefix early otherwise it is not possible to
4453 -- build the actual subtype of the component: it may need
4454 -- to duplicate this prefix and duplication is only allowed
4455 -- on fully resolved expressions.
4459 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
4460 -- subtypes in a package specification.
4463 -- limited with Pkg;
4465 -- type Acc_Inc is access Pkg.T;
4467 -- N : Natural := X.all.Comp; -- ERROR, limited view
4468 -- end Pkg; -- Comp is not visible
4470 if Nkind
(Name
) = N_Explicit_Dereference
4471 and then From_Limited_With
(Etype
(Prefix
(Name
)))
4472 and then not Is_Potentially_Use_Visible
(Etype
(Name
))
4473 and then Nkind
(Parent
(Cunit_Entity
(Current_Sem_Unit
))) =
4474 N_Package_Specification
4477 ("premature usage of incomplete}", Prefix
(Name
),
4478 Etype
(Prefix
(Name
)));
4481 -- We never need an actual subtype for the case of a selection
4482 -- for a indexed component of a non-packed array, since in
4483 -- this case gigi generates all the checks and can find the
4484 -- necessary bounds information.
4486 -- We also do not need an actual subtype for the case of a
4487 -- first, last, length, or range attribute applied to a
4488 -- non-packed array, since gigi can again get the bounds in
4489 -- these cases (gigi cannot handle the packed case, since it
4490 -- has the bounds of the packed array type, not the original
4491 -- bounds of the type). However, if the prefix is itself a
4492 -- selected component, as in a.b.c (i), gigi may regard a.b.c
4493 -- as a dynamic-sized temporary, so we do generate an actual
4494 -- subtype for this case.
4496 Parent_N
:= Parent
(N
);
4498 if not Is_Packed
(Etype
(Comp
))
4500 ((Nkind
(Parent_N
) = N_Indexed_Component
4501 and then Nkind
(Name
) /= N_Selected_Component
)
4503 (Nkind
(Parent_N
) = N_Attribute_Reference
4505 Nam_In
(Attribute_Name
(Parent_N
), Name_First
,
4510 Set_Etype
(N
, Etype
(Comp
));
4512 -- If full analysis is not enabled, we do not generate an
4513 -- actual subtype, because in the absence of expansion
4514 -- reference to a formal of a protected type, for example,
4515 -- will not be properly transformed, and will lead to
4516 -- out-of-scope references in gigi.
4518 -- In all other cases, we currently build an actual subtype.
4519 -- It seems likely that many of these cases can be avoided,
4520 -- but right now, the front end makes direct references to the
4521 -- bounds (e.g. in generating a length check), and if we do
4522 -- not make an actual subtype, we end up getting a direct
4523 -- reference to a discriminant, which will not do.
4525 elsif Full_Analysis
then
4527 Build_Actual_Subtype_Of_Component
(Etype
(Comp
), N
);
4528 Insert_Action
(N
, Act_Decl
);
4530 if No
(Act_Decl
) then
4531 Set_Etype
(N
, Etype
(Comp
));
4534 -- Component type depends on discriminants. Enter the
4535 -- main attributes of the subtype.
4538 Subt
: constant Entity_Id
:=
4539 Defining_Identifier
(Act_Decl
);
4542 Set_Etype
(Subt
, Base_Type
(Etype
(Comp
)));
4543 Set_Ekind
(Subt
, Ekind
(Etype
(Comp
)));
4544 Set_Etype
(N
, Subt
);
4548 -- If Full_Analysis not enabled, just set the Etype
4551 Set_Etype
(N
, Etype
(Comp
));
4554 Check_Implicit_Dereference
(N
, Etype
(N
));
4558 -- If the prefix is a private extension, check only the visible
4559 -- components of the partial view. This must include the tag,
4560 -- which can appear in expanded code in a tag check.
4562 if Ekind
(Type_To_Use
) = E_Record_Type_With_Private
4563 and then Chars
(Selector_Name
(N
)) /= Name_uTag
4565 exit when Comp
= Last_Entity
(Type_To_Use
);
4571 -- Ada 2005 (AI-252): The selected component can be interpreted as
4572 -- a prefixed view of a subprogram. Depending on the context, this is
4573 -- either a name that can appear in a renaming declaration, or part
4574 -- of an enclosing call given in prefix form.
4576 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
4577 -- selected component should resolve to a name.
4579 if Ada_Version
>= Ada_2005
4580 and then Is_Tagged_Type
(Prefix_Type
)
4581 and then not Is_Concurrent_Type
(Prefix_Type
)
4583 if Nkind
(Parent
(N
)) = N_Generic_Association
4584 or else Nkind
(Parent
(N
)) = N_Requeue_Statement
4585 or else Nkind
(Parent
(N
)) = N_Subprogram_Renaming_Declaration
4587 if Find_Primitive_Operation
(N
) then
4591 elsif Try_Object_Operation
(N
) then
4595 -- If the transformation fails, it will be necessary to redo the
4596 -- analysis with all errors enabled, to indicate candidate
4597 -- interpretations and reasons for each failure ???
4601 elsif Is_Private_Type
(Prefix_Type
) then
4603 -- Allow access only to discriminants of the type. If the type has
4604 -- no full view, gigi uses the parent type for the components, so we
4605 -- do the same here.
4607 if No
(Full_View
(Prefix_Type
)) then
4608 Type_To_Use
:= Root_Type
(Base_Type
(Prefix_Type
));
4609 Comp
:= First_Entity
(Type_To_Use
);
4612 while Present
(Comp
) loop
4613 if Chars
(Comp
) = Chars
(Sel
) then
4614 if Ekind
(Comp
) = E_Discriminant
then
4615 Set_Entity_With_Checks
(Sel
, Comp
);
4616 Generate_Reference
(Comp
, Sel
);
4618 Set_Etype
(Sel
, Etype
(Comp
));
4619 Set_Etype
(N
, Etype
(Comp
));
4620 Check_Implicit_Dereference
(N
, Etype
(N
));
4622 if Is_Generic_Type
(Prefix_Type
)
4623 or else Is_Generic_Type
(Root_Type
(Prefix_Type
))
4625 Set_Original_Discriminant
(Sel
, Comp
);
4628 -- Before declaring an error, check whether this is tagged
4629 -- private type and a call to a primitive operation.
4631 elsif Ada_Version
>= Ada_2005
4632 and then Is_Tagged_Type
(Prefix_Type
)
4633 and then Try_Object_Operation
(N
)
4638 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4639 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
4640 Set_Entity
(Sel
, Any_Id
);
4641 Set_Etype
(N
, Any_Type
);
4650 elsif Is_Concurrent_Type
(Prefix_Type
) then
4652 -- Find visible operation with given name. For a protected type,
4653 -- the possible candidates are discriminants, entries or protected
4654 -- procedures. For a task type, the set can only include entries or
4655 -- discriminants if the task type is not an enclosing scope. If it
4656 -- is an enclosing scope (e.g. in an inner task) then all entities
4657 -- are visible, but the prefix must denote the enclosing scope, i.e.
4658 -- can only be a direct name or an expanded name.
4660 Set_Etype
(Sel
, Any_Type
);
4661 In_Scope
:= In_Open_Scopes
(Prefix_Type
);
4663 while Present
(Comp
) loop
4664 if Chars
(Comp
) = Chars
(Sel
) then
4665 if Is_Overloadable
(Comp
) then
4666 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
4668 -- If the prefix is tagged, the correct interpretation may
4669 -- lie in the primitive or class-wide operations of the
4670 -- type. Perform a simple conformance check to determine
4671 -- whether Try_Object_Operation should be invoked even if
4672 -- a visible entity is found.
4674 if Is_Tagged_Type
(Prefix_Type
)
4676 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
4678 N_Indexed_Component
)
4679 and then Has_Mode_Conformant_Spec
(Comp
)
4681 Has_Candidate
:= True;
4684 -- Note: a selected component may not denote a component of a
4685 -- protected type (4.1.3(7)).
4687 elsif Ekind_In
(Comp
, E_Discriminant
, E_Entry_Family
)
4689 and then not Is_Protected_Type
(Prefix_Type
)
4690 and then Is_Entity_Name
(Name
))
4692 Set_Entity_With_Checks
(Sel
, Comp
);
4693 Generate_Reference
(Comp
, Sel
);
4695 -- The selector is not overloadable, so we have a candidate
4698 Has_Candidate
:= True;
4704 Set_Etype
(Sel
, Etype
(Comp
));
4705 Set_Etype
(N
, Etype
(Comp
));
4707 if Ekind
(Comp
) = E_Discriminant
then
4708 Set_Original_Discriminant
(Sel
, Comp
);
4711 -- For access type case, introduce explicit dereference for
4712 -- more uniform treatment of entry calls.
4714 if Is_Access_Type
(Etype
(Name
)) then
4715 Insert_Explicit_Dereference
(Name
);
4717 (Warn_On_Dereference
, "?d?implicit dereference", N
);
4723 exit when not In_Scope
4725 Comp
= First_Private_Entity
(Base_Type
(Prefix_Type
));
4728 -- If the scope is a current instance, the prefix cannot be an
4729 -- expression of the same type, unless the selector designates a
4730 -- public operation (otherwise that would represent an attempt to
4731 -- reach an internal entity of another synchronized object).
4732 -- This is legal if prefix is an access to such type and there is
4733 -- a dereference, or is a component with a dereferenced prefix.
4734 -- It is also legal if the prefix is a component of a task type,
4735 -- and the selector is one of the task operations.
4738 and then not Is_Entity_Name
(Name
)
4739 and then not Has_Dereference
(Name
)
4741 if Is_Task_Type
(Prefix_Type
)
4742 and then Present
(Entity
(Sel
))
4743 and then Ekind_In
(Entity
(Sel
), E_Entry
, E_Entry_Family
)
4749 ("invalid reference to internal operation of some object of "
4750 & "type &", N
, Type_To_Use
);
4751 Set_Entity
(Sel
, Any_Id
);
4752 Set_Etype
(Sel
, Any_Type
);
4757 -- If there is no visible entity with the given name or none of the
4758 -- visible entities are plausible interpretations, check whether
4759 -- there is some other primitive operation with that name.
4761 if Ada_Version
>= Ada_2005
and then Is_Tagged_Type
(Prefix_Type
) then
4762 if (Etype
(N
) = Any_Type
4763 or else not Has_Candidate
)
4764 and then Try_Object_Operation
(N
)
4768 -- If the context is not syntactically a procedure call, it
4769 -- may be a call to a primitive function declared outside of
4770 -- the synchronized type.
4772 -- If the context is a procedure call, there might still be
4773 -- an overloading between an entry and a primitive procedure
4774 -- declared outside of the synchronized type, called in prefix
4775 -- notation. This is harder to disambiguate because in one case
4776 -- the controlling formal is implicit ???
4778 elsif Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
4779 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
4780 and then Try_Object_Operation
(N
)
4785 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
4786 -- entry or procedure of a tagged concurrent type we must check
4787 -- if there are class-wide subprograms covering the primitive. If
4788 -- true then Try_Object_Operation reports the error.
4791 and then Is_Concurrent_Type
(Prefix_Type
)
4792 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
4794 -- Duplicate the call. This is required to avoid problems with
4795 -- the tree transformations performed by Try_Object_Operation.
4796 -- Set properly the parent of the copied call, because it is
4797 -- about to be reanalyzed.
4800 Par
: constant Node_Id
:= New_Copy_Tree
(Parent
(N
));
4803 Set_Parent
(Par
, Parent
(Parent
(N
)));
4805 if Try_Object_Operation
4806 (Sinfo
.Name
(Par
), CW_Test_Only
=> True)
4814 if Etype
(N
) = Any_Type
and then Is_Protected_Type
(Prefix_Type
) then
4816 -- Case of a prefix of a protected type: selector might denote
4817 -- an invisible private component.
4819 Comp
:= First_Private_Entity
(Base_Type
(Prefix_Type
));
4820 while Present
(Comp
) and then Chars
(Comp
) /= Chars
(Sel
) loop
4824 if Present
(Comp
) then
4825 if Is_Single_Concurrent_Object
then
4826 Error_Msg_Node_2
:= Entity
(Name
);
4827 Error_Msg_NE
("invisible selector& for &", N
, Sel
);
4830 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4831 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
4837 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
4842 Error_Msg_NE
("invalid prefix in selected component&", N
, Sel
);
4845 -- If N still has no type, the component is not defined in the prefix
4847 if Etype
(N
) = Any_Type
then
4849 if Is_Single_Concurrent_Object
then
4850 Error_Msg_Node_2
:= Entity
(Name
);
4851 Error_Msg_NE
("no selector& for&", N
, Sel
);
4853 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
4855 -- If this is a derived formal type, the parent may have different
4856 -- visibility at this point. Try for an inherited component before
4857 -- reporting an error.
4859 elsif Is_Generic_Type
(Prefix_Type
)
4860 and then Ekind
(Prefix_Type
) = E_Record_Type_With_Private
4861 and then Prefix_Type
/= Etype
(Prefix_Type
)
4862 and then Is_Record_Type
(Etype
(Prefix_Type
))
4864 Set_Etype
(Prefix
(N
), Etype
(Prefix_Type
));
4865 Analyze_Selected_Component
(N
);
4868 -- Similarly, if this is the actual for a formal derived type, or
4869 -- a derived type thereof, the component inherited from the generic
4870 -- parent may not be visible in the actual, but the selected
4871 -- component is legal. Climb up the derivation chain of the generic
4872 -- parent type until we find the proper ancestor type.
4874 elsif In_Instance
and then Is_Tagged_Type
(Prefix_Type
) then
4876 Par
: Entity_Id
:= Prefix_Type
;
4878 -- Climb up derivation chain to generic actual subtype
4880 while not Is_Generic_Actual_Type
(Par
) loop
4881 if Ekind
(Par
) = E_Record_Type
then
4882 Par
:= Parent_Subtype
(Par
);
4885 exit when Par
= Etype
(Par
);
4890 if Present
(Par
) and then Is_Generic_Actual_Type
(Par
) then
4892 -- Now look for component in ancestor types
4894 Par
:= Generic_Parent_Type
(Declaration_Node
(Par
));
4896 Find_Component_In_Instance
(Par
);
4897 exit when Present
(Entity
(Sel
))
4898 or else Par
= Etype
(Par
);
4902 -- Another special case: the type is an extension of a private
4903 -- type T, is an actual in an instance, and we are in the body
4904 -- of the instance, so the generic body had a full view of the
4905 -- type declaration for T or of some ancestor that defines the
4906 -- component in question.
4908 elsif Is_Derived_Type
(Type_To_Use
)
4909 and then Used_As_Generic_Actual
(Type_To_Use
)
4910 and then In_Instance_Body
4912 Find_Component_In_Instance
(Parent_Subtype
(Type_To_Use
));
4914 -- In ASIS mode the generic parent type may be absent. Examine
4915 -- the parent type directly for a component that may have been
4916 -- visible in a parent generic unit.
4918 elsif Is_Derived_Type
(Prefix_Type
) then
4919 Par
:= Etype
(Prefix_Type
);
4920 Find_Component_In_Instance
(Par
);
4924 -- The search above must have eventually succeeded, since the
4925 -- selected component was legal in the generic.
4927 if No
(Entity
(Sel
)) then
4928 raise Program_Error
;
4933 -- Component not found, specialize error message when appropriate
4936 if Ekind
(Prefix_Type
) = E_Record_Subtype
then
4938 -- Check whether this is a component of the base type which
4939 -- is absent from a statically constrained subtype. This will
4940 -- raise constraint error at run time, but is not a compile-
4941 -- time error. When the selector is illegal for base type as
4942 -- well fall through and generate a compilation error anyway.
4944 Comp
:= First_Component
(Base_Type
(Prefix_Type
));
4945 while Present
(Comp
) loop
4946 if Chars
(Comp
) = Chars
(Sel
)
4947 and then Is_Visible_Component
(Comp
)
4949 Set_Entity_With_Checks
(Sel
, Comp
);
4950 Generate_Reference
(Comp
, Sel
);
4951 Set_Etype
(Sel
, Etype
(Comp
));
4952 Set_Etype
(N
, Etype
(Comp
));
4954 -- Emit appropriate message. The node will be replaced
4955 -- by an appropriate raise statement.
4957 -- Note that in SPARK mode, as with all calls to apply a
4958 -- compile time constraint error, this will be made into
4959 -- an error to simplify the processing of the formal
4960 -- verification backend.
4962 Apply_Compile_Time_Constraint_Error
4963 (N
, "component not present in }??",
4964 CE_Discriminant_Check_Failed
,
4965 Ent
=> Prefix_Type
, Rep
=> False);
4967 Set_Raises_Constraint_Error
(N
);
4971 Next_Component
(Comp
);
4976 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4977 Error_Msg_NE
("no selector& for}", N
, Sel
);
4979 -- Add information in the case of an incomplete prefix
4981 if Is_Incomplete_Type
(Type_To_Use
) then
4983 Inc
: constant Entity_Id
:= First_Subtype
(Type_To_Use
);
4986 if From_Limited_With
(Scope
(Type_To_Use
)) then
4988 ("\limited view of& has no components", N
, Inc
);
4992 ("\premature usage of incomplete type&", N
, Inc
);
4994 if Nkind
(Parent
(Inc
)) =
4995 N_Incomplete_Type_Declaration
4997 -- Record location of premature use in entity so that
4998 -- a continuation message is generated when the
4999 -- completion is seen.
5001 Set_Premature_Use
(Parent
(Inc
), N
);
5007 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
5010 Set_Entity
(Sel
, Any_Id
);
5011 Set_Etype
(Sel
, Any_Type
);
5013 end Analyze_Selected_Component
;
5015 ---------------------------
5016 -- Analyze_Short_Circuit --
5017 ---------------------------
5019 procedure Analyze_Short_Circuit
(N
: Node_Id
) is
5020 L
: constant Node_Id
:= Left_Opnd
(N
);
5021 R
: constant Node_Id
:= Right_Opnd
(N
);
5026 Analyze_Expression
(L
);
5027 Analyze_Expression
(R
);
5028 Set_Etype
(N
, Any_Type
);
5030 if not Is_Overloaded
(L
) then
5031 if Root_Type
(Etype
(L
)) = Standard_Boolean
5032 and then Has_Compatible_Type
(R
, Etype
(L
))
5034 Add_One_Interp
(N
, Etype
(L
), Etype
(L
));
5038 Get_First_Interp
(L
, Ind
, It
);
5039 while Present
(It
.Typ
) loop
5040 if Root_Type
(It
.Typ
) = Standard_Boolean
5041 and then Has_Compatible_Type
(R
, It
.Typ
)
5043 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
5046 Get_Next_Interp
(Ind
, It
);
5050 -- Here we have failed to find an interpretation. Clearly we know that
5051 -- it is not the case that both operands can have an interpretation of
5052 -- Boolean, but this is by far the most likely intended interpretation.
5053 -- So we simply resolve both operands as Booleans, and at least one of
5054 -- these resolutions will generate an error message, and we do not need
5055 -- to give another error message on the short circuit operation itself.
5057 if Etype
(N
) = Any_Type
then
5058 Resolve
(L
, Standard_Boolean
);
5059 Resolve
(R
, Standard_Boolean
);
5060 Set_Etype
(N
, Standard_Boolean
);
5062 end Analyze_Short_Circuit
;
5068 procedure Analyze_Slice
(N
: Node_Id
) is
5069 D
: constant Node_Id
:= Discrete_Range
(N
);
5070 P
: constant Node_Id
:= Prefix
(N
);
5071 Array_Type
: Entity_Id
;
5072 Index_Type
: Entity_Id
;
5074 procedure Analyze_Overloaded_Slice
;
5075 -- If the prefix is overloaded, select those interpretations that
5076 -- yield a one-dimensional array type.
5078 ------------------------------
5079 -- Analyze_Overloaded_Slice --
5080 ------------------------------
5082 procedure Analyze_Overloaded_Slice
is
5088 Set_Etype
(N
, Any_Type
);
5090 Get_First_Interp
(P
, I
, It
);
5091 while Present
(It
.Nam
) loop
5094 if Is_Access_Type
(Typ
) then
5095 Typ
:= Designated_Type
(Typ
);
5097 (Warn_On_Dereference
, "?d?implicit dereference", N
);
5100 if Is_Array_Type
(Typ
)
5101 and then Number_Dimensions
(Typ
) = 1
5102 and then Has_Compatible_Type
(D
, Etype
(First_Index
(Typ
)))
5104 Add_One_Interp
(N
, Typ
, Typ
);
5107 Get_Next_Interp
(I
, It
);
5110 if Etype
(N
) = Any_Type
then
5111 Error_Msg_N
("expect array type in prefix of slice", N
);
5113 end Analyze_Overloaded_Slice
;
5115 -- Start of processing for Analyze_Slice
5118 if Comes_From_Source
(N
) then
5119 Check_SPARK_05_Restriction
("slice is not allowed", N
);
5125 if Is_Overloaded
(P
) then
5126 Analyze_Overloaded_Slice
;
5129 Array_Type
:= Etype
(P
);
5130 Set_Etype
(N
, Any_Type
);
5132 if Is_Access_Type
(Array_Type
) then
5133 Array_Type
:= Designated_Type
(Array_Type
);
5134 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
5137 if not Is_Array_Type
(Array_Type
) then
5138 Wrong_Type
(P
, Any_Array
);
5140 elsif Number_Dimensions
(Array_Type
) > 1 then
5142 ("type is not one-dimensional array in slice prefix", N
);
5145 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
5146 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
5148 Index_Type
:= Etype
(First_Index
(Array_Type
));
5151 if not Has_Compatible_Type
(D
, Index_Type
) then
5152 Wrong_Type
(D
, Index_Type
);
5154 Set_Etype
(N
, Array_Type
);
5160 -----------------------------
5161 -- Analyze_Type_Conversion --
5162 -----------------------------
5164 procedure Analyze_Type_Conversion
(N
: Node_Id
) is
5165 Expr
: constant Node_Id
:= Expression
(N
);
5169 -- If Conversion_OK is set, then the Etype is already set, and the only
5170 -- processing required is to analyze the expression. This is used to
5171 -- construct certain "illegal" conversions which are not allowed by Ada
5172 -- semantics, but can be handled by Gigi, see Sinfo for further details.
5174 if Conversion_OK
(N
) then
5179 -- Otherwise full type analysis is required, as well as some semantic
5180 -- checks to make sure the argument of the conversion is appropriate.
5182 Find_Type
(Subtype_Mark
(N
));
5183 Typ
:= Entity
(Subtype_Mark
(N
));
5185 Check_Fully_Declared
(Typ
, N
);
5186 Analyze_Expression
(Expr
);
5187 Validate_Remote_Type_Type_Conversion
(N
);
5189 -- Only remaining step is validity checks on the argument. These
5190 -- are skipped if the conversion does not come from the source.
5192 if not Comes_From_Source
(N
) then
5195 -- If there was an error in a generic unit, no need to replicate the
5196 -- error message. Conversely, constant-folding in the generic may
5197 -- transform the argument of a conversion into a string literal, which
5198 -- is legal. Therefore the following tests are not performed in an
5199 -- instance. The same applies to an inlined body.
5201 elsif In_Instance
or In_Inlined_Body
then
5204 elsif Nkind
(Expr
) = N_Null
then
5205 Error_Msg_N
("argument of conversion cannot be null", N
);
5206 Error_Msg_N
("\use qualified expression instead", N
);
5207 Set_Etype
(N
, Any_Type
);
5209 elsif Nkind
(Expr
) = N_Aggregate
then
5210 Error_Msg_N
("argument of conversion cannot be aggregate", N
);
5211 Error_Msg_N
("\use qualified expression instead", N
);
5213 elsif Nkind
(Expr
) = N_Allocator
then
5214 Error_Msg_N
("argument of conversion cannot be an allocator", N
);
5215 Error_Msg_N
("\use qualified expression instead", N
);
5217 elsif Nkind
(Expr
) = N_String_Literal
then
5218 Error_Msg_N
("argument of conversion cannot be string literal", N
);
5219 Error_Msg_N
("\use qualified expression instead", N
);
5221 elsif Nkind
(Expr
) = N_Character_Literal
then
5222 if Ada_Version
= Ada_83
then
5223 Resolve
(Expr
, Typ
);
5225 Error_Msg_N
("argument of conversion cannot be character literal",
5227 Error_Msg_N
("\use qualified expression instead", N
);
5230 elsif Nkind
(Expr
) = N_Attribute_Reference
5231 and then Nam_In
(Attribute_Name
(Expr
), Name_Access
,
5232 Name_Unchecked_Access
,
5233 Name_Unrestricted_Access
)
5235 Error_Msg_N
("argument of conversion cannot be access", N
);
5236 Error_Msg_N
("\use qualified expression instead", N
);
5239 -- A formal parameter of a specific tagged type whose related subprogram
5240 -- is subject to pragma Extensions_Visible with value "False" cannot
5241 -- appear in a class-wide conversion (SPARK RM 6.1.7(3)). Do not check
5242 -- internally generated expressions.
5244 if Is_Class_Wide_Type
(Typ
)
5245 and then Comes_From_Source
(Expr
)
5246 and then Is_EVF_Expression
(Expr
)
5249 ("formal parameter with Extensions_Visible False cannot be "
5250 & "converted to class-wide type", Expr
);
5252 end Analyze_Type_Conversion
;
5254 ----------------------
5255 -- Analyze_Unary_Op --
5256 ----------------------
5258 procedure Analyze_Unary_Op
(N
: Node_Id
) is
5259 R
: constant Node_Id
:= Right_Opnd
(N
);
5260 Op_Id
: Entity_Id
:= Entity
(N
);
5263 Set_Etype
(N
, Any_Type
);
5264 Candidate_Type
:= Empty
;
5266 Analyze_Expression
(R
);
5268 if Present
(Op_Id
) then
5269 if Ekind
(Op_Id
) = E_Operator
then
5270 Find_Unary_Types
(R
, Op_Id
, N
);
5272 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5276 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
5277 while Present
(Op_Id
) loop
5278 if Ekind
(Op_Id
) = E_Operator
then
5279 if No
(Next_Entity
(First_Entity
(Op_Id
))) then
5280 Find_Unary_Types
(R
, Op_Id
, N
);
5283 elsif Is_Overloadable
(Op_Id
) then
5284 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
5287 Op_Id
:= Homonym
(Op_Id
);
5292 end Analyze_Unary_Op
;
5294 ----------------------------------
5295 -- Analyze_Unchecked_Expression --
5296 ----------------------------------
5298 procedure Analyze_Unchecked_Expression
(N
: Node_Id
) is
5300 Analyze
(Expression
(N
), Suppress
=> All_Checks
);
5301 Set_Etype
(N
, Etype
(Expression
(N
)));
5302 Save_Interps
(Expression
(N
), N
);
5303 end Analyze_Unchecked_Expression
;
5305 ---------------------------------------
5306 -- Analyze_Unchecked_Type_Conversion --
5307 ---------------------------------------
5309 procedure Analyze_Unchecked_Type_Conversion
(N
: Node_Id
) is
5311 Find_Type
(Subtype_Mark
(N
));
5312 Analyze_Expression
(Expression
(N
));
5313 Set_Etype
(N
, Entity
(Subtype_Mark
(N
)));
5314 end Analyze_Unchecked_Type_Conversion
;
5316 ------------------------------------
5317 -- Analyze_User_Defined_Binary_Op --
5318 ------------------------------------
5320 procedure Analyze_User_Defined_Binary_Op
5325 -- Only do analysis if the operator Comes_From_Source, since otherwise
5326 -- the operator was generated by the expander, and all such operators
5327 -- always refer to the operators in package Standard.
5329 if Comes_From_Source
(N
) then
5331 F1
: constant Entity_Id
:= First_Formal
(Op_Id
);
5332 F2
: constant Entity_Id
:= Next_Formal
(F1
);
5335 -- Verify that Op_Id is a visible binary function. Note that since
5336 -- we know Op_Id is overloaded, potentially use visible means use
5337 -- visible for sure (RM 9.4(11)).
5339 if Ekind
(Op_Id
) = E_Function
5340 and then Present
(F2
)
5341 and then (Is_Immediately_Visible
(Op_Id
)
5342 or else Is_Potentially_Use_Visible
(Op_Id
))
5343 and then Has_Compatible_Type
(Left_Opnd
(N
), Etype
(F1
))
5344 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F2
))
5346 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5348 -- If the left operand is overloaded, indicate that the current
5349 -- type is a viable candidate. This is redundant in most cases,
5350 -- but for equality and comparison operators where the context
5351 -- does not impose a type on the operands, setting the proper
5352 -- type is necessary to avoid subsequent ambiguities during
5353 -- resolution, when both user-defined and predefined operators
5354 -- may be candidates.
5356 if Is_Overloaded
(Left_Opnd
(N
)) then
5357 Set_Etype
(Left_Opnd
(N
), Etype
(F1
));
5360 if Debug_Flag_E
then
5361 Write_Str
("user defined operator ");
5362 Write_Name
(Chars
(Op_Id
));
5363 Write_Str
(" on node ");
5364 Write_Int
(Int
(N
));
5370 end Analyze_User_Defined_Binary_Op
;
5372 -----------------------------------
5373 -- Analyze_User_Defined_Unary_Op --
5374 -----------------------------------
5376 procedure Analyze_User_Defined_Unary_Op
5381 -- Only do analysis if the operator Comes_From_Source, since otherwise
5382 -- the operator was generated by the expander, and all such operators
5383 -- always refer to the operators in package Standard.
5385 if Comes_From_Source
(N
) then
5387 F
: constant Entity_Id
:= First_Formal
(Op_Id
);
5390 -- Verify that Op_Id is a visible unary function. Note that since
5391 -- we know Op_Id is overloaded, potentially use visible means use
5392 -- visible for sure (RM 9.4(11)).
5394 if Ekind
(Op_Id
) = E_Function
5395 and then No
(Next_Formal
(F
))
5396 and then (Is_Immediately_Visible
(Op_Id
)
5397 or else Is_Potentially_Use_Visible
(Op_Id
))
5398 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F
))
5400 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5404 end Analyze_User_Defined_Unary_Op
;
5406 ---------------------------
5407 -- Check_Arithmetic_Pair --
5408 ---------------------------
5410 procedure Check_Arithmetic_Pair
5411 (T1
, T2
: Entity_Id
;
5415 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
5417 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean;
5418 -- Check whether the fixed-point type Typ has a user-defined operator
5419 -- (multiplication or division) that should hide the corresponding
5420 -- predefined operator. Used to implement Ada 2005 AI-264, to make
5421 -- such operators more visible and therefore useful.
5423 -- If the name of the operation is an expanded name with prefix
5424 -- Standard, the predefined universal fixed operator is available,
5425 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
5427 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
;
5428 -- Get specific type (i.e. non-universal type if there is one)
5434 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean is
5435 Bas
: constant Entity_Id
:= Base_Type
(Typ
);
5441 -- If the universal_fixed operation is given explicitly the rule
5442 -- concerning primitive operations of the type do not apply.
5444 if Nkind
(N
) = N_Function_Call
5445 and then Nkind
(Name
(N
)) = N_Expanded_Name
5446 and then Entity
(Prefix
(Name
(N
))) = Standard_Standard
5451 -- The operation is treated as primitive if it is declared in the
5452 -- same scope as the type, and therefore on the same entity chain.
5454 Ent
:= Next_Entity
(Typ
);
5455 while Present
(Ent
) loop
5456 if Chars
(Ent
) = Chars
(Op
) then
5457 F1
:= First_Formal
(Ent
);
5458 F2
:= Next_Formal
(F1
);
5460 -- The operation counts as primitive if either operand or
5461 -- result are of the given base type, and both operands are
5462 -- fixed point types.
5464 if (Base_Type
(Etype
(F1
)) = Bas
5465 and then Is_Fixed_Point_Type
(Etype
(F2
)))
5468 (Base_Type
(Etype
(F2
)) = Bas
5469 and then Is_Fixed_Point_Type
(Etype
(F1
)))
5472 (Base_Type
(Etype
(Ent
)) = Bas
5473 and then Is_Fixed_Point_Type
(Etype
(F1
))
5474 and then Is_Fixed_Point_Type
(Etype
(F2
)))
5490 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
is
5492 if T1
= Universal_Integer
or else T1
= Universal_Real
then
5493 return Base_Type
(T2
);
5495 return Base_Type
(T1
);
5499 -- Start of processing for Check_Arithmetic_Pair
5502 if Nam_In
(Op_Name
, Name_Op_Add
, Name_Op_Subtract
) then
5503 if Is_Numeric_Type
(T1
)
5504 and then Is_Numeric_Type
(T2
)
5505 and then (Covers
(T1
=> T1
, T2
=> T2
)
5507 Covers
(T1
=> T2
, T2
=> T1
))
5509 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5512 elsif Nam_In
(Op_Name
, Name_Op_Multiply
, Name_Op_Divide
) then
5513 if Is_Fixed_Point_Type
(T1
)
5514 and then (Is_Fixed_Point_Type
(T2
) or else T2
= Universal_Real
)
5516 -- If Treat_Fixed_As_Integer is set then the Etype is already set
5517 -- and no further processing is required (this is the case of an
5518 -- operator constructed by Exp_Fixd for a fixed point operation)
5519 -- Otherwise add one interpretation with universal fixed result
5520 -- If the operator is given in functional notation, it comes
5521 -- from source and Fixed_As_Integer cannot apply.
5523 if (Nkind
(N
) not in N_Op
5524 or else not Treat_Fixed_As_Integer
(N
))
5526 (not Has_Fixed_Op
(T1
, Op_Id
)
5527 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
5529 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
5532 elsif Is_Fixed_Point_Type
(T2
)
5533 and then (Nkind
(N
) not in N_Op
5534 or else not Treat_Fixed_As_Integer
(N
))
5535 and then T1
= Universal_Real
5537 (not Has_Fixed_Op
(T1
, Op_Id
)
5538 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
5540 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
5542 elsif Is_Numeric_Type
(T1
)
5543 and then Is_Numeric_Type
(T2
)
5544 and then (Covers
(T1
=> T1
, T2
=> T2
)
5546 Covers
(T1
=> T2
, T2
=> T1
))
5548 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5550 elsif Is_Fixed_Point_Type
(T1
)
5551 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5552 or else T2
= Universal_Integer
)
5554 Add_One_Interp
(N
, Op_Id
, T1
);
5556 elsif T2
= Universal_Real
5557 and then Base_Type
(T1
) = Base_Type
(Standard_Integer
)
5558 and then Op_Name
= Name_Op_Multiply
5560 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
5562 elsif T1
= Universal_Real
5563 and then Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5565 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
5567 elsif Is_Fixed_Point_Type
(T2
)
5568 and then (Base_Type
(T1
) = Base_Type
(Standard_Integer
)
5569 or else T1
= Universal_Integer
)
5570 and then Op_Name
= Name_Op_Multiply
5572 Add_One_Interp
(N
, Op_Id
, T2
);
5574 elsif T1
= Universal_Real
and then T2
= Universal_Integer
then
5575 Add_One_Interp
(N
, Op_Id
, T1
);
5577 elsif T2
= Universal_Real
5578 and then T1
= Universal_Integer
5579 and then Op_Name
= Name_Op_Multiply
5581 Add_One_Interp
(N
, Op_Id
, T2
);
5584 elsif Op_Name
= Name_Op_Mod
or else Op_Name
= Name_Op_Rem
then
5586 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
5587 -- set does not require any special processing, since the Etype is
5588 -- already set (case of operation constructed by Exp_Fixed).
5590 if Is_Integer_Type
(T1
)
5591 and then (Covers
(T1
=> T1
, T2
=> T2
)
5593 Covers
(T1
=> T2
, T2
=> T1
))
5595 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5598 elsif Op_Name
= Name_Op_Expon
then
5599 if Is_Numeric_Type
(T1
)
5600 and then not Is_Fixed_Point_Type
(T1
)
5601 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5602 or else T2
= Universal_Integer
)
5604 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
5607 else pragma Assert
(Nkind
(N
) in N_Op_Shift
);
5609 -- If not one of the predefined operators, the node may be one
5610 -- of the intrinsic functions. Its kind is always specific, and
5611 -- we can use it directly, rather than the name of the operation.
5613 if Is_Integer_Type
(T1
)
5614 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5615 or else T2
= Universal_Integer
)
5617 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
5620 end Check_Arithmetic_Pair
;
5622 -------------------------------
5623 -- Check_Misspelled_Selector --
5624 -------------------------------
5626 procedure Check_Misspelled_Selector
5627 (Prefix
: Entity_Id
;
5630 Max_Suggestions
: constant := 2;
5631 Nr_Of_Suggestions
: Natural := 0;
5633 Suggestion_1
: Entity_Id
:= Empty
;
5634 Suggestion_2
: Entity_Id
:= Empty
;
5639 -- All the components of the prefix of selector Sel are matched against
5640 -- Sel and a count is maintained of possible misspellings. When at
5641 -- the end of the analysis there are one or two (not more) possible
5642 -- misspellings, these misspellings will be suggested as possible
5645 if not (Is_Private_Type
(Prefix
) or else Is_Record_Type
(Prefix
)) then
5647 -- Concurrent types should be handled as well ???
5652 Comp
:= First_Entity
(Prefix
);
5653 while Nr_Of_Suggestions
<= Max_Suggestions
and then Present
(Comp
) loop
5654 if Is_Visible_Component
(Comp
) then
5655 if Is_Bad_Spelling_Of
(Chars
(Comp
), Chars
(Sel
)) then
5656 Nr_Of_Suggestions
:= Nr_Of_Suggestions
+ 1;
5658 case Nr_Of_Suggestions
is
5659 when 1 => Suggestion_1
:= Comp
;
5660 when 2 => Suggestion_2
:= Comp
;
5661 when others => exit;
5666 Comp
:= Next_Entity
(Comp
);
5669 -- Report at most two suggestions
5671 if Nr_Of_Suggestions
= 1 then
5672 Error_Msg_NE
-- CODEFIX
5673 ("\possible misspelling of&", Sel
, Suggestion_1
);
5675 elsif Nr_Of_Suggestions
= 2 then
5676 Error_Msg_Node_2
:= Suggestion_2
;
5677 Error_Msg_NE
-- CODEFIX
5678 ("\possible misspelling of& or&", Sel
, Suggestion_1
);
5680 end Check_Misspelled_Selector
;
5682 ----------------------
5683 -- Defined_In_Scope --
5684 ----------------------
5686 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean
5688 S1
: constant Entity_Id
:= Scope
(Base_Type
(T
));
5691 or else (S1
= System_Aux_Id
and then S
= Scope
(S1
));
5692 end Defined_In_Scope
;
5698 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
) is
5704 Void_Interp_Seen
: Boolean := False;
5707 pragma Warnings
(Off
, Boolean);
5710 if Ada_Version
>= Ada_2005
then
5711 Actual
:= First_Actual
(N
);
5712 while Present
(Actual
) loop
5714 -- Ada 2005 (AI-50217): Post an error in case of premature
5715 -- usage of an entity from the limited view.
5717 if not Analyzed
(Etype
(Actual
))
5718 and then From_Limited_With
(Etype
(Actual
))
5720 Error_Msg_Qual_Level
:= 1;
5722 ("missing with_clause for scope of imported type&",
5723 Actual
, Etype
(Actual
));
5724 Error_Msg_Qual_Level
:= 0;
5727 Next_Actual
(Actual
);
5731 -- Analyze each candidate call again, with full error reporting
5735 ("no candidate interpretations match the actuals:!", Nam
);
5736 Err_Mode
:= All_Errors_Mode
;
5737 All_Errors_Mode
:= True;
5739 -- If this is a call to an operation of a concurrent type,
5740 -- the failed interpretations have been removed from the
5741 -- name. Recover them to provide full diagnostics.
5743 if Nkind
(Parent
(Nam
)) = N_Selected_Component
then
5744 Set_Entity
(Nam
, Empty
);
5745 New_Nam
:= New_Copy_Tree
(Parent
(Nam
));
5746 Set_Is_Overloaded
(New_Nam
, False);
5747 Set_Is_Overloaded
(Selector_Name
(New_Nam
), False);
5748 Set_Parent
(New_Nam
, Parent
(Parent
(Nam
)));
5749 Analyze_Selected_Component
(New_Nam
);
5750 Get_First_Interp
(Selector_Name
(New_Nam
), X
, It
);
5752 Get_First_Interp
(Nam
, X
, It
);
5755 while Present
(It
.Nam
) loop
5756 if Etype
(It
.Nam
) = Standard_Void_Type
then
5757 Void_Interp_Seen
:= True;
5760 Analyze_One_Call
(N
, It
.Nam
, True, Success
);
5761 Get_Next_Interp
(X
, It
);
5764 if Nkind
(N
) = N_Function_Call
then
5765 Get_First_Interp
(Nam
, X
, It
);
5766 while Present
(It
.Nam
) loop
5767 if Ekind_In
(It
.Nam
, E_Function
, E_Operator
) then
5770 Get_Next_Interp
(X
, It
);
5774 -- If all interpretations are procedures, this deserves a
5775 -- more precise message. Ditto if this appears as the prefix
5776 -- of a selected component, which may be a lexical error.
5779 ("\context requires function call, found procedure name", Nam
);
5781 if Nkind
(Parent
(N
)) = N_Selected_Component
5782 and then N
= Prefix
(Parent
(N
))
5784 Error_Msg_N
-- CODEFIX
5785 ("\period should probably be semicolon", Parent
(N
));
5788 elsif Nkind
(N
) = N_Procedure_Call_Statement
5789 and then not Void_Interp_Seen
5792 "\function name found in procedure call", Nam
);
5795 All_Errors_Mode
:= Err_Mode
;
5798 ---------------------------
5799 -- Find_Arithmetic_Types --
5800 ---------------------------
5802 procedure Find_Arithmetic_Types
5807 Index1
: Interp_Index
;
5808 Index2
: Interp_Index
;
5812 procedure Check_Right_Argument
(T
: Entity_Id
);
5813 -- Check right operand of operator
5815 --------------------------
5816 -- Check_Right_Argument --
5817 --------------------------
5819 procedure Check_Right_Argument
(T
: Entity_Id
) is
5821 if not Is_Overloaded
(R
) then
5822 Check_Arithmetic_Pair
(T
, Etype
(R
), Op_Id
, N
);
5824 Get_First_Interp
(R
, Index2
, It2
);
5825 while Present
(It2
.Typ
) loop
5826 Check_Arithmetic_Pair
(T
, It2
.Typ
, Op_Id
, N
);
5827 Get_Next_Interp
(Index2
, It2
);
5830 end Check_Right_Argument
;
5832 -- Start of processing for Find_Arithmetic_Types
5835 if not Is_Overloaded
(L
) then
5836 Check_Right_Argument
(Etype
(L
));
5839 Get_First_Interp
(L
, Index1
, It1
);
5840 while Present
(It1
.Typ
) loop
5841 Check_Right_Argument
(It1
.Typ
);
5842 Get_Next_Interp
(Index1
, It1
);
5846 end Find_Arithmetic_Types
;
5848 ------------------------
5849 -- Find_Boolean_Types --
5850 ------------------------
5852 procedure Find_Boolean_Types
5857 Index
: Interp_Index
;
5860 procedure Check_Numeric_Argument
(T
: Entity_Id
);
5861 -- Special case for logical operations one of whose operands is an
5862 -- integer literal. If both are literal the result is any modular type.
5864 ----------------------------
5865 -- Check_Numeric_Argument --
5866 ----------------------------
5868 procedure Check_Numeric_Argument
(T
: Entity_Id
) is
5870 if T
= Universal_Integer
then
5871 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
5873 elsif Is_Modular_Integer_Type
(T
) then
5874 Add_One_Interp
(N
, Op_Id
, T
);
5876 end Check_Numeric_Argument
;
5878 -- Start of processing for Find_Boolean_Types
5881 if not Is_Overloaded
(L
) then
5882 if Etype
(L
) = Universal_Integer
5883 or else Etype
(L
) = Any_Modular
5885 if not Is_Overloaded
(R
) then
5886 Check_Numeric_Argument
(Etype
(R
));
5889 Get_First_Interp
(R
, Index
, It
);
5890 while Present
(It
.Typ
) loop
5891 Check_Numeric_Argument
(It
.Typ
);
5892 Get_Next_Interp
(Index
, It
);
5896 -- If operands are aggregates, we must assume that they may be
5897 -- boolean arrays, and leave disambiguation for the second pass.
5898 -- If only one is an aggregate, verify that the other one has an
5899 -- interpretation as a boolean array
5901 elsif Nkind
(L
) = N_Aggregate
then
5902 if Nkind
(R
) = N_Aggregate
then
5903 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
5905 elsif not Is_Overloaded
(R
) then
5906 if Valid_Boolean_Arg
(Etype
(R
)) then
5907 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
5911 Get_First_Interp
(R
, Index
, It
);
5912 while Present
(It
.Typ
) loop
5913 if Valid_Boolean_Arg
(It
.Typ
) then
5914 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
5917 Get_Next_Interp
(Index
, It
);
5921 elsif Valid_Boolean_Arg
(Etype
(L
))
5922 and then Has_Compatible_Type
(R
, Etype
(L
))
5924 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
5928 Get_First_Interp
(L
, Index
, It
);
5929 while Present
(It
.Typ
) loop
5930 if Valid_Boolean_Arg
(It
.Typ
)
5931 and then Has_Compatible_Type
(R
, It
.Typ
)
5933 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
5936 Get_Next_Interp
(Index
, It
);
5939 end Find_Boolean_Types
;
5941 ---------------------------
5942 -- Find_Comparison_Types --
5943 ---------------------------
5945 procedure Find_Comparison_Types
5950 Index
: Interp_Index
;
5952 Found
: Boolean := False;
5955 Scop
: Entity_Id
:= Empty
;
5957 procedure Try_One_Interp
(T1
: Entity_Id
);
5958 -- Routine to try one proposed interpretation. Note that the context
5959 -- of the operator plays no role in resolving the arguments, so that
5960 -- if there is more than one interpretation of the operands that is
5961 -- compatible with comparison, the operation is ambiguous.
5963 --------------------
5964 -- Try_One_Interp --
5965 --------------------
5967 procedure Try_One_Interp
(T1
: Entity_Id
) is
5970 -- If the operator is an expanded name, then the type of the operand
5971 -- must be defined in the corresponding scope. If the type is
5972 -- universal, the context will impose the correct type.
5975 and then not Defined_In_Scope
(T1
, Scop
)
5976 and then T1
/= Universal_Integer
5977 and then T1
/= Universal_Real
5978 and then T1
/= Any_String
5979 and then T1
/= Any_Composite
5984 if Valid_Comparison_Arg
(T1
) and then Has_Compatible_Type
(R
, T1
) then
5985 if Found
and then Base_Type
(T1
) /= Base_Type
(T_F
) then
5986 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
5988 if It
= No_Interp
then
5989 Ambiguous_Operands
(N
);
5990 Set_Etype
(L
, Any_Type
);
6004 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
6009 -- Start of processing for Find_Comparison_Types
6012 -- If left operand is aggregate, the right operand has to
6013 -- provide a usable type for it.
6015 if Nkind
(L
) = N_Aggregate
and then Nkind
(R
) /= N_Aggregate
then
6016 Find_Comparison_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
6020 if Nkind
(N
) = N_Function_Call
6021 and then Nkind
(Name
(N
)) = N_Expanded_Name
6023 Scop
:= Entity
(Prefix
(Name
(N
)));
6025 -- The prefix may be a package renaming, and the subsequent test
6026 -- requires the original package.
6028 if Ekind
(Scop
) = E_Package
6029 and then Present
(Renamed_Entity
(Scop
))
6031 Scop
:= Renamed_Entity
(Scop
);
6032 Set_Entity
(Prefix
(Name
(N
)), Scop
);
6036 if not Is_Overloaded
(L
) then
6037 Try_One_Interp
(Etype
(L
));
6040 Get_First_Interp
(L
, Index
, It
);
6041 while Present
(It
.Typ
) loop
6042 Try_One_Interp
(It
.Typ
);
6043 Get_Next_Interp
(Index
, It
);
6046 end Find_Comparison_Types
;
6048 ----------------------------------------
6049 -- Find_Non_Universal_Interpretations --
6050 ----------------------------------------
6052 procedure Find_Non_Universal_Interpretations
6058 Index
: Interp_Index
;
6062 if T1
= Universal_Integer
or else T1
= Universal_Real
6064 -- If the left operand of an equality operator is null, the visibility
6065 -- of the operator must be determined from the interpretation of the
6066 -- right operand. This processing must be done for Any_Access, which
6067 -- is the internal representation of the type of the literal null.
6069 or else T1
= Any_Access
6071 if not Is_Overloaded
(R
) then
6072 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(Etype
(R
)));
6074 Get_First_Interp
(R
, Index
, It
);
6075 while Present
(It
.Typ
) loop
6076 if Covers
(It
.Typ
, T1
) then
6078 (N
, Op_Id
, Standard_Boolean
, Base_Type
(It
.Typ
));
6081 Get_Next_Interp
(Index
, It
);
6085 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(T1
));
6087 end Find_Non_Universal_Interpretations
;
6089 ------------------------------
6090 -- Find_Concatenation_Types --
6091 ------------------------------
6093 procedure Find_Concatenation_Types
6098 Op_Type
: constant Entity_Id
:= Etype
(Op_Id
);
6101 if Is_Array_Type
(Op_Type
)
6102 and then not Is_Limited_Type
(Op_Type
)
6104 and then (Has_Compatible_Type
(L
, Op_Type
)
6106 Has_Compatible_Type
(L
, Component_Type
(Op_Type
)))
6108 and then (Has_Compatible_Type
(R
, Op_Type
)
6110 Has_Compatible_Type
(R
, Component_Type
(Op_Type
)))
6112 Add_One_Interp
(N
, Op_Id
, Op_Type
);
6114 end Find_Concatenation_Types
;
6116 -------------------------
6117 -- Find_Equality_Types --
6118 -------------------------
6120 procedure Find_Equality_Types
6125 Index
: Interp_Index
;
6127 Found
: Boolean := False;
6130 Scop
: Entity_Id
:= Empty
;
6132 procedure Try_One_Interp
(T1
: Entity_Id
);
6133 -- The context of the equality operator plays no role in resolving the
6134 -- arguments, so that if there is more than one interpretation of the
6135 -- operands that is compatible with equality, the construct is ambiguous
6136 -- and an error can be emitted now, after trying to disambiguate, i.e.
6137 -- applying preference rules.
6139 --------------------
6140 -- Try_One_Interp --
6141 --------------------
6143 procedure Try_One_Interp
(T1
: Entity_Id
) is
6144 Bas
: constant Entity_Id
:= Base_Type
(T1
);
6147 -- If the operator is an expanded name, then the type of the operand
6148 -- must be defined in the corresponding scope. If the type is
6149 -- universal, the context will impose the correct type. An anonymous
6150 -- type for a 'Access reference is also universal in this sense, as
6151 -- the actual type is obtained from context.
6153 -- In Ada 2005, the equality operator for anonymous access types
6154 -- is declared in Standard, and preference rules apply to it.
6156 if Present
(Scop
) then
6157 if Defined_In_Scope
(T1
, Scop
)
6158 or else T1
= Universal_Integer
6159 or else T1
= Universal_Real
6160 or else T1
= Any_Access
6161 or else T1
= Any_String
6162 or else T1
= Any_Composite
6163 or else (Ekind
(T1
) = E_Access_Subprogram_Type
6164 and then not Comes_From_Source
(T1
))
6168 elsif Ekind
(T1
) = E_Anonymous_Access_Type
6169 and then Scop
= Standard_Standard
6174 -- The scope does not contain an operator for the type
6179 -- If we have infix notation, the operator must be usable. Within
6180 -- an instance, if the type is already established we know it is
6181 -- correct. If an operand is universal it is compatible with any
6184 elsif In_Open_Scopes
(Scope
(Bas
))
6185 or else Is_Potentially_Use_Visible
(Bas
)
6186 or else In_Use
(Bas
)
6187 or else (In_Use
(Scope
(Bas
)) and then not Is_Hidden
(Bas
))
6189 -- In an instance, the type may have been immediately visible.
6190 -- Either the types are compatible, or one operand is universal
6191 -- (numeric or null).
6193 or else (In_Instance
6195 (First_Subtype
(T1
) = First_Subtype
(Etype
(R
))
6196 or else Nkind
(R
) = N_Null
6198 (Is_Numeric_Type
(T1
)
6199 and then Is_Universal_Numeric_Type
(Etype
(R
)))))
6201 -- In Ada 2005, the equality on anonymous access types is declared
6202 -- in Standard, and is always visible.
6204 or else Ekind
(T1
) = E_Anonymous_Access_Type
6209 -- Save candidate type for subsequent error message, if any
6211 if not Is_Limited_Type
(T1
) then
6212 Candidate_Type
:= T1
;
6218 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
6219 -- Do not allow anonymous access types in equality operators.
6221 if Ada_Version
< Ada_2005
6222 and then Ekind
(T1
) = E_Anonymous_Access_Type
6227 -- If the right operand has a type compatible with T1, check for an
6228 -- acceptable interpretation, unless T1 is limited (no predefined
6229 -- equality available), or this is use of a "/=" for a tagged type.
6230 -- In the latter case, possible interpretations of equality need
6231 -- to be considered, we don't want the default inequality declared
6232 -- in Standard to be chosen, and the "/=" will be rewritten as a
6233 -- negation of "=" (see the end of Analyze_Equality_Op). This ensures
6234 -- that rewriting happens during analysis rather than being
6235 -- delayed until expansion (this is needed for ASIS, which only sees
6236 -- the unexpanded tree). Note that if the node is N_Op_Ne, but Op_Id
6237 -- is Name_Op_Eq then we still proceed with the interpretation,
6238 -- because that indicates the potential rewriting case where the
6239 -- interpretation to consider is actually "=" and the node may be
6240 -- about to be rewritten by Analyze_Equality_Op.
6242 if T1
/= Standard_Void_Type
6243 and then Has_Compatible_Type
(R
, T1
)
6246 ((not Is_Limited_Type
(T1
)
6247 and then not Is_Limited_Composite
(T1
))
6251 and then not Is_Limited_Type
(Component_Type
(T1
))
6252 and then Available_Full_View_Of_Component
(T1
)))
6255 (Nkind
(N
) /= N_Op_Ne
6256 or else not Is_Tagged_Type
(T1
)
6257 or else Chars
(Op_Id
) = Name_Op_Eq
)
6260 and then Base_Type
(T1
) /= Base_Type
(T_F
)
6262 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
6264 if It
= No_Interp
then
6265 Ambiguous_Operands
(N
);
6266 Set_Etype
(L
, Any_Type
);
6279 if not Analyzed
(L
) then
6283 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
6285 -- Case of operator was not visible, Etype still set to Any_Type
6287 if Etype
(N
) = Any_Type
then
6291 elsif Scop
= Standard_Standard
6292 and then Ekind
(T1
) = E_Anonymous_Access_Type
6298 -- Start of processing for Find_Equality_Types
6301 -- If left operand is aggregate, the right operand has to
6302 -- provide a usable type for it.
6304 if Nkind
(L
) = N_Aggregate
6305 and then Nkind
(R
) /= N_Aggregate
6307 Find_Equality_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
6311 if Nkind
(N
) = N_Function_Call
6312 and then Nkind
(Name
(N
)) = N_Expanded_Name
6314 Scop
:= Entity
(Prefix
(Name
(N
)));
6316 -- The prefix may be a package renaming, and the subsequent test
6317 -- requires the original package.
6319 if Ekind
(Scop
) = E_Package
6320 and then Present
(Renamed_Entity
(Scop
))
6322 Scop
:= Renamed_Entity
(Scop
);
6323 Set_Entity
(Prefix
(Name
(N
)), Scop
);
6327 if not Is_Overloaded
(L
) then
6328 Try_One_Interp
(Etype
(L
));
6331 Get_First_Interp
(L
, Index
, It
);
6332 while Present
(It
.Typ
) loop
6333 Try_One_Interp
(It
.Typ
);
6334 Get_Next_Interp
(Index
, It
);
6337 end Find_Equality_Types
;
6339 -------------------------
6340 -- Find_Negation_Types --
6341 -------------------------
6343 procedure Find_Negation_Types
6348 Index
: Interp_Index
;
6352 if not Is_Overloaded
(R
) then
6353 if Etype
(R
) = Universal_Integer
then
6354 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
6355 elsif Valid_Boolean_Arg
(Etype
(R
)) then
6356 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
6360 Get_First_Interp
(R
, Index
, It
);
6361 while Present
(It
.Typ
) loop
6362 if Valid_Boolean_Arg
(It
.Typ
) then
6363 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
6366 Get_Next_Interp
(Index
, It
);
6369 end Find_Negation_Types
;
6371 ------------------------------
6372 -- Find_Primitive_Operation --
6373 ------------------------------
6375 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean is
6376 Obj
: constant Node_Id
:= Prefix
(N
);
6377 Op
: constant Node_Id
:= Selector_Name
(N
);
6384 Set_Etype
(Op
, Any_Type
);
6386 if Is_Access_Type
(Etype
(Obj
)) then
6387 Typ
:= Designated_Type
(Etype
(Obj
));
6392 if Is_Class_Wide_Type
(Typ
) then
6393 Typ
:= Root_Type
(Typ
);
6396 Prims
:= Primitive_Operations
(Typ
);
6398 Prim
:= First_Elmt
(Prims
);
6399 while Present
(Prim
) loop
6400 if Chars
(Node
(Prim
)) = Chars
(Op
) then
6401 Add_One_Interp
(Op
, Node
(Prim
), Etype
(Node
(Prim
)));
6402 Set_Etype
(N
, Etype
(Node
(Prim
)));
6408 -- Now look for class-wide operations of the type or any of its
6409 -- ancestors by iterating over the homonyms of the selector.
6412 Cls_Type
: constant Entity_Id
:= Class_Wide_Type
(Typ
);
6416 Hom
:= Current_Entity
(Op
);
6417 while Present
(Hom
) loop
6418 if (Ekind
(Hom
) = E_Procedure
6420 Ekind
(Hom
) = E_Function
)
6421 and then Scope
(Hom
) = Scope
(Typ
)
6422 and then Present
(First_Formal
(Hom
))
6424 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
6426 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
6428 Ekind
(Etype
(First_Formal
(Hom
))) =
6429 E_Anonymous_Access_Type
6432 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
6435 Add_One_Interp
(Op
, Hom
, Etype
(Hom
));
6436 Set_Etype
(N
, Etype
(Hom
));
6439 Hom
:= Homonym
(Hom
);
6443 return Etype
(Op
) /= Any_Type
;
6444 end Find_Primitive_Operation
;
6446 ----------------------
6447 -- Find_Unary_Types --
6448 ----------------------
6450 procedure Find_Unary_Types
6455 Index
: Interp_Index
;
6459 if not Is_Overloaded
(R
) then
6460 if Is_Numeric_Type
(Etype
(R
)) then
6462 -- In an instance a generic actual may be a numeric type even if
6463 -- the formal in the generic unit was not. In that case, the
6464 -- predefined operator was not a possible interpretation in the
6465 -- generic, and cannot be one in the instance, unless the operator
6466 -- is an actual of an instance.
6470 not Is_Numeric_Type
(Corresponding_Generic_Type
(Etype
(R
)))
6474 Add_One_Interp
(N
, Op_Id
, Base_Type
(Etype
(R
)));
6479 Get_First_Interp
(R
, Index
, It
);
6480 while Present
(It
.Typ
) loop
6481 if Is_Numeric_Type
(It
.Typ
) then
6485 (Corresponding_Generic_Type
(Etype
(It
.Typ
)))
6490 Add_One_Interp
(N
, Op_Id
, Base_Type
(It
.Typ
));
6494 Get_Next_Interp
(Index
, It
);
6497 end Find_Unary_Types
;
6503 function Junk_Operand
(N
: Node_Id
) return Boolean is
6507 if Error_Posted
(N
) then
6511 -- Get entity to be tested
6513 if Is_Entity_Name
(N
)
6514 and then Present
(Entity
(N
))
6518 -- An odd case, a procedure name gets converted to a very peculiar
6519 -- function call, and here is where we detect this happening.
6521 elsif Nkind
(N
) = N_Function_Call
6522 and then Is_Entity_Name
(Name
(N
))
6523 and then Present
(Entity
(Name
(N
)))
6527 -- Another odd case, there are at least some cases of selected
6528 -- components where the selected component is not marked as having
6529 -- an entity, even though the selector does have an entity
6531 elsif Nkind
(N
) = N_Selected_Component
6532 and then Present
(Entity
(Selector_Name
(N
)))
6534 Enode
:= Selector_Name
(N
);
6540 -- Now test the entity we got to see if it is a bad case
6542 case Ekind
(Entity
(Enode
)) is
6546 ("package name cannot be used as operand", Enode
);
6548 when Generic_Unit_Kind
=>
6550 ("generic unit name cannot be used as operand", Enode
);
6554 ("subtype name cannot be used as operand", Enode
);
6558 ("entry name cannot be used as operand", Enode
);
6562 ("procedure name cannot be used as operand", Enode
);
6566 ("exception name cannot be used as operand", Enode
);
6568 when E_Block | E_Label | E_Loop
=>
6570 ("label name cannot be used as operand", Enode
);
6580 --------------------
6581 -- Operator_Check --
6582 --------------------
6584 procedure Operator_Check
(N
: Node_Id
) is
6586 Remove_Abstract_Operations
(N
);
6588 -- Test for case of no interpretation found for operator
6590 if Etype
(N
) = Any_Type
then
6594 Op_Id
: Entity_Id
:= Empty
;
6597 R
:= Right_Opnd
(N
);
6599 if Nkind
(N
) in N_Binary_Op
then
6605 -- If either operand has no type, then don't complain further,
6606 -- since this simply means that we have a propagated error.
6609 or else Etype
(R
) = Any_Type
6610 or else (Nkind
(N
) in N_Binary_Op
and then Etype
(L
) = Any_Type
)
6612 -- For the rather unusual case where one of the operands is
6613 -- a Raise_Expression, whose initial type is Any_Type, use
6614 -- the type of the other operand.
6616 if Nkind
(L
) = N_Raise_Expression
then
6617 Set_Etype
(L
, Etype
(R
));
6618 Set_Etype
(N
, Etype
(R
));
6620 elsif Nkind
(R
) = N_Raise_Expression
then
6621 Set_Etype
(R
, Etype
(L
));
6622 Set_Etype
(N
, Etype
(L
));
6627 -- We explicitly check for the case of concatenation of component
6628 -- with component to avoid reporting spurious matching array types
6629 -- that might happen to be lurking in distant packages (such as
6630 -- run-time packages). This also prevents inconsistencies in the
6631 -- messages for certain ACVC B tests, which can vary depending on
6632 -- types declared in run-time interfaces. Another improvement when
6633 -- aggregates are present is to look for a well-typed operand.
6635 elsif Present
(Candidate_Type
)
6636 and then (Nkind
(N
) /= N_Op_Concat
6637 or else Is_Array_Type
(Etype
(L
))
6638 or else Is_Array_Type
(Etype
(R
)))
6640 if Nkind
(N
) = N_Op_Concat
then
6641 if Etype
(L
) /= Any_Composite
6642 and then Is_Array_Type
(Etype
(L
))
6644 Candidate_Type
:= Etype
(L
);
6646 elsif Etype
(R
) /= Any_Composite
6647 and then Is_Array_Type
(Etype
(R
))
6649 Candidate_Type
:= Etype
(R
);
6653 Error_Msg_NE
-- CODEFIX
6654 ("operator for} is not directly visible!",
6655 N
, First_Subtype
(Candidate_Type
));
6658 U
: constant Node_Id
:=
6659 Cunit
(Get_Source_Unit
(Candidate_Type
));
6661 if Unit_Is_Visible
(U
) then
6662 Error_Msg_N
-- CODEFIX
6663 ("use clause would make operation legal!", N
);
6665 Error_Msg_NE
-- CODEFIX
6666 ("add with_clause and use_clause for&!",
6667 N
, Defining_Entity
(Unit
(U
)));
6672 -- If either operand is a junk operand (e.g. package name), then
6673 -- post appropriate error messages, but do not complain further.
6675 -- Note that the use of OR in this test instead of OR ELSE is
6676 -- quite deliberate, we may as well check both operands in the
6677 -- binary operator case.
6679 elsif Junk_Operand
(R
)
6680 or -- really mean OR here and not OR ELSE, see above
6681 (Nkind
(N
) in N_Binary_Op
and then Junk_Operand
(L
))
6685 -- If we have a logical operator, one of whose operands is
6686 -- Boolean, then we know that the other operand cannot resolve to
6687 -- Boolean (since we got no interpretations), but in that case we
6688 -- pretty much know that the other operand should be Boolean, so
6689 -- resolve it that way (generating an error).
6691 elsif Nkind_In
(N
, N_Op_And
, N_Op_Or
, N_Op_Xor
) then
6692 if Etype
(L
) = Standard_Boolean
then
6693 Resolve
(R
, Standard_Boolean
);
6695 elsif Etype
(R
) = Standard_Boolean
then
6696 Resolve
(L
, Standard_Boolean
);
6700 -- For an arithmetic operator or comparison operator, if one
6701 -- of the operands is numeric, then we know the other operand
6702 -- is not the same numeric type. If it is a non-numeric type,
6703 -- then probably it is intended to match the other operand.
6705 elsif Nkind_In
(N
, N_Op_Add
,
6711 Nkind_In
(N
, N_Op_Lt
,
6717 -- If Allow_Integer_Address is active, check whether the
6718 -- operation becomes legal after converting an operand.
6720 if Is_Numeric_Type
(Etype
(L
))
6721 and then not Is_Numeric_Type
(Etype
(R
))
6723 if Address_Integer_Convert_OK
(Etype
(R
), Etype
(L
)) then
6725 Unchecked_Convert_To
(Etype
(L
), Relocate_Node
(R
)));
6727 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6728 Analyze_Comparison_Op
(N
);
6730 Analyze_Arithmetic_Op
(N
);
6733 Resolve
(R
, Etype
(L
));
6738 elsif Is_Numeric_Type
(Etype
(R
))
6739 and then not Is_Numeric_Type
(Etype
(L
))
6741 if Address_Integer_Convert_OK
(Etype
(L
), Etype
(R
)) then
6743 Unchecked_Convert_To
(Etype
(R
), Relocate_Node
(L
)));
6745 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6746 Analyze_Comparison_Op
(N
);
6748 Analyze_Arithmetic_Op
(N
);
6754 Resolve
(L
, Etype
(R
));
6759 elsif Allow_Integer_Address
6760 and then Is_Descendant_Of_Address
(Etype
(L
))
6761 and then Is_Descendant_Of_Address
(Etype
(R
))
6762 and then not Error_Posted
(N
)
6765 Addr_Type
: constant Entity_Id
:= Etype
(L
);
6769 Unchecked_Convert_To
(
6770 Standard_Integer
, Relocate_Node
(L
)));
6772 Unchecked_Convert_To
(
6773 Standard_Integer
, Relocate_Node
(R
)));
6775 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6776 Analyze_Comparison_Op
(N
);
6778 Analyze_Arithmetic_Op
(N
);
6781 -- If this is an operand in an enclosing arithmetic
6782 -- operation, Convert the result as an address so that
6783 -- arithmetic folding of address can continue.
6785 if Nkind
(Parent
(N
)) in N_Op
then
6787 Unchecked_Convert_To
(Addr_Type
, Relocate_Node
(N
)));
6794 -- Comparisons on A'Access are common enough to deserve a
6797 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
)
6798 and then Ekind
(Etype
(L
)) = E_Access_Attribute_Type
6799 and then Ekind
(Etype
(R
)) = E_Access_Attribute_Type
6802 ("two access attributes cannot be compared directly", N
);
6804 ("\use qualified expression for one of the operands",
6808 -- Another one for C programmers
6810 elsif Nkind
(N
) = N_Op_Concat
6811 and then Valid_Boolean_Arg
(Etype
(L
))
6812 and then Valid_Boolean_Arg
(Etype
(R
))
6814 Error_Msg_N
("invalid operands for concatenation", N
);
6815 Error_Msg_N
-- CODEFIX
6816 ("\maybe AND was meant", N
);
6819 -- A special case for comparison of access parameter with null
6821 elsif Nkind
(N
) = N_Op_Eq
6822 and then Is_Entity_Name
(L
)
6823 and then Nkind
(Parent
(Entity
(L
))) = N_Parameter_Specification
6824 and then Nkind
(Parameter_Type
(Parent
(Entity
(L
)))) =
6826 and then Nkind
(R
) = N_Null
6828 Error_Msg_N
("access parameter is not allowed to be null", L
);
6829 Error_Msg_N
("\(call would raise Constraint_Error)", L
);
6832 -- Another special case for exponentiation, where the right
6833 -- operand must be Natural, independently of the base.
6835 elsif Nkind
(N
) = N_Op_Expon
6836 and then Is_Numeric_Type
(Etype
(L
))
6837 and then not Is_Overloaded
(R
)
6839 First_Subtype
(Base_Type
(Etype
(R
))) /= Standard_Integer
6840 and then Base_Type
(Etype
(R
)) /= Universal_Integer
6842 if Ada_Version
>= Ada_2012
6843 and then Has_Dimension_System
(Etype
(L
))
6846 ("exponent for dimensioned type must be a rational" &
6847 ", found}", R
, Etype
(R
));
6850 ("exponent must be of type Natural, found}", R
, Etype
(R
));
6855 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
) then
6856 if Address_Integer_Convert_OK
(Etype
(R
), Etype
(L
)) then
6858 Unchecked_Convert_To
(Etype
(L
), Relocate_Node
(R
)));
6859 Analyze_Equality_Op
(N
);
6864 -- If we fall through then just give general message. Note that in
6865 -- the following messages, if the operand is overloaded we choose
6866 -- an arbitrary type to complain about, but that is probably more
6867 -- useful than not giving a type at all.
6869 if Nkind
(N
) in N_Unary_Op
then
6870 Error_Msg_Node_2
:= Etype
(R
);
6871 Error_Msg_N
("operator& not defined for}", N
);
6875 if Nkind
(N
) in N_Binary_Op
then
6876 if not Is_Overloaded
(L
)
6877 and then not Is_Overloaded
(R
)
6878 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
6880 Error_Msg_Node_2
:= First_Subtype
(Etype
(R
));
6881 Error_Msg_N
("there is no applicable operator& for}", N
);
6884 -- Another attempt to find a fix: one of the candidate
6885 -- interpretations may not be use-visible. This has
6886 -- already been checked for predefined operators, so
6887 -- we examine only user-defined functions.
6889 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
6891 while Present
(Op_Id
) loop
6892 if Ekind
(Op_Id
) /= E_Operator
6893 and then Is_Overloadable
(Op_Id
)
6895 if not Is_Immediately_Visible
(Op_Id
)
6896 and then not In_Use
(Scope
(Op_Id
))
6897 and then not Is_Abstract_Subprogram
(Op_Id
)
6898 and then not Is_Hidden
(Op_Id
)
6899 and then Ekind
(Scope
(Op_Id
)) = E_Package
6902 (L
, Etype
(First_Formal
(Op_Id
)))
6904 (Next_Formal
(First_Formal
(Op_Id
)))
6908 Etype
(Next_Formal
(First_Formal
(Op_Id
))))
6911 ("No legal interpretation for operator&", N
);
6913 ("\use clause on& would make operation legal",
6919 Op_Id
:= Homonym
(Op_Id
);
6923 Error_Msg_N
("invalid operand types for operator&", N
);
6925 if Nkind
(N
) /= N_Op_Concat
then
6926 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
6927 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
6929 -- For concatenation operators it is more difficult to
6930 -- determine which is the wrong operand. It is worth
6931 -- flagging explicitly an access type, for those who
6932 -- might think that a dereference happens here.
6934 elsif Is_Access_Type
(Etype
(L
)) then
6935 Error_Msg_N
("\left operand is access type", N
);
6937 elsif Is_Access_Type
(Etype
(R
)) then
6938 Error_Msg_N
("\right operand is access type", N
);
6948 -----------------------------------------
6949 -- Process_Implicit_Dereference_Prefix --
6950 -----------------------------------------
6952 function Process_Implicit_Dereference_Prefix
6954 P
: Entity_Id
) return Entity_Id
6957 Typ
: constant Entity_Id
:= Designated_Type
(Etype
(P
));
6961 and then (Operating_Mode
= Check_Semantics
or else not Expander_Active
)
6963 -- We create a dummy reference to E to ensure that the reference is
6964 -- not considered as part of an assignment (an implicit dereference
6965 -- can never assign to its prefix). The Comes_From_Source attribute
6966 -- needs to be propagated for accurate warnings.
6968 Ref
:= New_Occurrence_Of
(E
, Sloc
(P
));
6969 Set_Comes_From_Source
(Ref
, Comes_From_Source
(P
));
6970 Generate_Reference
(E
, Ref
);
6973 -- An implicit dereference is a legal occurrence of an incomplete type
6974 -- imported through a limited_with clause, if the full view is visible.
6976 if From_Limited_With
(Typ
)
6977 and then not From_Limited_With
(Scope
(Typ
))
6979 (Is_Immediately_Visible
(Scope
(Typ
))
6981 (Is_Child_Unit
(Scope
(Typ
))
6982 and then Is_Visible_Lib_Unit
(Scope
(Typ
))))
6984 return Available_View
(Typ
);
6988 end Process_Implicit_Dereference_Prefix
;
6990 --------------------------------
6991 -- Remove_Abstract_Operations --
6992 --------------------------------
6994 procedure Remove_Abstract_Operations
(N
: Node_Id
) is
6995 Abstract_Op
: Entity_Id
:= Empty
;
6996 Address_Descendant
: Boolean := False;
7000 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
7001 -- activate this if either extensions are enabled, or if the abstract
7002 -- operation in question comes from a predefined file. This latter test
7003 -- allows us to use abstract to make operations invisible to users. In
7004 -- particular, if type Address is non-private and abstract subprograms
7005 -- are used to hide its operators, they will be truly hidden.
7007 type Operand_Position
is (First_Op
, Second_Op
);
7008 Univ_Type
: constant Entity_Id
:= Universal_Interpretation
(N
);
7010 procedure Remove_Address_Interpretations
(Op
: Operand_Position
);
7011 -- Ambiguities may arise when the operands are literal and the address
7012 -- operations in s-auxdec are visible. In that case, remove the
7013 -- interpretation of a literal as Address, to retain the semantics
7014 -- of Address as a private type.
7016 ------------------------------------
7017 -- Remove_Address_Interpretations --
7018 ------------------------------------
7020 procedure Remove_Address_Interpretations
(Op
: Operand_Position
) is
7024 if Is_Overloaded
(N
) then
7025 Get_First_Interp
(N
, I
, It
);
7026 while Present
(It
.Nam
) loop
7027 Formal
:= First_Entity
(It
.Nam
);
7029 if Op
= Second_Op
then
7030 Formal
:= Next_Entity
(Formal
);
7033 if Is_Descendant_Of_Address
(Etype
(Formal
)) then
7034 Address_Descendant
:= True;
7038 Get_Next_Interp
(I
, It
);
7041 end Remove_Address_Interpretations
;
7043 -- Start of processing for Remove_Abstract_Operations
7046 if Is_Overloaded
(N
) then
7047 if Debug_Flag_V
then
7048 Write_Str
("Remove_Abstract_Operations: ");
7049 Write_Overloads
(N
);
7052 Get_First_Interp
(N
, I
, It
);
7054 while Present
(It
.Nam
) loop
7055 if Is_Overloadable
(It
.Nam
)
7056 and then Is_Abstract_Subprogram
(It
.Nam
)
7057 and then not Is_Dispatching_Operation
(It
.Nam
)
7059 Abstract_Op
:= It
.Nam
;
7061 if Is_Descendant_Of_Address
(It
.Typ
) then
7062 Address_Descendant
:= True;
7066 -- In Ada 2005, this operation does not participate in overload
7067 -- resolution. If the operation is defined in a predefined
7068 -- unit, it is one of the operations declared abstract in some
7069 -- variants of System, and it must be removed as well.
7071 elsif Ada_Version
>= Ada_2005
7072 or else Is_Predefined_File_Name
7073 (Unit_File_Name
(Get_Source_Unit
(It
.Nam
)))
7080 Get_Next_Interp
(I
, It
);
7083 if No
(Abstract_Op
) then
7085 -- If some interpretation yields an integer type, it is still
7086 -- possible that there are address interpretations. Remove them
7087 -- if one operand is a literal, to avoid spurious ambiguities
7088 -- on systems where Address is a visible integer type.
7090 if Is_Overloaded
(N
)
7091 and then Nkind
(N
) in N_Op
7092 and then Is_Integer_Type
(Etype
(N
))
7094 if Nkind
(N
) in N_Binary_Op
then
7095 if Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
7096 Remove_Address_Interpretations
(Second_Op
);
7098 elsif Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
7099 Remove_Address_Interpretations
(First_Op
);
7104 elsif Nkind
(N
) in N_Op
then
7106 -- Remove interpretations that treat literals as addresses. This
7107 -- is never appropriate, even when Address is defined as a visible
7108 -- Integer type. The reason is that we would really prefer Address
7109 -- to behave as a private type, even in this case. If Address is a
7110 -- visible integer type, we get lots of overload ambiguities.
7112 if Nkind
(N
) in N_Binary_Op
then
7114 U1
: constant Boolean :=
7115 Present
(Universal_Interpretation
(Right_Opnd
(N
)));
7116 U2
: constant Boolean :=
7117 Present
(Universal_Interpretation
(Left_Opnd
(N
)));
7121 Remove_Address_Interpretations
(Second_Op
);
7125 Remove_Address_Interpretations
(First_Op
);
7128 if not (U1
and U2
) then
7130 -- Remove corresponding predefined operator, which is
7131 -- always added to the overload set.
7133 Get_First_Interp
(N
, I
, It
);
7134 while Present
(It
.Nam
) loop
7135 if Scope
(It
.Nam
) = Standard_Standard
7136 and then Base_Type
(It
.Typ
) =
7137 Base_Type
(Etype
(Abstract_Op
))
7142 Get_Next_Interp
(I
, It
);
7145 elsif Is_Overloaded
(N
)
7146 and then Present
(Univ_Type
)
7148 -- If both operands have a universal interpretation,
7149 -- it is still necessary to remove interpretations that
7150 -- yield Address. Any remaining ambiguities will be
7151 -- removed in Disambiguate.
7153 Get_First_Interp
(N
, I
, It
);
7154 while Present
(It
.Nam
) loop
7155 if Is_Descendant_Of_Address
(It
.Typ
) then
7158 elsif not Is_Type
(It
.Nam
) then
7159 Set_Entity
(N
, It
.Nam
);
7162 Get_Next_Interp
(I
, It
);
7168 elsif Nkind
(N
) = N_Function_Call
7170 (Nkind
(Name
(N
)) = N_Operator_Symbol
7172 (Nkind
(Name
(N
)) = N_Expanded_Name
7174 Nkind
(Selector_Name
(Name
(N
))) = N_Operator_Symbol
))
7178 Arg1
: constant Node_Id
:= First
(Parameter_Associations
(N
));
7179 U1
: constant Boolean :=
7180 Present
(Universal_Interpretation
(Arg1
));
7181 U2
: constant Boolean :=
7182 Present
(Next
(Arg1
)) and then
7183 Present
(Universal_Interpretation
(Next
(Arg1
)));
7187 Remove_Address_Interpretations
(First_Op
);
7191 Remove_Address_Interpretations
(Second_Op
);
7194 if not (U1
and U2
) then
7195 Get_First_Interp
(N
, I
, It
);
7196 while Present
(It
.Nam
) loop
7197 if Scope
(It
.Nam
) = Standard_Standard
7198 and then It
.Typ
= Base_Type
(Etype
(Abstract_Op
))
7203 Get_Next_Interp
(I
, It
);
7209 -- If the removal has left no valid interpretations, emit an error
7210 -- message now and label node as illegal.
7212 if Present
(Abstract_Op
) then
7213 Get_First_Interp
(N
, I
, It
);
7217 -- Removal of abstract operation left no viable candidate
7219 Set_Etype
(N
, Any_Type
);
7220 Error_Msg_Sloc
:= Sloc
(Abstract_Op
);
7222 ("cannot call abstract operation& declared#", N
, Abstract_Op
);
7224 -- In Ada 2005, an abstract operation may disable predefined
7225 -- operators. Since the context is not yet known, we mark the
7226 -- predefined operators as potentially hidden. Do not include
7227 -- predefined operators when addresses are involved since this
7228 -- case is handled separately.
7230 elsif Ada_Version
>= Ada_2005
and then not Address_Descendant
then
7231 while Present
(It
.Nam
) loop
7232 if Is_Numeric_Type
(It
.Typ
)
7233 and then Scope
(It
.Typ
) = Standard_Standard
7235 Set_Abstract_Op
(I
, Abstract_Op
);
7238 Get_Next_Interp
(I
, It
);
7243 if Debug_Flag_V
then
7244 Write_Str
("Remove_Abstract_Operations done: ");
7245 Write_Overloads
(N
);
7248 end Remove_Abstract_Operations
;
7250 ----------------------------
7251 -- Try_Container_Indexing --
7252 ----------------------------
7254 function Try_Container_Indexing
7257 Exprs
: List_Id
) return Boolean
7259 Pref_Typ
: constant Entity_Id
:= Etype
(Prefix
);
7261 function Constant_Indexing_OK
return Boolean;
7262 -- Constant_Indexing is legal if there is no Variable_Indexing defined
7263 -- for the type, or else node not a target of assignment, or an actual
7264 -- for an IN OUT or OUT formal (RM 4.1.6 (11)).
7266 function Find_Indexing_Operations
7269 Is_Constant
: Boolean) return Node_Id
;
7270 -- Return a reference to the primitive operation of type T denoted by
7271 -- name Nam. If the operation is overloaded, the reference carries all
7272 -- interpretations. Flag Is_Constant should be set when the context is
7273 -- constant indexing.
7275 --------------------------
7276 -- Constant_Indexing_OK --
7277 --------------------------
7279 function Constant_Indexing_OK
return Boolean is
7283 if No
(Find_Value_Of_Aspect
(Pref_Typ
, Aspect_Variable_Indexing
)) then
7286 elsif not Is_Variable
(Prefix
) then
7291 while Present
(Par
) loop
7292 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
7293 and then Par
= Name
(Parent
(Par
))
7297 -- The call may be overloaded, in which case we assume that its
7298 -- resolution does not depend on the type of the parameter that
7299 -- includes the indexing operation.
7301 elsif Nkind_In
(Parent
(Par
), N_Function_Call
,
7302 N_Procedure_Call_Statement
)
7303 and then Is_Entity_Name
(Name
(Parent
(Par
)))
7311 -- We should look for an interpretation with the proper
7312 -- number of formals, and determine whether it is an
7313 -- In_Parameter, but for now we examine the formal that
7314 -- corresponds to the indexing, and assume that variable
7315 -- indexing is required if some interpretation has an
7316 -- assignable formal at that position. Still does not
7317 -- cover the most complex cases ???
7319 if Is_Overloaded
(Name
(Parent
(Par
))) then
7321 Proc
: constant Node_Id
:= Name
(Parent
(Par
));
7328 Get_First_Interp
(Proc
, I
, It
);
7329 while Present
(It
.Nam
) loop
7330 F
:= First_Formal
(It
.Nam
);
7331 A
:= First
(Parameter_Associations
(Parent
(Par
)));
7333 while Present
(F
) and then Present
(A
) loop
7335 if Ekind
(F
) /= E_In_Parameter
then
7338 exit; -- interpretation is safe
7346 Get_Next_Interp
(I
, It
);
7353 Proc
:= Entity
(Name
(Parent
(Par
)));
7355 -- If this is an indirect call, get formals from
7358 if Is_Access_Subprogram_Type
(Etype
(Proc
)) then
7359 Proc
:= Designated_Type
(Etype
(Proc
));
7363 Formal
:= First_Formal
(Proc
);
7364 Actual
:= First_Actual
(Parent
(Par
));
7366 -- Find corresponding actual
7368 while Present
(Actual
) loop
7369 exit when Actual
= Par
;
7370 Next_Actual
(Actual
);
7372 if Present
(Formal
) then
7373 Next_Formal
(Formal
);
7375 -- Otherwise this is a parameter mismatch, the error is
7376 -- reported elsewhere.
7383 return Ekind
(Formal
) = E_In_Parameter
;
7386 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
7389 -- If the indexed component is a prefix it may be the first actual
7390 -- of a prefixed call. Retrieve the called entity, if any, and
7391 -- check its first formal. Determine if the context is a procedure
7392 -- or function call.
7394 elsif Nkind
(Parent
(Par
)) = N_Selected_Component
then
7396 Sel
: constant Node_Id
:= Selector_Name
(Parent
(Par
));
7397 Nam
: constant Entity_Id
:= Current_Entity
(Sel
);
7400 if Present
(Nam
) and then Is_Overloadable
(Nam
) then
7401 if Nkind
(Parent
(Parent
(Par
))) =
7402 N_Procedure_Call_Statement
7406 elsif Ekind
(Nam
) = E_Function
7407 and then Present
(First_Formal
(Nam
))
7409 return Ekind
(First_Formal
(Nam
)) = E_In_Parameter
;
7414 elsif Nkind
(Par
) in N_Op
then
7418 Par
:= Parent
(Par
);
7421 -- In all other cases, constant indexing is legal
7424 end Constant_Indexing_OK
;
7426 ------------------------------
7427 -- Find_Indexing_Operations --
7428 ------------------------------
7430 function Find_Indexing_Operations
7433 Is_Constant
: Boolean) return Node_Id
7435 procedure Inspect_Declarations
7437 Ref
: in out Node_Id
);
7438 -- Traverse the declarative list where type Typ resides and collect
7439 -- all suitable interpretations in node Ref.
7441 procedure Inspect_Primitives
7443 Ref
: in out Node_Id
);
7444 -- Traverse the list of primitive operations of type Typ and collect
7445 -- all suitable interpretations in node Ref.
7447 function Is_OK_Candidate
7448 (Subp_Id
: Entity_Id
;
7449 Typ
: Entity_Id
) return Boolean;
7450 -- Determine whether subprogram Subp_Id is a suitable indexing
7451 -- operation for type Typ. To qualify as such, the subprogram must
7452 -- be a function, have at least two parameters, and the type of the
7453 -- first parameter must be either Typ, or Typ'Class, or access [to
7454 -- constant] with designated type Typ or Typ'Class.
7456 procedure Record_Interp
(Subp_Id
: Entity_Id
; Ref
: in out Node_Id
);
7457 -- Store subprogram Subp_Id as an interpretation in node Ref
7459 --------------------------
7460 -- Inspect_Declarations --
7461 --------------------------
7463 procedure Inspect_Declarations
7465 Ref
: in out Node_Id
)
7467 Typ_Decl
: constant Node_Id
:= Declaration_Node
(Typ
);
7469 Subp_Id
: Entity_Id
;
7472 -- Ensure that the routine is not called with itypes, which lack a
7473 -- declarative node.
7475 pragma Assert
(Present
(Typ_Decl
));
7476 pragma Assert
(Is_List_Member
(Typ_Decl
));
7478 Decl
:= First
(List_Containing
(Typ_Decl
));
7479 while Present
(Decl
) loop
7480 if Nkind
(Decl
) = N_Subprogram_Declaration
then
7481 Subp_Id
:= Defining_Entity
(Decl
);
7483 if Is_OK_Candidate
(Subp_Id
, Typ
) then
7484 Record_Interp
(Subp_Id
, Ref
);
7490 end Inspect_Declarations
;
7492 ------------------------
7493 -- Inspect_Primitives --
7494 ------------------------
7496 procedure Inspect_Primitives
7498 Ref
: in out Node_Id
)
7500 Prim_Elmt
: Elmt_Id
;
7501 Prim_Id
: Entity_Id
;
7504 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7505 while Present
(Prim_Elmt
) loop
7506 Prim_Id
:= Node
(Prim_Elmt
);
7508 if Is_OK_Candidate
(Prim_Id
, Typ
) then
7509 Record_Interp
(Prim_Id
, Ref
);
7512 Next_Elmt
(Prim_Elmt
);
7514 end Inspect_Primitives
;
7516 ---------------------
7517 -- Is_OK_Candidate --
7518 ---------------------
7520 function Is_OK_Candidate
7521 (Subp_Id
: Entity_Id
;
7522 Typ
: Entity_Id
) return Boolean
7525 Formal_Typ
: Entity_Id
;
7526 Param_Typ
: Node_Id
;
7529 -- To classify as a suitable candidate, the subprogram must be a
7530 -- function whose name matches the argument of aspect Constant or
7531 -- Variable_Indexing.
7533 if Ekind
(Subp_Id
) = E_Function
and then Chars
(Subp_Id
) = Nam
then
7534 Formal
:= First_Formal
(Subp_Id
);
7536 -- The candidate requires at least two parameters
7538 if Present
(Formal
) and then Present
(Next_Formal
(Formal
)) then
7539 Formal_Typ
:= Empty
;
7540 Param_Typ
:= Parameter_Type
(Parent
(Formal
));
7542 -- Use the designated type when the first parameter is of an
7545 if Nkind
(Param_Typ
) = N_Access_Definition
7546 and then Present
(Subtype_Mark
(Param_Typ
))
7548 -- When the context is a constant indexing, the access
7549 -- definition must be access-to-constant. This does not
7550 -- apply to variable indexing.
7553 or else Constant_Present
(Param_Typ
)
7555 Formal_Typ
:= Etype
(Subtype_Mark
(Param_Typ
));
7558 -- Otherwise use the parameter type
7561 Formal_Typ
:= Etype
(Param_Typ
);
7564 if Present
(Formal_Typ
) then
7566 -- Use the specific type when the parameter type is
7569 if Is_Class_Wide_Type
(Formal_Typ
) then
7570 Formal_Typ
:= Etype
(Base_Type
(Formal_Typ
));
7573 -- Use the full view when the parameter type is private
7576 if Is_Incomplete_Or_Private_Type
(Formal_Typ
)
7577 and then Present
(Full_View
(Formal_Typ
))
7579 Formal_Typ
:= Full_View
(Formal_Typ
);
7582 -- The type of the first parameter must denote the type
7583 -- of the container or acts as its ancestor type.
7587 or else Is_Ancestor
(Formal_Typ
, Typ
);
7593 end Is_OK_Candidate
;
7599 procedure Record_Interp
(Subp_Id
: Entity_Id
; Ref
: in out Node_Id
) is
7601 if Present
(Ref
) then
7602 Add_One_Interp
(Ref
, Subp_Id
, Etype
(Subp_Id
));
7604 -- Otherwise this is the first interpretation. Create a reference
7605 -- where all remaining interpretations will be collected.
7608 Ref
:= New_Occurrence_Of
(Subp_Id
, Sloc
(T
));
7617 -- Start of processing for Find_Indexing_Operations
7622 -- Use the specific type when the parameter type is class-wide
7624 if Is_Class_Wide_Type
(Typ
) then
7625 Typ
:= Root_Type
(Typ
);
7629 Typ
:= Underlying_Type
(Base_Type
(Typ
));
7631 Inspect_Primitives
(Typ
, Ref
);
7632 Inspect_Declarations
(Typ
, Ref
);
7635 end Find_Indexing_Operations
;
7639 Loc
: constant Source_Ptr
:= Sloc
(N
);
7643 Func_Name
: Node_Id
;
7646 Is_Constant_Indexing
: Boolean := False;
7647 -- This flag reflects the nature of the container indexing. Note that
7648 -- the context may be suited for constant indexing, but the type may
7649 -- lack a Constant_Indexing annotation.
7651 -- Start of processing for Try_Container_Indexing
7654 -- Node may have been analyzed already when testing for a prefixed
7655 -- call, in which case do not redo analysis.
7657 if Present
(Generalized_Indexing
(N
)) then
7663 -- If indexing a class-wide container, obtain indexing primitive from
7666 if Is_Class_Wide_Type
(C_Type
) then
7667 C_Type
:= Etype
(Base_Type
(C_Type
));
7670 -- Check whether the type has a specified indexing aspect
7674 -- The context is suitable for constant indexing, so obtain the name of
7675 -- the indexing function from aspect Constant_Indexing.
7677 if Constant_Indexing_OK
then
7679 Find_Value_Of_Aspect
(Pref_Typ
, Aspect_Constant_Indexing
);
7682 if Present
(Func_Name
) then
7683 Is_Constant_Indexing
:= True;
7685 -- Otherwise attempt variable indexing
7689 Find_Value_Of_Aspect
(Pref_Typ
, Aspect_Variable_Indexing
);
7692 -- The type is not subject to either form of indexing, therefore the
7693 -- indexed component does not denote container indexing. If this is a
7694 -- true error, it is diagnosed by the caller.
7696 if No
(Func_Name
) then
7698 -- The prefix itself may be an indexing of a container. Rewrite it
7699 -- as such and retry.
7701 if Has_Implicit_Dereference
(Pref_Typ
) then
7702 Build_Explicit_Dereference
(Prefix
, First_Discriminant
(Pref_Typ
));
7703 return Try_Container_Indexing
(N
, Prefix
, Exprs
);
7705 -- Otherwise this is definitely not container indexing
7711 -- If the container type is derived from another container type, the
7712 -- value of the inherited aspect is the Reference operation declared
7713 -- for the parent type.
7715 -- However, Reference is also a primitive operation of the type, and the
7716 -- inherited operation has a different signature. We retrieve the right
7717 -- ones (the function may be overloaded) from the list of primitive
7718 -- operations of the derived type.
7720 -- Note that predefined containers are typically all derived from one of
7721 -- the Controlled types. The code below is motivated by containers that
7722 -- are derived from other types with a Reference aspect.
7724 elsif Is_Derived_Type
(C_Type
)
7725 and then Etype
(First_Formal
(Entity
(Func_Name
))) /= Pref_Typ
7728 Find_Indexing_Operations
7730 Nam
=> Chars
(Func_Name
),
7731 Is_Constant
=> Is_Constant_Indexing
);
7734 Assoc
:= New_List
(Relocate_Node
(Prefix
));
7736 -- A generalized indexing may have nore than one index expression, so
7737 -- transfer all of them to the argument list to be used in the call.
7738 -- Note that there may be named associations, in which case the node
7739 -- was rewritten earlier as a call, and has been transformed back into
7740 -- an indexed expression to share the following processing.
7742 -- The generalized indexing node is the one on which analysis and
7743 -- resolution take place. Before expansion the original node is replaced
7744 -- with the generalized indexing node, which is a call, possibly with a
7745 -- dereference operation.
7747 if Comes_From_Source
(N
) then
7748 Check_Compiler_Unit
("generalized indexing", N
);
7751 -- Create argument list for function call that represents generalized
7752 -- indexing. Note that indices (i.e. actuals) may themselves be
7760 Arg
:= First
(Exprs
);
7761 while Present
(Arg
) loop
7762 New_Arg
:= Relocate_Node
(Arg
);
7764 -- The arguments can be parameter associations, in which case the
7765 -- explicit actual parameter carries the overloadings.
7767 if Nkind
(New_Arg
) /= N_Parameter_Association
then
7768 Save_Interps
(Arg
, New_Arg
);
7771 Append
(New_Arg
, Assoc
);
7776 if not Is_Overloaded
(Func_Name
) then
7777 Func
:= Entity
(Func_Name
);
7779 Make_Function_Call
(Loc
,
7780 Name
=> New_Occurrence_Of
(Func
, Loc
),
7781 Parameter_Associations
=> Assoc
);
7782 Set_Parent
(Indexing
, Parent
(N
));
7783 Set_Generalized_Indexing
(N
, Indexing
);
7785 Set_Etype
(N
, Etype
(Indexing
));
7787 -- If the return type of the indexing function is a reference type,
7788 -- add the dereference as a possible interpretation. Note that the
7789 -- indexing aspect may be a function that returns the element type
7790 -- with no intervening implicit dereference, and that the reference
7791 -- discriminant is not the first discriminant.
7793 if Has_Discriminants
(Etype
(Func
)) then
7794 Check_Implicit_Dereference
(N
, Etype
(Func
));
7798 -- If there are multiple indexing functions, build a function call
7799 -- and analyze it for each of the possible interpretations.
7802 Make_Function_Call
(Loc
,
7804 Make_Identifier
(Loc
, Chars
(Func_Name
)),
7805 Parameter_Associations
=> Assoc
);
7807 Set_Parent
(Indexing
, Parent
(N
));
7808 Set_Generalized_Indexing
(N
, Indexing
);
7809 Set_Etype
(N
, Any_Type
);
7810 Set_Etype
(Name
(Indexing
), Any_Type
);
7818 Get_First_Interp
(Func_Name
, I
, It
);
7819 Set_Etype
(Indexing
, Any_Type
);
7821 -- Analyze eacn candidae function with the given actuals
7823 while Present
(It
.Nam
) loop
7824 Analyze_One_Call
(Indexing
, It
.Nam
, False, Success
);
7825 Get_Next_Interp
(I
, It
);
7828 -- If there are several successful candidates, resolution will
7829 -- be by result. Mark the interpretations of the function name
7832 if Is_Overloaded
(Indexing
) then
7833 Get_First_Interp
(Indexing
, I
, It
);
7835 while Present
(It
.Nam
) loop
7836 Add_One_Interp
(Name
(Indexing
), It
.Nam
, It
.Typ
);
7837 Get_Next_Interp
(I
, It
);
7841 Set_Etype
(Name
(Indexing
), Etype
(Indexing
));
7844 -- Now add the candidate interpretations to the indexing node
7845 -- itself, to be replaced later by the function call.
7847 if Is_Overloaded
(Name
(Indexing
)) then
7848 Get_First_Interp
(Name
(Indexing
), I
, It
);
7850 while Present
(It
.Nam
) loop
7851 Add_One_Interp
(N
, It
.Nam
, It
.Typ
);
7853 -- Add dereference interpretation if the result type has
7854 -- implicit reference discriminants.
7856 if Has_Discriminants
(Etype
(It
.Nam
)) then
7857 Check_Implicit_Dereference
(N
, Etype
(It
.Nam
));
7860 Get_Next_Interp
(I
, It
);
7864 Set_Etype
(N
, Etype
(Name
(Indexing
)));
7865 if Has_Discriminants
(Etype
(N
)) then
7866 Check_Implicit_Dereference
(N
, Etype
(N
));
7872 if Etype
(Indexing
) = Any_Type
then
7874 ("container cannot be indexed with&", N
, Etype
(First
(Exprs
)));
7875 Rewrite
(N
, New_Occurrence_Of
(Any_Id
, Loc
));
7879 end Try_Container_Indexing
;
7881 -----------------------
7882 -- Try_Indirect_Call --
7883 -----------------------
7885 function Try_Indirect_Call
7888 Typ
: Entity_Id
) return Boolean
7894 pragma Warnings
(Off
, Call_OK
);
7897 Normalize_Actuals
(N
, Designated_Type
(Typ
), False, Call_OK
);
7899 Actual
:= First_Actual
(N
);
7900 Formal
:= First_Formal
(Designated_Type
(Typ
));
7901 while Present
(Actual
) and then Present
(Formal
) loop
7902 if not Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
7907 Next_Formal
(Formal
);
7910 if No
(Actual
) and then No
(Formal
) then
7911 Add_One_Interp
(N
, Nam
, Etype
(Designated_Type
(Typ
)));
7913 -- Nam is a candidate interpretation for the name in the call,
7914 -- if it is not an indirect call.
7916 if not Is_Type
(Nam
)
7917 and then Is_Entity_Name
(Name
(N
))
7919 Set_Entity
(Name
(N
), Nam
);
7927 end Try_Indirect_Call
;
7929 ----------------------
7930 -- Try_Indexed_Call --
7931 ----------------------
7933 function Try_Indexed_Call
7937 Skip_First
: Boolean) return Boolean
7939 Loc
: constant Source_Ptr
:= Sloc
(N
);
7940 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
7945 Actual
:= First
(Actuals
);
7947 -- If the call was originally written in prefix form, skip the first
7948 -- actual, which is obviously not defaulted.
7954 Index
:= First_Index
(Typ
);
7955 while Present
(Actual
) and then Present
(Index
) loop
7957 -- If the parameter list has a named association, the expression
7958 -- is definitely a call and not an indexed component.
7960 if Nkind
(Actual
) = N_Parameter_Association
then
7964 if Is_Entity_Name
(Actual
)
7965 and then Is_Type
(Entity
(Actual
))
7966 and then No
(Next
(Actual
))
7968 -- A single actual that is a type name indicates a slice if the
7969 -- type is discrete, and an error otherwise.
7971 if Is_Discrete_Type
(Entity
(Actual
)) then
7975 Make_Function_Call
(Loc
,
7976 Name
=> Relocate_Node
(Name
(N
))),
7978 New_Occurrence_Of
(Entity
(Actual
), Sloc
(Actual
))));
7983 Error_Msg_N
("invalid use of type in expression", Actual
);
7984 Set_Etype
(N
, Any_Type
);
7989 elsif not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
7997 if No
(Actual
) and then No
(Index
) then
7998 Add_One_Interp
(N
, Nam
, Component_Type
(Typ
));
8000 -- Nam is a candidate interpretation for the name in the call,
8001 -- if it is not an indirect call.
8003 if not Is_Type
(Nam
)
8004 and then Is_Entity_Name
(Name
(N
))
8006 Set_Entity
(Name
(N
), Nam
);
8013 end Try_Indexed_Call
;
8015 --------------------------
8016 -- Try_Object_Operation --
8017 --------------------------
8019 function Try_Object_Operation
8020 (N
: Node_Id
; CW_Test_Only
: Boolean := False) return Boolean
8022 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
8023 Is_Subprg_Call
: constant Boolean := K
in N_Subprogram_Call
;
8024 Loc
: constant Source_Ptr
:= Sloc
(N
);
8025 Obj
: constant Node_Id
:= Prefix
(N
);
8027 Subprog
: constant Node_Id
:=
8028 Make_Identifier
(Sloc
(Selector_Name
(N
)),
8029 Chars
=> Chars
(Selector_Name
(N
)));
8030 -- Identifier on which possible interpretations will be collected
8032 Report_Error
: Boolean := False;
8033 -- If no candidate interpretation matches the context, redo analysis
8034 -- with Report_Error True to provide additional information.
8037 Candidate
: Entity_Id
:= Empty
;
8038 New_Call_Node
: Node_Id
:= Empty
;
8039 Node_To_Replace
: Node_Id
;
8040 Obj_Type
: Entity_Id
:= Etype
(Obj
);
8041 Success
: Boolean := False;
8043 function Valid_Candidate
8046 Subp
: Entity_Id
) return Entity_Id
;
8047 -- If the subprogram is a valid interpretation, record it, and add
8048 -- to the list of interpretations of Subprog. Otherwise return Empty.
8050 procedure Complete_Object_Operation
8051 (Call_Node
: Node_Id
;
8052 Node_To_Replace
: Node_Id
);
8053 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
8054 -- Call_Node, insert the object (or its dereference) as the first actual
8055 -- in the call, and complete the analysis of the call.
8057 procedure Report_Ambiguity
(Op
: Entity_Id
);
8058 -- If a prefixed procedure call is ambiguous, indicate whether the
8059 -- call includes an implicit dereference or an implicit 'Access.
8061 procedure Transform_Object_Operation
8062 (Call_Node
: out Node_Id
;
8063 Node_To_Replace
: out Node_Id
);
8064 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
8065 -- Call_Node is the resulting subprogram call, Node_To_Replace is
8066 -- either N or the parent of N, and Subprog is a reference to the
8067 -- subprogram we are trying to match.
8069 function Try_Class_Wide_Operation
8070 (Call_Node
: Node_Id
;
8071 Node_To_Replace
: Node_Id
) return Boolean;
8072 -- Traverse all ancestor types looking for a class-wide subprogram
8073 -- for which the current operation is a valid non-dispatching call.
8075 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
);
8076 -- If prefix is overloaded, its interpretation may include different
8077 -- tagged types, and we must examine the primitive operations and
8078 -- the class-wide operations of each in order to find candidate
8079 -- interpretations for the call as a whole.
8081 function Try_Primitive_Operation
8082 (Call_Node
: Node_Id
;
8083 Node_To_Replace
: Node_Id
) return Boolean;
8084 -- Traverse the list of primitive subprograms looking for a dispatching
8085 -- operation for which the current node is a valid call .
8087 ---------------------
8088 -- Valid_Candidate --
8089 ---------------------
8091 function Valid_Candidate
8094 Subp
: Entity_Id
) return Entity_Id
8096 Arr_Type
: Entity_Id
;
8097 Comp_Type
: Entity_Id
;
8100 -- If the subprogram is a valid interpretation, record it in global
8101 -- variable Subprog, to collect all possible overloadings.
8104 if Subp
/= Entity
(Subprog
) then
8105 Add_One_Interp
(Subprog
, Subp
, Etype
(Subp
));
8109 -- If the call may be an indexed call, retrieve component type of
8110 -- resulting expression, and add possible interpretation.
8115 if Nkind
(Call
) = N_Function_Call
8116 and then Nkind
(Parent
(N
)) = N_Indexed_Component
8117 and then Needs_One_Actual
(Subp
)
8119 if Is_Array_Type
(Etype
(Subp
)) then
8120 Arr_Type
:= Etype
(Subp
);
8122 elsif Is_Access_Type
(Etype
(Subp
))
8123 and then Is_Array_Type
(Designated_Type
(Etype
(Subp
)))
8125 Arr_Type
:= Designated_Type
(Etype
(Subp
));
8129 if Present
(Arr_Type
) then
8131 -- Verify that the actuals (excluding the object) match the types
8139 Actual
:= Next
(First_Actual
(Call
));
8140 Index
:= First_Index
(Arr_Type
);
8141 while Present
(Actual
) and then Present
(Index
) loop
8142 if not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
8147 Next_Actual
(Actual
);
8153 and then Present
(Arr_Type
)
8155 Comp_Type
:= Component_Type
(Arr_Type
);
8159 if Present
(Comp_Type
)
8160 and then Etype
(Subprog
) /= Comp_Type
8162 Add_One_Interp
(Subprog
, Subp
, Comp_Type
);
8166 if Etype
(Call
) /= Any_Type
then
8171 end Valid_Candidate
;
8173 -------------------------------
8174 -- Complete_Object_Operation --
8175 -------------------------------
8177 procedure Complete_Object_Operation
8178 (Call_Node
: Node_Id
;
8179 Node_To_Replace
: Node_Id
)
8181 Control
: constant Entity_Id
:= First_Formal
(Entity
(Subprog
));
8182 Formal_Type
: constant Entity_Id
:= Etype
(Control
);
8183 First_Actual
: Node_Id
;
8186 -- Place the name of the operation, with its interpretations,
8187 -- on the rewritten call.
8189 Set_Name
(Call_Node
, Subprog
);
8191 First_Actual
:= First
(Parameter_Associations
(Call_Node
));
8193 -- For cross-reference purposes, treat the new node as being in the
8194 -- source if the original one is. Set entity and type, even though
8195 -- they may be overwritten during resolution if overloaded.
8197 Set_Comes_From_Source
(Subprog
, Comes_From_Source
(N
));
8198 Set_Comes_From_Source
(Call_Node
, Comes_From_Source
(N
));
8200 if Nkind
(N
) = N_Selected_Component
8201 and then not Inside_A_Generic
8203 Set_Entity
(Selector_Name
(N
), Entity
(Subprog
));
8204 Set_Etype
(Selector_Name
(N
), Etype
(Entity
(Subprog
)));
8207 -- If need be, rewrite first actual as an explicit dereference. If
8208 -- the call is overloaded, the rewriting can only be done once the
8209 -- primitive operation is identified.
8211 if Is_Overloaded
(Subprog
) then
8213 -- The prefix itself may be overloaded, and its interpretations
8214 -- must be propagated to the new actual in the call.
8216 if Is_Overloaded
(Obj
) then
8217 Save_Interps
(Obj
, First_Actual
);
8220 Rewrite
(First_Actual
, Obj
);
8222 elsif not Is_Access_Type
(Formal_Type
)
8223 and then Is_Access_Type
(Etype
(Obj
))
8225 Rewrite
(First_Actual
,
8226 Make_Explicit_Dereference
(Sloc
(Obj
), Obj
));
8227 Analyze
(First_Actual
);
8229 -- If we need to introduce an explicit dereference, verify that
8230 -- the resulting actual is compatible with the mode of the formal.
8232 if Ekind
(First_Formal
(Entity
(Subprog
))) /= E_In_Parameter
8233 and then Is_Access_Constant
(Etype
(Obj
))
8236 ("expect variable in call to&", Prefix
(N
), Entity
(Subprog
));
8239 -- Conversely, if the formal is an access parameter and the object
8240 -- is not, replace the actual with a 'Access reference. Its analysis
8241 -- will check that the object is aliased.
8243 elsif Is_Access_Type
(Formal_Type
)
8244 and then not Is_Access_Type
(Etype
(Obj
))
8246 -- A special case: A.all'access is illegal if A is an access to a
8247 -- constant and the context requires an access to a variable.
8249 if not Is_Access_Constant
(Formal_Type
) then
8250 if (Nkind
(Obj
) = N_Explicit_Dereference
8251 and then Is_Access_Constant
(Etype
(Prefix
(Obj
))))
8252 or else not Is_Variable
(Obj
)
8255 ("actual for & must be a variable", Obj
, Control
);
8259 Rewrite
(First_Actual
,
8260 Make_Attribute_Reference
(Loc
,
8261 Attribute_Name
=> Name_Access
,
8262 Prefix
=> Relocate_Node
(Obj
)));
8264 if not Is_Aliased_View
(Obj
) then
8266 ("object in prefixed call to & must be aliased "
8267 & "(RM 4.1.3 (13 1/2))", Prefix
(First_Actual
), Subprog
);
8270 Analyze
(First_Actual
);
8273 if Is_Overloaded
(Obj
) then
8274 Save_Interps
(Obj
, First_Actual
);
8277 Rewrite
(First_Actual
, Obj
);
8280 -- The operation is obtained from the dispatch table and not by
8281 -- visibility, and may be declared in a unit that is not explicitly
8282 -- referenced in the source, but is nevertheless required in the
8283 -- context of the current unit. Indicate that operation and its scope
8284 -- are referenced, to prevent spurious and misleading warnings. If
8285 -- the operation is overloaded, all primitives are in the same scope
8286 -- and we can use any of them.
8288 Set_Referenced
(Entity
(Subprog
), True);
8289 Set_Referenced
(Scope
(Entity
(Subprog
)), True);
8291 Rewrite
(Node_To_Replace
, Call_Node
);
8293 -- Propagate the interpretations collected in subprog to the new
8294 -- function call node, to be resolved from context.
8296 if Is_Overloaded
(Subprog
) then
8297 Save_Interps
(Subprog
, Node_To_Replace
);
8300 -- The type of the subprogram may be a limited view obtained
8301 -- transitively from another unit. If full view is available,
8302 -- use it to analyze call.
8305 T
: constant Entity_Id
:= Etype
(Subprog
);
8307 if From_Limited_With
(T
) then
8308 Set_Etype
(Entity
(Subprog
), Available_View
(T
));
8312 Analyze
(Node_To_Replace
);
8314 -- If the operation has been rewritten into a call, which may get
8315 -- subsequently an explicit dereference, preserve the type on the
8316 -- original node (selected component or indexed component) for
8317 -- subsequent legality tests, e.g. Is_Variable. which examines
8318 -- the original node.
8320 if Nkind
(Node_To_Replace
) = N_Function_Call
then
8322 (Original_Node
(Node_To_Replace
), Etype
(Node_To_Replace
));
8325 end Complete_Object_Operation
;
8327 ----------------------
8328 -- Report_Ambiguity --
8329 ----------------------
8331 procedure Report_Ambiguity
(Op
: Entity_Id
) is
8332 Access_Actual
: constant Boolean :=
8333 Is_Access_Type
(Etype
(Prefix
(N
)));
8334 Access_Formal
: Boolean := False;
8337 Error_Msg_Sloc
:= Sloc
(Op
);
8339 if Present
(First_Formal
(Op
)) then
8340 Access_Formal
:= Is_Access_Type
(Etype
(First_Formal
(Op
)));
8343 if Access_Formal
and then not Access_Actual
then
8344 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
8346 ("\possible interpretation "
8347 & "(inherited, with implicit 'Access) #", N
);
8350 ("\possible interpretation (with implicit 'Access) #", N
);
8353 elsif not Access_Formal
and then Access_Actual
then
8354 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
8356 ("\possible interpretation "
8357 & "(inherited, with implicit dereference) #", N
);
8360 ("\possible interpretation (with implicit dereference) #", N
);
8364 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
8365 Error_Msg_N
("\possible interpretation (inherited)#", N
);
8367 Error_Msg_N
-- CODEFIX
8368 ("\possible interpretation#", N
);
8371 end Report_Ambiguity
;
8373 --------------------------------
8374 -- Transform_Object_Operation --
8375 --------------------------------
8377 procedure Transform_Object_Operation
8378 (Call_Node
: out Node_Id
;
8379 Node_To_Replace
: out Node_Id
)
8381 Dummy
: constant Node_Id
:= New_Copy
(Obj
);
8382 -- Placeholder used as a first parameter in the call, replaced
8383 -- eventually by the proper object.
8385 Parent_Node
: constant Node_Id
:= Parent
(N
);
8391 -- Common case covering 1) Call to a procedure and 2) Call to a
8392 -- function that has some additional actuals.
8394 if Nkind
(Parent_Node
) in N_Subprogram_Call
8396 -- N is a selected component node containing the name of the
8397 -- subprogram. If N is not the name of the parent node we must
8398 -- not replace the parent node by the new construct. This case
8399 -- occurs when N is a parameterless call to a subprogram that
8400 -- is an actual parameter of a call to another subprogram. For
8402 -- Some_Subprogram (..., Obj.Operation, ...)
8404 and then Name
(Parent_Node
) = N
8406 Node_To_Replace
:= Parent_Node
;
8408 Actuals
:= Parameter_Associations
(Parent_Node
);
8410 if Present
(Actuals
) then
8411 Prepend
(Dummy
, Actuals
);
8413 Actuals
:= New_List
(Dummy
);
8416 if Nkind
(Parent_Node
) = N_Procedure_Call_Statement
then
8418 Make_Procedure_Call_Statement
(Loc
,
8419 Name
=> New_Copy
(Subprog
),
8420 Parameter_Associations
=> Actuals
);
8424 Make_Function_Call
(Loc
,
8425 Name
=> New_Copy
(Subprog
),
8426 Parameter_Associations
=> Actuals
);
8429 -- Before analysis, a function call appears as an indexed component
8430 -- if there are no named associations.
8432 elsif Nkind
(Parent_Node
) = N_Indexed_Component
8433 and then N
= Prefix
(Parent_Node
)
8435 Node_To_Replace
:= Parent_Node
;
8436 Actuals
:= Expressions
(Parent_Node
);
8438 Actual
:= First
(Actuals
);
8439 while Present
(Actual
) loop
8444 Prepend
(Dummy
, Actuals
);
8447 Make_Function_Call
(Loc
,
8448 Name
=> New_Copy
(Subprog
),
8449 Parameter_Associations
=> Actuals
);
8451 -- Parameterless call: Obj.F is rewritten as F (Obj)
8454 Node_To_Replace
:= N
;
8457 Make_Function_Call
(Loc
,
8458 Name
=> New_Copy
(Subprog
),
8459 Parameter_Associations
=> New_List
(Dummy
));
8461 end Transform_Object_Operation
;
8463 ------------------------------
8464 -- Try_Class_Wide_Operation --
8465 ------------------------------
8467 function Try_Class_Wide_Operation
8468 (Call_Node
: Node_Id
;
8469 Node_To_Replace
: Node_Id
) return Boolean
8471 Anc_Type
: Entity_Id
;
8472 Matching_Op
: Entity_Id
:= Empty
;
8475 procedure Traverse_Homonyms
8476 (Anc_Type
: Entity_Id
;
8477 Error
: out Boolean);
8478 -- Traverse the homonym chain of the subprogram searching for those
8479 -- homonyms whose first formal has the Anc_Type's class-wide type,
8480 -- or an anonymous access type designating the class-wide type. If
8481 -- an ambiguity is detected, then Error is set to True.
8483 procedure Traverse_Interfaces
8484 (Anc_Type
: Entity_Id
;
8485 Error
: out Boolean);
8486 -- Traverse the list of interfaces, if any, associated with Anc_Type
8487 -- and search for acceptable class-wide homonyms associated with each
8488 -- interface. If an ambiguity is detected, then Error is set to True.
8490 -----------------------
8491 -- Traverse_Homonyms --
8492 -----------------------
8494 procedure Traverse_Homonyms
8495 (Anc_Type
: Entity_Id
;
8496 Error
: out Boolean)
8498 Cls_Type
: Entity_Id
;
8506 Cls_Type
:= Class_Wide_Type
(Anc_Type
);
8508 Hom
:= Current_Entity
(Subprog
);
8510 -- Find a non-hidden operation whose first parameter is of the
8511 -- class-wide type, a subtype thereof, or an anonymous access
8512 -- to same. If in an instance, the operation can be considered
8513 -- even if hidden (it may be hidden because the instantiation
8514 -- is expanded after the containing package has been analyzed).
8516 while Present
(Hom
) loop
8517 if Ekind_In
(Hom
, E_Procedure
, E_Function
)
8518 and then (not Is_Hidden
(Hom
) or else In_Instance
)
8519 and then Scope
(Hom
) = Scope
(Anc_Type
)
8520 and then Present
(First_Formal
(Hom
))
8522 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
8524 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
8526 Ekind
(Etype
(First_Formal
(Hom
))) =
8527 E_Anonymous_Access_Type
8530 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
8533 -- If the context is a procedure call, ignore functions
8534 -- in the name of the call.
8536 if Ekind
(Hom
) = E_Function
8537 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
8538 and then N
= Name
(Parent
(N
))
8542 -- If the context is a function call, ignore procedures
8543 -- in the name of the call.
8545 elsif Ekind
(Hom
) = E_Procedure
8546 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
8551 Set_Etype
(Call_Node
, Any_Type
);
8552 Set_Is_Overloaded
(Call_Node
, False);
8555 if No
(Matching_Op
) then
8556 Hom_Ref
:= New_Occurrence_Of
(Hom
, Sloc
(Subprog
));
8557 Set_Etype
(Call_Node
, Any_Type
);
8558 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
8560 Set_Name
(Call_Node
, Hom_Ref
);
8565 Report
=> Report_Error
,
8567 Skip_First
=> True);
8570 Valid_Candidate
(Success
, Call_Node
, Hom
);
8576 Report
=> Report_Error
,
8578 Skip_First
=> True);
8580 if Present
(Valid_Candidate
(Success
, Call_Node
, Hom
))
8581 and then Nkind
(Call_Node
) /= N_Function_Call
8583 Error_Msg_NE
("ambiguous call to&", N
, Hom
);
8584 Report_Ambiguity
(Matching_Op
);
8585 Report_Ambiguity
(Hom
);
8593 Hom
:= Homonym
(Hom
);
8595 end Traverse_Homonyms
;
8597 -------------------------
8598 -- Traverse_Interfaces --
8599 -------------------------
8601 procedure Traverse_Interfaces
8602 (Anc_Type
: Entity_Id
;
8603 Error
: out Boolean)
8605 Intface_List
: constant List_Id
:=
8606 Abstract_Interface_List
(Anc_Type
);
8612 if Is_Non_Empty_List
(Intface_List
) then
8613 Intface
:= First
(Intface_List
);
8614 while Present
(Intface
) loop
8616 -- Look for acceptable class-wide homonyms associated with
8619 Traverse_Homonyms
(Etype
(Intface
), Error
);
8625 -- Continue the search by looking at each of the interface's
8626 -- associated interface ancestors.
8628 Traverse_Interfaces
(Etype
(Intface
), Error
);
8637 end Traverse_Interfaces
;
8639 -- Start of processing for Try_Class_Wide_Operation
8642 -- If we are searching only for conflicting class-wide subprograms
8643 -- then initialize directly Matching_Op with the target entity.
8645 if CW_Test_Only
then
8646 Matching_Op
:= Entity
(Selector_Name
(N
));
8649 -- Loop through ancestor types (including interfaces), traversing
8650 -- the homonym chain of the subprogram, trying out those homonyms
8651 -- whose first formal has the class-wide type of the ancestor, or
8652 -- an anonymous access type designating the class-wide type.
8654 Anc_Type
:= Obj_Type
;
8656 -- Look for a match among homonyms associated with the ancestor
8658 Traverse_Homonyms
(Anc_Type
, Error
);
8664 -- Continue the search for matches among homonyms associated with
8665 -- any interfaces implemented by the ancestor.
8667 Traverse_Interfaces
(Anc_Type
, Error
);
8673 exit when Etype
(Anc_Type
) = Anc_Type
;
8674 Anc_Type
:= Etype
(Anc_Type
);
8677 if Present
(Matching_Op
) then
8678 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
8681 return Present
(Matching_Op
);
8682 end Try_Class_Wide_Operation
;
8684 -----------------------------------
8685 -- Try_One_Prefix_Interpretation --
8686 -----------------------------------
8688 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
) is
8690 -- If the interpretation does not have a valid candidate type,
8691 -- preserve current value of Obj_Type for subsequent errors.
8693 Prev_Obj_Type
: constant Entity_Id
:= Obj_Type
;
8698 if Is_Access_Type
(Obj_Type
) then
8699 Obj_Type
:= Designated_Type
(Obj_Type
);
8702 if Ekind
(Obj_Type
) = E_Private_Subtype
then
8703 Obj_Type
:= Base_Type
(Obj_Type
);
8706 if Is_Class_Wide_Type
(Obj_Type
) then
8707 Obj_Type
:= Etype
(Class_Wide_Type
(Obj_Type
));
8710 -- The type may have be obtained through a limited_with clause,
8711 -- in which case the primitive operations are available on its
8712 -- non-limited view. If still incomplete, retrieve full view.
8714 if Ekind
(Obj_Type
) = E_Incomplete_Type
8715 and then From_Limited_With
(Obj_Type
)
8716 and then Has_Non_Limited_View
(Obj_Type
)
8718 Obj_Type
:= Get_Full_View
(Non_Limited_View
(Obj_Type
));
8721 -- If the object is not tagged, or the type is still an incomplete
8722 -- type, this is not a prefixed call.
8724 if not Is_Tagged_Type
(Obj_Type
)
8725 or else Is_Incomplete_Type
(Obj_Type
)
8728 -- Restore previous type if current one is not legal candidate
8730 Obj_Type
:= Prev_Obj_Type
;
8735 Dup_Call_Node
: constant Node_Id
:= New_Copy
(New_Call_Node
);
8736 CW_Result
: Boolean;
8737 Prim_Result
: Boolean;
8738 pragma Unreferenced
(CW_Result
);
8741 if not CW_Test_Only
then
8743 Try_Primitive_Operation
8744 (Call_Node
=> New_Call_Node
,
8745 Node_To_Replace
=> Node_To_Replace
);
8748 -- Check if there is a class-wide subprogram covering the
8749 -- primitive. This check must be done even if a candidate
8750 -- was found in order to report ambiguous calls.
8752 if not (Prim_Result
) then
8754 Try_Class_Wide_Operation
8755 (Call_Node
=> New_Call_Node
,
8756 Node_To_Replace
=> Node_To_Replace
);
8758 -- If we found a primitive we search for class-wide subprograms
8759 -- using a duplicate of the call node (done to avoid missing its
8760 -- decoration if there is no ambiguity).
8764 Try_Class_Wide_Operation
8765 (Call_Node
=> Dup_Call_Node
,
8766 Node_To_Replace
=> Node_To_Replace
);
8769 end Try_One_Prefix_Interpretation
;
8771 -----------------------------
8772 -- Try_Primitive_Operation --
8773 -----------------------------
8775 function Try_Primitive_Operation
8776 (Call_Node
: Node_Id
;
8777 Node_To_Replace
: Node_Id
) return Boolean
8780 Prim_Op
: Entity_Id
;
8781 Matching_Op
: Entity_Id
:= Empty
;
8782 Prim_Op_Ref
: Node_Id
:= Empty
;
8784 Corr_Type
: Entity_Id
:= Empty
;
8785 -- If the prefix is a synchronized type, the controlling type of
8786 -- the primitive operation is the corresponding record type, else
8787 -- this is the object type itself.
8789 Success
: Boolean := False;
8791 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
;
8792 -- For tagged types the candidate interpretations are found in
8793 -- the list of primitive operations of the type and its ancestors.
8794 -- For formal tagged types we have to find the operations declared
8795 -- in the same scope as the type (including in the generic formal
8796 -- part) because the type itself carries no primitive operations,
8797 -- except for formal derived types that inherit the operations of
8798 -- the parent and progenitors.
8800 -- If the context is a generic subprogram body, the generic formals
8801 -- are visible by name, but are not in the entity list of the
8802 -- subprogram because that list starts with the subprogram formals.
8803 -- We retrieve the candidate operations from the generic declaration.
8805 function Extended_Primitive_Ops
(T
: Entity_Id
) return Elist_Id
;
8806 -- Prefix notation can also be used on operations that are not
8807 -- primitives of the type, but are declared in the same immediate
8808 -- declarative part, which can only mean the corresponding package
8809 -- body (See RM 4.1.3 (9.2/3)). If we are in that body we extend the
8810 -- list of primitives with body operations with the same name that
8811 -- may be candidates, so that Try_Primitive_Operations can examine
8812 -- them if no real primitive is found.
8814 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean;
8815 -- An operation that overrides an inherited operation in the private
8816 -- part of its package may be hidden, but if the inherited operation
8817 -- is visible a direct call to it will dispatch to the private one,
8818 -- which is therefore a valid candidate.
8820 function Names_Match
8821 (Obj_Type
: Entity_Id
;
8822 Prim_Op
: Entity_Id
;
8823 Subprog
: Entity_Id
) return Boolean;
8824 -- Return True if the names of Prim_Op and Subprog match. If Obj_Type
8825 -- is a protected type then compare also the original name of Prim_Op
8826 -- with the name of Subprog (since the expander may have added a
8827 -- prefix to its original name --see Exp_Ch9.Build_Selected_Name).
8829 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean;
8830 -- Verify that the prefix, dereferenced if need be, is a valid
8831 -- controlling argument in a call to Op. The remaining actuals
8832 -- are checked in the subsequent call to Analyze_One_Call.
8834 ------------------------------
8835 -- Collect_Generic_Type_Ops --
8836 ------------------------------
8838 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
is
8839 Bas
: constant Entity_Id
:= Base_Type
(T
);
8840 Candidates
: constant Elist_Id
:= New_Elmt_List
;
8844 procedure Check_Candidate
;
8845 -- The operation is a candidate if its first parameter is a
8846 -- controlling operand of the desired type.
8848 -----------------------
8849 -- Check_Candidate; --
8850 -----------------------
8852 procedure Check_Candidate
is
8854 Formal
:= First_Formal
(Subp
);
8857 and then Is_Controlling_Formal
(Formal
)
8859 (Base_Type
(Etype
(Formal
)) = Bas
8861 (Is_Access_Type
(Etype
(Formal
))
8862 and then Designated_Type
(Etype
(Formal
)) = Bas
))
8864 Append_Elmt
(Subp
, Candidates
);
8866 end Check_Candidate
;
8868 -- Start of processing for Collect_Generic_Type_Ops
8871 if Is_Derived_Type
(T
) then
8872 return Primitive_Operations
(T
);
8874 elsif Ekind_In
(Scope
(T
), E_Procedure
, E_Function
) then
8876 -- Scan the list of generic formals to find subprograms
8877 -- that may have a first controlling formal of the type.
8879 if Nkind
(Unit_Declaration_Node
(Scope
(T
))) =
8880 N_Generic_Subprogram_Declaration
8887 First
(Generic_Formal_Declarations
8888 (Unit_Declaration_Node
(Scope
(T
))));
8889 while Present
(Decl
) loop
8890 if Nkind
(Decl
) in N_Formal_Subprogram_Declaration
then
8891 Subp
:= Defining_Entity
(Decl
);
8902 -- Scan the list of entities declared in the same scope as
8903 -- the type. In general this will be an open scope, given that
8904 -- the call we are analyzing can only appear within a generic
8905 -- declaration or body (either the one that declares T, or a
8908 -- For a subtype representing a generic actual type, go to the
8911 if Is_Generic_Actual_Type
(T
) then
8912 Subp
:= First_Entity
(Scope
(Base_Type
(T
)));
8914 Subp
:= First_Entity
(Scope
(T
));
8917 while Present
(Subp
) loop
8918 if Is_Overloadable
(Subp
) then
8927 end Collect_Generic_Type_Ops
;
8929 ----------------------------
8930 -- Extended_Primitive_Ops --
8931 ----------------------------
8933 function Extended_Primitive_Ops
(T
: Entity_Id
) return Elist_Id
is
8934 Type_Scope
: constant Entity_Id
:= Scope
(T
);
8936 Body_Decls
: List_Id
;
8942 Op_List
:= Primitive_Operations
(T
);
8944 if Ekind
(Type_Scope
) = E_Package
8945 and then In_Package_Body
(Type_Scope
)
8946 and then In_Open_Scopes
(Type_Scope
)
8948 -- Retrieve list of declarations of package body.
8952 (Unit_Declaration_Node
8954 (Unit_Declaration_Node
(Type_Scope
))));
8956 Op
:= Current_Entity
(Subprog
);
8958 while Present
(Op
) loop
8959 if Comes_From_Source
(Op
)
8960 and then Is_Overloadable
(Op
)
8962 -- Exclude overriding primitive operations of a type
8963 -- extension declared in the package body, to prevent
8964 -- duplicates in extended list.
8966 and then not Is_Primitive
(Op
)
8967 and then Is_List_Member
(Unit_Declaration_Node
(Op
))
8968 and then List_Containing
(Unit_Declaration_Node
(Op
)) =
8971 if not Op_Found
then
8973 -- Copy list of primitives so it is not affected for
8976 Op_List
:= New_Copy_Elist
(Op_List
);
8980 Append_Elmt
(Op
, Op_List
);
8988 end Extended_Primitive_Ops
;
8990 ---------------------------
8991 -- Is_Private_Overriding --
8992 ---------------------------
8994 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean is
8995 Visible_Op
: constant Entity_Id
:= Homonym
(Op
);
8998 return Present
(Visible_Op
)
8999 and then Scope
(Op
) = Scope
(Visible_Op
)
9000 and then not Comes_From_Source
(Visible_Op
)
9001 and then Alias
(Visible_Op
) = Op
9002 and then not Is_Hidden
(Visible_Op
);
9003 end Is_Private_Overriding
;
9009 function Names_Match
9010 (Obj_Type
: Entity_Id
;
9011 Prim_Op
: Entity_Id
;
9012 Subprog
: Entity_Id
) return Boolean is
9014 -- Common case: exact match
9016 if Chars
(Prim_Op
) = Chars
(Subprog
) then
9019 -- For protected type primitives the expander may have built the
9020 -- name of the dispatching primitive prepending the type name to
9021 -- avoid conflicts with the name of the protected subprogram (see
9022 -- Exp_Ch9.Build_Selected_Name).
9024 elsif Is_Protected_Type
(Obj_Type
) then
9026 Present
(Original_Protected_Subprogram
(Prim_Op
))
9027 and then Chars
(Original_Protected_Subprogram
(Prim_Op
)) =
9034 -----------------------------
9035 -- Valid_First_Argument_Of --
9036 -----------------------------
9038 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean is
9039 Typ
: Entity_Id
:= Etype
(First_Formal
(Op
));
9042 if Is_Concurrent_Type
(Typ
)
9043 and then Present
(Corresponding_Record_Type
(Typ
))
9045 Typ
:= Corresponding_Record_Type
(Typ
);
9048 -- Simple case. Object may be a subtype of the tagged type or
9049 -- may be the corresponding record of a synchronized type.
9051 return Obj_Type
= Typ
9052 or else Base_Type
(Obj_Type
) = Typ
9053 or else Corr_Type
= Typ
9055 -- Prefix can be dereferenced
9058 (Is_Access_Type
(Corr_Type
)
9059 and then Designated_Type
(Corr_Type
) = Typ
)
9061 -- Formal is an access parameter, for which the object
9062 -- can provide an access.
9065 (Ekind
(Typ
) = E_Anonymous_Access_Type
9067 Base_Type
(Designated_Type
(Typ
)) = Base_Type
(Corr_Type
));
9068 end Valid_First_Argument_Of
;
9070 -- Start of processing for Try_Primitive_Operation
9073 -- Look for subprograms in the list of primitive operations. The name
9074 -- must be identical, and the kind of call indicates the expected
9075 -- kind of operation (function or procedure). If the type is a
9076 -- (tagged) synchronized type, the primitive ops are attached to the
9077 -- corresponding record (base) type.
9079 if Is_Concurrent_Type
(Obj_Type
) then
9080 if Present
(Corresponding_Record_Type
(Obj_Type
)) then
9081 Corr_Type
:= Base_Type
(Corresponding_Record_Type
(Obj_Type
));
9082 Elmt
:= First_Elmt
(Primitive_Operations
(Corr_Type
));
9084 Corr_Type
:= Obj_Type
;
9085 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
9088 elsif not Is_Generic_Type
(Obj_Type
) then
9089 Corr_Type
:= Obj_Type
;
9090 Elmt
:= First_Elmt
(Extended_Primitive_Ops
(Obj_Type
));
9093 Corr_Type
:= Obj_Type
;
9094 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
9097 while Present
(Elmt
) loop
9098 Prim_Op
:= Node
(Elmt
);
9100 if Names_Match
(Obj_Type
, Prim_Op
, Subprog
)
9101 and then Present
(First_Formal
(Prim_Op
))
9102 and then Valid_First_Argument_Of
(Prim_Op
)
9104 (Nkind
(Call_Node
) = N_Function_Call
)
9106 (Ekind
(Prim_Op
) = E_Function
)
9108 -- Ada 2005 (AI-251): If this primitive operation corresponds
9109 -- to an immediate ancestor interface there is no need to add
9110 -- it to the list of interpretations; the corresponding aliased
9111 -- primitive is also in this list of primitive operations and
9112 -- will be used instead.
9114 if (Present
(Interface_Alias
(Prim_Op
))
9115 and then Is_Ancestor
(Find_Dispatching_Type
9116 (Alias
(Prim_Op
)), Corr_Type
))
9118 -- Do not consider hidden primitives unless the type is in an
9119 -- open scope or we are within an instance, where visibility
9120 -- is known to be correct, or else if this is an overriding
9121 -- operation in the private part for an inherited operation.
9123 or else (Is_Hidden
(Prim_Op
)
9124 and then not Is_Immediately_Visible
(Obj_Type
)
9125 and then not In_Instance
9126 and then not Is_Private_Overriding
(Prim_Op
))
9131 Set_Etype
(Call_Node
, Any_Type
);
9132 Set_Is_Overloaded
(Call_Node
, False);
9134 if No
(Matching_Op
) then
9135 Prim_Op_Ref
:= New_Occurrence_Of
(Prim_Op
, Sloc
(Subprog
));
9136 Candidate
:= Prim_Op
;
9138 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
9140 Set_Name
(Call_Node
, Prim_Op_Ref
);
9146 Report
=> Report_Error
,
9148 Skip_First
=> True);
9150 Matching_Op
:= Valid_Candidate
(Success
, Call_Node
, Prim_Op
);
9152 -- More than one interpretation, collect for subsequent
9153 -- disambiguation. If this is a procedure call and there
9154 -- is another match, report ambiguity now.
9160 Report
=> Report_Error
,
9162 Skip_First
=> True);
9164 if Present
(Valid_Candidate
(Success
, Call_Node
, Prim_Op
))
9165 and then Nkind
(Call_Node
) /= N_Function_Call
9167 Error_Msg_NE
("ambiguous call to&", N
, Prim_Op
);
9168 Report_Ambiguity
(Matching_Op
);
9169 Report_Ambiguity
(Prim_Op
);
9179 if Present
(Matching_Op
) then
9180 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
9183 return Present
(Matching_Op
);
9184 end Try_Primitive_Operation
;
9186 -- Start of processing for Try_Object_Operation
9189 Analyze_Expression
(Obj
);
9191 -- Analyze the actuals if node is known to be a subprogram call
9193 if Is_Subprg_Call
and then N
= Name
(Parent
(N
)) then
9194 Actual
:= First
(Parameter_Associations
(Parent
(N
)));
9195 while Present
(Actual
) loop
9196 Analyze_Expression
(Actual
);
9201 -- Build a subprogram call node, using a copy of Obj as its first
9202 -- actual. This is a placeholder, to be replaced by an explicit
9203 -- dereference when needed.
9205 Transform_Object_Operation
9206 (Call_Node
=> New_Call_Node
,
9207 Node_To_Replace
=> Node_To_Replace
);
9209 Set_Etype
(New_Call_Node
, Any_Type
);
9210 Set_Etype
(Subprog
, Any_Type
);
9211 Set_Parent
(New_Call_Node
, Parent
(Node_To_Replace
));
9213 if not Is_Overloaded
(Obj
) then
9214 Try_One_Prefix_Interpretation
(Obj_Type
);
9221 Get_First_Interp
(Obj
, I
, It
);
9222 while Present
(It
.Nam
) loop
9223 Try_One_Prefix_Interpretation
(It
.Typ
);
9224 Get_Next_Interp
(I
, It
);
9229 if Etype
(New_Call_Node
) /= Any_Type
then
9231 -- No need to complete the tree transformations if we are only
9232 -- searching for conflicting class-wide subprograms
9234 if CW_Test_Only
then
9237 Complete_Object_Operation
9238 (Call_Node
=> New_Call_Node
,
9239 Node_To_Replace
=> Node_To_Replace
);
9243 elsif Present
(Candidate
) then
9245 -- The argument list is not type correct. Re-analyze with error
9246 -- reporting enabled, and use one of the possible candidates.
9247 -- In All_Errors_Mode, re-analyze all failed interpretations.
9249 if All_Errors_Mode
then
9250 Report_Error
:= True;
9251 if Try_Primitive_Operation
9252 (Call_Node
=> New_Call_Node
,
9253 Node_To_Replace
=> Node_To_Replace
)
9256 Try_Class_Wide_Operation
9257 (Call_Node
=> New_Call_Node
,
9258 Node_To_Replace
=> Node_To_Replace
)
9265 (N
=> New_Call_Node
,
9269 Skip_First
=> True);
9272 -- No need for further errors
9277 -- There was no candidate operation, so report it as an error
9278 -- in the caller: Analyze_Selected_Component.
9282 end Try_Object_Operation
;
9288 procedure wpo
(T
: Entity_Id
) is
9293 if not Is_Tagged_Type
(T
) then
9297 E
:= First_Elmt
(Primitive_Operations
(Base_Type
(T
)));
9298 while Present
(E
) loop
9300 Write_Int
(Int
(Op
));
9301 Write_Str
(" === ");
9302 Write_Name
(Chars
(Op
));
9304 Write_Name
(Chars
(Scope
(Op
)));