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_Ghost_Subprogram_Call
;
858 -- Verify the legality of a call to a ghost subprogram. Such calls can
859 -- appear only in assertion expressions except subtype predicates or
860 -- from within another ghost subprogram.
862 procedure Check_Mixed_Parameter_And_Named_Associations
;
863 -- Check that parameter and named associations are not mixed. This is
864 -- a restriction in SPARK mode.
866 function Name_Denotes_Function
return Boolean;
867 -- If the type of the name is an access to subprogram, this may be the
868 -- type of a name, or the return type of the function being called. If
869 -- the name is not an entity then it can denote a protected function.
870 -- Until we distinguish Etype from Return_Type, we must use this routine
871 -- to resolve the meaning of the name in the call.
873 procedure No_Interpretation
;
874 -- Output error message when no valid interpretation exists
876 ---------------------------------
877 -- Check_Ghost_Subprogram_Call --
878 ---------------------------------
880 procedure Check_Ghost_Subprogram_Call
is
884 -- Do not perform the check while preanalyzing the enclosing context
885 -- because the call is not in its final place. Premature attempts to
886 -- verify the placement lead to bogus errors.
888 if In_Spec_Expression
then
891 -- The ghost subprogram appears inside an assertion expression which
892 -- is one of the allowed cases.
894 elsif In_Assertion_Expression_Pragma
(N
) then
897 -- Otherwise see if it inside another ghost subprogram
900 -- Loop to climb scopes
903 while Present
(S
) and then S
/= Standard_Standard
loop
905 -- The call appears inside another ghost subprogram
907 if Is_Ghost_Subprogram
(S
) then
914 -- If we fall through the loop it was not within another
915 -- ghost subprogram, so we have bad placement.
918 ("call to ghost subprogram must appear in assertion expression "
919 & "or another ghost subprogram", N
);
921 end Check_Ghost_Subprogram_Call
;
923 --------------------------------------------------
924 -- Check_Mixed_Parameter_And_Named_Associations --
925 --------------------------------------------------
927 procedure Check_Mixed_Parameter_And_Named_Associations
is
929 Named_Seen
: Boolean;
934 Actual
:= First
(Actuals
);
935 while Present
(Actual
) loop
936 case Nkind
(Actual
) is
937 when N_Parameter_Association
=>
939 Check_SPARK_05_Restriction
940 ("named association cannot follow positional one",
950 end Check_Mixed_Parameter_And_Named_Associations
;
952 ---------------------------
953 -- Name_Denotes_Function --
954 ---------------------------
956 function Name_Denotes_Function
return Boolean is
958 if Is_Entity_Name
(Nam
) then
959 return Ekind
(Entity
(Nam
)) = E_Function
;
961 elsif Nkind
(Nam
) = N_Selected_Component
then
962 return Ekind
(Entity
(Selector_Name
(Nam
))) = E_Function
;
967 end Name_Denotes_Function
;
969 -----------------------
970 -- No_Interpretation --
971 -----------------------
973 procedure No_Interpretation
is
974 L
: constant Boolean := Is_List_Member
(N
);
975 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
978 -- If the node is in a list whose parent is not an expression then it
979 -- must be an attempted procedure call.
981 if L
and then K
not in N_Subexpr
then
982 if Ekind
(Entity
(Nam
)) = E_Generic_Procedure
then
984 ("must instantiate generic procedure& before call",
988 ("procedure or entry name expected", Nam
);
991 -- Check for tasking cases where only an entry call will do
994 and then Nkind_In
(K
, N_Entry_Call_Alternative
,
995 N_Triggering_Alternative
)
997 Error_Msg_N
("entry name expected", Nam
);
999 -- Otherwise give general error message
1002 Error_Msg_N
("invalid prefix in call", Nam
);
1004 end No_Interpretation
;
1006 -- Start of processing for Analyze_Call
1009 if Restriction_Check_Required
(SPARK_05
) then
1010 Check_Mixed_Parameter_And_Named_Associations
;
1013 -- Initialize the type of the result of the call to the error type,
1014 -- which will be reset if the type is successfully resolved.
1016 Set_Etype
(N
, Any_Type
);
1020 if not Is_Overloaded
(Nam
) then
1022 -- Only one interpretation to check
1024 if Ekind
(Etype
(Nam
)) = E_Subprogram_Type
then
1025 Nam_Ent
:= Etype
(Nam
);
1027 -- If the prefix is an access_to_subprogram, this may be an indirect
1028 -- call. This is the case if the name in the call is not an entity
1029 -- name, or if it is a function name in the context of a procedure
1030 -- call. In this latter case, we have a call to a parameterless
1031 -- function that returns a pointer_to_procedure which is the entity
1032 -- being called. Finally, F (X) may be a call to a parameterless
1033 -- function that returns a pointer to a function with parameters.
1034 -- Note that if F returns an access-to-subprogram whose designated
1035 -- type is an array, F (X) cannot be interpreted as an indirect call
1036 -- through the result of the call to F.
1038 elsif Is_Access_Type
(Etype
(Nam
))
1039 and then Ekind
(Designated_Type
(Etype
(Nam
))) = E_Subprogram_Type
1041 (not Name_Denotes_Function
1042 or else Nkind
(N
) = N_Procedure_Call_Statement
1044 (Nkind
(Parent
(N
)) /= N_Explicit_Dereference
1045 and then Is_Entity_Name
(Nam
)
1046 and then No
(First_Formal
(Entity
(Nam
)))
1048 Is_Array_Type
(Etype
(Designated_Type
(Etype
(Nam
))))
1049 and then Present
(Actuals
)))
1051 Nam_Ent
:= Designated_Type
(Etype
(Nam
));
1052 Insert_Explicit_Dereference
(Nam
);
1054 -- Selected component case. Simple entry or protected operation,
1055 -- where the entry name is given by the selector name.
1057 elsif Nkind
(Nam
) = N_Selected_Component
then
1058 Nam_Ent
:= Entity
(Selector_Name
(Nam
));
1060 if not Ekind_In
(Nam_Ent
, E_Entry
,
1065 Error_Msg_N
("name in call is not a callable entity", Nam
);
1066 Set_Etype
(N
, Any_Type
);
1070 -- If the name is an Indexed component, it can be a call to a member
1071 -- of an entry family. The prefix must be a selected component whose
1072 -- selector is the entry. Analyze_Procedure_Call normalizes several
1073 -- kinds of call into this form.
1075 elsif Nkind
(Nam
) = N_Indexed_Component
then
1076 if Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
1077 Nam_Ent
:= Entity
(Selector_Name
(Prefix
(Nam
)));
1079 Error_Msg_N
("name in call is not a callable entity", Nam
);
1080 Set_Etype
(N
, Any_Type
);
1084 elsif not Is_Entity_Name
(Nam
) then
1085 Error_Msg_N
("name in call is not a callable entity", Nam
);
1086 Set_Etype
(N
, Any_Type
);
1090 Nam_Ent
:= Entity
(Nam
);
1092 -- If not overloadable, this may be a generalized indexing
1093 -- operation with named associations. Rewrite again as an
1094 -- indexed component and analyze as container indexing.
1096 if not Is_Overloadable
(Nam_Ent
) then
1098 (Find_Value_Of_Aspect
1099 (Etype
(Nam_Ent
), Aspect_Constant_Indexing
))
1102 Make_Indexed_Component
(Sloc
(N
),
1104 Expressions
=> Parameter_Associations
(N
)));
1106 if Try_Container_Indexing
(N
, Nam
, Expressions
(N
)) then
1120 -- Operations generated for RACW stub types are called only through
1121 -- dispatching, and can never be the static interpretation of a call.
1123 if Is_RACW_Stub_Type_Operation
(Nam_Ent
) then
1128 Analyze_One_Call
(N
, Nam_Ent
, True, Success
);
1130 -- If this is an indirect call, the return type of the access_to
1131 -- subprogram may be an incomplete type. At the point of the call,
1132 -- use the full type if available, and at the same time update the
1133 -- return type of the access_to_subprogram.
1136 and then Nkind
(Nam
) = N_Explicit_Dereference
1137 and then Ekind
(Etype
(N
)) = E_Incomplete_Type
1138 and then Present
(Full_View
(Etype
(N
)))
1140 Set_Etype
(N
, Full_View
(Etype
(N
)));
1141 Set_Etype
(Nam_Ent
, Etype
(N
));
1147 -- An overloaded selected component must denote overloaded operations
1148 -- of a concurrent type. The interpretations are attached to the
1149 -- simple name of those operations.
1151 if Nkind
(Nam
) = N_Selected_Component
then
1152 Nam
:= Selector_Name
(Nam
);
1155 Get_First_Interp
(Nam
, X
, It
);
1157 while Present
(It
.Nam
) loop
1161 -- Name may be call that returns an access to subprogram, or more
1162 -- generally an overloaded expression one of whose interpretations
1163 -- yields an access to subprogram. If the name is an entity, we do
1164 -- not dereference, because the node is a call that returns the
1165 -- access type: note difference between f(x), where the call may
1166 -- return an access subprogram type, and f(x)(y), where the type
1167 -- returned by the call to f is implicitly dereferenced to analyze
1170 if Is_Access_Type
(Nam_Ent
) then
1171 Nam_Ent
:= Designated_Type
(Nam_Ent
);
1173 elsif Is_Access_Type
(Etype
(Nam_Ent
))
1175 (not Is_Entity_Name
(Nam
)
1176 or else Nkind
(N
) = N_Procedure_Call_Statement
)
1177 and then Ekind
(Designated_Type
(Etype
(Nam_Ent
)))
1180 Nam_Ent
:= Designated_Type
(Etype
(Nam_Ent
));
1182 if Is_Entity_Name
(Nam
) then
1187 -- If the call has been rewritten from a prefixed call, the first
1188 -- parameter has been analyzed, but may need a subsequent
1189 -- dereference, so skip its analysis now.
1191 if N
/= Original_Node
(N
)
1192 and then Nkind
(Original_Node
(N
)) = Nkind
(N
)
1193 and then Nkind
(Name
(N
)) /= Nkind
(Name
(Original_Node
(N
)))
1194 and then Present
(Parameter_Associations
(N
))
1195 and then Present
(Etype
(First
(Parameter_Associations
(N
))))
1198 (N
, Nam_Ent
, False, Success
, Skip_First
=> True);
1200 Analyze_One_Call
(N
, Nam_Ent
, False, Success
);
1203 -- If the interpretation succeeds, mark the proper type of the
1204 -- prefix (any valid candidate will do). If not, remove the
1205 -- candidate interpretation. This only needs to be done for
1206 -- overloaded protected operations, for other entities disambi-
1207 -- guation is done directly in Resolve.
1211 and then Nkind
(Parent
(N
)) /= N_Explicit_Dereference
1213 Set_Entity
(Nam
, It
.Nam
);
1214 Insert_Explicit_Dereference
(Nam
);
1215 Set_Etype
(Nam
, Nam_Ent
);
1218 Set_Etype
(Nam
, It
.Typ
);
1221 elsif Nkind_In
(Name
(N
), N_Selected_Component
,
1227 Get_Next_Interp
(X
, It
);
1230 -- If the name is the result of a function call, it can only be a
1231 -- call to a function returning an access to subprogram. Insert
1232 -- explicit dereference.
1234 if Nkind
(Nam
) = N_Function_Call
then
1235 Insert_Explicit_Dereference
(Nam
);
1238 if Etype
(N
) = Any_Type
then
1240 -- None of the interpretations is compatible with the actuals
1242 Diagnose_Call
(N
, Nam
);
1244 -- Special checks for uninstantiated put routines
1246 if Nkind
(N
) = N_Procedure_Call_Statement
1247 and then Is_Entity_Name
(Nam
)
1248 and then Chars
(Nam
) = Name_Put
1249 and then List_Length
(Actuals
) = 1
1252 Arg
: constant Node_Id
:= First
(Actuals
);
1256 if Nkind
(Arg
) = N_Parameter_Association
then
1257 Typ
:= Etype
(Explicit_Actual_Parameter
(Arg
));
1262 if Is_Signed_Integer_Type
(Typ
) then
1264 ("possible missing instantiation of "
1265 & "'Text_'I'O.'Integer_'I'O!", Nam
);
1267 elsif Is_Modular_Integer_Type
(Typ
) then
1269 ("possible missing instantiation of "
1270 & "'Text_'I'O.'Modular_'I'O!", Nam
);
1272 elsif Is_Floating_Point_Type
(Typ
) then
1274 ("possible missing instantiation of "
1275 & "'Text_'I'O.'Float_'I'O!", Nam
);
1277 elsif Is_Ordinary_Fixed_Point_Type
(Typ
) then
1279 ("possible missing instantiation of "
1280 & "'Text_'I'O.'Fixed_'I'O!", Nam
);
1282 elsif Is_Decimal_Fixed_Point_Type
(Typ
) then
1284 ("possible missing instantiation of "
1285 & "'Text_'I'O.'Decimal_'I'O!", Nam
);
1287 elsif Is_Enumeration_Type
(Typ
) then
1289 ("possible missing instantiation of "
1290 & "'Text_'I'O.'Enumeration_'I'O!", Nam
);
1295 elsif not Is_Overloaded
(N
)
1296 and then Is_Entity_Name
(Nam
)
1298 -- Resolution yields a single interpretation. Verify that the
1299 -- reference has capitalization consistent with the declaration.
1301 Set_Entity_With_Checks
(Nam
, Entity
(Nam
));
1302 Generate_Reference
(Entity
(Nam
), Nam
);
1304 Set_Etype
(Nam
, Etype
(Entity
(Nam
)));
1306 Remove_Abstract_Operations
(N
);
1312 -- A call to a ghost subprogram is allowed only in assertion expressions
1313 -- excluding subtype predicates or from within another ghost subprogram.
1315 if Is_Ghost_Subprogram
(Get_Subprogram_Entity
(N
)) then
1316 Check_Ghost_Subprogram_Call
;
1320 -----------------------------
1321 -- Analyze_Case_Expression --
1322 -----------------------------
1324 procedure Analyze_Case_Expression
(N
: Node_Id
) is
1325 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
1326 -- Error routine invoked by the generic instantiation below when
1327 -- the case expression has a non static choice.
1329 package Case_Choices_Analysis
is new
1330 Generic_Analyze_Choices
1331 (Process_Associated_Node
=> No_OP
);
1332 use Case_Choices_Analysis
;
1334 package Case_Choices_Checking
is new
1335 Generic_Check_Choices
1336 (Process_Empty_Choice
=> No_OP
,
1337 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
1338 Process_Associated_Node
=> No_OP
);
1339 use Case_Choices_Checking
;
1341 -----------------------------
1342 -- Non_Static_Choice_Error --
1343 -----------------------------
1345 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
1347 Flag_Non_Static_Expr
1348 ("choice given in case expression is not static!", Choice
);
1349 end Non_Static_Choice_Error
;
1353 Expr
: constant Node_Id
:= Expression
(N
);
1355 Exp_Type
: Entity_Id
;
1356 Exp_Btype
: Entity_Id
;
1358 FirstX
: Node_Id
:= Empty
;
1359 -- First expression in the case for which there is some type information
1360 -- available, i.e. it is not Any_Type, which can happen because of some
1361 -- error, or from the use of e.g. raise Constraint_Error.
1363 Others_Present
: Boolean;
1364 -- Indicates if Others was present
1366 Wrong_Alt
: Node_Id
;
1367 -- For error reporting
1369 -- Start of processing for Analyze_Case_Expression
1372 if Comes_From_Source
(N
) then
1373 Check_Compiler_Unit
("case expression", N
);
1376 Analyze_And_Resolve
(Expr
, Any_Discrete
);
1377 Check_Unset_Reference
(Expr
);
1378 Exp_Type
:= Etype
(Expr
);
1379 Exp_Btype
:= Base_Type
(Exp_Type
);
1381 Alt
:= First
(Alternatives
(N
));
1382 while Present
(Alt
) loop
1383 Analyze
(Expression
(Alt
));
1385 if No
(FirstX
) and then Etype
(Expression
(Alt
)) /= Any_Type
then
1386 FirstX
:= Expression
(Alt
);
1392 -- Get our initial type from the first expression for which we got some
1393 -- useful type information from the expression.
1395 if not Is_Overloaded
(FirstX
) then
1396 Set_Etype
(N
, Etype
(FirstX
));
1404 Set_Etype
(N
, Any_Type
);
1406 Get_First_Interp
(FirstX
, I
, It
);
1407 while Present
(It
.Nam
) loop
1409 -- For each interpretation of the first expression, we only
1410 -- add the interpretation if every other expression in the
1411 -- case expression alternatives has a compatible type.
1413 Alt
:= Next
(First
(Alternatives
(N
)));
1414 while Present
(Alt
) loop
1415 exit when not Has_Compatible_Type
(Expression
(Alt
), It
.Typ
);
1420 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
1426 Get_Next_Interp
(I
, It
);
1431 Exp_Btype
:= Base_Type
(Exp_Type
);
1433 -- The expression must be of a discrete type which must be determinable
1434 -- independently of the context in which the expression occurs, but
1435 -- using the fact that the expression must be of a discrete type.
1436 -- Moreover, the type this expression must not be a character literal
1437 -- (which is always ambiguous).
1439 -- If error already reported by Resolve, nothing more to do
1441 if Exp_Btype
= Any_Discrete
or else Exp_Btype
= Any_Type
then
1444 -- Special casee message for character literal
1446 elsif Exp_Btype
= Any_Character
then
1448 ("character literal as case expression is ambiguous", Expr
);
1452 if Etype
(N
) = Any_Type
and then Present
(Wrong_Alt
) then
1454 ("type incompatible with that of previous alternatives",
1455 Expression
(Wrong_Alt
));
1459 -- If the case expression is a formal object of mode in out, then
1460 -- treat it as having a nonstatic subtype by forcing use of the base
1461 -- type (which has to get passed to Check_Case_Choices below). Also
1462 -- use base type when the case expression is parenthesized.
1464 if Paren_Count
(Expr
) > 0
1465 or else (Is_Entity_Name
(Expr
)
1466 and then Ekind
(Entity
(Expr
)) = E_Generic_In_Out_Parameter
)
1468 Exp_Type
:= Exp_Btype
;
1471 -- The case expression alternatives cover the range of a static subtype
1472 -- subject to aspect Static_Predicate. Do not check the choices when the
1473 -- case expression has not been fully analyzed yet because this may lead
1476 if Is_OK_Static_Subtype
(Exp_Type
)
1477 and then Has_Static_Predicate_Aspect
(Exp_Type
)
1478 and then In_Spec_Expression
1482 -- Call Analyze_Choices and Check_Choices to do the rest of the work
1485 Analyze_Choices
(Alternatives
(N
), Exp_Type
);
1486 Check_Choices
(N
, Alternatives
(N
), Exp_Type
, Others_Present
);
1489 if Exp_Type
= Universal_Integer
and then not Others_Present
then
1491 ("case on universal integer requires OTHERS choice", Expr
);
1493 end Analyze_Case_Expression
;
1495 ---------------------------
1496 -- Analyze_Comparison_Op --
1497 ---------------------------
1499 procedure Analyze_Comparison_Op
(N
: Node_Id
) is
1500 L
: constant Node_Id
:= Left_Opnd
(N
);
1501 R
: constant Node_Id
:= Right_Opnd
(N
);
1502 Op_Id
: Entity_Id
:= Entity
(N
);
1505 Set_Etype
(N
, Any_Type
);
1506 Candidate_Type
:= Empty
;
1508 Analyze_Expression
(L
);
1509 Analyze_Expression
(R
);
1511 if Present
(Op_Id
) then
1512 if Ekind
(Op_Id
) = E_Operator
then
1513 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1515 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1518 if Is_Overloaded
(L
) then
1519 Set_Etype
(L
, Intersect_Types
(L
, R
));
1523 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1524 while Present
(Op_Id
) loop
1525 if Ekind
(Op_Id
) = E_Operator
then
1526 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1528 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1531 Op_Id
:= Homonym
(Op_Id
);
1536 end Analyze_Comparison_Op
;
1538 ---------------------------
1539 -- Analyze_Concatenation --
1540 ---------------------------
1542 procedure Analyze_Concatenation
(N
: Node_Id
) is
1544 -- We wish to avoid deep recursion, because concatenations are often
1545 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1546 -- operands nonrecursively until we find something that is not a
1547 -- concatenation (A in this case), or has already been analyzed. We
1548 -- analyze that, and then walk back up the tree following Parent
1549 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1550 -- work at each level. The Parent pointers allow us to avoid recursion,
1551 -- and thus avoid running out of memory.
1557 Candidate_Type
:= Empty
;
1559 -- The following code is equivalent to:
1561 -- Set_Etype (N, Any_Type);
1562 -- Analyze_Expression (Left_Opnd (N));
1563 -- Analyze_Concatenation_Rest (N);
1565 -- where the Analyze_Expression call recurses back here if the left
1566 -- operand is a concatenation.
1568 -- Walk down left operands
1571 Set_Etype
(NN
, Any_Type
);
1572 L
:= Left_Opnd
(NN
);
1573 exit when Nkind
(L
) /= N_Op_Concat
or else Analyzed
(L
);
1577 -- Now (given the above example) NN is A&B and L is A
1579 -- First analyze L ...
1581 Analyze_Expression
(L
);
1583 -- ... then walk NN back up until we reach N (where we started), calling
1584 -- Analyze_Concatenation_Rest along the way.
1587 Analyze_Concatenation_Rest
(NN
);
1591 end Analyze_Concatenation
;
1593 --------------------------------
1594 -- Analyze_Concatenation_Rest --
1595 --------------------------------
1597 -- If the only one-dimensional array type in scope is String,
1598 -- this is the resulting type of the operation. Otherwise there
1599 -- will be a concatenation operation defined for each user-defined
1600 -- one-dimensional array.
1602 procedure Analyze_Concatenation_Rest
(N
: Node_Id
) is
1603 L
: constant Node_Id
:= Left_Opnd
(N
);
1604 R
: constant Node_Id
:= Right_Opnd
(N
);
1605 Op_Id
: Entity_Id
:= Entity
(N
);
1610 Analyze_Expression
(R
);
1612 -- If the entity is present, the node appears in an instance, and
1613 -- denotes a predefined concatenation operation. The resulting type is
1614 -- obtained from the arguments when possible. If the arguments are
1615 -- aggregates, the array type and the concatenation type must be
1618 if Present
(Op_Id
) then
1619 if Ekind
(Op_Id
) = E_Operator
then
1620 LT
:= Base_Type
(Etype
(L
));
1621 RT
:= Base_Type
(Etype
(R
));
1623 if Is_Array_Type
(LT
)
1624 and then (RT
= LT
or else RT
= Base_Type
(Component_Type
(LT
)))
1626 Add_One_Interp
(N
, Op_Id
, LT
);
1628 elsif Is_Array_Type
(RT
)
1629 and then LT
= Base_Type
(Component_Type
(RT
))
1631 Add_One_Interp
(N
, Op_Id
, RT
);
1633 -- If one operand is a string type or a user-defined array type,
1634 -- and the other is a literal, result is of the specific type.
1637 (Root_Type
(LT
) = Standard_String
1638 or else Scope
(LT
) /= Standard_Standard
)
1639 and then Etype
(R
) = Any_String
1641 Add_One_Interp
(N
, Op_Id
, LT
);
1644 (Root_Type
(RT
) = Standard_String
1645 or else Scope
(RT
) /= Standard_Standard
)
1646 and then Etype
(L
) = Any_String
1648 Add_One_Interp
(N
, Op_Id
, RT
);
1650 elsif not Is_Generic_Type
(Etype
(Op_Id
)) then
1651 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1654 -- Type and its operations must be visible
1656 Set_Entity
(N
, Empty
);
1657 Analyze_Concatenation
(N
);
1661 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1665 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Concat
);
1666 while Present
(Op_Id
) loop
1667 if Ekind
(Op_Id
) = E_Operator
then
1669 -- Do not consider operators declared in dead code, they can
1670 -- not be part of the resolution.
1672 if Is_Eliminated
(Op_Id
) then
1675 Find_Concatenation_Types
(L
, R
, Op_Id
, N
);
1679 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1682 Op_Id
:= Homonym
(Op_Id
);
1687 end Analyze_Concatenation_Rest
;
1689 -------------------------
1690 -- Analyze_Equality_Op --
1691 -------------------------
1693 procedure Analyze_Equality_Op
(N
: Node_Id
) is
1694 Loc
: constant Source_Ptr
:= Sloc
(N
);
1695 L
: constant Node_Id
:= Left_Opnd
(N
);
1696 R
: constant Node_Id
:= Right_Opnd
(N
);
1700 Set_Etype
(N
, Any_Type
);
1701 Candidate_Type
:= Empty
;
1703 Analyze_Expression
(L
);
1704 Analyze_Expression
(R
);
1706 -- If the entity is set, the node is a generic instance with a non-local
1707 -- reference to the predefined operator or to a user-defined function.
1708 -- It can also be an inequality that is expanded into the negation of a
1709 -- call to a user-defined equality operator.
1711 -- For the predefined case, the result is Boolean, regardless of the
1712 -- type of the operands. The operands may even be limited, if they are
1713 -- generic actuals. If they are overloaded, label the left argument with
1714 -- the common type that must be present, or with the type of the formal
1715 -- of the user-defined function.
1717 if Present
(Entity
(N
)) then
1718 Op_Id
:= Entity
(N
);
1720 if Ekind
(Op_Id
) = E_Operator
then
1721 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
);
1723 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1726 if Is_Overloaded
(L
) then
1727 if Ekind
(Op_Id
) = E_Operator
then
1728 Set_Etype
(L
, Intersect_Types
(L
, R
));
1730 Set_Etype
(L
, Etype
(First_Formal
(Op_Id
)));
1735 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1736 while Present
(Op_Id
) loop
1737 if Ekind
(Op_Id
) = E_Operator
then
1738 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1740 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1743 Op_Id
:= Homonym
(Op_Id
);
1747 -- If there was no match, and the operator is inequality, this may
1748 -- be a case where inequality has not been made explicit, as for
1749 -- tagged types. Analyze the node as the negation of an equality
1750 -- operation. This cannot be done earlier, because before analysis
1751 -- we cannot rule out the presence of an explicit inequality.
1753 if Etype
(N
) = Any_Type
1754 and then Nkind
(N
) = N_Op_Ne
1756 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Eq
);
1757 while Present
(Op_Id
) loop
1758 if Ekind
(Op_Id
) = E_Operator
then
1759 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1761 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1764 Op_Id
:= Homonym
(Op_Id
);
1767 if Etype
(N
) /= Any_Type
then
1768 Op_Id
:= Entity
(N
);
1774 Left_Opnd
=> Left_Opnd
(N
),
1775 Right_Opnd
=> Right_Opnd
(N
))));
1777 Set_Entity
(Right_Opnd
(N
), Op_Id
);
1783 end Analyze_Equality_Op
;
1785 ----------------------------------
1786 -- Analyze_Explicit_Dereference --
1787 ----------------------------------
1789 procedure Analyze_Explicit_Dereference
(N
: Node_Id
) is
1790 Loc
: constant Source_Ptr
:= Sloc
(N
);
1791 P
: constant Node_Id
:= Prefix
(N
);
1797 function Is_Function_Type
return Boolean;
1798 -- Check whether node may be interpreted as an implicit function call
1800 ----------------------
1801 -- Is_Function_Type --
1802 ----------------------
1804 function Is_Function_Type
return Boolean is
1809 if not Is_Overloaded
(N
) then
1810 return Ekind
(Base_Type
(Etype
(N
))) = E_Subprogram_Type
1811 and then Etype
(Base_Type
(Etype
(N
))) /= Standard_Void_Type
;
1814 Get_First_Interp
(N
, I
, It
);
1815 while Present
(It
.Nam
) loop
1816 if Ekind
(Base_Type
(It
.Typ
)) /= E_Subprogram_Type
1817 or else Etype
(Base_Type
(It
.Typ
)) = Standard_Void_Type
1822 Get_Next_Interp
(I
, It
);
1827 end Is_Function_Type
;
1829 -- Start of processing for Analyze_Explicit_Dereference
1832 -- If source node, check SPARK restriction. We guard this with the
1833 -- source node check, because ???
1835 if Comes_From_Source
(N
) then
1836 Check_SPARK_05_Restriction
("explicit dereference is not allowed", N
);
1839 -- In formal verification mode, keep track of all reads and writes
1840 -- through explicit dereferences.
1842 if GNATprove_Mode
then
1843 SPARK_Specific
.Generate_Dereference
(N
);
1847 Set_Etype
(N
, Any_Type
);
1849 -- Test for remote access to subprogram type, and if so return
1850 -- after rewriting the original tree.
1852 if Remote_AST_E_Dereference
(P
) then
1856 -- Normal processing for other than remote access to subprogram type
1858 if not Is_Overloaded
(P
) then
1859 if Is_Access_Type
(Etype
(P
)) then
1861 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
1862 -- avoid other problems caused by the Private_Subtype and it is
1863 -- safe to go to the Base_Type because this is the same as
1864 -- converting the access value to its Base_Type.
1867 DT
: Entity_Id
:= Designated_Type
(Etype
(P
));
1870 if Ekind
(DT
) = E_Private_Subtype
1871 and then Is_For_Access_Subtype
(DT
)
1873 DT
:= Base_Type
(DT
);
1876 -- An explicit dereference is a legal occurrence of an
1877 -- incomplete type imported through a limited_with clause,
1878 -- if the full view is visible.
1880 if From_Limited_With
(DT
)
1881 and then not From_Limited_With
(Scope
(DT
))
1883 (Is_Immediately_Visible
(Scope
(DT
))
1885 (Is_Child_Unit
(Scope
(DT
))
1886 and then Is_Visible_Lib_Unit
(Scope
(DT
))))
1888 Set_Etype
(N
, Available_View
(DT
));
1895 elsif Etype
(P
) /= Any_Type
then
1896 Error_Msg_N
("prefix of dereference must be an access type", N
);
1901 Get_First_Interp
(P
, I
, It
);
1902 while Present
(It
.Nam
) loop
1905 if Is_Access_Type
(T
) then
1906 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
1909 Get_Next_Interp
(I
, It
);
1912 -- Error if no interpretation of the prefix has an access type
1914 if Etype
(N
) = Any_Type
then
1916 ("access type required in prefix of explicit dereference", P
);
1917 Set_Etype
(N
, Any_Type
);
1923 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
1925 and then (Nkind
(Parent
(N
)) /= N_Function_Call
1926 or else N
/= Name
(Parent
(N
)))
1928 and then (Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1929 or else N
/= Name
(Parent
(N
)))
1931 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
1932 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
1934 (Attribute_Name
(Parent
(N
)) /= Name_Address
1936 Attribute_Name
(Parent
(N
)) /= Name_Access
))
1938 -- Name is a function call with no actuals, in a context that
1939 -- requires deproceduring (including as an actual in an enclosing
1940 -- function or procedure call). There are some pathological cases
1941 -- where the prefix might include functions that return access to
1942 -- subprograms and others that return a regular type. Disambiguation
1943 -- of those has to take place in Resolve.
1946 Make_Function_Call
(Loc
,
1947 Name
=> Make_Explicit_Dereference
(Loc
, P
),
1948 Parameter_Associations
=> New_List
);
1950 -- If the prefix is overloaded, remove operations that have formals,
1951 -- we know that this is a parameterless call.
1953 if Is_Overloaded
(P
) then
1954 Get_First_Interp
(P
, I
, It
);
1955 while Present
(It
.Nam
) loop
1958 if No
(First_Formal
(Base_Type
(Designated_Type
(T
)))) then
1964 Get_Next_Interp
(I
, It
);
1971 elsif not Is_Function_Type
1972 and then Is_Overloaded
(N
)
1974 -- The prefix may include access to subprograms and other access
1975 -- types. If the context selects the interpretation that is a
1976 -- function call (not a procedure call) we cannot rewrite the node
1977 -- yet, but we include the result of the call interpretation.
1979 Get_First_Interp
(N
, I
, It
);
1980 while Present
(It
.Nam
) loop
1981 if Ekind
(Base_Type
(It
.Typ
)) = E_Subprogram_Type
1982 and then Etype
(Base_Type
(It
.Typ
)) /= Standard_Void_Type
1983 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1985 Add_One_Interp
(N
, Etype
(It
.Typ
), Etype
(It
.Typ
));
1988 Get_Next_Interp
(I
, It
);
1992 -- A value of remote access-to-class-wide must not be dereferenced
1995 Validate_Remote_Access_To_Class_Wide_Type
(N
);
1996 end Analyze_Explicit_Dereference
;
1998 ------------------------
1999 -- Analyze_Expression --
2000 ------------------------
2002 procedure Analyze_Expression
(N
: Node_Id
) is
2005 -- If the expression is an indexed component that will be rewritten
2006 -- as a container indexing, it has already been analyzed.
2008 if Nkind
(N
) = N_Indexed_Component
2009 and then Present
(Generalized_Indexing
(N
))
2015 Check_Parameterless_Call
(N
);
2017 end Analyze_Expression
;
2019 -------------------------------------
2020 -- Analyze_Expression_With_Actions --
2021 -------------------------------------
2023 procedure Analyze_Expression_With_Actions
(N
: Node_Id
) is
2027 A
:= First
(Actions
(N
));
2028 while Present
(A
) loop
2033 Analyze_Expression
(Expression
(N
));
2034 Set_Etype
(N
, Etype
(Expression
(N
)));
2035 end Analyze_Expression_With_Actions
;
2037 ---------------------------
2038 -- Analyze_If_Expression --
2039 ---------------------------
2041 procedure Analyze_If_Expression
(N
: Node_Id
) is
2042 Condition
: constant Node_Id
:= First
(Expressions
(N
));
2043 Then_Expr
: constant Node_Id
:= Next
(Condition
);
2044 Else_Expr
: Node_Id
;
2047 -- Defend against error of missing expressions from previous error
2049 if No
(Then_Expr
) then
2050 Check_Error_Detected
;
2054 if Comes_From_Source
(N
) then
2055 Check_SPARK_05_Restriction
("if expression is not allowed", N
);
2058 Else_Expr
:= Next
(Then_Expr
);
2060 if Comes_From_Source
(N
) then
2061 Check_Compiler_Unit
("if expression", N
);
2064 -- Analyze and resolve the condition. We need to resolve this now so
2065 -- that it gets folded to True/False if possible, before we analyze
2066 -- the THEN/ELSE branches, because when analyzing these branches, we
2067 -- may call Is_Statically_Unevaluated, which expects the condition of
2068 -- an enclosing IF to have been analyze/resolved/evaluated.
2070 Analyze_Expression
(Condition
);
2071 Resolve
(Condition
, Any_Boolean
);
2073 -- Analyze THEN expression and (if present) ELSE expression. For those
2074 -- we delay resolution in the normal manner, because of overloading etc.
2076 Analyze_Expression
(Then_Expr
);
2078 if Present
(Else_Expr
) then
2079 Analyze_Expression
(Else_Expr
);
2082 -- If then expression not overloaded, then that decides the type
2084 if not Is_Overloaded
(Then_Expr
) then
2085 Set_Etype
(N
, Etype
(Then_Expr
));
2087 -- Case where then expression is overloaded
2095 Set_Etype
(N
, Any_Type
);
2097 -- Shouldn't the following statement be down in the ELSE of the
2098 -- following loop? ???
2100 Get_First_Interp
(Then_Expr
, I
, It
);
2102 -- if no Else_Expression the conditional must be boolean
2104 if No
(Else_Expr
) then
2105 Set_Etype
(N
, Standard_Boolean
);
2107 -- Else_Expression Present. For each possible intepretation of
2108 -- the Then_Expression, add it only if the Else_Expression has
2109 -- a compatible type.
2112 while Present
(It
.Nam
) loop
2113 if Has_Compatible_Type
(Else_Expr
, It
.Typ
) then
2114 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
2117 Get_Next_Interp
(I
, It
);
2122 end Analyze_If_Expression
;
2124 ------------------------------------
2125 -- Analyze_Indexed_Component_Form --
2126 ------------------------------------
2128 procedure Analyze_Indexed_Component_Form
(N
: Node_Id
) is
2129 P
: constant Node_Id
:= Prefix
(N
);
2130 Exprs
: constant List_Id
:= Expressions
(N
);
2136 procedure Process_Function_Call
;
2137 -- Prefix in indexed component form is an overloadable entity,
2138 -- so the node is a function call. Reformat it as such.
2140 procedure Process_Indexed_Component
;
2141 -- Prefix in indexed component form is actually an indexed component.
2142 -- This routine processes it, knowing that the prefix is already
2145 procedure Process_Indexed_Component_Or_Slice
;
2146 -- An indexed component with a single index may designate a slice if
2147 -- the index is a subtype mark. This routine disambiguates these two
2148 -- cases by resolving the prefix to see if it is a subtype mark.
2150 procedure Process_Overloaded_Indexed_Component
;
2151 -- If the prefix of an indexed component is overloaded, the proper
2152 -- interpretation is selected by the index types and the context.
2154 ---------------------------
2155 -- Process_Function_Call --
2156 ---------------------------
2158 procedure Process_Function_Call
is
2162 Change_Node
(N
, N_Function_Call
);
2164 Set_Parameter_Associations
(N
, Exprs
);
2166 -- Analyze actuals prior to analyzing the call itself
2168 Actual
:= First
(Parameter_Associations
(N
));
2169 while Present
(Actual
) loop
2171 Check_Parameterless_Call
(Actual
);
2173 -- Move to next actual. Note that we use Next, not Next_Actual
2174 -- here. The reason for this is a bit subtle. If a function call
2175 -- includes named associations, the parser recognizes the node as
2176 -- a call, and it is analyzed as such. If all associations are
2177 -- positional, the parser builds an indexed_component node, and
2178 -- it is only after analysis of the prefix that the construct
2179 -- is recognized as a call, in which case Process_Function_Call
2180 -- rewrites the node and analyzes the actuals. If the list of
2181 -- actuals is malformed, the parser may leave the node as an
2182 -- indexed component (despite the presence of named associations).
2183 -- The iterator Next_Actual is equivalent to Next if the list is
2184 -- positional, but follows the normalized chain of actuals when
2185 -- named associations are present. In this case normalization has
2186 -- not taken place, and actuals remain unanalyzed, which leads to
2187 -- subsequent crashes or loops if there is an attempt to continue
2188 -- analysis of the program.
2194 end Process_Function_Call
;
2196 -------------------------------
2197 -- Process_Indexed_Component --
2198 -------------------------------
2200 procedure Process_Indexed_Component
is
2202 Array_Type
: Entity_Id
;
2204 Pent
: Entity_Id
:= Empty
;
2207 Exp
:= First
(Exprs
);
2209 if Is_Overloaded
(P
) then
2210 Process_Overloaded_Indexed_Component
;
2213 Array_Type
:= Etype
(P
);
2215 if Is_Entity_Name
(P
) then
2217 elsif Nkind
(P
) = N_Selected_Component
2218 and then Is_Entity_Name
(Selector_Name
(P
))
2220 Pent
:= Entity
(Selector_Name
(P
));
2223 -- Prefix must be appropriate for an array type, taking into
2224 -- account a possible implicit dereference.
2226 if Is_Access_Type
(Array_Type
) then
2228 (Warn_On_Dereference
, "?d?implicit dereference", N
);
2229 Array_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, P
);
2232 if Is_Array_Type
(Array_Type
) then
2235 elsif Present
(Pent
) and then Ekind
(Pent
) = E_Entry_Family
then
2237 Set_Etype
(N
, Any_Type
);
2239 if not Has_Compatible_Type
2240 (Exp
, Entry_Index_Type
(Pent
))
2242 Error_Msg_N
("invalid index type in entry name", N
);
2244 elsif Present
(Next
(Exp
)) then
2245 Error_Msg_N
("too many subscripts in entry reference", N
);
2248 Set_Etype
(N
, Etype
(P
));
2253 elsif Is_Record_Type
(Array_Type
)
2254 and then Remote_AST_I_Dereference
(P
)
2258 elsif Try_Container_Indexing
(N
, P
, Exprs
) then
2261 elsif Array_Type
= Any_Type
then
2262 Set_Etype
(N
, Any_Type
);
2264 -- In most cases the analysis of the prefix will have emitted
2265 -- an error already, but if the prefix may be interpreted as a
2266 -- call in prefixed notation, the report is left to the caller.
2267 -- To prevent cascaded errors, report only if no previous ones.
2269 if Serious_Errors_Detected
= 0 then
2270 Error_Msg_N
("invalid prefix in indexed component", P
);
2272 if Nkind
(P
) = N_Expanded_Name
then
2273 Error_Msg_NE
("\& is not visible", P
, Selector_Name
(P
));
2279 -- Here we definitely have a bad indexing
2282 if Nkind
(Parent
(N
)) = N_Requeue_Statement
2283 and then Present
(Pent
) and then Ekind
(Pent
) = E_Entry
2286 ("REQUEUE does not permit parameters", First
(Exprs
));
2288 elsif Is_Entity_Name
(P
)
2289 and then Etype
(P
) = Standard_Void_Type
2291 Error_Msg_NE
("incorrect use of&", P
, Entity
(P
));
2294 Error_Msg_N
("array type required in indexed component", P
);
2297 Set_Etype
(N
, Any_Type
);
2301 Index
:= First_Index
(Array_Type
);
2302 while Present
(Index
) and then Present
(Exp
) loop
2303 if not Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2304 Wrong_Type
(Exp
, Etype
(Index
));
2305 Set_Etype
(N
, Any_Type
);
2313 Set_Etype
(N
, Component_Type
(Array_Type
));
2314 Check_Implicit_Dereference
(N
, Etype
(N
));
2316 if Present
(Index
) then
2318 ("too few subscripts in array reference", First
(Exprs
));
2320 elsif Present
(Exp
) then
2321 Error_Msg_N
("too many subscripts in array reference", Exp
);
2324 end Process_Indexed_Component
;
2326 ----------------------------------------
2327 -- Process_Indexed_Component_Or_Slice --
2328 ----------------------------------------
2330 procedure Process_Indexed_Component_Or_Slice
is
2332 Exp
:= First
(Exprs
);
2333 while Present
(Exp
) loop
2334 Analyze_Expression
(Exp
);
2338 Exp
:= First
(Exprs
);
2340 -- If one index is present, and it is a subtype name, then the
2341 -- node denotes a slice (note that the case of an explicit range
2342 -- for a slice was already built as an N_Slice node in the first
2343 -- place, so that case is not handled here).
2345 -- We use a replace rather than a rewrite here because this is one
2346 -- of the cases in which the tree built by the parser is plain wrong.
2349 and then Is_Entity_Name
(Exp
)
2350 and then Is_Type
(Entity
(Exp
))
2353 Make_Slice
(Sloc
(N
),
2355 Discrete_Range
=> New_Copy
(Exp
)));
2358 -- Otherwise (more than one index present, or single index is not
2359 -- a subtype name), then we have the indexed component case.
2362 Process_Indexed_Component
;
2364 end Process_Indexed_Component_Or_Slice
;
2366 ------------------------------------------
2367 -- Process_Overloaded_Indexed_Component --
2368 ------------------------------------------
2370 procedure Process_Overloaded_Indexed_Component
is
2379 Set_Etype
(N
, Any_Type
);
2381 Get_First_Interp
(P
, I
, It
);
2382 while Present
(It
.Nam
) loop
2385 if Is_Access_Type
(Typ
) then
2386 Typ
:= Designated_Type
(Typ
);
2388 (Warn_On_Dereference
, "?d?implicit dereference", N
);
2391 if Is_Array_Type
(Typ
) then
2393 -- Got a candidate: verify that index types are compatible
2395 Index
:= First_Index
(Typ
);
2397 Exp
:= First
(Exprs
);
2398 while Present
(Index
) and then Present
(Exp
) loop
2399 if Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2411 if Found
and then No
(Index
) and then No
(Exp
) then
2413 CT
: constant Entity_Id
:=
2414 Base_Type
(Component_Type
(Typ
));
2416 Add_One_Interp
(N
, CT
, CT
);
2417 Check_Implicit_Dereference
(N
, CT
);
2421 elsif Try_Container_Indexing
(N
, P
, Exprs
) then
2426 Get_Next_Interp
(I
, It
);
2429 if Etype
(N
) = Any_Type
then
2430 Error_Msg_N
("no legal interpretation for indexed component", N
);
2431 Set_Is_Overloaded
(N
, False);
2435 end Process_Overloaded_Indexed_Component
;
2437 -- Start of processing for Analyze_Indexed_Component_Form
2440 -- Get name of array, function or type
2444 -- If P is an explicit dereference whose prefix is of a remote access-
2445 -- to-subprogram type, then N has already been rewritten as a subprogram
2446 -- call and analyzed.
2448 if Nkind
(N
) in N_Subprogram_Call
then
2451 -- When the prefix is attribute 'Loop_Entry and the sole expression of
2452 -- the indexed component denotes a loop name, the indexed form is turned
2453 -- into an attribute reference.
2455 elsif Nkind
(N
) = N_Attribute_Reference
2456 and then Attribute_Name
(N
) = Name_Loop_Entry
2461 pragma Assert
(Nkind
(N
) = N_Indexed_Component
);
2463 P_T
:= Base_Type
(Etype
(P
));
2465 if Is_Entity_Name
(P
) and then Present
(Entity
(P
)) then
2468 if Is_Type
(U_N
) then
2470 -- Reformat node as a type conversion
2472 E
:= Remove_Head
(Exprs
);
2474 if Present
(First
(Exprs
)) then
2476 ("argument of type conversion must be single expression", N
);
2479 Change_Node
(N
, N_Type_Conversion
);
2480 Set_Subtype_Mark
(N
, P
);
2482 Set_Expression
(N
, E
);
2484 -- After changing the node, call for the specific Analysis
2485 -- routine directly, to avoid a double call to the expander.
2487 Analyze_Type_Conversion
(N
);
2491 if Is_Overloadable
(U_N
) then
2492 Process_Function_Call
;
2494 elsif Ekind
(Etype
(P
)) = E_Subprogram_Type
2495 or else (Is_Access_Type
(Etype
(P
))
2497 Ekind
(Designated_Type
(Etype
(P
))) =
2500 -- Call to access_to-subprogram with possible implicit dereference
2502 Process_Function_Call
;
2504 elsif Is_Generic_Subprogram
(U_N
) then
2506 -- A common beginner's (or C++ templates fan) error
2508 Error_Msg_N
("generic subprogram cannot be called", N
);
2509 Set_Etype
(N
, Any_Type
);
2513 Process_Indexed_Component_Or_Slice
;
2516 -- If not an entity name, prefix is an expression that may denote
2517 -- an array or an access-to-subprogram.
2520 if Ekind
(P_T
) = E_Subprogram_Type
2521 or else (Is_Access_Type
(P_T
)
2523 Ekind
(Designated_Type
(P_T
)) = E_Subprogram_Type
)
2525 Process_Function_Call
;
2527 elsif Nkind
(P
) = N_Selected_Component
2528 and then Present
(Entity
(Selector_Name
(P
)))
2529 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
2531 Process_Function_Call
;
2533 -- In ASIS mode within a generic, a prefixed call is analyzed and
2534 -- partially rewritten but the original indexed component has not
2535 -- yet been rewritten as a call. Perform the replacement now.
2537 elsif Nkind
(P
) = N_Selected_Component
2538 and then Nkind
(Parent
(P
)) = N_Function_Call
2541 Rewrite
(N
, Parent
(P
));
2545 -- Indexed component, slice, or a call to a member of a family
2546 -- entry, which will be converted to an entry call later.
2548 Process_Indexed_Component_Or_Slice
;
2552 Analyze_Dimension
(N
);
2553 end Analyze_Indexed_Component_Form
;
2555 ------------------------
2556 -- Analyze_Logical_Op --
2557 ------------------------
2559 procedure Analyze_Logical_Op
(N
: Node_Id
) is
2560 L
: constant Node_Id
:= Left_Opnd
(N
);
2561 R
: constant Node_Id
:= Right_Opnd
(N
);
2562 Op_Id
: Entity_Id
:= Entity
(N
);
2565 Set_Etype
(N
, Any_Type
);
2566 Candidate_Type
:= Empty
;
2568 Analyze_Expression
(L
);
2569 Analyze_Expression
(R
);
2571 if Present
(Op_Id
) then
2573 if Ekind
(Op_Id
) = E_Operator
then
2574 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
2576 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2580 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
2581 while Present
(Op_Id
) loop
2582 if Ekind
(Op_Id
) = E_Operator
then
2583 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
2585 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
2588 Op_Id
:= Homonym
(Op_Id
);
2593 end Analyze_Logical_Op
;
2595 ---------------------------
2596 -- Analyze_Membership_Op --
2597 ---------------------------
2599 procedure Analyze_Membership_Op
(N
: Node_Id
) is
2600 Loc
: constant Source_Ptr
:= Sloc
(N
);
2601 L
: constant Node_Id
:= Left_Opnd
(N
);
2602 R
: constant Node_Id
:= Right_Opnd
(N
);
2604 Index
: Interp_Index
;
2606 Found
: Boolean := False;
2610 procedure Try_One_Interp
(T1
: Entity_Id
);
2611 -- Routine to try one proposed interpretation. Note that the context
2612 -- of the operation plays no role in resolving the arguments, so that
2613 -- if there is more than one interpretation of the operands that is
2614 -- compatible with a membership test, the operation is ambiguous.
2616 --------------------
2617 -- Try_One_Interp --
2618 --------------------
2620 procedure Try_One_Interp
(T1
: Entity_Id
) is
2622 if Has_Compatible_Type
(R
, T1
) then
2624 and then Base_Type
(T1
) /= Base_Type
(T_F
)
2626 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
2628 if It
= No_Interp
then
2629 Ambiguous_Operands
(N
);
2630 Set_Etype
(L
, Any_Type
);
2647 procedure Analyze_Set_Membership
;
2648 -- If a set of alternatives is present, analyze each and find the
2649 -- common type to which they must all resolve.
2651 ----------------------------
2652 -- Analyze_Set_Membership --
2653 ----------------------------
2655 procedure Analyze_Set_Membership
is
2657 Index
: Interp_Index
;
2659 Candidate_Interps
: Node_Id
;
2660 Common_Type
: Entity_Id
:= Empty
;
2663 if Comes_From_Source
(N
) then
2664 Check_Compiler_Unit
("set membership", N
);
2668 Candidate_Interps
:= L
;
2670 if not Is_Overloaded
(L
) then
2671 Common_Type
:= Etype
(L
);
2673 Alt
:= First
(Alternatives
(N
));
2674 while Present
(Alt
) loop
2677 if not Has_Compatible_Type
(Alt
, Common_Type
) then
2678 Wrong_Type
(Alt
, Common_Type
);
2685 Alt
:= First
(Alternatives
(N
));
2686 while Present
(Alt
) loop
2688 if not Is_Overloaded
(Alt
) then
2689 Common_Type
:= Etype
(Alt
);
2692 Get_First_Interp
(Alt
, Index
, It
);
2693 while Present
(It
.Typ
) loop
2695 Has_Compatible_Type
(Candidate_Interps
, It
.Typ
)
2697 Remove_Interp
(Index
);
2700 Get_Next_Interp
(Index
, It
);
2703 Get_First_Interp
(Alt
, Index
, It
);
2706 Error_Msg_N
("alternative has no legal type", Alt
);
2710 -- If alternative is not overloaded, we have a unique type
2713 Set_Etype
(Alt
, It
.Typ
);
2714 Get_Next_Interp
(Index
, It
);
2717 Set_Is_Overloaded
(Alt
, False);
2718 Common_Type
:= Etype
(Alt
);
2721 Candidate_Interps
:= Alt
;
2728 Set_Etype
(N
, Standard_Boolean
);
2730 if Present
(Common_Type
) then
2731 Set_Etype
(L
, Common_Type
);
2732 Set_Is_Overloaded
(L
, False);
2735 Error_Msg_N
("cannot resolve membership operation", N
);
2737 end Analyze_Set_Membership
;
2739 -- Start of processing for Analyze_Membership_Op
2742 Analyze_Expression
(L
);
2744 if No
(R
) and then Ada_Version
>= Ada_2012
then
2745 Analyze_Set_Membership
;
2749 if Nkind
(R
) = N_Range
2750 or else (Nkind
(R
) = N_Attribute_Reference
2751 and then Attribute_Name
(R
) = Name_Range
)
2755 if not Is_Overloaded
(L
) then
2756 Try_One_Interp
(Etype
(L
));
2759 Get_First_Interp
(L
, Index
, It
);
2760 while Present
(It
.Typ
) loop
2761 Try_One_Interp
(It
.Typ
);
2762 Get_Next_Interp
(Index
, It
);
2766 -- If not a range, it can be a subtype mark, or else it is a degenerate
2767 -- membership test with a singleton value, i.e. a test for equality,
2768 -- if the types are compatible.
2773 if Is_Entity_Name
(R
)
2774 and then Is_Type
(Entity
(R
))
2777 Check_Fully_Declared
(Entity
(R
), R
);
2779 elsif Ada_Version
>= Ada_2012
2780 and then Has_Compatible_Type
(R
, Etype
(L
))
2782 if Nkind
(N
) = N_In
then
2798 -- In all versions of the language, if we reach this point there
2799 -- is a previous error that will be diagnosed below.
2805 -- Compatibility between expression and subtype mark or range is
2806 -- checked during resolution. The result of the operation is Boolean
2809 Set_Etype
(N
, Standard_Boolean
);
2811 if Comes_From_Source
(N
)
2812 and then Present
(Right_Opnd
(N
))
2813 and then Is_CPP_Class
(Etype
(Etype
(Right_Opnd
(N
))))
2815 Error_Msg_N
("membership test not applicable to cpp-class types", N
);
2817 end Analyze_Membership_Op
;
2823 procedure Analyze_Mod
(N
: Node_Id
) is
2825 -- A special warning check, if we have an expression of the form:
2826 -- expr mod 2 * literal
2827 -- where literal is 64 or less, then probably what was meant was
2828 -- expr mod 2 ** literal
2829 -- so issue an appropriate warning.
2831 if Warn_On_Suspicious_Modulus_Value
2832 and then Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
2833 and then Intval
(Right_Opnd
(N
)) = Uint_2
2834 and then Nkind
(Parent
(N
)) = N_Op_Multiply
2835 and then Nkind
(Right_Opnd
(Parent
(N
))) = N_Integer_Literal
2836 and then Intval
(Right_Opnd
(Parent
(N
))) <= Uint_64
2839 ("suspicious MOD value, was '*'* intended'??M?", Parent
(N
));
2842 -- Remaining processing is same as for other arithmetic operators
2844 Analyze_Arithmetic_Op
(N
);
2847 ----------------------
2848 -- Analyze_Negation --
2849 ----------------------
2851 procedure Analyze_Negation
(N
: Node_Id
) is
2852 R
: constant Node_Id
:= Right_Opnd
(N
);
2853 Op_Id
: Entity_Id
:= Entity
(N
);
2856 Set_Etype
(N
, Any_Type
);
2857 Candidate_Type
:= Empty
;
2859 Analyze_Expression
(R
);
2861 if Present
(Op_Id
) then
2862 if Ekind
(Op_Id
) = E_Operator
then
2863 Find_Negation_Types
(R
, Op_Id
, N
);
2865 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2869 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
2870 while Present
(Op_Id
) loop
2871 if Ekind
(Op_Id
) = E_Operator
then
2872 Find_Negation_Types
(R
, Op_Id
, N
);
2874 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
2877 Op_Id
:= Homonym
(Op_Id
);
2882 end Analyze_Negation
;
2888 procedure Analyze_Null
(N
: Node_Id
) is
2890 Check_SPARK_05_Restriction
("null is not allowed", N
);
2892 Set_Etype
(N
, Any_Access
);
2895 ----------------------
2896 -- Analyze_One_Call --
2897 ----------------------
2899 procedure Analyze_One_Call
2903 Success
: out Boolean;
2904 Skip_First
: Boolean := False)
2906 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
2907 Prev_T
: constant Entity_Id
:= Etype
(N
);
2909 Must_Skip
: constant Boolean := Skip_First
2910 or else Nkind
(Original_Node
(N
)) = N_Selected_Component
2912 (Nkind
(Original_Node
(N
)) = N_Indexed_Component
2913 and then Nkind
(Prefix
(Original_Node
(N
)))
2914 = N_Selected_Component
);
2915 -- The first formal must be omitted from the match when trying to find
2916 -- a primitive operation that is a possible interpretation, and also
2917 -- after the call has been rewritten, because the corresponding actual
2918 -- is already known to be compatible, and because this may be an
2919 -- indexing of a call with default parameters.
2923 Is_Indexed
: Boolean := False;
2924 Is_Indirect
: Boolean := False;
2925 Subp_Type
: constant Entity_Id
:= Etype
(Nam
);
2928 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean;
2929 -- There may be a user-defined operator that hides the current
2930 -- interpretation. We must check for this independently of the
2931 -- analysis of the call with the user-defined operation, because
2932 -- the parameter names may be wrong and yet the hiding takes place.
2933 -- This fixes a problem with ACATS test B34014O.
2935 -- When the type Address is a visible integer type, and the DEC
2936 -- system extension is visible, the predefined operator may be
2937 -- hidden as well, by one of the address operations in auxdec.
2938 -- Finally, The abstract operations on address do not hide the
2939 -- predefined operator (this is the purpose of making them abstract).
2941 procedure Indicate_Name_And_Type
;
2942 -- If candidate interpretation matches, indicate name and type of
2943 -- result on call node.
2945 ----------------------------
2946 -- Indicate_Name_And_Type --
2947 ----------------------------
2949 procedure Indicate_Name_And_Type
is
2951 Add_One_Interp
(N
, Nam
, Etype
(Nam
));
2952 Check_Implicit_Dereference
(N
, Etype
(Nam
));
2955 -- If the prefix of the call is a name, indicate the entity
2956 -- being called. If it is not a name, it is an expression that
2957 -- denotes an access to subprogram or else an entry or family. In
2958 -- the latter case, the name is a selected component, and the entity
2959 -- being called is noted on the selector.
2961 if not Is_Type
(Nam
) then
2962 if Is_Entity_Name
(Name
(N
)) then
2963 Set_Entity
(Name
(N
), Nam
);
2965 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
2966 Set_Entity
(Selector_Name
(Name
(N
)), Nam
);
2970 if Debug_Flag_E
and not Report
then
2971 Write_Str
(" Overloaded call ");
2972 Write_Int
(Int
(N
));
2973 Write_Str
(" compatible with ");
2974 Write_Int
(Int
(Nam
));
2977 end Indicate_Name_And_Type
;
2979 ------------------------
2980 -- Operator_Hidden_By --
2981 ------------------------
2983 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean is
2984 Act1
: constant Node_Id
:= First_Actual
(N
);
2985 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
2986 Form1
: constant Entity_Id
:= First_Formal
(Fun
);
2987 Form2
: constant Entity_Id
:= Next_Formal
(Form1
);
2990 if Ekind
(Fun
) /= E_Function
or else Is_Abstract_Subprogram
(Fun
) then
2993 elsif not Has_Compatible_Type
(Act1
, Etype
(Form1
)) then
2996 elsif Present
(Form2
) then
2998 or else not Has_Compatible_Type
(Act2
, Etype
(Form2
))
3003 elsif Present
(Act2
) then
3007 -- Now we know that the arity of the operator matches the function,
3008 -- and the function call is a valid interpretation. The function
3009 -- hides the operator if it has the right signature, or if one of
3010 -- its operands is a non-abstract operation on Address when this is
3011 -- a visible integer type.
3013 return Hides_Op
(Fun
, Nam
)
3014 or else Is_Descendent_Of_Address
(Etype
(Form1
))
3017 and then Is_Descendent_Of_Address
(Etype
(Form2
)));
3018 end Operator_Hidden_By
;
3020 -- Start of processing for Analyze_One_Call
3025 -- If the subprogram has no formals or if all the formals have defaults,
3026 -- and the return type is an array type, the node may denote an indexing
3027 -- of the result of a parameterless call. In Ada 2005, the subprogram
3028 -- may have one non-defaulted formal, and the call may have been written
3029 -- in prefix notation, so that the rebuilt parameter list has more than
3032 if not Is_Overloadable
(Nam
)
3033 and then Ekind
(Nam
) /= E_Subprogram_Type
3034 and then Ekind
(Nam
) /= E_Entry_Family
3039 -- An indexing requires at least one actual. The name of the call cannot
3040 -- be an implicit indirect call, so it cannot be a generated explicit
3043 if not Is_Empty_List
(Actuals
)
3045 (Needs_No_Actuals
(Nam
)
3047 (Needs_One_Actual
(Nam
)
3048 and then Present
(Next_Actual
(First
(Actuals
)))))
3050 if Is_Array_Type
(Subp_Type
)
3052 (Nkind
(Name
(N
)) /= N_Explicit_Dereference
3053 or else Comes_From_Source
(Name
(N
)))
3055 Is_Indexed
:= Try_Indexed_Call
(N
, Nam
, Subp_Type
, Must_Skip
);
3057 elsif Is_Access_Type
(Subp_Type
)
3058 and then Is_Array_Type
(Designated_Type
(Subp_Type
))
3062 (N
, Nam
, Designated_Type
(Subp_Type
), Must_Skip
);
3064 -- The prefix can also be a parameterless function that returns an
3065 -- access to subprogram, in which case this is an indirect call.
3066 -- If this succeeds, an explicit dereference is added later on,
3067 -- in Analyze_Call or Resolve_Call.
3069 elsif Is_Access_Type
(Subp_Type
)
3070 and then Ekind
(Designated_Type
(Subp_Type
)) = E_Subprogram_Type
3072 Is_Indirect
:= Try_Indirect_Call
(N
, Nam
, Subp_Type
);
3077 -- If the call has been transformed into a slice, it is of the form
3078 -- F (Subtype) where F is parameterless. The node has been rewritten in
3079 -- Try_Indexed_Call and there is nothing else to do.
3082 and then Nkind
(N
) = N_Slice
3088 (N
, Nam
, (Report
and not Is_Indexed
and not Is_Indirect
), Norm_OK
);
3092 -- If an indirect call is a possible interpretation, indicate
3093 -- success to the caller. This may be an indexing of an explicit
3094 -- dereference of a call that returns an access type (see above).
3098 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
3099 and then Comes_From_Source
(Name
(N
)))
3104 -- Mismatch in number or names of parameters
3106 elsif Debug_Flag_E
then
3107 Write_Str
(" normalization fails in call ");
3108 Write_Int
(Int
(N
));
3109 Write_Str
(" with subprogram ");
3110 Write_Int
(Int
(Nam
));
3114 -- If the context expects a function call, discard any interpretation
3115 -- that is a procedure. If the node is not overloaded, leave as is for
3116 -- better error reporting when type mismatch is found.
3118 elsif Nkind
(N
) = N_Function_Call
3119 and then Is_Overloaded
(Name
(N
))
3120 and then Ekind
(Nam
) = E_Procedure
3124 -- Ditto for function calls in a procedure context
3126 elsif Nkind
(N
) = N_Procedure_Call_Statement
3127 and then Is_Overloaded
(Name
(N
))
3128 and then Etype
(Nam
) /= Standard_Void_Type
3132 elsif No
(Actuals
) then
3134 -- If Normalize succeeds, then there are default parameters for
3137 Indicate_Name_And_Type
;
3139 elsif Ekind
(Nam
) = E_Operator
then
3140 if Nkind
(N
) = N_Procedure_Call_Statement
then
3144 -- This can occur when the prefix of the call is an operator
3145 -- name or an expanded name whose selector is an operator name.
3147 Analyze_Operator_Call
(N
, Nam
);
3149 if Etype
(N
) /= Prev_T
then
3151 -- Check that operator is not hidden by a function interpretation
3153 if Is_Overloaded
(Name
(N
)) then
3159 Get_First_Interp
(Name
(N
), I
, It
);
3160 while Present
(It
.Nam
) loop
3161 if Operator_Hidden_By
(It
.Nam
) then
3162 Set_Etype
(N
, Prev_T
);
3166 Get_Next_Interp
(I
, It
);
3171 -- If operator matches formals, record its name on the call.
3172 -- If the operator is overloaded, Resolve will select the
3173 -- correct one from the list of interpretations. The call
3174 -- node itself carries the first candidate.
3176 Set_Entity
(Name
(N
), Nam
);
3179 elsif Report
and then Etype
(N
) = Any_Type
then
3180 Error_Msg_N
("incompatible arguments for operator", N
);
3184 -- Normalize_Actuals has chained the named associations in the
3185 -- correct order of the formals.
3187 Actual
:= First_Actual
(N
);
3188 Formal
:= First_Formal
(Nam
);
3190 -- If we are analyzing a call rewritten from object notation, skip
3191 -- first actual, which may be rewritten later as an explicit
3195 Next_Actual
(Actual
);
3196 Next_Formal
(Formal
);
3199 while Present
(Actual
) and then Present
(Formal
) loop
3200 if Nkind
(Parent
(Actual
)) /= N_Parameter_Association
3201 or else Chars
(Selector_Name
(Parent
(Actual
))) = Chars
(Formal
)
3203 -- The actual can be compatible with the formal, but we must
3204 -- also check that the context is not an address type that is
3205 -- visibly an integer type. In this case the use of literals is
3206 -- illegal, except in the body of descendents of system, where
3207 -- arithmetic operations on address are of course used.
3209 if Has_Compatible_Type
(Actual
, Etype
(Formal
))
3211 (Etype
(Actual
) /= Universal_Integer
3212 or else not Is_Descendent_Of_Address
(Etype
(Formal
))
3214 Is_Predefined_File_Name
3215 (Unit_File_Name
(Get_Source_Unit
(N
))))
3217 Next_Actual
(Actual
);
3218 Next_Formal
(Formal
);
3220 -- In Allow_Integer_Address mode, we allow an actual integer to
3221 -- match a formal address type and vice versa. We only do this
3222 -- if we are certain that an error will otherwise be issued
3224 elsif Address_Integer_Convert_OK
3225 (Etype
(Actual
), Etype
(Formal
))
3226 and then (Report
and not Is_Indexed
and not Is_Indirect
)
3228 -- Handle this case by introducing an unchecked conversion
3231 Unchecked_Convert_To
(Etype
(Formal
),
3232 Relocate_Node
(Actual
)));
3233 Analyze_And_Resolve
(Actual
, Etype
(Formal
));
3234 Next_Actual
(Actual
);
3235 Next_Formal
(Formal
);
3238 if Debug_Flag_E
then
3239 Write_Str
(" type checking fails in call ");
3240 Write_Int
(Int
(N
));
3241 Write_Str
(" with formal ");
3242 Write_Int
(Int
(Formal
));
3243 Write_Str
(" in subprogram ");
3244 Write_Int
(Int
(Nam
));
3248 -- Comment needed on the following test???
3250 if Report
and not Is_Indexed
and not Is_Indirect
then
3252 -- Ada 2005 (AI-251): Complete the error notification
3253 -- to help new Ada 2005 users.
3255 if Is_Class_Wide_Type
(Etype
(Formal
))
3256 and then Is_Interface
(Etype
(Etype
(Formal
)))
3257 and then not Interface_Present_In_Ancestor
3258 (Typ
=> Etype
(Actual
),
3259 Iface
=> Etype
(Etype
(Formal
)))
3262 ("(Ada 2005) does not implement interface }",
3263 Actual
, Etype
(Etype
(Formal
)));
3266 Wrong_Type
(Actual
, Etype
(Formal
));
3268 if Nkind
(Actual
) = N_Op_Eq
3269 and then Nkind
(Left_Opnd
(Actual
)) = N_Identifier
3271 Formal
:= First_Formal
(Nam
);
3272 while Present
(Formal
) loop
3273 if Chars
(Left_Opnd
(Actual
)) = Chars
(Formal
) then
3274 Error_Msg_N
-- CODEFIX
3275 ("possible misspelling of `='>`!", Actual
);
3279 Next_Formal
(Formal
);
3283 if All_Errors_Mode
then
3284 Error_Msg_Sloc
:= Sloc
(Nam
);
3286 if Etype
(Formal
) = Any_Type
then
3288 ("there is no legal actual parameter", Actual
);
3291 if Is_Overloadable
(Nam
)
3292 and then Present
(Alias
(Nam
))
3293 and then not Comes_From_Source
(Nam
)
3296 ("\\ =='> in call to inherited operation & #!",
3299 elsif Ekind
(Nam
) = E_Subprogram_Type
then
3301 Access_To_Subprogram_Typ
:
3302 constant Entity_Id
:=
3304 (Associated_Node_For_Itype
(Nam
));
3307 ("\\ =='> in call to dereference of &#!",
3308 Actual
, Access_To_Subprogram_Typ
);
3313 ("\\ =='> in call to &#!", Actual
, Nam
);
3323 -- Normalize_Actuals has verified that a default value exists
3324 -- for this formal. Current actual names a subsequent formal.
3326 Next_Formal
(Formal
);
3330 -- On exit, all actuals match
3332 Indicate_Name_And_Type
;
3334 end Analyze_One_Call
;
3336 ---------------------------
3337 -- Analyze_Operator_Call --
3338 ---------------------------
3340 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
) is
3341 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
3342 Act1
: constant Node_Id
:= First_Actual
(N
);
3343 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
3346 -- Binary operator case
3348 if Present
(Act2
) then
3350 -- If more than two operands, then not binary operator after all
3352 if Present
(Next_Actual
(Act2
)) then
3356 -- Otherwise action depends on operator
3366 Find_Arithmetic_Types
(Act1
, Act2
, Op_Id
, N
);
3371 Find_Boolean_Types
(Act1
, Act2
, Op_Id
, N
);
3377 Find_Comparison_Types
(Act1
, Act2
, Op_Id
, N
);
3381 Find_Equality_Types
(Act1
, Act2
, Op_Id
, N
);
3383 when Name_Op_Concat
=>
3384 Find_Concatenation_Types
(Act1
, Act2
, Op_Id
, N
);
3386 -- Is this when others, or should it be an abort???
3392 -- Unary operator case
3396 when Name_Op_Subtract |
3399 Find_Unary_Types
(Act1
, Op_Id
, N
);
3402 Find_Negation_Types
(Act1
, Op_Id
, N
);
3404 -- Is this when others correct, or should it be an abort???
3410 end Analyze_Operator_Call
;
3412 -------------------------------------------
3413 -- Analyze_Overloaded_Selected_Component --
3414 -------------------------------------------
3416 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
) is
3417 Nam
: constant Node_Id
:= Prefix
(N
);
3418 Sel
: constant Node_Id
:= Selector_Name
(N
);
3425 Set_Etype
(Sel
, Any_Type
);
3427 Get_First_Interp
(Nam
, I
, It
);
3428 while Present
(It
.Typ
) loop
3429 if Is_Access_Type
(It
.Typ
) then
3430 T
:= Designated_Type
(It
.Typ
);
3431 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
3436 -- Locate the component. For a private prefix the selector can denote
3439 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
3441 -- If the prefix is a class-wide type, the visible components are
3442 -- those of the base type.
3444 if Is_Class_Wide_Type
(T
) then
3448 Comp
:= First_Entity
(T
);
3449 while Present
(Comp
) loop
3450 if Chars
(Comp
) = Chars
(Sel
)
3451 and then Is_Visible_Component
(Comp
)
3454 -- AI05-105: if the context is an object renaming with
3455 -- an anonymous access type, the expected type of the
3456 -- object must be anonymous. This is a name resolution rule.
3458 if Nkind
(Parent
(N
)) /= N_Object_Renaming_Declaration
3459 or else No
(Access_Definition
(Parent
(N
)))
3460 or else Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Type
3462 Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Subprogram_Type
3464 Set_Entity
(Sel
, Comp
);
3465 Set_Etype
(Sel
, Etype
(Comp
));
3466 Add_One_Interp
(N
, Etype
(Comp
), Etype
(Comp
));
3467 Check_Implicit_Dereference
(N
, Etype
(Comp
));
3469 -- This also specifies a candidate to resolve the name.
3470 -- Further overloading will be resolved from context.
3471 -- The selector name itself does not carry overloading
3474 Set_Etype
(Nam
, It
.Typ
);
3477 -- Named access type in the context of a renaming
3478 -- declaration with an access definition. Remove
3479 -- inapplicable candidate.
3488 elsif Is_Concurrent_Type
(T
) then
3489 Comp
:= First_Entity
(T
);
3490 while Present
(Comp
)
3491 and then Comp
/= First_Private_Entity
(T
)
3493 if Chars
(Comp
) = Chars
(Sel
) then
3494 if Is_Overloadable
(Comp
) then
3495 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
3497 Set_Entity_With_Checks
(Sel
, Comp
);
3498 Generate_Reference
(Comp
, Sel
);
3501 Set_Etype
(Sel
, Etype
(Comp
));
3502 Set_Etype
(N
, Etype
(Comp
));
3503 Set_Etype
(Nam
, It
.Typ
);
3505 -- For access type case, introduce explicit dereference for
3506 -- more uniform treatment of entry calls. Do this only once
3507 -- if several interpretations yield an access type.
3509 if Is_Access_Type
(Etype
(Nam
))
3510 and then Nkind
(Nam
) /= N_Explicit_Dereference
3512 Insert_Explicit_Dereference
(Nam
);
3514 (Warn_On_Dereference
, "?d?implicit dereference", N
);
3521 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
3524 Get_Next_Interp
(I
, It
);
3527 if Etype
(N
) = Any_Type
3528 and then not Try_Object_Operation
(N
)
3530 Error_Msg_NE
("undefined selector& for overloaded prefix", N
, Sel
);
3531 Set_Entity
(Sel
, Any_Id
);
3532 Set_Etype
(Sel
, Any_Type
);
3534 end Analyze_Overloaded_Selected_Component
;
3536 ----------------------------------
3537 -- Analyze_Qualified_Expression --
3538 ----------------------------------
3540 procedure Analyze_Qualified_Expression
(N
: Node_Id
) is
3541 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
3542 Expr
: constant Node_Id
:= Expression
(N
);
3548 Analyze_Expression
(Expr
);
3550 Set_Etype
(N
, Any_Type
);
3555 if T
= Any_Type
then
3559 Check_Fully_Declared
(T
, N
);
3561 -- If expected type is class-wide, check for exact match before
3562 -- expansion, because if the expression is a dispatching call it
3563 -- may be rewritten as explicit dereference with class-wide result.
3564 -- If expression is overloaded, retain only interpretations that
3565 -- will yield exact matches.
3567 if Is_Class_Wide_Type
(T
) then
3568 if not Is_Overloaded
(Expr
) then
3569 if Base_Type
(Etype
(Expr
)) /= Base_Type
(T
) then
3570 if Nkind
(Expr
) = N_Aggregate
then
3571 Error_Msg_N
("type of aggregate cannot be class-wide", Expr
);
3573 Wrong_Type
(Expr
, T
);
3578 Get_First_Interp
(Expr
, I
, It
);
3580 while Present
(It
.Nam
) loop
3581 if Base_Type
(It
.Typ
) /= Base_Type
(T
) then
3585 Get_Next_Interp
(I
, It
);
3591 end Analyze_Qualified_Expression
;
3593 -----------------------------------
3594 -- Analyze_Quantified_Expression --
3595 -----------------------------------
3597 procedure Analyze_Quantified_Expression
(N
: Node_Id
) is
3598 function Is_Empty_Range
(Typ
: Entity_Id
) return Boolean;
3599 -- If the iterator is part of a quantified expression, and the range is
3600 -- known to be statically empty, emit a warning and replace expression
3601 -- with its static value. Returns True if the replacement occurs.
3603 function No_Else_Or_Trivial_True
(If_Expr
: Node_Id
) return Boolean;
3604 -- Determine whether if expression If_Expr lacks an else part or if it
3605 -- has one, it evaluates to True.
3607 --------------------
3608 -- Is_Empty_Range --
3609 --------------------
3611 function Is_Empty_Range
(Typ
: Entity_Id
) return Boolean is
3612 Loc
: constant Source_Ptr
:= Sloc
(N
);
3615 if Is_Array_Type
(Typ
)
3616 and then Compile_Time_Known_Bounds
(Typ
)
3618 (Expr_Value
(Type_Low_Bound
(Etype
(First_Index
(Typ
)))) >
3619 Expr_Value
(Type_High_Bound
(Etype
(First_Index
(Typ
)))))
3621 Preanalyze_And_Resolve
(Condition
(N
), Standard_Boolean
);
3623 if All_Present
(N
) then
3625 ("??quantified expression with ALL "
3626 & "over a null range has value True", N
);
3627 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
3631 ("??quantified expression with SOME "
3632 & "over a null range has value False", N
);
3633 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
3644 -----------------------------
3645 -- No_Else_Or_Trivial_True --
3646 -----------------------------
3648 function No_Else_Or_Trivial_True
(If_Expr
: Node_Id
) return Boolean is
3649 Else_Expr
: constant Node_Id
:=
3650 Next
(Next
(First
(Expressions
(If_Expr
))));
3654 or else (Compile_Time_Known_Value
(Else_Expr
)
3655 and then Is_True
(Expr_Value
(Else_Expr
)));
3656 end No_Else_Or_Trivial_True
;
3660 Cond
: constant Node_Id
:= Condition
(N
);
3661 Loop_Id
: Entity_Id
;
3662 QE_Scop
: Entity_Id
;
3664 -- Start of processing for Analyze_Quantified_Expression
3667 Check_SPARK_05_Restriction
("quantified expression is not allowed", N
);
3669 -- Create a scope to emulate the loop-like behavior of the quantified
3670 -- expression. The scope is needed to provide proper visibility of the
3673 QE_Scop
:= New_Internal_Entity
(E_Loop
, Current_Scope
, Sloc
(N
), 'L');
3674 Set_Etype
(QE_Scop
, Standard_Void_Type
);
3675 Set_Scope
(QE_Scop
, Current_Scope
);
3676 Set_Parent
(QE_Scop
, N
);
3678 Push_Scope
(QE_Scop
);
3680 -- All constituents are preanalyzed and resolved to avoid untimely
3681 -- generation of various temporaries and types. Full analysis and
3682 -- expansion is carried out when the quantified expression is
3683 -- transformed into an expression with actions.
3685 if Present
(Iterator_Specification
(N
)) then
3686 Preanalyze
(Iterator_Specification
(N
));
3688 -- Do not proceed with the analysis when the range of iteration is
3689 -- empty. The appropriate error is issued by Is_Empty_Range.
3691 if Is_Entity_Name
(Name
(Iterator_Specification
(N
)))
3692 and then Is_Empty_Range
(Etype
(Name
(Iterator_Specification
(N
))))
3697 else pragma Assert
(Present
(Loop_Parameter_Specification
(N
)));
3699 Loop_Par
: constant Node_Id
:= Loop_Parameter_Specification
(N
);
3702 Preanalyze
(Loop_Par
);
3704 if Nkind
(Discrete_Subtype_Definition
(Loop_Par
)) = N_Function_Call
3705 and then Parent
(Loop_Par
) /= N
3707 -- The parser cannot distinguish between a loop specification
3708 -- and an iterator specification. If after pre-analysis the
3709 -- proper form has been recognized, rewrite the expression to
3710 -- reflect the right kind. This is needed for proper ASIS
3711 -- navigation. If expansion is enabled, the transformation is
3712 -- performed when the expression is rewritten as a loop.
3714 Set_Iterator_Specification
(N
,
3715 New_Copy_Tree
(Iterator_Specification
(Parent
(Loop_Par
))));
3717 Set_Defining_Identifier
(Iterator_Specification
(N
),
3718 Relocate_Node
(Defining_Identifier
(Loop_Par
)));
3719 Set_Name
(Iterator_Specification
(N
),
3720 Relocate_Node
(Discrete_Subtype_Definition
(Loop_Par
)));
3721 Set_Comes_From_Source
(Iterator_Specification
(N
),
3722 Comes_From_Source
(Loop_Parameter_Specification
(N
)));
3723 Set_Loop_Parameter_Specification
(N
, Empty
);
3728 Preanalyze_And_Resolve
(Cond
, Standard_Boolean
);
3731 Set_Etype
(N
, Standard_Boolean
);
3733 -- Verify that the loop variable is used within the condition of the
3734 -- quantified expression.
3736 if Present
(Iterator_Specification
(N
)) then
3737 Loop_Id
:= Defining_Identifier
(Iterator_Specification
(N
));
3739 Loop_Id
:= Defining_Identifier
(Loop_Parameter_Specification
(N
));
3742 if Warn_On_Suspicious_Contract
3743 and then not Referenced
(Loop_Id
, Cond
)
3745 Error_Msg_N
("?T?unused variable &", Loop_Id
);
3748 -- Diagnose a possible misuse of the SOME existential quantifier. When
3749 -- we have a quantified expression of the form:
3751 -- for some X => (if P then Q [else True])
3753 -- any value for X that makes P False results in the if expression being
3754 -- trivially True, and so also results in the the quantified expression
3755 -- being trivially True.
3757 if Warn_On_Suspicious_Contract
3758 and then not All_Present
(N
)
3759 and then Nkind
(Cond
) = N_If_Expression
3760 and then No_Else_Or_Trivial_True
(Cond
)
3762 Error_Msg_N
("?T?suspicious expression", N
);
3763 Error_Msg_N
("\\did you mean (for all X ='> (if P then Q))", N
);
3764 Error_Msg_N
("\\or (for some X ='> P and then Q) instead'?", N
);
3766 end Analyze_Quantified_Expression
;
3772 procedure Analyze_Range
(N
: Node_Id
) is
3773 L
: constant Node_Id
:= Low_Bound
(N
);
3774 H
: constant Node_Id
:= High_Bound
(N
);
3775 I1
, I2
: Interp_Index
;
3778 procedure Check_Common_Type
(T1
, T2
: Entity_Id
);
3779 -- Verify the compatibility of two types, and choose the
3780 -- non universal one if the other is universal.
3782 procedure Check_High_Bound
(T
: Entity_Id
);
3783 -- Test one interpretation of the low bound against all those
3784 -- of the high bound.
3786 procedure Check_Universal_Expression
(N
: Node_Id
);
3787 -- In Ada 83, reject bounds of a universal range that are not literals
3790 -----------------------
3791 -- Check_Common_Type --
3792 -----------------------
3794 procedure Check_Common_Type
(T1
, T2
: Entity_Id
) is
3796 if Covers
(T1
=> T1
, T2
=> T2
)
3798 Covers
(T1
=> T2
, T2
=> T1
)
3800 if T1
= Universal_Integer
3801 or else T1
= Universal_Real
3802 or else T1
= Any_Character
3804 Add_One_Interp
(N
, Base_Type
(T2
), Base_Type
(T2
));
3807 Add_One_Interp
(N
, T1
, T1
);
3810 Add_One_Interp
(N
, Base_Type
(T1
), Base_Type
(T1
));
3813 end Check_Common_Type
;
3815 ----------------------
3816 -- Check_High_Bound --
3817 ----------------------
3819 procedure Check_High_Bound
(T
: Entity_Id
) is
3821 if not Is_Overloaded
(H
) then
3822 Check_Common_Type
(T
, Etype
(H
));
3824 Get_First_Interp
(H
, I2
, It2
);
3825 while Present
(It2
.Typ
) loop
3826 Check_Common_Type
(T
, It2
.Typ
);
3827 Get_Next_Interp
(I2
, It2
);
3830 end Check_High_Bound
;
3832 -----------------------------
3833 -- Is_Universal_Expression --
3834 -----------------------------
3836 procedure Check_Universal_Expression
(N
: Node_Id
) is
3838 if Etype
(N
) = Universal_Integer
3839 and then Nkind
(N
) /= N_Integer_Literal
3840 and then not Is_Entity_Name
(N
)
3841 and then Nkind
(N
) /= N_Attribute_Reference
3843 Error_Msg_N
("illegal bound in discrete range", N
);
3845 end Check_Universal_Expression
;
3847 -- Start of processing for Analyze_Range
3850 Set_Etype
(N
, Any_Type
);
3851 Analyze_Expression
(L
);
3852 Analyze_Expression
(H
);
3854 if Etype
(L
) = Any_Type
or else Etype
(H
) = Any_Type
then
3858 if not Is_Overloaded
(L
) then
3859 Check_High_Bound
(Etype
(L
));
3861 Get_First_Interp
(L
, I1
, It1
);
3862 while Present
(It1
.Typ
) loop
3863 Check_High_Bound
(It1
.Typ
);
3864 Get_Next_Interp
(I1
, It1
);
3868 -- If result is Any_Type, then we did not find a compatible pair
3870 if Etype
(N
) = Any_Type
then
3871 Error_Msg_N
("incompatible types in range ", N
);
3875 if Ada_Version
= Ada_83
3877 (Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
3878 or else Nkind
(Parent
(N
)) = N_Constrained_Array_Definition
)
3880 Check_Universal_Expression
(L
);
3881 Check_Universal_Expression
(H
);
3884 Check_Function_Writable_Actuals
(N
);
3887 -----------------------
3888 -- Analyze_Reference --
3889 -----------------------
3891 procedure Analyze_Reference
(N
: Node_Id
) is
3892 P
: constant Node_Id
:= Prefix
(N
);
3895 Acc_Type
: Entity_Id
;
3900 -- An interesting error check, if we take the 'Reference of an object
3901 -- for which a pragma Atomic or Volatile has been given, and the type
3902 -- of the object is not Atomic or Volatile, then we are in trouble. The
3903 -- problem is that no trace of the atomic/volatile status will remain
3904 -- for the backend to respect when it deals with the resulting pointer,
3905 -- since the pointer type will not be marked atomic (it is a pointer to
3906 -- the base type of the object).
3908 -- It is not clear if that can ever occur, but in case it does, we will
3909 -- generate an error message. Not clear if this message can ever be
3910 -- generated, and pretty clear that it represents a bug if it is, still
3911 -- seems worth checking, except in CodePeer mode where we do not really
3912 -- care and don't want to bother the user.
3916 if Is_Entity_Name
(P
)
3917 and then Is_Object_Reference
(P
)
3918 and then not CodePeer_Mode
3923 if (Has_Atomic_Components
(E
)
3924 and then not Has_Atomic_Components
(T
))
3926 (Has_Volatile_Components
(E
)
3927 and then not Has_Volatile_Components
(T
))
3928 or else (Is_Atomic
(E
) and then not Is_Atomic
(T
))
3929 or else (Is_Volatile
(E
) and then not Is_Volatile
(T
))
3931 Error_Msg_N
("cannot take reference to Atomic/Volatile object", N
);
3935 -- Carry on with normal processing
3937 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
3938 Set_Etype
(Acc_Type
, Acc_Type
);
3939 Set_Directly_Designated_Type
(Acc_Type
, Etype
(P
));
3940 Set_Etype
(N
, Acc_Type
);
3941 end Analyze_Reference
;
3943 --------------------------------
3944 -- Analyze_Selected_Component --
3945 --------------------------------
3947 -- Prefix is a record type or a task or protected type. In the latter case,
3948 -- the selector must denote a visible entry.
3950 procedure Analyze_Selected_Component
(N
: Node_Id
) is
3951 Name
: constant Node_Id
:= Prefix
(N
);
3952 Sel
: constant Node_Id
:= Selector_Name
(N
);
3955 Has_Candidate
: Boolean := False;
3958 Pent
: Entity_Id
:= Empty
;
3959 Prefix_Type
: Entity_Id
;
3961 Type_To_Use
: Entity_Id
;
3962 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
3963 -- a class-wide type, we use its root type, whose components are
3964 -- present in the class-wide type.
3966 Is_Single_Concurrent_Object
: Boolean;
3967 -- Set True if the prefix is a single task or a single protected object
3969 procedure Find_Component_In_Instance
(Rec
: Entity_Id
);
3970 -- In an instance, a component of a private extension may not be visible
3971 -- while it was visible in the generic. Search candidate scope for a
3972 -- component with the proper identifier. This is only done if all other
3973 -- searches have failed. If a match is found, the Etype of both N and
3974 -- Sel are set from this component, and the entity of Sel is set to
3975 -- reference this component. If no match is found, Entity (Sel) remains
3978 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean;
3979 -- It is known that the parent of N denotes a subprogram call. Comp
3980 -- is an overloadable component of the concurrent type of the prefix.
3981 -- Determine whether all formals of the parent of N and Comp are mode
3982 -- conformant. If the parent node is not analyzed yet it may be an
3983 -- indexed component rather than a function call.
3985 --------------------------------
3986 -- Find_Component_In_Instance --
3987 --------------------------------
3989 procedure Find_Component_In_Instance
(Rec
: Entity_Id
) is
3993 Comp
:= First_Component
(Rec
);
3994 while Present
(Comp
) loop
3995 if Chars
(Comp
) = Chars
(Sel
) then
3996 Set_Entity_With_Checks
(Sel
, Comp
);
3997 Set_Etype
(Sel
, Etype
(Comp
));
3998 Set_Etype
(N
, Etype
(Comp
));
4002 Next_Component
(Comp
);
4005 -- If we fall through, no match, so no changes made
4008 end Find_Component_In_Instance
;
4010 ------------------------------
4011 -- Has_Mode_Conformant_Spec --
4012 ------------------------------
4014 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean is
4015 Comp_Param
: Entity_Id
;
4017 Param_Typ
: Entity_Id
;
4020 Comp_Param
:= First_Formal
(Comp
);
4022 if Nkind
(Parent
(N
)) = N_Indexed_Component
then
4023 Param
:= First
(Expressions
(Parent
(N
)));
4025 Param
:= First
(Parameter_Associations
(Parent
(N
)));
4028 while Present
(Comp_Param
)
4029 and then Present
(Param
)
4031 Param_Typ
:= Find_Parameter_Type
(Param
);
4033 if Present
(Param_Typ
)
4035 not Conforming_Types
4036 (Etype
(Comp_Param
), Param_Typ
, Mode_Conformant
)
4041 Next_Formal
(Comp_Param
);
4045 -- One of the specs has additional formals; there is no match, unless
4046 -- this may be an indexing of a parameterless call.
4048 -- Note that when expansion is disabled, the corresponding record
4049 -- type of synchronized types is not constructed, so that there is
4050 -- no point is attempting an interpretation as a prefixed call, as
4051 -- this is bound to fail because the primitive operations will not
4052 -- be properly located.
4054 if Present
(Comp_Param
) or else Present
(Param
) then
4055 if Needs_No_Actuals
(Comp
)
4056 and then Is_Array_Type
(Etype
(Comp
))
4057 and then not Expander_Active
4066 end Has_Mode_Conformant_Spec
;
4068 -- Start of processing for Analyze_Selected_Component
4071 Set_Etype
(N
, Any_Type
);
4073 if Is_Overloaded
(Name
) then
4074 Analyze_Overloaded_Selected_Component
(N
);
4077 elsif Etype
(Name
) = Any_Type
then
4078 Set_Entity
(Sel
, Any_Id
);
4079 Set_Etype
(Sel
, Any_Type
);
4083 Prefix_Type
:= Etype
(Name
);
4086 if Is_Access_Type
(Prefix_Type
) then
4088 -- A RACW object can never be used as prefix of a selected component
4089 -- since that means it is dereferenced without being a controlling
4090 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
4091 -- reporting an error, we must check whether this is actually a
4092 -- dispatching call in prefix form.
4094 if Is_Remote_Access_To_Class_Wide_Type
(Prefix_Type
)
4095 and then Comes_From_Source
(N
)
4097 if Try_Object_Operation
(N
) then
4101 ("invalid dereference of a remote access-to-class-wide value",
4105 -- Normal case of selected component applied to access type
4108 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4110 if Is_Entity_Name
(Name
) then
4111 Pent
:= Entity
(Name
);
4112 elsif Nkind
(Name
) = N_Selected_Component
4113 and then Is_Entity_Name
(Selector_Name
(Name
))
4115 Pent
:= Entity
(Selector_Name
(Name
));
4118 Prefix_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, Name
);
4121 -- If we have an explicit dereference of a remote access-to-class-wide
4122 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
4123 -- have to check for the case of a prefix that is a controlling operand
4124 -- of a prefixed dispatching call, as the dereference is legal in that
4125 -- case. Normally this condition is checked in Validate_Remote_Access_
4126 -- To_Class_Wide_Type, but we have to defer the checking for selected
4127 -- component prefixes because of the prefixed dispatching call case.
4128 -- Note that implicit dereferences are checked for this just above.
4130 elsif Nkind
(Name
) = N_Explicit_Dereference
4131 and then Is_Remote_Access_To_Class_Wide_Type
(Etype
(Prefix
(Name
)))
4132 and then Comes_From_Source
(N
)
4134 if Try_Object_Operation
(N
) then
4138 ("invalid dereference of a remote access-to-class-wide value",
4143 -- (Ada 2005): if the prefix is the limited view of a type, and
4144 -- the context already includes the full view, use the full view
4145 -- in what follows, either to retrieve a component of to find
4146 -- a primitive operation. If the prefix is an explicit dereference,
4147 -- set the type of the prefix to reflect this transformation.
4148 -- If the non-limited view is itself an incomplete type, get the
4149 -- full view if available.
4151 if Is_Incomplete_Type
(Prefix_Type
)
4152 and then From_Limited_With
(Prefix_Type
)
4153 and then Present
(Non_Limited_View
(Prefix_Type
))
4155 Prefix_Type
:= Get_Full_View
(Non_Limited_View
(Prefix_Type
));
4157 if Nkind
(N
) = N_Explicit_Dereference
then
4158 Set_Etype
(Prefix
(N
), Prefix_Type
);
4161 elsif Ekind
(Prefix_Type
) = E_Class_Wide_Type
4162 and then From_Limited_With
(Prefix_Type
)
4163 and then Present
(Non_Limited_View
(Etype
(Prefix_Type
)))
4166 Class_Wide_Type
(Non_Limited_View
(Etype
(Prefix_Type
)));
4168 if Nkind
(N
) = N_Explicit_Dereference
then
4169 Set_Etype
(Prefix
(N
), Prefix_Type
);
4173 if Ekind
(Prefix_Type
) = E_Private_Subtype
then
4174 Prefix_Type
:= Base_Type
(Prefix_Type
);
4177 Type_To_Use
:= Prefix_Type
;
4179 -- For class-wide types, use the entity list of the root type. This
4180 -- indirection is specially important for private extensions because
4181 -- only the root type get switched (not the class-wide type).
4183 if Is_Class_Wide_Type
(Prefix_Type
) then
4184 Type_To_Use
:= Root_Type
(Prefix_Type
);
4187 -- If the prefix is a single concurrent object, use its name in error
4188 -- messages, rather than that of its anonymous type.
4190 Is_Single_Concurrent_Object
:=
4191 Is_Concurrent_Type
(Prefix_Type
)
4192 and then Is_Internal_Name
(Chars
(Prefix_Type
))
4193 and then not Is_Derived_Type
(Prefix_Type
)
4194 and then Is_Entity_Name
(Name
);
4196 Comp
:= First_Entity
(Type_To_Use
);
4198 -- If the selector has an original discriminant, the node appears in
4199 -- an instance. Replace the discriminant with the corresponding one
4200 -- in the current discriminated type. For nested generics, this must
4201 -- be done transitively, so note the new original discriminant.
4203 if Nkind
(Sel
) = N_Identifier
4204 and then In_Instance
4205 and then Present
(Original_Discriminant
(Sel
))
4207 Comp
:= Find_Corresponding_Discriminant
(Sel
, Prefix_Type
);
4209 -- Mark entity before rewriting, for completeness and because
4210 -- subsequent semantic checks might examine the original node.
4212 Set_Entity
(Sel
, Comp
);
4213 Rewrite
(Selector_Name
(N
), New_Occurrence_Of
(Comp
, Sloc
(N
)));
4214 Set_Original_Discriminant
(Selector_Name
(N
), Comp
);
4215 Set_Etype
(N
, Etype
(Comp
));
4216 Check_Implicit_Dereference
(N
, Etype
(Comp
));
4218 if Is_Access_Type
(Etype
(Name
)) then
4219 Insert_Explicit_Dereference
(Name
);
4220 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4223 elsif Is_Record_Type
(Prefix_Type
) then
4225 -- Find component with given name. In an instance, if the node is
4226 -- known as a prefixed call, do not examine components whose
4227 -- visibility may be accidental.
4229 while Present
(Comp
) and then not Is_Prefixed_Call
(N
) loop
4230 if Chars
(Comp
) = Chars
(Sel
)
4231 and then Is_Visible_Component
(Comp
, N
)
4233 Set_Entity_With_Checks
(Sel
, Comp
);
4234 Set_Etype
(Sel
, Etype
(Comp
));
4236 if Ekind
(Comp
) = E_Discriminant
then
4237 if Is_Unchecked_Union
(Base_Type
(Prefix_Type
)) then
4239 ("cannot reference discriminant of unchecked union",
4243 if Is_Generic_Type
(Prefix_Type
)
4245 Is_Generic_Type
(Root_Type
(Prefix_Type
))
4247 Set_Original_Discriminant
(Sel
, Comp
);
4251 -- Resolve the prefix early otherwise it is not possible to
4252 -- build the actual subtype of the component: it may need
4253 -- to duplicate this prefix and duplication is only allowed
4254 -- on fully resolved expressions.
4258 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
4259 -- subtypes in a package specification.
4262 -- limited with Pkg;
4264 -- type Acc_Inc is access Pkg.T;
4266 -- N : Natural := X.all.Comp; -- ERROR, limited view
4267 -- end Pkg; -- Comp is not visible
4269 if Nkind
(Name
) = N_Explicit_Dereference
4270 and then From_Limited_With
(Etype
(Prefix
(Name
)))
4271 and then not Is_Potentially_Use_Visible
(Etype
(Name
))
4272 and then Nkind
(Parent
(Cunit_Entity
(Current_Sem_Unit
))) =
4273 N_Package_Specification
4276 ("premature usage of incomplete}", Prefix
(Name
),
4277 Etype
(Prefix
(Name
)));
4280 -- We never need an actual subtype for the case of a selection
4281 -- for a indexed component of a non-packed array, since in
4282 -- this case gigi generates all the checks and can find the
4283 -- necessary bounds information.
4285 -- We also do not need an actual subtype for the case of a
4286 -- first, last, length, or range attribute applied to a
4287 -- non-packed array, since gigi can again get the bounds in
4288 -- these cases (gigi cannot handle the packed case, since it
4289 -- has the bounds of the packed array type, not the original
4290 -- bounds of the type). However, if the prefix is itself a
4291 -- selected component, as in a.b.c (i), gigi may regard a.b.c
4292 -- as a dynamic-sized temporary, so we do generate an actual
4293 -- subtype for this case.
4295 Parent_N
:= Parent
(N
);
4297 if not Is_Packed
(Etype
(Comp
))
4299 ((Nkind
(Parent_N
) = N_Indexed_Component
4300 and then Nkind
(Name
) /= N_Selected_Component
)
4302 (Nkind
(Parent_N
) = N_Attribute_Reference
4304 Nam_In
(Attribute_Name
(Parent_N
), Name_First
,
4309 Set_Etype
(N
, Etype
(Comp
));
4311 -- If full analysis is not enabled, we do not generate an
4312 -- actual subtype, because in the absence of expansion
4313 -- reference to a formal of a protected type, for example,
4314 -- will not be properly transformed, and will lead to
4315 -- out-of-scope references in gigi.
4317 -- In all other cases, we currently build an actual subtype.
4318 -- It seems likely that many of these cases can be avoided,
4319 -- but right now, the front end makes direct references to the
4320 -- bounds (e.g. in generating a length check), and if we do
4321 -- not make an actual subtype, we end up getting a direct
4322 -- reference to a discriminant, which will not do.
4324 elsif Full_Analysis
then
4326 Build_Actual_Subtype_Of_Component
(Etype
(Comp
), N
);
4327 Insert_Action
(N
, Act_Decl
);
4329 if No
(Act_Decl
) then
4330 Set_Etype
(N
, Etype
(Comp
));
4333 -- Component type depends on discriminants. Enter the
4334 -- main attributes of the subtype.
4337 Subt
: constant Entity_Id
:=
4338 Defining_Identifier
(Act_Decl
);
4341 Set_Etype
(Subt
, Base_Type
(Etype
(Comp
)));
4342 Set_Ekind
(Subt
, Ekind
(Etype
(Comp
)));
4343 Set_Etype
(N
, Subt
);
4347 -- If Full_Analysis not enabled, just set the Etype
4350 Set_Etype
(N
, Etype
(Comp
));
4353 Check_Implicit_Dereference
(N
, Etype
(N
));
4357 -- If the prefix is a private extension, check only the visible
4358 -- components of the partial view. This must include the tag,
4359 -- which can appear in expanded code in a tag check.
4361 if Ekind
(Type_To_Use
) = E_Record_Type_With_Private
4362 and then Chars
(Selector_Name
(N
)) /= Name_uTag
4364 exit when Comp
= Last_Entity
(Type_To_Use
);
4370 -- Ada 2005 (AI-252): The selected component can be interpreted as
4371 -- a prefixed view of a subprogram. Depending on the context, this is
4372 -- either a name that can appear in a renaming declaration, or part
4373 -- of an enclosing call given in prefix form.
4375 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
4376 -- selected component should resolve to a name.
4378 if Ada_Version
>= Ada_2005
4379 and then Is_Tagged_Type
(Prefix_Type
)
4380 and then not Is_Concurrent_Type
(Prefix_Type
)
4382 if Nkind
(Parent
(N
)) = N_Generic_Association
4383 or else Nkind
(Parent
(N
)) = N_Requeue_Statement
4384 or else Nkind
(Parent
(N
)) = N_Subprogram_Renaming_Declaration
4386 if Find_Primitive_Operation
(N
) then
4390 elsif Try_Object_Operation
(N
) then
4394 -- If the transformation fails, it will be necessary to redo the
4395 -- analysis with all errors enabled, to indicate candidate
4396 -- interpretations and reasons for each failure ???
4400 elsif Is_Private_Type
(Prefix_Type
) then
4402 -- Allow access only to discriminants of the type. If the type has
4403 -- no full view, gigi uses the parent type for the components, so we
4404 -- do the same here.
4406 if No
(Full_View
(Prefix_Type
)) then
4407 Type_To_Use
:= Root_Type
(Base_Type
(Prefix_Type
));
4408 Comp
:= First_Entity
(Type_To_Use
);
4411 while Present
(Comp
) loop
4412 if Chars
(Comp
) = Chars
(Sel
) then
4413 if Ekind
(Comp
) = E_Discriminant
then
4414 Set_Entity_With_Checks
(Sel
, Comp
);
4415 Generate_Reference
(Comp
, Sel
);
4417 Set_Etype
(Sel
, Etype
(Comp
));
4418 Set_Etype
(N
, Etype
(Comp
));
4419 Check_Implicit_Dereference
(N
, Etype
(N
));
4421 if Is_Generic_Type
(Prefix_Type
)
4422 or else Is_Generic_Type
(Root_Type
(Prefix_Type
))
4424 Set_Original_Discriminant
(Sel
, Comp
);
4427 -- Before declaring an error, check whether this is tagged
4428 -- private type and a call to a primitive operation.
4430 elsif Ada_Version
>= Ada_2005
4431 and then Is_Tagged_Type
(Prefix_Type
)
4432 and then Try_Object_Operation
(N
)
4437 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4438 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
4439 Set_Entity
(Sel
, Any_Id
);
4440 Set_Etype
(N
, Any_Type
);
4449 elsif Is_Concurrent_Type
(Prefix_Type
) then
4451 -- Find visible operation with given name. For a protected type,
4452 -- the possible candidates are discriminants, entries or protected
4453 -- procedures. For a task type, the set can only include entries or
4454 -- discriminants if the task type is not an enclosing scope. If it
4455 -- is an enclosing scope (e.g. in an inner task) then all entities
4456 -- are visible, but the prefix must denote the enclosing scope, i.e.
4457 -- can only be a direct name or an expanded name.
4459 Set_Etype
(Sel
, Any_Type
);
4460 In_Scope
:= In_Open_Scopes
(Prefix_Type
);
4462 while Present
(Comp
) loop
4463 if Chars
(Comp
) = Chars
(Sel
) then
4464 if Is_Overloadable
(Comp
) then
4465 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
4467 -- If the prefix is tagged, the correct interpretation may
4468 -- lie in the primitive or class-wide operations of the
4469 -- type. Perform a simple conformance check to determine
4470 -- whether Try_Object_Operation should be invoked even if
4471 -- a visible entity is found.
4473 if Is_Tagged_Type
(Prefix_Type
)
4475 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
4477 N_Indexed_Component
)
4478 and then Has_Mode_Conformant_Spec
(Comp
)
4480 Has_Candidate
:= True;
4483 -- Note: a selected component may not denote a component of a
4484 -- protected type (4.1.3(7)).
4486 elsif Ekind_In
(Comp
, E_Discriminant
, E_Entry_Family
)
4488 and then not Is_Protected_Type
(Prefix_Type
)
4489 and then Is_Entity_Name
(Name
))
4491 Set_Entity_With_Checks
(Sel
, Comp
);
4492 Generate_Reference
(Comp
, Sel
);
4494 -- The selector is not overloadable, so we have a candidate
4497 Has_Candidate
:= True;
4503 Set_Etype
(Sel
, Etype
(Comp
));
4504 Set_Etype
(N
, Etype
(Comp
));
4506 if Ekind
(Comp
) = E_Discriminant
then
4507 Set_Original_Discriminant
(Sel
, Comp
);
4510 -- For access type case, introduce explicit dereference for
4511 -- more uniform treatment of entry calls.
4513 if Is_Access_Type
(Etype
(Name
)) then
4514 Insert_Explicit_Dereference
(Name
);
4516 (Warn_On_Dereference
, "?d?implicit dereference", N
);
4522 exit when not In_Scope
4524 Comp
= First_Private_Entity
(Base_Type
(Prefix_Type
));
4527 -- If there is no visible entity with the given name or none of the
4528 -- visible entities are plausible interpretations, check whether
4529 -- there is some other primitive operation with that name.
4531 if Ada_Version
>= Ada_2005
4532 and then Is_Tagged_Type
(Prefix_Type
)
4534 if (Etype
(N
) = Any_Type
4535 or else not Has_Candidate
)
4536 and then Try_Object_Operation
(N
)
4540 -- If the context is not syntactically a procedure call, it
4541 -- may be a call to a primitive function declared outside of
4542 -- the synchronized type.
4544 -- If the context is a procedure call, there might still be
4545 -- an overloading between an entry and a primitive procedure
4546 -- declared outside of the synchronized type, called in prefix
4547 -- notation. This is harder to disambiguate because in one case
4548 -- the controlling formal is implicit ???
4550 elsif Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
4551 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
4552 and then Try_Object_Operation
(N
)
4557 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
4558 -- entry or procedure of a tagged concurrent type we must check
4559 -- if there are class-wide subprograms covering the primitive. If
4560 -- true then Try_Object_Operation reports the error.
4563 and then Is_Concurrent_Type
(Prefix_Type
)
4564 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
4566 -- Duplicate the call. This is required to avoid problems with
4567 -- the tree transformations performed by Try_Object_Operation.
4568 -- Set properly the parent of the copied call, because it is
4569 -- about to be reanalyzed.
4573 Par
: constant Node_Id
:= New_Copy_Tree
(Parent
(N
));
4576 Set_Parent
(Par
, Parent
(Parent
(N
)));
4578 if Try_Object_Operation
4579 (Sinfo
.Name
(Par
), CW_Test_Only
=> True)
4587 if Etype
(N
) = Any_Type
and then Is_Protected_Type
(Prefix_Type
) then
4589 -- Case of a prefix of a protected type: selector might denote
4590 -- an invisible private component.
4592 Comp
:= First_Private_Entity
(Base_Type
(Prefix_Type
));
4593 while Present
(Comp
) and then Chars
(Comp
) /= Chars
(Sel
) loop
4597 if Present
(Comp
) then
4598 if Is_Single_Concurrent_Object
then
4599 Error_Msg_Node_2
:= Entity
(Name
);
4600 Error_Msg_NE
("invisible selector& for &", N
, Sel
);
4603 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4604 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
4610 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
4615 Error_Msg_NE
("invalid prefix in selected component&", N
, Sel
);
4618 -- If N still has no type, the component is not defined in the prefix
4620 if Etype
(N
) = Any_Type
then
4622 if Is_Single_Concurrent_Object
then
4623 Error_Msg_Node_2
:= Entity
(Name
);
4624 Error_Msg_NE
("no selector& for&", N
, Sel
);
4626 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
4628 -- If this is a derived formal type, the parent may have different
4629 -- visibility at this point. Try for an inherited component before
4630 -- reporting an error.
4632 elsif Is_Generic_Type
(Prefix_Type
)
4633 and then Ekind
(Prefix_Type
) = E_Record_Type_With_Private
4634 and then Prefix_Type
/= Etype
(Prefix_Type
)
4635 and then Is_Record_Type
(Etype
(Prefix_Type
))
4637 Set_Etype
(Prefix
(N
), Etype
(Prefix_Type
));
4638 Analyze_Selected_Component
(N
);
4641 -- Similarly, if this is the actual for a formal derived type, or
4642 -- a derived type thereof, the component inherited from the generic
4643 -- parent may not be visible in the actual, but the selected
4644 -- component is legal. Climb up the derivation chain of the generic
4645 -- parent type until we find the proper ancestor type.
4647 elsif In_Instance
and then Is_Tagged_Type
(Prefix_Type
) then
4649 Par
: Entity_Id
:= Prefix_Type
;
4651 -- Climb up derivation chain to generic actual subtype
4653 while not Is_Generic_Actual_Type
(Par
) loop
4654 if Ekind
(Par
) = E_Record_Type
then
4655 Par
:= Parent_Subtype
(Par
);
4658 exit when Par
= Etype
(Par
);
4663 if Present
(Par
) and then Is_Generic_Actual_Type
(Par
) then
4665 -- Now look for component in ancestor types
4667 Par
:= Generic_Parent_Type
(Declaration_Node
(Par
));
4669 Find_Component_In_Instance
(Par
);
4670 exit when Present
(Entity
(Sel
))
4671 or else Par
= Etype
(Par
);
4675 -- In ASIS mode the generic parent type may be absent. Examine
4676 -- the parent type directly for a component that may have been
4677 -- visible in a parent generic unit.
4679 elsif Is_Derived_Type
(Prefix_Type
) then
4680 Par
:= Etype
(Prefix_Type
);
4681 Find_Component_In_Instance
(Par
);
4685 -- The search above must have eventually succeeded, since the
4686 -- selected component was legal in the generic.
4688 if No
(Entity
(Sel
)) then
4689 raise Program_Error
;
4694 -- Component not found, specialize error message when appropriate
4697 if Ekind
(Prefix_Type
) = E_Record_Subtype
then
4699 -- Check whether this is a component of the base type which
4700 -- is absent from a statically constrained subtype. This will
4701 -- raise constraint error at run time, but is not a compile-
4702 -- time error. When the selector is illegal for base type as
4703 -- well fall through and generate a compilation error anyway.
4705 Comp
:= First_Component
(Base_Type
(Prefix_Type
));
4706 while Present
(Comp
) loop
4707 if Chars
(Comp
) = Chars
(Sel
)
4708 and then Is_Visible_Component
(Comp
)
4710 Set_Entity_With_Checks
(Sel
, Comp
);
4711 Generate_Reference
(Comp
, Sel
);
4712 Set_Etype
(Sel
, Etype
(Comp
));
4713 Set_Etype
(N
, Etype
(Comp
));
4715 -- Emit appropriate message. The node will be replaced
4716 -- by an appropriate raise statement.
4718 -- Note that in SPARK mode, as with all calls to apply a
4719 -- compile time constraint error, this will be made into
4720 -- an error to simplify the processing of the formal
4721 -- verification backend.
4723 Apply_Compile_Time_Constraint_Error
4724 (N
, "component not present in }??",
4725 CE_Discriminant_Check_Failed
,
4726 Ent
=> Prefix_Type
, Rep
=> False);
4728 Set_Raises_Constraint_Error
(N
);
4732 Next_Component
(Comp
);
4737 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4738 Error_Msg_NE
("no selector& for}", N
, Sel
);
4740 -- Add information in the case of an incomplete prefix
4742 if Is_Incomplete_Type
(Type_To_Use
) then
4744 Inc
: constant Entity_Id
:= First_Subtype
(Type_To_Use
);
4747 if From_Limited_With
(Scope
(Type_To_Use
)) then
4749 ("\limited view of& has no components", N
, Inc
);
4753 ("\premature usage of incomplete type&", N
, Inc
);
4755 if Nkind
(Parent
(Inc
)) =
4756 N_Incomplete_Type_Declaration
4758 -- Record location of premature use in entity so that
4759 -- a continuation message is generated when the
4760 -- completion is seen.
4762 Set_Premature_Use
(Parent
(Inc
), N
);
4768 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
4771 Set_Entity
(Sel
, Any_Id
);
4772 Set_Etype
(Sel
, Any_Type
);
4774 end Analyze_Selected_Component
;
4776 ---------------------------
4777 -- Analyze_Short_Circuit --
4778 ---------------------------
4780 procedure Analyze_Short_Circuit
(N
: Node_Id
) is
4781 L
: constant Node_Id
:= Left_Opnd
(N
);
4782 R
: constant Node_Id
:= Right_Opnd
(N
);
4787 Analyze_Expression
(L
);
4788 Analyze_Expression
(R
);
4789 Set_Etype
(N
, Any_Type
);
4791 if not Is_Overloaded
(L
) then
4792 if Root_Type
(Etype
(L
)) = Standard_Boolean
4793 and then Has_Compatible_Type
(R
, Etype
(L
))
4795 Add_One_Interp
(N
, Etype
(L
), Etype
(L
));
4799 Get_First_Interp
(L
, Ind
, It
);
4800 while Present
(It
.Typ
) loop
4801 if Root_Type
(It
.Typ
) = Standard_Boolean
4802 and then Has_Compatible_Type
(R
, It
.Typ
)
4804 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
4807 Get_Next_Interp
(Ind
, It
);
4811 -- Here we have failed to find an interpretation. Clearly we know that
4812 -- it is not the case that both operands can have an interpretation of
4813 -- Boolean, but this is by far the most likely intended interpretation.
4814 -- So we simply resolve both operands as Booleans, and at least one of
4815 -- these resolutions will generate an error message, and we do not need
4816 -- to give another error message on the short circuit operation itself.
4818 if Etype
(N
) = Any_Type
then
4819 Resolve
(L
, Standard_Boolean
);
4820 Resolve
(R
, Standard_Boolean
);
4821 Set_Etype
(N
, Standard_Boolean
);
4823 end Analyze_Short_Circuit
;
4829 procedure Analyze_Slice
(N
: Node_Id
) is
4830 D
: constant Node_Id
:= Discrete_Range
(N
);
4831 P
: constant Node_Id
:= Prefix
(N
);
4832 Array_Type
: Entity_Id
;
4833 Index_Type
: Entity_Id
;
4835 procedure Analyze_Overloaded_Slice
;
4836 -- If the prefix is overloaded, select those interpretations that
4837 -- yield a one-dimensional array type.
4839 ------------------------------
4840 -- Analyze_Overloaded_Slice --
4841 ------------------------------
4843 procedure Analyze_Overloaded_Slice
is
4849 Set_Etype
(N
, Any_Type
);
4851 Get_First_Interp
(P
, I
, It
);
4852 while Present
(It
.Nam
) loop
4855 if Is_Access_Type
(Typ
) then
4856 Typ
:= Designated_Type
(Typ
);
4858 (Warn_On_Dereference
, "?d?implicit dereference", N
);
4861 if Is_Array_Type
(Typ
)
4862 and then Number_Dimensions
(Typ
) = 1
4863 and then Has_Compatible_Type
(D
, Etype
(First_Index
(Typ
)))
4865 Add_One_Interp
(N
, Typ
, Typ
);
4868 Get_Next_Interp
(I
, It
);
4871 if Etype
(N
) = Any_Type
then
4872 Error_Msg_N
("expect array type in prefix of slice", N
);
4874 end Analyze_Overloaded_Slice
;
4876 -- Start of processing for Analyze_Slice
4879 if Comes_From_Source
(N
) then
4880 Check_SPARK_05_Restriction
("slice is not allowed", N
);
4886 if Is_Overloaded
(P
) then
4887 Analyze_Overloaded_Slice
;
4890 Array_Type
:= Etype
(P
);
4891 Set_Etype
(N
, Any_Type
);
4893 if Is_Access_Type
(Array_Type
) then
4894 Array_Type
:= Designated_Type
(Array_Type
);
4895 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4898 if not Is_Array_Type
(Array_Type
) then
4899 Wrong_Type
(P
, Any_Array
);
4901 elsif Number_Dimensions
(Array_Type
) > 1 then
4903 ("type is not one-dimensional array in slice prefix", N
);
4906 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
4907 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
4909 Index_Type
:= Etype
(First_Index
(Array_Type
));
4912 if not Has_Compatible_Type
(D
, Index_Type
) then
4913 Wrong_Type
(D
, Index_Type
);
4915 Set_Etype
(N
, Array_Type
);
4921 -----------------------------
4922 -- Analyze_Type_Conversion --
4923 -----------------------------
4925 procedure Analyze_Type_Conversion
(N
: Node_Id
) is
4926 Expr
: constant Node_Id
:= Expression
(N
);
4930 -- If Conversion_OK is set, then the Etype is already set, and the
4931 -- only processing required is to analyze the expression. This is
4932 -- used to construct certain "illegal" conversions which are not
4933 -- allowed by Ada semantics, but can be handled OK by Gigi, see
4934 -- Sinfo for further details.
4936 if Conversion_OK
(N
) then
4941 -- Otherwise full type analysis is required, as well as some semantic
4942 -- checks to make sure the argument of the conversion is appropriate.
4944 Find_Type
(Subtype_Mark
(N
));
4945 T
:= Entity
(Subtype_Mark
(N
));
4947 Check_Fully_Declared
(T
, N
);
4948 Analyze_Expression
(Expr
);
4949 Validate_Remote_Type_Type_Conversion
(N
);
4951 -- Only remaining step is validity checks on the argument. These
4952 -- are skipped if the conversion does not come from the source.
4954 if not Comes_From_Source
(N
) then
4957 -- If there was an error in a generic unit, no need to replicate the
4958 -- error message. Conversely, constant-folding in the generic may
4959 -- transform the argument of a conversion into a string literal, which
4960 -- is legal. Therefore the following tests are not performed in an
4961 -- instance. The same applies to an inlined body.
4963 elsif In_Instance
or In_Inlined_Body
then
4966 elsif Nkind
(Expr
) = N_Null
then
4967 Error_Msg_N
("argument of conversion cannot be null", N
);
4968 Error_Msg_N
("\use qualified expression instead", N
);
4969 Set_Etype
(N
, Any_Type
);
4971 elsif Nkind
(Expr
) = N_Aggregate
then
4972 Error_Msg_N
("argument of conversion cannot be aggregate", N
);
4973 Error_Msg_N
("\use qualified expression instead", N
);
4975 elsif Nkind
(Expr
) = N_Allocator
then
4976 Error_Msg_N
("argument of conversion cannot be an allocator", N
);
4977 Error_Msg_N
("\use qualified expression instead", N
);
4979 elsif Nkind
(Expr
) = N_String_Literal
then
4980 Error_Msg_N
("argument of conversion cannot be string literal", N
);
4981 Error_Msg_N
("\use qualified expression instead", N
);
4983 elsif Nkind
(Expr
) = N_Character_Literal
then
4984 if Ada_Version
= Ada_83
then
4987 Error_Msg_N
("argument of conversion cannot be character literal",
4989 Error_Msg_N
("\use qualified expression instead", N
);
4992 elsif Nkind
(Expr
) = N_Attribute_Reference
4994 Nam_In
(Attribute_Name
(Expr
), Name_Access
,
4995 Name_Unchecked_Access
,
4996 Name_Unrestricted_Access
)
4998 Error_Msg_N
("argument of conversion cannot be access", N
);
4999 Error_Msg_N
("\use qualified expression instead", N
);
5001 end Analyze_Type_Conversion
;
5003 ----------------------
5004 -- Analyze_Unary_Op --
5005 ----------------------
5007 procedure Analyze_Unary_Op
(N
: Node_Id
) is
5008 R
: constant Node_Id
:= Right_Opnd
(N
);
5009 Op_Id
: Entity_Id
:= Entity
(N
);
5012 Set_Etype
(N
, Any_Type
);
5013 Candidate_Type
:= Empty
;
5015 Analyze_Expression
(R
);
5017 if Present
(Op_Id
) then
5018 if Ekind
(Op_Id
) = E_Operator
then
5019 Find_Unary_Types
(R
, Op_Id
, N
);
5021 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5025 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
5026 while Present
(Op_Id
) loop
5027 if Ekind
(Op_Id
) = E_Operator
then
5028 if No
(Next_Entity
(First_Entity
(Op_Id
))) then
5029 Find_Unary_Types
(R
, Op_Id
, N
);
5032 elsif Is_Overloadable
(Op_Id
) then
5033 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
5036 Op_Id
:= Homonym
(Op_Id
);
5041 end Analyze_Unary_Op
;
5043 ----------------------------------
5044 -- Analyze_Unchecked_Expression --
5045 ----------------------------------
5047 procedure Analyze_Unchecked_Expression
(N
: Node_Id
) is
5049 Analyze
(Expression
(N
), Suppress
=> All_Checks
);
5050 Set_Etype
(N
, Etype
(Expression
(N
)));
5051 Save_Interps
(Expression
(N
), N
);
5052 end Analyze_Unchecked_Expression
;
5054 ---------------------------------------
5055 -- Analyze_Unchecked_Type_Conversion --
5056 ---------------------------------------
5058 procedure Analyze_Unchecked_Type_Conversion
(N
: Node_Id
) is
5060 Find_Type
(Subtype_Mark
(N
));
5061 Analyze_Expression
(Expression
(N
));
5062 Set_Etype
(N
, Entity
(Subtype_Mark
(N
)));
5063 end Analyze_Unchecked_Type_Conversion
;
5065 ------------------------------------
5066 -- Analyze_User_Defined_Binary_Op --
5067 ------------------------------------
5069 procedure Analyze_User_Defined_Binary_Op
5074 -- Only do analysis if the operator Comes_From_Source, since otherwise
5075 -- the operator was generated by the expander, and all such operators
5076 -- always refer to the operators in package Standard.
5078 if Comes_From_Source
(N
) then
5080 F1
: constant Entity_Id
:= First_Formal
(Op_Id
);
5081 F2
: constant Entity_Id
:= Next_Formal
(F1
);
5084 -- Verify that Op_Id is a visible binary function. Note that since
5085 -- we know Op_Id is overloaded, potentially use visible means use
5086 -- visible for sure (RM 9.4(11)).
5088 if Ekind
(Op_Id
) = E_Function
5089 and then Present
(F2
)
5090 and then (Is_Immediately_Visible
(Op_Id
)
5091 or else Is_Potentially_Use_Visible
(Op_Id
))
5092 and then Has_Compatible_Type
(Left_Opnd
(N
), Etype
(F1
))
5093 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F2
))
5095 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5097 -- If the left operand is overloaded, indicate that the current
5098 -- type is a viable candidate. This is redundant in most cases,
5099 -- but for equality and comparison operators where the context
5100 -- does not impose a type on the operands, setting the proper
5101 -- type is necessary to avoid subsequent ambiguities during
5102 -- resolution, when both user-defined and predefined operators
5103 -- may be candidates.
5105 if Is_Overloaded
(Left_Opnd
(N
)) then
5106 Set_Etype
(Left_Opnd
(N
), Etype
(F1
));
5109 if Debug_Flag_E
then
5110 Write_Str
("user defined operator ");
5111 Write_Name
(Chars
(Op_Id
));
5112 Write_Str
(" on node ");
5113 Write_Int
(Int
(N
));
5119 end Analyze_User_Defined_Binary_Op
;
5121 -----------------------------------
5122 -- Analyze_User_Defined_Unary_Op --
5123 -----------------------------------
5125 procedure Analyze_User_Defined_Unary_Op
5130 -- Only do analysis if the operator Comes_From_Source, since otherwise
5131 -- the operator was generated by the expander, and all such operators
5132 -- always refer to the operators in package Standard.
5134 if Comes_From_Source
(N
) then
5136 F
: constant Entity_Id
:= First_Formal
(Op_Id
);
5139 -- Verify that Op_Id is a visible unary function. Note that since
5140 -- we know Op_Id is overloaded, potentially use visible means use
5141 -- visible for sure (RM 9.4(11)).
5143 if Ekind
(Op_Id
) = E_Function
5144 and then No
(Next_Formal
(F
))
5145 and then (Is_Immediately_Visible
(Op_Id
)
5146 or else Is_Potentially_Use_Visible
(Op_Id
))
5147 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F
))
5149 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5153 end Analyze_User_Defined_Unary_Op
;
5155 ---------------------------
5156 -- Check_Arithmetic_Pair --
5157 ---------------------------
5159 procedure Check_Arithmetic_Pair
5160 (T1
, T2
: Entity_Id
;
5164 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
5166 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean;
5167 -- Check whether the fixed-point type Typ has a user-defined operator
5168 -- (multiplication or division) that should hide the corresponding
5169 -- predefined operator. Used to implement Ada 2005 AI-264, to make
5170 -- such operators more visible and therefore useful.
5172 -- If the name of the operation is an expanded name with prefix
5173 -- Standard, the predefined universal fixed operator is available,
5174 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
5176 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
;
5177 -- Get specific type (i.e. non-universal type if there is one)
5183 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean is
5184 Bas
: constant Entity_Id
:= Base_Type
(Typ
);
5190 -- If the universal_fixed operation is given explicitly the rule
5191 -- concerning primitive operations of the type do not apply.
5193 if Nkind
(N
) = N_Function_Call
5194 and then Nkind
(Name
(N
)) = N_Expanded_Name
5195 and then Entity
(Prefix
(Name
(N
))) = Standard_Standard
5200 -- The operation is treated as primitive if it is declared in the
5201 -- same scope as the type, and therefore on the same entity chain.
5203 Ent
:= Next_Entity
(Typ
);
5204 while Present
(Ent
) loop
5205 if Chars
(Ent
) = Chars
(Op
) then
5206 F1
:= First_Formal
(Ent
);
5207 F2
:= Next_Formal
(F1
);
5209 -- The operation counts as primitive if either operand or
5210 -- result are of the given base type, and both operands are
5211 -- fixed point types.
5213 if (Base_Type
(Etype
(F1
)) = Bas
5214 and then Is_Fixed_Point_Type
(Etype
(F2
)))
5217 (Base_Type
(Etype
(F2
)) = Bas
5218 and then Is_Fixed_Point_Type
(Etype
(F1
)))
5221 (Base_Type
(Etype
(Ent
)) = Bas
5222 and then Is_Fixed_Point_Type
(Etype
(F1
))
5223 and then Is_Fixed_Point_Type
(Etype
(F2
)))
5239 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
is
5241 if T1
= Universal_Integer
or else T1
= Universal_Real
then
5242 return Base_Type
(T2
);
5244 return Base_Type
(T1
);
5248 -- Start of processing for Check_Arithmetic_Pair
5251 if Nam_In
(Op_Name
, Name_Op_Add
, Name_Op_Subtract
) then
5252 if Is_Numeric_Type
(T1
)
5253 and then Is_Numeric_Type
(T2
)
5254 and then (Covers
(T1
=> T1
, T2
=> T2
)
5256 Covers
(T1
=> T2
, T2
=> T1
))
5258 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5261 elsif Nam_In
(Op_Name
, Name_Op_Multiply
, Name_Op_Divide
) then
5262 if Is_Fixed_Point_Type
(T1
)
5263 and then (Is_Fixed_Point_Type
(T2
) or else T2
= Universal_Real
)
5265 -- If Treat_Fixed_As_Integer is set then the Etype is already set
5266 -- and no further processing is required (this is the case of an
5267 -- operator constructed by Exp_Fixd for a fixed point operation)
5268 -- Otherwise add one interpretation with universal fixed result
5269 -- If the operator is given in functional notation, it comes
5270 -- from source and Fixed_As_Integer cannot apply.
5272 if (Nkind
(N
) not in N_Op
5273 or else not Treat_Fixed_As_Integer
(N
))
5275 (not Has_Fixed_Op
(T1
, Op_Id
)
5276 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
5278 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
5281 elsif Is_Fixed_Point_Type
(T2
)
5282 and then (Nkind
(N
) not in N_Op
5283 or else not Treat_Fixed_As_Integer
(N
))
5284 and then T1
= Universal_Real
5286 (not Has_Fixed_Op
(T1
, Op_Id
)
5287 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
5289 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
5291 elsif Is_Numeric_Type
(T1
)
5292 and then Is_Numeric_Type
(T2
)
5293 and then (Covers
(T1
=> T1
, T2
=> T2
)
5295 Covers
(T1
=> T2
, T2
=> T1
))
5297 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5299 elsif Is_Fixed_Point_Type
(T1
)
5300 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5301 or else T2
= Universal_Integer
)
5303 Add_One_Interp
(N
, Op_Id
, T1
);
5305 elsif T2
= Universal_Real
5306 and then Base_Type
(T1
) = Base_Type
(Standard_Integer
)
5307 and then Op_Name
= Name_Op_Multiply
5309 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
5311 elsif T1
= Universal_Real
5312 and then Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5314 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
5316 elsif Is_Fixed_Point_Type
(T2
)
5317 and then (Base_Type
(T1
) = Base_Type
(Standard_Integer
)
5318 or else T1
= Universal_Integer
)
5319 and then Op_Name
= Name_Op_Multiply
5321 Add_One_Interp
(N
, Op_Id
, T2
);
5323 elsif T1
= Universal_Real
and then T2
= Universal_Integer
then
5324 Add_One_Interp
(N
, Op_Id
, T1
);
5326 elsif T2
= Universal_Real
5327 and then T1
= Universal_Integer
5328 and then Op_Name
= Name_Op_Multiply
5330 Add_One_Interp
(N
, Op_Id
, T2
);
5333 elsif Op_Name
= Name_Op_Mod
or else Op_Name
= Name_Op_Rem
then
5335 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
5336 -- set does not require any special processing, since the Etype is
5337 -- already set (case of operation constructed by Exp_Fixed).
5339 if Is_Integer_Type
(T1
)
5340 and then (Covers
(T1
=> T1
, T2
=> T2
)
5342 Covers
(T1
=> T2
, T2
=> T1
))
5344 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5347 elsif Op_Name
= Name_Op_Expon
then
5348 if Is_Numeric_Type
(T1
)
5349 and then not Is_Fixed_Point_Type
(T1
)
5350 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5351 or else T2
= Universal_Integer
)
5353 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
5356 else pragma Assert
(Nkind
(N
) in N_Op_Shift
);
5358 -- If not one of the predefined operators, the node may be one
5359 -- of the intrinsic functions. Its kind is always specific, and
5360 -- we can use it directly, rather than the name of the operation.
5362 if Is_Integer_Type
(T1
)
5363 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5364 or else T2
= Universal_Integer
)
5366 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
5369 end Check_Arithmetic_Pair
;
5371 -------------------------------
5372 -- Check_Misspelled_Selector --
5373 -------------------------------
5375 procedure Check_Misspelled_Selector
5376 (Prefix
: Entity_Id
;
5379 Max_Suggestions
: constant := 2;
5380 Nr_Of_Suggestions
: Natural := 0;
5382 Suggestion_1
: Entity_Id
:= Empty
;
5383 Suggestion_2
: Entity_Id
:= Empty
;
5388 -- All the components of the prefix of selector Sel are matched against
5389 -- Sel and a count is maintained of possible misspellings. When at
5390 -- the end of the analysis there are one or two (not more) possible
5391 -- misspellings, these misspellings will be suggested as possible
5394 if not (Is_Private_Type
(Prefix
) or else Is_Record_Type
(Prefix
)) then
5396 -- Concurrent types should be handled as well ???
5401 Comp
:= First_Entity
(Prefix
);
5402 while Nr_Of_Suggestions
<= Max_Suggestions
and then Present
(Comp
) loop
5403 if Is_Visible_Component
(Comp
) then
5404 if Is_Bad_Spelling_Of
(Chars
(Comp
), Chars
(Sel
)) then
5405 Nr_Of_Suggestions
:= Nr_Of_Suggestions
+ 1;
5407 case Nr_Of_Suggestions
is
5408 when 1 => Suggestion_1
:= Comp
;
5409 when 2 => Suggestion_2
:= Comp
;
5410 when others => exit;
5415 Comp
:= Next_Entity
(Comp
);
5418 -- Report at most two suggestions
5420 if Nr_Of_Suggestions
= 1 then
5421 Error_Msg_NE
-- CODEFIX
5422 ("\possible misspelling of&", Sel
, Suggestion_1
);
5424 elsif Nr_Of_Suggestions
= 2 then
5425 Error_Msg_Node_2
:= Suggestion_2
;
5426 Error_Msg_NE
-- CODEFIX
5427 ("\possible misspelling of& or&", Sel
, Suggestion_1
);
5429 end Check_Misspelled_Selector
;
5431 ----------------------
5432 -- Defined_In_Scope --
5433 ----------------------
5435 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean
5437 S1
: constant Entity_Id
:= Scope
(Base_Type
(T
));
5440 or else (S1
= System_Aux_Id
and then S
= Scope
(S1
));
5441 end Defined_In_Scope
;
5447 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
) is
5453 Void_Interp_Seen
: Boolean := False;
5456 pragma Warnings
(Off
, Boolean);
5459 if Ada_Version
>= Ada_2005
then
5460 Actual
:= First_Actual
(N
);
5461 while Present
(Actual
) loop
5463 -- Ada 2005 (AI-50217): Post an error in case of premature
5464 -- usage of an entity from the limited view.
5466 if not Analyzed
(Etype
(Actual
))
5467 and then From_Limited_With
(Etype
(Actual
))
5469 Error_Msg_Qual_Level
:= 1;
5471 ("missing with_clause for scope of imported type&",
5472 Actual
, Etype
(Actual
));
5473 Error_Msg_Qual_Level
:= 0;
5476 Next_Actual
(Actual
);
5480 -- Analyze each candidate call again, with full error reporting
5484 ("no candidate interpretations match the actuals:!", Nam
);
5485 Err_Mode
:= All_Errors_Mode
;
5486 All_Errors_Mode
:= True;
5488 -- If this is a call to an operation of a concurrent type,
5489 -- the failed interpretations have been removed from the
5490 -- name. Recover them to provide full diagnostics.
5492 if Nkind
(Parent
(Nam
)) = N_Selected_Component
then
5493 Set_Entity
(Nam
, Empty
);
5494 New_Nam
:= New_Copy_Tree
(Parent
(Nam
));
5495 Set_Is_Overloaded
(New_Nam
, False);
5496 Set_Is_Overloaded
(Selector_Name
(New_Nam
), False);
5497 Set_Parent
(New_Nam
, Parent
(Parent
(Nam
)));
5498 Analyze_Selected_Component
(New_Nam
);
5499 Get_First_Interp
(Selector_Name
(New_Nam
), X
, It
);
5501 Get_First_Interp
(Nam
, X
, It
);
5504 while Present
(It
.Nam
) loop
5505 if Etype
(It
.Nam
) = Standard_Void_Type
then
5506 Void_Interp_Seen
:= True;
5509 Analyze_One_Call
(N
, It
.Nam
, True, Success
);
5510 Get_Next_Interp
(X
, It
);
5513 if Nkind
(N
) = N_Function_Call
then
5514 Get_First_Interp
(Nam
, X
, It
);
5515 while Present
(It
.Nam
) loop
5516 if Ekind_In
(It
.Nam
, E_Function
, E_Operator
) then
5519 Get_Next_Interp
(X
, It
);
5523 -- If all interpretations are procedures, this deserves a
5524 -- more precise message. Ditto if this appears as the prefix
5525 -- of a selected component, which may be a lexical error.
5528 ("\context requires function call, found procedure name", Nam
);
5530 if Nkind
(Parent
(N
)) = N_Selected_Component
5531 and then N
= Prefix
(Parent
(N
))
5533 Error_Msg_N
-- CODEFIX
5534 ("\period should probably be semicolon", Parent
(N
));
5537 elsif Nkind
(N
) = N_Procedure_Call_Statement
5538 and then not Void_Interp_Seen
5541 "\function name found in procedure call", Nam
);
5544 All_Errors_Mode
:= Err_Mode
;
5547 ---------------------------
5548 -- Find_Arithmetic_Types --
5549 ---------------------------
5551 procedure Find_Arithmetic_Types
5556 Index1
: Interp_Index
;
5557 Index2
: Interp_Index
;
5561 procedure Check_Right_Argument
(T
: Entity_Id
);
5562 -- Check right operand of operator
5564 --------------------------
5565 -- Check_Right_Argument --
5566 --------------------------
5568 procedure Check_Right_Argument
(T
: Entity_Id
) is
5570 if not Is_Overloaded
(R
) then
5571 Check_Arithmetic_Pair
(T
, Etype
(R
), Op_Id
, N
);
5573 Get_First_Interp
(R
, Index2
, It2
);
5574 while Present
(It2
.Typ
) loop
5575 Check_Arithmetic_Pair
(T
, It2
.Typ
, Op_Id
, N
);
5576 Get_Next_Interp
(Index2
, It2
);
5579 end Check_Right_Argument
;
5581 -- Start of processing for Find_Arithmetic_Types
5584 if not Is_Overloaded
(L
) then
5585 Check_Right_Argument
(Etype
(L
));
5588 Get_First_Interp
(L
, Index1
, It1
);
5589 while Present
(It1
.Typ
) loop
5590 Check_Right_Argument
(It1
.Typ
);
5591 Get_Next_Interp
(Index1
, It1
);
5595 end Find_Arithmetic_Types
;
5597 ------------------------
5598 -- Find_Boolean_Types --
5599 ------------------------
5601 procedure Find_Boolean_Types
5606 Index
: Interp_Index
;
5609 procedure Check_Numeric_Argument
(T
: Entity_Id
);
5610 -- Special case for logical operations one of whose operands is an
5611 -- integer literal. If both are literal the result is any modular type.
5613 ----------------------------
5614 -- Check_Numeric_Argument --
5615 ----------------------------
5617 procedure Check_Numeric_Argument
(T
: Entity_Id
) is
5619 if T
= Universal_Integer
then
5620 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
5622 elsif Is_Modular_Integer_Type
(T
) then
5623 Add_One_Interp
(N
, Op_Id
, T
);
5625 end Check_Numeric_Argument
;
5627 -- Start of processing for Find_Boolean_Types
5630 if not Is_Overloaded
(L
) then
5631 if Etype
(L
) = Universal_Integer
5632 or else Etype
(L
) = Any_Modular
5634 if not Is_Overloaded
(R
) then
5635 Check_Numeric_Argument
(Etype
(R
));
5638 Get_First_Interp
(R
, Index
, It
);
5639 while Present
(It
.Typ
) loop
5640 Check_Numeric_Argument
(It
.Typ
);
5641 Get_Next_Interp
(Index
, It
);
5645 -- If operands are aggregates, we must assume that they may be
5646 -- boolean arrays, and leave disambiguation for the second pass.
5647 -- If only one is an aggregate, verify that the other one has an
5648 -- interpretation as a boolean array
5650 elsif Nkind
(L
) = N_Aggregate
then
5651 if Nkind
(R
) = N_Aggregate
then
5652 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
5654 elsif not Is_Overloaded
(R
) then
5655 if Valid_Boolean_Arg
(Etype
(R
)) then
5656 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
5660 Get_First_Interp
(R
, Index
, It
);
5661 while Present
(It
.Typ
) loop
5662 if Valid_Boolean_Arg
(It
.Typ
) then
5663 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
5666 Get_Next_Interp
(Index
, It
);
5670 elsif Valid_Boolean_Arg
(Etype
(L
))
5671 and then Has_Compatible_Type
(R
, Etype
(L
))
5673 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
5677 Get_First_Interp
(L
, Index
, It
);
5678 while Present
(It
.Typ
) loop
5679 if Valid_Boolean_Arg
(It
.Typ
)
5680 and then Has_Compatible_Type
(R
, It
.Typ
)
5682 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
5685 Get_Next_Interp
(Index
, It
);
5688 end Find_Boolean_Types
;
5690 ---------------------------
5691 -- Find_Comparison_Types --
5692 ---------------------------
5694 procedure Find_Comparison_Types
5699 Index
: Interp_Index
;
5701 Found
: Boolean := False;
5704 Scop
: Entity_Id
:= Empty
;
5706 procedure Try_One_Interp
(T1
: Entity_Id
);
5707 -- Routine to try one proposed interpretation. Note that the context
5708 -- of the operator plays no role in resolving the arguments, so that
5709 -- if there is more than one interpretation of the operands that is
5710 -- compatible with comparison, the operation is ambiguous.
5712 --------------------
5713 -- Try_One_Interp --
5714 --------------------
5716 procedure Try_One_Interp
(T1
: Entity_Id
) is
5719 -- If the operator is an expanded name, then the type of the operand
5720 -- must be defined in the corresponding scope. If the type is
5721 -- universal, the context will impose the correct type.
5724 and then not Defined_In_Scope
(T1
, Scop
)
5725 and then T1
/= Universal_Integer
5726 and then T1
/= Universal_Real
5727 and then T1
/= Any_String
5728 and then T1
/= Any_Composite
5733 if Valid_Comparison_Arg
(T1
) and then Has_Compatible_Type
(R
, T1
) then
5734 if Found
and then Base_Type
(T1
) /= Base_Type
(T_F
) then
5735 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
5737 if It
= No_Interp
then
5738 Ambiguous_Operands
(N
);
5739 Set_Etype
(L
, Any_Type
);
5753 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
5758 -- Start of processing for Find_Comparison_Types
5761 -- If left operand is aggregate, the right operand has to
5762 -- provide a usable type for it.
5764 if Nkind
(L
) = N_Aggregate
and then Nkind
(R
) /= N_Aggregate
then
5765 Find_Comparison_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
5769 if Nkind
(N
) = N_Function_Call
5770 and then Nkind
(Name
(N
)) = N_Expanded_Name
5772 Scop
:= Entity
(Prefix
(Name
(N
)));
5774 -- The prefix may be a package renaming, and the subsequent test
5775 -- requires the original package.
5777 if Ekind
(Scop
) = E_Package
5778 and then Present
(Renamed_Entity
(Scop
))
5780 Scop
:= Renamed_Entity
(Scop
);
5781 Set_Entity
(Prefix
(Name
(N
)), Scop
);
5785 if not Is_Overloaded
(L
) then
5786 Try_One_Interp
(Etype
(L
));
5789 Get_First_Interp
(L
, Index
, It
);
5790 while Present
(It
.Typ
) loop
5791 Try_One_Interp
(It
.Typ
);
5792 Get_Next_Interp
(Index
, It
);
5795 end Find_Comparison_Types
;
5797 ----------------------------------------
5798 -- Find_Non_Universal_Interpretations --
5799 ----------------------------------------
5801 procedure Find_Non_Universal_Interpretations
5807 Index
: Interp_Index
;
5811 if T1
= Universal_Integer
or else T1
= Universal_Real
5813 -- If the left operand of an equality operator is null, the visibility
5814 -- of the operator must be determined from the interpretation of the
5815 -- right operand. This processing must be done for Any_Access, which
5816 -- is the internal representation of the type of the literal null.
5818 or else T1
= Any_Access
5820 if not Is_Overloaded
(R
) then
5821 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(Etype
(R
)));
5823 Get_First_Interp
(R
, Index
, It
);
5824 while Present
(It
.Typ
) loop
5825 if Covers
(It
.Typ
, T1
) then
5827 (N
, Op_Id
, Standard_Boolean
, Base_Type
(It
.Typ
));
5830 Get_Next_Interp
(Index
, It
);
5834 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(T1
));
5836 end Find_Non_Universal_Interpretations
;
5838 ------------------------------
5839 -- Find_Concatenation_Types --
5840 ------------------------------
5842 procedure Find_Concatenation_Types
5847 Op_Type
: constant Entity_Id
:= Etype
(Op_Id
);
5850 if Is_Array_Type
(Op_Type
)
5851 and then not Is_Limited_Type
(Op_Type
)
5853 and then (Has_Compatible_Type
(L
, Op_Type
)
5855 Has_Compatible_Type
(L
, Component_Type
(Op_Type
)))
5857 and then (Has_Compatible_Type
(R
, Op_Type
)
5859 Has_Compatible_Type
(R
, Component_Type
(Op_Type
)))
5861 Add_One_Interp
(N
, Op_Id
, Op_Type
);
5863 end Find_Concatenation_Types
;
5865 -------------------------
5866 -- Find_Equality_Types --
5867 -------------------------
5869 procedure Find_Equality_Types
5874 Index
: Interp_Index
;
5876 Found
: Boolean := False;
5879 Scop
: Entity_Id
:= Empty
;
5881 procedure Try_One_Interp
(T1
: Entity_Id
);
5882 -- The context of the equality operator plays no role in resolving the
5883 -- arguments, so that if there is more than one interpretation of the
5884 -- operands that is compatible with equality, the construct is ambiguous
5885 -- and an error can be emitted now, after trying to disambiguate, i.e.
5886 -- applying preference rules.
5888 --------------------
5889 -- Try_One_Interp --
5890 --------------------
5892 procedure Try_One_Interp
(T1
: Entity_Id
) is
5893 Bas
: constant Entity_Id
:= Base_Type
(T1
);
5896 -- If the operator is an expanded name, then the type of the operand
5897 -- must be defined in the corresponding scope. If the type is
5898 -- universal, the context will impose the correct type. An anonymous
5899 -- type for a 'Access reference is also universal in this sense, as
5900 -- the actual type is obtained from context.
5902 -- In Ada 2005, the equality operator for anonymous access types
5903 -- is declared in Standard, and preference rules apply to it.
5905 if Present
(Scop
) then
5906 if Defined_In_Scope
(T1
, Scop
)
5907 or else T1
= Universal_Integer
5908 or else T1
= Universal_Real
5909 or else T1
= Any_Access
5910 or else T1
= Any_String
5911 or else T1
= Any_Composite
5912 or else (Ekind
(T1
) = E_Access_Subprogram_Type
5913 and then not Comes_From_Source
(T1
))
5917 elsif Ekind
(T1
) = E_Anonymous_Access_Type
5918 and then Scop
= Standard_Standard
5923 -- The scope does not contain an operator for the type
5928 -- If we have infix notation, the operator must be usable. Within
5929 -- an instance, if the type is already established we know it is
5930 -- correct. If an operand is universal it is compatible with any
5933 elsif In_Open_Scopes
(Scope
(Bas
))
5934 or else Is_Potentially_Use_Visible
(Bas
)
5935 or else In_Use
(Bas
)
5936 or else (In_Use
(Scope
(Bas
)) and then not Is_Hidden
(Bas
))
5938 -- In an instance, the type may have been immediately visible.
5939 -- Either the types are compatible, or one operand is universal
5940 -- (numeric or null).
5942 or else (In_Instance
5944 (First_Subtype
(T1
) = First_Subtype
(Etype
(R
))
5945 or else Nkind
(R
) = N_Null
5947 (Is_Numeric_Type
(T1
)
5948 and then Is_Universal_Numeric_Type
(Etype
(R
)))))
5950 -- In Ada 2005, the equality on anonymous access types is declared
5951 -- in Standard, and is always visible.
5953 or else Ekind
(T1
) = E_Anonymous_Access_Type
5958 -- Save candidate type for subsequent error message, if any
5960 if not Is_Limited_Type
(T1
) then
5961 Candidate_Type
:= T1
;
5967 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
5968 -- Do not allow anonymous access types in equality operators.
5970 if Ada_Version
< Ada_2005
5971 and then Ekind
(T1
) = E_Anonymous_Access_Type
5976 -- If the right operand has a type compatible with T1, check for an
5977 -- acceptable interpretation, unless T1 is limited (no predefined
5978 -- equality available), or this is use of a "/=" for a tagged type.
5979 -- In the latter case, possible interpretations of equality need
5980 -- to be considered, we don't want the default inequality declared
5981 -- in Standard to be chosen, and the "/=" will be rewritten as a
5982 -- negation of "=" (see the end of Analyze_Equality_Op). This ensures
5983 -- that that rewriting happens during analysis rather than being
5984 -- delayed until expansion (this is needed for ASIS, which only sees
5985 -- the unexpanded tree). Note that if the node is N_Op_Ne, but Op_Id
5986 -- is Name_Op_Eq then we still proceed with the interpretation,
5987 -- because that indicates the potential rewriting case where the
5988 -- interpretation to consider is actually "=" and the node may be
5989 -- about to be rewritten by Analyze_Equality_Op.
5991 if T1
/= Standard_Void_Type
5992 and then Has_Compatible_Type
(R
, T1
)
5995 ((not Is_Limited_Type
(T1
)
5996 and then not Is_Limited_Composite
(T1
))
6000 and then not Is_Limited_Type
(Component_Type
(T1
))
6001 and then Available_Full_View_Of_Component
(T1
)))
6004 (Nkind
(N
) /= N_Op_Ne
6005 or else not Is_Tagged_Type
(T1
)
6006 or else Chars
(Op_Id
) = Name_Op_Eq
)
6009 and then Base_Type
(T1
) /= Base_Type
(T_F
)
6011 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
6013 if It
= No_Interp
then
6014 Ambiguous_Operands
(N
);
6015 Set_Etype
(L
, Any_Type
);
6028 if not Analyzed
(L
) then
6032 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
6034 -- Case of operator was not visible, Etype still set to Any_Type
6036 if Etype
(N
) = Any_Type
then
6040 elsif Scop
= Standard_Standard
6041 and then Ekind
(T1
) = E_Anonymous_Access_Type
6047 -- Start of processing for Find_Equality_Types
6050 -- If left operand is aggregate, the right operand has to
6051 -- provide a usable type for it.
6053 if Nkind
(L
) = N_Aggregate
6054 and then Nkind
(R
) /= N_Aggregate
6056 Find_Equality_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
6060 if Nkind
(N
) = N_Function_Call
6061 and then Nkind
(Name
(N
)) = N_Expanded_Name
6063 Scop
:= Entity
(Prefix
(Name
(N
)));
6065 -- The prefix may be a package renaming, and the subsequent test
6066 -- requires the original package.
6068 if Ekind
(Scop
) = E_Package
6069 and then Present
(Renamed_Entity
(Scop
))
6071 Scop
:= Renamed_Entity
(Scop
);
6072 Set_Entity
(Prefix
(Name
(N
)), Scop
);
6076 if not Is_Overloaded
(L
) then
6077 Try_One_Interp
(Etype
(L
));
6080 Get_First_Interp
(L
, Index
, It
);
6081 while Present
(It
.Typ
) loop
6082 Try_One_Interp
(It
.Typ
);
6083 Get_Next_Interp
(Index
, It
);
6086 end Find_Equality_Types
;
6088 -------------------------
6089 -- Find_Negation_Types --
6090 -------------------------
6092 procedure Find_Negation_Types
6097 Index
: Interp_Index
;
6101 if not Is_Overloaded
(R
) then
6102 if Etype
(R
) = Universal_Integer
then
6103 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
6104 elsif Valid_Boolean_Arg
(Etype
(R
)) then
6105 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
6109 Get_First_Interp
(R
, Index
, It
);
6110 while Present
(It
.Typ
) loop
6111 if Valid_Boolean_Arg
(It
.Typ
) then
6112 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
6115 Get_Next_Interp
(Index
, It
);
6118 end Find_Negation_Types
;
6120 ------------------------------
6121 -- Find_Primitive_Operation --
6122 ------------------------------
6124 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean is
6125 Obj
: constant Node_Id
:= Prefix
(N
);
6126 Op
: constant Node_Id
:= Selector_Name
(N
);
6133 Set_Etype
(Op
, Any_Type
);
6135 if Is_Access_Type
(Etype
(Obj
)) then
6136 Typ
:= Designated_Type
(Etype
(Obj
));
6141 if Is_Class_Wide_Type
(Typ
) then
6142 Typ
:= Root_Type
(Typ
);
6145 Prims
:= Primitive_Operations
(Typ
);
6147 Prim
:= First_Elmt
(Prims
);
6148 while Present
(Prim
) loop
6149 if Chars
(Node
(Prim
)) = Chars
(Op
) then
6150 Add_One_Interp
(Op
, Node
(Prim
), Etype
(Node
(Prim
)));
6151 Set_Etype
(N
, Etype
(Node
(Prim
)));
6157 -- Now look for class-wide operations of the type or any of its
6158 -- ancestors by iterating over the homonyms of the selector.
6161 Cls_Type
: constant Entity_Id
:= Class_Wide_Type
(Typ
);
6165 Hom
:= Current_Entity
(Op
);
6166 while Present
(Hom
) loop
6167 if (Ekind
(Hom
) = E_Procedure
6169 Ekind
(Hom
) = E_Function
)
6170 and then Scope
(Hom
) = Scope
(Typ
)
6171 and then Present
(First_Formal
(Hom
))
6173 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
6175 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
6177 Ekind
(Etype
(First_Formal
(Hom
))) =
6178 E_Anonymous_Access_Type
6181 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
6184 Add_One_Interp
(Op
, Hom
, Etype
(Hom
));
6185 Set_Etype
(N
, Etype
(Hom
));
6188 Hom
:= Homonym
(Hom
);
6192 return Etype
(Op
) /= Any_Type
;
6193 end Find_Primitive_Operation
;
6195 ----------------------
6196 -- Find_Unary_Types --
6197 ----------------------
6199 procedure Find_Unary_Types
6204 Index
: Interp_Index
;
6208 if not Is_Overloaded
(R
) then
6209 if Is_Numeric_Type
(Etype
(R
)) then
6211 -- In an instance a generic actual may be a numeric type even if
6212 -- the formal in the generic unit was not. In that case, the
6213 -- predefined operator was not a possible interpretation in the
6214 -- generic, and cannot be one in the instance, unless the operator
6215 -- is an actual of an instance.
6219 not Is_Numeric_Type
(Corresponding_Generic_Type
(Etype
(R
)))
6223 Add_One_Interp
(N
, Op_Id
, Base_Type
(Etype
(R
)));
6228 Get_First_Interp
(R
, Index
, It
);
6229 while Present
(It
.Typ
) loop
6230 if Is_Numeric_Type
(It
.Typ
) then
6234 (Corresponding_Generic_Type
(Etype
(It
.Typ
)))
6239 Add_One_Interp
(N
, Op_Id
, Base_Type
(It
.Typ
));
6243 Get_Next_Interp
(Index
, It
);
6246 end Find_Unary_Types
;
6252 function Junk_Operand
(N
: Node_Id
) return Boolean is
6256 if Error_Posted
(N
) then
6260 -- Get entity to be tested
6262 if Is_Entity_Name
(N
)
6263 and then Present
(Entity
(N
))
6267 -- An odd case, a procedure name gets converted to a very peculiar
6268 -- function call, and here is where we detect this happening.
6270 elsif Nkind
(N
) = N_Function_Call
6271 and then Is_Entity_Name
(Name
(N
))
6272 and then Present
(Entity
(Name
(N
)))
6276 -- Another odd case, there are at least some cases of selected
6277 -- components where the selected component is not marked as having
6278 -- an entity, even though the selector does have an entity
6280 elsif Nkind
(N
) = N_Selected_Component
6281 and then Present
(Entity
(Selector_Name
(N
)))
6283 Enode
:= Selector_Name
(N
);
6289 -- Now test the entity we got to see if it is a bad case
6291 case Ekind
(Entity
(Enode
)) is
6295 ("package name cannot be used as operand", Enode
);
6297 when Generic_Unit_Kind
=>
6299 ("generic unit name cannot be used as operand", Enode
);
6303 ("subtype name cannot be used as operand", Enode
);
6307 ("entry name cannot be used as operand", Enode
);
6311 ("procedure name cannot be used as operand", Enode
);
6315 ("exception name cannot be used as operand", Enode
);
6317 when E_Block | E_Label | E_Loop
=>
6319 ("label name cannot be used as operand", Enode
);
6329 --------------------
6330 -- Operator_Check --
6331 --------------------
6333 procedure Operator_Check
(N
: Node_Id
) is
6335 Remove_Abstract_Operations
(N
);
6337 -- Test for case of no interpretation found for operator
6339 if Etype
(N
) = Any_Type
then
6343 Op_Id
: Entity_Id
:= Empty
;
6346 R
:= Right_Opnd
(N
);
6348 if Nkind
(N
) in N_Binary_Op
then
6354 -- If either operand has no type, then don't complain further,
6355 -- since this simply means that we have a propagated error.
6358 or else Etype
(R
) = Any_Type
6359 or else (Nkind
(N
) in N_Binary_Op
and then Etype
(L
) = Any_Type
)
6361 -- For the rather unusual case where one of the operands is
6362 -- a Raise_Expression, whose initial type is Any_Type, use
6363 -- the type of the other operand.
6365 if Nkind
(L
) = N_Raise_Expression
then
6366 Set_Etype
(L
, Etype
(R
));
6367 Set_Etype
(N
, Etype
(R
));
6369 elsif Nkind
(R
) = N_Raise_Expression
then
6370 Set_Etype
(R
, Etype
(L
));
6371 Set_Etype
(N
, Etype
(L
));
6376 -- We explicitly check for the case of concatenation of component
6377 -- with component to avoid reporting spurious matching array types
6378 -- that might happen to be lurking in distant packages (such as
6379 -- run-time packages). This also prevents inconsistencies in the
6380 -- messages for certain ACVC B tests, which can vary depending on
6381 -- types declared in run-time interfaces. Another improvement when
6382 -- aggregates are present is to look for a well-typed operand.
6384 elsif Present
(Candidate_Type
)
6385 and then (Nkind
(N
) /= N_Op_Concat
6386 or else Is_Array_Type
(Etype
(L
))
6387 or else Is_Array_Type
(Etype
(R
)))
6389 if Nkind
(N
) = N_Op_Concat
then
6390 if Etype
(L
) /= Any_Composite
6391 and then Is_Array_Type
(Etype
(L
))
6393 Candidate_Type
:= Etype
(L
);
6395 elsif Etype
(R
) /= Any_Composite
6396 and then Is_Array_Type
(Etype
(R
))
6398 Candidate_Type
:= Etype
(R
);
6402 Error_Msg_NE
-- CODEFIX
6403 ("operator for} is not directly visible!",
6404 N
, First_Subtype
(Candidate_Type
));
6407 U
: constant Node_Id
:=
6408 Cunit
(Get_Source_Unit
(Candidate_Type
));
6410 if Unit_Is_Visible
(U
) then
6411 Error_Msg_N
-- CODEFIX
6412 ("use clause would make operation legal!", N
);
6414 Error_Msg_NE
-- CODEFIX
6415 ("add with_clause and use_clause for&!",
6416 N
, Defining_Entity
(Unit
(U
)));
6421 -- If either operand is a junk operand (e.g. package name), then
6422 -- post appropriate error messages, but do not complain further.
6424 -- Note that the use of OR in this test instead of OR ELSE is
6425 -- quite deliberate, we may as well check both operands in the
6426 -- binary operator case.
6428 elsif Junk_Operand
(R
)
6429 or -- really mean OR here and not OR ELSE, see above
6430 (Nkind
(N
) in N_Binary_Op
and then Junk_Operand
(L
))
6434 -- If we have a logical operator, one of whose operands is
6435 -- Boolean, then we know that the other operand cannot resolve to
6436 -- Boolean (since we got no interpretations), but in that case we
6437 -- pretty much know that the other operand should be Boolean, so
6438 -- resolve it that way (generating an error)
6440 elsif Nkind_In
(N
, N_Op_And
, N_Op_Or
, N_Op_Xor
) then
6441 if Etype
(L
) = Standard_Boolean
then
6442 Resolve
(R
, Standard_Boolean
);
6444 elsif Etype
(R
) = Standard_Boolean
then
6445 Resolve
(L
, Standard_Boolean
);
6449 -- For an arithmetic operator or comparison operator, if one
6450 -- of the operands is numeric, then we know the other operand
6451 -- is not the same numeric type. If it is a non-numeric type,
6452 -- then probably it is intended to match the other operand.
6454 elsif Nkind_In
(N
, N_Op_Add
,
6460 Nkind_In
(N
, N_Op_Lt
,
6466 -- If Allow_Integer_Address is active, check whether the
6467 -- operation becomes legal after converting an operand.
6469 if Is_Numeric_Type
(Etype
(L
))
6470 and then not Is_Numeric_Type
(Etype
(R
))
6472 if Address_Integer_Convert_OK
(Etype
(R
), Etype
(L
)) then
6474 Unchecked_Convert_To
(Etype
(L
), Relocate_Node
(R
)));
6476 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6477 Analyze_Comparison_Op
(N
);
6479 Analyze_Arithmetic_Op
(N
);
6482 Resolve
(R
, Etype
(L
));
6487 elsif Is_Numeric_Type
(Etype
(R
))
6488 and then not Is_Numeric_Type
(Etype
(L
))
6490 if Address_Integer_Convert_OK
(Etype
(L
), Etype
(R
)) then
6492 Unchecked_Convert_To
(Etype
(R
), Relocate_Node
(L
)));
6494 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6495 Analyze_Comparison_Op
(N
);
6497 Analyze_Arithmetic_Op
(N
);
6503 Resolve
(L
, Etype
(R
));
6508 elsif Allow_Integer_Address
6509 and then Is_Descendent_Of_Address
(Etype
(L
))
6510 and then Is_Descendent_Of_Address
(Etype
(R
))
6511 and then not Error_Posted
(N
)
6514 Addr_Type
: constant Entity_Id
:= Etype
(L
);
6518 Unchecked_Convert_To
(
6519 Standard_Integer
, Relocate_Node
(L
)));
6521 Unchecked_Convert_To
(
6522 Standard_Integer
, Relocate_Node
(R
)));
6524 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6525 Analyze_Comparison_Op
(N
);
6527 Analyze_Arithmetic_Op
(N
);
6530 -- If this is an operand in an enclosing arithmetic
6531 -- operation, Convert the result as an address so that
6532 -- arithmetic folding of address can continue.
6534 if Nkind
(Parent
(N
)) in N_Op
then
6536 Unchecked_Convert_To
(Addr_Type
, Relocate_Node
(N
)));
6543 -- Comparisons on A'Access are common enough to deserve a
6546 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
)
6547 and then Ekind
(Etype
(L
)) = E_Access_Attribute_Type
6548 and then Ekind
(Etype
(R
)) = E_Access_Attribute_Type
6551 ("two access attributes cannot be compared directly", N
);
6553 ("\use qualified expression for one of the operands",
6557 -- Another one for C programmers
6559 elsif Nkind
(N
) = N_Op_Concat
6560 and then Valid_Boolean_Arg
(Etype
(L
))
6561 and then Valid_Boolean_Arg
(Etype
(R
))
6563 Error_Msg_N
("invalid operands for concatenation", N
);
6564 Error_Msg_N
-- CODEFIX
6565 ("\maybe AND was meant", N
);
6568 -- A special case for comparison of access parameter with null
6570 elsif Nkind
(N
) = N_Op_Eq
6571 and then Is_Entity_Name
(L
)
6572 and then Nkind
(Parent
(Entity
(L
))) = N_Parameter_Specification
6573 and then Nkind
(Parameter_Type
(Parent
(Entity
(L
)))) =
6575 and then Nkind
(R
) = N_Null
6577 Error_Msg_N
("access parameter is not allowed to be null", L
);
6578 Error_Msg_N
("\(call would raise Constraint_Error)", L
);
6581 -- Another special case for exponentiation, where the right
6582 -- operand must be Natural, independently of the base.
6584 elsif Nkind
(N
) = N_Op_Expon
6585 and then Is_Numeric_Type
(Etype
(L
))
6586 and then not Is_Overloaded
(R
)
6588 First_Subtype
(Base_Type
(Etype
(R
))) /= Standard_Integer
6589 and then Base_Type
(Etype
(R
)) /= Universal_Integer
6591 if Ada_Version
>= Ada_2012
6592 and then Has_Dimension_System
(Etype
(L
))
6595 ("exponent for dimensioned type must be a rational" &
6596 ", found}", R
, Etype
(R
));
6599 ("exponent must be of type Natural, found}", R
, Etype
(R
));
6604 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
) then
6605 if Address_Integer_Convert_OK
(Etype
(R
), Etype
(L
)) then
6607 Unchecked_Convert_To
(Etype
(L
), Relocate_Node
(R
)));
6608 Analyze_Equality_Op
(N
);
6613 -- If we fall through then just give general message. Note that in
6614 -- the following messages, if the operand is overloaded we choose
6615 -- an arbitrary type to complain about, but that is probably more
6616 -- useful than not giving a type at all.
6618 if Nkind
(N
) in N_Unary_Op
then
6619 Error_Msg_Node_2
:= Etype
(R
);
6620 Error_Msg_N
("operator& not defined for}", N
);
6624 if Nkind
(N
) in N_Binary_Op
then
6625 if not Is_Overloaded
(L
)
6626 and then not Is_Overloaded
(R
)
6627 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
6629 Error_Msg_Node_2
:= First_Subtype
(Etype
(R
));
6630 Error_Msg_N
("there is no applicable operator& for}", N
);
6633 -- Another attempt to find a fix: one of the candidate
6634 -- interpretations may not be use-visible. This has
6635 -- already been checked for predefined operators, so
6636 -- we examine only user-defined functions.
6638 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
6640 while Present
(Op_Id
) loop
6641 if Ekind
(Op_Id
) /= E_Operator
6642 and then Is_Overloadable
(Op_Id
)
6644 if not Is_Immediately_Visible
(Op_Id
)
6645 and then not In_Use
(Scope
(Op_Id
))
6646 and then not Is_Abstract_Subprogram
(Op_Id
)
6647 and then not Is_Hidden
(Op_Id
)
6648 and then Ekind
(Scope
(Op_Id
)) = E_Package
6651 (L
, Etype
(First_Formal
(Op_Id
)))
6653 (Next_Formal
(First_Formal
(Op_Id
)))
6657 Etype
(Next_Formal
(First_Formal
(Op_Id
))))
6660 ("No legal interpretation for operator&", N
);
6662 ("\use clause on& would make operation legal",
6668 Op_Id
:= Homonym
(Op_Id
);
6672 Error_Msg_N
("invalid operand types for operator&", N
);
6674 if Nkind
(N
) /= N_Op_Concat
then
6675 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
6676 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
6678 -- For concatenation operators it is more difficult to
6679 -- determine which is the wrong operand. It is worth
6680 -- flagging explicitly an access type, for those who
6681 -- might think that a dereference happens here.
6683 elsif Is_Access_Type
(Etype
(L
)) then
6684 Error_Msg_N
("\left operand is access type", N
);
6686 elsif Is_Access_Type
(Etype
(R
)) then
6687 Error_Msg_N
("\right operand is access type", N
);
6697 -----------------------------------------
6698 -- Process_Implicit_Dereference_Prefix --
6699 -----------------------------------------
6701 function Process_Implicit_Dereference_Prefix
6703 P
: Entity_Id
) return Entity_Id
6706 Typ
: constant Entity_Id
:= Designated_Type
(Etype
(P
));
6710 and then (Operating_Mode
= Check_Semantics
or else not Expander_Active
)
6712 -- We create a dummy reference to E to ensure that the reference is
6713 -- not considered as part of an assignment (an implicit dereference
6714 -- can never assign to its prefix). The Comes_From_Source attribute
6715 -- needs to be propagated for accurate warnings.
6717 Ref
:= New_Occurrence_Of
(E
, Sloc
(P
));
6718 Set_Comes_From_Source
(Ref
, Comes_From_Source
(P
));
6719 Generate_Reference
(E
, Ref
);
6722 -- An implicit dereference is a legal occurrence of an incomplete type
6723 -- imported through a limited_with clause, if the full view is visible.
6725 if From_Limited_With
(Typ
)
6726 and then not From_Limited_With
(Scope
(Typ
))
6728 (Is_Immediately_Visible
(Scope
(Typ
))
6730 (Is_Child_Unit
(Scope
(Typ
))
6731 and then Is_Visible_Lib_Unit
(Scope
(Typ
))))
6733 return Available_View
(Typ
);
6737 end Process_Implicit_Dereference_Prefix
;
6739 --------------------------------
6740 -- Remove_Abstract_Operations --
6741 --------------------------------
6743 procedure Remove_Abstract_Operations
(N
: Node_Id
) is
6744 Abstract_Op
: Entity_Id
:= Empty
;
6745 Address_Descendent
: Boolean := False;
6749 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
6750 -- activate this if either extensions are enabled, or if the abstract
6751 -- operation in question comes from a predefined file. This latter test
6752 -- allows us to use abstract to make operations invisible to users. In
6753 -- particular, if type Address is non-private and abstract subprograms
6754 -- are used to hide its operators, they will be truly hidden.
6756 type Operand_Position
is (First_Op
, Second_Op
);
6757 Univ_Type
: constant Entity_Id
:= Universal_Interpretation
(N
);
6759 procedure Remove_Address_Interpretations
(Op
: Operand_Position
);
6760 -- Ambiguities may arise when the operands are literal and the address
6761 -- operations in s-auxdec are visible. In that case, remove the
6762 -- interpretation of a literal as Address, to retain the semantics
6763 -- of Address as a private type.
6765 ------------------------------------
6766 -- Remove_Address_Interpretations --
6767 ------------------------------------
6769 procedure Remove_Address_Interpretations
(Op
: Operand_Position
) is
6773 if Is_Overloaded
(N
) then
6774 Get_First_Interp
(N
, I
, It
);
6775 while Present
(It
.Nam
) loop
6776 Formal
:= First_Entity
(It
.Nam
);
6778 if Op
= Second_Op
then
6779 Formal
:= Next_Entity
(Formal
);
6782 if Is_Descendent_Of_Address
(Etype
(Formal
)) then
6783 Address_Descendent
:= True;
6787 Get_Next_Interp
(I
, It
);
6790 end Remove_Address_Interpretations
;
6792 -- Start of processing for Remove_Abstract_Operations
6795 if Is_Overloaded
(N
) then
6796 if Debug_Flag_V
then
6797 Write_Str
("Remove_Abstract_Operations: ");
6798 Write_Overloads
(N
);
6801 Get_First_Interp
(N
, I
, It
);
6803 while Present
(It
.Nam
) loop
6804 if Is_Overloadable
(It
.Nam
)
6805 and then Is_Abstract_Subprogram
(It
.Nam
)
6806 and then not Is_Dispatching_Operation
(It
.Nam
)
6808 Abstract_Op
:= It
.Nam
;
6810 if Is_Descendent_Of_Address
(It
.Typ
) then
6811 Address_Descendent
:= True;
6815 -- In Ada 2005, this operation does not participate in overload
6816 -- resolution. If the operation is defined in a predefined
6817 -- unit, it is one of the operations declared abstract in some
6818 -- variants of System, and it must be removed as well.
6820 elsif Ada_Version
>= Ada_2005
6821 or else Is_Predefined_File_Name
6822 (Unit_File_Name
(Get_Source_Unit
(It
.Nam
)))
6829 Get_Next_Interp
(I
, It
);
6832 if No
(Abstract_Op
) then
6834 -- If some interpretation yields an integer type, it is still
6835 -- possible that there are address interpretations. Remove them
6836 -- if one operand is a literal, to avoid spurious ambiguities
6837 -- on systems where Address is a visible integer type.
6839 if Is_Overloaded
(N
)
6840 and then Nkind
(N
) in N_Op
6841 and then Is_Integer_Type
(Etype
(N
))
6843 if Nkind
(N
) in N_Binary_Op
then
6844 if Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
6845 Remove_Address_Interpretations
(Second_Op
);
6847 elsif Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
6848 Remove_Address_Interpretations
(First_Op
);
6853 elsif Nkind
(N
) in N_Op
then
6855 -- Remove interpretations that treat literals as addresses. This
6856 -- is never appropriate, even when Address is defined as a visible
6857 -- Integer type. The reason is that we would really prefer Address
6858 -- to behave as a private type, even in this case. If Address is a
6859 -- visible integer type, we get lots of overload ambiguities.
6861 if Nkind
(N
) in N_Binary_Op
then
6863 U1
: constant Boolean :=
6864 Present
(Universal_Interpretation
(Right_Opnd
(N
)));
6865 U2
: constant Boolean :=
6866 Present
(Universal_Interpretation
(Left_Opnd
(N
)));
6870 Remove_Address_Interpretations
(Second_Op
);
6874 Remove_Address_Interpretations
(First_Op
);
6877 if not (U1
and U2
) then
6879 -- Remove corresponding predefined operator, which is
6880 -- always added to the overload set.
6882 Get_First_Interp
(N
, I
, It
);
6883 while Present
(It
.Nam
) loop
6884 if Scope
(It
.Nam
) = Standard_Standard
6885 and then Base_Type
(It
.Typ
) =
6886 Base_Type
(Etype
(Abstract_Op
))
6891 Get_Next_Interp
(I
, It
);
6894 elsif Is_Overloaded
(N
)
6895 and then Present
(Univ_Type
)
6897 -- If both operands have a universal interpretation,
6898 -- it is still necessary to remove interpretations that
6899 -- yield Address. Any remaining ambiguities will be
6900 -- removed in Disambiguate.
6902 Get_First_Interp
(N
, I
, It
);
6903 while Present
(It
.Nam
) loop
6904 if Is_Descendent_Of_Address
(It
.Typ
) then
6907 elsif not Is_Type
(It
.Nam
) then
6908 Set_Entity
(N
, It
.Nam
);
6911 Get_Next_Interp
(I
, It
);
6917 elsif Nkind
(N
) = N_Function_Call
6919 (Nkind
(Name
(N
)) = N_Operator_Symbol
6921 (Nkind
(Name
(N
)) = N_Expanded_Name
6923 Nkind
(Selector_Name
(Name
(N
))) = N_Operator_Symbol
))
6927 Arg1
: constant Node_Id
:= First
(Parameter_Associations
(N
));
6928 U1
: constant Boolean :=
6929 Present
(Universal_Interpretation
(Arg1
));
6930 U2
: constant Boolean :=
6931 Present
(Next
(Arg1
)) and then
6932 Present
(Universal_Interpretation
(Next
(Arg1
)));
6936 Remove_Address_Interpretations
(First_Op
);
6940 Remove_Address_Interpretations
(Second_Op
);
6943 if not (U1
and U2
) then
6944 Get_First_Interp
(N
, I
, It
);
6945 while Present
(It
.Nam
) loop
6946 if Scope
(It
.Nam
) = Standard_Standard
6947 and then It
.Typ
= Base_Type
(Etype
(Abstract_Op
))
6952 Get_Next_Interp
(I
, It
);
6958 -- If the removal has left no valid interpretations, emit an error
6959 -- message now and label node as illegal.
6961 if Present
(Abstract_Op
) then
6962 Get_First_Interp
(N
, I
, It
);
6966 -- Removal of abstract operation left no viable candidate
6968 Set_Etype
(N
, Any_Type
);
6969 Error_Msg_Sloc
:= Sloc
(Abstract_Op
);
6971 ("cannot call abstract operation& declared#", N
, Abstract_Op
);
6973 -- In Ada 2005, an abstract operation may disable predefined
6974 -- operators. Since the context is not yet known, we mark the
6975 -- predefined operators as potentially hidden. Do not include
6976 -- predefined operators when addresses are involved since this
6977 -- case is handled separately.
6979 elsif Ada_Version
>= Ada_2005
and then not Address_Descendent
then
6980 while Present
(It
.Nam
) loop
6981 if Is_Numeric_Type
(It
.Typ
)
6982 and then Scope
(It
.Typ
) = Standard_Standard
6984 Set_Abstract_Op
(I
, Abstract_Op
);
6987 Get_Next_Interp
(I
, It
);
6992 if Debug_Flag_V
then
6993 Write_Str
("Remove_Abstract_Operations done: ");
6994 Write_Overloads
(N
);
6997 end Remove_Abstract_Operations
;
6999 ----------------------------
7000 -- Try_Container_Indexing --
7001 ----------------------------
7003 function Try_Container_Indexing
7006 Exprs
: List_Id
) return Boolean
7008 Loc
: constant Source_Ptr
:= Sloc
(N
);
7013 Func_Name
: Node_Id
;
7017 C_Type
:= Etype
(Prefix
);
7019 -- If indexing a class-wide container, obtain indexing primitive
7020 -- from specific type.
7022 if Is_Class_Wide_Type
(C_Type
) then
7023 C_Type
:= Etype
(Base_Type
(C_Type
));
7026 -- Check whether type has a specified indexing aspect
7030 if Is_Variable
(Prefix
) then
7032 Find_Value_Of_Aspect
(Etype
(Prefix
), Aspect_Variable_Indexing
);
7035 if No
(Func_Name
) then
7037 Find_Value_Of_Aspect
(Etype
(Prefix
), Aspect_Constant_Indexing
);
7040 -- If aspect does not exist the expression is illegal. Error is
7041 -- diagnosed in caller.
7043 if No
(Func_Name
) then
7045 -- The prefix itself may be an indexing of a container: rewrite
7046 -- as such and re-analyze.
7048 if Has_Implicit_Dereference
(Etype
(Prefix
)) then
7049 Build_Explicit_Dereference
7050 (Prefix
, First_Discriminant
(Etype
(Prefix
)));
7051 return Try_Container_Indexing
(N
, Prefix
, Exprs
);
7057 -- If the container type is derived from another container type, the
7058 -- value of the inherited aspect is the Reference operation declared
7059 -- for the parent type.
7061 -- However, Reference is also a primitive operation of the type, and
7062 -- the inherited operation has a different signature. We retrieve the
7063 -- right one from the list of primitive operations of the derived type.
7065 -- Note that predefined containers are typically all derived from one
7066 -- of the Controlled types. The code below is motivated by containers
7067 -- that are derived from other types with a Reference aspect.
7069 -- Additional machinery may be needed for types that have several user-
7070 -- defined Reference operations with different signatures ???
7072 elsif Is_Derived_Type
(C_Type
)
7073 and then Etype
(First_Formal
(Entity
(Func_Name
))) /= Etype
(Prefix
)
7075 Func
:= Find_Prim_Op
(C_Type
, Chars
(Func_Name
));
7076 Func_Name
:= New_Occurrence_Of
(Func
, Loc
);
7079 Assoc
:= New_List
(Relocate_Node
(Prefix
));
7081 -- A generalized indexing may have nore than one index expression, so
7082 -- transfer all of them to the argument list to be used in the call.
7083 -- Note that there may be named associations, in which case the node
7084 -- was rewritten earlier as a call, and has been transformed back into
7085 -- an indexed expression to share the following processing.
7087 -- The generalized indexing node is the one on which analysis and
7088 -- resolution take place. Before expansion the original node is replaced
7089 -- with the generalized indexing node, which is a call, possibly with
7090 -- a dereference operation.
7092 if Comes_From_Source
(N
) then
7093 Check_Compiler_Unit
("generalized indexing", N
);
7099 Arg
:= First
(Exprs
);
7100 while Present
(Arg
) loop
7101 Append
(Relocate_Node
(Arg
), Assoc
);
7106 if not Is_Overloaded
(Func_Name
) then
7107 Func
:= Entity
(Func_Name
);
7109 Make_Function_Call
(Loc
,
7110 Name
=> New_Occurrence_Of
(Func
, Loc
),
7111 Parameter_Associations
=> Assoc
);
7112 Set_Parent
(Indexing
, Parent
(N
));
7113 Set_Generalized_Indexing
(N
, Indexing
);
7115 Set_Etype
(N
, Etype
(Indexing
));
7117 -- If the return type of the indexing function is a reference type,
7118 -- add the dereference as a possible interpretation. Note that the
7119 -- indexing aspect may be a function that returns the element type
7120 -- with no intervening implicit dereference, and that the reference
7121 -- discriminant is not the first discriminant.
7123 if Has_Discriminants
(Etype
(Func
)) then
7124 Disc
:= First_Discriminant
(Etype
(Func
));
7125 while Present
(Disc
) loop
7127 Elmt_Type
: Entity_Id
;
7129 if Has_Implicit_Dereference
(Disc
) then
7130 Elmt_Type
:= Designated_Type
(Etype
(Disc
));
7131 Add_One_Interp
(Indexing
, Disc
, Elmt_Type
);
7132 Add_One_Interp
(N
, Disc
, Elmt_Type
);
7137 Next_Discriminant
(Disc
);
7143 Make_Function_Call
(Loc
,
7144 Name
=> Make_Identifier
(Loc
, Chars
(Func_Name
)),
7145 Parameter_Associations
=> Assoc
);
7147 Set_Parent
(Indexing
, Parent
(N
));
7148 Set_Generalized_Indexing
(N
, Indexing
);
7156 Get_First_Interp
(Func_Name
, I
, It
);
7157 Set_Etype
(Indexing
, Any_Type
);
7158 while Present
(It
.Nam
) loop
7159 Analyze_One_Call
(Indexing
, It
.Nam
, False, Success
);
7162 Set_Etype
(Name
(Indexing
), It
.Typ
);
7163 Set_Entity
(Name
(Indexing
), It
.Nam
);
7164 Set_Etype
(N
, Etype
(Indexing
));
7166 -- Add implicit dereference interpretation
7168 if Has_Discriminants
(Etype
(It
.Nam
)) then
7169 Disc
:= First_Discriminant
(Etype
(It
.Nam
));
7170 while Present
(Disc
) loop
7171 if Has_Implicit_Dereference
(Disc
) then
7173 (Indexing
, Disc
, Designated_Type
(Etype
(Disc
)));
7175 (N
, Disc
, Designated_Type
(Etype
(Disc
)));
7179 Next_Discriminant
(Disc
);
7186 Get_Next_Interp
(I
, It
);
7191 if Etype
(Indexing
) = Any_Type
then
7193 ("container cannot be indexed with&", N
, Etype
(First
(Exprs
)));
7194 Rewrite
(N
, New_Occurrence_Of
(Any_Id
, Loc
));
7198 end Try_Container_Indexing
;
7200 -----------------------
7201 -- Try_Indirect_Call --
7202 -----------------------
7204 function Try_Indirect_Call
7207 Typ
: Entity_Id
) return Boolean
7213 pragma Warnings
(Off
, Call_OK
);
7216 Normalize_Actuals
(N
, Designated_Type
(Typ
), False, Call_OK
);
7218 Actual
:= First_Actual
(N
);
7219 Formal
:= First_Formal
(Designated_Type
(Typ
));
7220 while Present
(Actual
) and then Present
(Formal
) loop
7221 if not Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
7226 Next_Formal
(Formal
);
7229 if No
(Actual
) and then No
(Formal
) then
7230 Add_One_Interp
(N
, Nam
, Etype
(Designated_Type
(Typ
)));
7232 -- Nam is a candidate interpretation for the name in the call,
7233 -- if it is not an indirect call.
7235 if not Is_Type
(Nam
)
7236 and then Is_Entity_Name
(Name
(N
))
7238 Set_Entity
(Name
(N
), Nam
);
7246 end Try_Indirect_Call
;
7248 ----------------------
7249 -- Try_Indexed_Call --
7250 ----------------------
7252 function Try_Indexed_Call
7256 Skip_First
: Boolean) return Boolean
7258 Loc
: constant Source_Ptr
:= Sloc
(N
);
7259 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
7264 Actual
:= First
(Actuals
);
7266 -- If the call was originally written in prefix form, skip the first
7267 -- actual, which is obviously not defaulted.
7273 Index
:= First_Index
(Typ
);
7274 while Present
(Actual
) and then Present
(Index
) loop
7276 -- If the parameter list has a named association, the expression
7277 -- is definitely a call and not an indexed component.
7279 if Nkind
(Actual
) = N_Parameter_Association
then
7283 if Is_Entity_Name
(Actual
)
7284 and then Is_Type
(Entity
(Actual
))
7285 and then No
(Next
(Actual
))
7287 -- A single actual that is a type name indicates a slice if the
7288 -- type is discrete, and an error otherwise.
7290 if Is_Discrete_Type
(Entity
(Actual
)) then
7294 Make_Function_Call
(Loc
,
7295 Name
=> Relocate_Node
(Name
(N
))),
7297 New_Occurrence_Of
(Entity
(Actual
), Sloc
(Actual
))));
7302 Error_Msg_N
("invalid use of type in expression", Actual
);
7303 Set_Etype
(N
, Any_Type
);
7308 elsif not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
7316 if No
(Actual
) and then No
(Index
) then
7317 Add_One_Interp
(N
, Nam
, Component_Type
(Typ
));
7319 -- Nam is a candidate interpretation for the name in the call,
7320 -- if it is not an indirect call.
7322 if not Is_Type
(Nam
)
7323 and then Is_Entity_Name
(Name
(N
))
7325 Set_Entity
(Name
(N
), Nam
);
7332 end Try_Indexed_Call
;
7334 --------------------------
7335 -- Try_Object_Operation --
7336 --------------------------
7338 function Try_Object_Operation
7339 (N
: Node_Id
; CW_Test_Only
: Boolean := False) return Boolean
7341 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
7342 Is_Subprg_Call
: constant Boolean := K
in N_Subprogram_Call
;
7343 Loc
: constant Source_Ptr
:= Sloc
(N
);
7344 Obj
: constant Node_Id
:= Prefix
(N
);
7346 Subprog
: constant Node_Id
:=
7347 Make_Identifier
(Sloc
(Selector_Name
(N
)),
7348 Chars
=> Chars
(Selector_Name
(N
)));
7349 -- Identifier on which possible interpretations will be collected
7351 Report_Error
: Boolean := False;
7352 -- If no candidate interpretation matches the context, redo analysis
7353 -- with Report_Error True to provide additional information.
7356 Candidate
: Entity_Id
:= Empty
;
7357 New_Call_Node
: Node_Id
:= Empty
;
7358 Node_To_Replace
: Node_Id
;
7359 Obj_Type
: Entity_Id
:= Etype
(Obj
);
7360 Success
: Boolean := False;
7362 function Valid_Candidate
7365 Subp
: Entity_Id
) return Entity_Id
;
7366 -- If the subprogram is a valid interpretation, record it, and add
7367 -- to the list of interpretations of Subprog. Otherwise return Empty.
7369 procedure Complete_Object_Operation
7370 (Call_Node
: Node_Id
;
7371 Node_To_Replace
: Node_Id
);
7372 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
7373 -- Call_Node, insert the object (or its dereference) as the first actual
7374 -- in the call, and complete the analysis of the call.
7376 procedure Report_Ambiguity
(Op
: Entity_Id
);
7377 -- If a prefixed procedure call is ambiguous, indicate whether the
7378 -- call includes an implicit dereference or an implicit 'Access.
7380 procedure Transform_Object_Operation
7381 (Call_Node
: out Node_Id
;
7382 Node_To_Replace
: out Node_Id
);
7383 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
7384 -- Call_Node is the resulting subprogram call, Node_To_Replace is
7385 -- either N or the parent of N, and Subprog is a reference to the
7386 -- subprogram we are trying to match.
7388 function Try_Class_Wide_Operation
7389 (Call_Node
: Node_Id
;
7390 Node_To_Replace
: Node_Id
) return Boolean;
7391 -- Traverse all ancestor types looking for a class-wide subprogram
7392 -- for which the current operation is a valid non-dispatching call.
7394 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
);
7395 -- If prefix is overloaded, its interpretation may include different
7396 -- tagged types, and we must examine the primitive operations and
7397 -- the class-wide operations of each in order to find candidate
7398 -- interpretations for the call as a whole.
7400 function Try_Primitive_Operation
7401 (Call_Node
: Node_Id
;
7402 Node_To_Replace
: Node_Id
) return Boolean;
7403 -- Traverse the list of primitive subprograms looking for a dispatching
7404 -- operation for which the current node is a valid call .
7406 ---------------------
7407 -- Valid_Candidate --
7408 ---------------------
7410 function Valid_Candidate
7413 Subp
: Entity_Id
) return Entity_Id
7415 Arr_Type
: Entity_Id
;
7416 Comp_Type
: Entity_Id
;
7419 -- If the subprogram is a valid interpretation, record it in global
7420 -- variable Subprog, to collect all possible overloadings.
7423 if Subp
/= Entity
(Subprog
) then
7424 Add_One_Interp
(Subprog
, Subp
, Etype
(Subp
));
7428 -- If the call may be an indexed call, retrieve component type of
7429 -- resulting expression, and add possible interpretation.
7434 if Nkind
(Call
) = N_Function_Call
7435 and then Nkind
(Parent
(N
)) = N_Indexed_Component
7436 and then Needs_One_Actual
(Subp
)
7438 if Is_Array_Type
(Etype
(Subp
)) then
7439 Arr_Type
:= Etype
(Subp
);
7441 elsif Is_Access_Type
(Etype
(Subp
))
7442 and then Is_Array_Type
(Designated_Type
(Etype
(Subp
)))
7444 Arr_Type
:= Designated_Type
(Etype
(Subp
));
7448 if Present
(Arr_Type
) then
7450 -- Verify that the actuals (excluding the object) match the types
7458 Actual
:= Next
(First_Actual
(Call
));
7459 Index
:= First_Index
(Arr_Type
);
7460 while Present
(Actual
) and then Present
(Index
) loop
7461 if not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
7466 Next_Actual
(Actual
);
7472 and then Present
(Arr_Type
)
7474 Comp_Type
:= Component_Type
(Arr_Type
);
7478 if Present
(Comp_Type
)
7479 and then Etype
(Subprog
) /= Comp_Type
7481 Add_One_Interp
(Subprog
, Subp
, Comp_Type
);
7485 if Etype
(Call
) /= Any_Type
then
7490 end Valid_Candidate
;
7492 -------------------------------
7493 -- Complete_Object_Operation --
7494 -------------------------------
7496 procedure Complete_Object_Operation
7497 (Call_Node
: Node_Id
;
7498 Node_To_Replace
: Node_Id
)
7500 Control
: constant Entity_Id
:= First_Formal
(Entity
(Subprog
));
7501 Formal_Type
: constant Entity_Id
:= Etype
(Control
);
7502 First_Actual
: Node_Id
;
7505 -- Place the name of the operation, with its interpretations,
7506 -- on the rewritten call.
7508 Set_Name
(Call_Node
, Subprog
);
7510 First_Actual
:= First
(Parameter_Associations
(Call_Node
));
7512 -- For cross-reference purposes, treat the new node as being in the
7513 -- source if the original one is. Set entity and type, even though
7514 -- they may be overwritten during resolution if overloaded.
7516 Set_Comes_From_Source
(Subprog
, Comes_From_Source
(N
));
7517 Set_Comes_From_Source
(Call_Node
, Comes_From_Source
(N
));
7519 if Nkind
(N
) = N_Selected_Component
7520 and then not Inside_A_Generic
7522 Set_Entity
(Selector_Name
(N
), Entity
(Subprog
));
7523 Set_Etype
(Selector_Name
(N
), Etype
(Entity
(Subprog
)));
7526 -- If need be, rewrite first actual as an explicit dereference. If
7527 -- the call is overloaded, the rewriting can only be done once the
7528 -- primitive operation is identified.
7530 if Is_Overloaded
(Subprog
) then
7532 -- The prefix itself may be overloaded, and its interpretations
7533 -- must be propagated to the new actual in the call.
7535 if Is_Overloaded
(Obj
) then
7536 Save_Interps
(Obj
, First_Actual
);
7539 Rewrite
(First_Actual
, Obj
);
7541 elsif not Is_Access_Type
(Formal_Type
)
7542 and then Is_Access_Type
(Etype
(Obj
))
7544 Rewrite
(First_Actual
,
7545 Make_Explicit_Dereference
(Sloc
(Obj
), Obj
));
7546 Analyze
(First_Actual
);
7548 -- If we need to introduce an explicit dereference, verify that
7549 -- the resulting actual is compatible with the mode of the formal.
7551 if Ekind
(First_Formal
(Entity
(Subprog
))) /= E_In_Parameter
7552 and then Is_Access_Constant
(Etype
(Obj
))
7555 ("expect variable in call to&", Prefix
(N
), Entity
(Subprog
));
7558 -- Conversely, if the formal is an access parameter and the object
7559 -- is not, replace the actual with a 'Access reference. Its analysis
7560 -- will check that the object is aliased.
7562 elsif Is_Access_Type
(Formal_Type
)
7563 and then not Is_Access_Type
(Etype
(Obj
))
7565 -- A special case: A.all'access is illegal if A is an access to a
7566 -- constant and the context requires an access to a variable.
7568 if not Is_Access_Constant
(Formal_Type
) then
7569 if (Nkind
(Obj
) = N_Explicit_Dereference
7570 and then Is_Access_Constant
(Etype
(Prefix
(Obj
))))
7571 or else not Is_Variable
(Obj
)
7574 ("actual for& must be a variable", Obj
, Control
);
7578 Rewrite
(First_Actual
,
7579 Make_Attribute_Reference
(Loc
,
7580 Attribute_Name
=> Name_Access
,
7581 Prefix
=> Relocate_Node
(Obj
)));
7583 if not Is_Aliased_View
(Obj
) then
7585 ("object in prefixed call to& must be aliased"
7586 & " (RM-2005 4.3.1 (13))",
7587 Prefix
(First_Actual
), Subprog
);
7590 Analyze
(First_Actual
);
7593 if Is_Overloaded
(Obj
) then
7594 Save_Interps
(Obj
, First_Actual
);
7597 Rewrite
(First_Actual
, Obj
);
7600 Rewrite
(Node_To_Replace
, Call_Node
);
7602 -- Propagate the interpretations collected in subprog to the new
7603 -- function call node, to be resolved from context.
7605 if Is_Overloaded
(Subprog
) then
7606 Save_Interps
(Subprog
, Node_To_Replace
);
7609 -- The type of the subprogram may be a limited view obtained
7610 -- transitively from another unit. If full view is available,
7611 -- use it to analyze call.
7614 T
: constant Entity_Id
:= Etype
(Subprog
);
7616 if From_Limited_With
(T
) then
7617 Set_Etype
(Entity
(Subprog
), Available_View
(T
));
7621 Analyze
(Node_To_Replace
);
7623 -- If the operation has been rewritten into a call, which may get
7624 -- subsequently an explicit dereference, preserve the type on the
7625 -- original node (selected component or indexed component) for
7626 -- subsequent legality tests, e.g. Is_Variable. which examines
7627 -- the original node.
7629 if Nkind
(Node_To_Replace
) = N_Function_Call
then
7631 (Original_Node
(Node_To_Replace
), Etype
(Node_To_Replace
));
7634 end Complete_Object_Operation
;
7636 ----------------------
7637 -- Report_Ambiguity --
7638 ----------------------
7640 procedure Report_Ambiguity
(Op
: Entity_Id
) is
7641 Access_Actual
: constant Boolean :=
7642 Is_Access_Type
(Etype
(Prefix
(N
)));
7643 Access_Formal
: Boolean := False;
7646 Error_Msg_Sloc
:= Sloc
(Op
);
7648 if Present
(First_Formal
(Op
)) then
7649 Access_Formal
:= Is_Access_Type
(Etype
(First_Formal
(Op
)));
7652 if Access_Formal
and then not Access_Actual
then
7653 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
7655 ("\possible interpretation "
7656 & "(inherited, with implicit 'Access) #", N
);
7659 ("\possible interpretation (with implicit 'Access) #", N
);
7662 elsif not Access_Formal
and then Access_Actual
then
7663 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
7665 ("\possible interpretation "
7666 & "(inherited, with implicit dereference) #", N
);
7669 ("\possible interpretation (with implicit dereference) #", N
);
7673 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
7674 Error_Msg_N
("\possible interpretation (inherited)#", N
);
7676 Error_Msg_N
-- CODEFIX
7677 ("\possible interpretation#", N
);
7680 end Report_Ambiguity
;
7682 --------------------------------
7683 -- Transform_Object_Operation --
7684 --------------------------------
7686 procedure Transform_Object_Operation
7687 (Call_Node
: out Node_Id
;
7688 Node_To_Replace
: out Node_Id
)
7690 Dummy
: constant Node_Id
:= New_Copy
(Obj
);
7691 -- Placeholder used as a first parameter in the call, replaced
7692 -- eventually by the proper object.
7694 Parent_Node
: constant Node_Id
:= Parent
(N
);
7700 -- Common case covering 1) Call to a procedure and 2) Call to a
7701 -- function that has some additional actuals.
7703 if Nkind
(Parent_Node
) in N_Subprogram_Call
7705 -- N is a selected component node containing the name of the
7706 -- subprogram. If N is not the name of the parent node we must
7707 -- not replace the parent node by the new construct. This case
7708 -- occurs when N is a parameterless call to a subprogram that
7709 -- is an actual parameter of a call to another subprogram. For
7711 -- Some_Subprogram (..., Obj.Operation, ...)
7713 and then Name
(Parent_Node
) = N
7715 Node_To_Replace
:= Parent_Node
;
7717 Actuals
:= Parameter_Associations
(Parent_Node
);
7719 if Present
(Actuals
) then
7720 Prepend
(Dummy
, Actuals
);
7722 Actuals
:= New_List
(Dummy
);
7725 if Nkind
(Parent_Node
) = N_Procedure_Call_Statement
then
7727 Make_Procedure_Call_Statement
(Loc
,
7728 Name
=> New_Copy
(Subprog
),
7729 Parameter_Associations
=> Actuals
);
7733 Make_Function_Call
(Loc
,
7734 Name
=> New_Copy
(Subprog
),
7735 Parameter_Associations
=> Actuals
);
7738 -- Before analysis, a function call appears as an indexed component
7739 -- if there are no named associations.
7741 elsif Nkind
(Parent_Node
) = N_Indexed_Component
7742 and then N
= Prefix
(Parent_Node
)
7744 Node_To_Replace
:= Parent_Node
;
7745 Actuals
:= Expressions
(Parent_Node
);
7747 Actual
:= First
(Actuals
);
7748 while Present
(Actual
) loop
7753 Prepend
(Dummy
, Actuals
);
7756 Make_Function_Call
(Loc
,
7757 Name
=> New_Copy
(Subprog
),
7758 Parameter_Associations
=> Actuals
);
7760 -- Parameterless call: Obj.F is rewritten as F (Obj)
7763 Node_To_Replace
:= N
;
7766 Make_Function_Call
(Loc
,
7767 Name
=> New_Copy
(Subprog
),
7768 Parameter_Associations
=> New_List
(Dummy
));
7770 end Transform_Object_Operation
;
7772 ------------------------------
7773 -- Try_Class_Wide_Operation --
7774 ------------------------------
7776 function Try_Class_Wide_Operation
7777 (Call_Node
: Node_Id
;
7778 Node_To_Replace
: Node_Id
) return Boolean
7780 Anc_Type
: Entity_Id
;
7781 Matching_Op
: Entity_Id
:= Empty
;
7784 procedure Traverse_Homonyms
7785 (Anc_Type
: Entity_Id
;
7786 Error
: out Boolean);
7787 -- Traverse the homonym chain of the subprogram searching for those
7788 -- homonyms whose first formal has the Anc_Type's class-wide type,
7789 -- or an anonymous access type designating the class-wide type. If
7790 -- an ambiguity is detected, then Error is set to True.
7792 procedure Traverse_Interfaces
7793 (Anc_Type
: Entity_Id
;
7794 Error
: out Boolean);
7795 -- Traverse the list of interfaces, if any, associated with Anc_Type
7796 -- and search for acceptable class-wide homonyms associated with each
7797 -- interface. If an ambiguity is detected, then Error is set to True.
7799 -----------------------
7800 -- Traverse_Homonyms --
7801 -----------------------
7803 procedure Traverse_Homonyms
7804 (Anc_Type
: Entity_Id
;
7805 Error
: out Boolean)
7807 Cls_Type
: Entity_Id
;
7815 Cls_Type
:= Class_Wide_Type
(Anc_Type
);
7817 Hom
:= Current_Entity
(Subprog
);
7819 -- Find a non-hidden operation whose first parameter is of the
7820 -- class-wide type, a subtype thereof, or an anonymous access
7821 -- to same. If in an instance, the operation can be considered
7822 -- even if hidden (it may be hidden because the instantiation
7823 -- is expanded after the containing package has been analyzed).
7825 while Present
(Hom
) loop
7826 if Ekind_In
(Hom
, E_Procedure
, E_Function
)
7827 and then (not Is_Hidden
(Hom
) or else In_Instance
)
7828 and then Scope
(Hom
) = Scope
(Anc_Type
)
7829 and then Present
(First_Formal
(Hom
))
7831 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
7833 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
7835 Ekind
(Etype
(First_Formal
(Hom
))) =
7836 E_Anonymous_Access_Type
7839 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
7842 -- If the context is a procedure call, ignore functions
7843 -- in the name of the call.
7845 if Ekind
(Hom
) = E_Function
7846 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
7847 and then N
= Name
(Parent
(N
))
7851 -- If the context is a function call, ignore procedures
7852 -- in the name of the call.
7854 elsif Ekind
(Hom
) = E_Procedure
7855 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
7860 Set_Etype
(Call_Node
, Any_Type
);
7861 Set_Is_Overloaded
(Call_Node
, False);
7864 if No
(Matching_Op
) then
7865 Hom_Ref
:= New_Occurrence_Of
(Hom
, Sloc
(Subprog
));
7866 Set_Etype
(Call_Node
, Any_Type
);
7867 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
7869 Set_Name
(Call_Node
, Hom_Ref
);
7874 Report
=> Report_Error
,
7876 Skip_First
=> True);
7879 Valid_Candidate
(Success
, Call_Node
, Hom
);
7885 Report
=> Report_Error
,
7887 Skip_First
=> True);
7889 if Present
(Valid_Candidate
(Success
, Call_Node
, Hom
))
7890 and then Nkind
(Call_Node
) /= N_Function_Call
7892 Error_Msg_NE
("ambiguous call to&", N
, Hom
);
7893 Report_Ambiguity
(Matching_Op
);
7894 Report_Ambiguity
(Hom
);
7902 Hom
:= Homonym
(Hom
);
7904 end Traverse_Homonyms
;
7906 -------------------------
7907 -- Traverse_Interfaces --
7908 -------------------------
7910 procedure Traverse_Interfaces
7911 (Anc_Type
: Entity_Id
;
7912 Error
: out Boolean)
7914 Intface_List
: constant List_Id
:=
7915 Abstract_Interface_List
(Anc_Type
);
7921 if Is_Non_Empty_List
(Intface_List
) then
7922 Intface
:= First
(Intface_List
);
7923 while Present
(Intface
) loop
7925 -- Look for acceptable class-wide homonyms associated with
7928 Traverse_Homonyms
(Etype
(Intface
), Error
);
7934 -- Continue the search by looking at each of the interface's
7935 -- associated interface ancestors.
7937 Traverse_Interfaces
(Etype
(Intface
), Error
);
7946 end Traverse_Interfaces
;
7948 -- Start of processing for Try_Class_Wide_Operation
7951 -- If we are searching only for conflicting class-wide subprograms
7952 -- then initialize directly Matching_Op with the target entity.
7954 if CW_Test_Only
then
7955 Matching_Op
:= Entity
(Selector_Name
(N
));
7958 -- Loop through ancestor types (including interfaces), traversing
7959 -- the homonym chain of the subprogram, trying out those homonyms
7960 -- whose first formal has the class-wide type of the ancestor, or
7961 -- an anonymous access type designating the class-wide type.
7963 Anc_Type
:= Obj_Type
;
7965 -- Look for a match among homonyms associated with the ancestor
7967 Traverse_Homonyms
(Anc_Type
, Error
);
7973 -- Continue the search for matches among homonyms associated with
7974 -- any interfaces implemented by the ancestor.
7976 Traverse_Interfaces
(Anc_Type
, Error
);
7982 exit when Etype
(Anc_Type
) = Anc_Type
;
7983 Anc_Type
:= Etype
(Anc_Type
);
7986 if Present
(Matching_Op
) then
7987 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
7990 return Present
(Matching_Op
);
7991 end Try_Class_Wide_Operation
;
7993 -----------------------------------
7994 -- Try_One_Prefix_Interpretation --
7995 -----------------------------------
7997 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
) is
8001 if Is_Access_Type
(Obj_Type
) then
8002 Obj_Type
:= Designated_Type
(Obj_Type
);
8005 if Ekind
(Obj_Type
) = E_Private_Subtype
then
8006 Obj_Type
:= Base_Type
(Obj_Type
);
8009 if Is_Class_Wide_Type
(Obj_Type
) then
8010 Obj_Type
:= Etype
(Class_Wide_Type
(Obj_Type
));
8013 -- The type may have be obtained through a limited_with clause,
8014 -- in which case the primitive operations are available on its
8015 -- non-limited view. If still incomplete, retrieve full view.
8017 if Ekind
(Obj_Type
) = E_Incomplete_Type
8018 and then From_Limited_With
(Obj_Type
)
8020 Obj_Type
:= Get_Full_View
(Non_Limited_View
(Obj_Type
));
8023 -- If the object is not tagged, or the type is still an incomplete
8024 -- type, this is not a prefixed call.
8026 if not Is_Tagged_Type
(Obj_Type
)
8027 or else Is_Incomplete_Type
(Obj_Type
)
8033 Dup_Call_Node
: constant Node_Id
:= New_Copy
(New_Call_Node
);
8034 CW_Result
: Boolean;
8035 Prim_Result
: Boolean;
8036 pragma Unreferenced
(CW_Result
);
8039 if not CW_Test_Only
then
8041 Try_Primitive_Operation
8042 (Call_Node
=> New_Call_Node
,
8043 Node_To_Replace
=> Node_To_Replace
);
8046 -- Check if there is a class-wide subprogram covering the
8047 -- primitive. This check must be done even if a candidate
8048 -- was found in order to report ambiguous calls.
8050 if not (Prim_Result
) then
8052 Try_Class_Wide_Operation
8053 (Call_Node
=> New_Call_Node
,
8054 Node_To_Replace
=> Node_To_Replace
);
8056 -- If we found a primitive we search for class-wide subprograms
8057 -- using a duplicate of the call node (done to avoid missing its
8058 -- decoration if there is no ambiguity).
8062 Try_Class_Wide_Operation
8063 (Call_Node
=> Dup_Call_Node
,
8064 Node_To_Replace
=> Node_To_Replace
);
8067 end Try_One_Prefix_Interpretation
;
8069 -----------------------------
8070 -- Try_Primitive_Operation --
8071 -----------------------------
8073 function Try_Primitive_Operation
8074 (Call_Node
: Node_Id
;
8075 Node_To_Replace
: Node_Id
) return Boolean
8078 Prim_Op
: Entity_Id
;
8079 Matching_Op
: Entity_Id
:= Empty
;
8080 Prim_Op_Ref
: Node_Id
:= Empty
;
8082 Corr_Type
: Entity_Id
:= Empty
;
8083 -- If the prefix is a synchronized type, the controlling type of
8084 -- the primitive operation is the corresponding record type, else
8085 -- this is the object type itself.
8087 Success
: Boolean := False;
8089 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
;
8090 -- For tagged types the candidate interpretations are found in
8091 -- the list of primitive operations of the type and its ancestors.
8092 -- For formal tagged types we have to find the operations declared
8093 -- in the same scope as the type (including in the generic formal
8094 -- part) because the type itself carries no primitive operations,
8095 -- except for formal derived types that inherit the operations of
8096 -- the parent and progenitors.
8098 -- If the context is a generic subprogram body, the generic formals
8099 -- are visible by name, but are not in the entity list of the
8100 -- subprogram because that list starts with the subprogram formals.
8101 -- We retrieve the candidate operations from the generic declaration.
8103 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean;
8104 -- An operation that overrides an inherited operation in the private
8105 -- part of its package may be hidden, but if the inherited operation
8106 -- is visible a direct call to it will dispatch to the private one,
8107 -- which is therefore a valid candidate.
8109 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean;
8110 -- Verify that the prefix, dereferenced if need be, is a valid
8111 -- controlling argument in a call to Op. The remaining actuals
8112 -- are checked in the subsequent call to Analyze_One_Call.
8114 ------------------------------
8115 -- Collect_Generic_Type_Ops --
8116 ------------------------------
8118 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
is
8119 Bas
: constant Entity_Id
:= Base_Type
(T
);
8120 Candidates
: constant Elist_Id
:= New_Elmt_List
;
8124 procedure Check_Candidate
;
8125 -- The operation is a candidate if its first parameter is a
8126 -- controlling operand of the desired type.
8128 -----------------------
8129 -- Check_Candidate; --
8130 -----------------------
8132 procedure Check_Candidate
is
8134 Formal
:= First_Formal
(Subp
);
8137 and then Is_Controlling_Formal
(Formal
)
8139 (Base_Type
(Etype
(Formal
)) = Bas
8141 (Is_Access_Type
(Etype
(Formal
))
8142 and then Designated_Type
(Etype
(Formal
)) = Bas
))
8144 Append_Elmt
(Subp
, Candidates
);
8146 end Check_Candidate
;
8148 -- Start of processing for Collect_Generic_Type_Ops
8151 if Is_Derived_Type
(T
) then
8152 return Primitive_Operations
(T
);
8154 elsif Ekind_In
(Scope
(T
), E_Procedure
, E_Function
) then
8156 -- Scan the list of generic formals to find subprograms
8157 -- that may have a first controlling formal of the type.
8159 if Nkind
(Unit_Declaration_Node
(Scope
(T
))) =
8160 N_Generic_Subprogram_Declaration
8167 First
(Generic_Formal_Declarations
8168 (Unit_Declaration_Node
(Scope
(T
))));
8169 while Present
(Decl
) loop
8170 if Nkind
(Decl
) in N_Formal_Subprogram_Declaration
then
8171 Subp
:= Defining_Entity
(Decl
);
8182 -- Scan the list of entities declared in the same scope as
8183 -- the type. In general this will be an open scope, given that
8184 -- the call we are analyzing can only appear within a generic
8185 -- declaration or body (either the one that declares T, or a
8188 -- For a subtype representing a generic actual type, go to the
8191 if Is_Generic_Actual_Type
(T
) then
8192 Subp
:= First_Entity
(Scope
(Base_Type
(T
)));
8194 Subp
:= First_Entity
(Scope
(T
));
8197 while Present
(Subp
) loop
8198 if Is_Overloadable
(Subp
) then
8207 end Collect_Generic_Type_Ops
;
8209 ---------------------------
8210 -- Is_Private_Overriding --
8211 ---------------------------
8213 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean is
8214 Visible_Op
: constant Entity_Id
:= Homonym
(Op
);
8217 return Present
(Visible_Op
)
8218 and then Scope
(Op
) = Scope
(Visible_Op
)
8219 and then not Comes_From_Source
(Visible_Op
)
8220 and then Alias
(Visible_Op
) = Op
8221 and then not Is_Hidden
(Visible_Op
);
8222 end Is_Private_Overriding
;
8224 -----------------------------
8225 -- Valid_First_Argument_Of --
8226 -----------------------------
8228 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean is
8229 Typ
: Entity_Id
:= Etype
(First_Formal
(Op
));
8232 if Is_Concurrent_Type
(Typ
)
8233 and then Present
(Corresponding_Record_Type
(Typ
))
8235 Typ
:= Corresponding_Record_Type
(Typ
);
8238 -- Simple case. Object may be a subtype of the tagged type or
8239 -- may be the corresponding record of a synchronized type.
8241 return Obj_Type
= Typ
8242 or else Base_Type
(Obj_Type
) = Typ
8243 or else Corr_Type
= Typ
8245 -- Prefix can be dereferenced
8248 (Is_Access_Type
(Corr_Type
)
8249 and then Designated_Type
(Corr_Type
) = Typ
)
8251 -- Formal is an access parameter, for which the object
8252 -- can provide an access.
8255 (Ekind
(Typ
) = E_Anonymous_Access_Type
8257 Base_Type
(Designated_Type
(Typ
)) = Base_Type
(Corr_Type
));
8258 end Valid_First_Argument_Of
;
8260 -- Start of processing for Try_Primitive_Operation
8263 -- Look for subprograms in the list of primitive operations. The name
8264 -- must be identical, and the kind of call indicates the expected
8265 -- kind of operation (function or procedure). If the type is a
8266 -- (tagged) synchronized type, the primitive ops are attached to the
8267 -- corresponding record (base) type.
8269 if Is_Concurrent_Type
(Obj_Type
) then
8270 if Present
(Corresponding_Record_Type
(Obj_Type
)) then
8271 Corr_Type
:= Base_Type
(Corresponding_Record_Type
(Obj_Type
));
8272 Elmt
:= First_Elmt
(Primitive_Operations
(Corr_Type
));
8274 Corr_Type
:= Obj_Type
;
8275 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
8278 elsif not Is_Generic_Type
(Obj_Type
) then
8279 Corr_Type
:= Obj_Type
;
8280 Elmt
:= First_Elmt
(Primitive_Operations
(Obj_Type
));
8283 Corr_Type
:= Obj_Type
;
8284 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
8287 while Present
(Elmt
) loop
8288 Prim_Op
:= Node
(Elmt
);
8290 if Chars
(Prim_Op
) = Chars
(Subprog
)
8291 and then Present
(First_Formal
(Prim_Op
))
8292 and then Valid_First_Argument_Of
(Prim_Op
)
8294 (Nkind
(Call_Node
) = N_Function_Call
)
8296 (Ekind
(Prim_Op
) = E_Function
)
8298 -- Ada 2005 (AI-251): If this primitive operation corresponds
8299 -- to an immediate ancestor interface there is no need to add
8300 -- it to the list of interpretations; the corresponding aliased
8301 -- primitive is also in this list of primitive operations and
8302 -- will be used instead.
8304 if (Present
(Interface_Alias
(Prim_Op
))
8305 and then Is_Ancestor
(Find_Dispatching_Type
8306 (Alias
(Prim_Op
)), Corr_Type
))
8308 -- Do not consider hidden primitives unless the type is in an
8309 -- open scope or we are within an instance, where visibility
8310 -- is known to be correct, or else if this is an overriding
8311 -- operation in the private part for an inherited operation.
8313 or else (Is_Hidden
(Prim_Op
)
8314 and then not Is_Immediately_Visible
(Obj_Type
)
8315 and then not In_Instance
8316 and then not Is_Private_Overriding
(Prim_Op
))
8321 Set_Etype
(Call_Node
, Any_Type
);
8322 Set_Is_Overloaded
(Call_Node
, False);
8324 if No
(Matching_Op
) then
8325 Prim_Op_Ref
:= New_Occurrence_Of
(Prim_Op
, Sloc
(Subprog
));
8326 Candidate
:= Prim_Op
;
8328 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
8330 Set_Name
(Call_Node
, Prim_Op_Ref
);
8336 Report
=> Report_Error
,
8338 Skip_First
=> True);
8340 Matching_Op
:= Valid_Candidate
(Success
, Call_Node
, Prim_Op
);
8342 -- More than one interpretation, collect for subsequent
8343 -- disambiguation. If this is a procedure call and there
8344 -- is another match, report ambiguity now.
8350 Report
=> Report_Error
,
8352 Skip_First
=> True);
8354 if Present
(Valid_Candidate
(Success
, Call_Node
, Prim_Op
))
8355 and then Nkind
(Call_Node
) /= N_Function_Call
8357 Error_Msg_NE
("ambiguous call to&", N
, Prim_Op
);
8358 Report_Ambiguity
(Matching_Op
);
8359 Report_Ambiguity
(Prim_Op
);
8369 if Present
(Matching_Op
) then
8370 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
8373 return Present
(Matching_Op
);
8374 end Try_Primitive_Operation
;
8376 -- Start of processing for Try_Object_Operation
8379 Analyze_Expression
(Obj
);
8381 -- Analyze the actuals if node is known to be a subprogram call
8383 if Is_Subprg_Call
and then N
= Name
(Parent
(N
)) then
8384 Actual
:= First
(Parameter_Associations
(Parent
(N
)));
8385 while Present
(Actual
) loop
8386 Analyze_Expression
(Actual
);
8391 -- Build a subprogram call node, using a copy of Obj as its first
8392 -- actual. This is a placeholder, to be replaced by an explicit
8393 -- dereference when needed.
8395 Transform_Object_Operation
8396 (Call_Node
=> New_Call_Node
,
8397 Node_To_Replace
=> Node_To_Replace
);
8399 Set_Etype
(New_Call_Node
, Any_Type
);
8400 Set_Etype
(Subprog
, Any_Type
);
8401 Set_Parent
(New_Call_Node
, Parent
(Node_To_Replace
));
8403 if not Is_Overloaded
(Obj
) then
8404 Try_One_Prefix_Interpretation
(Obj_Type
);
8411 Get_First_Interp
(Obj
, I
, It
);
8412 while Present
(It
.Nam
) loop
8413 Try_One_Prefix_Interpretation
(It
.Typ
);
8414 Get_Next_Interp
(I
, It
);
8419 if Etype
(New_Call_Node
) /= Any_Type
then
8421 -- No need to complete the tree transformations if we are only
8422 -- searching for conflicting class-wide subprograms
8424 if CW_Test_Only
then
8427 Complete_Object_Operation
8428 (Call_Node
=> New_Call_Node
,
8429 Node_To_Replace
=> Node_To_Replace
);
8433 elsif Present
(Candidate
) then
8435 -- The argument list is not type correct. Re-analyze with error
8436 -- reporting enabled, and use one of the possible candidates.
8437 -- In All_Errors_Mode, re-analyze all failed interpretations.
8439 if All_Errors_Mode
then
8440 Report_Error
:= True;
8441 if Try_Primitive_Operation
8442 (Call_Node
=> New_Call_Node
,
8443 Node_To_Replace
=> Node_To_Replace
)
8446 Try_Class_Wide_Operation
8447 (Call_Node
=> New_Call_Node
,
8448 Node_To_Replace
=> Node_To_Replace
)
8455 (N
=> New_Call_Node
,
8459 Skip_First
=> True);
8462 -- No need for further errors
8467 -- There was no candidate operation, so report it as an error
8468 -- in the caller: Analyze_Selected_Component.
8472 end Try_Object_Operation
;
8478 procedure wpo
(T
: Entity_Id
) is
8483 if not Is_Tagged_Type
(T
) then
8487 E
:= First_Elmt
(Primitive_Operations
(Base_Type
(T
)));
8488 while Present
(E
) loop
8490 Write_Int
(Int
(Op
));
8491 Write_Str
(" === ");
8492 Write_Name
(Chars
(Op
));
8494 Write_Name
(Chars
(Scope
(Op
)));