1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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 -----------------------
69 -- Local Subprograms --
70 -----------------------
72 procedure Analyze_Concatenation_Rest
(N
: Node_Id
);
73 -- Does the "rest" of the work of Analyze_Concatenation, after the left
74 -- operand has been analyzed. See Analyze_Concatenation for details.
76 procedure Analyze_Expression
(N
: Node_Id
);
77 -- For expressions that are not names, this is just a call to analyze. If
78 -- the expression is a name, it may be a call to a parameterless function,
79 -- and if so must be converted into an explicit call node and analyzed as
80 -- such. This deproceduring must be done during the first pass of overload
81 -- resolution, because otherwise a procedure call with overloaded actuals
82 -- may fail to resolve.
84 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
);
85 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call is an
86 -- operator name or an expanded name whose selector is an operator name,
87 -- and one possible interpretation is as a predefined operator.
89 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
);
90 -- If the prefix of a selected_component is overloaded, the proper
91 -- interpretation that yields a record type with the proper selector
92 -- name must be selected.
94 procedure Analyze_User_Defined_Binary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
95 -- Procedure to analyze a user defined binary operator, which is resolved
96 -- like a function, but instead of a list of actuals it is presented
97 -- with the left and right operands of an operator node.
99 procedure Analyze_User_Defined_Unary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
100 -- Procedure to analyze a user defined unary operator, which is resolved
101 -- like a function, but instead of a list of actuals, it is presented with
102 -- the operand of the operator node.
104 procedure Ambiguous_Operands
(N
: Node_Id
);
105 -- For equality, membership, and comparison operators with overloaded
106 -- arguments, list possible interpretations.
108 procedure Analyze_One_Call
112 Success
: out Boolean;
113 Skip_First
: Boolean := False);
114 -- Check one interpretation of an overloaded subprogram name for
115 -- compatibility with the types of the actuals in a call. If there is a
116 -- single interpretation which does not match, post error if Report is
119 -- Nam is the entity that provides the formals against which the actuals
120 -- are checked. Nam is either the name of a subprogram, or the internal
121 -- subprogram type constructed for an access_to_subprogram. If the actuals
122 -- are compatible with Nam, then Nam is added to the list of candidate
123 -- interpretations for N, and Success is set to True.
125 -- The flag Skip_First is used when analyzing a call that was rewritten
126 -- from object notation. In this case the first actual may have to receive
127 -- an explicit dereference, depending on the first formal of the operation
128 -- being called. The caller will have verified that the object is legal
129 -- for the call. If the remaining parameters match, the first parameter
130 -- will rewritten as a dereference if needed, prior to completing analysis.
132 procedure Check_Misspelled_Selector
135 -- Give possible misspelling message if Sel seems likely to be a mis-
136 -- spelling of one of the selectors of the Prefix. This is called by
137 -- Analyze_Selected_Component after producing an invalid selector error
140 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean;
141 -- Verify that type T is declared in scope S. Used to find interpretations
142 -- for operators given by expanded names. This is abstracted as a separate
143 -- function to handle extensions to System, where S is System, but T is
144 -- declared in the extension.
146 procedure Find_Arithmetic_Types
150 -- L and R are the operands of an arithmetic operator. Find consistent
151 -- pairs of interpretations for L and R that have a numeric type consistent
152 -- with the semantics of the operator.
154 procedure Find_Comparison_Types
158 -- L and R are operands of a comparison operator. Find consistent pairs of
159 -- interpretations for L and R.
161 procedure Find_Concatenation_Types
165 -- For the four varieties of concatenation
167 procedure Find_Equality_Types
171 -- Ditto for equality operators
173 procedure Find_Boolean_Types
177 -- Ditto for binary logical operations
179 procedure Find_Negation_Types
183 -- Find consistent interpretation for operand of negation operator
185 procedure Find_Non_Universal_Interpretations
190 -- For equality and comparison operators, the result is always boolean,
191 -- and the legality of the operation is determined from the visibility
192 -- of the operand types. If one of the operands has a universal interpre-
193 -- tation, the legality check uses some compatible non-universal
194 -- interpretation of the other operand. N can be an operator node, or
195 -- a function call whose name is an operator designator. Any_Access, which
196 -- is the initial type of the literal NULL, is a universal type for the
197 -- purpose of this routine.
199 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean;
200 -- Find candidate interpretations for the name Obj.Proc when it appears
201 -- in a subprogram renaming declaration.
203 procedure Find_Unary_Types
207 -- Unary arithmetic types: plus, minus, abs
209 procedure Check_Arithmetic_Pair
213 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
214 -- types for left and right operand. Determine whether they constitute
215 -- a valid pair for the given operator, and record the corresponding
216 -- interpretation of the operator node. The node N may be an operator
217 -- node (the usual case) or a function call whose prefix is an operator
218 -- designator. In both cases Op_Id is the operator name itself.
220 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
);
221 -- Give detailed information on overloaded call where none of the
222 -- interpretations match. N is the call node, Nam the designator for
223 -- the overloaded entity being called.
225 function Junk_Operand
(N
: Node_Id
) return Boolean;
226 -- Test for an operand that is an inappropriate entity (e.g. a package
227 -- name or a label). If so, issue an error message and return True. If
228 -- the operand is not an inappropriate entity kind, return False.
230 procedure Operator_Check
(N
: Node_Id
);
231 -- Verify that an operator has received some valid interpretation. If none
232 -- was found, determine whether a use clause would make the operation
233 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
234 -- every type compatible with the operator, even if the operator for the
235 -- type is not directly visible. The routine uses this type to emit a more
236 -- informative message.
238 function Process_Implicit_Dereference_Prefix
240 P
: Node_Id
) return Entity_Id
;
241 -- Called when P is the prefix of an implicit dereference, denoting an
242 -- object E. The function returns the designated type of the prefix, taking
243 -- into account that the designated type of an anonymous access type may be
244 -- a limited view, when the non-limited view is visible.
245 -- If in semantics only mode (-gnatc or generic), the function also records
246 -- that the prefix is a reference to E, if any. Normally, such a reference
247 -- is generated only when the implicit dereference is expanded into an
248 -- explicit one, but for consistency we must generate the reference when
249 -- expansion is disabled as well.
251 procedure Remove_Abstract_Operations
(N
: Node_Id
);
252 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
253 -- operation is not a candidate interpretation.
255 function Try_Container_Indexing
258 Exprs
: List_Id
) return Boolean;
259 -- AI05-0139: Generalized indexing to support iterators over containers
261 function Try_Indexed_Call
265 Skip_First
: Boolean) return Boolean;
266 -- If a function has defaults for all its actuals, a call to it may in fact
267 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
268 -- interpretation as an indexing, prior to analysis as a call. If both are
269 -- possible, the node is overloaded with both interpretations (same symbol
270 -- but two different types). If the call is written in prefix form, the
271 -- prefix becomes the first parameter in the call, and only the remaining
272 -- actuals must be checked for the presence of defaults.
274 function Try_Indirect_Call
277 Typ
: Entity_Id
) return Boolean;
278 -- Similarly, a function F that needs no actuals can return an access to a
279 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
280 -- the call may be overloaded with both interpretations.
282 function Try_Object_Operation
284 CW_Test_Only
: Boolean := False) return Boolean;
285 -- Ada 2005 (AI-252): Support the object.operation notation. If node N
286 -- is a call in this notation, it is transformed into a normal subprogram
287 -- call where the prefix is a parameter, and True is returned. If node
288 -- N is not of this form, it is unchanged, and False is returned. if
289 -- CW_Test_Only is true then N is an N_Selected_Component node which
290 -- is part of a call to an entry or procedure of a tagged concurrent
291 -- type and this routine is invoked to search for class-wide subprograms
292 -- conflicting with the target entity.
294 procedure wpo
(T
: Entity_Id
);
295 pragma Warnings
(Off
, wpo
);
296 -- Used for debugging: obtain list of primitive operations even if
297 -- type is not frozen and dispatch table is not built yet.
299 ------------------------
300 -- Ambiguous_Operands --
301 ------------------------
303 procedure Ambiguous_Operands
(N
: Node_Id
) is
304 procedure List_Operand_Interps
(Opnd
: Node_Id
);
306 --------------------------
307 -- List_Operand_Interps --
308 --------------------------
310 procedure List_Operand_Interps
(Opnd
: Node_Id
) is
315 if Is_Overloaded
(Opnd
) then
316 if Nkind
(Opnd
) in N_Op
then
318 elsif Nkind
(Opnd
) = N_Function_Call
then
320 elsif Ada_Version
>= Ada_2012
then
326 Get_First_Interp
(Opnd
, I
, It
);
327 while Present
(It
.Nam
) loop
328 if Has_Implicit_Dereference
(It
.Typ
) then
330 ("can be interpreted as implicit dereference", Opnd
);
334 Get_Next_Interp
(I
, It
);
345 if Opnd
= Left_Opnd
(N
) then
346 Error_Msg_N
("\left operand has the following interpretations", N
);
349 ("\right operand has the following interpretations", N
);
353 List_Interps
(Nam
, Err
);
354 end List_Operand_Interps
;
356 -- Start of processing for Ambiguous_Operands
359 if Nkind
(N
) in N_Membership_Test
then
360 Error_Msg_N
("ambiguous operands for membership", N
);
362 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
) then
363 Error_Msg_N
("ambiguous operands for equality", N
);
366 Error_Msg_N
("ambiguous operands for comparison", N
);
369 if All_Errors_Mode
then
370 List_Operand_Interps
(Left_Opnd
(N
));
371 List_Operand_Interps
(Right_Opnd
(N
));
373 Error_Msg_N
("\use -gnatf switch for details", N
);
375 end Ambiguous_Operands
;
377 -----------------------
378 -- Analyze_Aggregate --
379 -----------------------
381 -- Most of the analysis of Aggregates requires that the type be known,
382 -- and is therefore put off until resolution.
384 procedure Analyze_Aggregate
(N
: Node_Id
) is
386 if No
(Etype
(N
)) then
387 Set_Etype
(N
, Any_Composite
);
389 end Analyze_Aggregate
;
391 -----------------------
392 -- Analyze_Allocator --
393 -----------------------
395 procedure Analyze_Allocator
(N
: Node_Id
) is
396 Loc
: constant Source_Ptr
:= Sloc
(N
);
397 Sav_Errs
: constant Nat
:= Serious_Errors_Detected
;
398 E
: Node_Id
:= Expression
(N
);
399 Acc_Type
: Entity_Id
;
406 Check_SPARK_05_Restriction
("allocator is not allowed", N
);
408 -- Deal with allocator restrictions
410 -- In accordance with H.4(7), the No_Allocators restriction only applies
411 -- to user-written allocators. The same consideration applies to the
412 -- No_Standard_Allocators_Before_Elaboration restriction.
414 if Comes_From_Source
(N
) then
415 Check_Restriction
(No_Allocators
, N
);
417 -- Processing for No_Standard_Allocators_After_Elaboration, loop to
418 -- look at enclosing context, checking task/main subprogram case.
422 while Present
(P
) loop
424 -- For the task case we need a handled sequence of statements,
425 -- where the occurrence of the allocator is within the statements
426 -- and the parent is a task body
428 if Nkind
(P
) = N_Handled_Sequence_Of_Statements
429 and then Is_List_Member
(C
)
430 and then List_Containing
(C
) = Statements
(P
)
432 Onode
:= Original_Node
(Parent
(P
));
434 -- Check for allocator within task body, this is a definite
435 -- violation of No_Allocators_After_Elaboration we can detect
438 if Nkind
(Onode
) = N_Task_Body
then
440 (No_Standard_Allocators_After_Elaboration
, N
);
445 -- The other case is appearance in a subprogram body. This is
446 -- a violation if this is a library level subprogram with no
447 -- parameters. Note that this is now a static error even if the
448 -- subprogram is not the main program (this is a change, in an
449 -- earlier version only the main program was affected, and the
450 -- check had to be done in the binder.
452 if Nkind
(P
) = N_Subprogram_Body
453 and then Nkind
(Parent
(P
)) = N_Compilation_Unit
454 and then No
(Parameter_Specifications
(Specification
(P
)))
457 (No_Standard_Allocators_After_Elaboration
, N
);
465 -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
466 -- any. The expected type for the name is any type. A non-overloading
467 -- rule then requires it to be of a type descended from
468 -- System.Storage_Pools.Subpools.Subpool_Handle.
470 -- This isn't exactly what the AI says, but it seems to be the right
471 -- rule. The AI should be fixed.???
474 Subpool
: constant Node_Id
:= Subpool_Handle_Name
(N
);
477 if Present
(Subpool
) then
480 if Is_Overloaded
(Subpool
) then
481 Error_Msg_N
("ambiguous subpool handle", Subpool
);
484 -- Check that Etype (Subpool) is descended from Subpool_Handle
490 -- Analyze the qualified expression or subtype indication
492 if Nkind
(E
) = N_Qualified_Expression
then
493 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
494 Set_Etype
(Acc_Type
, Acc_Type
);
495 Find_Type
(Subtype_Mark
(E
));
497 -- Analyze the qualified expression, and apply the name resolution
498 -- rule given in 4.7(3).
501 Type_Id
:= Etype
(E
);
502 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
504 -- Allocators generated by the build-in-place expansion mechanism
505 -- are explicitly marked as coming from source but do not need to be
506 -- checked for limited initialization. To exclude this case, ensure
507 -- that the parent of the allocator is a source node.
509 if Is_Limited_Type
(Type_Id
)
510 and then Comes_From_Source
(N
)
511 and then Comes_From_Source
(Parent
(N
))
512 and then not In_Instance_Body
514 if not OK_For_Limited_Init
(Type_Id
, Expression
(E
)) then
515 Error_Msg_N
("initialization not allowed for limited types", N
);
516 Explain_Limited_Type
(Type_Id
, N
);
520 -- A qualified expression requires an exact match of the type,
521 -- class-wide matching is not allowed.
523 -- if Is_Class_Wide_Type (Type_Id)
524 -- and then Base_Type
525 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
527 -- Wrong_Type (Expression (E), Type_Id);
530 -- We don't analyze the qualified expression itself because it's
531 -- part of the allocator. It is fully analyzed and resolved when
532 -- the allocator is resolved with the context type.
534 Set_Etype
(E
, Type_Id
);
536 -- Case where allocator has a subtype indication
541 Base_Typ
: Entity_Id
;
544 -- If the allocator includes a N_Subtype_Indication then a
545 -- constraint is present, otherwise the node is a subtype mark.
546 -- Introduce an explicit subtype declaration into the tree
547 -- defining some anonymous subtype and rewrite the allocator to
548 -- use this subtype rather than the subtype indication.
550 -- It is important to introduce the explicit subtype declaration
551 -- so that the bounds of the subtype indication are attached to
552 -- the tree in case the allocator is inside a generic unit.
554 if Nkind
(E
) = N_Subtype_Indication
then
556 -- A constraint is only allowed for a composite type in Ada
557 -- 95. In Ada 83, a constraint is also allowed for an
558 -- access-to-composite type, but the constraint is ignored.
560 Find_Type
(Subtype_Mark
(E
));
561 Base_Typ
:= Entity
(Subtype_Mark
(E
));
563 if Is_Elementary_Type
(Base_Typ
) then
564 if not (Ada_Version
= Ada_83
565 and then Is_Access_Type
(Base_Typ
))
567 Error_Msg_N
("constraint not allowed here", E
);
569 if Nkind
(Constraint
(E
)) =
570 N_Index_Or_Discriminant_Constraint
572 Error_Msg_N
-- CODEFIX
573 ("\if qualified expression was meant, " &
574 "use apostrophe", Constraint
(E
));
578 -- Get rid of the bogus constraint:
580 Rewrite
(E
, New_Copy_Tree
(Subtype_Mark
(E
)));
581 Analyze_Allocator
(N
);
585 if Expander_Active
then
586 Def_Id
:= Make_Temporary
(Loc
, 'S');
589 Make_Subtype_Declaration
(Loc
,
590 Defining_Identifier
=> Def_Id
,
591 Subtype_Indication
=> Relocate_Node
(E
)));
593 if Sav_Errs
/= Serious_Errors_Detected
594 and then Nkind
(Constraint
(E
)) =
595 N_Index_Or_Discriminant_Constraint
597 Error_Msg_N
-- CODEFIX
598 ("if qualified expression was meant, "
599 & "use apostrophe!", Constraint
(E
));
602 E
:= New_Occurrence_Of
(Def_Id
, Loc
);
603 Rewrite
(Expression
(N
), E
);
607 Type_Id
:= Process_Subtype
(E
, N
);
608 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
609 Set_Etype
(Acc_Type
, Acc_Type
);
610 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
611 Check_Fully_Declared
(Type_Id
, N
);
613 -- Ada 2005 (AI-231): If the designated type is itself an access
614 -- type that excludes null, its default initialization will
615 -- be a null object, and we can insert an unconditional raise
616 -- before the allocator.
618 -- Ada 2012 (AI-104): A not null indication here is altogether
621 if Can_Never_Be_Null
(Type_Id
) then
623 Not_Null_Check
: constant Node_Id
:=
624 Make_Raise_Constraint_Error
(Sloc
(E
),
625 Reason
=> CE_Null_Not_Allowed
);
628 if Expander_Active
then
629 Insert_Action
(N
, Not_Null_Check
);
630 Analyze
(Not_Null_Check
);
632 elsif Warn_On_Ada_2012_Compatibility
then
634 ("null value not allowed here in Ada 2012?y?", E
);
639 -- Check for missing initialization. Skip this check if we already
640 -- had errors on analyzing the allocator, since in that case these
641 -- are probably cascaded errors.
643 if Is_Indefinite_Subtype
(Type_Id
)
644 and then Serious_Errors_Detected
= Sav_Errs
646 -- The build-in-place machinery may produce an allocator when
647 -- the designated type is indefinite but the underlying type is
648 -- not. In this case the unknown discriminants are meaningless
649 -- and should not trigger error messages. Check the parent node
650 -- because the allocator is marked as coming from source.
652 if Present
(Underlying_Type
(Type_Id
))
653 and then not Is_Indefinite_Subtype
(Underlying_Type
(Type_Id
))
654 and then not Comes_From_Source
(Parent
(N
))
658 elsif Is_Class_Wide_Type
(Type_Id
) then
660 ("initialization required in class-wide allocation", N
);
663 if Ada_Version
< Ada_2005
664 and then Is_Limited_Type
(Type_Id
)
666 Error_Msg_N
("unconstrained allocation not allowed", N
);
668 if Is_Array_Type
(Type_Id
) then
670 ("\constraint with array bounds required", N
);
672 elsif Has_Unknown_Discriminants
(Type_Id
) then
675 else pragma Assert
(Has_Discriminants
(Type_Id
));
677 ("\constraint with discriminant values required", N
);
680 -- Limited Ada 2005 and general non-limited case
684 ("uninitialized unconstrained allocation not allowed",
687 if Is_Array_Type
(Type_Id
) then
689 ("\qualified expression or constraint with " &
690 "array bounds required", N
);
692 elsif Has_Unknown_Discriminants
(Type_Id
) then
693 Error_Msg_N
("\qualified expression required", N
);
695 else pragma Assert
(Has_Discriminants
(Type_Id
));
697 ("\qualified expression or constraint with " &
698 "discriminant values required", N
);
706 if Is_Abstract_Type
(Type_Id
) then
707 Error_Msg_N
("cannot allocate abstract object", E
);
710 if Has_Task
(Designated_Type
(Acc_Type
)) then
711 Check_Restriction
(No_Tasking
, N
);
712 Check_Restriction
(Max_Tasks
, N
);
713 Check_Restriction
(No_Task_Allocators
, N
);
716 -- Check restriction against dynamically allocated protected objects
718 if Has_Protected
(Designated_Type
(Acc_Type
)) then
719 Check_Restriction
(No_Protected_Type_Allocators
, N
);
722 -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
723 -- type is nested, and the designated type needs finalization. The rule
724 -- is conservative in that class-wide types need finalization.
726 if Needs_Finalization
(Designated_Type
(Acc_Type
))
727 and then not Is_Library_Level_Entity
(Acc_Type
)
729 Check_Restriction
(No_Nested_Finalization
, N
);
732 -- Check that an allocator of a nested access type doesn't create a
733 -- protected object when restriction No_Local_Protected_Objects applies.
735 if Has_Protected
(Designated_Type
(Acc_Type
))
736 and then not Is_Library_Level_Entity
(Acc_Type
)
738 Check_Restriction
(No_Local_Protected_Objects
, N
);
741 -- If the No_Streams restriction is set, check that the type of the
742 -- object is not, and does not contain, any subtype derived from
743 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
744 -- Has_Stream just for efficiency reasons. There is no point in
745 -- spending time on a Has_Stream check if the restriction is not set.
747 if Restriction_Check_Required
(No_Streams
) then
748 if Has_Stream
(Designated_Type
(Acc_Type
)) then
749 Check_Restriction
(No_Streams
, N
);
753 Set_Etype
(N
, Acc_Type
);
755 if not Is_Library_Level_Entity
(Acc_Type
) then
756 Check_Restriction
(No_Local_Allocators
, N
);
759 if Serious_Errors_Detected
> Sav_Errs
then
760 Set_Error_Posted
(N
);
761 Set_Etype
(N
, Any_Type
);
763 end Analyze_Allocator
;
765 ---------------------------
766 -- Analyze_Arithmetic_Op --
767 ---------------------------
769 procedure Analyze_Arithmetic_Op
(N
: Node_Id
) is
770 L
: constant Node_Id
:= Left_Opnd
(N
);
771 R
: constant Node_Id
:= Right_Opnd
(N
);
775 Candidate_Type
:= Empty
;
776 Analyze_Expression
(L
);
777 Analyze_Expression
(R
);
779 -- If the entity is already set, the node is the instantiation of a
780 -- generic node with a non-local reference, or was manufactured by a
781 -- call to Make_Op_xxx. In either case the entity is known to be valid,
782 -- and we do not need to collect interpretations, instead we just get
783 -- the single possible interpretation.
787 if Present
(Op_Id
) then
788 if Ekind
(Op_Id
) = E_Operator
then
790 if Nkind_In
(N
, N_Op_Divide
, N_Op_Mod
, N_Op_Multiply
, N_Op_Rem
)
791 and then Treat_Fixed_As_Integer
(N
)
795 Set_Etype
(N
, Any_Type
);
796 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
800 Set_Etype
(N
, Any_Type
);
801 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
804 -- Entity is not already set, so we do need to collect interpretations
807 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
808 Set_Etype
(N
, Any_Type
);
810 while Present
(Op_Id
) loop
811 if Ekind
(Op_Id
) = E_Operator
812 and then Present
(Next_Entity
(First_Entity
(Op_Id
)))
814 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
816 -- The following may seem superfluous, because an operator cannot
817 -- be generic, but this ignores the cleverness of the author of
820 elsif Is_Overloadable
(Op_Id
) then
821 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
824 Op_Id
:= Homonym
(Op_Id
);
829 end Analyze_Arithmetic_Op
;
835 -- Function, procedure, and entry calls are checked here. The Name in
836 -- the call may be overloaded. The actuals have been analyzed and may
837 -- themselves be overloaded. On exit from this procedure, the node N
838 -- may have zero, one or more interpretations. In the first case an
839 -- error message is produced. In the last case, the node is flagged
840 -- as overloaded and the interpretations are collected in All_Interp.
842 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
843 -- the type-checking is similar to that of other calls.
845 procedure Analyze_Call
(N
: Node_Id
) is
846 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
851 Success
: Boolean := False;
853 Deref
: Boolean := False;
854 -- Flag indicates whether an interpretation of the prefix is a
855 -- parameterless call that returns an access_to_subprogram.
857 procedure Check_Mixed_Parameter_And_Named_Associations
;
858 -- Check that parameter and named associations are not mixed. This is
859 -- a restriction in SPARK mode.
861 function Name_Denotes_Function
return Boolean;
862 -- If the type of the name is an access to subprogram, this may be the
863 -- type of a name, or the return type of the function being called. If
864 -- the name is not an entity then it can denote a protected function.
865 -- Until we distinguish Etype from Return_Type, we must use this routine
866 -- to resolve the meaning of the name in the call.
868 procedure No_Interpretation
;
869 -- Output error message when no valid interpretation exists
871 --------------------------------------------------
872 -- Check_Mixed_Parameter_And_Named_Associations --
873 --------------------------------------------------
875 procedure Check_Mixed_Parameter_And_Named_Associations
is
877 Named_Seen
: Boolean;
882 Actual
:= First
(Actuals
);
883 while Present
(Actual
) loop
884 case Nkind
(Actual
) is
885 when N_Parameter_Association
=>
887 Check_SPARK_05_Restriction
888 ("named association cannot follow positional one",
898 end Check_Mixed_Parameter_And_Named_Associations
;
900 ---------------------------
901 -- Name_Denotes_Function --
902 ---------------------------
904 function Name_Denotes_Function
return Boolean is
906 if Is_Entity_Name
(Nam
) then
907 return Ekind
(Entity
(Nam
)) = E_Function
;
909 elsif Nkind
(Nam
) = N_Selected_Component
then
910 return Ekind
(Entity
(Selector_Name
(Nam
))) = E_Function
;
915 end Name_Denotes_Function
;
917 -----------------------
918 -- No_Interpretation --
919 -----------------------
921 procedure No_Interpretation
is
922 L
: constant Boolean := Is_List_Member
(N
);
923 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
926 -- If the node is in a list whose parent is not an expression then it
927 -- must be an attempted procedure call.
929 if L
and then K
not in N_Subexpr
then
930 if Ekind
(Entity
(Nam
)) = E_Generic_Procedure
then
932 ("must instantiate generic procedure& before call",
936 ("procedure or entry name expected", Nam
);
939 -- Check for tasking cases where only an entry call will do
942 and then Nkind_In
(K
, N_Entry_Call_Alternative
,
943 N_Triggering_Alternative
)
945 Error_Msg_N
("entry name expected", Nam
);
947 -- Otherwise give general error message
950 Error_Msg_N
("invalid prefix in call", Nam
);
952 end No_Interpretation
;
954 -- Start of processing for Analyze_Call
957 if Restriction_Check_Required
(SPARK_05
) then
958 Check_Mixed_Parameter_And_Named_Associations
;
961 -- Initialize the type of the result of the call to the error type,
962 -- which will be reset if the type is successfully resolved.
964 Set_Etype
(N
, Any_Type
);
968 if not Is_Overloaded
(Nam
) then
970 -- Only one interpretation to check
972 if Ekind
(Etype
(Nam
)) = E_Subprogram_Type
then
973 Nam_Ent
:= Etype
(Nam
);
975 -- If the prefix is an access_to_subprogram, this may be an indirect
976 -- call. This is the case if the name in the call is not an entity
977 -- name, or if it is a function name in the context of a procedure
978 -- call. In this latter case, we have a call to a parameterless
979 -- function that returns a pointer_to_procedure which is the entity
980 -- being called. Finally, F (X) may be a call to a parameterless
981 -- function that returns a pointer to a function with parameters.
982 -- Note that if F returns an access-to-subprogram whose designated
983 -- type is an array, F (X) cannot be interpreted as an indirect call
984 -- through the result of the call to F.
986 elsif Is_Access_Type
(Etype
(Nam
))
987 and then Ekind
(Designated_Type
(Etype
(Nam
))) = E_Subprogram_Type
989 (not Name_Denotes_Function
990 or else Nkind
(N
) = N_Procedure_Call_Statement
992 (Nkind
(Parent
(N
)) /= N_Explicit_Dereference
993 and then Is_Entity_Name
(Nam
)
994 and then No
(First_Formal
(Entity
(Nam
)))
996 Is_Array_Type
(Etype
(Designated_Type
(Etype
(Nam
))))
997 and then Present
(Actuals
)))
999 Nam_Ent
:= Designated_Type
(Etype
(Nam
));
1000 Insert_Explicit_Dereference
(Nam
);
1002 -- Selected component case. Simple entry or protected operation,
1003 -- where the entry name is given by the selector name.
1005 elsif Nkind
(Nam
) = N_Selected_Component
then
1006 Nam_Ent
:= Entity
(Selector_Name
(Nam
));
1008 if not Ekind_In
(Nam_Ent
, E_Entry
,
1013 Error_Msg_N
("name in call is not a callable entity", Nam
);
1014 Set_Etype
(N
, Any_Type
);
1018 -- If the name is an Indexed component, it can be a call to a member
1019 -- of an entry family. The prefix must be a selected component whose
1020 -- selector is the entry. Analyze_Procedure_Call normalizes several
1021 -- kinds of call into this form.
1023 elsif Nkind
(Nam
) = N_Indexed_Component
then
1024 if Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
1025 Nam_Ent
:= Entity
(Selector_Name
(Prefix
(Nam
)));
1027 Error_Msg_N
("name in call is not a callable entity", Nam
);
1028 Set_Etype
(N
, Any_Type
);
1032 elsif not Is_Entity_Name
(Nam
) then
1033 Error_Msg_N
("name in call is not a callable entity", Nam
);
1034 Set_Etype
(N
, Any_Type
);
1038 Nam_Ent
:= Entity
(Nam
);
1040 -- If not overloadable, this may be a generalized indexing
1041 -- operation with named associations. Rewrite again as an
1042 -- indexed component and analyze as container indexing.
1044 if not Is_Overloadable
(Nam_Ent
) then
1046 (Find_Value_Of_Aspect
1047 (Etype
(Nam_Ent
), Aspect_Constant_Indexing
))
1050 Make_Indexed_Component
(Sloc
(N
),
1052 Expressions
=> Parameter_Associations
(N
)));
1054 if Try_Container_Indexing
(N
, Nam
, Expressions
(N
)) then
1068 -- Operations generated for RACW stub types are called only through
1069 -- dispatching, and can never be the static interpretation of a call.
1071 if Is_RACW_Stub_Type_Operation
(Nam_Ent
) then
1076 Analyze_One_Call
(N
, Nam_Ent
, True, Success
);
1078 -- If this is an indirect call, the return type of the access_to
1079 -- subprogram may be an incomplete type. At the point of the call,
1080 -- use the full type if available, and at the same time update the
1081 -- return type of the access_to_subprogram.
1084 and then Nkind
(Nam
) = N_Explicit_Dereference
1085 and then Ekind
(Etype
(N
)) = E_Incomplete_Type
1086 and then Present
(Full_View
(Etype
(N
)))
1088 Set_Etype
(N
, Full_View
(Etype
(N
)));
1089 Set_Etype
(Nam_Ent
, Etype
(N
));
1095 -- An overloaded selected component must denote overloaded operations
1096 -- of a concurrent type. The interpretations are attached to the
1097 -- simple name of those operations.
1099 if Nkind
(Nam
) = N_Selected_Component
then
1100 Nam
:= Selector_Name
(Nam
);
1103 Get_First_Interp
(Nam
, X
, It
);
1105 while Present
(It
.Nam
) loop
1109 -- Name may be call that returns an access to subprogram, or more
1110 -- generally an overloaded expression one of whose interpretations
1111 -- yields an access to subprogram. If the name is an entity, we do
1112 -- not dereference, because the node is a call that returns the
1113 -- access type: note difference between f(x), where the call may
1114 -- return an access subprogram type, and f(x)(y), where the type
1115 -- returned by the call to f is implicitly dereferenced to analyze
1118 if Is_Access_Type
(Nam_Ent
) then
1119 Nam_Ent
:= Designated_Type
(Nam_Ent
);
1121 elsif Is_Access_Type
(Etype
(Nam_Ent
))
1123 (not Is_Entity_Name
(Nam
)
1124 or else Nkind
(N
) = N_Procedure_Call_Statement
)
1125 and then Ekind
(Designated_Type
(Etype
(Nam_Ent
)))
1128 Nam_Ent
:= Designated_Type
(Etype
(Nam_Ent
));
1130 if Is_Entity_Name
(Nam
) then
1135 -- If the call has been rewritten from a prefixed call, the first
1136 -- parameter has been analyzed, but may need a subsequent
1137 -- dereference, so skip its analysis now.
1139 if N
/= Original_Node
(N
)
1140 and then Nkind
(Original_Node
(N
)) = Nkind
(N
)
1141 and then Nkind
(Name
(N
)) /= Nkind
(Name
(Original_Node
(N
)))
1142 and then Present
(Parameter_Associations
(N
))
1143 and then Present
(Etype
(First
(Parameter_Associations
(N
))))
1146 (N
, Nam_Ent
, False, Success
, Skip_First
=> True);
1148 Analyze_One_Call
(N
, Nam_Ent
, False, Success
);
1151 -- If the interpretation succeeds, mark the proper type of the
1152 -- prefix (any valid candidate will do). If not, remove the
1153 -- candidate interpretation. This only needs to be done for
1154 -- overloaded protected operations, for other entities disambi-
1155 -- guation is done directly in Resolve.
1159 and then Nkind
(Parent
(N
)) /= N_Explicit_Dereference
1161 Set_Entity
(Nam
, It
.Nam
);
1162 Insert_Explicit_Dereference
(Nam
);
1163 Set_Etype
(Nam
, Nam_Ent
);
1166 Set_Etype
(Nam
, It
.Typ
);
1169 elsif Nkind_In
(Name
(N
), N_Selected_Component
,
1175 Get_Next_Interp
(X
, It
);
1178 -- If the name is the result of a function call, it can only be a
1179 -- call to a function returning an access to subprogram. Insert
1180 -- explicit dereference.
1182 if Nkind
(Nam
) = N_Function_Call
then
1183 Insert_Explicit_Dereference
(Nam
);
1186 if Etype
(N
) = Any_Type
then
1188 -- None of the interpretations is compatible with the actuals
1190 Diagnose_Call
(N
, Nam
);
1192 -- Special checks for uninstantiated put routines
1194 if Nkind
(N
) = N_Procedure_Call_Statement
1195 and then Is_Entity_Name
(Nam
)
1196 and then Chars
(Nam
) = Name_Put
1197 and then List_Length
(Actuals
) = 1
1200 Arg
: constant Node_Id
:= First
(Actuals
);
1204 if Nkind
(Arg
) = N_Parameter_Association
then
1205 Typ
:= Etype
(Explicit_Actual_Parameter
(Arg
));
1210 if Is_Signed_Integer_Type
(Typ
) then
1212 ("possible missing instantiation of "
1213 & "'Text_'I'O.'Integer_'I'O!", Nam
);
1215 elsif Is_Modular_Integer_Type
(Typ
) then
1217 ("possible missing instantiation of "
1218 & "'Text_'I'O.'Modular_'I'O!", Nam
);
1220 elsif Is_Floating_Point_Type
(Typ
) then
1222 ("possible missing instantiation of "
1223 & "'Text_'I'O.'Float_'I'O!", Nam
);
1225 elsif Is_Ordinary_Fixed_Point_Type
(Typ
) then
1227 ("possible missing instantiation of "
1228 & "'Text_'I'O.'Fixed_'I'O!", Nam
);
1230 elsif Is_Decimal_Fixed_Point_Type
(Typ
) then
1232 ("possible missing instantiation of "
1233 & "'Text_'I'O.'Decimal_'I'O!", Nam
);
1235 elsif Is_Enumeration_Type
(Typ
) then
1237 ("possible missing instantiation of "
1238 & "'Text_'I'O.'Enumeration_'I'O!", Nam
);
1243 elsif not Is_Overloaded
(N
)
1244 and then Is_Entity_Name
(Nam
)
1246 -- Resolution yields a single interpretation. Verify that the
1247 -- reference has capitalization consistent with the declaration.
1249 Set_Entity_With_Checks
(Nam
, Entity
(Nam
));
1250 Generate_Reference
(Entity
(Nam
), Nam
);
1252 Set_Etype
(Nam
, Etype
(Entity
(Nam
)));
1254 Remove_Abstract_Operations
(N
);
1261 -----------------------------
1262 -- Analyze_Case_Expression --
1263 -----------------------------
1265 procedure Analyze_Case_Expression
(N
: Node_Id
) is
1266 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
1267 -- Error routine invoked by the generic instantiation below when
1268 -- the case expression has a non static choice.
1270 package Case_Choices_Analysis
is new
1271 Generic_Analyze_Choices
1272 (Process_Associated_Node
=> No_OP
);
1273 use Case_Choices_Analysis
;
1275 package Case_Choices_Checking
is new
1276 Generic_Check_Choices
1277 (Process_Empty_Choice
=> No_OP
,
1278 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
1279 Process_Associated_Node
=> No_OP
);
1280 use Case_Choices_Checking
;
1282 -----------------------------
1283 -- Non_Static_Choice_Error --
1284 -----------------------------
1286 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
1288 Flag_Non_Static_Expr
1289 ("choice given in case expression is not static!", Choice
);
1290 end Non_Static_Choice_Error
;
1294 Expr
: constant Node_Id
:= Expression
(N
);
1296 Exp_Type
: Entity_Id
;
1297 Exp_Btype
: Entity_Id
;
1299 FirstX
: Node_Id
:= Empty
;
1300 -- First expression in the case for which there is some type information
1301 -- available, i.e. it is not Any_Type, which can happen because of some
1302 -- error, or from the use of e.g. raise Constraint_Error.
1304 Others_Present
: Boolean;
1305 -- Indicates if Others was present
1307 Wrong_Alt
: Node_Id
;
1308 -- For error reporting
1310 -- Start of processing for Analyze_Case_Expression
1313 if Comes_From_Source
(N
) then
1314 Check_Compiler_Unit
("case expression", N
);
1317 Analyze_And_Resolve
(Expr
, Any_Discrete
);
1318 Check_Unset_Reference
(Expr
);
1319 Exp_Type
:= Etype
(Expr
);
1320 Exp_Btype
:= Base_Type
(Exp_Type
);
1322 Alt
:= First
(Alternatives
(N
));
1323 while Present
(Alt
) loop
1324 Analyze
(Expression
(Alt
));
1326 if No
(FirstX
) and then Etype
(Expression
(Alt
)) /= Any_Type
then
1327 FirstX
:= Expression
(Alt
);
1333 -- Get our initial type from the first expression for which we got some
1334 -- useful type information from the expression.
1336 if not Is_Overloaded
(FirstX
) then
1337 Set_Etype
(N
, Etype
(FirstX
));
1345 Set_Etype
(N
, Any_Type
);
1347 Get_First_Interp
(FirstX
, I
, It
);
1348 while Present
(It
.Nam
) loop
1350 -- For each interpretation of the first expression, we only
1351 -- add the interpretation if every other expression in the
1352 -- case expression alternatives has a compatible type.
1354 Alt
:= Next
(First
(Alternatives
(N
)));
1355 while Present
(Alt
) loop
1356 exit when not Has_Compatible_Type
(Expression
(Alt
), It
.Typ
);
1361 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
1367 Get_Next_Interp
(I
, It
);
1372 Exp_Btype
:= Base_Type
(Exp_Type
);
1374 -- The expression must be of a discrete type which must be determinable
1375 -- independently of the context in which the expression occurs, but
1376 -- using the fact that the expression must be of a discrete type.
1377 -- Moreover, the type this expression must not be a character literal
1378 -- (which is always ambiguous).
1380 -- If error already reported by Resolve, nothing more to do
1382 if Exp_Btype
= Any_Discrete
or else Exp_Btype
= Any_Type
then
1385 -- Special casee message for character literal
1387 elsif Exp_Btype
= Any_Character
then
1389 ("character literal as case expression is ambiguous", Expr
);
1393 if Etype
(N
) = Any_Type
and then Present
(Wrong_Alt
) then
1395 ("type incompatible with that of previous alternatives",
1396 Expression
(Wrong_Alt
));
1400 -- If the case expression is a formal object of mode in out, then
1401 -- treat it as having a nonstatic subtype by forcing use of the base
1402 -- type (which has to get passed to Check_Case_Choices below). Also
1403 -- use base type when the case expression is parenthesized.
1405 if Paren_Count
(Expr
) > 0
1406 or else (Is_Entity_Name
(Expr
)
1407 and then Ekind
(Entity
(Expr
)) = E_Generic_In_Out_Parameter
)
1409 Exp_Type
:= Exp_Btype
;
1412 -- The case expression alternatives cover the range of a static subtype
1413 -- subject to aspect Static_Predicate. Do not check the choices when the
1414 -- case expression has not been fully analyzed yet because this may lead
1417 if Is_OK_Static_Subtype
(Exp_Type
)
1418 and then Has_Static_Predicate_Aspect
(Exp_Type
)
1419 and then In_Spec_Expression
1423 -- Call Analyze_Choices and Check_Choices to do the rest of the work
1426 Analyze_Choices
(Alternatives
(N
), Exp_Type
);
1427 Check_Choices
(N
, Alternatives
(N
), Exp_Type
, Others_Present
);
1430 if Exp_Type
= Universal_Integer
and then not Others_Present
then
1432 ("case on universal integer requires OTHERS choice", Expr
);
1434 end Analyze_Case_Expression
;
1436 ---------------------------
1437 -- Analyze_Comparison_Op --
1438 ---------------------------
1440 procedure Analyze_Comparison_Op
(N
: Node_Id
) is
1441 L
: constant Node_Id
:= Left_Opnd
(N
);
1442 R
: constant Node_Id
:= Right_Opnd
(N
);
1443 Op_Id
: Entity_Id
:= Entity
(N
);
1446 Set_Etype
(N
, Any_Type
);
1447 Candidate_Type
:= Empty
;
1449 Analyze_Expression
(L
);
1450 Analyze_Expression
(R
);
1452 if Present
(Op_Id
) then
1453 if Ekind
(Op_Id
) = E_Operator
then
1454 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1456 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1459 if Is_Overloaded
(L
) then
1460 Set_Etype
(L
, Intersect_Types
(L
, R
));
1464 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1465 while Present
(Op_Id
) loop
1466 if Ekind
(Op_Id
) = E_Operator
then
1467 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1469 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1472 Op_Id
:= Homonym
(Op_Id
);
1477 end Analyze_Comparison_Op
;
1479 ---------------------------
1480 -- Analyze_Concatenation --
1481 ---------------------------
1483 procedure Analyze_Concatenation
(N
: Node_Id
) is
1485 -- We wish to avoid deep recursion, because concatenations are often
1486 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1487 -- operands nonrecursively until we find something that is not a
1488 -- concatenation (A in this case), or has already been analyzed. We
1489 -- analyze that, and then walk back up the tree following Parent
1490 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1491 -- work at each level. The Parent pointers allow us to avoid recursion,
1492 -- and thus avoid running out of memory.
1498 Candidate_Type
:= Empty
;
1500 -- The following code is equivalent to:
1502 -- Set_Etype (N, Any_Type);
1503 -- Analyze_Expression (Left_Opnd (N));
1504 -- Analyze_Concatenation_Rest (N);
1506 -- where the Analyze_Expression call recurses back here if the left
1507 -- operand is a concatenation.
1509 -- Walk down left operands
1512 Set_Etype
(NN
, Any_Type
);
1513 L
:= Left_Opnd
(NN
);
1514 exit when Nkind
(L
) /= N_Op_Concat
or else Analyzed
(L
);
1518 -- Now (given the above example) NN is A&B and L is A
1520 -- First analyze L ...
1522 Analyze_Expression
(L
);
1524 -- ... then walk NN back up until we reach N (where we started), calling
1525 -- Analyze_Concatenation_Rest along the way.
1528 Analyze_Concatenation_Rest
(NN
);
1532 end Analyze_Concatenation
;
1534 --------------------------------
1535 -- Analyze_Concatenation_Rest --
1536 --------------------------------
1538 -- If the only one-dimensional array type in scope is String,
1539 -- this is the resulting type of the operation. Otherwise there
1540 -- will be a concatenation operation defined for each user-defined
1541 -- one-dimensional array.
1543 procedure Analyze_Concatenation_Rest
(N
: Node_Id
) is
1544 L
: constant Node_Id
:= Left_Opnd
(N
);
1545 R
: constant Node_Id
:= Right_Opnd
(N
);
1546 Op_Id
: Entity_Id
:= Entity
(N
);
1551 Analyze_Expression
(R
);
1553 -- If the entity is present, the node appears in an instance, and
1554 -- denotes a predefined concatenation operation. The resulting type is
1555 -- obtained from the arguments when possible. If the arguments are
1556 -- aggregates, the array type and the concatenation type must be
1559 if Present
(Op_Id
) then
1560 if Ekind
(Op_Id
) = E_Operator
then
1561 LT
:= Base_Type
(Etype
(L
));
1562 RT
:= Base_Type
(Etype
(R
));
1564 if Is_Array_Type
(LT
)
1565 and then (RT
= LT
or else RT
= Base_Type
(Component_Type
(LT
)))
1567 Add_One_Interp
(N
, Op_Id
, LT
);
1569 elsif Is_Array_Type
(RT
)
1570 and then LT
= Base_Type
(Component_Type
(RT
))
1572 Add_One_Interp
(N
, Op_Id
, RT
);
1574 -- If one operand is a string type or a user-defined array type,
1575 -- and the other is a literal, result is of the specific type.
1578 (Root_Type
(LT
) = Standard_String
1579 or else Scope
(LT
) /= Standard_Standard
)
1580 and then Etype
(R
) = Any_String
1582 Add_One_Interp
(N
, Op_Id
, LT
);
1585 (Root_Type
(RT
) = Standard_String
1586 or else Scope
(RT
) /= Standard_Standard
)
1587 and then Etype
(L
) = Any_String
1589 Add_One_Interp
(N
, Op_Id
, RT
);
1591 elsif not Is_Generic_Type
(Etype
(Op_Id
)) then
1592 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1595 -- Type and its operations must be visible
1597 Set_Entity
(N
, Empty
);
1598 Analyze_Concatenation
(N
);
1602 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1606 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Concat
);
1607 while Present
(Op_Id
) loop
1608 if Ekind
(Op_Id
) = E_Operator
then
1610 -- Do not consider operators declared in dead code, they can
1611 -- not be part of the resolution.
1613 if Is_Eliminated
(Op_Id
) then
1616 Find_Concatenation_Types
(L
, R
, Op_Id
, N
);
1620 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1623 Op_Id
:= Homonym
(Op_Id
);
1628 end Analyze_Concatenation_Rest
;
1630 -------------------------
1631 -- Analyze_Equality_Op --
1632 -------------------------
1634 procedure Analyze_Equality_Op
(N
: Node_Id
) is
1635 Loc
: constant Source_Ptr
:= Sloc
(N
);
1636 L
: constant Node_Id
:= Left_Opnd
(N
);
1637 R
: constant Node_Id
:= Right_Opnd
(N
);
1641 Set_Etype
(N
, Any_Type
);
1642 Candidate_Type
:= Empty
;
1644 Analyze_Expression
(L
);
1645 Analyze_Expression
(R
);
1647 -- If the entity is set, the node is a generic instance with a non-local
1648 -- reference to the predefined operator or to a user-defined function.
1649 -- It can also be an inequality that is expanded into the negation of a
1650 -- call to a user-defined equality operator.
1652 -- For the predefined case, the result is Boolean, regardless of the
1653 -- type of the operands. The operands may even be limited, if they are
1654 -- generic actuals. If they are overloaded, label the left argument with
1655 -- the common type that must be present, or with the type of the formal
1656 -- of the user-defined function.
1658 if Present
(Entity
(N
)) then
1659 Op_Id
:= Entity
(N
);
1661 if Ekind
(Op_Id
) = E_Operator
then
1662 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
);
1664 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1667 if Is_Overloaded
(L
) then
1668 if Ekind
(Op_Id
) = E_Operator
then
1669 Set_Etype
(L
, Intersect_Types
(L
, R
));
1671 Set_Etype
(L
, Etype
(First_Formal
(Op_Id
)));
1676 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1677 while Present
(Op_Id
) loop
1678 if Ekind
(Op_Id
) = E_Operator
then
1679 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1681 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1684 Op_Id
:= Homonym
(Op_Id
);
1688 -- If there was no match, and the operator is inequality, this may
1689 -- be a case where inequality has not been made explicit, as for
1690 -- tagged types. Analyze the node as the negation of an equality
1691 -- operation. This cannot be done earlier, because before analysis
1692 -- we cannot rule out the presence of an explicit inequality.
1694 if Etype
(N
) = Any_Type
1695 and then Nkind
(N
) = N_Op_Ne
1697 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Eq
);
1698 while Present
(Op_Id
) loop
1699 if Ekind
(Op_Id
) = E_Operator
then
1700 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1702 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1705 Op_Id
:= Homonym
(Op_Id
);
1708 if Etype
(N
) /= Any_Type
then
1709 Op_Id
:= Entity
(N
);
1715 Left_Opnd
=> Left_Opnd
(N
),
1716 Right_Opnd
=> Right_Opnd
(N
))));
1718 Set_Entity
(Right_Opnd
(N
), Op_Id
);
1724 end Analyze_Equality_Op
;
1726 ----------------------------------
1727 -- Analyze_Explicit_Dereference --
1728 ----------------------------------
1730 procedure Analyze_Explicit_Dereference
(N
: Node_Id
) is
1731 Loc
: constant Source_Ptr
:= Sloc
(N
);
1732 P
: constant Node_Id
:= Prefix
(N
);
1738 function Is_Function_Type
return Boolean;
1739 -- Check whether node may be interpreted as an implicit function call
1741 ----------------------
1742 -- Is_Function_Type --
1743 ----------------------
1745 function Is_Function_Type
return Boolean is
1750 if not Is_Overloaded
(N
) then
1751 return Ekind
(Base_Type
(Etype
(N
))) = E_Subprogram_Type
1752 and then Etype
(Base_Type
(Etype
(N
))) /= Standard_Void_Type
;
1755 Get_First_Interp
(N
, I
, It
);
1756 while Present
(It
.Nam
) loop
1757 if Ekind
(Base_Type
(It
.Typ
)) /= E_Subprogram_Type
1758 or else Etype
(Base_Type
(It
.Typ
)) = Standard_Void_Type
1763 Get_Next_Interp
(I
, It
);
1768 end Is_Function_Type
;
1770 -- Start of processing for Analyze_Explicit_Dereference
1773 -- If source node, check SPARK restriction. We guard this with the
1774 -- source node check, because ???
1776 if Comes_From_Source
(N
) then
1777 Check_SPARK_05_Restriction
("explicit dereference is not allowed", N
);
1780 -- In formal verification mode, keep track of all reads and writes
1781 -- through explicit dereferences.
1783 if GNATprove_Mode
then
1784 SPARK_Specific
.Generate_Dereference
(N
);
1788 Set_Etype
(N
, Any_Type
);
1790 -- Test for remote access to subprogram type, and if so return
1791 -- after rewriting the original tree.
1793 if Remote_AST_E_Dereference
(P
) then
1797 -- Normal processing for other than remote access to subprogram type
1799 if not Is_Overloaded
(P
) then
1800 if Is_Access_Type
(Etype
(P
)) then
1802 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
1803 -- avoid other problems caused by the Private_Subtype and it is
1804 -- safe to go to the Base_Type because this is the same as
1805 -- converting the access value to its Base_Type.
1808 DT
: Entity_Id
:= Designated_Type
(Etype
(P
));
1811 if Ekind
(DT
) = E_Private_Subtype
1812 and then Is_For_Access_Subtype
(DT
)
1814 DT
:= Base_Type
(DT
);
1817 -- An explicit dereference is a legal occurrence of an
1818 -- incomplete type imported through a limited_with clause,
1819 -- if the full view is visible.
1821 if From_Limited_With
(DT
)
1822 and then not From_Limited_With
(Scope
(DT
))
1824 (Is_Immediately_Visible
(Scope
(DT
))
1826 (Is_Child_Unit
(Scope
(DT
))
1827 and then Is_Visible_Lib_Unit
(Scope
(DT
))))
1829 Set_Etype
(N
, Available_View
(DT
));
1836 elsif Etype
(P
) /= Any_Type
then
1837 Error_Msg_N
("prefix of dereference must be an access type", N
);
1842 Get_First_Interp
(P
, I
, It
);
1843 while Present
(It
.Nam
) loop
1846 if Is_Access_Type
(T
) then
1847 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
1850 Get_Next_Interp
(I
, It
);
1853 -- Error if no interpretation of the prefix has an access type
1855 if Etype
(N
) = Any_Type
then
1857 ("access type required in prefix of explicit dereference", P
);
1858 Set_Etype
(N
, Any_Type
);
1864 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
1866 and then (Nkind
(Parent
(N
)) /= N_Function_Call
1867 or else N
/= Name
(Parent
(N
)))
1869 and then (Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1870 or else N
/= Name
(Parent
(N
)))
1872 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
1873 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
1875 (Attribute_Name
(Parent
(N
)) /= Name_Address
1877 Attribute_Name
(Parent
(N
)) /= Name_Access
))
1879 -- Name is a function call with no actuals, in a context that
1880 -- requires deproceduring (including as an actual in an enclosing
1881 -- function or procedure call). There are some pathological cases
1882 -- where the prefix might include functions that return access to
1883 -- subprograms and others that return a regular type. Disambiguation
1884 -- of those has to take place in Resolve.
1887 Make_Function_Call
(Loc
,
1888 Name
=> Make_Explicit_Dereference
(Loc
, P
),
1889 Parameter_Associations
=> New_List
);
1891 -- If the prefix is overloaded, remove operations that have formals,
1892 -- we know that this is a parameterless call.
1894 if Is_Overloaded
(P
) then
1895 Get_First_Interp
(P
, I
, It
);
1896 while Present
(It
.Nam
) loop
1899 if No
(First_Formal
(Base_Type
(Designated_Type
(T
)))) then
1905 Get_Next_Interp
(I
, It
);
1912 elsif not Is_Function_Type
1913 and then Is_Overloaded
(N
)
1915 -- The prefix may include access to subprograms and other access
1916 -- types. If the context selects the interpretation that is a
1917 -- function call (not a procedure call) we cannot rewrite the node
1918 -- yet, but we include the result of the call interpretation.
1920 Get_First_Interp
(N
, I
, It
);
1921 while Present
(It
.Nam
) loop
1922 if Ekind
(Base_Type
(It
.Typ
)) = E_Subprogram_Type
1923 and then Etype
(Base_Type
(It
.Typ
)) /= Standard_Void_Type
1924 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1926 Add_One_Interp
(N
, Etype
(It
.Typ
), Etype
(It
.Typ
));
1929 Get_Next_Interp
(I
, It
);
1933 -- A value of remote access-to-class-wide must not be dereferenced
1936 Validate_Remote_Access_To_Class_Wide_Type
(N
);
1937 end Analyze_Explicit_Dereference
;
1939 ------------------------
1940 -- Analyze_Expression --
1941 ------------------------
1943 procedure Analyze_Expression
(N
: Node_Id
) is
1946 -- If the expression is an indexed component that will be rewritten
1947 -- as a container indexing, it has already been analyzed.
1949 if Nkind
(N
) = N_Indexed_Component
1950 and then Present
(Generalized_Indexing
(N
))
1956 Check_Parameterless_Call
(N
);
1958 end Analyze_Expression
;
1960 -------------------------------------
1961 -- Analyze_Expression_With_Actions --
1962 -------------------------------------
1964 procedure Analyze_Expression_With_Actions
(N
: Node_Id
) is
1968 A
:= First
(Actions
(N
));
1969 while Present
(A
) loop
1974 Analyze_Expression
(Expression
(N
));
1975 Set_Etype
(N
, Etype
(Expression
(N
)));
1976 end Analyze_Expression_With_Actions
;
1978 ---------------------------
1979 -- Analyze_If_Expression --
1980 ---------------------------
1982 procedure Analyze_If_Expression
(N
: Node_Id
) is
1983 Condition
: constant Node_Id
:= First
(Expressions
(N
));
1984 Then_Expr
: constant Node_Id
:= Next
(Condition
);
1985 Else_Expr
: Node_Id
;
1988 -- Defend against error of missing expressions from previous error
1990 if No
(Then_Expr
) then
1991 Check_Error_Detected
;
1995 if Comes_From_Source
(N
) then
1996 Check_SPARK_05_Restriction
("if expression is not allowed", N
);
1999 Else_Expr
:= Next
(Then_Expr
);
2001 if Comes_From_Source
(N
) then
2002 Check_Compiler_Unit
("if expression", N
);
2005 -- Analyze and resolve the condition. We need to resolve this now so
2006 -- that it gets folded to True/False if possible, before we analyze
2007 -- the THEN/ELSE branches, because when analyzing these branches, we
2008 -- may call Is_Statically_Unevaluated, which expects the condition of
2009 -- an enclosing IF to have been analyze/resolved/evaluated.
2011 Analyze_Expression
(Condition
);
2012 Resolve
(Condition
, Any_Boolean
);
2014 -- Analyze THEN expression and (if present) ELSE expression. For those
2015 -- we delay resolution in the normal manner, because of overloading etc.
2017 Analyze_Expression
(Then_Expr
);
2019 if Present
(Else_Expr
) then
2020 Analyze_Expression
(Else_Expr
);
2023 -- If then expression not overloaded, then that decides the type
2025 if not Is_Overloaded
(Then_Expr
) then
2026 Set_Etype
(N
, Etype
(Then_Expr
));
2028 -- Case where then expression is overloaded
2036 Set_Etype
(N
, Any_Type
);
2038 -- Shouldn't the following statement be down in the ELSE of the
2039 -- following loop? ???
2041 Get_First_Interp
(Then_Expr
, I
, It
);
2043 -- if no Else_Expression the conditional must be boolean
2045 if No
(Else_Expr
) then
2046 Set_Etype
(N
, Standard_Boolean
);
2048 -- Else_Expression Present. For each possible intepretation of
2049 -- the Then_Expression, add it only if the Else_Expression has
2050 -- a compatible type.
2053 while Present
(It
.Nam
) loop
2054 if Has_Compatible_Type
(Else_Expr
, It
.Typ
) then
2055 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
2058 Get_Next_Interp
(I
, It
);
2063 end Analyze_If_Expression
;
2065 ------------------------------------
2066 -- Analyze_Indexed_Component_Form --
2067 ------------------------------------
2069 procedure Analyze_Indexed_Component_Form
(N
: Node_Id
) is
2070 P
: constant Node_Id
:= Prefix
(N
);
2071 Exprs
: constant List_Id
:= Expressions
(N
);
2077 procedure Process_Function_Call
;
2078 -- Prefix in indexed component form is an overloadable entity,
2079 -- so the node is a function call. Reformat it as such.
2081 procedure Process_Indexed_Component
;
2082 -- Prefix in indexed component form is actually an indexed component.
2083 -- This routine processes it, knowing that the prefix is already
2086 procedure Process_Indexed_Component_Or_Slice
;
2087 -- An indexed component with a single index may designate a slice if
2088 -- the index is a subtype mark. This routine disambiguates these two
2089 -- cases by resolving the prefix to see if it is a subtype mark.
2091 procedure Process_Overloaded_Indexed_Component
;
2092 -- If the prefix of an indexed component is overloaded, the proper
2093 -- interpretation is selected by the index types and the context.
2095 ---------------------------
2096 -- Process_Function_Call --
2097 ---------------------------
2099 procedure Process_Function_Call
is
2100 Loc
: constant Source_Ptr
:= Sloc
(N
);
2104 Change_Node
(N
, N_Function_Call
);
2106 Set_Parameter_Associations
(N
, Exprs
);
2108 -- Analyze actuals prior to analyzing the call itself
2110 Actual
:= First
(Parameter_Associations
(N
));
2111 while Present
(Actual
) loop
2113 Check_Parameterless_Call
(Actual
);
2115 -- Move to next actual. Note that we use Next, not Next_Actual
2116 -- here. The reason for this is a bit subtle. If a function call
2117 -- includes named associations, the parser recognizes the node as
2118 -- a call, and it is analyzed as such. If all associations are
2119 -- positional, the parser builds an indexed_component node, and
2120 -- it is only after analysis of the prefix that the construct
2121 -- is recognized as a call, in which case Process_Function_Call
2122 -- rewrites the node and analyzes the actuals. If the list of
2123 -- actuals is malformed, the parser may leave the node as an
2124 -- indexed component (despite the presence of named associations).
2125 -- The iterator Next_Actual is equivalent to Next if the list is
2126 -- positional, but follows the normalized chain of actuals when
2127 -- named associations are present. In this case normalization has
2128 -- not taken place, and actuals remain unanalyzed, which leads to
2129 -- subsequent crashes or loops if there is an attempt to continue
2130 -- analysis of the program.
2132 -- IF there is a single actual and it is a type name, the node
2133 -- can only be interpreted as a slice of a parameterless call.
2134 -- Rebuild the node as such and analyze.
2136 if No
(Next
(Actual
))
2137 and then Is_Entity_Name
(Actual
)
2138 and then Is_Type
(Entity
(Actual
))
2139 and then Is_Discrete_Type
(Entity
(Actual
))
2145 New_Occurrence_Of
(Entity
(Actual
), Loc
)));
2155 end Process_Function_Call
;
2157 -------------------------------
2158 -- Process_Indexed_Component --
2159 -------------------------------
2161 procedure Process_Indexed_Component
is
2163 Array_Type
: Entity_Id
;
2165 Pent
: Entity_Id
:= Empty
;
2168 Exp
:= First
(Exprs
);
2170 if Is_Overloaded
(P
) then
2171 Process_Overloaded_Indexed_Component
;
2174 Array_Type
:= Etype
(P
);
2176 if Is_Entity_Name
(P
) then
2178 elsif Nkind
(P
) = N_Selected_Component
2179 and then Is_Entity_Name
(Selector_Name
(P
))
2181 Pent
:= Entity
(Selector_Name
(P
));
2184 -- Prefix must be appropriate for an array type, taking into
2185 -- account a possible implicit dereference.
2187 if Is_Access_Type
(Array_Type
) then
2189 (Warn_On_Dereference
, "?d?implicit dereference", N
);
2190 Array_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, P
);
2193 if Is_Array_Type
(Array_Type
) then
2196 elsif Present
(Pent
) and then Ekind
(Pent
) = E_Entry_Family
then
2198 Set_Etype
(N
, Any_Type
);
2200 if not Has_Compatible_Type
2201 (Exp
, Entry_Index_Type
(Pent
))
2203 Error_Msg_N
("invalid index type in entry name", N
);
2205 elsif Present
(Next
(Exp
)) then
2206 Error_Msg_N
("too many subscripts in entry reference", N
);
2209 Set_Etype
(N
, Etype
(P
));
2214 elsif Is_Record_Type
(Array_Type
)
2215 and then Remote_AST_I_Dereference
(P
)
2219 elsif Try_Container_Indexing
(N
, P
, Exprs
) then
2222 elsif Array_Type
= Any_Type
then
2223 Set_Etype
(N
, Any_Type
);
2225 -- In most cases the analysis of the prefix will have emitted
2226 -- an error already, but if the prefix may be interpreted as a
2227 -- call in prefixed notation, the report is left to the caller.
2228 -- To prevent cascaded errors, report only if no previous ones.
2230 if Serious_Errors_Detected
= 0 then
2231 Error_Msg_N
("invalid prefix in indexed component", P
);
2233 if Nkind
(P
) = N_Expanded_Name
then
2234 Error_Msg_NE
("\& is not visible", P
, Selector_Name
(P
));
2240 -- Here we definitely have a bad indexing
2243 if Nkind
(Parent
(N
)) = N_Requeue_Statement
2244 and then Present
(Pent
) and then Ekind
(Pent
) = E_Entry
2247 ("REQUEUE does not permit parameters", First
(Exprs
));
2249 elsif Is_Entity_Name
(P
)
2250 and then Etype
(P
) = Standard_Void_Type
2252 Error_Msg_NE
("incorrect use of&", P
, Entity
(P
));
2255 Error_Msg_N
("array type required in indexed component", P
);
2258 Set_Etype
(N
, Any_Type
);
2262 Index
:= First_Index
(Array_Type
);
2263 while Present
(Index
) and then Present
(Exp
) loop
2264 if not Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2265 Wrong_Type
(Exp
, Etype
(Index
));
2266 Set_Etype
(N
, Any_Type
);
2274 Set_Etype
(N
, Component_Type
(Array_Type
));
2275 Check_Implicit_Dereference
(N
, Etype
(N
));
2277 if Present
(Index
) then
2279 ("too few subscripts in array reference", First
(Exprs
));
2281 elsif Present
(Exp
) then
2282 Error_Msg_N
("too many subscripts in array reference", Exp
);
2285 end Process_Indexed_Component
;
2287 ----------------------------------------
2288 -- Process_Indexed_Component_Or_Slice --
2289 ----------------------------------------
2291 procedure Process_Indexed_Component_Or_Slice
is
2293 Exp
:= First
(Exprs
);
2294 while Present
(Exp
) loop
2295 Analyze_Expression
(Exp
);
2299 Exp
:= First
(Exprs
);
2301 -- If one index is present, and it is a subtype name, then the
2302 -- node denotes a slice (note that the case of an explicit range
2303 -- for a slice was already built as an N_Slice node in the first
2304 -- place, so that case is not handled here).
2306 -- We use a replace rather than a rewrite here because this is one
2307 -- of the cases in which the tree built by the parser is plain wrong.
2310 and then Is_Entity_Name
(Exp
)
2311 and then Is_Type
(Entity
(Exp
))
2314 Make_Slice
(Sloc
(N
),
2316 Discrete_Range
=> New_Copy
(Exp
)));
2319 -- Otherwise (more than one index present, or single index is not
2320 -- a subtype name), then we have the indexed component case.
2323 Process_Indexed_Component
;
2325 end Process_Indexed_Component_Or_Slice
;
2327 ------------------------------------------
2328 -- Process_Overloaded_Indexed_Component --
2329 ------------------------------------------
2331 procedure Process_Overloaded_Indexed_Component
is
2340 Set_Etype
(N
, Any_Type
);
2342 Get_First_Interp
(P
, I
, It
);
2343 while Present
(It
.Nam
) loop
2346 if Is_Access_Type
(Typ
) then
2347 Typ
:= Designated_Type
(Typ
);
2349 (Warn_On_Dereference
, "?d?implicit dereference", N
);
2352 if Is_Array_Type
(Typ
) then
2354 -- Got a candidate: verify that index types are compatible
2356 Index
:= First_Index
(Typ
);
2358 Exp
:= First
(Exprs
);
2359 while Present
(Index
) and then Present
(Exp
) loop
2360 if Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2372 if Found
and then No
(Index
) and then No
(Exp
) then
2374 CT
: constant Entity_Id
:=
2375 Base_Type
(Component_Type
(Typ
));
2377 Add_One_Interp
(N
, CT
, CT
);
2378 Check_Implicit_Dereference
(N
, CT
);
2382 elsif Try_Container_Indexing
(N
, P
, Exprs
) then
2387 Get_Next_Interp
(I
, It
);
2390 if Etype
(N
) = Any_Type
then
2391 Error_Msg_N
("no legal interpretation for indexed component", N
);
2392 Set_Is_Overloaded
(N
, False);
2396 end Process_Overloaded_Indexed_Component
;
2398 -- Start of processing for Analyze_Indexed_Component_Form
2401 -- Get name of array, function or type
2405 -- If P is an explicit dereference whose prefix is of a remote access-
2406 -- to-subprogram type, then N has already been rewritten as a subprogram
2407 -- call and analyzed.
2409 if Nkind
(N
) in N_Subprogram_Call
then
2412 -- When the prefix is attribute 'Loop_Entry and the sole expression of
2413 -- the indexed component denotes a loop name, the indexed form is turned
2414 -- into an attribute reference.
2416 elsif Nkind
(N
) = N_Attribute_Reference
2417 and then Attribute_Name
(N
) = Name_Loop_Entry
2422 pragma Assert
(Nkind
(N
) = N_Indexed_Component
);
2424 P_T
:= Base_Type
(Etype
(P
));
2426 if Is_Entity_Name
(P
) and then Present
(Entity
(P
)) then
2429 if Is_Type
(U_N
) then
2431 -- Reformat node as a type conversion
2433 E
:= Remove_Head
(Exprs
);
2435 if Present
(First
(Exprs
)) then
2437 ("argument of type conversion must be single expression", N
);
2440 Change_Node
(N
, N_Type_Conversion
);
2441 Set_Subtype_Mark
(N
, P
);
2443 Set_Expression
(N
, E
);
2445 -- After changing the node, call for the specific Analysis
2446 -- routine directly, to avoid a double call to the expander.
2448 Analyze_Type_Conversion
(N
);
2452 if Is_Overloadable
(U_N
) then
2453 Process_Function_Call
;
2455 elsif Ekind
(Etype
(P
)) = E_Subprogram_Type
2456 or else (Is_Access_Type
(Etype
(P
))
2458 Ekind
(Designated_Type
(Etype
(P
))) =
2461 -- Call to access_to-subprogram with possible implicit dereference
2463 Process_Function_Call
;
2465 elsif Is_Generic_Subprogram
(U_N
) then
2467 -- A common beginner's (or C++ templates fan) error
2469 Error_Msg_N
("generic subprogram cannot be called", N
);
2470 Set_Etype
(N
, Any_Type
);
2474 Process_Indexed_Component_Or_Slice
;
2477 -- If not an entity name, prefix is an expression that may denote
2478 -- an array or an access-to-subprogram.
2481 if Ekind
(P_T
) = E_Subprogram_Type
2482 or else (Is_Access_Type
(P_T
)
2484 Ekind
(Designated_Type
(P_T
)) = E_Subprogram_Type
)
2486 Process_Function_Call
;
2488 elsif Nkind
(P
) = N_Selected_Component
2489 and then Present
(Entity
(Selector_Name
(P
)))
2490 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
2492 Process_Function_Call
;
2494 -- In ASIS mode within a generic, a prefixed call is analyzed and
2495 -- partially rewritten but the original indexed component has not
2496 -- yet been rewritten as a call. Perform the replacement now.
2498 elsif Nkind
(P
) = N_Selected_Component
2499 and then Nkind
(Parent
(P
)) = N_Function_Call
2502 Rewrite
(N
, Parent
(P
));
2506 -- Indexed component, slice, or a call to a member of a family
2507 -- entry, which will be converted to an entry call later.
2509 Process_Indexed_Component_Or_Slice
;
2513 Analyze_Dimension
(N
);
2514 end Analyze_Indexed_Component_Form
;
2516 ------------------------
2517 -- Analyze_Logical_Op --
2518 ------------------------
2520 procedure Analyze_Logical_Op
(N
: Node_Id
) is
2521 L
: constant Node_Id
:= Left_Opnd
(N
);
2522 R
: constant Node_Id
:= Right_Opnd
(N
);
2523 Op_Id
: Entity_Id
:= Entity
(N
);
2526 Set_Etype
(N
, Any_Type
);
2527 Candidate_Type
:= Empty
;
2529 Analyze_Expression
(L
);
2530 Analyze_Expression
(R
);
2532 if Present
(Op_Id
) then
2534 if Ekind
(Op_Id
) = E_Operator
then
2535 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
2537 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2541 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
2542 while Present
(Op_Id
) loop
2543 if Ekind
(Op_Id
) = E_Operator
then
2544 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
2546 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
2549 Op_Id
:= Homonym
(Op_Id
);
2554 end Analyze_Logical_Op
;
2556 ---------------------------
2557 -- Analyze_Membership_Op --
2558 ---------------------------
2560 procedure Analyze_Membership_Op
(N
: Node_Id
) is
2561 Loc
: constant Source_Ptr
:= Sloc
(N
);
2562 L
: constant Node_Id
:= Left_Opnd
(N
);
2563 R
: constant Node_Id
:= Right_Opnd
(N
);
2565 Index
: Interp_Index
;
2567 Found
: Boolean := False;
2571 procedure Try_One_Interp
(T1
: Entity_Id
);
2572 -- Routine to try one proposed interpretation. Note that the context
2573 -- of the operation plays no role in resolving the arguments, so that
2574 -- if there is more than one interpretation of the operands that is
2575 -- compatible with a membership test, the operation is ambiguous.
2577 --------------------
2578 -- Try_One_Interp --
2579 --------------------
2581 procedure Try_One_Interp
(T1
: Entity_Id
) is
2583 if Has_Compatible_Type
(R
, T1
) then
2585 and then Base_Type
(T1
) /= Base_Type
(T_F
)
2587 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
2589 if It
= No_Interp
then
2590 Ambiguous_Operands
(N
);
2591 Set_Etype
(L
, Any_Type
);
2608 procedure Analyze_Set_Membership
;
2609 -- If a set of alternatives is present, analyze each and find the
2610 -- common type to which they must all resolve.
2612 ----------------------------
2613 -- Analyze_Set_Membership --
2614 ----------------------------
2616 procedure Analyze_Set_Membership
is
2618 Index
: Interp_Index
;
2620 Candidate_Interps
: Node_Id
;
2621 Common_Type
: Entity_Id
:= Empty
;
2624 if Comes_From_Source
(N
) then
2625 Check_Compiler_Unit
("set membership", N
);
2629 Candidate_Interps
:= L
;
2631 if not Is_Overloaded
(L
) then
2632 Common_Type
:= Etype
(L
);
2634 Alt
:= First
(Alternatives
(N
));
2635 while Present
(Alt
) loop
2638 if not Has_Compatible_Type
(Alt
, Common_Type
) then
2639 Wrong_Type
(Alt
, Common_Type
);
2646 Alt
:= First
(Alternatives
(N
));
2647 while Present
(Alt
) loop
2649 if not Is_Overloaded
(Alt
) then
2650 Common_Type
:= Etype
(Alt
);
2653 Get_First_Interp
(Alt
, Index
, It
);
2654 while Present
(It
.Typ
) loop
2656 Has_Compatible_Type
(Candidate_Interps
, It
.Typ
)
2658 Remove_Interp
(Index
);
2661 Get_Next_Interp
(Index
, It
);
2664 Get_First_Interp
(Alt
, Index
, It
);
2667 Error_Msg_N
("alternative has no legal type", Alt
);
2671 -- If alternative is not overloaded, we have a unique type
2674 Set_Etype
(Alt
, It
.Typ
);
2675 Get_Next_Interp
(Index
, It
);
2678 Set_Is_Overloaded
(Alt
, False);
2679 Common_Type
:= Etype
(Alt
);
2682 Candidate_Interps
:= Alt
;
2689 Set_Etype
(N
, Standard_Boolean
);
2691 if Present
(Common_Type
) then
2692 Set_Etype
(L
, Common_Type
);
2693 Set_Is_Overloaded
(L
, False);
2696 Error_Msg_N
("cannot resolve membership operation", N
);
2698 end Analyze_Set_Membership
;
2700 -- Start of processing for Analyze_Membership_Op
2703 Analyze_Expression
(L
);
2705 if No
(R
) and then Ada_Version
>= Ada_2012
then
2706 Analyze_Set_Membership
;
2710 if Nkind
(R
) = N_Range
2711 or else (Nkind
(R
) = N_Attribute_Reference
2712 and then Attribute_Name
(R
) = Name_Range
)
2716 if not Is_Overloaded
(L
) then
2717 Try_One_Interp
(Etype
(L
));
2720 Get_First_Interp
(L
, Index
, It
);
2721 while Present
(It
.Typ
) loop
2722 Try_One_Interp
(It
.Typ
);
2723 Get_Next_Interp
(Index
, It
);
2727 -- If not a range, it can be a subtype mark, or else it is a degenerate
2728 -- membership test with a singleton value, i.e. a test for equality,
2729 -- if the types are compatible.
2734 if Is_Entity_Name
(R
)
2735 and then Is_Type
(Entity
(R
))
2738 Check_Fully_Declared
(Entity
(R
), R
);
2740 elsif Ada_Version
>= Ada_2012
2741 and then Has_Compatible_Type
(R
, Etype
(L
))
2743 if Nkind
(N
) = N_In
then
2759 -- In all versions of the language, if we reach this point there
2760 -- is a previous error that will be diagnosed below.
2766 -- Compatibility between expression and subtype mark or range is
2767 -- checked during resolution. The result of the operation is Boolean
2770 Set_Etype
(N
, Standard_Boolean
);
2772 if Comes_From_Source
(N
)
2773 and then Present
(Right_Opnd
(N
))
2774 and then Is_CPP_Class
(Etype
(Etype
(Right_Opnd
(N
))))
2776 Error_Msg_N
("membership test not applicable to cpp-class types", N
);
2778 end Analyze_Membership_Op
;
2784 procedure Analyze_Mod
(N
: Node_Id
) is
2786 -- A special warning check, if we have an expression of the form:
2787 -- expr mod 2 * literal
2788 -- where literal is 64 or less, then probably what was meant was
2789 -- expr mod 2 ** literal
2790 -- so issue an appropriate warning.
2792 if Warn_On_Suspicious_Modulus_Value
2793 and then Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
2794 and then Intval
(Right_Opnd
(N
)) = Uint_2
2795 and then Nkind
(Parent
(N
)) = N_Op_Multiply
2796 and then Nkind
(Right_Opnd
(Parent
(N
))) = N_Integer_Literal
2797 and then Intval
(Right_Opnd
(Parent
(N
))) <= Uint_64
2800 ("suspicious MOD value, was '*'* intended'??M?", Parent
(N
));
2803 -- Remaining processing is same as for other arithmetic operators
2805 Analyze_Arithmetic_Op
(N
);
2808 ----------------------
2809 -- Analyze_Negation --
2810 ----------------------
2812 procedure Analyze_Negation
(N
: Node_Id
) is
2813 R
: constant Node_Id
:= Right_Opnd
(N
);
2814 Op_Id
: Entity_Id
:= Entity
(N
);
2817 Set_Etype
(N
, Any_Type
);
2818 Candidate_Type
:= Empty
;
2820 Analyze_Expression
(R
);
2822 if Present
(Op_Id
) then
2823 if Ekind
(Op_Id
) = E_Operator
then
2824 Find_Negation_Types
(R
, Op_Id
, N
);
2826 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2830 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
2831 while Present
(Op_Id
) loop
2832 if Ekind
(Op_Id
) = E_Operator
then
2833 Find_Negation_Types
(R
, Op_Id
, N
);
2835 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
2838 Op_Id
:= Homonym
(Op_Id
);
2843 end Analyze_Negation
;
2849 procedure Analyze_Null
(N
: Node_Id
) is
2851 Check_SPARK_05_Restriction
("null is not allowed", N
);
2853 Set_Etype
(N
, Any_Access
);
2856 ----------------------
2857 -- Analyze_One_Call --
2858 ----------------------
2860 procedure Analyze_One_Call
2864 Success
: out Boolean;
2865 Skip_First
: Boolean := False)
2867 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
2868 Prev_T
: constant Entity_Id
:= Etype
(N
);
2870 Must_Skip
: constant Boolean := Skip_First
2871 or else Nkind
(Original_Node
(N
)) = N_Selected_Component
2873 (Nkind
(Original_Node
(N
)) = N_Indexed_Component
2874 and then Nkind
(Prefix
(Original_Node
(N
)))
2875 = N_Selected_Component
);
2876 -- The first formal must be omitted from the match when trying to find
2877 -- a primitive operation that is a possible interpretation, and also
2878 -- after the call has been rewritten, because the corresponding actual
2879 -- is already known to be compatible, and because this may be an
2880 -- indexing of a call with default parameters.
2884 Is_Indexed
: Boolean := False;
2885 Is_Indirect
: Boolean := False;
2886 Subp_Type
: constant Entity_Id
:= Etype
(Nam
);
2889 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean;
2890 -- There may be a user-defined operator that hides the current
2891 -- interpretation. We must check for this independently of the
2892 -- analysis of the call with the user-defined operation, because
2893 -- the parameter names may be wrong and yet the hiding takes place.
2894 -- This fixes a problem with ACATS test B34014O.
2896 -- When the type Address is a visible integer type, and the DEC
2897 -- system extension is visible, the predefined operator may be
2898 -- hidden as well, by one of the address operations in auxdec.
2899 -- Finally, The abstract operations on address do not hide the
2900 -- predefined operator (this is the purpose of making them abstract).
2902 procedure Indicate_Name_And_Type
;
2903 -- If candidate interpretation matches, indicate name and type of
2904 -- result on call node.
2906 ----------------------------
2907 -- Indicate_Name_And_Type --
2908 ----------------------------
2910 procedure Indicate_Name_And_Type
is
2912 Add_One_Interp
(N
, Nam
, Etype
(Nam
));
2913 Check_Implicit_Dereference
(N
, Etype
(Nam
));
2916 -- If the prefix of the call is a name, indicate the entity
2917 -- being called. If it is not a name, it is an expression that
2918 -- denotes an access to subprogram or else an entry or family. In
2919 -- the latter case, the name is a selected component, and the entity
2920 -- being called is noted on the selector.
2922 if not Is_Type
(Nam
) then
2923 if Is_Entity_Name
(Name
(N
)) then
2924 Set_Entity
(Name
(N
), Nam
);
2926 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
2927 Set_Entity
(Selector_Name
(Name
(N
)), Nam
);
2931 if Debug_Flag_E
and not Report
then
2932 Write_Str
(" Overloaded call ");
2933 Write_Int
(Int
(N
));
2934 Write_Str
(" compatible with ");
2935 Write_Int
(Int
(Nam
));
2938 end Indicate_Name_And_Type
;
2940 ------------------------
2941 -- Operator_Hidden_By --
2942 ------------------------
2944 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean is
2945 Act1
: constant Node_Id
:= First_Actual
(N
);
2946 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
2947 Form1
: constant Entity_Id
:= First_Formal
(Fun
);
2948 Form2
: constant Entity_Id
:= Next_Formal
(Form1
);
2951 if Ekind
(Fun
) /= E_Function
or else Is_Abstract_Subprogram
(Fun
) then
2954 elsif not Has_Compatible_Type
(Act1
, Etype
(Form1
)) then
2957 elsif Present
(Form2
) then
2959 or else not Has_Compatible_Type
(Act2
, Etype
(Form2
))
2964 elsif Present
(Act2
) then
2968 -- Now we know that the arity of the operator matches the function,
2969 -- and the function call is a valid interpretation. The function
2970 -- hides the operator if it has the right signature, or if one of
2971 -- its operands is a non-abstract operation on Address when this is
2972 -- a visible integer type.
2974 return Hides_Op
(Fun
, Nam
)
2975 or else Is_Descendent_Of_Address
(Etype
(Form1
))
2978 and then Is_Descendent_Of_Address
(Etype
(Form2
)));
2979 end Operator_Hidden_By
;
2981 -- Start of processing for Analyze_One_Call
2986 -- If the subprogram has no formals or if all the formals have defaults,
2987 -- and the return type is an array type, the node may denote an indexing
2988 -- of the result of a parameterless call. In Ada 2005, the subprogram
2989 -- may have one non-defaulted formal, and the call may have been written
2990 -- in prefix notation, so that the rebuilt parameter list has more than
2993 if not Is_Overloadable
(Nam
)
2994 and then Ekind
(Nam
) /= E_Subprogram_Type
2995 and then Ekind
(Nam
) /= E_Entry_Family
3000 -- An indexing requires at least one actual. The name of the call cannot
3001 -- be an implicit indirect call, so it cannot be a generated explicit
3004 if not Is_Empty_List
(Actuals
)
3006 (Needs_No_Actuals
(Nam
)
3008 (Needs_One_Actual
(Nam
)
3009 and then Present
(Next_Actual
(First
(Actuals
)))))
3011 if Is_Array_Type
(Subp_Type
)
3013 (Nkind
(Name
(N
)) /= N_Explicit_Dereference
3014 or else Comes_From_Source
(Name
(N
)))
3016 Is_Indexed
:= Try_Indexed_Call
(N
, Nam
, Subp_Type
, Must_Skip
);
3018 elsif Is_Access_Type
(Subp_Type
)
3019 and then Is_Array_Type
(Designated_Type
(Subp_Type
))
3023 (N
, Nam
, Designated_Type
(Subp_Type
), Must_Skip
);
3025 -- The prefix can also be a parameterless function that returns an
3026 -- access to subprogram, in which case this is an indirect call.
3027 -- If this succeeds, an explicit dereference is added later on,
3028 -- in Analyze_Call or Resolve_Call.
3030 elsif Is_Access_Type
(Subp_Type
)
3031 and then Ekind
(Designated_Type
(Subp_Type
)) = E_Subprogram_Type
3033 Is_Indirect
:= Try_Indirect_Call
(N
, Nam
, Subp_Type
);
3038 -- If the call has been transformed into a slice, it is of the form
3039 -- F (Subtype) where F is parameterless. The node has been rewritten in
3040 -- Try_Indexed_Call and there is nothing else to do.
3043 and then Nkind
(N
) = N_Slice
3049 (N
, Nam
, (Report
and not Is_Indexed
and not Is_Indirect
), Norm_OK
);
3053 -- If an indirect call is a possible interpretation, indicate
3054 -- success to the caller. This may be an indexing of an explicit
3055 -- dereference of a call that returns an access type (see above).
3059 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
3060 and then Comes_From_Source
(Name
(N
)))
3065 -- Mismatch in number or names of parameters
3067 elsif Debug_Flag_E
then
3068 Write_Str
(" normalization fails in call ");
3069 Write_Int
(Int
(N
));
3070 Write_Str
(" with subprogram ");
3071 Write_Int
(Int
(Nam
));
3075 -- If the context expects a function call, discard any interpretation
3076 -- that is a procedure. If the node is not overloaded, leave as is for
3077 -- better error reporting when type mismatch is found.
3079 elsif Nkind
(N
) = N_Function_Call
3080 and then Is_Overloaded
(Name
(N
))
3081 and then Ekind
(Nam
) = E_Procedure
3085 -- Ditto for function calls in a procedure context
3087 elsif Nkind
(N
) = N_Procedure_Call_Statement
3088 and then Is_Overloaded
(Name
(N
))
3089 and then Etype
(Nam
) /= Standard_Void_Type
3093 elsif No
(Actuals
) then
3095 -- If Normalize succeeds, then there are default parameters for
3098 Indicate_Name_And_Type
;
3100 elsif Ekind
(Nam
) = E_Operator
then
3101 if Nkind
(N
) = N_Procedure_Call_Statement
then
3105 -- This can occur when the prefix of the call is an operator
3106 -- name or an expanded name whose selector is an operator name.
3108 Analyze_Operator_Call
(N
, Nam
);
3110 if Etype
(N
) /= Prev_T
then
3112 -- Check that operator is not hidden by a function interpretation
3114 if Is_Overloaded
(Name
(N
)) then
3120 Get_First_Interp
(Name
(N
), I
, It
);
3121 while Present
(It
.Nam
) loop
3122 if Operator_Hidden_By
(It
.Nam
) then
3123 Set_Etype
(N
, Prev_T
);
3127 Get_Next_Interp
(I
, It
);
3132 -- If operator matches formals, record its name on the call.
3133 -- If the operator is overloaded, Resolve will select the
3134 -- correct one from the list of interpretations. The call
3135 -- node itself carries the first candidate.
3137 Set_Entity
(Name
(N
), Nam
);
3140 elsif Report
and then Etype
(N
) = Any_Type
then
3141 Error_Msg_N
("incompatible arguments for operator", N
);
3145 -- Normalize_Actuals has chained the named associations in the
3146 -- correct order of the formals.
3148 Actual
:= First_Actual
(N
);
3149 Formal
:= First_Formal
(Nam
);
3151 -- If we are analyzing a call rewritten from object notation, skip
3152 -- first actual, which may be rewritten later as an explicit
3156 Next_Actual
(Actual
);
3157 Next_Formal
(Formal
);
3160 while Present
(Actual
) and then Present
(Formal
) loop
3161 if Nkind
(Parent
(Actual
)) /= N_Parameter_Association
3162 or else Chars
(Selector_Name
(Parent
(Actual
))) = Chars
(Formal
)
3164 -- The actual can be compatible with the formal, but we must
3165 -- also check that the context is not an address type that is
3166 -- visibly an integer type. In this case the use of literals is
3167 -- illegal, except in the body of descendents of system, where
3168 -- arithmetic operations on address are of course used.
3170 if Has_Compatible_Type
(Actual
, Etype
(Formal
))
3172 (Etype
(Actual
) /= Universal_Integer
3173 or else not Is_Descendent_Of_Address
(Etype
(Formal
))
3175 Is_Predefined_File_Name
3176 (Unit_File_Name
(Get_Source_Unit
(N
))))
3178 Next_Actual
(Actual
);
3179 Next_Formal
(Formal
);
3181 -- In Allow_Integer_Address mode, we allow an actual integer to
3182 -- match a formal address type and vice versa. We only do this
3183 -- if we are certain that an error will otherwise be issued
3185 elsif Address_Integer_Convert_OK
3186 (Etype
(Actual
), Etype
(Formal
))
3187 and then (Report
and not Is_Indexed
and not Is_Indirect
)
3189 -- Handle this case by introducing an unchecked conversion
3192 Unchecked_Convert_To
(Etype
(Formal
),
3193 Relocate_Node
(Actual
)));
3194 Analyze_And_Resolve
(Actual
, Etype
(Formal
));
3195 Next_Actual
(Actual
);
3196 Next_Formal
(Formal
);
3199 if Debug_Flag_E
then
3200 Write_Str
(" type checking fails in call ");
3201 Write_Int
(Int
(N
));
3202 Write_Str
(" with formal ");
3203 Write_Int
(Int
(Formal
));
3204 Write_Str
(" in subprogram ");
3205 Write_Int
(Int
(Nam
));
3209 -- Comment needed on the following test???
3211 if Report
and not Is_Indexed
and not Is_Indirect
then
3213 -- Ada 2005 (AI-251): Complete the error notification
3214 -- to help new Ada 2005 users.
3216 if Is_Class_Wide_Type
(Etype
(Formal
))
3217 and then Is_Interface
(Etype
(Etype
(Formal
)))
3218 and then not Interface_Present_In_Ancestor
3219 (Typ
=> Etype
(Actual
),
3220 Iface
=> Etype
(Etype
(Formal
)))
3223 ("(Ada 2005) does not implement interface }",
3224 Actual
, Etype
(Etype
(Formal
)));
3227 Wrong_Type
(Actual
, Etype
(Formal
));
3229 if Nkind
(Actual
) = N_Op_Eq
3230 and then Nkind
(Left_Opnd
(Actual
)) = N_Identifier
3232 Formal
:= First_Formal
(Nam
);
3233 while Present
(Formal
) loop
3234 if Chars
(Left_Opnd
(Actual
)) = Chars
(Formal
) then
3235 Error_Msg_N
-- CODEFIX
3236 ("possible misspelling of `='>`!", Actual
);
3240 Next_Formal
(Formal
);
3244 if All_Errors_Mode
then
3245 Error_Msg_Sloc
:= Sloc
(Nam
);
3247 if Etype
(Formal
) = Any_Type
then
3249 ("there is no legal actual parameter", Actual
);
3252 if Is_Overloadable
(Nam
)
3253 and then Present
(Alias
(Nam
))
3254 and then not Comes_From_Source
(Nam
)
3257 ("\\ =='> in call to inherited operation & #!",
3260 elsif Ekind
(Nam
) = E_Subprogram_Type
then
3262 Access_To_Subprogram_Typ
:
3263 constant Entity_Id
:=
3265 (Associated_Node_For_Itype
(Nam
));
3268 ("\\ =='> in call to dereference of &#!",
3269 Actual
, Access_To_Subprogram_Typ
);
3274 ("\\ =='> in call to &#!", Actual
, Nam
);
3284 -- Normalize_Actuals has verified that a default value exists
3285 -- for this formal. Current actual names a subsequent formal.
3287 Next_Formal
(Formal
);
3291 -- On exit, all actuals match
3293 Indicate_Name_And_Type
;
3295 end Analyze_One_Call
;
3297 ---------------------------
3298 -- Analyze_Operator_Call --
3299 ---------------------------
3301 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
) is
3302 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
3303 Act1
: constant Node_Id
:= First_Actual
(N
);
3304 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
3307 -- Binary operator case
3309 if Present
(Act2
) then
3311 -- If more than two operands, then not binary operator after all
3313 if Present
(Next_Actual
(Act2
)) then
3317 -- Otherwise action depends on operator
3327 Find_Arithmetic_Types
(Act1
, Act2
, Op_Id
, N
);
3332 Find_Boolean_Types
(Act1
, Act2
, Op_Id
, N
);
3338 Find_Comparison_Types
(Act1
, Act2
, Op_Id
, N
);
3342 Find_Equality_Types
(Act1
, Act2
, Op_Id
, N
);
3344 when Name_Op_Concat
=>
3345 Find_Concatenation_Types
(Act1
, Act2
, Op_Id
, N
);
3347 -- Is this when others, or should it be an abort???
3353 -- Unary operator case
3357 when Name_Op_Subtract |
3360 Find_Unary_Types
(Act1
, Op_Id
, N
);
3363 Find_Negation_Types
(Act1
, Op_Id
, N
);
3365 -- Is this when others correct, or should it be an abort???
3371 end Analyze_Operator_Call
;
3373 -------------------------------------------
3374 -- Analyze_Overloaded_Selected_Component --
3375 -------------------------------------------
3377 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
) is
3378 Nam
: constant Node_Id
:= Prefix
(N
);
3379 Sel
: constant Node_Id
:= Selector_Name
(N
);
3386 Set_Etype
(Sel
, Any_Type
);
3388 Get_First_Interp
(Nam
, I
, It
);
3389 while Present
(It
.Typ
) loop
3390 if Is_Access_Type
(It
.Typ
) then
3391 T
:= Designated_Type
(It
.Typ
);
3392 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
3397 -- Locate the component. For a private prefix the selector can denote
3400 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
3402 -- If the prefix is a class-wide type, the visible components are
3403 -- those of the base type.
3405 if Is_Class_Wide_Type
(T
) then
3409 Comp
:= First_Entity
(T
);
3410 while Present
(Comp
) loop
3411 if Chars
(Comp
) = Chars
(Sel
)
3412 and then Is_Visible_Component
(Comp
)
3415 -- AI05-105: if the context is an object renaming with
3416 -- an anonymous access type, the expected type of the
3417 -- object must be anonymous. This is a name resolution rule.
3419 if Nkind
(Parent
(N
)) /= N_Object_Renaming_Declaration
3420 or else No
(Access_Definition
(Parent
(N
)))
3421 or else Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Type
3423 Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Subprogram_Type
3425 Set_Entity
(Sel
, Comp
);
3426 Set_Etype
(Sel
, Etype
(Comp
));
3427 Add_One_Interp
(N
, Etype
(Comp
), Etype
(Comp
));
3428 Check_Implicit_Dereference
(N
, Etype
(Comp
));
3430 -- This also specifies a candidate to resolve the name.
3431 -- Further overloading will be resolved from context.
3432 -- The selector name itself does not carry overloading
3435 Set_Etype
(Nam
, It
.Typ
);
3438 -- Named access type in the context of a renaming
3439 -- declaration with an access definition. Remove
3440 -- inapplicable candidate.
3449 elsif Is_Concurrent_Type
(T
) then
3450 Comp
:= First_Entity
(T
);
3451 while Present
(Comp
)
3452 and then Comp
/= First_Private_Entity
(T
)
3454 if Chars
(Comp
) = Chars
(Sel
) then
3455 if Is_Overloadable
(Comp
) then
3456 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
3458 Set_Entity_With_Checks
(Sel
, Comp
);
3459 Generate_Reference
(Comp
, Sel
);
3462 Set_Etype
(Sel
, Etype
(Comp
));
3463 Set_Etype
(N
, Etype
(Comp
));
3464 Set_Etype
(Nam
, It
.Typ
);
3466 -- For access type case, introduce explicit dereference for
3467 -- more uniform treatment of entry calls. Do this only once
3468 -- if several interpretations yield an access type.
3470 if Is_Access_Type
(Etype
(Nam
))
3471 and then Nkind
(Nam
) /= N_Explicit_Dereference
3473 Insert_Explicit_Dereference
(Nam
);
3475 (Warn_On_Dereference
, "?d?implicit dereference", N
);
3482 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
3485 Get_Next_Interp
(I
, It
);
3488 if Etype
(N
) = Any_Type
3489 and then not Try_Object_Operation
(N
)
3491 Error_Msg_NE
("undefined selector& for overloaded prefix", N
, Sel
);
3492 Set_Entity
(Sel
, Any_Id
);
3493 Set_Etype
(Sel
, Any_Type
);
3495 end Analyze_Overloaded_Selected_Component
;
3497 ----------------------------------
3498 -- Analyze_Qualified_Expression --
3499 ----------------------------------
3501 procedure Analyze_Qualified_Expression
(N
: Node_Id
) is
3502 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
3503 Expr
: constant Node_Id
:= Expression
(N
);
3509 Analyze_Expression
(Expr
);
3511 Set_Etype
(N
, Any_Type
);
3516 if T
= Any_Type
then
3520 Check_Fully_Declared
(T
, N
);
3522 -- If expected type is class-wide, check for exact match before
3523 -- expansion, because if the expression is a dispatching call it
3524 -- may be rewritten as explicit dereference with class-wide result.
3525 -- If expression is overloaded, retain only interpretations that
3526 -- will yield exact matches.
3528 if Is_Class_Wide_Type
(T
) then
3529 if not Is_Overloaded
(Expr
) then
3530 if Base_Type
(Etype
(Expr
)) /= Base_Type
(T
) then
3531 if Nkind
(Expr
) = N_Aggregate
then
3532 Error_Msg_N
("type of aggregate cannot be class-wide", Expr
);
3534 Wrong_Type
(Expr
, T
);
3539 Get_First_Interp
(Expr
, I
, It
);
3541 while Present
(It
.Nam
) loop
3542 if Base_Type
(It
.Typ
) /= Base_Type
(T
) then
3546 Get_Next_Interp
(I
, It
);
3552 end Analyze_Qualified_Expression
;
3554 -----------------------------------
3555 -- Analyze_Quantified_Expression --
3556 -----------------------------------
3558 procedure Analyze_Quantified_Expression
(N
: Node_Id
) is
3559 function Is_Empty_Range
(Typ
: Entity_Id
) return Boolean;
3560 -- If the iterator is part of a quantified expression, and the range is
3561 -- known to be statically empty, emit a warning and replace expression
3562 -- with its static value. Returns True if the replacement occurs.
3564 function No_Else_Or_Trivial_True
(If_Expr
: Node_Id
) return Boolean;
3565 -- Determine whether if expression If_Expr lacks an else part or if it
3566 -- has one, it evaluates to True.
3568 --------------------
3569 -- Is_Empty_Range --
3570 --------------------
3572 function Is_Empty_Range
(Typ
: Entity_Id
) return Boolean is
3573 Loc
: constant Source_Ptr
:= Sloc
(N
);
3576 if Is_Array_Type
(Typ
)
3577 and then Compile_Time_Known_Bounds
(Typ
)
3579 (Expr_Value
(Type_Low_Bound
(Etype
(First_Index
(Typ
)))) >
3580 Expr_Value
(Type_High_Bound
(Etype
(First_Index
(Typ
)))))
3582 Preanalyze_And_Resolve
(Condition
(N
), Standard_Boolean
);
3584 if All_Present
(N
) then
3586 ("??quantified expression with ALL "
3587 & "over a null range has value True", N
);
3588 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
3592 ("??quantified expression with SOME "
3593 & "over a null range has value False", N
);
3594 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
3605 -----------------------------
3606 -- No_Else_Or_Trivial_True --
3607 -----------------------------
3609 function No_Else_Or_Trivial_True
(If_Expr
: Node_Id
) return Boolean is
3610 Else_Expr
: constant Node_Id
:=
3611 Next
(Next
(First
(Expressions
(If_Expr
))));
3615 or else (Compile_Time_Known_Value
(Else_Expr
)
3616 and then Is_True
(Expr_Value
(Else_Expr
)));
3617 end No_Else_Or_Trivial_True
;
3621 Cond
: constant Node_Id
:= Condition
(N
);
3622 Loop_Id
: Entity_Id
;
3623 QE_Scop
: Entity_Id
;
3625 -- Start of processing for Analyze_Quantified_Expression
3628 Check_SPARK_05_Restriction
("quantified expression is not allowed", N
);
3630 -- Create a scope to emulate the loop-like behavior of the quantified
3631 -- expression. The scope is needed to provide proper visibility of the
3634 QE_Scop
:= New_Internal_Entity
(E_Loop
, Current_Scope
, Sloc
(N
), 'L');
3635 Set_Etype
(QE_Scop
, Standard_Void_Type
);
3636 Set_Scope
(QE_Scop
, Current_Scope
);
3637 Set_Parent
(QE_Scop
, N
);
3639 Push_Scope
(QE_Scop
);
3641 -- All constituents are preanalyzed and resolved to avoid untimely
3642 -- generation of various temporaries and types. Full analysis and
3643 -- expansion is carried out when the quantified expression is
3644 -- transformed into an expression with actions.
3646 if Present
(Iterator_Specification
(N
)) then
3647 Preanalyze
(Iterator_Specification
(N
));
3649 -- Do not proceed with the analysis when the range of iteration is
3650 -- empty. The appropriate error is issued by Is_Empty_Range.
3652 if Is_Entity_Name
(Name
(Iterator_Specification
(N
)))
3653 and then Is_Empty_Range
(Etype
(Name
(Iterator_Specification
(N
))))
3658 else pragma Assert
(Present
(Loop_Parameter_Specification
(N
)));
3660 Loop_Par
: constant Node_Id
:= Loop_Parameter_Specification
(N
);
3663 Preanalyze
(Loop_Par
);
3665 if Nkind
(Discrete_Subtype_Definition
(Loop_Par
)) = N_Function_Call
3666 and then Parent
(Loop_Par
) /= N
3668 -- The parser cannot distinguish between a loop specification
3669 -- and an iterator specification. If after pre-analysis the
3670 -- proper form has been recognized, rewrite the expression to
3671 -- reflect the right kind. This is needed for proper ASIS
3672 -- navigation. If expansion is enabled, the transformation is
3673 -- performed when the expression is rewritten as a loop.
3675 Set_Iterator_Specification
(N
,
3676 New_Copy_Tree
(Iterator_Specification
(Parent
(Loop_Par
))));
3678 Set_Defining_Identifier
(Iterator_Specification
(N
),
3679 Relocate_Node
(Defining_Identifier
(Loop_Par
)));
3680 Set_Name
(Iterator_Specification
(N
),
3681 Relocate_Node
(Discrete_Subtype_Definition
(Loop_Par
)));
3682 Set_Comes_From_Source
(Iterator_Specification
(N
),
3683 Comes_From_Source
(Loop_Parameter_Specification
(N
)));
3684 Set_Loop_Parameter_Specification
(N
, Empty
);
3689 Preanalyze_And_Resolve
(Cond
, Standard_Boolean
);
3692 Set_Etype
(N
, Standard_Boolean
);
3694 -- Verify that the loop variable is used within the condition of the
3695 -- quantified expression.
3697 if Present
(Iterator_Specification
(N
)) then
3698 Loop_Id
:= Defining_Identifier
(Iterator_Specification
(N
));
3700 Loop_Id
:= Defining_Identifier
(Loop_Parameter_Specification
(N
));
3703 if Warn_On_Suspicious_Contract
3704 and then not Referenced
(Loop_Id
, Cond
)
3706 Error_Msg_N
("?T?unused variable &", Loop_Id
);
3709 -- Diagnose a possible misuse of the SOME existential quantifier. When
3710 -- we have a quantified expression of the form:
3712 -- for some X => (if P then Q [else True])
3714 -- any value for X that makes P False results in the if expression being
3715 -- trivially True, and so also results in the the quantified expression
3716 -- being trivially True.
3718 if Warn_On_Suspicious_Contract
3719 and then not All_Present
(N
)
3720 and then Nkind
(Cond
) = N_If_Expression
3721 and then No_Else_Or_Trivial_True
(Cond
)
3723 Error_Msg_N
("?T?suspicious expression", N
);
3724 Error_Msg_N
("\\did you mean (for all X ='> (if P then Q))", N
);
3725 Error_Msg_N
("\\or (for some X ='> P and then Q) instead'?", N
);
3727 end Analyze_Quantified_Expression
;
3733 procedure Analyze_Range
(N
: Node_Id
) is
3734 L
: constant Node_Id
:= Low_Bound
(N
);
3735 H
: constant Node_Id
:= High_Bound
(N
);
3736 I1
, I2
: Interp_Index
;
3739 procedure Check_Common_Type
(T1
, T2
: Entity_Id
);
3740 -- Verify the compatibility of two types, and choose the
3741 -- non universal one if the other is universal.
3743 procedure Check_High_Bound
(T
: Entity_Id
);
3744 -- Test one interpretation of the low bound against all those
3745 -- of the high bound.
3747 procedure Check_Universal_Expression
(N
: Node_Id
);
3748 -- In Ada 83, reject bounds of a universal range that are not literals
3751 -----------------------
3752 -- Check_Common_Type --
3753 -----------------------
3755 procedure Check_Common_Type
(T1
, T2
: Entity_Id
) is
3757 if Covers
(T1
=> T1
, T2
=> T2
)
3759 Covers
(T1
=> T2
, T2
=> T1
)
3761 if T1
= Universal_Integer
3762 or else T1
= Universal_Real
3763 or else T1
= Any_Character
3765 Add_One_Interp
(N
, Base_Type
(T2
), Base_Type
(T2
));
3768 Add_One_Interp
(N
, T1
, T1
);
3771 Add_One_Interp
(N
, Base_Type
(T1
), Base_Type
(T1
));
3774 end Check_Common_Type
;
3776 ----------------------
3777 -- Check_High_Bound --
3778 ----------------------
3780 procedure Check_High_Bound
(T
: Entity_Id
) is
3782 if not Is_Overloaded
(H
) then
3783 Check_Common_Type
(T
, Etype
(H
));
3785 Get_First_Interp
(H
, I2
, It2
);
3786 while Present
(It2
.Typ
) loop
3787 Check_Common_Type
(T
, It2
.Typ
);
3788 Get_Next_Interp
(I2
, It2
);
3791 end Check_High_Bound
;
3793 -----------------------------
3794 -- Is_Universal_Expression --
3795 -----------------------------
3797 procedure Check_Universal_Expression
(N
: Node_Id
) is
3799 if Etype
(N
) = Universal_Integer
3800 and then Nkind
(N
) /= N_Integer_Literal
3801 and then not Is_Entity_Name
(N
)
3802 and then Nkind
(N
) /= N_Attribute_Reference
3804 Error_Msg_N
("illegal bound in discrete range", N
);
3806 end Check_Universal_Expression
;
3808 -- Start of processing for Analyze_Range
3811 Set_Etype
(N
, Any_Type
);
3812 Analyze_Expression
(L
);
3813 Analyze_Expression
(H
);
3815 if Etype
(L
) = Any_Type
or else Etype
(H
) = Any_Type
then
3819 if not Is_Overloaded
(L
) then
3820 Check_High_Bound
(Etype
(L
));
3822 Get_First_Interp
(L
, I1
, It1
);
3823 while Present
(It1
.Typ
) loop
3824 Check_High_Bound
(It1
.Typ
);
3825 Get_Next_Interp
(I1
, It1
);
3829 -- If result is Any_Type, then we did not find a compatible pair
3831 if Etype
(N
) = Any_Type
then
3832 Error_Msg_N
("incompatible types in range ", N
);
3836 if Ada_Version
= Ada_83
3838 (Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
3839 or else Nkind
(Parent
(N
)) = N_Constrained_Array_Definition
)
3841 Check_Universal_Expression
(L
);
3842 Check_Universal_Expression
(H
);
3845 Check_Function_Writable_Actuals
(N
);
3848 -----------------------
3849 -- Analyze_Reference --
3850 -----------------------
3852 procedure Analyze_Reference
(N
: Node_Id
) is
3853 P
: constant Node_Id
:= Prefix
(N
);
3856 Acc_Type
: Entity_Id
;
3861 -- An interesting error check, if we take the 'Reference of an object
3862 -- for which a pragma Atomic or Volatile has been given, and the type
3863 -- of the object is not Atomic or Volatile, then we are in trouble. The
3864 -- problem is that no trace of the atomic/volatile status will remain
3865 -- for the backend to respect when it deals with the resulting pointer,
3866 -- since the pointer type will not be marked atomic (it is a pointer to
3867 -- the base type of the object).
3869 -- It is not clear if that can ever occur, but in case it does, we will
3870 -- generate an error message. Not clear if this message can ever be
3871 -- generated, and pretty clear that it represents a bug if it is, still
3872 -- seems worth checking, except in CodePeer mode where we do not really
3873 -- care and don't want to bother the user.
3877 if Is_Entity_Name
(P
)
3878 and then Is_Object_Reference
(P
)
3879 and then not CodePeer_Mode
3884 if (Has_Atomic_Components
(E
)
3885 and then not Has_Atomic_Components
(T
))
3887 (Has_Volatile_Components
(E
)
3888 and then not Has_Volatile_Components
(T
))
3889 or else (Is_Atomic
(E
) and then not Is_Atomic
(T
))
3890 or else (Is_Volatile
(E
) and then not Is_Volatile
(T
))
3892 Error_Msg_N
("cannot take reference to Atomic/Volatile object", N
);
3896 -- Carry on with normal processing
3898 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
3899 Set_Etype
(Acc_Type
, Acc_Type
);
3900 Set_Directly_Designated_Type
(Acc_Type
, Etype
(P
));
3901 Set_Etype
(N
, Acc_Type
);
3902 end Analyze_Reference
;
3904 --------------------------------
3905 -- Analyze_Selected_Component --
3906 --------------------------------
3908 -- Prefix is a record type or a task or protected type. In the latter case,
3909 -- the selector must denote a visible entry.
3911 procedure Analyze_Selected_Component
(N
: Node_Id
) is
3912 Name
: constant Node_Id
:= Prefix
(N
);
3913 Sel
: constant Node_Id
:= Selector_Name
(N
);
3916 Has_Candidate
: Boolean := False;
3919 Pent
: Entity_Id
:= Empty
;
3920 Prefix_Type
: Entity_Id
;
3922 Type_To_Use
: Entity_Id
;
3923 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
3924 -- a class-wide type, we use its root type, whose components are
3925 -- present in the class-wide type.
3927 Is_Single_Concurrent_Object
: Boolean;
3928 -- Set True if the prefix is a single task or a single protected object
3930 procedure Find_Component_In_Instance
(Rec
: Entity_Id
);
3931 -- In an instance, a component of a private extension may not be visible
3932 -- while it was visible in the generic. Search candidate scope for a
3933 -- component with the proper identifier. This is only done if all other
3934 -- searches have failed. If a match is found, the Etype of both N and
3935 -- Sel are set from this component, and the entity of Sel is set to
3936 -- reference this component. If no match is found, Entity (Sel) remains
3939 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean;
3940 -- It is known that the parent of N denotes a subprogram call. Comp
3941 -- is an overloadable component of the concurrent type of the prefix.
3942 -- Determine whether all formals of the parent of N and Comp are mode
3943 -- conformant. If the parent node is not analyzed yet it may be an
3944 -- indexed component rather than a function call.
3946 --------------------------------
3947 -- Find_Component_In_Instance --
3948 --------------------------------
3950 procedure Find_Component_In_Instance
(Rec
: Entity_Id
) is
3954 Comp
:= First_Component
(Rec
);
3955 while Present
(Comp
) loop
3956 if Chars
(Comp
) = Chars
(Sel
) then
3957 Set_Entity_With_Checks
(Sel
, Comp
);
3958 Set_Etype
(Sel
, Etype
(Comp
));
3959 Set_Etype
(N
, Etype
(Comp
));
3963 Next_Component
(Comp
);
3966 -- If we fall through, no match, so no changes made
3969 end Find_Component_In_Instance
;
3971 ------------------------------
3972 -- Has_Mode_Conformant_Spec --
3973 ------------------------------
3975 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean is
3976 Comp_Param
: Entity_Id
;
3978 Param_Typ
: Entity_Id
;
3981 Comp_Param
:= First_Formal
(Comp
);
3983 if Nkind
(Parent
(N
)) = N_Indexed_Component
then
3984 Param
:= First
(Expressions
(Parent
(N
)));
3986 Param
:= First
(Parameter_Associations
(Parent
(N
)));
3989 while Present
(Comp_Param
)
3990 and then Present
(Param
)
3992 Param_Typ
:= Find_Parameter_Type
(Param
);
3994 if Present
(Param_Typ
)
3996 not Conforming_Types
3997 (Etype
(Comp_Param
), Param_Typ
, Mode_Conformant
)
4002 Next_Formal
(Comp_Param
);
4006 -- One of the specs has additional formals; there is no match, unless
4007 -- this may be an indexing of a parameterless call.
4009 -- Note that when expansion is disabled, the corresponding record
4010 -- type of synchronized types is not constructed, so that there is
4011 -- no point is attempting an interpretation as a prefixed call, as
4012 -- this is bound to fail because the primitive operations will not
4013 -- be properly located.
4015 if Present
(Comp_Param
) or else Present
(Param
) then
4016 if Needs_No_Actuals
(Comp
)
4017 and then Is_Array_Type
(Etype
(Comp
))
4018 and then not Expander_Active
4027 end Has_Mode_Conformant_Spec
;
4029 -- Start of processing for Analyze_Selected_Component
4032 Set_Etype
(N
, Any_Type
);
4034 if Is_Overloaded
(Name
) then
4035 Analyze_Overloaded_Selected_Component
(N
);
4038 elsif Etype
(Name
) = Any_Type
then
4039 Set_Entity
(Sel
, Any_Id
);
4040 Set_Etype
(Sel
, Any_Type
);
4044 Prefix_Type
:= Etype
(Name
);
4047 if Is_Access_Type
(Prefix_Type
) then
4049 -- A RACW object can never be used as prefix of a selected component
4050 -- since that means it is dereferenced without being a controlling
4051 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
4052 -- reporting an error, we must check whether this is actually a
4053 -- dispatching call in prefix form.
4055 if Is_Remote_Access_To_Class_Wide_Type
(Prefix_Type
)
4056 and then Comes_From_Source
(N
)
4058 if Try_Object_Operation
(N
) then
4062 ("invalid dereference of a remote access-to-class-wide value",
4066 -- Normal case of selected component applied to access type
4069 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4071 if Is_Entity_Name
(Name
) then
4072 Pent
:= Entity
(Name
);
4073 elsif Nkind
(Name
) = N_Selected_Component
4074 and then Is_Entity_Name
(Selector_Name
(Name
))
4076 Pent
:= Entity
(Selector_Name
(Name
));
4079 Prefix_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, Name
);
4082 -- If we have an explicit dereference of a remote access-to-class-wide
4083 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
4084 -- have to check for the case of a prefix that is a controlling operand
4085 -- of a prefixed dispatching call, as the dereference is legal in that
4086 -- case. Normally this condition is checked in Validate_Remote_Access_
4087 -- To_Class_Wide_Type, but we have to defer the checking for selected
4088 -- component prefixes because of the prefixed dispatching call case.
4089 -- Note that implicit dereferences are checked for this just above.
4091 elsif Nkind
(Name
) = N_Explicit_Dereference
4092 and then Is_Remote_Access_To_Class_Wide_Type
(Etype
(Prefix
(Name
)))
4093 and then Comes_From_Source
(N
)
4095 if Try_Object_Operation
(N
) then
4099 ("invalid dereference of a remote access-to-class-wide value",
4104 -- (Ada 2005): if the prefix is the limited view of a type, and
4105 -- the context already includes the full view, use the full view
4106 -- in what follows, either to retrieve a component of to find
4107 -- a primitive operation. If the prefix is an explicit dereference,
4108 -- set the type of the prefix to reflect this transformation.
4109 -- If the non-limited view is itself an incomplete type, get the
4110 -- full view if available.
4112 if Is_Incomplete_Type
(Prefix_Type
)
4113 and then From_Limited_With
(Prefix_Type
)
4114 and then Present
(Non_Limited_View
(Prefix_Type
))
4116 Prefix_Type
:= Get_Full_View
(Non_Limited_View
(Prefix_Type
));
4118 if Nkind
(N
) = N_Explicit_Dereference
then
4119 Set_Etype
(Prefix
(N
), Prefix_Type
);
4122 elsif Ekind
(Prefix_Type
) = E_Class_Wide_Type
4123 and then From_Limited_With
(Prefix_Type
)
4124 and then Present
(Non_Limited_View
(Etype
(Prefix_Type
)))
4127 Class_Wide_Type
(Non_Limited_View
(Etype
(Prefix_Type
)));
4129 if Nkind
(N
) = N_Explicit_Dereference
then
4130 Set_Etype
(Prefix
(N
), Prefix_Type
);
4134 if Ekind
(Prefix_Type
) = E_Private_Subtype
then
4135 Prefix_Type
:= Base_Type
(Prefix_Type
);
4138 Type_To_Use
:= Prefix_Type
;
4140 -- For class-wide types, use the entity list of the root type. This
4141 -- indirection is specially important for private extensions because
4142 -- only the root type get switched (not the class-wide type).
4144 if Is_Class_Wide_Type
(Prefix_Type
) then
4145 Type_To_Use
:= Root_Type
(Prefix_Type
);
4148 -- If the prefix is a single concurrent object, use its name in error
4149 -- messages, rather than that of its anonymous type.
4151 Is_Single_Concurrent_Object
:=
4152 Is_Concurrent_Type
(Prefix_Type
)
4153 and then Is_Internal_Name
(Chars
(Prefix_Type
))
4154 and then not Is_Derived_Type
(Prefix_Type
)
4155 and then Is_Entity_Name
(Name
);
4157 Comp
:= First_Entity
(Type_To_Use
);
4159 -- If the selector has an original discriminant, the node appears in
4160 -- an instance. Replace the discriminant with the corresponding one
4161 -- in the current discriminated type. For nested generics, this must
4162 -- be done transitively, so note the new original discriminant.
4164 if Nkind
(Sel
) = N_Identifier
4165 and then In_Instance
4166 and then Present
(Original_Discriminant
(Sel
))
4168 Comp
:= Find_Corresponding_Discriminant
(Sel
, Prefix_Type
);
4170 -- Mark entity before rewriting, for completeness and because
4171 -- subsequent semantic checks might examine the original node.
4173 Set_Entity
(Sel
, Comp
);
4174 Rewrite
(Selector_Name
(N
), New_Occurrence_Of
(Comp
, Sloc
(N
)));
4175 Set_Original_Discriminant
(Selector_Name
(N
), Comp
);
4176 Set_Etype
(N
, Etype
(Comp
));
4177 Check_Implicit_Dereference
(N
, Etype
(Comp
));
4179 if Is_Access_Type
(Etype
(Name
)) then
4180 Insert_Explicit_Dereference
(Name
);
4181 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4184 elsif Is_Record_Type
(Prefix_Type
) then
4186 -- Find component with given name. In an instance, if the node is
4187 -- known as a prefixed call, do not examine components whose
4188 -- visibility may be accidental.
4190 while Present
(Comp
) and then not Is_Prefixed_Call
(N
) loop
4191 if Chars
(Comp
) = Chars
(Sel
)
4192 and then Is_Visible_Component
(Comp
, N
)
4194 Set_Entity_With_Checks
(Sel
, Comp
);
4195 Set_Etype
(Sel
, Etype
(Comp
));
4197 if Ekind
(Comp
) = E_Discriminant
then
4198 if Is_Unchecked_Union
(Base_Type
(Prefix_Type
)) then
4200 ("cannot reference discriminant of unchecked union",
4204 if Is_Generic_Type
(Prefix_Type
)
4206 Is_Generic_Type
(Root_Type
(Prefix_Type
))
4208 Set_Original_Discriminant
(Sel
, Comp
);
4212 -- Resolve the prefix early otherwise it is not possible to
4213 -- build the actual subtype of the component: it may need
4214 -- to duplicate this prefix and duplication is only allowed
4215 -- on fully resolved expressions.
4219 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
4220 -- subtypes in a package specification.
4223 -- limited with Pkg;
4225 -- type Acc_Inc is access Pkg.T;
4227 -- N : Natural := X.all.Comp; -- ERROR, limited view
4228 -- end Pkg; -- Comp is not visible
4230 if Nkind
(Name
) = N_Explicit_Dereference
4231 and then From_Limited_With
(Etype
(Prefix
(Name
)))
4232 and then not Is_Potentially_Use_Visible
(Etype
(Name
))
4233 and then Nkind
(Parent
(Cunit_Entity
(Current_Sem_Unit
))) =
4234 N_Package_Specification
4237 ("premature usage of incomplete}", Prefix
(Name
),
4238 Etype
(Prefix
(Name
)));
4241 -- We never need an actual subtype for the case of a selection
4242 -- for a indexed component of a non-packed array, since in
4243 -- this case gigi generates all the checks and can find the
4244 -- necessary bounds information.
4246 -- We also do not need an actual subtype for the case of a
4247 -- first, last, length, or range attribute applied to a
4248 -- non-packed array, since gigi can again get the bounds in
4249 -- these cases (gigi cannot handle the packed case, since it
4250 -- has the bounds of the packed array type, not the original
4251 -- bounds of the type). However, if the prefix is itself a
4252 -- selected component, as in a.b.c (i), gigi may regard a.b.c
4253 -- as a dynamic-sized temporary, so we do generate an actual
4254 -- subtype for this case.
4256 Parent_N
:= Parent
(N
);
4258 if not Is_Packed
(Etype
(Comp
))
4260 ((Nkind
(Parent_N
) = N_Indexed_Component
4261 and then Nkind
(Name
) /= N_Selected_Component
)
4263 (Nkind
(Parent_N
) = N_Attribute_Reference
4265 Nam_In
(Attribute_Name
(Parent_N
), Name_First
,
4270 Set_Etype
(N
, Etype
(Comp
));
4272 -- If full analysis is not enabled, we do not generate an
4273 -- actual subtype, because in the absence of expansion
4274 -- reference to a formal of a protected type, for example,
4275 -- will not be properly transformed, and will lead to
4276 -- out-of-scope references in gigi.
4278 -- In all other cases, we currently build an actual subtype.
4279 -- It seems likely that many of these cases can be avoided,
4280 -- but right now, the front end makes direct references to the
4281 -- bounds (e.g. in generating a length check), and if we do
4282 -- not make an actual subtype, we end up getting a direct
4283 -- reference to a discriminant, which will not do.
4285 elsif Full_Analysis
then
4287 Build_Actual_Subtype_Of_Component
(Etype
(Comp
), N
);
4288 Insert_Action
(N
, Act_Decl
);
4290 if No
(Act_Decl
) then
4291 Set_Etype
(N
, Etype
(Comp
));
4294 -- Component type depends on discriminants. Enter the
4295 -- main attributes of the subtype.
4298 Subt
: constant Entity_Id
:=
4299 Defining_Identifier
(Act_Decl
);
4302 Set_Etype
(Subt
, Base_Type
(Etype
(Comp
)));
4303 Set_Ekind
(Subt
, Ekind
(Etype
(Comp
)));
4304 Set_Etype
(N
, Subt
);
4308 -- If Full_Analysis not enabled, just set the Etype
4311 Set_Etype
(N
, Etype
(Comp
));
4314 Check_Implicit_Dereference
(N
, Etype
(N
));
4318 -- If the prefix is a private extension, check only the visible
4319 -- components of the partial view. This must include the tag,
4320 -- which can appear in expanded code in a tag check.
4322 if Ekind
(Type_To_Use
) = E_Record_Type_With_Private
4323 and then Chars
(Selector_Name
(N
)) /= Name_uTag
4325 exit when Comp
= Last_Entity
(Type_To_Use
);
4331 -- Ada 2005 (AI-252): The selected component can be interpreted as
4332 -- a prefixed view of a subprogram. Depending on the context, this is
4333 -- either a name that can appear in a renaming declaration, or part
4334 -- of an enclosing call given in prefix form.
4336 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
4337 -- selected component should resolve to a name.
4339 if Ada_Version
>= Ada_2005
4340 and then Is_Tagged_Type
(Prefix_Type
)
4341 and then not Is_Concurrent_Type
(Prefix_Type
)
4343 if Nkind
(Parent
(N
)) = N_Generic_Association
4344 or else Nkind
(Parent
(N
)) = N_Requeue_Statement
4345 or else Nkind
(Parent
(N
)) = N_Subprogram_Renaming_Declaration
4347 if Find_Primitive_Operation
(N
) then
4351 elsif Try_Object_Operation
(N
) then
4355 -- If the transformation fails, it will be necessary to redo the
4356 -- analysis with all errors enabled, to indicate candidate
4357 -- interpretations and reasons for each failure ???
4361 elsif Is_Private_Type
(Prefix_Type
) then
4363 -- Allow access only to discriminants of the type. If the type has
4364 -- no full view, gigi uses the parent type for the components, so we
4365 -- do the same here.
4367 if No
(Full_View
(Prefix_Type
)) then
4368 Type_To_Use
:= Root_Type
(Base_Type
(Prefix_Type
));
4369 Comp
:= First_Entity
(Type_To_Use
);
4372 while Present
(Comp
) loop
4373 if Chars
(Comp
) = Chars
(Sel
) then
4374 if Ekind
(Comp
) = E_Discriminant
then
4375 Set_Entity_With_Checks
(Sel
, Comp
);
4376 Generate_Reference
(Comp
, Sel
);
4378 Set_Etype
(Sel
, Etype
(Comp
));
4379 Set_Etype
(N
, Etype
(Comp
));
4380 Check_Implicit_Dereference
(N
, Etype
(N
));
4382 if Is_Generic_Type
(Prefix_Type
)
4383 or else Is_Generic_Type
(Root_Type
(Prefix_Type
))
4385 Set_Original_Discriminant
(Sel
, Comp
);
4388 -- Before declaring an error, check whether this is tagged
4389 -- private type and a call to a primitive operation.
4391 elsif Ada_Version
>= Ada_2005
4392 and then Is_Tagged_Type
(Prefix_Type
)
4393 and then Try_Object_Operation
(N
)
4398 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4399 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
4400 Set_Entity
(Sel
, Any_Id
);
4401 Set_Etype
(N
, Any_Type
);
4410 elsif Is_Concurrent_Type
(Prefix_Type
) then
4412 -- Find visible operation with given name. For a protected type,
4413 -- the possible candidates are discriminants, entries or protected
4414 -- procedures. For a task type, the set can only include entries or
4415 -- discriminants if the task type is not an enclosing scope. If it
4416 -- is an enclosing scope (e.g. in an inner task) then all entities
4417 -- are visible, but the prefix must denote the enclosing scope, i.e.
4418 -- can only be a direct name or an expanded name.
4420 Set_Etype
(Sel
, Any_Type
);
4421 In_Scope
:= In_Open_Scopes
(Prefix_Type
);
4423 while Present
(Comp
) loop
4424 if Chars
(Comp
) = Chars
(Sel
) then
4425 if Is_Overloadable
(Comp
) then
4426 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
4428 -- If the prefix is tagged, the correct interpretation may
4429 -- lie in the primitive or class-wide operations of the
4430 -- type. Perform a simple conformance check to determine
4431 -- whether Try_Object_Operation should be invoked even if
4432 -- a visible entity is found.
4434 if Is_Tagged_Type
(Prefix_Type
)
4436 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
4438 N_Indexed_Component
)
4439 and then Has_Mode_Conformant_Spec
(Comp
)
4441 Has_Candidate
:= True;
4444 -- Note: a selected component may not denote a component of a
4445 -- protected type (4.1.3(7)).
4447 elsif Ekind_In
(Comp
, E_Discriminant
, E_Entry_Family
)
4449 and then not Is_Protected_Type
(Prefix_Type
)
4450 and then Is_Entity_Name
(Name
))
4452 Set_Entity_With_Checks
(Sel
, Comp
);
4453 Generate_Reference
(Comp
, Sel
);
4455 -- The selector is not overloadable, so we have a candidate
4458 Has_Candidate
:= True;
4464 Set_Etype
(Sel
, Etype
(Comp
));
4465 Set_Etype
(N
, Etype
(Comp
));
4467 if Ekind
(Comp
) = E_Discriminant
then
4468 Set_Original_Discriminant
(Sel
, Comp
);
4471 -- For access type case, introduce explicit dereference for
4472 -- more uniform treatment of entry calls.
4474 if Is_Access_Type
(Etype
(Name
)) then
4475 Insert_Explicit_Dereference
(Name
);
4477 (Warn_On_Dereference
, "?d?implicit dereference", N
);
4483 exit when not In_Scope
4485 Comp
= First_Private_Entity
(Base_Type
(Prefix_Type
));
4488 -- If there is no visible entity with the given name or none of the
4489 -- visible entities are plausible interpretations, check whether
4490 -- there is some other primitive operation with that name.
4492 if Ada_Version
>= Ada_2005
4493 and then Is_Tagged_Type
(Prefix_Type
)
4495 if (Etype
(N
) = Any_Type
4496 or else not Has_Candidate
)
4497 and then Try_Object_Operation
(N
)
4501 -- If the context is not syntactically a procedure call, it
4502 -- may be a call to a primitive function declared outside of
4503 -- the synchronized type.
4505 -- If the context is a procedure call, there might still be
4506 -- an overloading between an entry and a primitive procedure
4507 -- declared outside of the synchronized type, called in prefix
4508 -- notation. This is harder to disambiguate because in one case
4509 -- the controlling formal is implicit ???
4511 elsif Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
4512 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
4513 and then Try_Object_Operation
(N
)
4518 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
4519 -- entry or procedure of a tagged concurrent type we must check
4520 -- if there are class-wide subprograms covering the primitive. If
4521 -- true then Try_Object_Operation reports the error.
4524 and then Is_Concurrent_Type
(Prefix_Type
)
4525 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
4527 -- Duplicate the call. This is required to avoid problems with
4528 -- the tree transformations performed by Try_Object_Operation.
4529 -- Set properly the parent of the copied call, because it is
4530 -- about to be reanalyzed.
4534 Par
: constant Node_Id
:= New_Copy_Tree
(Parent
(N
));
4537 Set_Parent
(Par
, Parent
(Parent
(N
)));
4539 if Try_Object_Operation
4540 (Sinfo
.Name
(Par
), CW_Test_Only
=> True)
4548 if Etype
(N
) = Any_Type
and then Is_Protected_Type
(Prefix_Type
) then
4550 -- Case of a prefix of a protected type: selector might denote
4551 -- an invisible private component.
4553 Comp
:= First_Private_Entity
(Base_Type
(Prefix_Type
));
4554 while Present
(Comp
) and then Chars
(Comp
) /= Chars
(Sel
) loop
4558 if Present
(Comp
) then
4559 if Is_Single_Concurrent_Object
then
4560 Error_Msg_Node_2
:= Entity
(Name
);
4561 Error_Msg_NE
("invisible selector& for &", N
, Sel
);
4564 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4565 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
4571 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
4576 Error_Msg_NE
("invalid prefix in selected component&", N
, Sel
);
4579 -- If N still has no type, the component is not defined in the prefix
4581 if Etype
(N
) = Any_Type
then
4583 if Is_Single_Concurrent_Object
then
4584 Error_Msg_Node_2
:= Entity
(Name
);
4585 Error_Msg_NE
("no selector& for&", N
, Sel
);
4587 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
4589 -- If this is a derived formal type, the parent may have different
4590 -- visibility at this point. Try for an inherited component before
4591 -- reporting an error.
4593 elsif Is_Generic_Type
(Prefix_Type
)
4594 and then Ekind
(Prefix_Type
) = E_Record_Type_With_Private
4595 and then Prefix_Type
/= Etype
(Prefix_Type
)
4596 and then Is_Record_Type
(Etype
(Prefix_Type
))
4598 Set_Etype
(Prefix
(N
), Etype
(Prefix_Type
));
4599 Analyze_Selected_Component
(N
);
4602 -- Similarly, if this is the actual for a formal derived type, or
4603 -- a derived type thereof, the component inherited from the generic
4604 -- parent may not be visible in the actual, but the selected
4605 -- component is legal. Climb up the derivation chain of the generic
4606 -- parent type until we find the proper ancestor type.
4608 elsif In_Instance
and then Is_Tagged_Type
(Prefix_Type
) then
4610 Par
: Entity_Id
:= Prefix_Type
;
4612 -- Climb up derivation chain to generic actual subtype
4614 while not Is_Generic_Actual_Type
(Par
) loop
4615 if Ekind
(Par
) = E_Record_Type
then
4616 Par
:= Parent_Subtype
(Par
);
4619 exit when Par
= Etype
(Par
);
4624 if Present
(Par
) and then Is_Generic_Actual_Type
(Par
) then
4626 -- Now look for component in ancestor types
4628 Par
:= Generic_Parent_Type
(Declaration_Node
(Par
));
4630 Find_Component_In_Instance
(Par
);
4631 exit when Present
(Entity
(Sel
))
4632 or else Par
= Etype
(Par
);
4636 -- In ASIS mode the generic parent type may be absent. Examine
4637 -- the parent type directly for a component that may have been
4638 -- visible in a parent generic unit.
4640 elsif Is_Derived_Type
(Prefix_Type
) then
4641 Par
:= Etype
(Prefix_Type
);
4642 Find_Component_In_Instance
(Par
);
4646 -- The search above must have eventually succeeded, since the
4647 -- selected component was legal in the generic.
4649 if No
(Entity
(Sel
)) then
4650 raise Program_Error
;
4655 -- Component not found, specialize error message when appropriate
4658 if Ekind
(Prefix_Type
) = E_Record_Subtype
then
4660 -- Check whether this is a component of the base type which
4661 -- is absent from a statically constrained subtype. This will
4662 -- raise constraint error at run time, but is not a compile-
4663 -- time error. When the selector is illegal for base type as
4664 -- well fall through and generate a compilation error anyway.
4666 Comp
:= First_Component
(Base_Type
(Prefix_Type
));
4667 while Present
(Comp
) loop
4668 if Chars
(Comp
) = Chars
(Sel
)
4669 and then Is_Visible_Component
(Comp
)
4671 Set_Entity_With_Checks
(Sel
, Comp
);
4672 Generate_Reference
(Comp
, Sel
);
4673 Set_Etype
(Sel
, Etype
(Comp
));
4674 Set_Etype
(N
, Etype
(Comp
));
4676 -- Emit appropriate message. The node will be replaced
4677 -- by an appropriate raise statement.
4679 -- Note that in SPARK mode, as with all calls to apply a
4680 -- compile time constraint error, this will be made into
4681 -- an error to simplify the processing of the formal
4682 -- verification backend.
4684 Apply_Compile_Time_Constraint_Error
4685 (N
, "component not present in }??",
4686 CE_Discriminant_Check_Failed
,
4687 Ent
=> Prefix_Type
, Rep
=> False);
4689 Set_Raises_Constraint_Error
(N
);
4693 Next_Component
(Comp
);
4698 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4699 Error_Msg_NE
("no selector& for}", N
, Sel
);
4701 -- Add information in the case of an incomplete prefix
4703 if Is_Incomplete_Type
(Type_To_Use
) then
4705 Inc
: constant Entity_Id
:= First_Subtype
(Type_To_Use
);
4708 if From_Limited_With
(Scope
(Type_To_Use
)) then
4710 ("\limited view of& has no components", N
, Inc
);
4714 ("\premature usage of incomplete type&", N
, Inc
);
4716 if Nkind
(Parent
(Inc
)) =
4717 N_Incomplete_Type_Declaration
4719 -- Record location of premature use in entity so that
4720 -- a continuation message is generated when the
4721 -- completion is seen.
4723 Set_Premature_Use
(Parent
(Inc
), N
);
4729 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
4732 Set_Entity
(Sel
, Any_Id
);
4733 Set_Etype
(Sel
, Any_Type
);
4735 end Analyze_Selected_Component
;
4737 ---------------------------
4738 -- Analyze_Short_Circuit --
4739 ---------------------------
4741 procedure Analyze_Short_Circuit
(N
: Node_Id
) is
4742 L
: constant Node_Id
:= Left_Opnd
(N
);
4743 R
: constant Node_Id
:= Right_Opnd
(N
);
4748 Analyze_Expression
(L
);
4749 Analyze_Expression
(R
);
4750 Set_Etype
(N
, Any_Type
);
4752 if not Is_Overloaded
(L
) then
4753 if Root_Type
(Etype
(L
)) = Standard_Boolean
4754 and then Has_Compatible_Type
(R
, Etype
(L
))
4756 Add_One_Interp
(N
, Etype
(L
), Etype
(L
));
4760 Get_First_Interp
(L
, Ind
, It
);
4761 while Present
(It
.Typ
) loop
4762 if Root_Type
(It
.Typ
) = Standard_Boolean
4763 and then Has_Compatible_Type
(R
, It
.Typ
)
4765 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
4768 Get_Next_Interp
(Ind
, It
);
4772 -- Here we have failed to find an interpretation. Clearly we know that
4773 -- it is not the case that both operands can have an interpretation of
4774 -- Boolean, but this is by far the most likely intended interpretation.
4775 -- So we simply resolve both operands as Booleans, and at least one of
4776 -- these resolutions will generate an error message, and we do not need
4777 -- to give another error message on the short circuit operation itself.
4779 if Etype
(N
) = Any_Type
then
4780 Resolve
(L
, Standard_Boolean
);
4781 Resolve
(R
, Standard_Boolean
);
4782 Set_Etype
(N
, Standard_Boolean
);
4784 end Analyze_Short_Circuit
;
4790 procedure Analyze_Slice
(N
: Node_Id
) is
4791 D
: constant Node_Id
:= Discrete_Range
(N
);
4792 P
: constant Node_Id
:= Prefix
(N
);
4793 Array_Type
: Entity_Id
;
4794 Index_Type
: Entity_Id
;
4796 procedure Analyze_Overloaded_Slice
;
4797 -- If the prefix is overloaded, select those interpretations that
4798 -- yield a one-dimensional array type.
4800 ------------------------------
4801 -- Analyze_Overloaded_Slice --
4802 ------------------------------
4804 procedure Analyze_Overloaded_Slice
is
4810 Set_Etype
(N
, Any_Type
);
4812 Get_First_Interp
(P
, I
, It
);
4813 while Present
(It
.Nam
) loop
4816 if Is_Access_Type
(Typ
) then
4817 Typ
:= Designated_Type
(Typ
);
4819 (Warn_On_Dereference
, "?d?implicit dereference", N
);
4822 if Is_Array_Type
(Typ
)
4823 and then Number_Dimensions
(Typ
) = 1
4824 and then Has_Compatible_Type
(D
, Etype
(First_Index
(Typ
)))
4826 Add_One_Interp
(N
, Typ
, Typ
);
4829 Get_Next_Interp
(I
, It
);
4832 if Etype
(N
) = Any_Type
then
4833 Error_Msg_N
("expect array type in prefix of slice", N
);
4835 end Analyze_Overloaded_Slice
;
4837 -- Start of processing for Analyze_Slice
4840 if Comes_From_Source
(N
) then
4841 Check_SPARK_05_Restriction
("slice is not allowed", N
);
4847 if Is_Overloaded
(P
) then
4848 Analyze_Overloaded_Slice
;
4851 Array_Type
:= Etype
(P
);
4852 Set_Etype
(N
, Any_Type
);
4854 if Is_Access_Type
(Array_Type
) then
4855 Array_Type
:= Designated_Type
(Array_Type
);
4856 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4859 if not Is_Array_Type
(Array_Type
) then
4860 Wrong_Type
(P
, Any_Array
);
4862 elsif Number_Dimensions
(Array_Type
) > 1 then
4864 ("type is not one-dimensional array in slice prefix", N
);
4867 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
4868 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
4870 Index_Type
:= Etype
(First_Index
(Array_Type
));
4873 if not Has_Compatible_Type
(D
, Index_Type
) then
4874 Wrong_Type
(D
, Index_Type
);
4876 Set_Etype
(N
, Array_Type
);
4882 -----------------------------
4883 -- Analyze_Type_Conversion --
4884 -----------------------------
4886 procedure Analyze_Type_Conversion
(N
: Node_Id
) is
4887 Expr
: constant Node_Id
:= Expression
(N
);
4891 -- If Conversion_OK is set, then the Etype is already set, and the only
4892 -- processing required is to analyze the expression. This is used to
4893 -- construct certain "illegal" conversions which are not allowed by Ada
4894 -- semantics, but can be handled by Gigi, see Sinfo for further details.
4896 if Conversion_OK
(N
) then
4901 -- Otherwise full type analysis is required, as well as some semantic
4902 -- checks to make sure the argument of the conversion is appropriate.
4904 Find_Type
(Subtype_Mark
(N
));
4905 Typ
:= Entity
(Subtype_Mark
(N
));
4907 Check_Fully_Declared
(Typ
, N
);
4908 Analyze_Expression
(Expr
);
4909 Validate_Remote_Type_Type_Conversion
(N
);
4911 -- Only remaining step is validity checks on the argument. These
4912 -- are skipped if the conversion does not come from the source.
4914 if not Comes_From_Source
(N
) then
4917 -- If there was an error in a generic unit, no need to replicate the
4918 -- error message. Conversely, constant-folding in the generic may
4919 -- transform the argument of a conversion into a string literal, which
4920 -- is legal. Therefore the following tests are not performed in an
4921 -- instance. The same applies to an inlined body.
4923 elsif In_Instance
or In_Inlined_Body
then
4926 elsif Nkind
(Expr
) = N_Null
then
4927 Error_Msg_N
("argument of conversion cannot be null", N
);
4928 Error_Msg_N
("\use qualified expression instead", N
);
4929 Set_Etype
(N
, Any_Type
);
4931 elsif Nkind
(Expr
) = N_Aggregate
then
4932 Error_Msg_N
("argument of conversion cannot be aggregate", N
);
4933 Error_Msg_N
("\use qualified expression instead", N
);
4935 elsif Nkind
(Expr
) = N_Allocator
then
4936 Error_Msg_N
("argument of conversion cannot be an allocator", N
);
4937 Error_Msg_N
("\use qualified expression instead", N
);
4939 elsif Nkind
(Expr
) = N_String_Literal
then
4940 Error_Msg_N
("argument of conversion cannot be string literal", N
);
4941 Error_Msg_N
("\use qualified expression instead", N
);
4943 elsif Nkind
(Expr
) = N_Character_Literal
then
4944 if Ada_Version
= Ada_83
then
4945 Resolve
(Expr
, Typ
);
4947 Error_Msg_N
("argument of conversion cannot be character literal",
4949 Error_Msg_N
("\use qualified expression instead", N
);
4952 elsif Nkind
(Expr
) = N_Attribute_Reference
4953 and then Nam_In
(Attribute_Name
(Expr
), Name_Access
,
4954 Name_Unchecked_Access
,
4955 Name_Unrestricted_Access
)
4957 Error_Msg_N
("argument of conversion cannot be access", N
);
4958 Error_Msg_N
("\use qualified expression instead", N
);
4961 -- A formal parameter of a specific tagged type whose related subprogram
4962 -- is subject to pragma Extensions_Visible with value "False" cannot
4963 -- appear in a class-wide conversion (SPARK RM 6.1.7(3)).
4965 if Is_Class_Wide_Type
(Typ
) and then Is_EVF_Expression
(Expr
) then
4967 ("formal parameter with Extensions_Visible False cannot be "
4968 & "converted to class-wide type", Expr
);
4970 end Analyze_Type_Conversion
;
4972 ----------------------
4973 -- Analyze_Unary_Op --
4974 ----------------------
4976 procedure Analyze_Unary_Op
(N
: Node_Id
) is
4977 R
: constant Node_Id
:= Right_Opnd
(N
);
4978 Op_Id
: Entity_Id
:= Entity
(N
);
4981 Set_Etype
(N
, Any_Type
);
4982 Candidate_Type
:= Empty
;
4984 Analyze_Expression
(R
);
4986 if Present
(Op_Id
) then
4987 if Ekind
(Op_Id
) = E_Operator
then
4988 Find_Unary_Types
(R
, Op_Id
, N
);
4990 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
4994 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
4995 while Present
(Op_Id
) loop
4996 if Ekind
(Op_Id
) = E_Operator
then
4997 if No
(Next_Entity
(First_Entity
(Op_Id
))) then
4998 Find_Unary_Types
(R
, Op_Id
, N
);
5001 elsif Is_Overloadable
(Op_Id
) then
5002 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
5005 Op_Id
:= Homonym
(Op_Id
);
5010 end Analyze_Unary_Op
;
5012 ----------------------------------
5013 -- Analyze_Unchecked_Expression --
5014 ----------------------------------
5016 procedure Analyze_Unchecked_Expression
(N
: Node_Id
) is
5018 Analyze
(Expression
(N
), Suppress
=> All_Checks
);
5019 Set_Etype
(N
, Etype
(Expression
(N
)));
5020 Save_Interps
(Expression
(N
), N
);
5021 end Analyze_Unchecked_Expression
;
5023 ---------------------------------------
5024 -- Analyze_Unchecked_Type_Conversion --
5025 ---------------------------------------
5027 procedure Analyze_Unchecked_Type_Conversion
(N
: Node_Id
) is
5029 Find_Type
(Subtype_Mark
(N
));
5030 Analyze_Expression
(Expression
(N
));
5031 Set_Etype
(N
, Entity
(Subtype_Mark
(N
)));
5032 end Analyze_Unchecked_Type_Conversion
;
5034 ------------------------------------
5035 -- Analyze_User_Defined_Binary_Op --
5036 ------------------------------------
5038 procedure Analyze_User_Defined_Binary_Op
5043 -- Only do analysis if the operator Comes_From_Source, since otherwise
5044 -- the operator was generated by the expander, and all such operators
5045 -- always refer to the operators in package Standard.
5047 if Comes_From_Source
(N
) then
5049 F1
: constant Entity_Id
:= First_Formal
(Op_Id
);
5050 F2
: constant Entity_Id
:= Next_Formal
(F1
);
5053 -- Verify that Op_Id is a visible binary function. Note that since
5054 -- we know Op_Id is overloaded, potentially use visible means use
5055 -- visible for sure (RM 9.4(11)).
5057 if Ekind
(Op_Id
) = E_Function
5058 and then Present
(F2
)
5059 and then (Is_Immediately_Visible
(Op_Id
)
5060 or else Is_Potentially_Use_Visible
(Op_Id
))
5061 and then Has_Compatible_Type
(Left_Opnd
(N
), Etype
(F1
))
5062 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F2
))
5064 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5066 -- If the left operand is overloaded, indicate that the current
5067 -- type is a viable candidate. This is redundant in most cases,
5068 -- but for equality and comparison operators where the context
5069 -- does not impose a type on the operands, setting the proper
5070 -- type is necessary to avoid subsequent ambiguities during
5071 -- resolution, when both user-defined and predefined operators
5072 -- may be candidates.
5074 if Is_Overloaded
(Left_Opnd
(N
)) then
5075 Set_Etype
(Left_Opnd
(N
), Etype
(F1
));
5078 if Debug_Flag_E
then
5079 Write_Str
("user defined operator ");
5080 Write_Name
(Chars
(Op_Id
));
5081 Write_Str
(" on node ");
5082 Write_Int
(Int
(N
));
5088 end Analyze_User_Defined_Binary_Op
;
5090 -----------------------------------
5091 -- Analyze_User_Defined_Unary_Op --
5092 -----------------------------------
5094 procedure Analyze_User_Defined_Unary_Op
5099 -- Only do analysis if the operator Comes_From_Source, since otherwise
5100 -- the operator was generated by the expander, and all such operators
5101 -- always refer to the operators in package Standard.
5103 if Comes_From_Source
(N
) then
5105 F
: constant Entity_Id
:= First_Formal
(Op_Id
);
5108 -- Verify that Op_Id is a visible unary function. Note that since
5109 -- we know Op_Id is overloaded, potentially use visible means use
5110 -- visible for sure (RM 9.4(11)).
5112 if Ekind
(Op_Id
) = E_Function
5113 and then No
(Next_Formal
(F
))
5114 and then (Is_Immediately_Visible
(Op_Id
)
5115 or else Is_Potentially_Use_Visible
(Op_Id
))
5116 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F
))
5118 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5122 end Analyze_User_Defined_Unary_Op
;
5124 ---------------------------
5125 -- Check_Arithmetic_Pair --
5126 ---------------------------
5128 procedure Check_Arithmetic_Pair
5129 (T1
, T2
: Entity_Id
;
5133 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
5135 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean;
5136 -- Check whether the fixed-point type Typ has a user-defined operator
5137 -- (multiplication or division) that should hide the corresponding
5138 -- predefined operator. Used to implement Ada 2005 AI-264, to make
5139 -- such operators more visible and therefore useful.
5141 -- If the name of the operation is an expanded name with prefix
5142 -- Standard, the predefined universal fixed operator is available,
5143 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
5145 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
;
5146 -- Get specific type (i.e. non-universal type if there is one)
5152 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean is
5153 Bas
: constant Entity_Id
:= Base_Type
(Typ
);
5159 -- If the universal_fixed operation is given explicitly the rule
5160 -- concerning primitive operations of the type do not apply.
5162 if Nkind
(N
) = N_Function_Call
5163 and then Nkind
(Name
(N
)) = N_Expanded_Name
5164 and then Entity
(Prefix
(Name
(N
))) = Standard_Standard
5169 -- The operation is treated as primitive if it is declared in the
5170 -- same scope as the type, and therefore on the same entity chain.
5172 Ent
:= Next_Entity
(Typ
);
5173 while Present
(Ent
) loop
5174 if Chars
(Ent
) = Chars
(Op
) then
5175 F1
:= First_Formal
(Ent
);
5176 F2
:= Next_Formal
(F1
);
5178 -- The operation counts as primitive if either operand or
5179 -- result are of the given base type, and both operands are
5180 -- fixed point types.
5182 if (Base_Type
(Etype
(F1
)) = Bas
5183 and then Is_Fixed_Point_Type
(Etype
(F2
)))
5186 (Base_Type
(Etype
(F2
)) = Bas
5187 and then Is_Fixed_Point_Type
(Etype
(F1
)))
5190 (Base_Type
(Etype
(Ent
)) = Bas
5191 and then Is_Fixed_Point_Type
(Etype
(F1
))
5192 and then Is_Fixed_Point_Type
(Etype
(F2
)))
5208 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
is
5210 if T1
= Universal_Integer
or else T1
= Universal_Real
then
5211 return Base_Type
(T2
);
5213 return Base_Type
(T1
);
5217 -- Start of processing for Check_Arithmetic_Pair
5220 if Nam_In
(Op_Name
, Name_Op_Add
, Name_Op_Subtract
) then
5221 if Is_Numeric_Type
(T1
)
5222 and then Is_Numeric_Type
(T2
)
5223 and then (Covers
(T1
=> T1
, T2
=> T2
)
5225 Covers
(T1
=> T2
, T2
=> T1
))
5227 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5230 elsif Nam_In
(Op_Name
, Name_Op_Multiply
, Name_Op_Divide
) then
5231 if Is_Fixed_Point_Type
(T1
)
5232 and then (Is_Fixed_Point_Type
(T2
) or else T2
= Universal_Real
)
5234 -- If Treat_Fixed_As_Integer is set then the Etype is already set
5235 -- and no further processing is required (this is the case of an
5236 -- operator constructed by Exp_Fixd for a fixed point operation)
5237 -- Otherwise add one interpretation with universal fixed result
5238 -- If the operator is given in functional notation, it comes
5239 -- from source and Fixed_As_Integer cannot apply.
5241 if (Nkind
(N
) not in N_Op
5242 or else not Treat_Fixed_As_Integer
(N
))
5244 (not Has_Fixed_Op
(T1
, Op_Id
)
5245 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
5247 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
5250 elsif Is_Fixed_Point_Type
(T2
)
5251 and then (Nkind
(N
) not in N_Op
5252 or else not Treat_Fixed_As_Integer
(N
))
5253 and then T1
= Universal_Real
5255 (not Has_Fixed_Op
(T1
, Op_Id
)
5256 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
5258 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
5260 elsif Is_Numeric_Type
(T1
)
5261 and then Is_Numeric_Type
(T2
)
5262 and then (Covers
(T1
=> T1
, T2
=> T2
)
5264 Covers
(T1
=> T2
, T2
=> T1
))
5266 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5268 elsif Is_Fixed_Point_Type
(T1
)
5269 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5270 or else T2
= Universal_Integer
)
5272 Add_One_Interp
(N
, Op_Id
, T1
);
5274 elsif T2
= Universal_Real
5275 and then Base_Type
(T1
) = Base_Type
(Standard_Integer
)
5276 and then Op_Name
= Name_Op_Multiply
5278 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
5280 elsif T1
= Universal_Real
5281 and then Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5283 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
5285 elsif Is_Fixed_Point_Type
(T2
)
5286 and then (Base_Type
(T1
) = Base_Type
(Standard_Integer
)
5287 or else T1
= Universal_Integer
)
5288 and then Op_Name
= Name_Op_Multiply
5290 Add_One_Interp
(N
, Op_Id
, T2
);
5292 elsif T1
= Universal_Real
and then T2
= Universal_Integer
then
5293 Add_One_Interp
(N
, Op_Id
, T1
);
5295 elsif T2
= Universal_Real
5296 and then T1
= Universal_Integer
5297 and then Op_Name
= Name_Op_Multiply
5299 Add_One_Interp
(N
, Op_Id
, T2
);
5302 elsif Op_Name
= Name_Op_Mod
or else Op_Name
= Name_Op_Rem
then
5304 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
5305 -- set does not require any special processing, since the Etype is
5306 -- already set (case of operation constructed by Exp_Fixed).
5308 if Is_Integer_Type
(T1
)
5309 and then (Covers
(T1
=> T1
, T2
=> T2
)
5311 Covers
(T1
=> T2
, T2
=> T1
))
5313 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5316 elsif Op_Name
= Name_Op_Expon
then
5317 if Is_Numeric_Type
(T1
)
5318 and then not Is_Fixed_Point_Type
(T1
)
5319 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5320 or else T2
= Universal_Integer
)
5322 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
5325 else pragma Assert
(Nkind
(N
) in N_Op_Shift
);
5327 -- If not one of the predefined operators, the node may be one
5328 -- of the intrinsic functions. Its kind is always specific, and
5329 -- we can use it directly, rather than the name of the operation.
5331 if Is_Integer_Type
(T1
)
5332 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5333 or else T2
= Universal_Integer
)
5335 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
5338 end Check_Arithmetic_Pair
;
5340 -------------------------------
5341 -- Check_Misspelled_Selector --
5342 -------------------------------
5344 procedure Check_Misspelled_Selector
5345 (Prefix
: Entity_Id
;
5348 Max_Suggestions
: constant := 2;
5349 Nr_Of_Suggestions
: Natural := 0;
5351 Suggestion_1
: Entity_Id
:= Empty
;
5352 Suggestion_2
: Entity_Id
:= Empty
;
5357 -- All the components of the prefix of selector Sel are matched against
5358 -- Sel and a count is maintained of possible misspellings. When at
5359 -- the end of the analysis there are one or two (not more) possible
5360 -- misspellings, these misspellings will be suggested as possible
5363 if not (Is_Private_Type
(Prefix
) or else Is_Record_Type
(Prefix
)) then
5365 -- Concurrent types should be handled as well ???
5370 Comp
:= First_Entity
(Prefix
);
5371 while Nr_Of_Suggestions
<= Max_Suggestions
and then Present
(Comp
) loop
5372 if Is_Visible_Component
(Comp
) then
5373 if Is_Bad_Spelling_Of
(Chars
(Comp
), Chars
(Sel
)) then
5374 Nr_Of_Suggestions
:= Nr_Of_Suggestions
+ 1;
5376 case Nr_Of_Suggestions
is
5377 when 1 => Suggestion_1
:= Comp
;
5378 when 2 => Suggestion_2
:= Comp
;
5379 when others => exit;
5384 Comp
:= Next_Entity
(Comp
);
5387 -- Report at most two suggestions
5389 if Nr_Of_Suggestions
= 1 then
5390 Error_Msg_NE
-- CODEFIX
5391 ("\possible misspelling of&", Sel
, Suggestion_1
);
5393 elsif Nr_Of_Suggestions
= 2 then
5394 Error_Msg_Node_2
:= Suggestion_2
;
5395 Error_Msg_NE
-- CODEFIX
5396 ("\possible misspelling of& or&", Sel
, Suggestion_1
);
5398 end Check_Misspelled_Selector
;
5400 ----------------------
5401 -- Defined_In_Scope --
5402 ----------------------
5404 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean
5406 S1
: constant Entity_Id
:= Scope
(Base_Type
(T
));
5409 or else (S1
= System_Aux_Id
and then S
= Scope
(S1
));
5410 end Defined_In_Scope
;
5416 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
) is
5422 Void_Interp_Seen
: Boolean := False;
5425 pragma Warnings
(Off
, Boolean);
5428 if Ada_Version
>= Ada_2005
then
5429 Actual
:= First_Actual
(N
);
5430 while Present
(Actual
) loop
5432 -- Ada 2005 (AI-50217): Post an error in case of premature
5433 -- usage of an entity from the limited view.
5435 if not Analyzed
(Etype
(Actual
))
5436 and then From_Limited_With
(Etype
(Actual
))
5438 Error_Msg_Qual_Level
:= 1;
5440 ("missing with_clause for scope of imported type&",
5441 Actual
, Etype
(Actual
));
5442 Error_Msg_Qual_Level
:= 0;
5445 Next_Actual
(Actual
);
5449 -- Analyze each candidate call again, with full error reporting
5453 ("no candidate interpretations match the actuals:!", Nam
);
5454 Err_Mode
:= All_Errors_Mode
;
5455 All_Errors_Mode
:= True;
5457 -- If this is a call to an operation of a concurrent type,
5458 -- the failed interpretations have been removed from the
5459 -- name. Recover them to provide full diagnostics.
5461 if Nkind
(Parent
(Nam
)) = N_Selected_Component
then
5462 Set_Entity
(Nam
, Empty
);
5463 New_Nam
:= New_Copy_Tree
(Parent
(Nam
));
5464 Set_Is_Overloaded
(New_Nam
, False);
5465 Set_Is_Overloaded
(Selector_Name
(New_Nam
), False);
5466 Set_Parent
(New_Nam
, Parent
(Parent
(Nam
)));
5467 Analyze_Selected_Component
(New_Nam
);
5468 Get_First_Interp
(Selector_Name
(New_Nam
), X
, It
);
5470 Get_First_Interp
(Nam
, X
, It
);
5473 while Present
(It
.Nam
) loop
5474 if Etype
(It
.Nam
) = Standard_Void_Type
then
5475 Void_Interp_Seen
:= True;
5478 Analyze_One_Call
(N
, It
.Nam
, True, Success
);
5479 Get_Next_Interp
(X
, It
);
5482 if Nkind
(N
) = N_Function_Call
then
5483 Get_First_Interp
(Nam
, X
, It
);
5484 while Present
(It
.Nam
) loop
5485 if Ekind_In
(It
.Nam
, E_Function
, E_Operator
) then
5488 Get_Next_Interp
(X
, It
);
5492 -- If all interpretations are procedures, this deserves a
5493 -- more precise message. Ditto if this appears as the prefix
5494 -- of a selected component, which may be a lexical error.
5497 ("\context requires function call, found procedure name", Nam
);
5499 if Nkind
(Parent
(N
)) = N_Selected_Component
5500 and then N
= Prefix
(Parent
(N
))
5502 Error_Msg_N
-- CODEFIX
5503 ("\period should probably be semicolon", Parent
(N
));
5506 elsif Nkind
(N
) = N_Procedure_Call_Statement
5507 and then not Void_Interp_Seen
5510 "\function name found in procedure call", Nam
);
5513 All_Errors_Mode
:= Err_Mode
;
5516 ---------------------------
5517 -- Find_Arithmetic_Types --
5518 ---------------------------
5520 procedure Find_Arithmetic_Types
5525 Index1
: Interp_Index
;
5526 Index2
: Interp_Index
;
5530 procedure Check_Right_Argument
(T
: Entity_Id
);
5531 -- Check right operand of operator
5533 --------------------------
5534 -- Check_Right_Argument --
5535 --------------------------
5537 procedure Check_Right_Argument
(T
: Entity_Id
) is
5539 if not Is_Overloaded
(R
) then
5540 Check_Arithmetic_Pair
(T
, Etype
(R
), Op_Id
, N
);
5542 Get_First_Interp
(R
, Index2
, It2
);
5543 while Present
(It2
.Typ
) loop
5544 Check_Arithmetic_Pair
(T
, It2
.Typ
, Op_Id
, N
);
5545 Get_Next_Interp
(Index2
, It2
);
5548 end Check_Right_Argument
;
5550 -- Start of processing for Find_Arithmetic_Types
5553 if not Is_Overloaded
(L
) then
5554 Check_Right_Argument
(Etype
(L
));
5557 Get_First_Interp
(L
, Index1
, It1
);
5558 while Present
(It1
.Typ
) loop
5559 Check_Right_Argument
(It1
.Typ
);
5560 Get_Next_Interp
(Index1
, It1
);
5564 end Find_Arithmetic_Types
;
5566 ------------------------
5567 -- Find_Boolean_Types --
5568 ------------------------
5570 procedure Find_Boolean_Types
5575 Index
: Interp_Index
;
5578 procedure Check_Numeric_Argument
(T
: Entity_Id
);
5579 -- Special case for logical operations one of whose operands is an
5580 -- integer literal. If both are literal the result is any modular type.
5582 ----------------------------
5583 -- Check_Numeric_Argument --
5584 ----------------------------
5586 procedure Check_Numeric_Argument
(T
: Entity_Id
) is
5588 if T
= Universal_Integer
then
5589 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
5591 elsif Is_Modular_Integer_Type
(T
) then
5592 Add_One_Interp
(N
, Op_Id
, T
);
5594 end Check_Numeric_Argument
;
5596 -- Start of processing for Find_Boolean_Types
5599 if not Is_Overloaded
(L
) then
5600 if Etype
(L
) = Universal_Integer
5601 or else Etype
(L
) = Any_Modular
5603 if not Is_Overloaded
(R
) then
5604 Check_Numeric_Argument
(Etype
(R
));
5607 Get_First_Interp
(R
, Index
, It
);
5608 while Present
(It
.Typ
) loop
5609 Check_Numeric_Argument
(It
.Typ
);
5610 Get_Next_Interp
(Index
, It
);
5614 -- If operands are aggregates, we must assume that they may be
5615 -- boolean arrays, and leave disambiguation for the second pass.
5616 -- If only one is an aggregate, verify that the other one has an
5617 -- interpretation as a boolean array
5619 elsif Nkind
(L
) = N_Aggregate
then
5620 if Nkind
(R
) = N_Aggregate
then
5621 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
5623 elsif not Is_Overloaded
(R
) then
5624 if Valid_Boolean_Arg
(Etype
(R
)) then
5625 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
5629 Get_First_Interp
(R
, Index
, It
);
5630 while Present
(It
.Typ
) loop
5631 if Valid_Boolean_Arg
(It
.Typ
) then
5632 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
5635 Get_Next_Interp
(Index
, It
);
5639 elsif Valid_Boolean_Arg
(Etype
(L
))
5640 and then Has_Compatible_Type
(R
, Etype
(L
))
5642 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
5646 Get_First_Interp
(L
, Index
, It
);
5647 while Present
(It
.Typ
) loop
5648 if Valid_Boolean_Arg
(It
.Typ
)
5649 and then Has_Compatible_Type
(R
, It
.Typ
)
5651 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
5654 Get_Next_Interp
(Index
, It
);
5657 end Find_Boolean_Types
;
5659 ---------------------------
5660 -- Find_Comparison_Types --
5661 ---------------------------
5663 procedure Find_Comparison_Types
5668 Index
: Interp_Index
;
5670 Found
: Boolean := False;
5673 Scop
: Entity_Id
:= Empty
;
5675 procedure Try_One_Interp
(T1
: Entity_Id
);
5676 -- Routine to try one proposed interpretation. Note that the context
5677 -- of the operator plays no role in resolving the arguments, so that
5678 -- if there is more than one interpretation of the operands that is
5679 -- compatible with comparison, the operation is ambiguous.
5681 --------------------
5682 -- Try_One_Interp --
5683 --------------------
5685 procedure Try_One_Interp
(T1
: Entity_Id
) is
5688 -- If the operator is an expanded name, then the type of the operand
5689 -- must be defined in the corresponding scope. If the type is
5690 -- universal, the context will impose the correct type.
5693 and then not Defined_In_Scope
(T1
, Scop
)
5694 and then T1
/= Universal_Integer
5695 and then T1
/= Universal_Real
5696 and then T1
/= Any_String
5697 and then T1
/= Any_Composite
5702 if Valid_Comparison_Arg
(T1
) and then Has_Compatible_Type
(R
, T1
) then
5703 if Found
and then Base_Type
(T1
) /= Base_Type
(T_F
) then
5704 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
5706 if It
= No_Interp
then
5707 Ambiguous_Operands
(N
);
5708 Set_Etype
(L
, Any_Type
);
5722 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
5727 -- Start of processing for Find_Comparison_Types
5730 -- If left operand is aggregate, the right operand has to
5731 -- provide a usable type for it.
5733 if Nkind
(L
) = N_Aggregate
and then Nkind
(R
) /= N_Aggregate
then
5734 Find_Comparison_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
5738 if Nkind
(N
) = N_Function_Call
5739 and then Nkind
(Name
(N
)) = N_Expanded_Name
5741 Scop
:= Entity
(Prefix
(Name
(N
)));
5743 -- The prefix may be a package renaming, and the subsequent test
5744 -- requires the original package.
5746 if Ekind
(Scop
) = E_Package
5747 and then Present
(Renamed_Entity
(Scop
))
5749 Scop
:= Renamed_Entity
(Scop
);
5750 Set_Entity
(Prefix
(Name
(N
)), Scop
);
5754 if not Is_Overloaded
(L
) then
5755 Try_One_Interp
(Etype
(L
));
5758 Get_First_Interp
(L
, Index
, It
);
5759 while Present
(It
.Typ
) loop
5760 Try_One_Interp
(It
.Typ
);
5761 Get_Next_Interp
(Index
, It
);
5764 end Find_Comparison_Types
;
5766 ----------------------------------------
5767 -- Find_Non_Universal_Interpretations --
5768 ----------------------------------------
5770 procedure Find_Non_Universal_Interpretations
5776 Index
: Interp_Index
;
5780 if T1
= Universal_Integer
or else T1
= Universal_Real
5782 -- If the left operand of an equality operator is null, the visibility
5783 -- of the operator must be determined from the interpretation of the
5784 -- right operand. This processing must be done for Any_Access, which
5785 -- is the internal representation of the type of the literal null.
5787 or else T1
= Any_Access
5789 if not Is_Overloaded
(R
) then
5790 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(Etype
(R
)));
5792 Get_First_Interp
(R
, Index
, It
);
5793 while Present
(It
.Typ
) loop
5794 if Covers
(It
.Typ
, T1
) then
5796 (N
, Op_Id
, Standard_Boolean
, Base_Type
(It
.Typ
));
5799 Get_Next_Interp
(Index
, It
);
5803 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(T1
));
5805 end Find_Non_Universal_Interpretations
;
5807 ------------------------------
5808 -- Find_Concatenation_Types --
5809 ------------------------------
5811 procedure Find_Concatenation_Types
5816 Op_Type
: constant Entity_Id
:= Etype
(Op_Id
);
5819 if Is_Array_Type
(Op_Type
)
5820 and then not Is_Limited_Type
(Op_Type
)
5822 and then (Has_Compatible_Type
(L
, Op_Type
)
5824 Has_Compatible_Type
(L
, Component_Type
(Op_Type
)))
5826 and then (Has_Compatible_Type
(R
, Op_Type
)
5828 Has_Compatible_Type
(R
, Component_Type
(Op_Type
)))
5830 Add_One_Interp
(N
, Op_Id
, Op_Type
);
5832 end Find_Concatenation_Types
;
5834 -------------------------
5835 -- Find_Equality_Types --
5836 -------------------------
5838 procedure Find_Equality_Types
5843 Index
: Interp_Index
;
5845 Found
: Boolean := False;
5848 Scop
: Entity_Id
:= Empty
;
5850 procedure Try_One_Interp
(T1
: Entity_Id
);
5851 -- The context of the equality operator plays no role in resolving the
5852 -- arguments, so that if there is more than one interpretation of the
5853 -- operands that is compatible with equality, the construct is ambiguous
5854 -- and an error can be emitted now, after trying to disambiguate, i.e.
5855 -- applying preference rules.
5857 --------------------
5858 -- Try_One_Interp --
5859 --------------------
5861 procedure Try_One_Interp
(T1
: Entity_Id
) is
5862 Bas
: constant Entity_Id
:= Base_Type
(T1
);
5865 -- If the operator is an expanded name, then the type of the operand
5866 -- must be defined in the corresponding scope. If the type is
5867 -- universal, the context will impose the correct type. An anonymous
5868 -- type for a 'Access reference is also universal in this sense, as
5869 -- the actual type is obtained from context.
5871 -- In Ada 2005, the equality operator for anonymous access types
5872 -- is declared in Standard, and preference rules apply to it.
5874 if Present
(Scop
) then
5875 if Defined_In_Scope
(T1
, Scop
)
5876 or else T1
= Universal_Integer
5877 or else T1
= Universal_Real
5878 or else T1
= Any_Access
5879 or else T1
= Any_String
5880 or else T1
= Any_Composite
5881 or else (Ekind
(T1
) = E_Access_Subprogram_Type
5882 and then not Comes_From_Source
(T1
))
5886 elsif Ekind
(T1
) = E_Anonymous_Access_Type
5887 and then Scop
= Standard_Standard
5892 -- The scope does not contain an operator for the type
5897 -- If we have infix notation, the operator must be usable. Within
5898 -- an instance, if the type is already established we know it is
5899 -- correct. If an operand is universal it is compatible with any
5902 elsif In_Open_Scopes
(Scope
(Bas
))
5903 or else Is_Potentially_Use_Visible
(Bas
)
5904 or else In_Use
(Bas
)
5905 or else (In_Use
(Scope
(Bas
)) and then not Is_Hidden
(Bas
))
5907 -- In an instance, the type may have been immediately visible.
5908 -- Either the types are compatible, or one operand is universal
5909 -- (numeric or null).
5911 or else (In_Instance
5913 (First_Subtype
(T1
) = First_Subtype
(Etype
(R
))
5914 or else Nkind
(R
) = N_Null
5916 (Is_Numeric_Type
(T1
)
5917 and then Is_Universal_Numeric_Type
(Etype
(R
)))))
5919 -- In Ada 2005, the equality on anonymous access types is declared
5920 -- in Standard, and is always visible.
5922 or else Ekind
(T1
) = E_Anonymous_Access_Type
5927 -- Save candidate type for subsequent error message, if any
5929 if not Is_Limited_Type
(T1
) then
5930 Candidate_Type
:= T1
;
5936 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
5937 -- Do not allow anonymous access types in equality operators.
5939 if Ada_Version
< Ada_2005
5940 and then Ekind
(T1
) = E_Anonymous_Access_Type
5945 -- If the right operand has a type compatible with T1, check for an
5946 -- acceptable interpretation, unless T1 is limited (no predefined
5947 -- equality available), or this is use of a "/=" for a tagged type.
5948 -- In the latter case, possible interpretations of equality need
5949 -- to be considered, we don't want the default inequality declared
5950 -- in Standard to be chosen, and the "/=" will be rewritten as a
5951 -- negation of "=" (see the end of Analyze_Equality_Op). This ensures
5952 -- that that rewriting happens during analysis rather than being
5953 -- delayed until expansion (this is needed for ASIS, which only sees
5954 -- the unexpanded tree). Note that if the node is N_Op_Ne, but Op_Id
5955 -- is Name_Op_Eq then we still proceed with the interpretation,
5956 -- because that indicates the potential rewriting case where the
5957 -- interpretation to consider is actually "=" and the node may be
5958 -- about to be rewritten by Analyze_Equality_Op.
5960 if T1
/= Standard_Void_Type
5961 and then Has_Compatible_Type
(R
, T1
)
5964 ((not Is_Limited_Type
(T1
)
5965 and then not Is_Limited_Composite
(T1
))
5969 and then not Is_Limited_Type
(Component_Type
(T1
))
5970 and then Available_Full_View_Of_Component
(T1
)))
5973 (Nkind
(N
) /= N_Op_Ne
5974 or else not Is_Tagged_Type
(T1
)
5975 or else Chars
(Op_Id
) = Name_Op_Eq
)
5978 and then Base_Type
(T1
) /= Base_Type
(T_F
)
5980 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
5982 if It
= No_Interp
then
5983 Ambiguous_Operands
(N
);
5984 Set_Etype
(L
, Any_Type
);
5997 if not Analyzed
(L
) then
6001 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
6003 -- Case of operator was not visible, Etype still set to Any_Type
6005 if Etype
(N
) = Any_Type
then
6009 elsif Scop
= Standard_Standard
6010 and then Ekind
(T1
) = E_Anonymous_Access_Type
6016 -- Start of processing for Find_Equality_Types
6019 -- If left operand is aggregate, the right operand has to
6020 -- provide a usable type for it.
6022 if Nkind
(L
) = N_Aggregate
6023 and then Nkind
(R
) /= N_Aggregate
6025 Find_Equality_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
6029 if Nkind
(N
) = N_Function_Call
6030 and then Nkind
(Name
(N
)) = N_Expanded_Name
6032 Scop
:= Entity
(Prefix
(Name
(N
)));
6034 -- The prefix may be a package renaming, and the subsequent test
6035 -- requires the original package.
6037 if Ekind
(Scop
) = E_Package
6038 and then Present
(Renamed_Entity
(Scop
))
6040 Scop
:= Renamed_Entity
(Scop
);
6041 Set_Entity
(Prefix
(Name
(N
)), Scop
);
6045 if not Is_Overloaded
(L
) then
6046 Try_One_Interp
(Etype
(L
));
6049 Get_First_Interp
(L
, Index
, It
);
6050 while Present
(It
.Typ
) loop
6051 Try_One_Interp
(It
.Typ
);
6052 Get_Next_Interp
(Index
, It
);
6055 end Find_Equality_Types
;
6057 -------------------------
6058 -- Find_Negation_Types --
6059 -------------------------
6061 procedure Find_Negation_Types
6066 Index
: Interp_Index
;
6070 if not Is_Overloaded
(R
) then
6071 if Etype
(R
) = Universal_Integer
then
6072 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
6073 elsif Valid_Boolean_Arg
(Etype
(R
)) then
6074 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
6078 Get_First_Interp
(R
, Index
, It
);
6079 while Present
(It
.Typ
) loop
6080 if Valid_Boolean_Arg
(It
.Typ
) then
6081 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
6084 Get_Next_Interp
(Index
, It
);
6087 end Find_Negation_Types
;
6089 ------------------------------
6090 -- Find_Primitive_Operation --
6091 ------------------------------
6093 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean is
6094 Obj
: constant Node_Id
:= Prefix
(N
);
6095 Op
: constant Node_Id
:= Selector_Name
(N
);
6102 Set_Etype
(Op
, Any_Type
);
6104 if Is_Access_Type
(Etype
(Obj
)) then
6105 Typ
:= Designated_Type
(Etype
(Obj
));
6110 if Is_Class_Wide_Type
(Typ
) then
6111 Typ
:= Root_Type
(Typ
);
6114 Prims
:= Primitive_Operations
(Typ
);
6116 Prim
:= First_Elmt
(Prims
);
6117 while Present
(Prim
) loop
6118 if Chars
(Node
(Prim
)) = Chars
(Op
) then
6119 Add_One_Interp
(Op
, Node
(Prim
), Etype
(Node
(Prim
)));
6120 Set_Etype
(N
, Etype
(Node
(Prim
)));
6126 -- Now look for class-wide operations of the type or any of its
6127 -- ancestors by iterating over the homonyms of the selector.
6130 Cls_Type
: constant Entity_Id
:= Class_Wide_Type
(Typ
);
6134 Hom
:= Current_Entity
(Op
);
6135 while Present
(Hom
) loop
6136 if (Ekind
(Hom
) = E_Procedure
6138 Ekind
(Hom
) = E_Function
)
6139 and then Scope
(Hom
) = Scope
(Typ
)
6140 and then Present
(First_Formal
(Hom
))
6142 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
6144 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
6146 Ekind
(Etype
(First_Formal
(Hom
))) =
6147 E_Anonymous_Access_Type
6150 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
6153 Add_One_Interp
(Op
, Hom
, Etype
(Hom
));
6154 Set_Etype
(N
, Etype
(Hom
));
6157 Hom
:= Homonym
(Hom
);
6161 return Etype
(Op
) /= Any_Type
;
6162 end Find_Primitive_Operation
;
6164 ----------------------
6165 -- Find_Unary_Types --
6166 ----------------------
6168 procedure Find_Unary_Types
6173 Index
: Interp_Index
;
6177 if not Is_Overloaded
(R
) then
6178 if Is_Numeric_Type
(Etype
(R
)) then
6180 -- In an instance a generic actual may be a numeric type even if
6181 -- the formal in the generic unit was not. In that case, the
6182 -- predefined operator was not a possible interpretation in the
6183 -- generic, and cannot be one in the instance, unless the operator
6184 -- is an actual of an instance.
6188 not Is_Numeric_Type
(Corresponding_Generic_Type
(Etype
(R
)))
6192 Add_One_Interp
(N
, Op_Id
, Base_Type
(Etype
(R
)));
6197 Get_First_Interp
(R
, Index
, It
);
6198 while Present
(It
.Typ
) loop
6199 if Is_Numeric_Type
(It
.Typ
) then
6203 (Corresponding_Generic_Type
(Etype
(It
.Typ
)))
6208 Add_One_Interp
(N
, Op_Id
, Base_Type
(It
.Typ
));
6212 Get_Next_Interp
(Index
, It
);
6215 end Find_Unary_Types
;
6221 function Junk_Operand
(N
: Node_Id
) return Boolean is
6225 if Error_Posted
(N
) then
6229 -- Get entity to be tested
6231 if Is_Entity_Name
(N
)
6232 and then Present
(Entity
(N
))
6236 -- An odd case, a procedure name gets converted to a very peculiar
6237 -- function call, and here is where we detect this happening.
6239 elsif Nkind
(N
) = N_Function_Call
6240 and then Is_Entity_Name
(Name
(N
))
6241 and then Present
(Entity
(Name
(N
)))
6245 -- Another odd case, there are at least some cases of selected
6246 -- components where the selected component is not marked as having
6247 -- an entity, even though the selector does have an entity
6249 elsif Nkind
(N
) = N_Selected_Component
6250 and then Present
(Entity
(Selector_Name
(N
)))
6252 Enode
:= Selector_Name
(N
);
6258 -- Now test the entity we got to see if it is a bad case
6260 case Ekind
(Entity
(Enode
)) is
6264 ("package name cannot be used as operand", Enode
);
6266 when Generic_Unit_Kind
=>
6268 ("generic unit name cannot be used as operand", Enode
);
6272 ("subtype name cannot be used as operand", Enode
);
6276 ("entry name cannot be used as operand", Enode
);
6280 ("procedure name cannot be used as operand", Enode
);
6284 ("exception name cannot be used as operand", Enode
);
6286 when E_Block | E_Label | E_Loop
=>
6288 ("label name cannot be used as operand", Enode
);
6298 --------------------
6299 -- Operator_Check --
6300 --------------------
6302 procedure Operator_Check
(N
: Node_Id
) is
6304 Remove_Abstract_Operations
(N
);
6306 -- Test for case of no interpretation found for operator
6308 if Etype
(N
) = Any_Type
then
6312 Op_Id
: Entity_Id
:= Empty
;
6315 R
:= Right_Opnd
(N
);
6317 if Nkind
(N
) in N_Binary_Op
then
6323 -- If either operand has no type, then don't complain further,
6324 -- since this simply means that we have a propagated error.
6327 or else Etype
(R
) = Any_Type
6328 or else (Nkind
(N
) in N_Binary_Op
and then Etype
(L
) = Any_Type
)
6330 -- For the rather unusual case where one of the operands is
6331 -- a Raise_Expression, whose initial type is Any_Type, use
6332 -- the type of the other operand.
6334 if Nkind
(L
) = N_Raise_Expression
then
6335 Set_Etype
(L
, Etype
(R
));
6336 Set_Etype
(N
, Etype
(R
));
6338 elsif Nkind
(R
) = N_Raise_Expression
then
6339 Set_Etype
(R
, Etype
(L
));
6340 Set_Etype
(N
, Etype
(L
));
6345 -- We explicitly check for the case of concatenation of component
6346 -- with component to avoid reporting spurious matching array types
6347 -- that might happen to be lurking in distant packages (such as
6348 -- run-time packages). This also prevents inconsistencies in the
6349 -- messages for certain ACVC B tests, which can vary depending on
6350 -- types declared in run-time interfaces. Another improvement when
6351 -- aggregates are present is to look for a well-typed operand.
6353 elsif Present
(Candidate_Type
)
6354 and then (Nkind
(N
) /= N_Op_Concat
6355 or else Is_Array_Type
(Etype
(L
))
6356 or else Is_Array_Type
(Etype
(R
)))
6358 if Nkind
(N
) = N_Op_Concat
then
6359 if Etype
(L
) /= Any_Composite
6360 and then Is_Array_Type
(Etype
(L
))
6362 Candidate_Type
:= Etype
(L
);
6364 elsif Etype
(R
) /= Any_Composite
6365 and then Is_Array_Type
(Etype
(R
))
6367 Candidate_Type
:= Etype
(R
);
6371 Error_Msg_NE
-- CODEFIX
6372 ("operator for} is not directly visible!",
6373 N
, First_Subtype
(Candidate_Type
));
6376 U
: constant Node_Id
:=
6377 Cunit
(Get_Source_Unit
(Candidate_Type
));
6379 if Unit_Is_Visible
(U
) then
6380 Error_Msg_N
-- CODEFIX
6381 ("use clause would make operation legal!", N
);
6383 Error_Msg_NE
-- CODEFIX
6384 ("add with_clause and use_clause for&!",
6385 N
, Defining_Entity
(Unit
(U
)));
6390 -- If either operand is a junk operand (e.g. package name), then
6391 -- post appropriate error messages, but do not complain further.
6393 -- Note that the use of OR in this test instead of OR ELSE is
6394 -- quite deliberate, we may as well check both operands in the
6395 -- binary operator case.
6397 elsif Junk_Operand
(R
)
6398 or -- really mean OR here and not OR ELSE, see above
6399 (Nkind
(N
) in N_Binary_Op
and then Junk_Operand
(L
))
6403 -- If we have a logical operator, one of whose operands is
6404 -- Boolean, then we know that the other operand cannot resolve to
6405 -- Boolean (since we got no interpretations), but in that case we
6406 -- pretty much know that the other operand should be Boolean, so
6407 -- resolve it that way (generating an error)
6409 elsif Nkind_In
(N
, N_Op_And
, N_Op_Or
, N_Op_Xor
) then
6410 if Etype
(L
) = Standard_Boolean
then
6411 Resolve
(R
, Standard_Boolean
);
6413 elsif Etype
(R
) = Standard_Boolean
then
6414 Resolve
(L
, Standard_Boolean
);
6418 -- For an arithmetic operator or comparison operator, if one
6419 -- of the operands is numeric, then we know the other operand
6420 -- is not the same numeric type. If it is a non-numeric type,
6421 -- then probably it is intended to match the other operand.
6423 elsif Nkind_In
(N
, N_Op_Add
,
6429 Nkind_In
(N
, N_Op_Lt
,
6435 -- If Allow_Integer_Address is active, check whether the
6436 -- operation becomes legal after converting an operand.
6438 if Is_Numeric_Type
(Etype
(L
))
6439 and then not Is_Numeric_Type
(Etype
(R
))
6441 if Address_Integer_Convert_OK
(Etype
(R
), Etype
(L
)) then
6443 Unchecked_Convert_To
(Etype
(L
), Relocate_Node
(R
)));
6445 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6446 Analyze_Comparison_Op
(N
);
6448 Analyze_Arithmetic_Op
(N
);
6451 Resolve
(R
, Etype
(L
));
6456 elsif Is_Numeric_Type
(Etype
(R
))
6457 and then not Is_Numeric_Type
(Etype
(L
))
6459 if Address_Integer_Convert_OK
(Etype
(L
), Etype
(R
)) then
6461 Unchecked_Convert_To
(Etype
(R
), Relocate_Node
(L
)));
6463 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6464 Analyze_Comparison_Op
(N
);
6466 Analyze_Arithmetic_Op
(N
);
6472 Resolve
(L
, Etype
(R
));
6477 elsif Allow_Integer_Address
6478 and then Is_Descendent_Of_Address
(Etype
(L
))
6479 and then Is_Descendent_Of_Address
(Etype
(R
))
6480 and then not Error_Posted
(N
)
6483 Addr_Type
: constant Entity_Id
:= Etype
(L
);
6487 Unchecked_Convert_To
(
6488 Standard_Integer
, Relocate_Node
(L
)));
6490 Unchecked_Convert_To
(
6491 Standard_Integer
, Relocate_Node
(R
)));
6493 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6494 Analyze_Comparison_Op
(N
);
6496 Analyze_Arithmetic_Op
(N
);
6499 -- If this is an operand in an enclosing arithmetic
6500 -- operation, Convert the result as an address so that
6501 -- arithmetic folding of address can continue.
6503 if Nkind
(Parent
(N
)) in N_Op
then
6505 Unchecked_Convert_To
(Addr_Type
, Relocate_Node
(N
)));
6512 -- Comparisons on A'Access are common enough to deserve a
6515 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
)
6516 and then Ekind
(Etype
(L
)) = E_Access_Attribute_Type
6517 and then Ekind
(Etype
(R
)) = E_Access_Attribute_Type
6520 ("two access attributes cannot be compared directly", N
);
6522 ("\use qualified expression for one of the operands",
6526 -- Another one for C programmers
6528 elsif Nkind
(N
) = N_Op_Concat
6529 and then Valid_Boolean_Arg
(Etype
(L
))
6530 and then Valid_Boolean_Arg
(Etype
(R
))
6532 Error_Msg_N
("invalid operands for concatenation", N
);
6533 Error_Msg_N
-- CODEFIX
6534 ("\maybe AND was meant", N
);
6537 -- A special case for comparison of access parameter with null
6539 elsif Nkind
(N
) = N_Op_Eq
6540 and then Is_Entity_Name
(L
)
6541 and then Nkind
(Parent
(Entity
(L
))) = N_Parameter_Specification
6542 and then Nkind
(Parameter_Type
(Parent
(Entity
(L
)))) =
6544 and then Nkind
(R
) = N_Null
6546 Error_Msg_N
("access parameter is not allowed to be null", L
);
6547 Error_Msg_N
("\(call would raise Constraint_Error)", L
);
6550 -- Another special case for exponentiation, where the right
6551 -- operand must be Natural, independently of the base.
6553 elsif Nkind
(N
) = N_Op_Expon
6554 and then Is_Numeric_Type
(Etype
(L
))
6555 and then not Is_Overloaded
(R
)
6557 First_Subtype
(Base_Type
(Etype
(R
))) /= Standard_Integer
6558 and then Base_Type
(Etype
(R
)) /= Universal_Integer
6560 if Ada_Version
>= Ada_2012
6561 and then Has_Dimension_System
(Etype
(L
))
6564 ("exponent for dimensioned type must be a rational" &
6565 ", found}", R
, Etype
(R
));
6568 ("exponent must be of type Natural, found}", R
, Etype
(R
));
6573 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
) then
6574 if Address_Integer_Convert_OK
(Etype
(R
), Etype
(L
)) then
6576 Unchecked_Convert_To
(Etype
(L
), Relocate_Node
(R
)));
6577 Analyze_Equality_Op
(N
);
6582 -- If we fall through then just give general message. Note that in
6583 -- the following messages, if the operand is overloaded we choose
6584 -- an arbitrary type to complain about, but that is probably more
6585 -- useful than not giving a type at all.
6587 if Nkind
(N
) in N_Unary_Op
then
6588 Error_Msg_Node_2
:= Etype
(R
);
6589 Error_Msg_N
("operator& not defined for}", N
);
6593 if Nkind
(N
) in N_Binary_Op
then
6594 if not Is_Overloaded
(L
)
6595 and then not Is_Overloaded
(R
)
6596 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
6598 Error_Msg_Node_2
:= First_Subtype
(Etype
(R
));
6599 Error_Msg_N
("there is no applicable operator& for}", N
);
6602 -- Another attempt to find a fix: one of the candidate
6603 -- interpretations may not be use-visible. This has
6604 -- already been checked for predefined operators, so
6605 -- we examine only user-defined functions.
6607 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
6609 while Present
(Op_Id
) loop
6610 if Ekind
(Op_Id
) /= E_Operator
6611 and then Is_Overloadable
(Op_Id
)
6613 if not Is_Immediately_Visible
(Op_Id
)
6614 and then not In_Use
(Scope
(Op_Id
))
6615 and then not Is_Abstract_Subprogram
(Op_Id
)
6616 and then not Is_Hidden
(Op_Id
)
6617 and then Ekind
(Scope
(Op_Id
)) = E_Package
6620 (L
, Etype
(First_Formal
(Op_Id
)))
6622 (Next_Formal
(First_Formal
(Op_Id
)))
6626 Etype
(Next_Formal
(First_Formal
(Op_Id
))))
6629 ("No legal interpretation for operator&", N
);
6631 ("\use clause on& would make operation legal",
6637 Op_Id
:= Homonym
(Op_Id
);
6641 Error_Msg_N
("invalid operand types for operator&", N
);
6643 if Nkind
(N
) /= N_Op_Concat
then
6644 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
6645 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
6647 -- For concatenation operators it is more difficult to
6648 -- determine which is the wrong operand. It is worth
6649 -- flagging explicitly an access type, for those who
6650 -- might think that a dereference happens here.
6652 elsif Is_Access_Type
(Etype
(L
)) then
6653 Error_Msg_N
("\left operand is access type", N
);
6655 elsif Is_Access_Type
(Etype
(R
)) then
6656 Error_Msg_N
("\right operand is access type", N
);
6666 -----------------------------------------
6667 -- Process_Implicit_Dereference_Prefix --
6668 -----------------------------------------
6670 function Process_Implicit_Dereference_Prefix
6672 P
: Entity_Id
) return Entity_Id
6675 Typ
: constant Entity_Id
:= Designated_Type
(Etype
(P
));
6679 and then (Operating_Mode
= Check_Semantics
or else not Expander_Active
)
6681 -- We create a dummy reference to E to ensure that the reference is
6682 -- not considered as part of an assignment (an implicit dereference
6683 -- can never assign to its prefix). The Comes_From_Source attribute
6684 -- needs to be propagated for accurate warnings.
6686 Ref
:= New_Occurrence_Of
(E
, Sloc
(P
));
6687 Set_Comes_From_Source
(Ref
, Comes_From_Source
(P
));
6688 Generate_Reference
(E
, Ref
);
6691 -- An implicit dereference is a legal occurrence of an incomplete type
6692 -- imported through a limited_with clause, if the full view is visible.
6694 if From_Limited_With
(Typ
)
6695 and then not From_Limited_With
(Scope
(Typ
))
6697 (Is_Immediately_Visible
(Scope
(Typ
))
6699 (Is_Child_Unit
(Scope
(Typ
))
6700 and then Is_Visible_Lib_Unit
(Scope
(Typ
))))
6702 return Available_View
(Typ
);
6706 end Process_Implicit_Dereference_Prefix
;
6708 --------------------------------
6709 -- Remove_Abstract_Operations --
6710 --------------------------------
6712 procedure Remove_Abstract_Operations
(N
: Node_Id
) is
6713 Abstract_Op
: Entity_Id
:= Empty
;
6714 Address_Descendent
: Boolean := False;
6718 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
6719 -- activate this if either extensions are enabled, or if the abstract
6720 -- operation in question comes from a predefined file. This latter test
6721 -- allows us to use abstract to make operations invisible to users. In
6722 -- particular, if type Address is non-private and abstract subprograms
6723 -- are used to hide its operators, they will be truly hidden.
6725 type Operand_Position
is (First_Op
, Second_Op
);
6726 Univ_Type
: constant Entity_Id
:= Universal_Interpretation
(N
);
6728 procedure Remove_Address_Interpretations
(Op
: Operand_Position
);
6729 -- Ambiguities may arise when the operands are literal and the address
6730 -- operations in s-auxdec are visible. In that case, remove the
6731 -- interpretation of a literal as Address, to retain the semantics
6732 -- of Address as a private type.
6734 ------------------------------------
6735 -- Remove_Address_Interpretations --
6736 ------------------------------------
6738 procedure Remove_Address_Interpretations
(Op
: Operand_Position
) is
6742 if Is_Overloaded
(N
) then
6743 Get_First_Interp
(N
, I
, It
);
6744 while Present
(It
.Nam
) loop
6745 Formal
:= First_Entity
(It
.Nam
);
6747 if Op
= Second_Op
then
6748 Formal
:= Next_Entity
(Formal
);
6751 if Is_Descendent_Of_Address
(Etype
(Formal
)) then
6752 Address_Descendent
:= True;
6756 Get_Next_Interp
(I
, It
);
6759 end Remove_Address_Interpretations
;
6761 -- Start of processing for Remove_Abstract_Operations
6764 if Is_Overloaded
(N
) then
6765 if Debug_Flag_V
then
6766 Write_Str
("Remove_Abstract_Operations: ");
6767 Write_Overloads
(N
);
6770 Get_First_Interp
(N
, I
, It
);
6772 while Present
(It
.Nam
) loop
6773 if Is_Overloadable
(It
.Nam
)
6774 and then Is_Abstract_Subprogram
(It
.Nam
)
6775 and then not Is_Dispatching_Operation
(It
.Nam
)
6777 Abstract_Op
:= It
.Nam
;
6779 if Is_Descendent_Of_Address
(It
.Typ
) then
6780 Address_Descendent
:= True;
6784 -- In Ada 2005, this operation does not participate in overload
6785 -- resolution. If the operation is defined in a predefined
6786 -- unit, it is one of the operations declared abstract in some
6787 -- variants of System, and it must be removed as well.
6789 elsif Ada_Version
>= Ada_2005
6790 or else Is_Predefined_File_Name
6791 (Unit_File_Name
(Get_Source_Unit
(It
.Nam
)))
6798 Get_Next_Interp
(I
, It
);
6801 if No
(Abstract_Op
) then
6803 -- If some interpretation yields an integer type, it is still
6804 -- possible that there are address interpretations. Remove them
6805 -- if one operand is a literal, to avoid spurious ambiguities
6806 -- on systems where Address is a visible integer type.
6808 if Is_Overloaded
(N
)
6809 and then Nkind
(N
) in N_Op
6810 and then Is_Integer_Type
(Etype
(N
))
6812 if Nkind
(N
) in N_Binary_Op
then
6813 if Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
6814 Remove_Address_Interpretations
(Second_Op
);
6816 elsif Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
6817 Remove_Address_Interpretations
(First_Op
);
6822 elsif Nkind
(N
) in N_Op
then
6824 -- Remove interpretations that treat literals as addresses. This
6825 -- is never appropriate, even when Address is defined as a visible
6826 -- Integer type. The reason is that we would really prefer Address
6827 -- to behave as a private type, even in this case. If Address is a
6828 -- visible integer type, we get lots of overload ambiguities.
6830 if Nkind
(N
) in N_Binary_Op
then
6832 U1
: constant Boolean :=
6833 Present
(Universal_Interpretation
(Right_Opnd
(N
)));
6834 U2
: constant Boolean :=
6835 Present
(Universal_Interpretation
(Left_Opnd
(N
)));
6839 Remove_Address_Interpretations
(Second_Op
);
6843 Remove_Address_Interpretations
(First_Op
);
6846 if not (U1
and U2
) then
6848 -- Remove corresponding predefined operator, which is
6849 -- always added to the overload set.
6851 Get_First_Interp
(N
, I
, It
);
6852 while Present
(It
.Nam
) loop
6853 if Scope
(It
.Nam
) = Standard_Standard
6854 and then Base_Type
(It
.Typ
) =
6855 Base_Type
(Etype
(Abstract_Op
))
6860 Get_Next_Interp
(I
, It
);
6863 elsif Is_Overloaded
(N
)
6864 and then Present
(Univ_Type
)
6866 -- If both operands have a universal interpretation,
6867 -- it is still necessary to remove interpretations that
6868 -- yield Address. Any remaining ambiguities will be
6869 -- removed in Disambiguate.
6871 Get_First_Interp
(N
, I
, It
);
6872 while Present
(It
.Nam
) loop
6873 if Is_Descendent_Of_Address
(It
.Typ
) then
6876 elsif not Is_Type
(It
.Nam
) then
6877 Set_Entity
(N
, It
.Nam
);
6880 Get_Next_Interp
(I
, It
);
6886 elsif Nkind
(N
) = N_Function_Call
6888 (Nkind
(Name
(N
)) = N_Operator_Symbol
6890 (Nkind
(Name
(N
)) = N_Expanded_Name
6892 Nkind
(Selector_Name
(Name
(N
))) = N_Operator_Symbol
))
6896 Arg1
: constant Node_Id
:= First
(Parameter_Associations
(N
));
6897 U1
: constant Boolean :=
6898 Present
(Universal_Interpretation
(Arg1
));
6899 U2
: constant Boolean :=
6900 Present
(Next
(Arg1
)) and then
6901 Present
(Universal_Interpretation
(Next
(Arg1
)));
6905 Remove_Address_Interpretations
(First_Op
);
6909 Remove_Address_Interpretations
(Second_Op
);
6912 if not (U1
and U2
) then
6913 Get_First_Interp
(N
, I
, It
);
6914 while Present
(It
.Nam
) loop
6915 if Scope
(It
.Nam
) = Standard_Standard
6916 and then It
.Typ
= Base_Type
(Etype
(Abstract_Op
))
6921 Get_Next_Interp
(I
, It
);
6927 -- If the removal has left no valid interpretations, emit an error
6928 -- message now and label node as illegal.
6930 if Present
(Abstract_Op
) then
6931 Get_First_Interp
(N
, I
, It
);
6935 -- Removal of abstract operation left no viable candidate
6937 Set_Etype
(N
, Any_Type
);
6938 Error_Msg_Sloc
:= Sloc
(Abstract_Op
);
6940 ("cannot call abstract operation& declared#", N
, Abstract_Op
);
6942 -- In Ada 2005, an abstract operation may disable predefined
6943 -- operators. Since the context is not yet known, we mark the
6944 -- predefined operators as potentially hidden. Do not include
6945 -- predefined operators when addresses are involved since this
6946 -- case is handled separately.
6948 elsif Ada_Version
>= Ada_2005
and then not Address_Descendent
then
6949 while Present
(It
.Nam
) loop
6950 if Is_Numeric_Type
(It
.Typ
)
6951 and then Scope
(It
.Typ
) = Standard_Standard
6953 Set_Abstract_Op
(I
, Abstract_Op
);
6956 Get_Next_Interp
(I
, It
);
6961 if Debug_Flag_V
then
6962 Write_Str
("Remove_Abstract_Operations done: ");
6963 Write_Overloads
(N
);
6966 end Remove_Abstract_Operations
;
6968 ----------------------------
6969 -- Try_Container_Indexing --
6970 ----------------------------
6972 function Try_Container_Indexing
6975 Exprs
: List_Id
) return Boolean
6977 Loc
: constant Source_Ptr
:= Sloc
(N
);
6981 Func_Name
: Node_Id
;
6985 C_Type
:= Etype
(Prefix
);
6987 -- If indexing a class-wide container, obtain indexing primitive
6988 -- from specific type.
6990 if Is_Class_Wide_Type
(C_Type
) then
6991 C_Type
:= Etype
(Base_Type
(C_Type
));
6994 -- Check whether type has a specified indexing aspect
6998 if Is_Variable
(Prefix
) then
7000 Find_Value_Of_Aspect
(Etype
(Prefix
), Aspect_Variable_Indexing
);
7003 if No
(Func_Name
) then
7005 Find_Value_Of_Aspect
(Etype
(Prefix
), Aspect_Constant_Indexing
);
7008 -- If aspect does not exist the expression is illegal. Error is
7009 -- diagnosed in caller.
7011 if No
(Func_Name
) then
7013 -- The prefix itself may be an indexing of a container: rewrite
7014 -- as such and re-analyze.
7016 if Has_Implicit_Dereference
(Etype
(Prefix
)) then
7017 Build_Explicit_Dereference
7018 (Prefix
, First_Discriminant
(Etype
(Prefix
)));
7019 return Try_Container_Indexing
(N
, Prefix
, Exprs
);
7025 -- If the container type is derived from another container type, the
7026 -- value of the inherited aspect is the Reference operation declared
7027 -- for the parent type.
7029 -- However, Reference is also a primitive operation of the type, and
7030 -- the inherited operation has a different signature. We retrieve the
7031 -- right one from the list of primitive operations of the derived type.
7033 -- Note that predefined containers are typically all derived from one
7034 -- of the Controlled types. The code below is motivated by containers
7035 -- that are derived from other types with a Reference aspect.
7037 -- Additional machinery may be needed for types that have several user-
7038 -- defined Reference operations with different signatures ???
7040 elsif Is_Derived_Type
(C_Type
)
7041 and then Etype
(First_Formal
(Entity
(Func_Name
))) /= Etype
(Prefix
)
7043 Func
:= Find_Prim_Op
(C_Type
, Chars
(Func_Name
));
7044 Func_Name
:= New_Occurrence_Of
(Func
, Loc
);
7047 Assoc
:= New_List
(Relocate_Node
(Prefix
));
7049 -- A generalized indexing may have nore than one index expression, so
7050 -- transfer all of them to the argument list to be used in the call.
7051 -- Note that there may be named associations, in which case the node
7052 -- was rewritten earlier as a call, and has been transformed back into
7053 -- an indexed expression to share the following processing.
7055 -- The generalized indexing node is the one on which analysis and
7056 -- resolution take place. Before expansion the original node is replaced
7057 -- with the generalized indexing node, which is a call, possibly with
7058 -- a dereference operation.
7060 if Comes_From_Source
(N
) then
7061 Check_Compiler_Unit
("generalized indexing", N
);
7067 Arg
:= First
(Exprs
);
7068 while Present
(Arg
) loop
7069 Append
(Relocate_Node
(Arg
), Assoc
);
7074 if not Is_Overloaded
(Func_Name
) then
7075 Func
:= Entity
(Func_Name
);
7077 Make_Function_Call
(Loc
,
7078 Name
=> New_Occurrence_Of
(Func
, Loc
),
7079 Parameter_Associations
=> Assoc
);
7080 Set_Parent
(Indexing
, Parent
(N
));
7081 Set_Generalized_Indexing
(N
, Indexing
);
7083 Set_Etype
(N
, Etype
(Indexing
));
7085 -- If the return type of the indexing function is a reference type,
7086 -- add the dereference as a possible interpretation. Note that the
7087 -- indexing aspect may be a function that returns the element type
7088 -- with no intervening implicit dereference, and that the reference
7089 -- discriminant is not the first discriminant.
7091 if Has_Discriminants
(Etype
(Func
)) then
7092 Check_Implicit_Dereference
(N
, Etype
(Func
));
7097 Make_Function_Call
(Loc
,
7098 Name
=> Make_Identifier
(Loc
, Chars
(Func_Name
)),
7099 Parameter_Associations
=> Assoc
);
7101 Set_Parent
(Indexing
, Parent
(N
));
7102 Set_Generalized_Indexing
(N
, Indexing
);
7110 Get_First_Interp
(Func_Name
, I
, It
);
7111 Set_Etype
(Indexing
, Any_Type
);
7112 while Present
(It
.Nam
) loop
7113 Analyze_One_Call
(Indexing
, It
.Nam
, False, Success
);
7116 Set_Etype
(Name
(Indexing
), It
.Typ
);
7117 Set_Entity
(Name
(Indexing
), It
.Nam
);
7118 Set_Etype
(N
, Etype
(Indexing
));
7120 -- Add implicit dereference interpretation
7122 if Has_Discriminants
(Etype
(It
.Nam
)) then
7123 Check_Implicit_Dereference
(N
, Etype
(It
.Nam
));
7129 Get_Next_Interp
(I
, It
);
7134 if Etype
(Indexing
) = Any_Type
then
7136 ("container cannot be indexed with&", N
, Etype
(First
(Exprs
)));
7137 Rewrite
(N
, New_Occurrence_Of
(Any_Id
, Loc
));
7141 end Try_Container_Indexing
;
7143 -----------------------
7144 -- Try_Indirect_Call --
7145 -----------------------
7147 function Try_Indirect_Call
7150 Typ
: Entity_Id
) return Boolean
7156 pragma Warnings
(Off
, Call_OK
);
7159 Normalize_Actuals
(N
, Designated_Type
(Typ
), False, Call_OK
);
7161 Actual
:= First_Actual
(N
);
7162 Formal
:= First_Formal
(Designated_Type
(Typ
));
7163 while Present
(Actual
) and then Present
(Formal
) loop
7164 if not Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
7169 Next_Formal
(Formal
);
7172 if No
(Actual
) and then No
(Formal
) then
7173 Add_One_Interp
(N
, Nam
, Etype
(Designated_Type
(Typ
)));
7175 -- Nam is a candidate interpretation for the name in the call,
7176 -- if it is not an indirect call.
7178 if not Is_Type
(Nam
)
7179 and then Is_Entity_Name
(Name
(N
))
7181 Set_Entity
(Name
(N
), Nam
);
7189 end Try_Indirect_Call
;
7191 ----------------------
7192 -- Try_Indexed_Call --
7193 ----------------------
7195 function Try_Indexed_Call
7199 Skip_First
: Boolean) return Boolean
7201 Loc
: constant Source_Ptr
:= Sloc
(N
);
7202 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
7207 Actual
:= First
(Actuals
);
7209 -- If the call was originally written in prefix form, skip the first
7210 -- actual, which is obviously not defaulted.
7216 Index
:= First_Index
(Typ
);
7217 while Present
(Actual
) and then Present
(Index
) loop
7219 -- If the parameter list has a named association, the expression
7220 -- is definitely a call and not an indexed component.
7222 if Nkind
(Actual
) = N_Parameter_Association
then
7226 if Is_Entity_Name
(Actual
)
7227 and then Is_Type
(Entity
(Actual
))
7228 and then No
(Next
(Actual
))
7230 -- A single actual that is a type name indicates a slice if the
7231 -- type is discrete, and an error otherwise.
7233 if Is_Discrete_Type
(Entity
(Actual
)) then
7237 Make_Function_Call
(Loc
,
7238 Name
=> Relocate_Node
(Name
(N
))),
7240 New_Occurrence_Of
(Entity
(Actual
), Sloc
(Actual
))));
7245 Error_Msg_N
("invalid use of type in expression", Actual
);
7246 Set_Etype
(N
, Any_Type
);
7251 elsif not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
7259 if No
(Actual
) and then No
(Index
) then
7260 Add_One_Interp
(N
, Nam
, Component_Type
(Typ
));
7262 -- Nam is a candidate interpretation for the name in the call,
7263 -- if it is not an indirect call.
7265 if not Is_Type
(Nam
)
7266 and then Is_Entity_Name
(Name
(N
))
7268 Set_Entity
(Name
(N
), Nam
);
7275 end Try_Indexed_Call
;
7277 --------------------------
7278 -- Try_Object_Operation --
7279 --------------------------
7281 function Try_Object_Operation
7282 (N
: Node_Id
; CW_Test_Only
: Boolean := False) return Boolean
7284 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
7285 Is_Subprg_Call
: constant Boolean := K
in N_Subprogram_Call
;
7286 Loc
: constant Source_Ptr
:= Sloc
(N
);
7287 Obj
: constant Node_Id
:= Prefix
(N
);
7289 Subprog
: constant Node_Id
:=
7290 Make_Identifier
(Sloc
(Selector_Name
(N
)),
7291 Chars
=> Chars
(Selector_Name
(N
)));
7292 -- Identifier on which possible interpretations will be collected
7294 Report_Error
: Boolean := False;
7295 -- If no candidate interpretation matches the context, redo analysis
7296 -- with Report_Error True to provide additional information.
7299 Candidate
: Entity_Id
:= Empty
;
7300 New_Call_Node
: Node_Id
:= Empty
;
7301 Node_To_Replace
: Node_Id
;
7302 Obj_Type
: Entity_Id
:= Etype
(Obj
);
7303 Success
: Boolean := False;
7305 function Valid_Candidate
7308 Subp
: Entity_Id
) return Entity_Id
;
7309 -- If the subprogram is a valid interpretation, record it, and add
7310 -- to the list of interpretations of Subprog. Otherwise return Empty.
7312 procedure Complete_Object_Operation
7313 (Call_Node
: Node_Id
;
7314 Node_To_Replace
: Node_Id
);
7315 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
7316 -- Call_Node, insert the object (or its dereference) as the first actual
7317 -- in the call, and complete the analysis of the call.
7319 procedure Report_Ambiguity
(Op
: Entity_Id
);
7320 -- If a prefixed procedure call is ambiguous, indicate whether the
7321 -- call includes an implicit dereference or an implicit 'Access.
7323 procedure Transform_Object_Operation
7324 (Call_Node
: out Node_Id
;
7325 Node_To_Replace
: out Node_Id
);
7326 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
7327 -- Call_Node is the resulting subprogram call, Node_To_Replace is
7328 -- either N or the parent of N, and Subprog is a reference to the
7329 -- subprogram we are trying to match.
7331 function Try_Class_Wide_Operation
7332 (Call_Node
: Node_Id
;
7333 Node_To_Replace
: Node_Id
) return Boolean;
7334 -- Traverse all ancestor types looking for a class-wide subprogram
7335 -- for which the current operation is a valid non-dispatching call.
7337 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
);
7338 -- If prefix is overloaded, its interpretation may include different
7339 -- tagged types, and we must examine the primitive operations and
7340 -- the class-wide operations of each in order to find candidate
7341 -- interpretations for the call as a whole.
7343 function Try_Primitive_Operation
7344 (Call_Node
: Node_Id
;
7345 Node_To_Replace
: Node_Id
) return Boolean;
7346 -- Traverse the list of primitive subprograms looking for a dispatching
7347 -- operation for which the current node is a valid call .
7349 ---------------------
7350 -- Valid_Candidate --
7351 ---------------------
7353 function Valid_Candidate
7356 Subp
: Entity_Id
) return Entity_Id
7358 Arr_Type
: Entity_Id
;
7359 Comp_Type
: Entity_Id
;
7362 -- If the subprogram is a valid interpretation, record it in global
7363 -- variable Subprog, to collect all possible overloadings.
7366 if Subp
/= Entity
(Subprog
) then
7367 Add_One_Interp
(Subprog
, Subp
, Etype
(Subp
));
7371 -- If the call may be an indexed call, retrieve component type of
7372 -- resulting expression, and add possible interpretation.
7377 if Nkind
(Call
) = N_Function_Call
7378 and then Nkind
(Parent
(N
)) = N_Indexed_Component
7379 and then Needs_One_Actual
(Subp
)
7381 if Is_Array_Type
(Etype
(Subp
)) then
7382 Arr_Type
:= Etype
(Subp
);
7384 elsif Is_Access_Type
(Etype
(Subp
))
7385 and then Is_Array_Type
(Designated_Type
(Etype
(Subp
)))
7387 Arr_Type
:= Designated_Type
(Etype
(Subp
));
7391 if Present
(Arr_Type
) then
7393 -- Verify that the actuals (excluding the object) match the types
7401 Actual
:= Next
(First_Actual
(Call
));
7402 Index
:= First_Index
(Arr_Type
);
7403 while Present
(Actual
) and then Present
(Index
) loop
7404 if not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
7409 Next_Actual
(Actual
);
7415 and then Present
(Arr_Type
)
7417 Comp_Type
:= Component_Type
(Arr_Type
);
7421 if Present
(Comp_Type
)
7422 and then Etype
(Subprog
) /= Comp_Type
7424 Add_One_Interp
(Subprog
, Subp
, Comp_Type
);
7428 if Etype
(Call
) /= Any_Type
then
7433 end Valid_Candidate
;
7435 -------------------------------
7436 -- Complete_Object_Operation --
7437 -------------------------------
7439 procedure Complete_Object_Operation
7440 (Call_Node
: Node_Id
;
7441 Node_To_Replace
: Node_Id
)
7443 Control
: constant Entity_Id
:= First_Formal
(Entity
(Subprog
));
7444 Formal_Type
: constant Entity_Id
:= Etype
(Control
);
7445 First_Actual
: Node_Id
;
7448 -- Place the name of the operation, with its interpretations,
7449 -- on the rewritten call.
7451 Set_Name
(Call_Node
, Subprog
);
7453 First_Actual
:= First
(Parameter_Associations
(Call_Node
));
7455 -- For cross-reference purposes, treat the new node as being in the
7456 -- source if the original one is. Set entity and type, even though
7457 -- they may be overwritten during resolution if overloaded.
7459 Set_Comes_From_Source
(Subprog
, Comes_From_Source
(N
));
7460 Set_Comes_From_Source
(Call_Node
, Comes_From_Source
(N
));
7462 if Nkind
(N
) = N_Selected_Component
7463 and then not Inside_A_Generic
7465 Set_Entity
(Selector_Name
(N
), Entity
(Subprog
));
7466 Set_Etype
(Selector_Name
(N
), Etype
(Entity
(Subprog
)));
7469 -- If need be, rewrite first actual as an explicit dereference. If
7470 -- the call is overloaded, the rewriting can only be done once the
7471 -- primitive operation is identified.
7473 if Is_Overloaded
(Subprog
) then
7475 -- The prefix itself may be overloaded, and its interpretations
7476 -- must be propagated to the new actual in the call.
7478 if Is_Overloaded
(Obj
) then
7479 Save_Interps
(Obj
, First_Actual
);
7482 Rewrite
(First_Actual
, Obj
);
7484 elsif not Is_Access_Type
(Formal_Type
)
7485 and then Is_Access_Type
(Etype
(Obj
))
7487 Rewrite
(First_Actual
,
7488 Make_Explicit_Dereference
(Sloc
(Obj
), Obj
));
7489 Analyze
(First_Actual
);
7491 -- If we need to introduce an explicit dereference, verify that
7492 -- the resulting actual is compatible with the mode of the formal.
7494 if Ekind
(First_Formal
(Entity
(Subprog
))) /= E_In_Parameter
7495 and then Is_Access_Constant
(Etype
(Obj
))
7498 ("expect variable in call to&", Prefix
(N
), Entity
(Subprog
));
7501 -- Conversely, if the formal is an access parameter and the object
7502 -- is not, replace the actual with a 'Access reference. Its analysis
7503 -- will check that the object is aliased.
7505 elsif Is_Access_Type
(Formal_Type
)
7506 and then not Is_Access_Type
(Etype
(Obj
))
7508 -- A special case: A.all'access is illegal if A is an access to a
7509 -- constant and the context requires an access to a variable.
7511 if not Is_Access_Constant
(Formal_Type
) then
7512 if (Nkind
(Obj
) = N_Explicit_Dereference
7513 and then Is_Access_Constant
(Etype
(Prefix
(Obj
))))
7514 or else not Is_Variable
(Obj
)
7517 ("actual for & must be a variable", Obj
, Control
);
7521 Rewrite
(First_Actual
,
7522 Make_Attribute_Reference
(Loc
,
7523 Attribute_Name
=> Name_Access
,
7524 Prefix
=> Relocate_Node
(Obj
)));
7526 if not Is_Aliased_View
(Obj
) then
7528 ("object in prefixed call to & must be aliased "
7529 & "(RM 4.1.3 (13 1/2))", Prefix
(First_Actual
), Subprog
);
7532 Analyze
(First_Actual
);
7535 if Is_Overloaded
(Obj
) then
7536 Save_Interps
(Obj
, First_Actual
);
7539 Rewrite
(First_Actual
, Obj
);
7542 -- The operation is obtained from the dispatch table and not by
7543 -- visibility, and may be declared in a unit that is not explicitly
7544 -- referenced in the source, but is nevertheless required in the
7545 -- context of the current unit. Indicate that operation and its scope
7546 -- are referenced, to prevent spurious and misleading warnings. If
7547 -- the operation is overloaded, all primitives are in the same scope
7548 -- and we can use any of them.
7550 Set_Referenced
(Entity
(Subprog
), True);
7551 Set_Referenced
(Scope
(Entity
(Subprog
)), True);
7553 Rewrite
(Node_To_Replace
, Call_Node
);
7555 -- Propagate the interpretations collected in subprog to the new
7556 -- function call node, to be resolved from context.
7558 if Is_Overloaded
(Subprog
) then
7559 Save_Interps
(Subprog
, Node_To_Replace
);
7562 -- The type of the subprogram may be a limited view obtained
7563 -- transitively from another unit. If full view is available,
7564 -- use it to analyze call.
7567 T
: constant Entity_Id
:= Etype
(Subprog
);
7569 if From_Limited_With
(T
) then
7570 Set_Etype
(Entity
(Subprog
), Available_View
(T
));
7574 Analyze
(Node_To_Replace
);
7576 -- If the operation has been rewritten into a call, which may get
7577 -- subsequently an explicit dereference, preserve the type on the
7578 -- original node (selected component or indexed component) for
7579 -- subsequent legality tests, e.g. Is_Variable. which examines
7580 -- the original node.
7582 if Nkind
(Node_To_Replace
) = N_Function_Call
then
7584 (Original_Node
(Node_To_Replace
), Etype
(Node_To_Replace
));
7587 end Complete_Object_Operation
;
7589 ----------------------
7590 -- Report_Ambiguity --
7591 ----------------------
7593 procedure Report_Ambiguity
(Op
: Entity_Id
) is
7594 Access_Actual
: constant Boolean :=
7595 Is_Access_Type
(Etype
(Prefix
(N
)));
7596 Access_Formal
: Boolean := False;
7599 Error_Msg_Sloc
:= Sloc
(Op
);
7601 if Present
(First_Formal
(Op
)) then
7602 Access_Formal
:= Is_Access_Type
(Etype
(First_Formal
(Op
)));
7605 if Access_Formal
and then not Access_Actual
then
7606 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
7608 ("\possible interpretation "
7609 & "(inherited, with implicit 'Access) #", N
);
7612 ("\possible interpretation (with implicit 'Access) #", N
);
7615 elsif not Access_Formal
and then Access_Actual
then
7616 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
7618 ("\possible interpretation "
7619 & "(inherited, with implicit dereference) #", N
);
7622 ("\possible interpretation (with implicit dereference) #", N
);
7626 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
7627 Error_Msg_N
("\possible interpretation (inherited)#", N
);
7629 Error_Msg_N
-- CODEFIX
7630 ("\possible interpretation#", N
);
7633 end Report_Ambiguity
;
7635 --------------------------------
7636 -- Transform_Object_Operation --
7637 --------------------------------
7639 procedure Transform_Object_Operation
7640 (Call_Node
: out Node_Id
;
7641 Node_To_Replace
: out Node_Id
)
7643 Dummy
: constant Node_Id
:= New_Copy
(Obj
);
7644 -- Placeholder used as a first parameter in the call, replaced
7645 -- eventually by the proper object.
7647 Parent_Node
: constant Node_Id
:= Parent
(N
);
7653 -- Common case covering 1) Call to a procedure and 2) Call to a
7654 -- function that has some additional actuals.
7656 if Nkind
(Parent_Node
) in N_Subprogram_Call
7658 -- N is a selected component node containing the name of the
7659 -- subprogram. If N is not the name of the parent node we must
7660 -- not replace the parent node by the new construct. This case
7661 -- occurs when N is a parameterless call to a subprogram that
7662 -- is an actual parameter of a call to another subprogram. For
7664 -- Some_Subprogram (..., Obj.Operation, ...)
7666 and then Name
(Parent_Node
) = N
7668 Node_To_Replace
:= Parent_Node
;
7670 Actuals
:= Parameter_Associations
(Parent_Node
);
7672 if Present
(Actuals
) then
7673 Prepend
(Dummy
, Actuals
);
7675 Actuals
:= New_List
(Dummy
);
7678 if Nkind
(Parent_Node
) = N_Procedure_Call_Statement
then
7680 Make_Procedure_Call_Statement
(Loc
,
7681 Name
=> New_Copy
(Subprog
),
7682 Parameter_Associations
=> Actuals
);
7686 Make_Function_Call
(Loc
,
7687 Name
=> New_Copy
(Subprog
),
7688 Parameter_Associations
=> Actuals
);
7691 -- Before analysis, a function call appears as an indexed component
7692 -- if there are no named associations.
7694 elsif Nkind
(Parent_Node
) = N_Indexed_Component
7695 and then N
= Prefix
(Parent_Node
)
7697 Node_To_Replace
:= Parent_Node
;
7698 Actuals
:= Expressions
(Parent_Node
);
7700 Actual
:= First
(Actuals
);
7701 while Present
(Actual
) loop
7706 Prepend
(Dummy
, Actuals
);
7709 Make_Function_Call
(Loc
,
7710 Name
=> New_Copy
(Subprog
),
7711 Parameter_Associations
=> Actuals
);
7713 -- Parameterless call: Obj.F is rewritten as F (Obj)
7716 Node_To_Replace
:= N
;
7719 Make_Function_Call
(Loc
,
7720 Name
=> New_Copy
(Subprog
),
7721 Parameter_Associations
=> New_List
(Dummy
));
7723 end Transform_Object_Operation
;
7725 ------------------------------
7726 -- Try_Class_Wide_Operation --
7727 ------------------------------
7729 function Try_Class_Wide_Operation
7730 (Call_Node
: Node_Id
;
7731 Node_To_Replace
: Node_Id
) return Boolean
7733 Anc_Type
: Entity_Id
;
7734 Matching_Op
: Entity_Id
:= Empty
;
7737 procedure Traverse_Homonyms
7738 (Anc_Type
: Entity_Id
;
7739 Error
: out Boolean);
7740 -- Traverse the homonym chain of the subprogram searching for those
7741 -- homonyms whose first formal has the Anc_Type's class-wide type,
7742 -- or an anonymous access type designating the class-wide type. If
7743 -- an ambiguity is detected, then Error is set to True.
7745 procedure Traverse_Interfaces
7746 (Anc_Type
: Entity_Id
;
7747 Error
: out Boolean);
7748 -- Traverse the list of interfaces, if any, associated with Anc_Type
7749 -- and search for acceptable class-wide homonyms associated with each
7750 -- interface. If an ambiguity is detected, then Error is set to True.
7752 -----------------------
7753 -- Traverse_Homonyms --
7754 -----------------------
7756 procedure Traverse_Homonyms
7757 (Anc_Type
: Entity_Id
;
7758 Error
: out Boolean)
7760 Cls_Type
: Entity_Id
;
7768 Cls_Type
:= Class_Wide_Type
(Anc_Type
);
7770 Hom
:= Current_Entity
(Subprog
);
7772 -- Find a non-hidden operation whose first parameter is of the
7773 -- class-wide type, a subtype thereof, or an anonymous access
7774 -- to same. If in an instance, the operation can be considered
7775 -- even if hidden (it may be hidden because the instantiation
7776 -- is expanded after the containing package has been analyzed).
7778 while Present
(Hom
) loop
7779 if Ekind_In
(Hom
, E_Procedure
, E_Function
)
7780 and then (not Is_Hidden
(Hom
) or else In_Instance
)
7781 and then Scope
(Hom
) = Scope
(Anc_Type
)
7782 and then Present
(First_Formal
(Hom
))
7784 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
7786 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
7788 Ekind
(Etype
(First_Formal
(Hom
))) =
7789 E_Anonymous_Access_Type
7792 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
7795 -- If the context is a procedure call, ignore functions
7796 -- in the name of the call.
7798 if Ekind
(Hom
) = E_Function
7799 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
7800 and then N
= Name
(Parent
(N
))
7804 -- If the context is a function call, ignore procedures
7805 -- in the name of the call.
7807 elsif Ekind
(Hom
) = E_Procedure
7808 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
7813 Set_Etype
(Call_Node
, Any_Type
);
7814 Set_Is_Overloaded
(Call_Node
, False);
7817 if No
(Matching_Op
) then
7818 Hom_Ref
:= New_Occurrence_Of
(Hom
, Sloc
(Subprog
));
7819 Set_Etype
(Call_Node
, Any_Type
);
7820 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
7822 Set_Name
(Call_Node
, Hom_Ref
);
7827 Report
=> Report_Error
,
7829 Skip_First
=> True);
7832 Valid_Candidate
(Success
, Call_Node
, Hom
);
7838 Report
=> Report_Error
,
7840 Skip_First
=> True);
7842 if Present
(Valid_Candidate
(Success
, Call_Node
, Hom
))
7843 and then Nkind
(Call_Node
) /= N_Function_Call
7845 Error_Msg_NE
("ambiguous call to&", N
, Hom
);
7846 Report_Ambiguity
(Matching_Op
);
7847 Report_Ambiguity
(Hom
);
7855 Hom
:= Homonym
(Hom
);
7857 end Traverse_Homonyms
;
7859 -------------------------
7860 -- Traverse_Interfaces --
7861 -------------------------
7863 procedure Traverse_Interfaces
7864 (Anc_Type
: Entity_Id
;
7865 Error
: out Boolean)
7867 Intface_List
: constant List_Id
:=
7868 Abstract_Interface_List
(Anc_Type
);
7874 if Is_Non_Empty_List
(Intface_List
) then
7875 Intface
:= First
(Intface_List
);
7876 while Present
(Intface
) loop
7878 -- Look for acceptable class-wide homonyms associated with
7881 Traverse_Homonyms
(Etype
(Intface
), Error
);
7887 -- Continue the search by looking at each of the interface's
7888 -- associated interface ancestors.
7890 Traverse_Interfaces
(Etype
(Intface
), Error
);
7899 end Traverse_Interfaces
;
7901 -- Start of processing for Try_Class_Wide_Operation
7904 -- If we are searching only for conflicting class-wide subprograms
7905 -- then initialize directly Matching_Op with the target entity.
7907 if CW_Test_Only
then
7908 Matching_Op
:= Entity
(Selector_Name
(N
));
7911 -- Loop through ancestor types (including interfaces), traversing
7912 -- the homonym chain of the subprogram, trying out those homonyms
7913 -- whose first formal has the class-wide type of the ancestor, or
7914 -- an anonymous access type designating the class-wide type.
7916 Anc_Type
:= Obj_Type
;
7918 -- Look for a match among homonyms associated with the ancestor
7920 Traverse_Homonyms
(Anc_Type
, Error
);
7926 -- Continue the search for matches among homonyms associated with
7927 -- any interfaces implemented by the ancestor.
7929 Traverse_Interfaces
(Anc_Type
, Error
);
7935 exit when Etype
(Anc_Type
) = Anc_Type
;
7936 Anc_Type
:= Etype
(Anc_Type
);
7939 if Present
(Matching_Op
) then
7940 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
7943 return Present
(Matching_Op
);
7944 end Try_Class_Wide_Operation
;
7946 -----------------------------------
7947 -- Try_One_Prefix_Interpretation --
7948 -----------------------------------
7950 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
) is
7954 if Is_Access_Type
(Obj_Type
) then
7955 Obj_Type
:= Designated_Type
(Obj_Type
);
7958 if Ekind
(Obj_Type
) = E_Private_Subtype
then
7959 Obj_Type
:= Base_Type
(Obj_Type
);
7962 if Is_Class_Wide_Type
(Obj_Type
) then
7963 Obj_Type
:= Etype
(Class_Wide_Type
(Obj_Type
));
7966 -- The type may have be obtained through a limited_with clause,
7967 -- in which case the primitive operations are available on its
7968 -- non-limited view. If still incomplete, retrieve full view.
7970 if Ekind
(Obj_Type
) = E_Incomplete_Type
7971 and then From_Limited_With
(Obj_Type
)
7973 Obj_Type
:= Get_Full_View
(Non_Limited_View
(Obj_Type
));
7976 -- If the object is not tagged, or the type is still an incomplete
7977 -- type, this is not a prefixed call.
7979 if not Is_Tagged_Type
(Obj_Type
)
7980 or else Is_Incomplete_Type
(Obj_Type
)
7986 Dup_Call_Node
: constant Node_Id
:= New_Copy
(New_Call_Node
);
7987 CW_Result
: Boolean;
7988 Prim_Result
: Boolean;
7989 pragma Unreferenced
(CW_Result
);
7992 if not CW_Test_Only
then
7994 Try_Primitive_Operation
7995 (Call_Node
=> New_Call_Node
,
7996 Node_To_Replace
=> Node_To_Replace
);
7999 -- Check if there is a class-wide subprogram covering the
8000 -- primitive. This check must be done even if a candidate
8001 -- was found in order to report ambiguous calls.
8003 if not (Prim_Result
) then
8005 Try_Class_Wide_Operation
8006 (Call_Node
=> New_Call_Node
,
8007 Node_To_Replace
=> Node_To_Replace
);
8009 -- If we found a primitive we search for class-wide subprograms
8010 -- using a duplicate of the call node (done to avoid missing its
8011 -- decoration if there is no ambiguity).
8015 Try_Class_Wide_Operation
8016 (Call_Node
=> Dup_Call_Node
,
8017 Node_To_Replace
=> Node_To_Replace
);
8020 end Try_One_Prefix_Interpretation
;
8022 -----------------------------
8023 -- Try_Primitive_Operation --
8024 -----------------------------
8026 function Try_Primitive_Operation
8027 (Call_Node
: Node_Id
;
8028 Node_To_Replace
: Node_Id
) return Boolean
8031 Prim_Op
: Entity_Id
;
8032 Matching_Op
: Entity_Id
:= Empty
;
8033 Prim_Op_Ref
: Node_Id
:= Empty
;
8035 Corr_Type
: Entity_Id
:= Empty
;
8036 -- If the prefix is a synchronized type, the controlling type of
8037 -- the primitive operation is the corresponding record type, else
8038 -- this is the object type itself.
8040 Success
: Boolean := False;
8042 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
;
8043 -- For tagged types the candidate interpretations are found in
8044 -- the list of primitive operations of the type and its ancestors.
8045 -- For formal tagged types we have to find the operations declared
8046 -- in the same scope as the type (including in the generic formal
8047 -- part) because the type itself carries no primitive operations,
8048 -- except for formal derived types that inherit the operations of
8049 -- the parent and progenitors.
8051 -- If the context is a generic subprogram body, the generic formals
8052 -- are visible by name, but are not in the entity list of the
8053 -- subprogram because that list starts with the subprogram formals.
8054 -- We retrieve the candidate operations from the generic declaration.
8056 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean;
8057 -- An operation that overrides an inherited operation in the private
8058 -- part of its package may be hidden, but if the inherited operation
8059 -- is visible a direct call to it will dispatch to the private one,
8060 -- which is therefore a valid candidate.
8062 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean;
8063 -- Verify that the prefix, dereferenced if need be, is a valid
8064 -- controlling argument in a call to Op. The remaining actuals
8065 -- are checked in the subsequent call to Analyze_One_Call.
8067 ------------------------------
8068 -- Collect_Generic_Type_Ops --
8069 ------------------------------
8071 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
is
8072 Bas
: constant Entity_Id
:= Base_Type
(T
);
8073 Candidates
: constant Elist_Id
:= New_Elmt_List
;
8077 procedure Check_Candidate
;
8078 -- The operation is a candidate if its first parameter is a
8079 -- controlling operand of the desired type.
8081 -----------------------
8082 -- Check_Candidate; --
8083 -----------------------
8085 procedure Check_Candidate
is
8087 Formal
:= First_Formal
(Subp
);
8090 and then Is_Controlling_Formal
(Formal
)
8092 (Base_Type
(Etype
(Formal
)) = Bas
8094 (Is_Access_Type
(Etype
(Formal
))
8095 and then Designated_Type
(Etype
(Formal
)) = Bas
))
8097 Append_Elmt
(Subp
, Candidates
);
8099 end Check_Candidate
;
8101 -- Start of processing for Collect_Generic_Type_Ops
8104 if Is_Derived_Type
(T
) then
8105 return Primitive_Operations
(T
);
8107 elsif Ekind_In
(Scope
(T
), E_Procedure
, E_Function
) then
8109 -- Scan the list of generic formals to find subprograms
8110 -- that may have a first controlling formal of the type.
8112 if Nkind
(Unit_Declaration_Node
(Scope
(T
))) =
8113 N_Generic_Subprogram_Declaration
8120 First
(Generic_Formal_Declarations
8121 (Unit_Declaration_Node
(Scope
(T
))));
8122 while Present
(Decl
) loop
8123 if Nkind
(Decl
) in N_Formal_Subprogram_Declaration
then
8124 Subp
:= Defining_Entity
(Decl
);
8135 -- Scan the list of entities declared in the same scope as
8136 -- the type. In general this will be an open scope, given that
8137 -- the call we are analyzing can only appear within a generic
8138 -- declaration or body (either the one that declares T, or a
8141 -- For a subtype representing a generic actual type, go to the
8144 if Is_Generic_Actual_Type
(T
) then
8145 Subp
:= First_Entity
(Scope
(Base_Type
(T
)));
8147 Subp
:= First_Entity
(Scope
(T
));
8150 while Present
(Subp
) loop
8151 if Is_Overloadable
(Subp
) then
8160 end Collect_Generic_Type_Ops
;
8162 ---------------------------
8163 -- Is_Private_Overriding --
8164 ---------------------------
8166 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean is
8167 Visible_Op
: constant Entity_Id
:= Homonym
(Op
);
8170 return Present
(Visible_Op
)
8171 and then Scope
(Op
) = Scope
(Visible_Op
)
8172 and then not Comes_From_Source
(Visible_Op
)
8173 and then Alias
(Visible_Op
) = Op
8174 and then not Is_Hidden
(Visible_Op
);
8175 end Is_Private_Overriding
;
8177 -----------------------------
8178 -- Valid_First_Argument_Of --
8179 -----------------------------
8181 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean is
8182 Typ
: Entity_Id
:= Etype
(First_Formal
(Op
));
8185 if Is_Concurrent_Type
(Typ
)
8186 and then Present
(Corresponding_Record_Type
(Typ
))
8188 Typ
:= Corresponding_Record_Type
(Typ
);
8191 -- Simple case. Object may be a subtype of the tagged type or
8192 -- may be the corresponding record of a synchronized type.
8194 return Obj_Type
= Typ
8195 or else Base_Type
(Obj_Type
) = Typ
8196 or else Corr_Type
= Typ
8198 -- Prefix can be dereferenced
8201 (Is_Access_Type
(Corr_Type
)
8202 and then Designated_Type
(Corr_Type
) = Typ
)
8204 -- Formal is an access parameter, for which the object
8205 -- can provide an access.
8208 (Ekind
(Typ
) = E_Anonymous_Access_Type
8210 Base_Type
(Designated_Type
(Typ
)) = Base_Type
(Corr_Type
));
8211 end Valid_First_Argument_Of
;
8213 -- Start of processing for Try_Primitive_Operation
8216 -- Look for subprograms in the list of primitive operations. The name
8217 -- must be identical, and the kind of call indicates the expected
8218 -- kind of operation (function or procedure). If the type is a
8219 -- (tagged) synchronized type, the primitive ops are attached to the
8220 -- corresponding record (base) type.
8222 if Is_Concurrent_Type
(Obj_Type
) then
8223 if Present
(Corresponding_Record_Type
(Obj_Type
)) then
8224 Corr_Type
:= Base_Type
(Corresponding_Record_Type
(Obj_Type
));
8225 Elmt
:= First_Elmt
(Primitive_Operations
(Corr_Type
));
8227 Corr_Type
:= Obj_Type
;
8228 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
8231 elsif not Is_Generic_Type
(Obj_Type
) then
8232 Corr_Type
:= Obj_Type
;
8233 Elmt
:= First_Elmt
(Primitive_Operations
(Obj_Type
));
8236 Corr_Type
:= Obj_Type
;
8237 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
8240 while Present
(Elmt
) loop
8241 Prim_Op
:= Node
(Elmt
);
8243 if Chars
(Prim_Op
) = Chars
(Subprog
)
8244 and then Present
(First_Formal
(Prim_Op
))
8245 and then Valid_First_Argument_Of
(Prim_Op
)
8247 (Nkind
(Call_Node
) = N_Function_Call
)
8249 (Ekind
(Prim_Op
) = E_Function
)
8251 -- Ada 2005 (AI-251): If this primitive operation corresponds
8252 -- to an immediate ancestor interface there is no need to add
8253 -- it to the list of interpretations; the corresponding aliased
8254 -- primitive is also in this list of primitive operations and
8255 -- will be used instead.
8257 if (Present
(Interface_Alias
(Prim_Op
))
8258 and then Is_Ancestor
(Find_Dispatching_Type
8259 (Alias
(Prim_Op
)), Corr_Type
))
8261 -- Do not consider hidden primitives unless the type is in an
8262 -- open scope or we are within an instance, where visibility
8263 -- is known to be correct, or else if this is an overriding
8264 -- operation in the private part for an inherited operation.
8266 or else (Is_Hidden
(Prim_Op
)
8267 and then not Is_Immediately_Visible
(Obj_Type
)
8268 and then not In_Instance
8269 and then not Is_Private_Overriding
(Prim_Op
))
8274 Set_Etype
(Call_Node
, Any_Type
);
8275 Set_Is_Overloaded
(Call_Node
, False);
8277 if No
(Matching_Op
) then
8278 Prim_Op_Ref
:= New_Occurrence_Of
(Prim_Op
, Sloc
(Subprog
));
8279 Candidate
:= Prim_Op
;
8281 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
8283 Set_Name
(Call_Node
, Prim_Op_Ref
);
8289 Report
=> Report_Error
,
8291 Skip_First
=> True);
8293 Matching_Op
:= Valid_Candidate
(Success
, Call_Node
, Prim_Op
);
8295 -- More than one interpretation, collect for subsequent
8296 -- disambiguation. If this is a procedure call and there
8297 -- is another match, report ambiguity now.
8303 Report
=> Report_Error
,
8305 Skip_First
=> True);
8307 if Present
(Valid_Candidate
(Success
, Call_Node
, Prim_Op
))
8308 and then Nkind
(Call_Node
) /= N_Function_Call
8310 Error_Msg_NE
("ambiguous call to&", N
, Prim_Op
);
8311 Report_Ambiguity
(Matching_Op
);
8312 Report_Ambiguity
(Prim_Op
);
8322 if Present
(Matching_Op
) then
8323 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
8326 return Present
(Matching_Op
);
8327 end Try_Primitive_Operation
;
8329 -- Start of processing for Try_Object_Operation
8332 Analyze_Expression
(Obj
);
8334 -- Analyze the actuals if node is known to be a subprogram call
8336 if Is_Subprg_Call
and then N
= Name
(Parent
(N
)) then
8337 Actual
:= First
(Parameter_Associations
(Parent
(N
)));
8338 while Present
(Actual
) loop
8339 Analyze_Expression
(Actual
);
8344 -- Build a subprogram call node, using a copy of Obj as its first
8345 -- actual. This is a placeholder, to be replaced by an explicit
8346 -- dereference when needed.
8348 Transform_Object_Operation
8349 (Call_Node
=> New_Call_Node
,
8350 Node_To_Replace
=> Node_To_Replace
);
8352 Set_Etype
(New_Call_Node
, Any_Type
);
8353 Set_Etype
(Subprog
, Any_Type
);
8354 Set_Parent
(New_Call_Node
, Parent
(Node_To_Replace
));
8356 if not Is_Overloaded
(Obj
) then
8357 Try_One_Prefix_Interpretation
(Obj_Type
);
8364 Get_First_Interp
(Obj
, I
, It
);
8365 while Present
(It
.Nam
) loop
8366 Try_One_Prefix_Interpretation
(It
.Typ
);
8367 Get_Next_Interp
(I
, It
);
8372 if Etype
(New_Call_Node
) /= Any_Type
then
8374 -- No need to complete the tree transformations if we are only
8375 -- searching for conflicting class-wide subprograms
8377 if CW_Test_Only
then
8380 Complete_Object_Operation
8381 (Call_Node
=> New_Call_Node
,
8382 Node_To_Replace
=> Node_To_Replace
);
8386 elsif Present
(Candidate
) then
8388 -- The argument list is not type correct. Re-analyze with error
8389 -- reporting enabled, and use one of the possible candidates.
8390 -- In All_Errors_Mode, re-analyze all failed interpretations.
8392 if All_Errors_Mode
then
8393 Report_Error
:= True;
8394 if Try_Primitive_Operation
8395 (Call_Node
=> New_Call_Node
,
8396 Node_To_Replace
=> Node_To_Replace
)
8399 Try_Class_Wide_Operation
8400 (Call_Node
=> New_Call_Node
,
8401 Node_To_Replace
=> Node_To_Replace
)
8408 (N
=> New_Call_Node
,
8412 Skip_First
=> True);
8415 -- No need for further errors
8420 -- There was no candidate operation, so report it as an error
8421 -- in the caller: Analyze_Selected_Component.
8425 end Try_Object_Operation
;
8431 procedure wpo
(T
: Entity_Id
) is
8436 if not Is_Tagged_Type
(T
) then
8440 E
:= First_Elmt
(Primitive_Operations
(Base_Type
(T
)));
8441 while Present
(E
) loop
8443 Write_Int
(Int
(Op
));
8444 Write_Str
(" === ");
8445 Write_Name
(Chars
(Op
));
8447 Write_Name
(Chars
(Scope
(Op
)));