1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Util
; use Exp_Util
;
33 with Fname
; use Fname
;
34 with Itypes
; use Itypes
;
36 with Lib
.Xref
; use Lib
.Xref
;
37 with Namet
; use Namet
;
38 with Namet
.Sp
; use Namet
.Sp
;
39 with Nlists
; use Nlists
;
40 with Nmake
; use Nmake
;
42 with Output
; use Output
;
43 with Restrict
; use Restrict
;
44 with Rident
; use Rident
;
46 with Sem_Aux
; use Sem_Aux
;
47 with Sem_Case
; use Sem_Case
;
48 with Sem_Cat
; use Sem_Cat
;
49 with Sem_Ch3
; use Sem_Ch3
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch8
; use Sem_Ch8
;
52 with Sem_Dim
; use Sem_Dim
;
53 with Sem_Disp
; use Sem_Disp
;
54 with Sem_Dist
; use Sem_Dist
;
55 with Sem_Eval
; use Sem_Eval
;
56 with Sem_Res
; use Sem_Res
;
57 with Sem_Type
; use Sem_Type
;
58 with Sem_Util
; use Sem_Util
;
59 with Sem_Warn
; use Sem_Warn
;
60 with Stand
; use Stand
;
61 with Sinfo
; use Sinfo
;
62 with Snames
; use Snames
;
63 with Tbuild
; use Tbuild
;
64 with Uintp
; use Uintp
;
66 package body Sem_Ch4
is
68 -- Tables which speed up the identification of dangerous calls to Ada 2012
69 -- functions with writable actuals (AI05-0144).
71 -- The following table enumerates the Ada constructs which may evaluate in
72 -- arbitrary order. It does not cover all the language constructs which can
73 -- be evaluated in arbitrary order but the subset needed for AI05-0144.
75 Has_Arbitrary_Evaluation_Order
: constant array (Node_Kind
) of Boolean :=
77 N_Assignment_Statement
=> True,
78 N_Entry_Call_Statement
=> True,
79 N_Extension_Aggregate
=> True,
80 N_Full_Type_Declaration
=> True,
81 N_Indexed_Component
=> True,
82 N_Object_Declaration
=> True,
86 N_Array_Type_Definition
=> True,
87 N_Membership_Test
=> True,
89 N_Subprogram_Call
=> True,
92 -- The following table enumerates the nodes on which we stop climbing when
93 -- locating the outermost Ada construct that can be evaluated in arbitrary
96 Stop_Subtree_Climbing
: constant array (Node_Kind
) of Boolean :=
98 N_Assignment_Statement
=> True,
99 N_Entry_Call_Statement
=> True,
100 N_Extended_Return_Statement
=> True,
101 N_Extension_Aggregate
=> True,
102 N_Full_Type_Declaration
=> True,
103 N_Object_Declaration
=> True,
104 N_Object_Renaming_Declaration
=> True,
105 N_Package_Specification
=> True,
107 N_Procedure_Call_Statement
=> True,
108 N_Simple_Return_Statement
=> True,
109 N_Has_Condition
=> True,
112 -----------------------
113 -- Local Subprograms --
114 -----------------------
116 procedure Analyze_Concatenation_Rest
(N
: Node_Id
);
117 -- Does the "rest" of the work of Analyze_Concatenation, after the left
118 -- operand has been analyzed. See Analyze_Concatenation for details.
120 procedure Analyze_Expression
(N
: Node_Id
);
121 -- For expressions that are not names, this is just a call to analyze. If
122 -- the expression is a name, it may be a call to a parameterless function,
123 -- and if so must be converted into an explicit call node and analyzed as
124 -- such. This deproceduring must be done during the first pass of overload
125 -- resolution, because otherwise a procedure call with overloaded actuals
126 -- may fail to resolve.
128 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
);
129 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call is an
130 -- operator name or an expanded name whose selector is an operator name,
131 -- and one possible interpretation is as a predefined operator.
133 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
);
134 -- If the prefix of a selected_component is overloaded, the proper
135 -- interpretation that yields a record type with the proper selector
136 -- name must be selected.
138 procedure Analyze_User_Defined_Binary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
139 -- Procedure to analyze a user defined binary operator, which is resolved
140 -- like a function, but instead of a list of actuals it is presented
141 -- with the left and right operands of an operator node.
143 procedure Analyze_User_Defined_Unary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
144 -- Procedure to analyze a user defined unary operator, which is resolved
145 -- like a function, but instead of a list of actuals, it is presented with
146 -- the operand of the operator node.
148 procedure Ambiguous_Operands
(N
: Node_Id
);
149 -- For equality, membership, and comparison operators with overloaded
150 -- arguments, list possible interpretations.
152 procedure Analyze_One_Call
156 Success
: out Boolean;
157 Skip_First
: Boolean := False);
158 -- Check one interpretation of an overloaded subprogram name for
159 -- compatibility with the types of the actuals in a call. If there is a
160 -- single interpretation which does not match, post error if Report is
163 -- Nam is the entity that provides the formals against which the actuals
164 -- are checked. Nam is either the name of a subprogram, or the internal
165 -- subprogram type constructed for an access_to_subprogram. If the actuals
166 -- are compatible with Nam, then Nam is added to the list of candidate
167 -- interpretations for N, and Success is set to True.
169 -- The flag Skip_First is used when analyzing a call that was rewritten
170 -- from object notation. In this case the first actual may have to receive
171 -- an explicit dereference, depending on the first formal of the operation
172 -- being called. The caller will have verified that the object is legal
173 -- for the call. If the remaining parameters match, the first parameter
174 -- will rewritten as a dereference if needed, prior to completing analysis.
176 procedure Check_Misspelled_Selector
179 -- Give possible misspelling message if Sel seems likely to be a mis-
180 -- spelling of one of the selectors of the Prefix. This is called by
181 -- Analyze_Selected_Component after producing an invalid selector error
184 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean;
185 -- Verify that type T is declared in scope S. Used to find interpretations
186 -- for operators given by expanded names. This is abstracted as a separate
187 -- function to handle extensions to System, where S is System, but T is
188 -- declared in the extension.
190 procedure Find_Arithmetic_Types
194 -- L and R are the operands of an arithmetic operator. Find consistent
195 -- pairs of interpretations for L and R that have a numeric type consistent
196 -- with the semantics of the operator.
198 procedure Find_Comparison_Types
202 -- L and R are operands of a comparison operator. Find consistent pairs of
203 -- interpretations for L and R.
205 procedure Find_Concatenation_Types
209 -- For the four varieties of concatenation
211 procedure Find_Equality_Types
215 -- Ditto for equality operators
217 procedure Find_Boolean_Types
221 -- Ditto for binary logical operations
223 procedure Find_Negation_Types
227 -- Find consistent interpretation for operand of negation operator
229 procedure Find_Non_Universal_Interpretations
234 -- For equality and comparison operators, the result is always boolean,
235 -- and the legality of the operation is determined from the visibility
236 -- of the operand types. If one of the operands has a universal interpre-
237 -- tation, the legality check uses some compatible non-universal
238 -- interpretation of the other operand. N can be an operator node, or
239 -- a function call whose name is an operator designator. Any_Access, which
240 -- is the initial type of the literal NULL, is a universal type for the
241 -- purpose of this routine.
243 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean;
244 -- Find candidate interpretations for the name Obj.Proc when it appears
245 -- in a subprogram renaming declaration.
247 procedure Find_Unary_Types
251 -- Unary arithmetic types: plus, minus, abs
253 procedure Check_Arithmetic_Pair
257 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid types
258 -- for left and right operand. Determine whether they constitute a valid
259 -- pair for the given operator, and record the corresponding interpretation
260 -- of the operator node. The node N may be an operator node (the usual
261 -- case) or a function call whose prefix is an operator designator. In
262 -- both cases Op_Id is the operator name itself.
264 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
);
265 -- Give detailed information on overloaded call where none of the
266 -- interpretations match. N is the call node, Nam the designator for
267 -- the overloaded entity being called.
269 function Junk_Operand
(N
: Node_Id
) return Boolean;
270 -- Test for an operand that is an inappropriate entity (e.g. a package
271 -- name or a label). If so, issue an error message and return True. If
272 -- the operand is not an inappropriate entity kind, return False.
274 procedure Operator_Check
(N
: Node_Id
);
275 -- Verify that an operator has received some valid interpretation. If none
276 -- was found, determine whether a use clause would make the operation
277 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
278 -- every type compatible with the operator, even if the operator for the
279 -- type is not directly visible. The routine uses this type to emit a more
280 -- informative message.
282 function Process_Implicit_Dereference_Prefix
284 P
: Node_Id
) return Entity_Id
;
285 -- Called when P is the prefix of an implicit dereference, denoting an
286 -- object E. The function returns the designated type of the prefix, taking
287 -- into account that the designated type of an anonymous access type may be
288 -- a limited view, when the non-limited view is visible.
290 -- If in semantics only mode (-gnatc or generic), the function also records
291 -- that the prefix is a reference to E, if any. Normally, such a reference
292 -- is generated only when the implicit dereference is expanded into an
293 -- explicit one, but for consistency we must generate the reference when
294 -- expansion is disabled as well.
296 procedure Remove_Abstract_Operations
(N
: Node_Id
);
297 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
298 -- operation is not a candidate interpretation.
300 function Try_Container_Indexing
303 Exprs
: List_Id
) return Boolean;
304 -- AI05-0139: Generalized indexing to support iterators over containers
306 function Try_Indexed_Call
310 Skip_First
: Boolean) return Boolean;
311 -- If a function has defaults for all its actuals, a call to it may in fact
312 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
313 -- interpretation as an indexing, prior to analysis as a call. If both are
314 -- possible, the node is overloaded with both interpretations (same symbol
315 -- but two different types). If the call is written in prefix form, the
316 -- prefix becomes the first parameter in the call, and only the remaining
317 -- actuals must be checked for the presence of defaults.
319 function Try_Indirect_Call
322 Typ
: Entity_Id
) return Boolean;
323 -- Similarly, a function F that needs no actuals can return an access to a
324 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
325 -- the call may be overloaded with both interpretations.
327 function Try_Object_Operation
329 CW_Test_Only
: Boolean := False) return Boolean;
330 -- Ada 2005 (AI-252): Support the object.operation notation. If node N
331 -- is a call in this notation, it is transformed into a normal subprogram
332 -- call where the prefix is a parameter, and True is returned. If node
333 -- N is not of this form, it is unchanged, and False is returned. If
334 -- CW_Test_Only is true then N is an N_Selected_Component node which
335 -- is part of a call to an entry or procedure of a tagged concurrent
336 -- type and this routine is invoked to search for class-wide subprograms
337 -- conflicting with the target entity.
339 procedure wpo
(T
: Entity_Id
);
340 pragma Warnings
(Off
, wpo
);
341 -- Used for debugging: obtain list of primitive operations even if
342 -- type is not frozen and dispatch table is not built yet.
344 ------------------------
345 -- Ambiguous_Operands --
346 ------------------------
348 procedure Ambiguous_Operands
(N
: Node_Id
) is
349 procedure List_Operand_Interps
(Opnd
: Node_Id
);
351 --------------------------
352 -- List_Operand_Interps --
353 --------------------------
355 procedure List_Operand_Interps
(Opnd
: Node_Id
) is
360 if Is_Overloaded
(Opnd
) then
361 if Nkind
(Opnd
) in N_Op
then
364 elsif Nkind
(Opnd
) = N_Function_Call
then
367 elsif Ada_Version
>= Ada_2012
then
373 Get_First_Interp
(Opnd
, I
, It
);
374 while Present
(It
.Nam
) loop
375 if Has_Implicit_Dereference
(It
.Typ
) then
377 ("can be interpreted as implicit dereference", Opnd
);
381 Get_Next_Interp
(I
, It
);
392 if Opnd
= Left_Opnd
(N
) then
394 ("\left operand has the following interpretations", N
);
397 ("\right operand has the following interpretations", N
);
401 List_Interps
(Nam
, Err
);
402 end List_Operand_Interps
;
404 -- Start of processing for Ambiguous_Operands
407 if Nkind
(N
) in N_Membership_Test
then
408 Error_Msg_N
("ambiguous operands for membership", N
);
410 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
) then
411 Error_Msg_N
("ambiguous operands for equality", N
);
414 Error_Msg_N
("ambiguous operands for comparison", N
);
417 if All_Errors_Mode
then
418 List_Operand_Interps
(Left_Opnd
(N
));
419 List_Operand_Interps
(Right_Opnd
(N
));
421 Error_Msg_N
("\use -gnatf switch for details", N
);
423 end Ambiguous_Operands
;
425 -----------------------
426 -- Analyze_Aggregate --
427 -----------------------
429 -- Most of the analysis of Aggregates requires that the type be known,
430 -- and is therefore put off until resolution.
432 procedure Analyze_Aggregate
(N
: Node_Id
) is
434 if No
(Etype
(N
)) then
435 Set_Etype
(N
, Any_Composite
);
437 end Analyze_Aggregate
;
439 -----------------------
440 -- Analyze_Allocator --
441 -----------------------
443 procedure Analyze_Allocator
(N
: Node_Id
) is
444 Loc
: constant Source_Ptr
:= Sloc
(N
);
445 Sav_Errs
: constant Nat
:= Serious_Errors_Detected
;
446 E
: Node_Id
:= Expression
(N
);
447 Acc_Type
: Entity_Id
;
454 Check_SPARK_05_Restriction
("allocator is not allowed", N
);
456 -- Deal with allocator restrictions
458 -- In accordance with H.4(7), the No_Allocators restriction only applies
459 -- to user-written allocators. The same consideration applies to the
460 -- No_Standard_Allocators_Before_Elaboration restriction.
462 if Comes_From_Source
(N
) then
463 Check_Restriction
(No_Allocators
, N
);
465 -- Processing for No_Standard_Allocators_After_Elaboration, loop to
466 -- look at enclosing context, checking task/main subprogram case.
470 while Present
(P
) loop
472 -- For the task case we need a handled sequence of statements,
473 -- where the occurrence of the allocator is within the statements
474 -- and the parent is a task body
476 if Nkind
(P
) = N_Handled_Sequence_Of_Statements
477 and then Is_List_Member
(C
)
478 and then List_Containing
(C
) = Statements
(P
)
480 Onode
:= Original_Node
(Parent
(P
));
482 -- Check for allocator within task body, this is a definite
483 -- violation of No_Allocators_After_Elaboration we can detect
486 if Nkind
(Onode
) = N_Task_Body
then
488 (No_Standard_Allocators_After_Elaboration
, N
);
493 -- The other case is appearance in a subprogram body. This is
494 -- a violation if this is a library level subprogram with no
495 -- parameters. Note that this is now a static error even if the
496 -- subprogram is not the main program (this is a change, in an
497 -- earlier version only the main program was affected, and the
498 -- check had to be done in the binder.
500 if Nkind
(P
) = N_Subprogram_Body
501 and then Nkind
(Parent
(P
)) = N_Compilation_Unit
502 and then No
(Parameter_Specifications
(Specification
(P
)))
505 (No_Standard_Allocators_After_Elaboration
, N
);
513 -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
514 -- any. The expected type for the name is any type. A non-overloading
515 -- rule then requires it to be of a type descended from
516 -- System.Storage_Pools.Subpools.Subpool_Handle.
518 -- This isn't exactly what the AI says, but it seems to be the right
519 -- rule. The AI should be fixed.???
522 Subpool
: constant Node_Id
:= Subpool_Handle_Name
(N
);
525 if Present
(Subpool
) then
528 if Is_Overloaded
(Subpool
) then
529 Error_Msg_N
("ambiguous subpool handle", Subpool
);
532 -- Check that Etype (Subpool) is descended from Subpool_Handle
538 -- Analyze the qualified expression or subtype indication
540 if Nkind
(E
) = N_Qualified_Expression
then
541 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
542 Set_Etype
(Acc_Type
, Acc_Type
);
543 Find_Type
(Subtype_Mark
(E
));
545 -- Analyze the qualified expression, and apply the name resolution
546 -- rule given in 4.7(3).
549 Type_Id
:= Etype
(E
);
550 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
552 -- Allocators generated by the build-in-place expansion mechanism
553 -- are explicitly marked as coming from source but do not need to be
554 -- checked for limited initialization. To exclude this case, ensure
555 -- that the parent of the allocator is a source node.
557 if Is_Limited_Type
(Type_Id
)
558 and then Comes_From_Source
(N
)
559 and then Comes_From_Source
(Parent
(N
))
560 and then not In_Instance_Body
562 if not OK_For_Limited_Init
(Type_Id
, Expression
(E
)) then
563 Error_Msg_N
("initialization not allowed for limited types", N
);
564 Explain_Limited_Type
(Type_Id
, N
);
568 -- A qualified expression requires an exact match of the type,
569 -- class-wide matching is not allowed.
571 -- if Is_Class_Wide_Type (Type_Id)
572 -- and then Base_Type
573 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
575 -- Wrong_Type (Expression (E), Type_Id);
578 -- We don't analyze the qualified expression itself because it's
579 -- part of the allocator. It is fully analyzed and resolved when
580 -- the allocator is resolved with the context type.
582 Set_Etype
(E
, Type_Id
);
584 -- Case where allocator has a subtype indication
589 Base_Typ
: Entity_Id
;
592 -- If the allocator includes a N_Subtype_Indication then a
593 -- constraint is present, otherwise the node is a subtype mark.
594 -- Introduce an explicit subtype declaration into the tree
595 -- defining some anonymous subtype and rewrite the allocator to
596 -- use this subtype rather than the subtype indication.
598 -- It is important to introduce the explicit subtype declaration
599 -- so that the bounds of the subtype indication are attached to
600 -- the tree in case the allocator is inside a generic unit.
602 if Nkind
(E
) = N_Subtype_Indication
then
604 -- A constraint is only allowed for a composite type in Ada
605 -- 95. In Ada 83, a constraint is also allowed for an
606 -- access-to-composite type, but the constraint is ignored.
608 Find_Type
(Subtype_Mark
(E
));
609 Base_Typ
:= Entity
(Subtype_Mark
(E
));
611 if Is_Elementary_Type
(Base_Typ
) then
612 if not (Ada_Version
= Ada_83
613 and then Is_Access_Type
(Base_Typ
))
615 Error_Msg_N
("constraint not allowed here", E
);
617 if Nkind
(Constraint
(E
)) =
618 N_Index_Or_Discriminant_Constraint
620 Error_Msg_N
-- CODEFIX
621 ("\if qualified expression was meant, " &
622 "use apostrophe", Constraint
(E
));
626 -- Get rid of the bogus constraint:
628 Rewrite
(E
, New_Copy_Tree
(Subtype_Mark
(E
)));
629 Analyze_Allocator
(N
);
633 if Expander_Active
then
634 Def_Id
:= Make_Temporary
(Loc
, 'S');
637 Make_Subtype_Declaration
(Loc
,
638 Defining_Identifier
=> Def_Id
,
639 Subtype_Indication
=> Relocate_Node
(E
)));
641 if Sav_Errs
/= Serious_Errors_Detected
642 and then Nkind
(Constraint
(E
)) =
643 N_Index_Or_Discriminant_Constraint
645 Error_Msg_N
-- CODEFIX
646 ("if qualified expression was meant, "
647 & "use apostrophe!", Constraint
(E
));
650 E
:= New_Occurrence_Of
(Def_Id
, Loc
);
651 Rewrite
(Expression
(N
), E
);
655 Type_Id
:= Process_Subtype
(E
, N
);
656 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
657 Set_Etype
(Acc_Type
, Acc_Type
);
658 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
659 Check_Fully_Declared
(Type_Id
, N
);
661 -- Ada 2005 (AI-231): If the designated type is itself an access
662 -- type that excludes null, its default initialization will
663 -- be a null object, and we can insert an unconditional raise
664 -- before the allocator.
666 -- Ada 2012 (AI-104): A not null indication here is altogether
669 if Can_Never_Be_Null
(Type_Id
) then
671 Not_Null_Check
: constant Node_Id
:=
672 Make_Raise_Constraint_Error
(Sloc
(E
),
673 Reason
=> CE_Null_Not_Allowed
);
676 if Expander_Active
then
677 Insert_Action
(N
, Not_Null_Check
);
678 Analyze
(Not_Null_Check
);
680 elsif Warn_On_Ada_2012_Compatibility
then
682 ("null value not allowed here in Ada 2012?y?", E
);
687 -- Check for missing initialization. Skip this check if we already
688 -- had errors on analyzing the allocator, since in that case these
689 -- are probably cascaded errors.
691 if not Is_Definite_Subtype
(Type_Id
)
692 and then Serious_Errors_Detected
= Sav_Errs
694 -- The build-in-place machinery may produce an allocator when
695 -- the designated type is indefinite but the underlying type is
696 -- not. In this case the unknown discriminants are meaningless
697 -- and should not trigger error messages. Check the parent node
698 -- because the allocator is marked as coming from source.
700 if Present
(Underlying_Type
(Type_Id
))
701 and then Is_Definite_Subtype
(Underlying_Type
(Type_Id
))
702 and then not Comes_From_Source
(Parent
(N
))
706 elsif Is_Class_Wide_Type
(Type_Id
) then
708 ("initialization required in class-wide allocation", N
);
711 if Ada_Version
< Ada_2005
712 and then Is_Limited_Type
(Type_Id
)
714 Error_Msg_N
("unconstrained allocation not allowed", N
);
716 if Is_Array_Type
(Type_Id
) then
718 ("\constraint with array bounds required", N
);
720 elsif Has_Unknown_Discriminants
(Type_Id
) then
723 else pragma Assert
(Has_Discriminants
(Type_Id
));
725 ("\constraint with discriminant values required", N
);
728 -- Limited Ada 2005 and general non-limited case
732 ("uninitialized unconstrained allocation not "
735 if Is_Array_Type
(Type_Id
) then
737 ("\qualified expression or constraint with "
738 & "array bounds required", N
);
740 elsif Has_Unknown_Discriminants
(Type_Id
) then
741 Error_Msg_N
("\qualified expression required", N
);
743 else pragma Assert
(Has_Discriminants
(Type_Id
));
745 ("\qualified expression or constraint with "
746 & "discriminant values required", N
);
754 if Is_Abstract_Type
(Type_Id
) then
755 Error_Msg_N
("cannot allocate abstract object", E
);
758 if Has_Task
(Designated_Type
(Acc_Type
)) then
759 Check_Restriction
(No_Tasking
, N
);
760 Check_Restriction
(Max_Tasks
, N
);
761 Check_Restriction
(No_Task_Allocators
, N
);
764 -- Check restriction against dynamically allocated protected objects
766 if Has_Protected
(Designated_Type
(Acc_Type
)) then
767 Check_Restriction
(No_Protected_Type_Allocators
, N
);
770 -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
771 -- type is nested, and the designated type needs finalization. The rule
772 -- is conservative in that class-wide types need finalization.
774 if Needs_Finalization
(Designated_Type
(Acc_Type
))
775 and then not Is_Library_Level_Entity
(Acc_Type
)
777 Check_Restriction
(No_Nested_Finalization
, N
);
780 -- Check that an allocator of a nested access type doesn't create a
781 -- protected object when restriction No_Local_Protected_Objects applies.
783 if Has_Protected
(Designated_Type
(Acc_Type
))
784 and then not Is_Library_Level_Entity
(Acc_Type
)
786 Check_Restriction
(No_Local_Protected_Objects
, N
);
789 -- If the No_Streams restriction is set, check that the type of the
790 -- object is not, and does not contain, any subtype derived from
791 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
792 -- Has_Stream just for efficiency reasons. There is no point in
793 -- spending time on a Has_Stream check if the restriction is not set.
795 if Restriction_Check_Required
(No_Streams
) then
796 if Has_Stream
(Designated_Type
(Acc_Type
)) then
797 Check_Restriction
(No_Streams
, N
);
801 Set_Etype
(N
, Acc_Type
);
803 if not Is_Library_Level_Entity
(Acc_Type
) then
804 Check_Restriction
(No_Local_Allocators
, N
);
807 if Serious_Errors_Detected
> Sav_Errs
then
808 Set_Error_Posted
(N
);
809 Set_Etype
(N
, Any_Type
);
811 end Analyze_Allocator
;
813 ---------------------------
814 -- Analyze_Arithmetic_Op --
815 ---------------------------
817 procedure Analyze_Arithmetic_Op
(N
: Node_Id
) is
818 L
: constant Node_Id
:= Left_Opnd
(N
);
819 R
: constant Node_Id
:= Right_Opnd
(N
);
823 Candidate_Type
:= Empty
;
824 Analyze_Expression
(L
);
825 Analyze_Expression
(R
);
827 -- If the entity is already set, the node is the instantiation of a
828 -- generic node with a non-local reference, or was manufactured by a
829 -- call to Make_Op_xxx. In either case the entity is known to be valid,
830 -- and we do not need to collect interpretations, instead we just get
831 -- the single possible interpretation.
835 if Present
(Op_Id
) then
836 if Ekind
(Op_Id
) = E_Operator
then
838 if Nkind_In
(N
, N_Op_Divide
, N_Op_Mod
, N_Op_Multiply
, N_Op_Rem
)
839 and then Treat_Fixed_As_Integer
(N
)
843 Set_Etype
(N
, Any_Type
);
844 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
848 Set_Etype
(N
, Any_Type
);
849 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
852 -- Entity is not already set, so we do need to collect interpretations
855 Set_Etype
(N
, Any_Type
);
857 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
858 while Present
(Op_Id
) loop
859 if Ekind
(Op_Id
) = E_Operator
860 and then Present
(Next_Entity
(First_Entity
(Op_Id
)))
862 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
864 -- The following may seem superfluous, because an operator cannot
865 -- be generic, but this ignores the cleverness of the author of
868 elsif Is_Overloadable
(Op_Id
) then
869 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
872 Op_Id
:= Homonym
(Op_Id
);
877 Check_Function_Writable_Actuals
(N
);
878 end Analyze_Arithmetic_Op
;
884 -- Function, procedure, and entry calls are checked here. The Name in
885 -- the call may be overloaded. The actuals have been analyzed and may
886 -- themselves be overloaded. On exit from this procedure, the node N
887 -- may have zero, one or more interpretations. In the first case an
888 -- error message is produced. In the last case, the node is flagged
889 -- as overloaded and the interpretations are collected in All_Interp.
891 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
892 -- the type-checking is similar to that of other calls.
894 procedure Analyze_Call
(N
: Node_Id
) is
895 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
900 Success
: Boolean := False;
902 Deref
: Boolean := False;
903 -- Flag indicates whether an interpretation of the prefix is a
904 -- parameterless call that returns an access_to_subprogram.
906 procedure Check_Mixed_Parameter_And_Named_Associations
;
907 -- Check that parameter and named associations are not mixed. This is
908 -- a restriction in SPARK mode.
910 procedure Check_Writable_Actuals
(N
: Node_Id
);
911 -- If the call has out or in-out parameters then mark its outermost
912 -- enclosing construct as a node on which the writable actuals check
913 -- must be performed.
915 function Name_Denotes_Function
return Boolean;
916 -- If the type of the name is an access to subprogram, this may be the
917 -- type of a name, or the return type of the function being called. If
918 -- the name is not an entity then it can denote a protected function.
919 -- Until we distinguish Etype from Return_Type, we must use this routine
920 -- to resolve the meaning of the name in the call.
922 procedure No_Interpretation
;
923 -- Output error message when no valid interpretation exists
925 --------------------------------------------------
926 -- Check_Mixed_Parameter_And_Named_Associations --
927 --------------------------------------------------
929 procedure Check_Mixed_Parameter_And_Named_Associations
is
931 Named_Seen
: Boolean;
936 Actual
:= First
(Actuals
);
937 while Present
(Actual
) loop
938 case Nkind
(Actual
) is
939 when N_Parameter_Association
=>
941 Check_SPARK_05_Restriction
942 ("named association cannot follow positional one",
953 end Check_Mixed_Parameter_And_Named_Associations
;
955 ----------------------------
956 -- Check_Writable_Actuals --
957 ----------------------------
959 -- The identification of conflicts in calls to functions with writable
960 -- actuals is performed in the analysis phase of the front end to ensure
961 -- that it reports exactly the same errors compiling with and without
962 -- expansion enabled. It is performed in two stages:
964 -- 1) When a call to a function with out-mode parameters is found,
965 -- we climb to the outermost enclosing construct that can be
966 -- evaluated in arbitrary order and we mark it with the flag
969 -- 2) When the analysis of the marked node is complete, we traverse
970 -- its decorated subtree searching for conflicts (see function
971 -- Sem_Util.Check_Function_Writable_Actuals).
973 -- The unique exception to this general rule is for aggregates, since
974 -- their analysis is performed by the front end in the resolution
975 -- phase. For aggregates we do not climb to their enclosing construct:
976 -- we restrict the analysis to the subexpressions initializing the
977 -- aggregate components.
979 -- This implies that the analysis of expressions containing aggregates
980 -- is not complete, since there may be conflicts on writable actuals
981 -- involving subexpressions of the enclosing logical or arithmetic
982 -- expressions. However, we cannot wait and perform the analysis when
983 -- the whole subtree is resolved, since the subtrees may be transformed,
984 -- thus adding extra complexity and computation cost to identify and
985 -- report exactly the same errors compiling with and without expansion
988 procedure Check_Writable_Actuals
(N
: Node_Id
) is
990 if Comes_From_Source
(N
)
991 and then Present
(Get_Subprogram_Entity
(N
))
992 and then Has_Out_Or_In_Out_Parameter
(Get_Subprogram_Entity
(N
))
994 -- For procedures and entries there is no need to climb since
995 -- we only need to check if the actuals of this call invoke
996 -- functions whose out-mode parameters overlap.
998 if Nkind
(N
) /= N_Function_Call
then
999 Set_Check_Actuals
(N
);
1001 -- For calls to functions we climb to the outermost enclosing
1002 -- construct where the out-mode actuals of this function may
1003 -- introduce conflicts.
1007 Outermost
: Node_Id
;
1011 while Present
(P
) loop
1013 -- For object declarations we can climb to the node from
1014 -- its object definition branch or from its initializing
1015 -- expression. We prefer to mark the child node as the
1016 -- outermost construct to avoid adding further complexity
1017 -- to the routine that will later take care of
1018 -- performing the writable actuals check.
1020 if Has_Arbitrary_Evaluation_Order
(Nkind
(P
))
1021 and then not Nkind_In
(P
, N_Assignment_Statement
,
1022 N_Object_Declaration
)
1027 -- Avoid climbing more than needed!
1029 exit when Stop_Subtree_Climbing
(Nkind
(P
))
1030 or else (Nkind
(P
) = N_Range
1032 Nkind_In
(Parent
(P
), N_In
, N_Not_In
));
1037 Set_Check_Actuals
(Outermost
);
1041 end Check_Writable_Actuals
;
1043 ---------------------------
1044 -- Name_Denotes_Function --
1045 ---------------------------
1047 function Name_Denotes_Function
return Boolean is
1049 if Is_Entity_Name
(Nam
) then
1050 return Ekind
(Entity
(Nam
)) = E_Function
;
1051 elsif Nkind
(Nam
) = N_Selected_Component
then
1052 return Ekind
(Entity
(Selector_Name
(Nam
))) = E_Function
;
1056 end Name_Denotes_Function
;
1058 -----------------------
1059 -- No_Interpretation --
1060 -----------------------
1062 procedure No_Interpretation
is
1063 L
: constant Boolean := Is_List_Member
(N
);
1064 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
1067 -- If the node is in a list whose parent is not an expression then it
1068 -- must be an attempted procedure call.
1070 if L
and then K
not in N_Subexpr
then
1071 if Ekind
(Entity
(Nam
)) = E_Generic_Procedure
then
1073 ("must instantiate generic procedure& before call",
1076 Error_Msg_N
("procedure or entry name expected", Nam
);
1079 -- Check for tasking cases where only an entry call will do
1082 and then Nkind_In
(K
, N_Entry_Call_Alternative
,
1083 N_Triggering_Alternative
)
1085 Error_Msg_N
("entry name expected", Nam
);
1087 -- Otherwise give general error message
1090 Error_Msg_N
("invalid prefix in call", Nam
);
1092 end No_Interpretation
;
1094 -- Start of processing for Analyze_Call
1097 if Restriction_Check_Required
(SPARK_05
) then
1098 Check_Mixed_Parameter_And_Named_Associations
;
1101 -- Initialize the type of the result of the call to the error type,
1102 -- which will be reset if the type is successfully resolved.
1104 Set_Etype
(N
, Any_Type
);
1108 if not Is_Overloaded
(Nam
) then
1110 -- Only one interpretation to check
1112 if Ekind
(Etype
(Nam
)) = E_Subprogram_Type
then
1113 Nam_Ent
:= Etype
(Nam
);
1115 -- If the prefix is an access_to_subprogram, this may be an indirect
1116 -- call. This is the case if the name in the call is not an entity
1117 -- name, or if it is a function name in the context of a procedure
1118 -- call. In this latter case, we have a call to a parameterless
1119 -- function that returns a pointer_to_procedure which is the entity
1120 -- being called. Finally, F (X) may be a call to a parameterless
1121 -- function that returns a pointer to a function with parameters.
1122 -- Note that if F returns an access-to-subprogram whose designated
1123 -- type is an array, F (X) cannot be interpreted as an indirect call
1124 -- through the result of the call to F.
1126 elsif Is_Access_Type
(Etype
(Nam
))
1127 and then Ekind
(Designated_Type
(Etype
(Nam
))) = E_Subprogram_Type
1129 (not Name_Denotes_Function
1130 or else Nkind
(N
) = N_Procedure_Call_Statement
1132 (Nkind
(Parent
(N
)) /= N_Explicit_Dereference
1133 and then Is_Entity_Name
(Nam
)
1134 and then No
(First_Formal
(Entity
(Nam
)))
1136 Is_Array_Type
(Etype
(Designated_Type
(Etype
(Nam
))))
1137 and then Present
(Actuals
)))
1139 Nam_Ent
:= Designated_Type
(Etype
(Nam
));
1140 Insert_Explicit_Dereference
(Nam
);
1142 -- Selected component case. Simple entry or protected operation,
1143 -- where the entry name is given by the selector name.
1145 elsif Nkind
(Nam
) = N_Selected_Component
then
1146 Nam_Ent
:= Entity
(Selector_Name
(Nam
));
1148 if not Ekind_In
(Nam_Ent
, E_Entry
,
1153 Error_Msg_N
("name in call is not a callable entity", Nam
);
1154 Set_Etype
(N
, Any_Type
);
1158 -- If the name is an Indexed component, it can be a call to a member
1159 -- of an entry family. The prefix must be a selected component whose
1160 -- selector is the entry. Analyze_Procedure_Call normalizes several
1161 -- kinds of call into this form.
1163 elsif Nkind
(Nam
) = N_Indexed_Component
then
1164 if Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
1165 Nam_Ent
:= Entity
(Selector_Name
(Prefix
(Nam
)));
1167 Error_Msg_N
("name in call is not a callable entity", Nam
);
1168 Set_Etype
(N
, Any_Type
);
1172 elsif not Is_Entity_Name
(Nam
) then
1173 Error_Msg_N
("name in call is not a callable entity", Nam
);
1174 Set_Etype
(N
, Any_Type
);
1178 Nam_Ent
:= Entity
(Nam
);
1180 -- If not overloadable, this may be a generalized indexing
1181 -- operation with named associations. Rewrite again as an
1182 -- indexed component and analyze as container indexing.
1184 if not Is_Overloadable
(Nam_Ent
) then
1186 (Find_Value_Of_Aspect
1187 (Etype
(Nam_Ent
), Aspect_Constant_Indexing
))
1190 Make_Indexed_Component
(Sloc
(N
),
1192 Expressions
=> Parameter_Associations
(N
)));
1194 if Try_Container_Indexing
(N
, Nam
, Expressions
(N
)) then
1208 -- Operations generated for RACW stub types are called only through
1209 -- dispatching, and can never be the static interpretation of a call.
1211 if Is_RACW_Stub_Type_Operation
(Nam_Ent
) then
1216 Analyze_One_Call
(N
, Nam_Ent
, True, Success
);
1218 -- If this is an indirect call, the return type of the access_to
1219 -- subprogram may be an incomplete type. At the point of the call,
1220 -- use the full type if available, and at the same time update the
1221 -- return type of the access_to_subprogram.
1224 and then Nkind
(Nam
) = N_Explicit_Dereference
1225 and then Ekind
(Etype
(N
)) = E_Incomplete_Type
1226 and then Present
(Full_View
(Etype
(N
)))
1228 Set_Etype
(N
, Full_View
(Etype
(N
)));
1229 Set_Etype
(Nam_Ent
, Etype
(N
));
1235 -- An overloaded selected component must denote overloaded operations
1236 -- of a concurrent type. The interpretations are attached to the
1237 -- simple name of those operations.
1239 if Nkind
(Nam
) = N_Selected_Component
then
1240 Nam
:= Selector_Name
(Nam
);
1243 Get_First_Interp
(Nam
, X
, It
);
1244 while Present
(It
.Nam
) loop
1248 -- Name may be call that returns an access to subprogram, or more
1249 -- generally an overloaded expression one of whose interpretations
1250 -- yields an access to subprogram. If the name is an entity, we do
1251 -- not dereference, because the node is a call that returns the
1252 -- access type: note difference between f(x), where the call may
1253 -- return an access subprogram type, and f(x)(y), where the type
1254 -- returned by the call to f is implicitly dereferenced to analyze
1257 if Is_Access_Type
(Nam_Ent
) then
1258 Nam_Ent
:= Designated_Type
(Nam_Ent
);
1260 elsif Is_Access_Type
(Etype
(Nam_Ent
))
1262 (not Is_Entity_Name
(Nam
)
1263 or else Nkind
(N
) = N_Procedure_Call_Statement
)
1264 and then Ekind
(Designated_Type
(Etype
(Nam_Ent
)))
1267 Nam_Ent
:= Designated_Type
(Etype
(Nam_Ent
));
1269 if Is_Entity_Name
(Nam
) then
1274 -- If the call has been rewritten from a prefixed call, the first
1275 -- parameter has been analyzed, but may need a subsequent
1276 -- dereference, so skip its analysis now.
1278 if N
/= Original_Node
(N
)
1279 and then Nkind
(Original_Node
(N
)) = Nkind
(N
)
1280 and then Nkind
(Name
(N
)) /= Nkind
(Name
(Original_Node
(N
)))
1281 and then Present
(Parameter_Associations
(N
))
1282 and then Present
(Etype
(First
(Parameter_Associations
(N
))))
1285 (N
, Nam_Ent
, False, Success
, Skip_First
=> True);
1287 Analyze_One_Call
(N
, Nam_Ent
, False, Success
);
1290 -- If the interpretation succeeds, mark the proper type of the
1291 -- prefix (any valid candidate will do). If not, remove the
1292 -- candidate interpretation. This only needs to be done for
1293 -- overloaded protected operations, for other entities disambi-
1294 -- guation is done directly in Resolve.
1298 and then Nkind
(Parent
(N
)) /= N_Explicit_Dereference
1300 Set_Entity
(Nam
, It
.Nam
);
1301 Insert_Explicit_Dereference
(Nam
);
1302 Set_Etype
(Nam
, Nam_Ent
);
1305 Set_Etype
(Nam
, It
.Typ
);
1308 elsif Nkind_In
(Name
(N
), N_Selected_Component
,
1314 Get_Next_Interp
(X
, It
);
1317 -- If the name is the result of a function call, it can only be a
1318 -- call to a function returning an access to subprogram. Insert
1319 -- explicit dereference.
1321 if Nkind
(Nam
) = N_Function_Call
then
1322 Insert_Explicit_Dereference
(Nam
);
1325 if Etype
(N
) = Any_Type
then
1327 -- None of the interpretations is compatible with the actuals
1329 Diagnose_Call
(N
, Nam
);
1331 -- Special checks for uninstantiated put routines
1333 if Nkind
(N
) = N_Procedure_Call_Statement
1334 and then Is_Entity_Name
(Nam
)
1335 and then Chars
(Nam
) = Name_Put
1336 and then List_Length
(Actuals
) = 1
1339 Arg
: constant Node_Id
:= First
(Actuals
);
1343 if Nkind
(Arg
) = N_Parameter_Association
then
1344 Typ
:= Etype
(Explicit_Actual_Parameter
(Arg
));
1349 if Is_Signed_Integer_Type
(Typ
) then
1351 ("possible missing instantiation of "
1352 & "'Text_'I'O.'Integer_'I'O!", Nam
);
1354 elsif Is_Modular_Integer_Type
(Typ
) then
1356 ("possible missing instantiation of "
1357 & "'Text_'I'O.'Modular_'I'O!", Nam
);
1359 elsif Is_Floating_Point_Type
(Typ
) then
1361 ("possible missing instantiation of "
1362 & "'Text_'I'O.'Float_'I'O!", Nam
);
1364 elsif Is_Ordinary_Fixed_Point_Type
(Typ
) then
1366 ("possible missing instantiation of "
1367 & "'Text_'I'O.'Fixed_'I'O!", Nam
);
1369 elsif Is_Decimal_Fixed_Point_Type
(Typ
) then
1371 ("possible missing instantiation of "
1372 & "'Text_'I'O.'Decimal_'I'O!", Nam
);
1374 elsif Is_Enumeration_Type
(Typ
) then
1376 ("possible missing instantiation of "
1377 & "'Text_'I'O.'Enumeration_'I'O!", Nam
);
1382 elsif not Is_Overloaded
(N
)
1383 and then Is_Entity_Name
(Nam
)
1385 -- Resolution yields a single interpretation. Verify that the
1386 -- reference has capitalization consistent with the declaration.
1388 Set_Entity_With_Checks
(Nam
, Entity
(Nam
));
1389 Generate_Reference
(Entity
(Nam
), Nam
);
1391 Set_Etype
(Nam
, Etype
(Entity
(Nam
)));
1393 Remove_Abstract_Operations
(N
);
1399 if Ada_Version
>= Ada_2012
then
1401 -- Check if the call contains a function with writable actuals
1403 Check_Writable_Actuals
(N
);
1405 -- If found and the outermost construct that can be evaluated in
1406 -- an arbitrary order is precisely this call, then check all its
1409 Check_Function_Writable_Actuals
(N
);
1413 -----------------------------
1414 -- Analyze_Case_Expression --
1415 -----------------------------
1417 procedure Analyze_Case_Expression
(N
: Node_Id
) is
1418 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
1419 -- Error routine invoked by the generic instantiation below when
1420 -- the case expression has a non static choice.
1422 package Case_Choices_Analysis
is new
1423 Generic_Analyze_Choices
1424 (Process_Associated_Node
=> No_OP
);
1425 use Case_Choices_Analysis
;
1427 package Case_Choices_Checking
is new
1428 Generic_Check_Choices
1429 (Process_Empty_Choice
=> No_OP
,
1430 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
1431 Process_Associated_Node
=> No_OP
);
1432 use Case_Choices_Checking
;
1434 -----------------------------
1435 -- Non_Static_Choice_Error --
1436 -----------------------------
1438 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
1440 Flag_Non_Static_Expr
1441 ("choice given in case expression is not static!", Choice
);
1442 end Non_Static_Choice_Error
;
1446 Expr
: constant Node_Id
:= Expression
(N
);
1448 Exp_Type
: Entity_Id
;
1449 Exp_Btype
: Entity_Id
;
1451 FirstX
: Node_Id
:= Empty
;
1452 -- First expression in the case for which there is some type information
1453 -- available, i.e. it is not Any_Type, which can happen because of some
1454 -- error, or from the use of e.g. raise Constraint_Error.
1456 Others_Present
: Boolean;
1457 -- Indicates if Others was present
1459 Wrong_Alt
: Node_Id
;
1460 -- For error reporting
1462 -- Start of processing for Analyze_Case_Expression
1465 if Comes_From_Source
(N
) then
1466 Check_Compiler_Unit
("case expression", N
);
1469 Analyze_And_Resolve
(Expr
, Any_Discrete
);
1470 Check_Unset_Reference
(Expr
);
1471 Exp_Type
:= Etype
(Expr
);
1472 Exp_Btype
:= Base_Type
(Exp_Type
);
1474 Alt
:= First
(Alternatives
(N
));
1475 while Present
(Alt
) loop
1476 Analyze
(Expression
(Alt
));
1478 if No
(FirstX
) and then Etype
(Expression
(Alt
)) /= Any_Type
then
1479 FirstX
:= Expression
(Alt
);
1485 -- Get our initial type from the first expression for which we got some
1486 -- useful type information from the expression.
1488 if not Is_Overloaded
(FirstX
) then
1489 Set_Etype
(N
, Etype
(FirstX
));
1497 Set_Etype
(N
, Any_Type
);
1499 Get_First_Interp
(FirstX
, I
, It
);
1500 while Present
(It
.Nam
) loop
1502 -- For each interpretation of the first expression, we only
1503 -- add the interpretation if every other expression in the
1504 -- case expression alternatives has a compatible type.
1506 Alt
:= Next
(First
(Alternatives
(N
)));
1507 while Present
(Alt
) loop
1508 exit when not Has_Compatible_Type
(Expression
(Alt
), It
.Typ
);
1513 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
1518 Get_Next_Interp
(I
, It
);
1523 Exp_Btype
:= Base_Type
(Exp_Type
);
1525 -- The expression must be of a discrete type which must be determinable
1526 -- independently of the context in which the expression occurs, but
1527 -- using the fact that the expression must be of a discrete type.
1528 -- Moreover, the type this expression must not be a character literal
1529 -- (which is always ambiguous).
1531 -- If error already reported by Resolve, nothing more to do
1533 if Exp_Btype
= Any_Discrete
or else Exp_Btype
= Any_Type
then
1536 -- Special casee message for character literal
1538 elsif Exp_Btype
= Any_Character
then
1540 ("character literal as case expression is ambiguous", Expr
);
1544 if Etype
(N
) = Any_Type
and then Present
(Wrong_Alt
) then
1546 ("type incompatible with that of previous alternatives",
1547 Expression
(Wrong_Alt
));
1551 -- If the case expression is a formal object of mode in out, then
1552 -- treat it as having a nonstatic subtype by forcing use of the base
1553 -- type (which has to get passed to Check_Case_Choices below). Also
1554 -- use base type when the case expression is parenthesized.
1556 if Paren_Count
(Expr
) > 0
1557 or else (Is_Entity_Name
(Expr
)
1558 and then Ekind
(Entity
(Expr
)) = E_Generic_In_Out_Parameter
)
1560 Exp_Type
:= Exp_Btype
;
1563 -- The case expression alternatives cover the range of a static subtype
1564 -- subject to aspect Static_Predicate. Do not check the choices when the
1565 -- case expression has not been fully analyzed yet because this may lead
1568 if Is_OK_Static_Subtype
(Exp_Type
)
1569 and then Has_Static_Predicate_Aspect
(Exp_Type
)
1570 and then In_Spec_Expression
1574 -- Call Analyze_Choices and Check_Choices to do the rest of the work
1577 Analyze_Choices
(Alternatives
(N
), Exp_Type
);
1578 Check_Choices
(N
, Alternatives
(N
), Exp_Type
, Others_Present
);
1581 if Exp_Type
= Universal_Integer
and then not Others_Present
then
1583 ("case on universal integer requires OTHERS choice", Expr
);
1585 end Analyze_Case_Expression
;
1587 ---------------------------
1588 -- Analyze_Comparison_Op --
1589 ---------------------------
1591 procedure Analyze_Comparison_Op
(N
: Node_Id
) is
1592 L
: constant Node_Id
:= Left_Opnd
(N
);
1593 R
: constant Node_Id
:= Right_Opnd
(N
);
1594 Op_Id
: Entity_Id
:= Entity
(N
);
1597 Set_Etype
(N
, Any_Type
);
1598 Candidate_Type
:= Empty
;
1600 Analyze_Expression
(L
);
1601 Analyze_Expression
(R
);
1603 if Present
(Op_Id
) then
1604 if Ekind
(Op_Id
) = E_Operator
then
1605 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1607 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1610 if Is_Overloaded
(L
) then
1611 Set_Etype
(L
, Intersect_Types
(L
, R
));
1615 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1616 while Present
(Op_Id
) loop
1617 if Ekind
(Op_Id
) = E_Operator
then
1618 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
1620 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1623 Op_Id
:= Homonym
(Op_Id
);
1628 Check_Function_Writable_Actuals
(N
);
1629 end Analyze_Comparison_Op
;
1631 ---------------------------
1632 -- Analyze_Concatenation --
1633 ---------------------------
1635 procedure Analyze_Concatenation
(N
: Node_Id
) is
1637 -- We wish to avoid deep recursion, because concatenations are often
1638 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1639 -- operands nonrecursively until we find something that is not a
1640 -- concatenation (A in this case), or has already been analyzed. We
1641 -- analyze that, and then walk back up the tree following Parent
1642 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1643 -- work at each level. The Parent pointers allow us to avoid recursion,
1644 -- and thus avoid running out of memory.
1650 Candidate_Type
:= Empty
;
1652 -- The following code is equivalent to:
1654 -- Set_Etype (N, Any_Type);
1655 -- Analyze_Expression (Left_Opnd (N));
1656 -- Analyze_Concatenation_Rest (N);
1658 -- where the Analyze_Expression call recurses back here if the left
1659 -- operand is a concatenation.
1661 -- Walk down left operands
1664 Set_Etype
(NN
, Any_Type
);
1665 L
:= Left_Opnd
(NN
);
1666 exit when Nkind
(L
) /= N_Op_Concat
or else Analyzed
(L
);
1670 -- Now (given the above example) NN is A&B and L is A
1672 -- First analyze L ...
1674 Analyze_Expression
(L
);
1676 -- ... then walk NN back up until we reach N (where we started), calling
1677 -- Analyze_Concatenation_Rest along the way.
1680 Analyze_Concatenation_Rest
(NN
);
1684 end Analyze_Concatenation
;
1686 --------------------------------
1687 -- Analyze_Concatenation_Rest --
1688 --------------------------------
1690 -- If the only one-dimensional array type in scope is String,
1691 -- this is the resulting type of the operation. Otherwise there
1692 -- will be a concatenation operation defined for each user-defined
1693 -- one-dimensional array.
1695 procedure Analyze_Concatenation_Rest
(N
: Node_Id
) is
1696 L
: constant Node_Id
:= Left_Opnd
(N
);
1697 R
: constant Node_Id
:= Right_Opnd
(N
);
1698 Op_Id
: Entity_Id
:= Entity
(N
);
1703 Analyze_Expression
(R
);
1705 -- If the entity is present, the node appears in an instance, and
1706 -- denotes a predefined concatenation operation. The resulting type is
1707 -- obtained from the arguments when possible. If the arguments are
1708 -- aggregates, the array type and the concatenation type must be
1711 if Present
(Op_Id
) then
1712 if Ekind
(Op_Id
) = E_Operator
then
1713 LT
:= Base_Type
(Etype
(L
));
1714 RT
:= Base_Type
(Etype
(R
));
1716 if Is_Array_Type
(LT
)
1717 and then (RT
= LT
or else RT
= Base_Type
(Component_Type
(LT
)))
1719 Add_One_Interp
(N
, Op_Id
, LT
);
1721 elsif Is_Array_Type
(RT
)
1722 and then LT
= Base_Type
(Component_Type
(RT
))
1724 Add_One_Interp
(N
, Op_Id
, RT
);
1726 -- If one operand is a string type or a user-defined array type,
1727 -- and the other is a literal, result is of the specific type.
1730 (Root_Type
(LT
) = Standard_String
1731 or else Scope
(LT
) /= Standard_Standard
)
1732 and then Etype
(R
) = Any_String
1734 Add_One_Interp
(N
, Op_Id
, LT
);
1737 (Root_Type
(RT
) = Standard_String
1738 or else Scope
(RT
) /= Standard_Standard
)
1739 and then Etype
(L
) = Any_String
1741 Add_One_Interp
(N
, Op_Id
, RT
);
1743 elsif not Is_Generic_Type
(Etype
(Op_Id
)) then
1744 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1747 -- Type and its operations must be visible
1749 Set_Entity
(N
, Empty
);
1750 Analyze_Concatenation
(N
);
1754 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1758 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Concat
);
1759 while Present
(Op_Id
) loop
1760 if Ekind
(Op_Id
) = E_Operator
then
1762 -- Do not consider operators declared in dead code, they can
1763 -- not be part of the resolution.
1765 if Is_Eliminated
(Op_Id
) then
1768 Find_Concatenation_Types
(L
, R
, Op_Id
, N
);
1772 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1775 Op_Id
:= Homonym
(Op_Id
);
1780 end Analyze_Concatenation_Rest
;
1782 -------------------------
1783 -- Analyze_Equality_Op --
1784 -------------------------
1786 procedure Analyze_Equality_Op
(N
: Node_Id
) is
1787 Loc
: constant Source_Ptr
:= Sloc
(N
);
1788 L
: constant Node_Id
:= Left_Opnd
(N
);
1789 R
: constant Node_Id
:= Right_Opnd
(N
);
1793 Set_Etype
(N
, Any_Type
);
1794 Candidate_Type
:= Empty
;
1796 Analyze_Expression
(L
);
1797 Analyze_Expression
(R
);
1799 -- If the entity is set, the node is a generic instance with a non-local
1800 -- reference to the predefined operator or to a user-defined function.
1801 -- It can also be an inequality that is expanded into the negation of a
1802 -- call to a user-defined equality operator.
1804 -- For the predefined case, the result is Boolean, regardless of the
1805 -- type of the operands. The operands may even be limited, if they are
1806 -- generic actuals. If they are overloaded, label the left argument with
1807 -- the common type that must be present, or with the type of the formal
1808 -- of the user-defined function.
1810 if Present
(Entity
(N
)) then
1811 Op_Id
:= Entity
(N
);
1813 if Ekind
(Op_Id
) = E_Operator
then
1814 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
);
1816 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1819 if Is_Overloaded
(L
) then
1820 if Ekind
(Op_Id
) = E_Operator
then
1821 Set_Etype
(L
, Intersect_Types
(L
, R
));
1823 Set_Etype
(L
, Etype
(First_Formal
(Op_Id
)));
1828 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1829 while Present
(Op_Id
) loop
1830 if Ekind
(Op_Id
) = E_Operator
then
1831 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1833 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1836 Op_Id
:= Homonym
(Op_Id
);
1840 -- If there was no match, and the operator is inequality, this may be
1841 -- a case where inequality has not been made explicit, as for tagged
1842 -- types. Analyze the node as the negation of an equality operation.
1843 -- This cannot be done earlier, because before analysis we cannot rule
1844 -- out the presence of an explicit inequality.
1846 if Etype
(N
) = Any_Type
1847 and then Nkind
(N
) = N_Op_Ne
1849 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Eq
);
1850 while Present
(Op_Id
) loop
1851 if Ekind
(Op_Id
) = E_Operator
then
1852 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1854 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1857 Op_Id
:= Homonym
(Op_Id
);
1860 if Etype
(N
) /= Any_Type
then
1861 Op_Id
:= Entity
(N
);
1867 Left_Opnd
=> Left_Opnd
(N
),
1868 Right_Opnd
=> Right_Opnd
(N
))));
1870 Set_Entity
(Right_Opnd
(N
), Op_Id
);
1876 Check_Function_Writable_Actuals
(N
);
1877 end Analyze_Equality_Op
;
1879 ----------------------------------
1880 -- Analyze_Explicit_Dereference --
1881 ----------------------------------
1883 procedure Analyze_Explicit_Dereference
(N
: Node_Id
) is
1884 Loc
: constant Source_Ptr
:= Sloc
(N
);
1885 P
: constant Node_Id
:= Prefix
(N
);
1891 function Is_Function_Type
return Boolean;
1892 -- Check whether node may be interpreted as an implicit function call
1894 ----------------------
1895 -- Is_Function_Type --
1896 ----------------------
1898 function Is_Function_Type
return Boolean is
1903 if not Is_Overloaded
(N
) then
1904 return Ekind
(Base_Type
(Etype
(N
))) = E_Subprogram_Type
1905 and then Etype
(Base_Type
(Etype
(N
))) /= Standard_Void_Type
;
1908 Get_First_Interp
(N
, I
, It
);
1909 while Present
(It
.Nam
) loop
1910 if Ekind
(Base_Type
(It
.Typ
)) /= E_Subprogram_Type
1911 or else Etype
(Base_Type
(It
.Typ
)) = Standard_Void_Type
1916 Get_Next_Interp
(I
, It
);
1921 end Is_Function_Type
;
1923 -- Start of processing for Analyze_Explicit_Dereference
1926 -- If source node, check SPARK restriction. We guard this with the
1927 -- source node check, because ???
1929 if Comes_From_Source
(N
) then
1930 Check_SPARK_05_Restriction
("explicit dereference is not allowed", N
);
1933 -- In formal verification mode, keep track of all reads and writes
1934 -- through explicit dereferences.
1936 if GNATprove_Mode
then
1937 SPARK_Specific
.Generate_Dereference
(N
);
1941 Set_Etype
(N
, Any_Type
);
1943 -- Test for remote access to subprogram type, and if so return
1944 -- after rewriting the original tree.
1946 if Remote_AST_E_Dereference
(P
) then
1950 -- Normal processing for other than remote access to subprogram type
1952 if not Is_Overloaded
(P
) then
1953 if Is_Access_Type
(Etype
(P
)) then
1955 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
1956 -- avoid other problems caused by the Private_Subtype and it is
1957 -- safe to go to the Base_Type because this is the same as
1958 -- converting the access value to its Base_Type.
1961 DT
: Entity_Id
:= Designated_Type
(Etype
(P
));
1964 if Ekind
(DT
) = E_Private_Subtype
1965 and then Is_For_Access_Subtype
(DT
)
1967 DT
:= Base_Type
(DT
);
1970 -- An explicit dereference is a legal occurrence of an
1971 -- incomplete type imported through a limited_with clause, if
1972 -- the full view is visible, or if we are within an instance
1973 -- body, where the enclosing body has a regular with_clause
1976 if From_Limited_With
(DT
)
1977 and then not From_Limited_With
(Scope
(DT
))
1979 (Is_Immediately_Visible
(Scope
(DT
))
1981 (Is_Child_Unit
(Scope
(DT
))
1982 and then Is_Visible_Lib_Unit
(Scope
(DT
)))
1983 or else In_Instance_Body
)
1985 Set_Etype
(N
, Available_View
(DT
));
1992 elsif Etype
(P
) /= Any_Type
then
1993 Error_Msg_N
("prefix of dereference must be an access type", N
);
1998 Get_First_Interp
(P
, I
, It
);
1999 while Present
(It
.Nam
) loop
2002 if Is_Access_Type
(T
) then
2003 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
2006 Get_Next_Interp
(I
, It
);
2009 -- Error if no interpretation of the prefix has an access type
2011 if Etype
(N
) = Any_Type
then
2013 ("access type required in prefix of explicit dereference", P
);
2014 Set_Etype
(N
, Any_Type
);
2020 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
2022 and then (Nkind
(Parent
(N
)) /= N_Function_Call
2023 or else N
/= Name
(Parent
(N
)))
2025 and then (Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
2026 or else N
/= Name
(Parent
(N
)))
2028 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
2029 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
2031 (Attribute_Name
(Parent
(N
)) /= Name_Address
2033 Attribute_Name
(Parent
(N
)) /= Name_Access
))
2035 -- Name is a function call with no actuals, in a context that
2036 -- requires deproceduring (including as an actual in an enclosing
2037 -- function or procedure call). There are some pathological cases
2038 -- where the prefix might include functions that return access to
2039 -- subprograms and others that return a regular type. Disambiguation
2040 -- of those has to take place in Resolve.
2043 Make_Function_Call
(Loc
,
2044 Name
=> Make_Explicit_Dereference
(Loc
, P
),
2045 Parameter_Associations
=> New_List
);
2047 -- If the prefix is overloaded, remove operations that have formals,
2048 -- we know that this is a parameterless call.
2050 if Is_Overloaded
(P
) then
2051 Get_First_Interp
(P
, I
, It
);
2052 while Present
(It
.Nam
) loop
2055 if No
(First_Formal
(Base_Type
(Designated_Type
(T
)))) then
2061 Get_Next_Interp
(I
, It
);
2068 elsif not Is_Function_Type
2069 and then Is_Overloaded
(N
)
2071 -- The prefix may include access to subprograms and other access
2072 -- types. If the context selects the interpretation that is a
2073 -- function call (not a procedure call) we cannot rewrite the node
2074 -- yet, but we include the result of the call interpretation.
2076 Get_First_Interp
(N
, I
, It
);
2077 while Present
(It
.Nam
) loop
2078 if Ekind
(Base_Type
(It
.Typ
)) = E_Subprogram_Type
2079 and then Etype
(Base_Type
(It
.Typ
)) /= Standard_Void_Type
2080 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
2082 Add_One_Interp
(N
, Etype
(It
.Typ
), Etype
(It
.Typ
));
2085 Get_Next_Interp
(I
, It
);
2089 -- A value of remote access-to-class-wide must not be dereferenced
2092 Validate_Remote_Access_To_Class_Wide_Type
(N
);
2093 end Analyze_Explicit_Dereference
;
2095 ------------------------
2096 -- Analyze_Expression --
2097 ------------------------
2099 procedure Analyze_Expression
(N
: Node_Id
) is
2102 -- If the expression is an indexed component that will be rewritten
2103 -- as a container indexing, it has already been analyzed.
2105 if Nkind
(N
) = N_Indexed_Component
2106 and then Present
(Generalized_Indexing
(N
))
2112 Check_Parameterless_Call
(N
);
2114 end Analyze_Expression
;
2116 -------------------------------------
2117 -- Analyze_Expression_With_Actions --
2118 -------------------------------------
2120 procedure Analyze_Expression_With_Actions
(N
: Node_Id
) is
2124 A
:= First
(Actions
(N
));
2125 while Present
(A
) loop
2130 Analyze_Expression
(Expression
(N
));
2131 Set_Etype
(N
, Etype
(Expression
(N
)));
2132 end Analyze_Expression_With_Actions
;
2134 ---------------------------
2135 -- Analyze_If_Expression --
2136 ---------------------------
2138 procedure Analyze_If_Expression
(N
: Node_Id
) is
2139 Condition
: constant Node_Id
:= First
(Expressions
(N
));
2140 Then_Expr
: constant Node_Id
:= Next
(Condition
);
2141 Else_Expr
: Node_Id
;
2144 -- Defend against error of missing expressions from previous error
2146 if No
(Then_Expr
) then
2147 Check_Error_Detected
;
2151 if Comes_From_Source
(N
) then
2152 Check_SPARK_05_Restriction
("if expression is not allowed", N
);
2155 Else_Expr
:= Next
(Then_Expr
);
2157 if Comes_From_Source
(N
) then
2158 Check_Compiler_Unit
("if expression", N
);
2161 -- Analyze and resolve the condition. We need to resolve this now so
2162 -- that it gets folded to True/False if possible, before we analyze
2163 -- the THEN/ELSE branches, because when analyzing these branches, we
2164 -- may call Is_Statically_Unevaluated, which expects the condition of
2165 -- an enclosing IF to have been analyze/resolved/evaluated.
2167 Analyze_Expression
(Condition
);
2168 Resolve
(Condition
, Any_Boolean
);
2170 -- Analyze THEN expression and (if present) ELSE expression. For those
2171 -- we delay resolution in the normal manner, because of overloading etc.
2173 Analyze_Expression
(Then_Expr
);
2175 if Present
(Else_Expr
) then
2176 Analyze_Expression
(Else_Expr
);
2179 -- If then expression not overloaded, then that decides the type
2181 if not Is_Overloaded
(Then_Expr
) then
2182 Set_Etype
(N
, Etype
(Then_Expr
));
2184 -- Case where then expression is overloaded
2192 Set_Etype
(N
, Any_Type
);
2194 -- Loop through intepretations of Then_Expr
2196 Get_First_Interp
(Then_Expr
, I
, It
);
2197 while Present
(It
.Nam
) loop
2199 -- Add possible intepretation of Then_Expr if no Else_Expr, or
2200 -- Else_Expr is present and has a compatible type.
2203 or else Has_Compatible_Type
(Else_Expr
, It
.Typ
)
2205 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
2208 Get_Next_Interp
(I
, It
);
2212 end Analyze_If_Expression
;
2214 ------------------------------------
2215 -- Analyze_Indexed_Component_Form --
2216 ------------------------------------
2218 procedure Analyze_Indexed_Component_Form
(N
: Node_Id
) is
2219 P
: constant Node_Id
:= Prefix
(N
);
2220 Exprs
: constant List_Id
:= Expressions
(N
);
2226 procedure Process_Function_Call
;
2227 -- Prefix in indexed component form is an overloadable entity, so the
2228 -- node is a function call. Reformat it as such.
2230 procedure Process_Indexed_Component
;
2231 -- Prefix in indexed component form is actually an indexed component.
2232 -- This routine processes it, knowing that the prefix is already
2235 procedure Process_Indexed_Component_Or_Slice
;
2236 -- An indexed component with a single index may designate a slice if
2237 -- the index is a subtype mark. This routine disambiguates these two
2238 -- cases by resolving the prefix to see if it is a subtype mark.
2240 procedure Process_Overloaded_Indexed_Component
;
2241 -- If the prefix of an indexed component is overloaded, the proper
2242 -- interpretation is selected by the index types and the context.
2244 ---------------------------
2245 -- Process_Function_Call --
2246 ---------------------------
2248 procedure Process_Function_Call
is
2249 Loc
: constant Source_Ptr
:= Sloc
(N
);
2253 Change_Node
(N
, N_Function_Call
);
2255 Set_Parameter_Associations
(N
, Exprs
);
2257 -- Analyze actuals prior to analyzing the call itself
2259 Actual
:= First
(Parameter_Associations
(N
));
2260 while Present
(Actual
) loop
2262 Check_Parameterless_Call
(Actual
);
2264 -- Move to next actual. Note that we use Next, not Next_Actual
2265 -- here. The reason for this is a bit subtle. If a function call
2266 -- includes named associations, the parser recognizes the node
2267 -- as a call, and it is analyzed as such. If all associations are
2268 -- positional, the parser builds an indexed_component node, and
2269 -- it is only after analysis of the prefix that the construct
2270 -- is recognized as a call, in which case Process_Function_Call
2271 -- rewrites the node and analyzes the actuals. If the list of
2272 -- actuals is malformed, the parser may leave the node as an
2273 -- indexed component (despite the presence of named associations).
2274 -- The iterator Next_Actual is equivalent to Next if the list is
2275 -- positional, but follows the normalized chain of actuals when
2276 -- named associations are present. In this case normalization has
2277 -- not taken place, and actuals remain unanalyzed, which leads to
2278 -- subsequent crashes or loops if there is an attempt to continue
2279 -- analysis of the program.
2281 -- IF there is a single actual and it is a type name, the node
2282 -- can only be interpreted as a slice of a parameterless call.
2283 -- Rebuild the node as such and analyze.
2285 if No
(Next
(Actual
))
2286 and then Is_Entity_Name
(Actual
)
2287 and then Is_Type
(Entity
(Actual
))
2288 and then Is_Discrete_Type
(Entity
(Actual
))
2294 New_Occurrence_Of
(Entity
(Actual
), Loc
)));
2304 end Process_Function_Call
;
2306 -------------------------------
2307 -- Process_Indexed_Component --
2308 -------------------------------
2310 procedure Process_Indexed_Component
is
2312 Array_Type
: Entity_Id
;
2314 Pent
: Entity_Id
:= Empty
;
2317 Exp
:= First
(Exprs
);
2319 if Is_Overloaded
(P
) then
2320 Process_Overloaded_Indexed_Component
;
2323 Array_Type
:= Etype
(P
);
2325 if Is_Entity_Name
(P
) then
2327 elsif Nkind
(P
) = N_Selected_Component
2328 and then Is_Entity_Name
(Selector_Name
(P
))
2330 Pent
:= Entity
(Selector_Name
(P
));
2333 -- Prefix must be appropriate for an array type, taking into
2334 -- account a possible implicit dereference.
2336 if Is_Access_Type
(Array_Type
) then
2338 (Warn_On_Dereference
, "?d?implicit dereference", N
);
2339 Array_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, P
);
2342 if Is_Array_Type
(Array_Type
) then
2345 elsif Present
(Pent
) and then Ekind
(Pent
) = E_Entry_Family
then
2347 Set_Etype
(N
, Any_Type
);
2349 if not Has_Compatible_Type
2350 (Exp
, Entry_Index_Type
(Pent
))
2352 Error_Msg_N
("invalid index type in entry name", N
);
2354 elsif Present
(Next
(Exp
)) then
2355 Error_Msg_N
("too many subscripts in entry reference", N
);
2358 Set_Etype
(N
, Etype
(P
));
2363 elsif Is_Record_Type
(Array_Type
)
2364 and then Remote_AST_I_Dereference
(P
)
2368 elsif Try_Container_Indexing
(N
, P
, Exprs
) then
2371 elsif Array_Type
= Any_Type
then
2372 Set_Etype
(N
, Any_Type
);
2374 -- In most cases the analysis of the prefix will have emitted
2375 -- an error already, but if the prefix may be interpreted as a
2376 -- call in prefixed notation, the report is left to the caller.
2377 -- To prevent cascaded errors, report only if no previous ones.
2379 if Serious_Errors_Detected
= 0 then
2380 Error_Msg_N
("invalid prefix in indexed component", P
);
2382 if Nkind
(P
) = N_Expanded_Name
then
2383 Error_Msg_NE
("\& is not visible", P
, Selector_Name
(P
));
2389 -- Here we definitely have a bad indexing
2392 if Nkind
(Parent
(N
)) = N_Requeue_Statement
2393 and then Present
(Pent
) and then Ekind
(Pent
) = E_Entry
2396 ("REQUEUE does not permit parameters", First
(Exprs
));
2398 elsif Is_Entity_Name
(P
)
2399 and then Etype
(P
) = Standard_Void_Type
2401 Error_Msg_NE
("incorrect use of &", P
, Entity
(P
));
2404 Error_Msg_N
("array type required in indexed component", P
);
2407 Set_Etype
(N
, Any_Type
);
2411 Index
:= First_Index
(Array_Type
);
2412 while Present
(Index
) and then Present
(Exp
) loop
2413 if not Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2414 Wrong_Type
(Exp
, Etype
(Index
));
2415 Set_Etype
(N
, Any_Type
);
2423 Set_Etype
(N
, Component_Type
(Array_Type
));
2424 Check_Implicit_Dereference
(N
, Etype
(N
));
2426 if Present
(Index
) then
2428 ("too few subscripts in array reference", First
(Exprs
));
2430 elsif Present
(Exp
) then
2431 Error_Msg_N
("too many subscripts in array reference", Exp
);
2434 end Process_Indexed_Component
;
2436 ----------------------------------------
2437 -- Process_Indexed_Component_Or_Slice --
2438 ----------------------------------------
2440 procedure Process_Indexed_Component_Or_Slice
is
2442 Exp
:= First
(Exprs
);
2443 while Present
(Exp
) loop
2444 Analyze_Expression
(Exp
);
2448 Exp
:= First
(Exprs
);
2450 -- If one index is present, and it is a subtype name, then the node
2451 -- denotes a slice (note that the case of an explicit range for a
2452 -- slice was already built as an N_Slice node in the first place,
2453 -- so that case is not handled here).
2455 -- We use a replace rather than a rewrite here because this is one
2456 -- of the cases in which the tree built by the parser is plain wrong.
2459 and then Is_Entity_Name
(Exp
)
2460 and then Is_Type
(Entity
(Exp
))
2463 Make_Slice
(Sloc
(N
),
2465 Discrete_Range
=> New_Copy
(Exp
)));
2468 -- Otherwise (more than one index present, or single index is not
2469 -- a subtype name), then we have the indexed component case.
2472 Process_Indexed_Component
;
2474 end Process_Indexed_Component_Or_Slice
;
2476 ------------------------------------------
2477 -- Process_Overloaded_Indexed_Component --
2478 ------------------------------------------
2480 procedure Process_Overloaded_Indexed_Component
is
2489 Set_Etype
(N
, Any_Type
);
2491 Get_First_Interp
(P
, I
, It
);
2492 while Present
(It
.Nam
) loop
2495 if Is_Access_Type
(Typ
) then
2496 Typ
:= Designated_Type
(Typ
);
2498 (Warn_On_Dereference
, "?d?implicit dereference", N
);
2501 if Is_Array_Type
(Typ
) then
2503 -- Got a candidate: verify that index types are compatible
2505 Index
:= First_Index
(Typ
);
2507 Exp
:= First
(Exprs
);
2508 while Present
(Index
) and then Present
(Exp
) loop
2509 if Has_Compatible_Type
(Exp
, Etype
(Index
)) then
2521 if Found
and then No
(Index
) and then No
(Exp
) then
2523 CT
: constant Entity_Id
:=
2524 Base_Type
(Component_Type
(Typ
));
2526 Add_One_Interp
(N
, CT
, CT
);
2527 Check_Implicit_Dereference
(N
, CT
);
2531 elsif Try_Container_Indexing
(N
, P
, Exprs
) then
2536 Get_Next_Interp
(I
, It
);
2539 if Etype
(N
) = Any_Type
then
2540 Error_Msg_N
("no legal interpretation for indexed component", N
);
2541 Set_Is_Overloaded
(N
, False);
2545 end Process_Overloaded_Indexed_Component
;
2547 -- Start of processing for Analyze_Indexed_Component_Form
2550 -- Get name of array, function or type
2554 -- If P is an explicit dereference whose prefix is of a remote access-
2555 -- to-subprogram type, then N has already been rewritten as a subprogram
2556 -- call and analyzed.
2558 if Nkind
(N
) in N_Subprogram_Call
then
2561 -- When the prefix is attribute 'Loop_Entry and the sole expression of
2562 -- the indexed component denotes a loop name, the indexed form is turned
2563 -- into an attribute reference.
2565 elsif Nkind
(N
) = N_Attribute_Reference
2566 and then Attribute_Name
(N
) = Name_Loop_Entry
2571 pragma Assert
(Nkind
(N
) = N_Indexed_Component
);
2573 P_T
:= Base_Type
(Etype
(P
));
2575 if Is_Entity_Name
(P
) and then Present
(Entity
(P
)) then
2578 if Is_Type
(U_N
) then
2580 -- Reformat node as a type conversion
2582 E
:= Remove_Head
(Exprs
);
2584 if Present
(First
(Exprs
)) then
2586 ("argument of type conversion must be single expression", N
);
2589 Change_Node
(N
, N_Type_Conversion
);
2590 Set_Subtype_Mark
(N
, P
);
2592 Set_Expression
(N
, E
);
2594 -- After changing the node, call for the specific Analysis
2595 -- routine directly, to avoid a double call to the expander.
2597 Analyze_Type_Conversion
(N
);
2601 if Is_Overloadable
(U_N
) then
2602 Process_Function_Call
;
2604 elsif Ekind
(Etype
(P
)) = E_Subprogram_Type
2605 or else (Is_Access_Type
(Etype
(P
))
2607 Ekind
(Designated_Type
(Etype
(P
))) =
2610 -- Call to access_to-subprogram with possible implicit dereference
2612 Process_Function_Call
;
2614 elsif Is_Generic_Subprogram
(U_N
) then
2616 -- A common beginner's (or C++ templates fan) error
2618 Error_Msg_N
("generic subprogram cannot be called", N
);
2619 Set_Etype
(N
, Any_Type
);
2623 Process_Indexed_Component_Or_Slice
;
2626 -- If not an entity name, prefix is an expression that may denote
2627 -- an array or an access-to-subprogram.
2630 if Ekind
(P_T
) = E_Subprogram_Type
2631 or else (Is_Access_Type
(P_T
)
2633 Ekind
(Designated_Type
(P_T
)) = E_Subprogram_Type
)
2635 Process_Function_Call
;
2637 elsif Nkind
(P
) = N_Selected_Component
2638 and then Present
(Entity
(Selector_Name
(P
)))
2639 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
2641 Process_Function_Call
;
2643 -- In ASIS mode within a generic, a prefixed call is analyzed and
2644 -- partially rewritten but the original indexed component has not
2645 -- yet been rewritten as a call. Perform the replacement now.
2647 elsif Nkind
(P
) = N_Selected_Component
2648 and then Nkind
(Parent
(P
)) = N_Function_Call
2651 Rewrite
(N
, Parent
(P
));
2655 -- Indexed component, slice, or a call to a member of a family
2656 -- entry, which will be converted to an entry call later.
2658 Process_Indexed_Component_Or_Slice
;
2662 Analyze_Dimension
(N
);
2663 end Analyze_Indexed_Component_Form
;
2665 ------------------------
2666 -- Analyze_Logical_Op --
2667 ------------------------
2669 procedure Analyze_Logical_Op
(N
: Node_Id
) is
2670 L
: constant Node_Id
:= Left_Opnd
(N
);
2671 R
: constant Node_Id
:= Right_Opnd
(N
);
2672 Op_Id
: Entity_Id
:= Entity
(N
);
2675 Set_Etype
(N
, Any_Type
);
2676 Candidate_Type
:= Empty
;
2678 Analyze_Expression
(L
);
2679 Analyze_Expression
(R
);
2681 if Present
(Op_Id
) then
2683 if Ekind
(Op_Id
) = E_Operator
then
2684 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
2686 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2690 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
2691 while Present
(Op_Id
) loop
2692 if Ekind
(Op_Id
) = E_Operator
then
2693 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
2695 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
2698 Op_Id
:= Homonym
(Op_Id
);
2703 Check_Function_Writable_Actuals
(N
);
2704 end Analyze_Logical_Op
;
2706 ---------------------------
2707 -- Analyze_Membership_Op --
2708 ---------------------------
2710 procedure Analyze_Membership_Op
(N
: Node_Id
) is
2711 Loc
: constant Source_Ptr
:= Sloc
(N
);
2712 L
: constant Node_Id
:= Left_Opnd
(N
);
2713 R
: constant Node_Id
:= Right_Opnd
(N
);
2715 Index
: Interp_Index
;
2717 Found
: Boolean := False;
2721 procedure Try_One_Interp
(T1
: Entity_Id
);
2722 -- Routine to try one proposed interpretation. Note that the context
2723 -- of the operation plays no role in resolving the arguments, so that
2724 -- if there is more than one interpretation of the operands that is
2725 -- compatible with a membership test, the operation is ambiguous.
2727 --------------------
2728 -- Try_One_Interp --
2729 --------------------
2731 procedure Try_One_Interp
(T1
: Entity_Id
) is
2733 if Has_Compatible_Type
(R
, T1
) then
2735 and then Base_Type
(T1
) /= Base_Type
(T_F
)
2737 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
2739 if It
= No_Interp
then
2740 Ambiguous_Operands
(N
);
2741 Set_Etype
(L
, Any_Type
);
2758 procedure Analyze_Set_Membership
;
2759 -- If a set of alternatives is present, analyze each and find the
2760 -- common type to which they must all resolve.
2762 ----------------------------
2763 -- Analyze_Set_Membership --
2764 ----------------------------
2766 procedure Analyze_Set_Membership
is
2768 Index
: Interp_Index
;
2770 Candidate_Interps
: Node_Id
;
2771 Common_Type
: Entity_Id
:= Empty
;
2774 if Comes_From_Source
(N
) then
2775 Check_Compiler_Unit
("set membership", N
);
2779 Candidate_Interps
:= L
;
2781 if not Is_Overloaded
(L
) then
2782 Common_Type
:= Etype
(L
);
2784 Alt
:= First
(Alternatives
(N
));
2785 while Present
(Alt
) loop
2788 if not Has_Compatible_Type
(Alt
, Common_Type
) then
2789 Wrong_Type
(Alt
, Common_Type
);
2796 Alt
:= First
(Alternatives
(N
));
2797 while Present
(Alt
) loop
2799 if not Is_Overloaded
(Alt
) then
2800 Common_Type
:= Etype
(Alt
);
2803 Get_First_Interp
(Alt
, Index
, It
);
2804 while Present
(It
.Typ
) loop
2806 Has_Compatible_Type
(Candidate_Interps
, It
.Typ
)
2808 Remove_Interp
(Index
);
2811 Get_Next_Interp
(Index
, It
);
2814 Get_First_Interp
(Alt
, Index
, It
);
2817 Error_Msg_N
("alternative has no legal type", Alt
);
2821 -- If alternative is not overloaded, we have a unique type
2824 Set_Etype
(Alt
, It
.Typ
);
2825 Get_Next_Interp
(Index
, It
);
2828 Set_Is_Overloaded
(Alt
, False);
2829 Common_Type
:= Etype
(Alt
);
2832 Candidate_Interps
:= Alt
;
2839 Set_Etype
(N
, Standard_Boolean
);
2841 if Present
(Common_Type
) then
2842 Set_Etype
(L
, Common_Type
);
2844 -- The left operand may still be overloaded, to be resolved using
2848 Error_Msg_N
("cannot resolve membership operation", N
);
2850 end Analyze_Set_Membership
;
2852 -- Start of processing for Analyze_Membership_Op
2855 Analyze_Expression
(L
);
2857 if No
(R
) and then Ada_Version
>= Ada_2012
then
2858 Analyze_Set_Membership
;
2859 Check_Function_Writable_Actuals
(N
);
2864 if Nkind
(R
) = N_Range
2865 or else (Nkind
(R
) = N_Attribute_Reference
2866 and then Attribute_Name
(R
) = Name_Range
)
2870 if not Is_Overloaded
(L
) then
2871 Try_One_Interp
(Etype
(L
));
2874 Get_First_Interp
(L
, Index
, It
);
2875 while Present
(It
.Typ
) loop
2876 Try_One_Interp
(It
.Typ
);
2877 Get_Next_Interp
(Index
, It
);
2881 -- If not a range, it can be a subtype mark, or else it is a degenerate
2882 -- membership test with a singleton value, i.e. a test for equality,
2883 -- if the types are compatible.
2888 if Is_Entity_Name
(R
)
2889 and then Is_Type
(Entity
(R
))
2892 Check_Fully_Declared
(Entity
(R
), R
);
2894 elsif Ada_Version
>= Ada_2012
2895 and then Has_Compatible_Type
(R
, Etype
(L
))
2897 if Nkind
(N
) = N_In
then
2913 -- In all versions of the language, if we reach this point there
2914 -- is a previous error that will be diagnosed below.
2920 -- Compatibility between expression and subtype mark or range is
2921 -- checked during resolution. The result of the operation is Boolean
2924 Set_Etype
(N
, Standard_Boolean
);
2926 if Comes_From_Source
(N
)
2927 and then Present
(Right_Opnd
(N
))
2928 and then Is_CPP_Class
(Etype
(Etype
(Right_Opnd
(N
))))
2930 Error_Msg_N
("membership test not applicable to cpp-class types", N
);
2933 Check_Function_Writable_Actuals
(N
);
2934 end Analyze_Membership_Op
;
2940 procedure Analyze_Mod
(N
: Node_Id
) is
2942 -- A special warning check, if we have an expression of the form:
2943 -- expr mod 2 * literal
2944 -- where literal is 64 or less, then probably what was meant was
2945 -- expr mod 2 ** literal
2946 -- so issue an appropriate warning.
2948 if Warn_On_Suspicious_Modulus_Value
2949 and then Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
2950 and then Intval
(Right_Opnd
(N
)) = Uint_2
2951 and then Nkind
(Parent
(N
)) = N_Op_Multiply
2952 and then Nkind
(Right_Opnd
(Parent
(N
))) = N_Integer_Literal
2953 and then Intval
(Right_Opnd
(Parent
(N
))) <= Uint_64
2956 ("suspicious MOD value, was '*'* intended'??M?", Parent
(N
));
2959 -- Remaining processing is same as for other arithmetic operators
2961 Analyze_Arithmetic_Op
(N
);
2964 ----------------------
2965 -- Analyze_Negation --
2966 ----------------------
2968 procedure Analyze_Negation
(N
: Node_Id
) is
2969 R
: constant Node_Id
:= Right_Opnd
(N
);
2970 Op_Id
: Entity_Id
:= Entity
(N
);
2973 Set_Etype
(N
, Any_Type
);
2974 Candidate_Type
:= Empty
;
2976 Analyze_Expression
(R
);
2978 if Present
(Op_Id
) then
2979 if Ekind
(Op_Id
) = E_Operator
then
2980 Find_Negation_Types
(R
, Op_Id
, N
);
2982 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2986 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
2987 while Present
(Op_Id
) loop
2988 if Ekind
(Op_Id
) = E_Operator
then
2989 Find_Negation_Types
(R
, Op_Id
, N
);
2991 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
2994 Op_Id
:= Homonym
(Op_Id
);
2999 end Analyze_Negation
;
3005 procedure Analyze_Null
(N
: Node_Id
) is
3007 Check_SPARK_05_Restriction
("null is not allowed", N
);
3009 Set_Etype
(N
, Any_Access
);
3012 ----------------------
3013 -- Analyze_One_Call --
3014 ----------------------
3016 procedure Analyze_One_Call
3020 Success
: out Boolean;
3021 Skip_First
: Boolean := False)
3023 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
3024 Prev_T
: constant Entity_Id
:= Etype
(N
);
3026 Must_Skip
: constant Boolean := Skip_First
3027 or else Nkind
(Original_Node
(N
)) = N_Selected_Component
3029 (Nkind
(Original_Node
(N
)) = N_Indexed_Component
3030 and then Nkind
(Prefix
(Original_Node
(N
)))
3031 = N_Selected_Component
);
3032 -- The first formal must be omitted from the match when trying to find
3033 -- a primitive operation that is a possible interpretation, and also
3034 -- after the call has been rewritten, because the corresponding actual
3035 -- is already known to be compatible, and because this may be an
3036 -- indexing of a call with default parameters.
3040 Is_Indexed
: Boolean := False;
3041 Is_Indirect
: Boolean := False;
3042 Subp_Type
: constant Entity_Id
:= Etype
(Nam
);
3045 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean;
3046 -- There may be a user-defined operator that hides the current
3047 -- interpretation. We must check for this independently of the
3048 -- analysis of the call with the user-defined operation, because
3049 -- the parameter names may be wrong and yet the hiding takes place.
3050 -- This fixes a problem with ACATS test B34014O.
3052 -- When the type Address is a visible integer type, and the DEC
3053 -- system extension is visible, the predefined operator may be
3054 -- hidden as well, by one of the address operations in auxdec.
3055 -- Finally, The abstract operations on address do not hide the
3056 -- predefined operator (this is the purpose of making them abstract).
3058 procedure Indicate_Name_And_Type
;
3059 -- If candidate interpretation matches, indicate name and type of
3060 -- result on call node.
3062 ----------------------------
3063 -- Indicate_Name_And_Type --
3064 ----------------------------
3066 procedure Indicate_Name_And_Type
is
3068 Add_One_Interp
(N
, Nam
, Etype
(Nam
));
3069 Check_Implicit_Dereference
(N
, Etype
(Nam
));
3072 -- If the prefix of the call is a name, indicate the entity
3073 -- being called. If it is not a name, it is an expression that
3074 -- denotes an access to subprogram or else an entry or family. In
3075 -- the latter case, the name is a selected component, and the entity
3076 -- being called is noted on the selector.
3078 if not Is_Type
(Nam
) then
3079 if Is_Entity_Name
(Name
(N
)) then
3080 Set_Entity
(Name
(N
), Nam
);
3082 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
3083 Set_Entity
(Selector_Name
(Name
(N
)), Nam
);
3087 if Debug_Flag_E
and not Report
then
3088 Write_Str
(" Overloaded call ");
3089 Write_Int
(Int
(N
));
3090 Write_Str
(" compatible with ");
3091 Write_Int
(Int
(Nam
));
3094 end Indicate_Name_And_Type
;
3096 ------------------------
3097 -- Operator_Hidden_By --
3098 ------------------------
3100 function Operator_Hidden_By
(Fun
: Entity_Id
) return Boolean is
3101 Act1
: constant Node_Id
:= First_Actual
(N
);
3102 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
3103 Form1
: constant Entity_Id
:= First_Formal
(Fun
);
3104 Form2
: constant Entity_Id
:= Next_Formal
(Form1
);
3107 if Ekind
(Fun
) /= E_Function
or else Is_Abstract_Subprogram
(Fun
) then
3110 elsif not Has_Compatible_Type
(Act1
, Etype
(Form1
)) then
3113 elsif Present
(Form2
) then
3115 or else not Has_Compatible_Type
(Act2
, Etype
(Form2
))
3120 elsif Present
(Act2
) then
3124 -- Now we know that the arity of the operator matches the function,
3125 -- and the function call is a valid interpretation. The function
3126 -- hides the operator if it has the right signature, or if one of
3127 -- its operands is a non-abstract operation on Address when this is
3128 -- a visible integer type.
3130 return Hides_Op
(Fun
, Nam
)
3131 or else Is_Descendent_Of_Address
(Etype
(Form1
))
3134 and then Is_Descendent_Of_Address
(Etype
(Form2
)));
3135 end Operator_Hidden_By
;
3137 -- Start of processing for Analyze_One_Call
3142 -- If the subprogram has no formals or if all the formals have defaults,
3143 -- and the return type is an array type, the node may denote an indexing
3144 -- of the result of a parameterless call. In Ada 2005, the subprogram
3145 -- may have one non-defaulted formal, and the call may have been written
3146 -- in prefix notation, so that the rebuilt parameter list has more than
3149 if not Is_Overloadable
(Nam
)
3150 and then Ekind
(Nam
) /= E_Subprogram_Type
3151 and then Ekind
(Nam
) /= E_Entry_Family
3156 -- An indexing requires at least one actual. The name of the call cannot
3157 -- be an implicit indirect call, so it cannot be a generated explicit
3160 if not Is_Empty_List
(Actuals
)
3162 (Needs_No_Actuals
(Nam
)
3164 (Needs_One_Actual
(Nam
)
3165 and then Present
(Next_Actual
(First
(Actuals
)))))
3167 if Is_Array_Type
(Subp_Type
)
3169 (Nkind
(Name
(N
)) /= N_Explicit_Dereference
3170 or else Comes_From_Source
(Name
(N
)))
3172 Is_Indexed
:= Try_Indexed_Call
(N
, Nam
, Subp_Type
, Must_Skip
);
3174 elsif Is_Access_Type
(Subp_Type
)
3175 and then Is_Array_Type
(Designated_Type
(Subp_Type
))
3179 (N
, Nam
, Designated_Type
(Subp_Type
), Must_Skip
);
3181 -- The prefix can also be a parameterless function that returns an
3182 -- access to subprogram, in which case this is an indirect call.
3183 -- If this succeeds, an explicit dereference is added later on,
3184 -- in Analyze_Call or Resolve_Call.
3186 elsif Is_Access_Type
(Subp_Type
)
3187 and then Ekind
(Designated_Type
(Subp_Type
)) = E_Subprogram_Type
3189 Is_Indirect
:= Try_Indirect_Call
(N
, Nam
, Subp_Type
);
3194 -- If the call has been transformed into a slice, it is of the form
3195 -- F (Subtype) where F is parameterless. The node has been rewritten in
3196 -- Try_Indexed_Call and there is nothing else to do.
3199 and then Nkind
(N
) = N_Slice
3205 (N
, Nam
, (Report
and not Is_Indexed
and not Is_Indirect
), Norm_OK
);
3209 -- If an indirect call is a possible interpretation, indicate
3210 -- success to the caller. This may be an indexing of an explicit
3211 -- dereference of a call that returns an access type (see above).
3215 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
3216 and then Comes_From_Source
(Name
(N
)))
3221 -- Mismatch in number or names of parameters
3223 elsif Debug_Flag_E
then
3224 Write_Str
(" normalization fails in call ");
3225 Write_Int
(Int
(N
));
3226 Write_Str
(" with subprogram ");
3227 Write_Int
(Int
(Nam
));
3231 -- If the context expects a function call, discard any interpretation
3232 -- that is a procedure. If the node is not overloaded, leave as is for
3233 -- better error reporting when type mismatch is found.
3235 elsif Nkind
(N
) = N_Function_Call
3236 and then Is_Overloaded
(Name
(N
))
3237 and then Ekind
(Nam
) = E_Procedure
3241 -- Ditto for function calls in a procedure context
3243 elsif Nkind
(N
) = N_Procedure_Call_Statement
3244 and then Is_Overloaded
(Name
(N
))
3245 and then Etype
(Nam
) /= Standard_Void_Type
3249 elsif No
(Actuals
) then
3251 -- If Normalize succeeds, then there are default parameters for
3254 Indicate_Name_And_Type
;
3256 elsif Ekind
(Nam
) = E_Operator
then
3257 if Nkind
(N
) = N_Procedure_Call_Statement
then
3261 -- This can occur when the prefix of the call is an operator
3262 -- name or an expanded name whose selector is an operator name.
3264 Analyze_Operator_Call
(N
, Nam
);
3266 if Etype
(N
) /= Prev_T
then
3268 -- Check that operator is not hidden by a function interpretation
3270 if Is_Overloaded
(Name
(N
)) then
3276 Get_First_Interp
(Name
(N
), I
, It
);
3277 while Present
(It
.Nam
) loop
3278 if Operator_Hidden_By
(It
.Nam
) then
3279 Set_Etype
(N
, Prev_T
);
3283 Get_Next_Interp
(I
, It
);
3288 -- If operator matches formals, record its name on the call.
3289 -- If the operator is overloaded, Resolve will select the
3290 -- correct one from the list of interpretations. The call
3291 -- node itself carries the first candidate.
3293 Set_Entity
(Name
(N
), Nam
);
3296 elsif Report
and then Etype
(N
) = Any_Type
then
3297 Error_Msg_N
("incompatible arguments for operator", N
);
3301 -- Normalize_Actuals has chained the named associations in the
3302 -- correct order of the formals.
3304 Actual
:= First_Actual
(N
);
3305 Formal
:= First_Formal
(Nam
);
3307 -- If we are analyzing a call rewritten from object notation, skip
3308 -- first actual, which may be rewritten later as an explicit
3312 Next_Actual
(Actual
);
3313 Next_Formal
(Formal
);
3316 while Present
(Actual
) and then Present
(Formal
) loop
3317 if Nkind
(Parent
(Actual
)) /= N_Parameter_Association
3318 or else Chars
(Selector_Name
(Parent
(Actual
))) = Chars
(Formal
)
3320 -- The actual can be compatible with the formal, but we must
3321 -- also check that the context is not an address type that is
3322 -- visibly an integer type. In this case the use of literals is
3323 -- illegal, except in the body of descendents of system, where
3324 -- arithmetic operations on address are of course used.
3326 if Has_Compatible_Type
(Actual
, Etype
(Formal
))
3328 (Etype
(Actual
) /= Universal_Integer
3329 or else not Is_Descendent_Of_Address
(Etype
(Formal
))
3331 Is_Predefined_File_Name
3332 (Unit_File_Name
(Get_Source_Unit
(N
))))
3334 Next_Actual
(Actual
);
3335 Next_Formal
(Formal
);
3337 -- In Allow_Integer_Address mode, we allow an actual integer to
3338 -- match a formal address type and vice versa. We only do this
3339 -- if we are certain that an error will otherwise be issued
3341 elsif Address_Integer_Convert_OK
3342 (Etype
(Actual
), Etype
(Formal
))
3343 and then (Report
and not Is_Indexed
and not Is_Indirect
)
3345 -- Handle this case by introducing an unchecked conversion
3348 Unchecked_Convert_To
(Etype
(Formal
),
3349 Relocate_Node
(Actual
)));
3350 Analyze_And_Resolve
(Actual
, Etype
(Formal
));
3351 Next_Actual
(Actual
);
3352 Next_Formal
(Formal
);
3354 -- For an Ada 2012 predicate or invariant, a call may mention
3355 -- an incomplete type, while resolution of the corresponding
3356 -- predicate function may see the full view, as a consequence
3357 -- of the delayed resolution of the corresponding expressions.
3359 elsif Ekind
(Etype
(Formal
)) = E_Incomplete_Type
3360 and then Full_View
(Etype
(Formal
)) = Etype
(Actual
)
3362 Set_Etype
(Formal
, Etype
(Actual
));
3363 Next_Actual
(Actual
);
3364 Next_Formal
(Formal
);
3367 if Debug_Flag_E
then
3368 Write_Str
(" type checking fails in call ");
3369 Write_Int
(Int
(N
));
3370 Write_Str
(" with formal ");
3371 Write_Int
(Int
(Formal
));
3372 Write_Str
(" in subprogram ");
3373 Write_Int
(Int
(Nam
));
3377 -- Comment needed on the following test???
3379 if Report
and not Is_Indexed
and not Is_Indirect
then
3381 -- Ada 2005 (AI-251): Complete the error notification
3382 -- to help new Ada 2005 users.
3384 if Is_Class_Wide_Type
(Etype
(Formal
))
3385 and then Is_Interface
(Etype
(Etype
(Formal
)))
3386 and then not Interface_Present_In_Ancestor
3387 (Typ
=> Etype
(Actual
),
3388 Iface
=> Etype
(Etype
(Formal
)))
3391 ("(Ada 2005) does not implement interface }",
3392 Actual
, Etype
(Etype
(Formal
)));
3395 Wrong_Type
(Actual
, Etype
(Formal
));
3397 if Nkind
(Actual
) = N_Op_Eq
3398 and then Nkind
(Left_Opnd
(Actual
)) = N_Identifier
3400 Formal
:= First_Formal
(Nam
);
3401 while Present
(Formal
) loop
3402 if Chars
(Left_Opnd
(Actual
)) = Chars
(Formal
) then
3403 Error_Msg_N
-- CODEFIX
3404 ("possible misspelling of `='>`!", Actual
);
3408 Next_Formal
(Formal
);
3412 if All_Errors_Mode
then
3413 Error_Msg_Sloc
:= Sloc
(Nam
);
3415 if Etype
(Formal
) = Any_Type
then
3417 ("there is no legal actual parameter", Actual
);
3420 if Is_Overloadable
(Nam
)
3421 and then Present
(Alias
(Nam
))
3422 and then not Comes_From_Source
(Nam
)
3425 ("\\ =='> in call to inherited operation & #!",
3428 elsif Ekind
(Nam
) = E_Subprogram_Type
then
3430 Access_To_Subprogram_Typ
:
3431 constant Entity_Id
:=
3433 (Associated_Node_For_Itype
(Nam
));
3436 ("\\ =='> in call to dereference of &#!",
3437 Actual
, Access_To_Subprogram_Typ
);
3442 ("\\ =='> in call to &#!", Actual
, Nam
);
3452 -- Normalize_Actuals has verified that a default value exists
3453 -- for this formal. Current actual names a subsequent formal.
3455 Next_Formal
(Formal
);
3459 -- On exit, all actuals match
3461 Indicate_Name_And_Type
;
3463 end Analyze_One_Call
;
3465 ---------------------------
3466 -- Analyze_Operator_Call --
3467 ---------------------------
3469 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
) is
3470 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
3471 Act1
: constant Node_Id
:= First_Actual
(N
);
3472 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
3475 -- Binary operator case
3477 if Present
(Act2
) then
3479 -- If more than two operands, then not binary operator after all
3481 if Present
(Next_Actual
(Act2
)) then
3485 -- Otherwise action depends on operator
3495 Find_Arithmetic_Types
(Act1
, Act2
, Op_Id
, N
);
3500 Find_Boolean_Types
(Act1
, Act2
, Op_Id
, N
);
3506 Find_Comparison_Types
(Act1
, Act2
, Op_Id
, N
);
3510 Find_Equality_Types
(Act1
, Act2
, Op_Id
, N
);
3512 when Name_Op_Concat
=>
3513 Find_Concatenation_Types
(Act1
, Act2
, Op_Id
, N
);
3515 -- Is this when others, or should it be an abort???
3521 -- Unary operator case
3525 when Name_Op_Subtract |
3528 Find_Unary_Types
(Act1
, Op_Id
, N
);
3531 Find_Negation_Types
(Act1
, Op_Id
, N
);
3533 -- Is this when others correct, or should it be an abort???
3539 end Analyze_Operator_Call
;
3541 -------------------------------------------
3542 -- Analyze_Overloaded_Selected_Component --
3543 -------------------------------------------
3545 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
) is
3546 Nam
: constant Node_Id
:= Prefix
(N
);
3547 Sel
: constant Node_Id
:= Selector_Name
(N
);
3554 Set_Etype
(Sel
, Any_Type
);
3556 Get_First_Interp
(Nam
, I
, It
);
3557 while Present
(It
.Typ
) loop
3558 if Is_Access_Type
(It
.Typ
) then
3559 T
:= Designated_Type
(It
.Typ
);
3560 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
3565 -- Locate the component. For a private prefix the selector can denote
3568 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
3570 -- If the prefix is a class-wide type, the visible components are
3571 -- those of the base type.
3573 if Is_Class_Wide_Type
(T
) then
3577 Comp
:= First_Entity
(T
);
3578 while Present
(Comp
) loop
3579 if Chars
(Comp
) = Chars
(Sel
)
3580 and then Is_Visible_Component
(Comp
)
3583 -- AI05-105: if the context is an object renaming with
3584 -- an anonymous access type, the expected type of the
3585 -- object must be anonymous. This is a name resolution rule.
3587 if Nkind
(Parent
(N
)) /= N_Object_Renaming_Declaration
3588 or else No
(Access_Definition
(Parent
(N
)))
3589 or else Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Type
3591 Ekind
(Etype
(Comp
)) = E_Anonymous_Access_Subprogram_Type
3593 Set_Entity
(Sel
, Comp
);
3594 Set_Etype
(Sel
, Etype
(Comp
));
3595 Add_One_Interp
(N
, Etype
(Comp
), Etype
(Comp
));
3596 Check_Implicit_Dereference
(N
, Etype
(Comp
));
3598 -- This also specifies a candidate to resolve the name.
3599 -- Further overloading will be resolved from context.
3600 -- The selector name itself does not carry overloading
3603 Set_Etype
(Nam
, It
.Typ
);
3606 -- Named access type in the context of a renaming
3607 -- declaration with an access definition. Remove
3608 -- inapplicable candidate.
3617 elsif Is_Concurrent_Type
(T
) then
3618 Comp
:= First_Entity
(T
);
3619 while Present
(Comp
)
3620 and then Comp
/= First_Private_Entity
(T
)
3622 if Chars
(Comp
) = Chars
(Sel
) then
3623 if Is_Overloadable
(Comp
) then
3624 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
3626 Set_Entity_With_Checks
(Sel
, Comp
);
3627 Generate_Reference
(Comp
, Sel
);
3630 Set_Etype
(Sel
, Etype
(Comp
));
3631 Set_Etype
(N
, Etype
(Comp
));
3632 Set_Etype
(Nam
, It
.Typ
);
3634 -- For access type case, introduce explicit dereference for
3635 -- more uniform treatment of entry calls. Do this only once
3636 -- if several interpretations yield an access type.
3638 if Is_Access_Type
(Etype
(Nam
))
3639 and then Nkind
(Nam
) /= N_Explicit_Dereference
3641 Insert_Explicit_Dereference
(Nam
);
3643 (Warn_On_Dereference
, "?d?implicit dereference", N
);
3650 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
3653 Get_Next_Interp
(I
, It
);
3656 if Etype
(N
) = Any_Type
3657 and then not Try_Object_Operation
(N
)
3659 Error_Msg_NE
("undefined selector& for overloaded prefix", N
, Sel
);
3660 Set_Entity
(Sel
, Any_Id
);
3661 Set_Etype
(Sel
, Any_Type
);
3663 end Analyze_Overloaded_Selected_Component
;
3665 ----------------------------------
3666 -- Analyze_Qualified_Expression --
3667 ----------------------------------
3669 procedure Analyze_Qualified_Expression
(N
: Node_Id
) is
3670 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
3671 Expr
: constant Node_Id
:= Expression
(N
);
3677 Analyze_Expression
(Expr
);
3679 Set_Etype
(N
, Any_Type
);
3684 if T
= Any_Type
then
3688 Check_Fully_Declared
(T
, N
);
3690 -- If expected type is class-wide, check for exact match before
3691 -- expansion, because if the expression is a dispatching call it
3692 -- may be rewritten as explicit dereference with class-wide result.
3693 -- If expression is overloaded, retain only interpretations that
3694 -- will yield exact matches.
3696 if Is_Class_Wide_Type
(T
) then
3697 if not Is_Overloaded
(Expr
) then
3698 if Base_Type
(Etype
(Expr
)) /= Base_Type
(T
) then
3699 if Nkind
(Expr
) = N_Aggregate
then
3700 Error_Msg_N
("type of aggregate cannot be class-wide", Expr
);
3702 Wrong_Type
(Expr
, T
);
3707 Get_First_Interp
(Expr
, I
, It
);
3709 while Present
(It
.Nam
) loop
3710 if Base_Type
(It
.Typ
) /= Base_Type
(T
) then
3714 Get_Next_Interp
(I
, It
);
3720 end Analyze_Qualified_Expression
;
3722 -----------------------------------
3723 -- Analyze_Quantified_Expression --
3724 -----------------------------------
3726 procedure Analyze_Quantified_Expression
(N
: Node_Id
) is
3727 function Is_Empty_Range
(Typ
: Entity_Id
) return Boolean;
3728 -- If the iterator is part of a quantified expression, and the range is
3729 -- known to be statically empty, emit a warning and replace expression
3730 -- with its static value. Returns True if the replacement occurs.
3732 function No_Else_Or_Trivial_True
(If_Expr
: Node_Id
) return Boolean;
3733 -- Determine whether if expression If_Expr lacks an else part or if it
3734 -- has one, it evaluates to True.
3736 --------------------
3737 -- Is_Empty_Range --
3738 --------------------
3740 function Is_Empty_Range
(Typ
: Entity_Id
) return Boolean is
3741 Loc
: constant Source_Ptr
:= Sloc
(N
);
3744 if Is_Array_Type
(Typ
)
3745 and then Compile_Time_Known_Bounds
(Typ
)
3747 (Expr_Value
(Type_Low_Bound
(Etype
(First_Index
(Typ
)))) >
3748 Expr_Value
(Type_High_Bound
(Etype
(First_Index
(Typ
)))))
3750 Preanalyze_And_Resolve
(Condition
(N
), Standard_Boolean
);
3752 if All_Present
(N
) then
3754 ("??quantified expression with ALL "
3755 & "over a null range has value True", N
);
3756 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
3760 ("??quantified expression with SOME "
3761 & "over a null range has value False", N
);
3762 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
3773 -----------------------------
3774 -- No_Else_Or_Trivial_True --
3775 -----------------------------
3777 function No_Else_Or_Trivial_True
(If_Expr
: Node_Id
) return Boolean is
3778 Else_Expr
: constant Node_Id
:=
3779 Next
(Next
(First
(Expressions
(If_Expr
))));
3783 or else (Compile_Time_Known_Value
(Else_Expr
)
3784 and then Is_True
(Expr_Value
(Else_Expr
)));
3785 end No_Else_Or_Trivial_True
;
3789 Cond
: constant Node_Id
:= Condition
(N
);
3790 Loop_Id
: Entity_Id
;
3791 QE_Scop
: Entity_Id
;
3793 -- Start of processing for Analyze_Quantified_Expression
3796 Check_SPARK_05_Restriction
("quantified expression is not allowed", N
);
3798 -- Create a scope to emulate the loop-like behavior of the quantified
3799 -- expression. The scope is needed to provide proper visibility of the
3802 QE_Scop
:= New_Internal_Entity
(E_Loop
, Current_Scope
, Sloc
(N
), 'L');
3803 Set_Etype
(QE_Scop
, Standard_Void_Type
);
3804 Set_Scope
(QE_Scop
, Current_Scope
);
3805 Set_Parent
(QE_Scop
, N
);
3807 Push_Scope
(QE_Scop
);
3809 -- All constituents are preanalyzed and resolved to avoid untimely
3810 -- generation of various temporaries and types. Full analysis and
3811 -- expansion is carried out when the quantified expression is
3812 -- transformed into an expression with actions.
3814 if Present
(Iterator_Specification
(N
)) then
3815 Preanalyze
(Iterator_Specification
(N
));
3817 -- Do not proceed with the analysis when the range of iteration is
3818 -- empty. The appropriate error is issued by Is_Empty_Range.
3820 if Is_Entity_Name
(Name
(Iterator_Specification
(N
)))
3821 and then Is_Empty_Range
(Etype
(Name
(Iterator_Specification
(N
))))
3826 else pragma Assert
(Present
(Loop_Parameter_Specification
(N
)));
3828 Loop_Par
: constant Node_Id
:= Loop_Parameter_Specification
(N
);
3831 Preanalyze
(Loop_Par
);
3833 if Nkind
(Discrete_Subtype_Definition
(Loop_Par
)) = N_Function_Call
3834 and then Parent
(Loop_Par
) /= N
3836 -- The parser cannot distinguish between a loop specification
3837 -- and an iterator specification. If after pre-analysis the
3838 -- proper form has been recognized, rewrite the expression to
3839 -- reflect the right kind. This is needed for proper ASIS
3840 -- navigation. If expansion is enabled, the transformation is
3841 -- performed when the expression is rewritten as a loop.
3843 Set_Iterator_Specification
(N
,
3844 New_Copy_Tree
(Iterator_Specification
(Parent
(Loop_Par
))));
3846 Set_Defining_Identifier
(Iterator_Specification
(N
),
3847 Relocate_Node
(Defining_Identifier
(Loop_Par
)));
3848 Set_Name
(Iterator_Specification
(N
),
3849 Relocate_Node
(Discrete_Subtype_Definition
(Loop_Par
)));
3850 Set_Comes_From_Source
(Iterator_Specification
(N
),
3851 Comes_From_Source
(Loop_Parameter_Specification
(N
)));
3852 Set_Loop_Parameter_Specification
(N
, Empty
);
3857 Preanalyze_And_Resolve
(Cond
, Standard_Boolean
);
3860 Set_Etype
(N
, Standard_Boolean
);
3862 -- Verify that the loop variable is used within the condition of the
3863 -- quantified expression.
3865 if Present
(Iterator_Specification
(N
)) then
3866 Loop_Id
:= Defining_Identifier
(Iterator_Specification
(N
));
3868 Loop_Id
:= Defining_Identifier
(Loop_Parameter_Specification
(N
));
3871 if Warn_On_Suspicious_Contract
3872 and then not Referenced
(Loop_Id
, Cond
)
3874 Error_Msg_N
("?T?unused variable &", Loop_Id
);
3877 -- Diagnose a possible misuse of the SOME existential quantifier. When
3878 -- we have a quantified expression of the form:
3880 -- for some X => (if P then Q [else True])
3882 -- any value for X that makes P False results in the if expression being
3883 -- trivially True, and so also results in the quantified expression
3884 -- being trivially True.
3886 if Warn_On_Suspicious_Contract
3887 and then not All_Present
(N
)
3888 and then Nkind
(Cond
) = N_If_Expression
3889 and then No_Else_Or_Trivial_True
(Cond
)
3891 Error_Msg_N
("?T?suspicious expression", N
);
3892 Error_Msg_N
("\\did you mean (for all X ='> (if P then Q))", N
);
3893 Error_Msg_N
("\\or (for some X ='> P and then Q) instead'?", N
);
3895 end Analyze_Quantified_Expression
;
3901 procedure Analyze_Range
(N
: Node_Id
) is
3902 L
: constant Node_Id
:= Low_Bound
(N
);
3903 H
: constant Node_Id
:= High_Bound
(N
);
3904 I1
, I2
: Interp_Index
;
3907 procedure Check_Common_Type
(T1
, T2
: Entity_Id
);
3908 -- Verify the compatibility of two types, and choose the
3909 -- non universal one if the other is universal.
3911 procedure Check_High_Bound
(T
: Entity_Id
);
3912 -- Test one interpretation of the low bound against all those
3913 -- of the high bound.
3915 procedure Check_Universal_Expression
(N
: Node_Id
);
3916 -- In Ada 83, reject bounds of a universal range that are not literals
3919 -----------------------
3920 -- Check_Common_Type --
3921 -----------------------
3923 procedure Check_Common_Type
(T1
, T2
: Entity_Id
) is
3925 if Covers
(T1
=> T1
, T2
=> T2
)
3927 Covers
(T1
=> T2
, T2
=> T1
)
3929 if T1
= Universal_Integer
3930 or else T1
= Universal_Real
3931 or else T1
= Any_Character
3933 Add_One_Interp
(N
, Base_Type
(T2
), Base_Type
(T2
));
3936 Add_One_Interp
(N
, T1
, T1
);
3939 Add_One_Interp
(N
, Base_Type
(T1
), Base_Type
(T1
));
3942 end Check_Common_Type
;
3944 ----------------------
3945 -- Check_High_Bound --
3946 ----------------------
3948 procedure Check_High_Bound
(T
: Entity_Id
) is
3950 if not Is_Overloaded
(H
) then
3951 Check_Common_Type
(T
, Etype
(H
));
3953 Get_First_Interp
(H
, I2
, It2
);
3954 while Present
(It2
.Typ
) loop
3955 Check_Common_Type
(T
, It2
.Typ
);
3956 Get_Next_Interp
(I2
, It2
);
3959 end Check_High_Bound
;
3961 -----------------------------
3962 -- Is_Universal_Expression --
3963 -----------------------------
3965 procedure Check_Universal_Expression
(N
: Node_Id
) is
3967 if Etype
(N
) = Universal_Integer
3968 and then Nkind
(N
) /= N_Integer_Literal
3969 and then not Is_Entity_Name
(N
)
3970 and then Nkind
(N
) /= N_Attribute_Reference
3972 Error_Msg_N
("illegal bound in discrete range", N
);
3974 end Check_Universal_Expression
;
3976 -- Start of processing for Analyze_Range
3979 Set_Etype
(N
, Any_Type
);
3980 Analyze_Expression
(L
);
3981 Analyze_Expression
(H
);
3983 if Etype
(L
) = Any_Type
or else Etype
(H
) = Any_Type
then
3987 if not Is_Overloaded
(L
) then
3988 Check_High_Bound
(Etype
(L
));
3990 Get_First_Interp
(L
, I1
, It1
);
3991 while Present
(It1
.Typ
) loop
3992 Check_High_Bound
(It1
.Typ
);
3993 Get_Next_Interp
(I1
, It1
);
3997 -- If result is Any_Type, then we did not find a compatible pair
3999 if Etype
(N
) = Any_Type
then
4000 Error_Msg_N
("incompatible types in range ", N
);
4004 if Ada_Version
= Ada_83
4006 (Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
4007 or else Nkind
(Parent
(N
)) = N_Constrained_Array_Definition
)
4009 Check_Universal_Expression
(L
);
4010 Check_Universal_Expression
(H
);
4013 Check_Function_Writable_Actuals
(N
);
4016 -----------------------
4017 -- Analyze_Reference --
4018 -----------------------
4020 procedure Analyze_Reference
(N
: Node_Id
) is
4021 P
: constant Node_Id
:= Prefix
(N
);
4024 Acc_Type
: Entity_Id
;
4029 -- An interesting error check, if we take the 'Ref of an object for
4030 -- which a pragma Atomic or Volatile has been given, and the type of the
4031 -- object is not Atomic or Volatile, then we are in trouble. The problem
4032 -- is that no trace of the atomic/volatile status will remain for the
4033 -- backend to respect when it deals with the resulting pointer, since
4034 -- the pointer type will not be marked atomic (it is a pointer to the
4035 -- base type of the object).
4037 -- It is not clear if that can ever occur, but in case it does, we will
4038 -- generate an error message. Not clear if this message can ever be
4039 -- generated, and pretty clear that it represents a bug if it is, still
4040 -- seems worth checking, except in CodePeer mode where we do not really
4041 -- care and don't want to bother the user.
4045 if Is_Entity_Name
(P
)
4046 and then Is_Object_Reference
(P
)
4047 and then not CodePeer_Mode
4052 if (Has_Atomic_Components
(E
)
4053 and then not Has_Atomic_Components
(T
))
4055 (Has_Volatile_Components
(E
)
4056 and then not Has_Volatile_Components
(T
))
4057 or else (Is_Atomic
(E
) and then not Is_Atomic
(T
))
4058 or else (Is_Volatile
(E
) and then not Is_Volatile
(T
))
4060 Error_Msg_N
("cannot take reference to Atomic/Volatile object", N
);
4064 -- Carry on with normal processing
4066 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
4067 Set_Etype
(Acc_Type
, Acc_Type
);
4068 Set_Directly_Designated_Type
(Acc_Type
, Etype
(P
));
4069 Set_Etype
(N
, Acc_Type
);
4070 end Analyze_Reference
;
4072 --------------------------------
4073 -- Analyze_Selected_Component --
4074 --------------------------------
4076 -- Prefix is a record type or a task or protected type. In the latter case,
4077 -- the selector must denote a visible entry.
4079 procedure Analyze_Selected_Component
(N
: Node_Id
) is
4080 Name
: constant Node_Id
:= Prefix
(N
);
4081 Sel
: constant Node_Id
:= Selector_Name
(N
);
4084 Has_Candidate
: Boolean := False;
4087 Pent
: Entity_Id
:= Empty
;
4088 Prefix_Type
: Entity_Id
;
4090 Type_To_Use
: Entity_Id
;
4091 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
4092 -- a class-wide type, we use its root type, whose components are
4093 -- present in the class-wide type.
4095 Is_Single_Concurrent_Object
: Boolean;
4096 -- Set True if the prefix is a single task or a single protected object
4098 procedure Find_Component_In_Instance
(Rec
: Entity_Id
);
4099 -- In an instance, a component of a private extension may not be visible
4100 -- while it was visible in the generic. Search candidate scope for a
4101 -- component with the proper identifier. This is only done if all other
4102 -- searches have failed. If a match is found, the Etype of both N and
4103 -- Sel are set from this component, and the entity of Sel is set to
4104 -- reference this component. If no match is found, Entity (Sel) remains
4105 -- unset. For a derived type that is an actual of the instance, the
4106 -- desired component may be found in any ancestor.
4108 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean;
4109 -- It is known that the parent of N denotes a subprogram call. Comp
4110 -- is an overloadable component of the concurrent type of the prefix.
4111 -- Determine whether all formals of the parent of N and Comp are mode
4112 -- conformant. If the parent node is not analyzed yet it may be an
4113 -- indexed component rather than a function call.
4115 --------------------------------
4116 -- Find_Component_In_Instance --
4117 --------------------------------
4119 procedure Find_Component_In_Instance
(Rec
: Entity_Id
) is
4125 while Present
(Typ
) loop
4126 Comp
:= First_Component
(Typ
);
4127 while Present
(Comp
) loop
4128 if Chars
(Comp
) = Chars
(Sel
) then
4129 Set_Entity_With_Checks
(Sel
, Comp
);
4130 Set_Etype
(Sel
, Etype
(Comp
));
4131 Set_Etype
(N
, Etype
(Comp
));
4135 Next_Component
(Comp
);
4138 -- If not found, the component may be declared in the parent
4139 -- type or its full view, if any.
4141 if Is_Derived_Type
(Typ
) then
4144 if Is_Private_Type
(Typ
) then
4145 Typ
:= Full_View
(Typ
);
4153 -- If we fall through, no match, so no changes made
4156 end Find_Component_In_Instance
;
4158 ------------------------------
4159 -- Has_Mode_Conformant_Spec --
4160 ------------------------------
4162 function Has_Mode_Conformant_Spec
(Comp
: Entity_Id
) return Boolean is
4163 Comp_Param
: Entity_Id
;
4165 Param_Typ
: Entity_Id
;
4168 Comp_Param
:= First_Formal
(Comp
);
4170 if Nkind
(Parent
(N
)) = N_Indexed_Component
then
4171 Param
:= First
(Expressions
(Parent
(N
)));
4173 Param
:= First
(Parameter_Associations
(Parent
(N
)));
4176 while Present
(Comp_Param
)
4177 and then Present
(Param
)
4179 Param_Typ
:= Find_Parameter_Type
(Param
);
4181 if Present
(Param_Typ
)
4183 not Conforming_Types
4184 (Etype
(Comp_Param
), Param_Typ
, Mode_Conformant
)
4189 Next_Formal
(Comp_Param
);
4193 -- One of the specs has additional formals; there is no match, unless
4194 -- this may be an indexing of a parameterless call.
4196 -- Note that when expansion is disabled, the corresponding record
4197 -- type of synchronized types is not constructed, so that there is
4198 -- no point is attempting an interpretation as a prefixed call, as
4199 -- this is bound to fail because the primitive operations will not
4200 -- be properly located.
4202 if Present
(Comp_Param
) or else Present
(Param
) then
4203 if Needs_No_Actuals
(Comp
)
4204 and then Is_Array_Type
(Etype
(Comp
))
4205 and then not Expander_Active
4214 end Has_Mode_Conformant_Spec
;
4216 -- Start of processing for Analyze_Selected_Component
4219 Set_Etype
(N
, Any_Type
);
4221 if Is_Overloaded
(Name
) then
4222 Analyze_Overloaded_Selected_Component
(N
);
4225 elsif Etype
(Name
) = Any_Type
then
4226 Set_Entity
(Sel
, Any_Id
);
4227 Set_Etype
(Sel
, Any_Type
);
4231 Prefix_Type
:= Etype
(Name
);
4234 if Is_Access_Type
(Prefix_Type
) then
4236 -- A RACW object can never be used as prefix of a selected component
4237 -- since that means it is dereferenced without being a controlling
4238 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
4239 -- reporting an error, we must check whether this is actually a
4240 -- dispatching call in prefix form.
4242 if Is_Remote_Access_To_Class_Wide_Type
(Prefix_Type
)
4243 and then Comes_From_Source
(N
)
4245 if Try_Object_Operation
(N
) then
4249 ("invalid dereference of a remote access-to-class-wide value",
4253 -- Normal case of selected component applied to access type
4256 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4258 if Is_Entity_Name
(Name
) then
4259 Pent
:= Entity
(Name
);
4260 elsif Nkind
(Name
) = N_Selected_Component
4261 and then Is_Entity_Name
(Selector_Name
(Name
))
4263 Pent
:= Entity
(Selector_Name
(Name
));
4266 Prefix_Type
:= Process_Implicit_Dereference_Prefix
(Pent
, Name
);
4269 -- If we have an explicit dereference of a remote access-to-class-wide
4270 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
4271 -- have to check for the case of a prefix that is a controlling operand
4272 -- of a prefixed dispatching call, as the dereference is legal in that
4273 -- case. Normally this condition is checked in Validate_Remote_Access_
4274 -- To_Class_Wide_Type, but we have to defer the checking for selected
4275 -- component prefixes because of the prefixed dispatching call case.
4276 -- Note that implicit dereferences are checked for this just above.
4278 elsif Nkind
(Name
) = N_Explicit_Dereference
4279 and then Is_Remote_Access_To_Class_Wide_Type
(Etype
(Prefix
(Name
)))
4280 and then Comes_From_Source
(N
)
4282 if Try_Object_Operation
(N
) then
4286 ("invalid dereference of a remote access-to-class-wide value",
4291 -- (Ada 2005): if the prefix is the limited view of a type, and
4292 -- the context already includes the full view, use the full view
4293 -- in what follows, either to retrieve a component of to find
4294 -- a primitive operation. If the prefix is an explicit dereference,
4295 -- set the type of the prefix to reflect this transformation.
4296 -- If the non-limited view is itself an incomplete type, get the
4297 -- full view if available.
4299 if From_Limited_With
(Prefix_Type
)
4300 and then Has_Non_Limited_View
(Prefix_Type
)
4302 Prefix_Type
:= Get_Full_View
(Non_Limited_View
(Prefix_Type
));
4304 if Nkind
(N
) = N_Explicit_Dereference
then
4305 Set_Etype
(Prefix
(N
), Prefix_Type
);
4309 if Ekind
(Prefix_Type
) = E_Private_Subtype
then
4310 Prefix_Type
:= Base_Type
(Prefix_Type
);
4313 Type_To_Use
:= Prefix_Type
;
4315 -- For class-wide types, use the entity list of the root type. This
4316 -- indirection is specially important for private extensions because
4317 -- only the root type get switched (not the class-wide type).
4319 if Is_Class_Wide_Type
(Prefix_Type
) then
4320 Type_To_Use
:= Root_Type
(Prefix_Type
);
4323 -- If the prefix is a single concurrent object, use its name in error
4324 -- messages, rather than that of its anonymous type.
4326 Is_Single_Concurrent_Object
:=
4327 Is_Concurrent_Type
(Prefix_Type
)
4328 and then Is_Internal_Name
(Chars
(Prefix_Type
))
4329 and then not Is_Derived_Type
(Prefix_Type
)
4330 and then Is_Entity_Name
(Name
);
4332 Comp
:= First_Entity
(Type_To_Use
);
4334 -- If the selector has an original discriminant, the node appears in
4335 -- an instance. Replace the discriminant with the corresponding one
4336 -- in the current discriminated type. For nested generics, this must
4337 -- be done transitively, so note the new original discriminant.
4339 if Nkind
(Sel
) = N_Identifier
4340 and then In_Instance
4341 and then Present
(Original_Discriminant
(Sel
))
4343 Comp
:= Find_Corresponding_Discriminant
(Sel
, Prefix_Type
);
4345 -- Mark entity before rewriting, for completeness and because
4346 -- subsequent semantic checks might examine the original node.
4348 Set_Entity
(Sel
, Comp
);
4349 Rewrite
(Selector_Name
(N
), New_Occurrence_Of
(Comp
, Sloc
(N
)));
4350 Set_Original_Discriminant
(Selector_Name
(N
), Comp
);
4351 Set_Etype
(N
, Etype
(Comp
));
4352 Check_Implicit_Dereference
(N
, Etype
(Comp
));
4354 if Is_Access_Type
(Etype
(Name
)) then
4355 Insert_Explicit_Dereference
(Name
);
4356 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
4359 elsif Is_Record_Type
(Prefix_Type
) then
4361 -- Find component with given name. In an instance, if the node is
4362 -- known as a prefixed call, do not examine components whose
4363 -- visibility may be accidental.
4365 while Present
(Comp
) and then not Is_Prefixed_Call
(N
) loop
4366 if Chars
(Comp
) = Chars
(Sel
)
4367 and then Is_Visible_Component
(Comp
, N
)
4369 Set_Entity_With_Checks
(Sel
, Comp
);
4370 Set_Etype
(Sel
, Etype
(Comp
));
4372 if Ekind
(Comp
) = E_Discriminant
then
4373 if Is_Unchecked_Union
(Base_Type
(Prefix_Type
)) then
4375 ("cannot reference discriminant of unchecked union",
4379 if Is_Generic_Type
(Prefix_Type
)
4381 Is_Generic_Type
(Root_Type
(Prefix_Type
))
4383 Set_Original_Discriminant
(Sel
, Comp
);
4387 -- Resolve the prefix early otherwise it is not possible to
4388 -- build the actual subtype of the component: it may need
4389 -- to duplicate this prefix and duplication is only allowed
4390 -- on fully resolved expressions.
4394 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
4395 -- subtypes in a package specification.
4398 -- limited with Pkg;
4400 -- type Acc_Inc is access Pkg.T;
4402 -- N : Natural := X.all.Comp; -- ERROR, limited view
4403 -- end Pkg; -- Comp is not visible
4405 if Nkind
(Name
) = N_Explicit_Dereference
4406 and then From_Limited_With
(Etype
(Prefix
(Name
)))
4407 and then not Is_Potentially_Use_Visible
(Etype
(Name
))
4408 and then Nkind
(Parent
(Cunit_Entity
(Current_Sem_Unit
))) =
4409 N_Package_Specification
4412 ("premature usage of incomplete}", Prefix
(Name
),
4413 Etype
(Prefix
(Name
)));
4416 -- We never need an actual subtype for the case of a selection
4417 -- for a indexed component of a non-packed array, since in
4418 -- this case gigi generates all the checks and can find the
4419 -- necessary bounds information.
4421 -- We also do not need an actual subtype for the case of a
4422 -- first, last, length, or range attribute applied to a
4423 -- non-packed array, since gigi can again get the bounds in
4424 -- these cases (gigi cannot handle the packed case, since it
4425 -- has the bounds of the packed array type, not the original
4426 -- bounds of the type). However, if the prefix is itself a
4427 -- selected component, as in a.b.c (i), gigi may regard a.b.c
4428 -- as a dynamic-sized temporary, so we do generate an actual
4429 -- subtype for this case.
4431 Parent_N
:= Parent
(N
);
4433 if not Is_Packed
(Etype
(Comp
))
4435 ((Nkind
(Parent_N
) = N_Indexed_Component
4436 and then Nkind
(Name
) /= N_Selected_Component
)
4438 (Nkind
(Parent_N
) = N_Attribute_Reference
4440 Nam_In
(Attribute_Name
(Parent_N
), Name_First
,
4445 Set_Etype
(N
, Etype
(Comp
));
4447 -- If full analysis is not enabled, we do not generate an
4448 -- actual subtype, because in the absence of expansion
4449 -- reference to a formal of a protected type, for example,
4450 -- will not be properly transformed, and will lead to
4451 -- out-of-scope references in gigi.
4453 -- In all other cases, we currently build an actual subtype.
4454 -- It seems likely that many of these cases can be avoided,
4455 -- but right now, the front end makes direct references to the
4456 -- bounds (e.g. in generating a length check), and if we do
4457 -- not make an actual subtype, we end up getting a direct
4458 -- reference to a discriminant, which will not do.
4460 elsif Full_Analysis
then
4462 Build_Actual_Subtype_Of_Component
(Etype
(Comp
), N
);
4463 Insert_Action
(N
, Act_Decl
);
4465 if No
(Act_Decl
) then
4466 Set_Etype
(N
, Etype
(Comp
));
4469 -- Component type depends on discriminants. Enter the
4470 -- main attributes of the subtype.
4473 Subt
: constant Entity_Id
:=
4474 Defining_Identifier
(Act_Decl
);
4477 Set_Etype
(Subt
, Base_Type
(Etype
(Comp
)));
4478 Set_Ekind
(Subt
, Ekind
(Etype
(Comp
)));
4479 Set_Etype
(N
, Subt
);
4483 -- If Full_Analysis not enabled, just set the Etype
4486 Set_Etype
(N
, Etype
(Comp
));
4489 Check_Implicit_Dereference
(N
, Etype
(N
));
4493 -- If the prefix is a private extension, check only the visible
4494 -- components of the partial view. This must include the tag,
4495 -- which can appear in expanded code in a tag check.
4497 if Ekind
(Type_To_Use
) = E_Record_Type_With_Private
4498 and then Chars
(Selector_Name
(N
)) /= Name_uTag
4500 exit when Comp
= Last_Entity
(Type_To_Use
);
4506 -- Ada 2005 (AI-252): The selected component can be interpreted as
4507 -- a prefixed view of a subprogram. Depending on the context, this is
4508 -- either a name that can appear in a renaming declaration, or part
4509 -- of an enclosing call given in prefix form.
4511 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
4512 -- selected component should resolve to a name.
4514 if Ada_Version
>= Ada_2005
4515 and then Is_Tagged_Type
(Prefix_Type
)
4516 and then not Is_Concurrent_Type
(Prefix_Type
)
4518 if Nkind
(Parent
(N
)) = N_Generic_Association
4519 or else Nkind
(Parent
(N
)) = N_Requeue_Statement
4520 or else Nkind
(Parent
(N
)) = N_Subprogram_Renaming_Declaration
4522 if Find_Primitive_Operation
(N
) then
4526 elsif Try_Object_Operation
(N
) then
4530 -- If the transformation fails, it will be necessary to redo the
4531 -- analysis with all errors enabled, to indicate candidate
4532 -- interpretations and reasons for each failure ???
4536 elsif Is_Private_Type
(Prefix_Type
) then
4538 -- Allow access only to discriminants of the type. If the type has
4539 -- no full view, gigi uses the parent type for the components, so we
4540 -- do the same here.
4542 if No
(Full_View
(Prefix_Type
)) then
4543 Type_To_Use
:= Root_Type
(Base_Type
(Prefix_Type
));
4544 Comp
:= First_Entity
(Type_To_Use
);
4547 while Present
(Comp
) loop
4548 if Chars
(Comp
) = Chars
(Sel
) then
4549 if Ekind
(Comp
) = E_Discriminant
then
4550 Set_Entity_With_Checks
(Sel
, Comp
);
4551 Generate_Reference
(Comp
, Sel
);
4553 Set_Etype
(Sel
, Etype
(Comp
));
4554 Set_Etype
(N
, Etype
(Comp
));
4555 Check_Implicit_Dereference
(N
, Etype
(N
));
4557 if Is_Generic_Type
(Prefix_Type
)
4558 or else Is_Generic_Type
(Root_Type
(Prefix_Type
))
4560 Set_Original_Discriminant
(Sel
, Comp
);
4563 -- Before declaring an error, check whether this is tagged
4564 -- private type and a call to a primitive operation.
4566 elsif Ada_Version
>= Ada_2005
4567 and then Is_Tagged_Type
(Prefix_Type
)
4568 and then Try_Object_Operation
(N
)
4573 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4574 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
4575 Set_Entity
(Sel
, Any_Id
);
4576 Set_Etype
(N
, Any_Type
);
4585 elsif Is_Concurrent_Type
(Prefix_Type
) then
4587 -- Find visible operation with given name. For a protected type,
4588 -- the possible candidates are discriminants, entries or protected
4589 -- procedures. For a task type, the set can only include entries or
4590 -- discriminants if the task type is not an enclosing scope. If it
4591 -- is an enclosing scope (e.g. in an inner task) then all entities
4592 -- are visible, but the prefix must denote the enclosing scope, i.e.
4593 -- can only be a direct name or an expanded name.
4595 Set_Etype
(Sel
, Any_Type
);
4596 In_Scope
:= In_Open_Scopes
(Prefix_Type
);
4598 while Present
(Comp
) loop
4599 if Chars
(Comp
) = Chars
(Sel
) then
4600 if Is_Overloadable
(Comp
) then
4601 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
4603 -- If the prefix is tagged, the correct interpretation may
4604 -- lie in the primitive or class-wide operations of the
4605 -- type. Perform a simple conformance check to determine
4606 -- whether Try_Object_Operation should be invoked even if
4607 -- a visible entity is found.
4609 if Is_Tagged_Type
(Prefix_Type
)
4611 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
4613 N_Indexed_Component
)
4614 and then Has_Mode_Conformant_Spec
(Comp
)
4616 Has_Candidate
:= True;
4619 -- Note: a selected component may not denote a component of a
4620 -- protected type (4.1.3(7)).
4622 elsif Ekind_In
(Comp
, E_Discriminant
, E_Entry_Family
)
4624 and then not Is_Protected_Type
(Prefix_Type
)
4625 and then Is_Entity_Name
(Name
))
4627 Set_Entity_With_Checks
(Sel
, Comp
);
4628 Generate_Reference
(Comp
, Sel
);
4630 -- The selector is not overloadable, so we have a candidate
4633 Has_Candidate
:= True;
4639 Set_Etype
(Sel
, Etype
(Comp
));
4640 Set_Etype
(N
, Etype
(Comp
));
4642 if Ekind
(Comp
) = E_Discriminant
then
4643 Set_Original_Discriminant
(Sel
, Comp
);
4646 -- For access type case, introduce explicit dereference for
4647 -- more uniform treatment of entry calls.
4649 if Is_Access_Type
(Etype
(Name
)) then
4650 Insert_Explicit_Dereference
(Name
);
4652 (Warn_On_Dereference
, "?d?implicit dereference", N
);
4658 exit when not In_Scope
4660 Comp
= First_Private_Entity
(Base_Type
(Prefix_Type
));
4663 -- If there is no visible entity with the given name or none of the
4664 -- visible entities are plausible interpretations, check whether
4665 -- there is some other primitive operation with that name.
4667 if Ada_Version
>= Ada_2005
4668 and then Is_Tagged_Type
(Prefix_Type
)
4670 if (Etype
(N
) = Any_Type
4671 or else not Has_Candidate
)
4672 and then Try_Object_Operation
(N
)
4676 -- If the context is not syntactically a procedure call, it
4677 -- may be a call to a primitive function declared outside of
4678 -- the synchronized type.
4680 -- If the context is a procedure call, there might still be
4681 -- an overloading between an entry and a primitive procedure
4682 -- declared outside of the synchronized type, called in prefix
4683 -- notation. This is harder to disambiguate because in one case
4684 -- the controlling formal is implicit ???
4686 elsif Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
4687 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
4688 and then Try_Object_Operation
(N
)
4693 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
4694 -- entry or procedure of a tagged concurrent type we must check
4695 -- if there are class-wide subprograms covering the primitive. If
4696 -- true then Try_Object_Operation reports the error.
4699 and then Is_Concurrent_Type
(Prefix_Type
)
4700 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
4702 -- Duplicate the call. This is required to avoid problems with
4703 -- the tree transformations performed by Try_Object_Operation.
4704 -- Set properly the parent of the copied call, because it is
4705 -- about to be reanalyzed.
4709 Par
: constant Node_Id
:= New_Copy_Tree
(Parent
(N
));
4712 Set_Parent
(Par
, Parent
(Parent
(N
)));
4714 if Try_Object_Operation
4715 (Sinfo
.Name
(Par
), CW_Test_Only
=> True)
4723 if Etype
(N
) = Any_Type
and then Is_Protected_Type
(Prefix_Type
) then
4725 -- Case of a prefix of a protected type: selector might denote
4726 -- an invisible private component.
4728 Comp
:= First_Private_Entity
(Base_Type
(Prefix_Type
));
4729 while Present
(Comp
) and then Chars
(Comp
) /= Chars
(Sel
) loop
4733 if Present
(Comp
) then
4734 if Is_Single_Concurrent_Object
then
4735 Error_Msg_Node_2
:= Entity
(Name
);
4736 Error_Msg_NE
("invisible selector& for &", N
, Sel
);
4739 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4740 Error_Msg_NE
("invisible selector& for }", N
, Sel
);
4746 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
4751 Error_Msg_NE
("invalid prefix in selected component&", N
, Sel
);
4754 -- If N still has no type, the component is not defined in the prefix
4756 if Etype
(N
) = Any_Type
then
4758 if Is_Single_Concurrent_Object
then
4759 Error_Msg_Node_2
:= Entity
(Name
);
4760 Error_Msg_NE
("no selector& for&", N
, Sel
);
4762 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
4764 -- If this is a derived formal type, the parent may have different
4765 -- visibility at this point. Try for an inherited component before
4766 -- reporting an error.
4768 elsif Is_Generic_Type
(Prefix_Type
)
4769 and then Ekind
(Prefix_Type
) = E_Record_Type_With_Private
4770 and then Prefix_Type
/= Etype
(Prefix_Type
)
4771 and then Is_Record_Type
(Etype
(Prefix_Type
))
4773 Set_Etype
(Prefix
(N
), Etype
(Prefix_Type
));
4774 Analyze_Selected_Component
(N
);
4777 -- Similarly, if this is the actual for a formal derived type, or
4778 -- a derived type thereof, the component inherited from the generic
4779 -- parent may not be visible in the actual, but the selected
4780 -- component is legal. Climb up the derivation chain of the generic
4781 -- parent type until we find the proper ancestor type.
4783 elsif In_Instance
and then Is_Tagged_Type
(Prefix_Type
) then
4785 Par
: Entity_Id
:= Prefix_Type
;
4787 -- Climb up derivation chain to generic actual subtype
4789 while not Is_Generic_Actual_Type
(Par
) loop
4790 if Ekind
(Par
) = E_Record_Type
then
4791 Par
:= Parent_Subtype
(Par
);
4794 exit when Par
= Etype
(Par
);
4799 if Present
(Par
) and then Is_Generic_Actual_Type
(Par
) then
4801 -- Now look for component in ancestor types
4803 Par
:= Generic_Parent_Type
(Declaration_Node
(Par
));
4805 Find_Component_In_Instance
(Par
);
4806 exit when Present
(Entity
(Sel
))
4807 or else Par
= Etype
(Par
);
4811 -- Another special case: the type is an extension of a private
4812 -- type T, is an actual in an instance, and we are in the body
4813 -- of the instance, so the generic body had a full view of the
4814 -- type declaration for T or of some ancestor that defines the
4815 -- component in question.
4817 elsif Is_Derived_Type
(Type_To_Use
)
4818 and then Used_As_Generic_Actual
(Type_To_Use
)
4819 and then In_Instance_Body
4821 Find_Component_In_Instance
(Parent_Subtype
(Type_To_Use
));
4823 -- In ASIS mode the generic parent type may be absent. Examine
4824 -- the parent type directly for a component that may have been
4825 -- visible in a parent generic unit.
4827 elsif Is_Derived_Type
(Prefix_Type
) then
4828 Par
:= Etype
(Prefix_Type
);
4829 Find_Component_In_Instance
(Par
);
4833 -- The search above must have eventually succeeded, since the
4834 -- selected component was legal in the generic.
4836 if No
(Entity
(Sel
)) then
4837 raise Program_Error
;
4842 -- Component not found, specialize error message when appropriate
4845 if Ekind
(Prefix_Type
) = E_Record_Subtype
then
4847 -- Check whether this is a component of the base type which
4848 -- is absent from a statically constrained subtype. This will
4849 -- raise constraint error at run time, but is not a compile-
4850 -- time error. When the selector is illegal for base type as
4851 -- well fall through and generate a compilation error anyway.
4853 Comp
:= First_Component
(Base_Type
(Prefix_Type
));
4854 while Present
(Comp
) loop
4855 if Chars
(Comp
) = Chars
(Sel
)
4856 and then Is_Visible_Component
(Comp
)
4858 Set_Entity_With_Checks
(Sel
, Comp
);
4859 Generate_Reference
(Comp
, Sel
);
4860 Set_Etype
(Sel
, Etype
(Comp
));
4861 Set_Etype
(N
, Etype
(Comp
));
4863 -- Emit appropriate message. The node will be replaced
4864 -- by an appropriate raise statement.
4866 -- Note that in SPARK mode, as with all calls to apply a
4867 -- compile time constraint error, this will be made into
4868 -- an error to simplify the processing of the formal
4869 -- verification backend.
4871 Apply_Compile_Time_Constraint_Error
4872 (N
, "component not present in }??",
4873 CE_Discriminant_Check_Failed
,
4874 Ent
=> Prefix_Type
, Rep
=> False);
4876 Set_Raises_Constraint_Error
(N
);
4880 Next_Component
(Comp
);
4885 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
4886 Error_Msg_NE
("no selector& for}", N
, Sel
);
4888 -- Add information in the case of an incomplete prefix
4890 if Is_Incomplete_Type
(Type_To_Use
) then
4892 Inc
: constant Entity_Id
:= First_Subtype
(Type_To_Use
);
4895 if From_Limited_With
(Scope
(Type_To_Use
)) then
4897 ("\limited view of& has no components", N
, Inc
);
4901 ("\premature usage of incomplete type&", N
, Inc
);
4903 if Nkind
(Parent
(Inc
)) =
4904 N_Incomplete_Type_Declaration
4906 -- Record location of premature use in entity so that
4907 -- a continuation message is generated when the
4908 -- completion is seen.
4910 Set_Premature_Use
(Parent
(Inc
), N
);
4916 Check_Misspelled_Selector
(Type_To_Use
, Sel
);
4919 Set_Entity
(Sel
, Any_Id
);
4920 Set_Etype
(Sel
, Any_Type
);
4922 end Analyze_Selected_Component
;
4924 ---------------------------
4925 -- Analyze_Short_Circuit --
4926 ---------------------------
4928 procedure Analyze_Short_Circuit
(N
: Node_Id
) is
4929 L
: constant Node_Id
:= Left_Opnd
(N
);
4930 R
: constant Node_Id
:= Right_Opnd
(N
);
4935 Analyze_Expression
(L
);
4936 Analyze_Expression
(R
);
4937 Set_Etype
(N
, Any_Type
);
4939 if not Is_Overloaded
(L
) then
4940 if Root_Type
(Etype
(L
)) = Standard_Boolean
4941 and then Has_Compatible_Type
(R
, Etype
(L
))
4943 Add_One_Interp
(N
, Etype
(L
), Etype
(L
));
4947 Get_First_Interp
(L
, Ind
, It
);
4948 while Present
(It
.Typ
) loop
4949 if Root_Type
(It
.Typ
) = Standard_Boolean
4950 and then Has_Compatible_Type
(R
, It
.Typ
)
4952 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
4955 Get_Next_Interp
(Ind
, It
);
4959 -- Here we have failed to find an interpretation. Clearly we know that
4960 -- it is not the case that both operands can have an interpretation of
4961 -- Boolean, but this is by far the most likely intended interpretation.
4962 -- So we simply resolve both operands as Booleans, and at least one of
4963 -- these resolutions will generate an error message, and we do not need
4964 -- to give another error message on the short circuit operation itself.
4966 if Etype
(N
) = Any_Type
then
4967 Resolve
(L
, Standard_Boolean
);
4968 Resolve
(R
, Standard_Boolean
);
4969 Set_Etype
(N
, Standard_Boolean
);
4971 end Analyze_Short_Circuit
;
4977 procedure Analyze_Slice
(N
: Node_Id
) is
4978 D
: constant Node_Id
:= Discrete_Range
(N
);
4979 P
: constant Node_Id
:= Prefix
(N
);
4980 Array_Type
: Entity_Id
;
4981 Index_Type
: Entity_Id
;
4983 procedure Analyze_Overloaded_Slice
;
4984 -- If the prefix is overloaded, select those interpretations that
4985 -- yield a one-dimensional array type.
4987 ------------------------------
4988 -- Analyze_Overloaded_Slice --
4989 ------------------------------
4991 procedure Analyze_Overloaded_Slice
is
4997 Set_Etype
(N
, Any_Type
);
4999 Get_First_Interp
(P
, I
, It
);
5000 while Present
(It
.Nam
) loop
5003 if Is_Access_Type
(Typ
) then
5004 Typ
:= Designated_Type
(Typ
);
5006 (Warn_On_Dereference
, "?d?implicit dereference", N
);
5009 if Is_Array_Type
(Typ
)
5010 and then Number_Dimensions
(Typ
) = 1
5011 and then Has_Compatible_Type
(D
, Etype
(First_Index
(Typ
)))
5013 Add_One_Interp
(N
, Typ
, Typ
);
5016 Get_Next_Interp
(I
, It
);
5019 if Etype
(N
) = Any_Type
then
5020 Error_Msg_N
("expect array type in prefix of slice", N
);
5022 end Analyze_Overloaded_Slice
;
5024 -- Start of processing for Analyze_Slice
5027 if Comes_From_Source
(N
) then
5028 Check_SPARK_05_Restriction
("slice is not allowed", N
);
5034 if Is_Overloaded
(P
) then
5035 Analyze_Overloaded_Slice
;
5038 Array_Type
:= Etype
(P
);
5039 Set_Etype
(N
, Any_Type
);
5041 if Is_Access_Type
(Array_Type
) then
5042 Array_Type
:= Designated_Type
(Array_Type
);
5043 Error_Msg_NW
(Warn_On_Dereference
, "?d?implicit dereference", N
);
5046 if not Is_Array_Type
(Array_Type
) then
5047 Wrong_Type
(P
, Any_Array
);
5049 elsif Number_Dimensions
(Array_Type
) > 1 then
5051 ("type is not one-dimensional array in slice prefix", N
);
5054 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
5055 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
5057 Index_Type
:= Etype
(First_Index
(Array_Type
));
5060 if not Has_Compatible_Type
(D
, Index_Type
) then
5061 Wrong_Type
(D
, Index_Type
);
5063 Set_Etype
(N
, Array_Type
);
5069 -----------------------------
5070 -- Analyze_Type_Conversion --
5071 -----------------------------
5073 procedure Analyze_Type_Conversion
(N
: Node_Id
) is
5074 Expr
: constant Node_Id
:= Expression
(N
);
5078 -- If Conversion_OK is set, then the Etype is already set, and the only
5079 -- processing required is to analyze the expression. This is used to
5080 -- construct certain "illegal" conversions which are not allowed by Ada
5081 -- semantics, but can be handled by Gigi, see Sinfo for further details.
5083 if Conversion_OK
(N
) then
5088 -- Otherwise full type analysis is required, as well as some semantic
5089 -- checks to make sure the argument of the conversion is appropriate.
5091 Find_Type
(Subtype_Mark
(N
));
5092 Typ
:= Entity
(Subtype_Mark
(N
));
5094 Check_Fully_Declared
(Typ
, N
);
5095 Analyze_Expression
(Expr
);
5096 Validate_Remote_Type_Type_Conversion
(N
);
5098 -- Only remaining step is validity checks on the argument. These
5099 -- are skipped if the conversion does not come from the source.
5101 if not Comes_From_Source
(N
) then
5104 -- If there was an error in a generic unit, no need to replicate the
5105 -- error message. Conversely, constant-folding in the generic may
5106 -- transform the argument of a conversion into a string literal, which
5107 -- is legal. Therefore the following tests are not performed in an
5108 -- instance. The same applies to an inlined body.
5110 elsif In_Instance
or In_Inlined_Body
then
5113 elsif Nkind
(Expr
) = N_Null
then
5114 Error_Msg_N
("argument of conversion cannot be null", N
);
5115 Error_Msg_N
("\use qualified expression instead", N
);
5116 Set_Etype
(N
, Any_Type
);
5118 elsif Nkind
(Expr
) = N_Aggregate
then
5119 Error_Msg_N
("argument of conversion cannot be aggregate", N
);
5120 Error_Msg_N
("\use qualified expression instead", N
);
5122 elsif Nkind
(Expr
) = N_Allocator
then
5123 Error_Msg_N
("argument of conversion cannot be an allocator", N
);
5124 Error_Msg_N
("\use qualified expression instead", N
);
5126 elsif Nkind
(Expr
) = N_String_Literal
then
5127 Error_Msg_N
("argument of conversion cannot be string literal", N
);
5128 Error_Msg_N
("\use qualified expression instead", N
);
5130 elsif Nkind
(Expr
) = N_Character_Literal
then
5131 if Ada_Version
= Ada_83
then
5132 Resolve
(Expr
, Typ
);
5134 Error_Msg_N
("argument of conversion cannot be character literal",
5136 Error_Msg_N
("\use qualified expression instead", N
);
5139 elsif Nkind
(Expr
) = N_Attribute_Reference
5140 and then Nam_In
(Attribute_Name
(Expr
), Name_Access
,
5141 Name_Unchecked_Access
,
5142 Name_Unrestricted_Access
)
5144 Error_Msg_N
("argument of conversion cannot be access", N
);
5145 Error_Msg_N
("\use qualified expression instead", N
);
5148 -- A formal parameter of a specific tagged type whose related subprogram
5149 -- is subject to pragma Extensions_Visible with value "False" cannot
5150 -- appear in a class-wide conversion (SPARK RM 6.1.7(3)).
5152 if Is_Class_Wide_Type
(Typ
) and then Is_EVF_Expression
(Expr
) then
5154 ("formal parameter with Extensions_Visible False cannot be "
5155 & "converted to class-wide type", Expr
);
5157 end Analyze_Type_Conversion
;
5159 ----------------------
5160 -- Analyze_Unary_Op --
5161 ----------------------
5163 procedure Analyze_Unary_Op
(N
: Node_Id
) is
5164 R
: constant Node_Id
:= Right_Opnd
(N
);
5165 Op_Id
: Entity_Id
:= Entity
(N
);
5168 Set_Etype
(N
, Any_Type
);
5169 Candidate_Type
:= Empty
;
5171 Analyze_Expression
(R
);
5173 if Present
(Op_Id
) then
5174 if Ekind
(Op_Id
) = E_Operator
then
5175 Find_Unary_Types
(R
, Op_Id
, N
);
5177 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5181 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
5182 while Present
(Op_Id
) loop
5183 if Ekind
(Op_Id
) = E_Operator
then
5184 if No
(Next_Entity
(First_Entity
(Op_Id
))) then
5185 Find_Unary_Types
(R
, Op_Id
, N
);
5188 elsif Is_Overloadable
(Op_Id
) then
5189 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
5192 Op_Id
:= Homonym
(Op_Id
);
5197 end Analyze_Unary_Op
;
5199 ----------------------------------
5200 -- Analyze_Unchecked_Expression --
5201 ----------------------------------
5203 procedure Analyze_Unchecked_Expression
(N
: Node_Id
) is
5205 Analyze
(Expression
(N
), Suppress
=> All_Checks
);
5206 Set_Etype
(N
, Etype
(Expression
(N
)));
5207 Save_Interps
(Expression
(N
), N
);
5208 end Analyze_Unchecked_Expression
;
5210 ---------------------------------------
5211 -- Analyze_Unchecked_Type_Conversion --
5212 ---------------------------------------
5214 procedure Analyze_Unchecked_Type_Conversion
(N
: Node_Id
) is
5216 Find_Type
(Subtype_Mark
(N
));
5217 Analyze_Expression
(Expression
(N
));
5218 Set_Etype
(N
, Entity
(Subtype_Mark
(N
)));
5219 end Analyze_Unchecked_Type_Conversion
;
5221 ------------------------------------
5222 -- Analyze_User_Defined_Binary_Op --
5223 ------------------------------------
5225 procedure Analyze_User_Defined_Binary_Op
5230 -- Only do analysis if the operator Comes_From_Source, since otherwise
5231 -- the operator was generated by the expander, and all such operators
5232 -- always refer to the operators in package Standard.
5234 if Comes_From_Source
(N
) then
5236 F1
: constant Entity_Id
:= First_Formal
(Op_Id
);
5237 F2
: constant Entity_Id
:= Next_Formal
(F1
);
5240 -- Verify that Op_Id is a visible binary function. Note that since
5241 -- we know Op_Id is overloaded, potentially use visible means use
5242 -- visible for sure (RM 9.4(11)).
5244 if Ekind
(Op_Id
) = E_Function
5245 and then Present
(F2
)
5246 and then (Is_Immediately_Visible
(Op_Id
)
5247 or else Is_Potentially_Use_Visible
(Op_Id
))
5248 and then Has_Compatible_Type
(Left_Opnd
(N
), Etype
(F1
))
5249 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F2
))
5251 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5253 -- If the left operand is overloaded, indicate that the current
5254 -- type is a viable candidate. This is redundant in most cases,
5255 -- but for equality and comparison operators where the context
5256 -- does not impose a type on the operands, setting the proper
5257 -- type is necessary to avoid subsequent ambiguities during
5258 -- resolution, when both user-defined and predefined operators
5259 -- may be candidates.
5261 if Is_Overloaded
(Left_Opnd
(N
)) then
5262 Set_Etype
(Left_Opnd
(N
), Etype
(F1
));
5265 if Debug_Flag_E
then
5266 Write_Str
("user defined operator ");
5267 Write_Name
(Chars
(Op_Id
));
5268 Write_Str
(" on node ");
5269 Write_Int
(Int
(N
));
5275 end Analyze_User_Defined_Binary_Op
;
5277 -----------------------------------
5278 -- Analyze_User_Defined_Unary_Op --
5279 -----------------------------------
5281 procedure Analyze_User_Defined_Unary_Op
5286 -- Only do analysis if the operator Comes_From_Source, since otherwise
5287 -- the operator was generated by the expander, and all such operators
5288 -- always refer to the operators in package Standard.
5290 if Comes_From_Source
(N
) then
5292 F
: constant Entity_Id
:= First_Formal
(Op_Id
);
5295 -- Verify that Op_Id is a visible unary function. Note that since
5296 -- we know Op_Id is overloaded, potentially use visible means use
5297 -- visible for sure (RM 9.4(11)).
5299 if Ekind
(Op_Id
) = E_Function
5300 and then No
(Next_Formal
(F
))
5301 and then (Is_Immediately_Visible
(Op_Id
)
5302 or else Is_Potentially_Use_Visible
(Op_Id
))
5303 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F
))
5305 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
5309 end Analyze_User_Defined_Unary_Op
;
5311 ---------------------------
5312 -- Check_Arithmetic_Pair --
5313 ---------------------------
5315 procedure Check_Arithmetic_Pair
5316 (T1
, T2
: Entity_Id
;
5320 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
5322 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean;
5323 -- Check whether the fixed-point type Typ has a user-defined operator
5324 -- (multiplication or division) that should hide the corresponding
5325 -- predefined operator. Used to implement Ada 2005 AI-264, to make
5326 -- such operators more visible and therefore useful.
5328 -- If the name of the operation is an expanded name with prefix
5329 -- Standard, the predefined universal fixed operator is available,
5330 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
5332 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
;
5333 -- Get specific type (i.e. non-universal type if there is one)
5339 function Has_Fixed_Op
(Typ
: Entity_Id
; Op
: Entity_Id
) return Boolean is
5340 Bas
: constant Entity_Id
:= Base_Type
(Typ
);
5346 -- If the universal_fixed operation is given explicitly the rule
5347 -- concerning primitive operations of the type do not apply.
5349 if Nkind
(N
) = N_Function_Call
5350 and then Nkind
(Name
(N
)) = N_Expanded_Name
5351 and then Entity
(Prefix
(Name
(N
))) = Standard_Standard
5356 -- The operation is treated as primitive if it is declared in the
5357 -- same scope as the type, and therefore on the same entity chain.
5359 Ent
:= Next_Entity
(Typ
);
5360 while Present
(Ent
) loop
5361 if Chars
(Ent
) = Chars
(Op
) then
5362 F1
:= First_Formal
(Ent
);
5363 F2
:= Next_Formal
(F1
);
5365 -- The operation counts as primitive if either operand or
5366 -- result are of the given base type, and both operands are
5367 -- fixed point types.
5369 if (Base_Type
(Etype
(F1
)) = Bas
5370 and then Is_Fixed_Point_Type
(Etype
(F2
)))
5373 (Base_Type
(Etype
(F2
)) = Bas
5374 and then Is_Fixed_Point_Type
(Etype
(F1
)))
5377 (Base_Type
(Etype
(Ent
)) = Bas
5378 and then Is_Fixed_Point_Type
(Etype
(F1
))
5379 and then Is_Fixed_Point_Type
(Etype
(F2
)))
5395 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
is
5397 if T1
= Universal_Integer
or else T1
= Universal_Real
then
5398 return Base_Type
(T2
);
5400 return Base_Type
(T1
);
5404 -- Start of processing for Check_Arithmetic_Pair
5407 if Nam_In
(Op_Name
, Name_Op_Add
, Name_Op_Subtract
) then
5408 if Is_Numeric_Type
(T1
)
5409 and then Is_Numeric_Type
(T2
)
5410 and then (Covers
(T1
=> T1
, T2
=> T2
)
5412 Covers
(T1
=> T2
, T2
=> T1
))
5414 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5417 elsif Nam_In
(Op_Name
, Name_Op_Multiply
, Name_Op_Divide
) then
5418 if Is_Fixed_Point_Type
(T1
)
5419 and then (Is_Fixed_Point_Type
(T2
) or else T2
= Universal_Real
)
5421 -- If Treat_Fixed_As_Integer is set then the Etype is already set
5422 -- and no further processing is required (this is the case of an
5423 -- operator constructed by Exp_Fixd for a fixed point operation)
5424 -- Otherwise add one interpretation with universal fixed result
5425 -- If the operator is given in functional notation, it comes
5426 -- from source and Fixed_As_Integer cannot apply.
5428 if (Nkind
(N
) not in N_Op
5429 or else not Treat_Fixed_As_Integer
(N
))
5431 (not Has_Fixed_Op
(T1
, Op_Id
)
5432 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
5434 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
5437 elsif Is_Fixed_Point_Type
(T2
)
5438 and then (Nkind
(N
) not in N_Op
5439 or else not Treat_Fixed_As_Integer
(N
))
5440 and then T1
= Universal_Real
5442 (not Has_Fixed_Op
(T1
, Op_Id
)
5443 or else Nkind
(Parent
(N
)) = N_Type_Conversion
)
5445 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
5447 elsif Is_Numeric_Type
(T1
)
5448 and then Is_Numeric_Type
(T2
)
5449 and then (Covers
(T1
=> T1
, T2
=> T2
)
5451 Covers
(T1
=> T2
, T2
=> T1
))
5453 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5455 elsif Is_Fixed_Point_Type
(T1
)
5456 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5457 or else T2
= Universal_Integer
)
5459 Add_One_Interp
(N
, Op_Id
, T1
);
5461 elsif T2
= Universal_Real
5462 and then Base_Type
(T1
) = Base_Type
(Standard_Integer
)
5463 and then Op_Name
= Name_Op_Multiply
5465 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
5467 elsif T1
= Universal_Real
5468 and then Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5470 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
5472 elsif Is_Fixed_Point_Type
(T2
)
5473 and then (Base_Type
(T1
) = Base_Type
(Standard_Integer
)
5474 or else T1
= Universal_Integer
)
5475 and then Op_Name
= Name_Op_Multiply
5477 Add_One_Interp
(N
, Op_Id
, T2
);
5479 elsif T1
= Universal_Real
and then T2
= Universal_Integer
then
5480 Add_One_Interp
(N
, Op_Id
, T1
);
5482 elsif T2
= Universal_Real
5483 and then T1
= Universal_Integer
5484 and then Op_Name
= Name_Op_Multiply
5486 Add_One_Interp
(N
, Op_Id
, T2
);
5489 elsif Op_Name
= Name_Op_Mod
or else Op_Name
= Name_Op_Rem
then
5491 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
5492 -- set does not require any special processing, since the Etype is
5493 -- already set (case of operation constructed by Exp_Fixed).
5495 if Is_Integer_Type
(T1
)
5496 and then (Covers
(T1
=> T1
, T2
=> T2
)
5498 Covers
(T1
=> T2
, T2
=> T1
))
5500 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
5503 elsif Op_Name
= Name_Op_Expon
then
5504 if Is_Numeric_Type
(T1
)
5505 and then not Is_Fixed_Point_Type
(T1
)
5506 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5507 or else T2
= Universal_Integer
)
5509 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
5512 else pragma Assert
(Nkind
(N
) in N_Op_Shift
);
5514 -- If not one of the predefined operators, the node may be one
5515 -- of the intrinsic functions. Its kind is always specific, and
5516 -- we can use it directly, rather than the name of the operation.
5518 if Is_Integer_Type
(T1
)
5519 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
5520 or else T2
= Universal_Integer
)
5522 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
5525 end Check_Arithmetic_Pair
;
5527 -------------------------------
5528 -- Check_Misspelled_Selector --
5529 -------------------------------
5531 procedure Check_Misspelled_Selector
5532 (Prefix
: Entity_Id
;
5535 Max_Suggestions
: constant := 2;
5536 Nr_Of_Suggestions
: Natural := 0;
5538 Suggestion_1
: Entity_Id
:= Empty
;
5539 Suggestion_2
: Entity_Id
:= Empty
;
5544 -- All the components of the prefix of selector Sel are matched against
5545 -- Sel and a count is maintained of possible misspellings. When at
5546 -- the end of the analysis there are one or two (not more) possible
5547 -- misspellings, these misspellings will be suggested as possible
5550 if not (Is_Private_Type
(Prefix
) or else Is_Record_Type
(Prefix
)) then
5552 -- Concurrent types should be handled as well ???
5557 Comp
:= First_Entity
(Prefix
);
5558 while Nr_Of_Suggestions
<= Max_Suggestions
and then Present
(Comp
) loop
5559 if Is_Visible_Component
(Comp
) then
5560 if Is_Bad_Spelling_Of
(Chars
(Comp
), Chars
(Sel
)) then
5561 Nr_Of_Suggestions
:= Nr_Of_Suggestions
+ 1;
5563 case Nr_Of_Suggestions
is
5564 when 1 => Suggestion_1
:= Comp
;
5565 when 2 => Suggestion_2
:= Comp
;
5566 when others => exit;
5571 Comp
:= Next_Entity
(Comp
);
5574 -- Report at most two suggestions
5576 if Nr_Of_Suggestions
= 1 then
5577 Error_Msg_NE
-- CODEFIX
5578 ("\possible misspelling of&", Sel
, Suggestion_1
);
5580 elsif Nr_Of_Suggestions
= 2 then
5581 Error_Msg_Node_2
:= Suggestion_2
;
5582 Error_Msg_NE
-- CODEFIX
5583 ("\possible misspelling of& or&", Sel
, Suggestion_1
);
5585 end Check_Misspelled_Selector
;
5587 ----------------------
5588 -- Defined_In_Scope --
5589 ----------------------
5591 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean
5593 S1
: constant Entity_Id
:= Scope
(Base_Type
(T
));
5596 or else (S1
= System_Aux_Id
and then S
= Scope
(S1
));
5597 end Defined_In_Scope
;
5603 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
) is
5609 Void_Interp_Seen
: Boolean := False;
5612 pragma Warnings
(Off
, Boolean);
5615 if Ada_Version
>= Ada_2005
then
5616 Actual
:= First_Actual
(N
);
5617 while Present
(Actual
) loop
5619 -- Ada 2005 (AI-50217): Post an error in case of premature
5620 -- usage of an entity from the limited view.
5622 if not Analyzed
(Etype
(Actual
))
5623 and then From_Limited_With
(Etype
(Actual
))
5625 Error_Msg_Qual_Level
:= 1;
5627 ("missing with_clause for scope of imported type&",
5628 Actual
, Etype
(Actual
));
5629 Error_Msg_Qual_Level
:= 0;
5632 Next_Actual
(Actual
);
5636 -- Analyze each candidate call again, with full error reporting
5640 ("no candidate interpretations match the actuals:!", Nam
);
5641 Err_Mode
:= All_Errors_Mode
;
5642 All_Errors_Mode
:= True;
5644 -- If this is a call to an operation of a concurrent type,
5645 -- the failed interpretations have been removed from the
5646 -- name. Recover them to provide full diagnostics.
5648 if Nkind
(Parent
(Nam
)) = N_Selected_Component
then
5649 Set_Entity
(Nam
, Empty
);
5650 New_Nam
:= New_Copy_Tree
(Parent
(Nam
));
5651 Set_Is_Overloaded
(New_Nam
, False);
5652 Set_Is_Overloaded
(Selector_Name
(New_Nam
), False);
5653 Set_Parent
(New_Nam
, Parent
(Parent
(Nam
)));
5654 Analyze_Selected_Component
(New_Nam
);
5655 Get_First_Interp
(Selector_Name
(New_Nam
), X
, It
);
5657 Get_First_Interp
(Nam
, X
, It
);
5660 while Present
(It
.Nam
) loop
5661 if Etype
(It
.Nam
) = Standard_Void_Type
then
5662 Void_Interp_Seen
:= True;
5665 Analyze_One_Call
(N
, It
.Nam
, True, Success
);
5666 Get_Next_Interp
(X
, It
);
5669 if Nkind
(N
) = N_Function_Call
then
5670 Get_First_Interp
(Nam
, X
, It
);
5671 while Present
(It
.Nam
) loop
5672 if Ekind_In
(It
.Nam
, E_Function
, E_Operator
) then
5675 Get_Next_Interp
(X
, It
);
5679 -- If all interpretations are procedures, this deserves a
5680 -- more precise message. Ditto if this appears as the prefix
5681 -- of a selected component, which may be a lexical error.
5684 ("\context requires function call, found procedure name", Nam
);
5686 if Nkind
(Parent
(N
)) = N_Selected_Component
5687 and then N
= Prefix
(Parent
(N
))
5689 Error_Msg_N
-- CODEFIX
5690 ("\period should probably be semicolon", Parent
(N
));
5693 elsif Nkind
(N
) = N_Procedure_Call_Statement
5694 and then not Void_Interp_Seen
5697 "\function name found in procedure call", Nam
);
5700 All_Errors_Mode
:= Err_Mode
;
5703 ---------------------------
5704 -- Find_Arithmetic_Types --
5705 ---------------------------
5707 procedure Find_Arithmetic_Types
5712 Index1
: Interp_Index
;
5713 Index2
: Interp_Index
;
5717 procedure Check_Right_Argument
(T
: Entity_Id
);
5718 -- Check right operand of operator
5720 --------------------------
5721 -- Check_Right_Argument --
5722 --------------------------
5724 procedure Check_Right_Argument
(T
: Entity_Id
) is
5726 if not Is_Overloaded
(R
) then
5727 Check_Arithmetic_Pair
(T
, Etype
(R
), Op_Id
, N
);
5729 Get_First_Interp
(R
, Index2
, It2
);
5730 while Present
(It2
.Typ
) loop
5731 Check_Arithmetic_Pair
(T
, It2
.Typ
, Op_Id
, N
);
5732 Get_Next_Interp
(Index2
, It2
);
5735 end Check_Right_Argument
;
5737 -- Start of processing for Find_Arithmetic_Types
5740 if not Is_Overloaded
(L
) then
5741 Check_Right_Argument
(Etype
(L
));
5744 Get_First_Interp
(L
, Index1
, It1
);
5745 while Present
(It1
.Typ
) loop
5746 Check_Right_Argument
(It1
.Typ
);
5747 Get_Next_Interp
(Index1
, It1
);
5751 end Find_Arithmetic_Types
;
5753 ------------------------
5754 -- Find_Boolean_Types --
5755 ------------------------
5757 procedure Find_Boolean_Types
5762 Index
: Interp_Index
;
5765 procedure Check_Numeric_Argument
(T
: Entity_Id
);
5766 -- Special case for logical operations one of whose operands is an
5767 -- integer literal. If both are literal the result is any modular type.
5769 ----------------------------
5770 -- Check_Numeric_Argument --
5771 ----------------------------
5773 procedure Check_Numeric_Argument
(T
: Entity_Id
) is
5775 if T
= Universal_Integer
then
5776 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
5778 elsif Is_Modular_Integer_Type
(T
) then
5779 Add_One_Interp
(N
, Op_Id
, T
);
5781 end Check_Numeric_Argument
;
5783 -- Start of processing for Find_Boolean_Types
5786 if not Is_Overloaded
(L
) then
5787 if Etype
(L
) = Universal_Integer
5788 or else Etype
(L
) = Any_Modular
5790 if not Is_Overloaded
(R
) then
5791 Check_Numeric_Argument
(Etype
(R
));
5794 Get_First_Interp
(R
, Index
, It
);
5795 while Present
(It
.Typ
) loop
5796 Check_Numeric_Argument
(It
.Typ
);
5797 Get_Next_Interp
(Index
, It
);
5801 -- If operands are aggregates, we must assume that they may be
5802 -- boolean arrays, and leave disambiguation for the second pass.
5803 -- If only one is an aggregate, verify that the other one has an
5804 -- interpretation as a boolean array
5806 elsif Nkind
(L
) = N_Aggregate
then
5807 if Nkind
(R
) = N_Aggregate
then
5808 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
5810 elsif not Is_Overloaded
(R
) then
5811 if Valid_Boolean_Arg
(Etype
(R
)) then
5812 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
5816 Get_First_Interp
(R
, Index
, It
);
5817 while Present
(It
.Typ
) loop
5818 if Valid_Boolean_Arg
(It
.Typ
) then
5819 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
5822 Get_Next_Interp
(Index
, It
);
5826 elsif Valid_Boolean_Arg
(Etype
(L
))
5827 and then Has_Compatible_Type
(R
, Etype
(L
))
5829 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
5833 Get_First_Interp
(L
, Index
, It
);
5834 while Present
(It
.Typ
) loop
5835 if Valid_Boolean_Arg
(It
.Typ
)
5836 and then Has_Compatible_Type
(R
, It
.Typ
)
5838 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
5841 Get_Next_Interp
(Index
, It
);
5844 end Find_Boolean_Types
;
5846 ---------------------------
5847 -- Find_Comparison_Types --
5848 ---------------------------
5850 procedure Find_Comparison_Types
5855 Index
: Interp_Index
;
5857 Found
: Boolean := False;
5860 Scop
: Entity_Id
:= Empty
;
5862 procedure Try_One_Interp
(T1
: Entity_Id
);
5863 -- Routine to try one proposed interpretation. Note that the context
5864 -- of the operator plays no role in resolving the arguments, so that
5865 -- if there is more than one interpretation of the operands that is
5866 -- compatible with comparison, the operation is ambiguous.
5868 --------------------
5869 -- Try_One_Interp --
5870 --------------------
5872 procedure Try_One_Interp
(T1
: Entity_Id
) is
5875 -- If the operator is an expanded name, then the type of the operand
5876 -- must be defined in the corresponding scope. If the type is
5877 -- universal, the context will impose the correct type.
5880 and then not Defined_In_Scope
(T1
, Scop
)
5881 and then T1
/= Universal_Integer
5882 and then T1
/= Universal_Real
5883 and then T1
/= Any_String
5884 and then T1
/= Any_Composite
5889 if Valid_Comparison_Arg
(T1
) and then Has_Compatible_Type
(R
, T1
) then
5890 if Found
and then Base_Type
(T1
) /= Base_Type
(T_F
) then
5891 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
5893 if It
= No_Interp
then
5894 Ambiguous_Operands
(N
);
5895 Set_Etype
(L
, Any_Type
);
5909 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
5914 -- Start of processing for Find_Comparison_Types
5917 -- If left operand is aggregate, the right operand has to
5918 -- provide a usable type for it.
5920 if Nkind
(L
) = N_Aggregate
and then Nkind
(R
) /= N_Aggregate
then
5921 Find_Comparison_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
5925 if Nkind
(N
) = N_Function_Call
5926 and then Nkind
(Name
(N
)) = N_Expanded_Name
5928 Scop
:= Entity
(Prefix
(Name
(N
)));
5930 -- The prefix may be a package renaming, and the subsequent test
5931 -- requires the original package.
5933 if Ekind
(Scop
) = E_Package
5934 and then Present
(Renamed_Entity
(Scop
))
5936 Scop
:= Renamed_Entity
(Scop
);
5937 Set_Entity
(Prefix
(Name
(N
)), Scop
);
5941 if not Is_Overloaded
(L
) then
5942 Try_One_Interp
(Etype
(L
));
5945 Get_First_Interp
(L
, Index
, It
);
5946 while Present
(It
.Typ
) loop
5947 Try_One_Interp
(It
.Typ
);
5948 Get_Next_Interp
(Index
, It
);
5951 end Find_Comparison_Types
;
5953 ----------------------------------------
5954 -- Find_Non_Universal_Interpretations --
5955 ----------------------------------------
5957 procedure Find_Non_Universal_Interpretations
5963 Index
: Interp_Index
;
5967 if T1
= Universal_Integer
or else T1
= Universal_Real
5969 -- If the left operand of an equality operator is null, the visibility
5970 -- of the operator must be determined from the interpretation of the
5971 -- right operand. This processing must be done for Any_Access, which
5972 -- is the internal representation of the type of the literal null.
5974 or else T1
= Any_Access
5976 if not Is_Overloaded
(R
) then
5977 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(Etype
(R
)));
5979 Get_First_Interp
(R
, Index
, It
);
5980 while Present
(It
.Typ
) loop
5981 if Covers
(It
.Typ
, T1
) then
5983 (N
, Op_Id
, Standard_Boolean
, Base_Type
(It
.Typ
));
5986 Get_Next_Interp
(Index
, It
);
5990 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(T1
));
5992 end Find_Non_Universal_Interpretations
;
5994 ------------------------------
5995 -- Find_Concatenation_Types --
5996 ------------------------------
5998 procedure Find_Concatenation_Types
6003 Op_Type
: constant Entity_Id
:= Etype
(Op_Id
);
6006 if Is_Array_Type
(Op_Type
)
6007 and then not Is_Limited_Type
(Op_Type
)
6009 and then (Has_Compatible_Type
(L
, Op_Type
)
6011 Has_Compatible_Type
(L
, Component_Type
(Op_Type
)))
6013 and then (Has_Compatible_Type
(R
, Op_Type
)
6015 Has_Compatible_Type
(R
, Component_Type
(Op_Type
)))
6017 Add_One_Interp
(N
, Op_Id
, Op_Type
);
6019 end Find_Concatenation_Types
;
6021 -------------------------
6022 -- Find_Equality_Types --
6023 -------------------------
6025 procedure Find_Equality_Types
6030 Index
: Interp_Index
;
6032 Found
: Boolean := False;
6035 Scop
: Entity_Id
:= Empty
;
6037 procedure Try_One_Interp
(T1
: Entity_Id
);
6038 -- The context of the equality operator plays no role in resolving the
6039 -- arguments, so that if there is more than one interpretation of the
6040 -- operands that is compatible with equality, the construct is ambiguous
6041 -- and an error can be emitted now, after trying to disambiguate, i.e.
6042 -- applying preference rules.
6044 --------------------
6045 -- Try_One_Interp --
6046 --------------------
6048 procedure Try_One_Interp
(T1
: Entity_Id
) is
6049 Bas
: constant Entity_Id
:= Base_Type
(T1
);
6052 -- If the operator is an expanded name, then the type of the operand
6053 -- must be defined in the corresponding scope. If the type is
6054 -- universal, the context will impose the correct type. An anonymous
6055 -- type for a 'Access reference is also universal in this sense, as
6056 -- the actual type is obtained from context.
6058 -- In Ada 2005, the equality operator for anonymous access types
6059 -- is declared in Standard, and preference rules apply to it.
6061 if Present
(Scop
) then
6062 if Defined_In_Scope
(T1
, Scop
)
6063 or else T1
= Universal_Integer
6064 or else T1
= Universal_Real
6065 or else T1
= Any_Access
6066 or else T1
= Any_String
6067 or else T1
= Any_Composite
6068 or else (Ekind
(T1
) = E_Access_Subprogram_Type
6069 and then not Comes_From_Source
(T1
))
6073 elsif Ekind
(T1
) = E_Anonymous_Access_Type
6074 and then Scop
= Standard_Standard
6079 -- The scope does not contain an operator for the type
6084 -- If we have infix notation, the operator must be usable. Within
6085 -- an instance, if the type is already established we know it is
6086 -- correct. If an operand is universal it is compatible with any
6089 elsif In_Open_Scopes
(Scope
(Bas
))
6090 or else Is_Potentially_Use_Visible
(Bas
)
6091 or else In_Use
(Bas
)
6092 or else (In_Use
(Scope
(Bas
)) and then not Is_Hidden
(Bas
))
6094 -- In an instance, the type may have been immediately visible.
6095 -- Either the types are compatible, or one operand is universal
6096 -- (numeric or null).
6098 or else (In_Instance
6100 (First_Subtype
(T1
) = First_Subtype
(Etype
(R
))
6101 or else Nkind
(R
) = N_Null
6103 (Is_Numeric_Type
(T1
)
6104 and then Is_Universal_Numeric_Type
(Etype
(R
)))))
6106 -- In Ada 2005, the equality on anonymous access types is declared
6107 -- in Standard, and is always visible.
6109 or else Ekind
(T1
) = E_Anonymous_Access_Type
6114 -- Save candidate type for subsequent error message, if any
6116 if not Is_Limited_Type
(T1
) then
6117 Candidate_Type
:= T1
;
6123 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
6124 -- Do not allow anonymous access types in equality operators.
6126 if Ada_Version
< Ada_2005
6127 and then Ekind
(T1
) = E_Anonymous_Access_Type
6132 -- If the right operand has a type compatible with T1, check for an
6133 -- acceptable interpretation, unless T1 is limited (no predefined
6134 -- equality available), or this is use of a "/=" for a tagged type.
6135 -- In the latter case, possible interpretations of equality need
6136 -- to be considered, we don't want the default inequality declared
6137 -- in Standard to be chosen, and the "/=" will be rewritten as a
6138 -- negation of "=" (see the end of Analyze_Equality_Op). This ensures
6139 -- that rewriting happens during analysis rather than being
6140 -- delayed until expansion (this is needed for ASIS, which only sees
6141 -- the unexpanded tree). Note that if the node is N_Op_Ne, but Op_Id
6142 -- is Name_Op_Eq then we still proceed with the interpretation,
6143 -- because that indicates the potential rewriting case where the
6144 -- interpretation to consider is actually "=" and the node may be
6145 -- about to be rewritten by Analyze_Equality_Op.
6147 if T1
/= Standard_Void_Type
6148 and then Has_Compatible_Type
(R
, T1
)
6151 ((not Is_Limited_Type
(T1
)
6152 and then not Is_Limited_Composite
(T1
))
6156 and then not Is_Limited_Type
(Component_Type
(T1
))
6157 and then Available_Full_View_Of_Component
(T1
)))
6160 (Nkind
(N
) /= N_Op_Ne
6161 or else not Is_Tagged_Type
(T1
)
6162 or else Chars
(Op_Id
) = Name_Op_Eq
)
6165 and then Base_Type
(T1
) /= Base_Type
(T_F
)
6167 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
6169 if It
= No_Interp
then
6170 Ambiguous_Operands
(N
);
6171 Set_Etype
(L
, Any_Type
);
6184 if not Analyzed
(L
) then
6188 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
6190 -- Case of operator was not visible, Etype still set to Any_Type
6192 if Etype
(N
) = Any_Type
then
6196 elsif Scop
= Standard_Standard
6197 and then Ekind
(T1
) = E_Anonymous_Access_Type
6203 -- Start of processing for Find_Equality_Types
6206 -- If left operand is aggregate, the right operand has to
6207 -- provide a usable type for it.
6209 if Nkind
(L
) = N_Aggregate
6210 and then Nkind
(R
) /= N_Aggregate
6212 Find_Equality_Types
(L
=> R
, R
=> L
, Op_Id
=> Op_Id
, N
=> N
);
6216 if Nkind
(N
) = N_Function_Call
6217 and then Nkind
(Name
(N
)) = N_Expanded_Name
6219 Scop
:= Entity
(Prefix
(Name
(N
)));
6221 -- The prefix may be a package renaming, and the subsequent test
6222 -- requires the original package.
6224 if Ekind
(Scop
) = E_Package
6225 and then Present
(Renamed_Entity
(Scop
))
6227 Scop
:= Renamed_Entity
(Scop
);
6228 Set_Entity
(Prefix
(Name
(N
)), Scop
);
6232 if not Is_Overloaded
(L
) then
6233 Try_One_Interp
(Etype
(L
));
6236 Get_First_Interp
(L
, Index
, It
);
6237 while Present
(It
.Typ
) loop
6238 Try_One_Interp
(It
.Typ
);
6239 Get_Next_Interp
(Index
, It
);
6242 end Find_Equality_Types
;
6244 -------------------------
6245 -- Find_Negation_Types --
6246 -------------------------
6248 procedure Find_Negation_Types
6253 Index
: Interp_Index
;
6257 if not Is_Overloaded
(R
) then
6258 if Etype
(R
) = Universal_Integer
then
6259 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
6260 elsif Valid_Boolean_Arg
(Etype
(R
)) then
6261 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
6265 Get_First_Interp
(R
, Index
, It
);
6266 while Present
(It
.Typ
) loop
6267 if Valid_Boolean_Arg
(It
.Typ
) then
6268 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
6271 Get_Next_Interp
(Index
, It
);
6274 end Find_Negation_Types
;
6276 ------------------------------
6277 -- Find_Primitive_Operation --
6278 ------------------------------
6280 function Find_Primitive_Operation
(N
: Node_Id
) return Boolean is
6281 Obj
: constant Node_Id
:= Prefix
(N
);
6282 Op
: constant Node_Id
:= Selector_Name
(N
);
6289 Set_Etype
(Op
, Any_Type
);
6291 if Is_Access_Type
(Etype
(Obj
)) then
6292 Typ
:= Designated_Type
(Etype
(Obj
));
6297 if Is_Class_Wide_Type
(Typ
) then
6298 Typ
:= Root_Type
(Typ
);
6301 Prims
:= Primitive_Operations
(Typ
);
6303 Prim
:= First_Elmt
(Prims
);
6304 while Present
(Prim
) loop
6305 if Chars
(Node
(Prim
)) = Chars
(Op
) then
6306 Add_One_Interp
(Op
, Node
(Prim
), Etype
(Node
(Prim
)));
6307 Set_Etype
(N
, Etype
(Node
(Prim
)));
6313 -- Now look for class-wide operations of the type or any of its
6314 -- ancestors by iterating over the homonyms of the selector.
6317 Cls_Type
: constant Entity_Id
:= Class_Wide_Type
(Typ
);
6321 Hom
:= Current_Entity
(Op
);
6322 while Present
(Hom
) loop
6323 if (Ekind
(Hom
) = E_Procedure
6325 Ekind
(Hom
) = E_Function
)
6326 and then Scope
(Hom
) = Scope
(Typ
)
6327 and then Present
(First_Formal
(Hom
))
6329 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
6331 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
6333 Ekind
(Etype
(First_Formal
(Hom
))) =
6334 E_Anonymous_Access_Type
6337 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
6340 Add_One_Interp
(Op
, Hom
, Etype
(Hom
));
6341 Set_Etype
(N
, Etype
(Hom
));
6344 Hom
:= Homonym
(Hom
);
6348 return Etype
(Op
) /= Any_Type
;
6349 end Find_Primitive_Operation
;
6351 ----------------------
6352 -- Find_Unary_Types --
6353 ----------------------
6355 procedure Find_Unary_Types
6360 Index
: Interp_Index
;
6364 if not Is_Overloaded
(R
) then
6365 if Is_Numeric_Type
(Etype
(R
)) then
6367 -- In an instance a generic actual may be a numeric type even if
6368 -- the formal in the generic unit was not. In that case, the
6369 -- predefined operator was not a possible interpretation in the
6370 -- generic, and cannot be one in the instance, unless the operator
6371 -- is an actual of an instance.
6375 not Is_Numeric_Type
(Corresponding_Generic_Type
(Etype
(R
)))
6379 Add_One_Interp
(N
, Op_Id
, Base_Type
(Etype
(R
)));
6384 Get_First_Interp
(R
, Index
, It
);
6385 while Present
(It
.Typ
) loop
6386 if Is_Numeric_Type
(It
.Typ
) then
6390 (Corresponding_Generic_Type
(Etype
(It
.Typ
)))
6395 Add_One_Interp
(N
, Op_Id
, Base_Type
(It
.Typ
));
6399 Get_Next_Interp
(Index
, It
);
6402 end Find_Unary_Types
;
6408 function Junk_Operand
(N
: Node_Id
) return Boolean is
6412 if Error_Posted
(N
) then
6416 -- Get entity to be tested
6418 if Is_Entity_Name
(N
)
6419 and then Present
(Entity
(N
))
6423 -- An odd case, a procedure name gets converted to a very peculiar
6424 -- function call, and here is where we detect this happening.
6426 elsif Nkind
(N
) = N_Function_Call
6427 and then Is_Entity_Name
(Name
(N
))
6428 and then Present
(Entity
(Name
(N
)))
6432 -- Another odd case, there are at least some cases of selected
6433 -- components where the selected component is not marked as having
6434 -- an entity, even though the selector does have an entity
6436 elsif Nkind
(N
) = N_Selected_Component
6437 and then Present
(Entity
(Selector_Name
(N
)))
6439 Enode
:= Selector_Name
(N
);
6445 -- Now test the entity we got to see if it is a bad case
6447 case Ekind
(Entity
(Enode
)) is
6451 ("package name cannot be used as operand", Enode
);
6453 when Generic_Unit_Kind
=>
6455 ("generic unit name cannot be used as operand", Enode
);
6459 ("subtype name cannot be used as operand", Enode
);
6463 ("entry name cannot be used as operand", Enode
);
6467 ("procedure name cannot be used as operand", Enode
);
6471 ("exception name cannot be used as operand", Enode
);
6473 when E_Block | E_Label | E_Loop
=>
6475 ("label name cannot be used as operand", Enode
);
6485 --------------------
6486 -- Operator_Check --
6487 --------------------
6489 procedure Operator_Check
(N
: Node_Id
) is
6491 Remove_Abstract_Operations
(N
);
6493 -- Test for case of no interpretation found for operator
6495 if Etype
(N
) = Any_Type
then
6499 Op_Id
: Entity_Id
:= Empty
;
6502 R
:= Right_Opnd
(N
);
6504 if Nkind
(N
) in N_Binary_Op
then
6510 -- If either operand has no type, then don't complain further,
6511 -- since this simply means that we have a propagated error.
6514 or else Etype
(R
) = Any_Type
6515 or else (Nkind
(N
) in N_Binary_Op
and then Etype
(L
) = Any_Type
)
6517 -- For the rather unusual case where one of the operands is
6518 -- a Raise_Expression, whose initial type is Any_Type, use
6519 -- the type of the other operand.
6521 if Nkind
(L
) = N_Raise_Expression
then
6522 Set_Etype
(L
, Etype
(R
));
6523 Set_Etype
(N
, Etype
(R
));
6525 elsif Nkind
(R
) = N_Raise_Expression
then
6526 Set_Etype
(R
, Etype
(L
));
6527 Set_Etype
(N
, Etype
(L
));
6532 -- We explicitly check for the case of concatenation of component
6533 -- with component to avoid reporting spurious matching array types
6534 -- that might happen to be lurking in distant packages (such as
6535 -- run-time packages). This also prevents inconsistencies in the
6536 -- messages for certain ACVC B tests, which can vary depending on
6537 -- types declared in run-time interfaces. Another improvement when
6538 -- aggregates are present is to look for a well-typed operand.
6540 elsif Present
(Candidate_Type
)
6541 and then (Nkind
(N
) /= N_Op_Concat
6542 or else Is_Array_Type
(Etype
(L
))
6543 or else Is_Array_Type
(Etype
(R
)))
6545 if Nkind
(N
) = N_Op_Concat
then
6546 if Etype
(L
) /= Any_Composite
6547 and then Is_Array_Type
(Etype
(L
))
6549 Candidate_Type
:= Etype
(L
);
6551 elsif Etype
(R
) /= Any_Composite
6552 and then Is_Array_Type
(Etype
(R
))
6554 Candidate_Type
:= Etype
(R
);
6558 Error_Msg_NE
-- CODEFIX
6559 ("operator for} is not directly visible!",
6560 N
, First_Subtype
(Candidate_Type
));
6563 U
: constant Node_Id
:=
6564 Cunit
(Get_Source_Unit
(Candidate_Type
));
6566 if Unit_Is_Visible
(U
) then
6567 Error_Msg_N
-- CODEFIX
6568 ("use clause would make operation legal!", N
);
6570 Error_Msg_NE
-- CODEFIX
6571 ("add with_clause and use_clause for&!",
6572 N
, Defining_Entity
(Unit
(U
)));
6577 -- If either operand is a junk operand (e.g. package name), then
6578 -- post appropriate error messages, but do not complain further.
6580 -- Note that the use of OR in this test instead of OR ELSE is
6581 -- quite deliberate, we may as well check both operands in the
6582 -- binary operator case.
6584 elsif Junk_Operand
(R
)
6585 or -- really mean OR here and not OR ELSE, see above
6586 (Nkind
(N
) in N_Binary_Op
and then Junk_Operand
(L
))
6590 -- If we have a logical operator, one of whose operands is
6591 -- Boolean, then we know that the other operand cannot resolve to
6592 -- Boolean (since we got no interpretations), but in that case we
6593 -- pretty much know that the other operand should be Boolean, so
6594 -- resolve it that way (generating an error)
6596 elsif Nkind_In
(N
, N_Op_And
, N_Op_Or
, N_Op_Xor
) then
6597 if Etype
(L
) = Standard_Boolean
then
6598 Resolve
(R
, Standard_Boolean
);
6600 elsif Etype
(R
) = Standard_Boolean
then
6601 Resolve
(L
, Standard_Boolean
);
6605 -- For an arithmetic operator or comparison operator, if one
6606 -- of the operands is numeric, then we know the other operand
6607 -- is not the same numeric type. If it is a non-numeric type,
6608 -- then probably it is intended to match the other operand.
6610 elsif Nkind_In
(N
, N_Op_Add
,
6616 Nkind_In
(N
, N_Op_Lt
,
6622 -- If Allow_Integer_Address is active, check whether the
6623 -- operation becomes legal after converting an operand.
6625 if Is_Numeric_Type
(Etype
(L
))
6626 and then not Is_Numeric_Type
(Etype
(R
))
6628 if Address_Integer_Convert_OK
(Etype
(R
), Etype
(L
)) then
6630 Unchecked_Convert_To
(Etype
(L
), Relocate_Node
(R
)));
6632 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6633 Analyze_Comparison_Op
(N
);
6635 Analyze_Arithmetic_Op
(N
);
6638 Resolve
(R
, Etype
(L
));
6643 elsif Is_Numeric_Type
(Etype
(R
))
6644 and then not Is_Numeric_Type
(Etype
(L
))
6646 if Address_Integer_Convert_OK
(Etype
(L
), Etype
(R
)) then
6648 Unchecked_Convert_To
(Etype
(R
), Relocate_Node
(L
)));
6650 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6651 Analyze_Comparison_Op
(N
);
6653 Analyze_Arithmetic_Op
(N
);
6659 Resolve
(L
, Etype
(R
));
6664 elsif Allow_Integer_Address
6665 and then Is_Descendent_Of_Address
(Etype
(L
))
6666 and then Is_Descendent_Of_Address
(Etype
(R
))
6667 and then not Error_Posted
(N
)
6670 Addr_Type
: constant Entity_Id
:= Etype
(L
);
6674 Unchecked_Convert_To
(
6675 Standard_Integer
, Relocate_Node
(L
)));
6677 Unchecked_Convert_To
(
6678 Standard_Integer
, Relocate_Node
(R
)));
6680 if Nkind_In
(N
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
) then
6681 Analyze_Comparison_Op
(N
);
6683 Analyze_Arithmetic_Op
(N
);
6686 -- If this is an operand in an enclosing arithmetic
6687 -- operation, Convert the result as an address so that
6688 -- arithmetic folding of address can continue.
6690 if Nkind
(Parent
(N
)) in N_Op
then
6692 Unchecked_Convert_To
(Addr_Type
, Relocate_Node
(N
)));
6699 -- Comparisons on A'Access are common enough to deserve a
6702 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
)
6703 and then Ekind
(Etype
(L
)) = E_Access_Attribute_Type
6704 and then Ekind
(Etype
(R
)) = E_Access_Attribute_Type
6707 ("two access attributes cannot be compared directly", N
);
6709 ("\use qualified expression for one of the operands",
6713 -- Another one for C programmers
6715 elsif Nkind
(N
) = N_Op_Concat
6716 and then Valid_Boolean_Arg
(Etype
(L
))
6717 and then Valid_Boolean_Arg
(Etype
(R
))
6719 Error_Msg_N
("invalid operands for concatenation", N
);
6720 Error_Msg_N
-- CODEFIX
6721 ("\maybe AND was meant", N
);
6724 -- A special case for comparison of access parameter with null
6726 elsif Nkind
(N
) = N_Op_Eq
6727 and then Is_Entity_Name
(L
)
6728 and then Nkind
(Parent
(Entity
(L
))) = N_Parameter_Specification
6729 and then Nkind
(Parameter_Type
(Parent
(Entity
(L
)))) =
6731 and then Nkind
(R
) = N_Null
6733 Error_Msg_N
("access parameter is not allowed to be null", L
);
6734 Error_Msg_N
("\(call would raise Constraint_Error)", L
);
6737 -- Another special case for exponentiation, where the right
6738 -- operand must be Natural, independently of the base.
6740 elsif Nkind
(N
) = N_Op_Expon
6741 and then Is_Numeric_Type
(Etype
(L
))
6742 and then not Is_Overloaded
(R
)
6744 First_Subtype
(Base_Type
(Etype
(R
))) /= Standard_Integer
6745 and then Base_Type
(Etype
(R
)) /= Universal_Integer
6747 if Ada_Version
>= Ada_2012
6748 and then Has_Dimension_System
(Etype
(L
))
6751 ("exponent for dimensioned type must be a rational" &
6752 ", found}", R
, Etype
(R
));
6755 ("exponent must be of type Natural, found}", R
, Etype
(R
));
6760 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ne
) then
6761 if Address_Integer_Convert_OK
(Etype
(R
), Etype
(L
)) then
6763 Unchecked_Convert_To
(Etype
(L
), Relocate_Node
(R
)));
6764 Analyze_Equality_Op
(N
);
6769 -- If we fall through then just give general message. Note that in
6770 -- the following messages, if the operand is overloaded we choose
6771 -- an arbitrary type to complain about, but that is probably more
6772 -- useful than not giving a type at all.
6774 if Nkind
(N
) in N_Unary_Op
then
6775 Error_Msg_Node_2
:= Etype
(R
);
6776 Error_Msg_N
("operator& not defined for}", N
);
6780 if Nkind
(N
) in N_Binary_Op
then
6781 if not Is_Overloaded
(L
)
6782 and then not Is_Overloaded
(R
)
6783 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
6785 Error_Msg_Node_2
:= First_Subtype
(Etype
(R
));
6786 Error_Msg_N
("there is no applicable operator& for}", N
);
6789 -- Another attempt to find a fix: one of the candidate
6790 -- interpretations may not be use-visible. This has
6791 -- already been checked for predefined operators, so
6792 -- we examine only user-defined functions.
6794 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
6796 while Present
(Op_Id
) loop
6797 if Ekind
(Op_Id
) /= E_Operator
6798 and then Is_Overloadable
(Op_Id
)
6800 if not Is_Immediately_Visible
(Op_Id
)
6801 and then not In_Use
(Scope
(Op_Id
))
6802 and then not Is_Abstract_Subprogram
(Op_Id
)
6803 and then not Is_Hidden
(Op_Id
)
6804 and then Ekind
(Scope
(Op_Id
)) = E_Package
6807 (L
, Etype
(First_Formal
(Op_Id
)))
6809 (Next_Formal
(First_Formal
(Op_Id
)))
6813 Etype
(Next_Formal
(First_Formal
(Op_Id
))))
6816 ("No legal interpretation for operator&", N
);
6818 ("\use clause on& would make operation legal",
6824 Op_Id
:= Homonym
(Op_Id
);
6828 Error_Msg_N
("invalid operand types for operator&", N
);
6830 if Nkind
(N
) /= N_Op_Concat
then
6831 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
6832 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
6834 -- For concatenation operators it is more difficult to
6835 -- determine which is the wrong operand. It is worth
6836 -- flagging explicitly an access type, for those who
6837 -- might think that a dereference happens here.
6839 elsif Is_Access_Type
(Etype
(L
)) then
6840 Error_Msg_N
("\left operand is access type", N
);
6842 elsif Is_Access_Type
(Etype
(R
)) then
6843 Error_Msg_N
("\right operand is access type", N
);
6853 -----------------------------------------
6854 -- Process_Implicit_Dereference_Prefix --
6855 -----------------------------------------
6857 function Process_Implicit_Dereference_Prefix
6859 P
: Entity_Id
) return Entity_Id
6862 Typ
: constant Entity_Id
:= Designated_Type
(Etype
(P
));
6866 and then (Operating_Mode
= Check_Semantics
or else not Expander_Active
)
6868 -- We create a dummy reference to E to ensure that the reference is
6869 -- not considered as part of an assignment (an implicit dereference
6870 -- can never assign to its prefix). The Comes_From_Source attribute
6871 -- needs to be propagated for accurate warnings.
6873 Ref
:= New_Occurrence_Of
(E
, Sloc
(P
));
6874 Set_Comes_From_Source
(Ref
, Comes_From_Source
(P
));
6875 Generate_Reference
(E
, Ref
);
6878 -- An implicit dereference is a legal occurrence of an incomplete type
6879 -- imported through a limited_with clause, if the full view is visible.
6881 if From_Limited_With
(Typ
)
6882 and then not From_Limited_With
(Scope
(Typ
))
6884 (Is_Immediately_Visible
(Scope
(Typ
))
6886 (Is_Child_Unit
(Scope
(Typ
))
6887 and then Is_Visible_Lib_Unit
(Scope
(Typ
))))
6889 return Available_View
(Typ
);
6893 end Process_Implicit_Dereference_Prefix
;
6895 --------------------------------
6896 -- Remove_Abstract_Operations --
6897 --------------------------------
6899 procedure Remove_Abstract_Operations
(N
: Node_Id
) is
6900 Abstract_Op
: Entity_Id
:= Empty
;
6901 Address_Descendent
: Boolean := False;
6905 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
6906 -- activate this if either extensions are enabled, or if the abstract
6907 -- operation in question comes from a predefined file. This latter test
6908 -- allows us to use abstract to make operations invisible to users. In
6909 -- particular, if type Address is non-private and abstract subprograms
6910 -- are used to hide its operators, they will be truly hidden.
6912 type Operand_Position
is (First_Op
, Second_Op
);
6913 Univ_Type
: constant Entity_Id
:= Universal_Interpretation
(N
);
6915 procedure Remove_Address_Interpretations
(Op
: Operand_Position
);
6916 -- Ambiguities may arise when the operands are literal and the address
6917 -- operations in s-auxdec are visible. In that case, remove the
6918 -- interpretation of a literal as Address, to retain the semantics
6919 -- of Address as a private type.
6921 ------------------------------------
6922 -- Remove_Address_Interpretations --
6923 ------------------------------------
6925 procedure Remove_Address_Interpretations
(Op
: Operand_Position
) is
6929 if Is_Overloaded
(N
) then
6930 Get_First_Interp
(N
, I
, It
);
6931 while Present
(It
.Nam
) loop
6932 Formal
:= First_Entity
(It
.Nam
);
6934 if Op
= Second_Op
then
6935 Formal
:= Next_Entity
(Formal
);
6938 if Is_Descendent_Of_Address
(Etype
(Formal
)) then
6939 Address_Descendent
:= True;
6943 Get_Next_Interp
(I
, It
);
6946 end Remove_Address_Interpretations
;
6948 -- Start of processing for Remove_Abstract_Operations
6951 if Is_Overloaded
(N
) then
6952 if Debug_Flag_V
then
6953 Write_Str
("Remove_Abstract_Operations: ");
6954 Write_Overloads
(N
);
6957 Get_First_Interp
(N
, I
, It
);
6959 while Present
(It
.Nam
) loop
6960 if Is_Overloadable
(It
.Nam
)
6961 and then Is_Abstract_Subprogram
(It
.Nam
)
6962 and then not Is_Dispatching_Operation
(It
.Nam
)
6964 Abstract_Op
:= It
.Nam
;
6966 if Is_Descendent_Of_Address
(It
.Typ
) then
6967 Address_Descendent
:= True;
6971 -- In Ada 2005, this operation does not participate in overload
6972 -- resolution. If the operation is defined in a predefined
6973 -- unit, it is one of the operations declared abstract in some
6974 -- variants of System, and it must be removed as well.
6976 elsif Ada_Version
>= Ada_2005
6977 or else Is_Predefined_File_Name
6978 (Unit_File_Name
(Get_Source_Unit
(It
.Nam
)))
6985 Get_Next_Interp
(I
, It
);
6988 if No
(Abstract_Op
) then
6990 -- If some interpretation yields an integer type, it is still
6991 -- possible that there are address interpretations. Remove them
6992 -- if one operand is a literal, to avoid spurious ambiguities
6993 -- on systems where Address is a visible integer type.
6995 if Is_Overloaded
(N
)
6996 and then Nkind
(N
) in N_Op
6997 and then Is_Integer_Type
(Etype
(N
))
6999 if Nkind
(N
) in N_Binary_Op
then
7000 if Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
7001 Remove_Address_Interpretations
(Second_Op
);
7003 elsif Nkind
(Right_Opnd
(N
)) = N_Integer_Literal
then
7004 Remove_Address_Interpretations
(First_Op
);
7009 elsif Nkind
(N
) in N_Op
then
7011 -- Remove interpretations that treat literals as addresses. This
7012 -- is never appropriate, even when Address is defined as a visible
7013 -- Integer type. The reason is that we would really prefer Address
7014 -- to behave as a private type, even in this case. If Address is a
7015 -- visible integer type, we get lots of overload ambiguities.
7017 if Nkind
(N
) in N_Binary_Op
then
7019 U1
: constant Boolean :=
7020 Present
(Universal_Interpretation
(Right_Opnd
(N
)));
7021 U2
: constant Boolean :=
7022 Present
(Universal_Interpretation
(Left_Opnd
(N
)));
7026 Remove_Address_Interpretations
(Second_Op
);
7030 Remove_Address_Interpretations
(First_Op
);
7033 if not (U1
and U2
) then
7035 -- Remove corresponding predefined operator, which is
7036 -- always added to the overload set.
7038 Get_First_Interp
(N
, I
, It
);
7039 while Present
(It
.Nam
) loop
7040 if Scope
(It
.Nam
) = Standard_Standard
7041 and then Base_Type
(It
.Typ
) =
7042 Base_Type
(Etype
(Abstract_Op
))
7047 Get_Next_Interp
(I
, It
);
7050 elsif Is_Overloaded
(N
)
7051 and then Present
(Univ_Type
)
7053 -- If both operands have a universal interpretation,
7054 -- it is still necessary to remove interpretations that
7055 -- yield Address. Any remaining ambiguities will be
7056 -- removed in Disambiguate.
7058 Get_First_Interp
(N
, I
, It
);
7059 while Present
(It
.Nam
) loop
7060 if Is_Descendent_Of_Address
(It
.Typ
) then
7063 elsif not Is_Type
(It
.Nam
) then
7064 Set_Entity
(N
, It
.Nam
);
7067 Get_Next_Interp
(I
, It
);
7073 elsif Nkind
(N
) = N_Function_Call
7075 (Nkind
(Name
(N
)) = N_Operator_Symbol
7077 (Nkind
(Name
(N
)) = N_Expanded_Name
7079 Nkind
(Selector_Name
(Name
(N
))) = N_Operator_Symbol
))
7083 Arg1
: constant Node_Id
:= First
(Parameter_Associations
(N
));
7084 U1
: constant Boolean :=
7085 Present
(Universal_Interpretation
(Arg1
));
7086 U2
: constant Boolean :=
7087 Present
(Next
(Arg1
)) and then
7088 Present
(Universal_Interpretation
(Next
(Arg1
)));
7092 Remove_Address_Interpretations
(First_Op
);
7096 Remove_Address_Interpretations
(Second_Op
);
7099 if not (U1
and U2
) then
7100 Get_First_Interp
(N
, I
, It
);
7101 while Present
(It
.Nam
) loop
7102 if Scope
(It
.Nam
) = Standard_Standard
7103 and then It
.Typ
= Base_Type
(Etype
(Abstract_Op
))
7108 Get_Next_Interp
(I
, It
);
7114 -- If the removal has left no valid interpretations, emit an error
7115 -- message now and label node as illegal.
7117 if Present
(Abstract_Op
) then
7118 Get_First_Interp
(N
, I
, It
);
7122 -- Removal of abstract operation left no viable candidate
7124 Set_Etype
(N
, Any_Type
);
7125 Error_Msg_Sloc
:= Sloc
(Abstract_Op
);
7127 ("cannot call abstract operation& declared#", N
, Abstract_Op
);
7129 -- In Ada 2005, an abstract operation may disable predefined
7130 -- operators. Since the context is not yet known, we mark the
7131 -- predefined operators as potentially hidden. Do not include
7132 -- predefined operators when addresses are involved since this
7133 -- case is handled separately.
7135 elsif Ada_Version
>= Ada_2005
and then not Address_Descendent
then
7136 while Present
(It
.Nam
) loop
7137 if Is_Numeric_Type
(It
.Typ
)
7138 and then Scope
(It
.Typ
) = Standard_Standard
7140 Set_Abstract_Op
(I
, Abstract_Op
);
7143 Get_Next_Interp
(I
, It
);
7148 if Debug_Flag_V
then
7149 Write_Str
("Remove_Abstract_Operations done: ");
7150 Write_Overloads
(N
);
7153 end Remove_Abstract_Operations
;
7155 ----------------------------
7156 -- Try_Container_Indexing --
7157 ----------------------------
7159 function Try_Container_Indexing
7162 Exprs
: List_Id
) return Boolean
7164 Loc
: constant Source_Ptr
:= Sloc
(N
);
7168 Func_Name
: Node_Id
;
7172 C_Type
:= Etype
(Prefix
);
7174 -- If indexing a class-wide container, obtain indexing primitive
7175 -- from specific type.
7177 if Is_Class_Wide_Type
(C_Type
) then
7178 C_Type
:= Etype
(Base_Type
(C_Type
));
7181 -- Check whether type has a specified indexing aspect
7185 if Is_Variable
(Prefix
) then
7187 Find_Value_Of_Aspect
(Etype
(Prefix
), Aspect_Variable_Indexing
);
7190 if No
(Func_Name
) then
7192 Find_Value_Of_Aspect
(Etype
(Prefix
), Aspect_Constant_Indexing
);
7195 -- If aspect does not exist the expression is illegal. Error is
7196 -- diagnosed in caller.
7198 if No
(Func_Name
) then
7200 -- The prefix itself may be an indexing of a container: rewrite
7201 -- as such and re-analyze.
7203 if Has_Implicit_Dereference
(Etype
(Prefix
)) then
7204 Build_Explicit_Dereference
7205 (Prefix
, First_Discriminant
(Etype
(Prefix
)));
7206 return Try_Container_Indexing
(N
, Prefix
, Exprs
);
7212 -- If the container type is derived from another container type, the
7213 -- value of the inherited aspect is the Reference operation declared
7214 -- for the parent type.
7216 -- However, Reference is also a primitive operation of the type, and
7217 -- the inherited operation has a different signature. We retrieve the
7218 -- right one from the list of primitive operations of the derived type.
7220 -- Note that predefined containers are typically all derived from one
7221 -- of the Controlled types. The code below is motivated by containers
7222 -- that are derived from other types with a Reference aspect.
7224 -- Additional machinery may be needed for types that have several user-
7225 -- defined Reference operations with different signatures ???
7227 elsif Is_Derived_Type
(C_Type
)
7228 and then Etype
(First_Formal
(Entity
(Func_Name
))) /= Etype
(Prefix
)
7230 Func
:= Find_Prim_Op
(C_Type
, Chars
(Func_Name
));
7231 Func_Name
:= New_Occurrence_Of
(Func
, Loc
);
7234 Assoc
:= New_List
(Relocate_Node
(Prefix
));
7236 -- A generalized indexing may have nore than one index expression, so
7237 -- transfer all of them to the argument list to be used in the call.
7238 -- Note that there may be named associations, in which case the node
7239 -- was rewritten earlier as a call, and has been transformed back into
7240 -- an indexed expression to share the following processing.
7242 -- The generalized indexing node is the one on which analysis and
7243 -- resolution take place. Before expansion the original node is replaced
7244 -- with the generalized indexing node, which is a call, possibly with
7245 -- a dereference operation.
7247 if Comes_From_Source
(N
) then
7248 Check_Compiler_Unit
("generalized indexing", N
);
7254 Arg
:= First
(Exprs
);
7255 while Present
(Arg
) loop
7256 Append
(Relocate_Node
(Arg
), Assoc
);
7261 if not Is_Overloaded
(Func_Name
) then
7262 Func
:= Entity
(Func_Name
);
7264 Make_Function_Call
(Loc
,
7265 Name
=> New_Occurrence_Of
(Func
, Loc
),
7266 Parameter_Associations
=> Assoc
);
7267 Set_Parent
(Indexing
, Parent
(N
));
7268 Set_Generalized_Indexing
(N
, Indexing
);
7270 Set_Etype
(N
, Etype
(Indexing
));
7272 -- If the return type of the indexing function is a reference type,
7273 -- add the dereference as a possible interpretation. Note that the
7274 -- indexing aspect may be a function that returns the element type
7275 -- with no intervening implicit dereference, and that the reference
7276 -- discriminant is not the first discriminant.
7278 if Has_Discriminants
(Etype
(Func
)) then
7279 Check_Implicit_Dereference
(N
, Etype
(Func
));
7284 Make_Function_Call
(Loc
,
7285 Name
=> Make_Identifier
(Loc
, Chars
(Func_Name
)),
7286 Parameter_Associations
=> Assoc
);
7288 Set_Parent
(Indexing
, Parent
(N
));
7289 Set_Generalized_Indexing
(N
, Indexing
);
7297 Get_First_Interp
(Func_Name
, I
, It
);
7298 Set_Etype
(Indexing
, Any_Type
);
7299 while Present
(It
.Nam
) loop
7300 Analyze_One_Call
(Indexing
, It
.Nam
, False, Success
);
7303 Set_Etype
(Name
(Indexing
), It
.Typ
);
7304 Set_Entity
(Name
(Indexing
), It
.Nam
);
7305 Set_Etype
(N
, Etype
(Indexing
));
7307 -- Add implicit dereference interpretation
7309 if Has_Discriminants
(Etype
(It
.Nam
)) then
7310 Check_Implicit_Dereference
(N
, Etype
(It
.Nam
));
7316 Get_Next_Interp
(I
, It
);
7321 if Etype
(Indexing
) = Any_Type
then
7323 ("container cannot be indexed with&", N
, Etype
(First
(Exprs
)));
7324 Rewrite
(N
, New_Occurrence_Of
(Any_Id
, Loc
));
7328 end Try_Container_Indexing
;
7330 -----------------------
7331 -- Try_Indirect_Call --
7332 -----------------------
7334 function Try_Indirect_Call
7337 Typ
: Entity_Id
) return Boolean
7343 pragma Warnings
(Off
, Call_OK
);
7346 Normalize_Actuals
(N
, Designated_Type
(Typ
), False, Call_OK
);
7348 Actual
:= First_Actual
(N
);
7349 Formal
:= First_Formal
(Designated_Type
(Typ
));
7350 while Present
(Actual
) and then Present
(Formal
) loop
7351 if not Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
7356 Next_Formal
(Formal
);
7359 if No
(Actual
) and then No
(Formal
) then
7360 Add_One_Interp
(N
, Nam
, Etype
(Designated_Type
(Typ
)));
7362 -- Nam is a candidate interpretation for the name in the call,
7363 -- if it is not an indirect call.
7365 if not Is_Type
(Nam
)
7366 and then Is_Entity_Name
(Name
(N
))
7368 Set_Entity
(Name
(N
), Nam
);
7376 end Try_Indirect_Call
;
7378 ----------------------
7379 -- Try_Indexed_Call --
7380 ----------------------
7382 function Try_Indexed_Call
7386 Skip_First
: Boolean) return Boolean
7388 Loc
: constant Source_Ptr
:= Sloc
(N
);
7389 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
7394 Actual
:= First
(Actuals
);
7396 -- If the call was originally written in prefix form, skip the first
7397 -- actual, which is obviously not defaulted.
7403 Index
:= First_Index
(Typ
);
7404 while Present
(Actual
) and then Present
(Index
) loop
7406 -- If the parameter list has a named association, the expression
7407 -- is definitely a call and not an indexed component.
7409 if Nkind
(Actual
) = N_Parameter_Association
then
7413 if Is_Entity_Name
(Actual
)
7414 and then Is_Type
(Entity
(Actual
))
7415 and then No
(Next
(Actual
))
7417 -- A single actual that is a type name indicates a slice if the
7418 -- type is discrete, and an error otherwise.
7420 if Is_Discrete_Type
(Entity
(Actual
)) then
7424 Make_Function_Call
(Loc
,
7425 Name
=> Relocate_Node
(Name
(N
))),
7427 New_Occurrence_Of
(Entity
(Actual
), Sloc
(Actual
))));
7432 Error_Msg_N
("invalid use of type in expression", Actual
);
7433 Set_Etype
(N
, Any_Type
);
7438 elsif not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
7446 if No
(Actual
) and then No
(Index
) then
7447 Add_One_Interp
(N
, Nam
, Component_Type
(Typ
));
7449 -- Nam is a candidate interpretation for the name in the call,
7450 -- if it is not an indirect call.
7452 if not Is_Type
(Nam
)
7453 and then Is_Entity_Name
(Name
(N
))
7455 Set_Entity
(Name
(N
), Nam
);
7462 end Try_Indexed_Call
;
7464 --------------------------
7465 -- Try_Object_Operation --
7466 --------------------------
7468 function Try_Object_Operation
7469 (N
: Node_Id
; CW_Test_Only
: Boolean := False) return Boolean
7471 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
7472 Is_Subprg_Call
: constant Boolean := K
in N_Subprogram_Call
;
7473 Loc
: constant Source_Ptr
:= Sloc
(N
);
7474 Obj
: constant Node_Id
:= Prefix
(N
);
7476 Subprog
: constant Node_Id
:=
7477 Make_Identifier
(Sloc
(Selector_Name
(N
)),
7478 Chars
=> Chars
(Selector_Name
(N
)));
7479 -- Identifier on which possible interpretations will be collected
7481 Report_Error
: Boolean := False;
7482 -- If no candidate interpretation matches the context, redo analysis
7483 -- with Report_Error True to provide additional information.
7486 Candidate
: Entity_Id
:= Empty
;
7487 New_Call_Node
: Node_Id
:= Empty
;
7488 Node_To_Replace
: Node_Id
;
7489 Obj_Type
: Entity_Id
:= Etype
(Obj
);
7490 Success
: Boolean := False;
7492 function Valid_Candidate
7495 Subp
: Entity_Id
) return Entity_Id
;
7496 -- If the subprogram is a valid interpretation, record it, and add
7497 -- to the list of interpretations of Subprog. Otherwise return Empty.
7499 procedure Complete_Object_Operation
7500 (Call_Node
: Node_Id
;
7501 Node_To_Replace
: Node_Id
);
7502 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
7503 -- Call_Node, insert the object (or its dereference) as the first actual
7504 -- in the call, and complete the analysis of the call.
7506 procedure Report_Ambiguity
(Op
: Entity_Id
);
7507 -- If a prefixed procedure call is ambiguous, indicate whether the
7508 -- call includes an implicit dereference or an implicit 'Access.
7510 procedure Transform_Object_Operation
7511 (Call_Node
: out Node_Id
;
7512 Node_To_Replace
: out Node_Id
);
7513 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
7514 -- Call_Node is the resulting subprogram call, Node_To_Replace is
7515 -- either N or the parent of N, and Subprog is a reference to the
7516 -- subprogram we are trying to match.
7518 function Try_Class_Wide_Operation
7519 (Call_Node
: Node_Id
;
7520 Node_To_Replace
: Node_Id
) return Boolean;
7521 -- Traverse all ancestor types looking for a class-wide subprogram
7522 -- for which the current operation is a valid non-dispatching call.
7524 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
);
7525 -- If prefix is overloaded, its interpretation may include different
7526 -- tagged types, and we must examine the primitive operations and
7527 -- the class-wide operations of each in order to find candidate
7528 -- interpretations for the call as a whole.
7530 function Try_Primitive_Operation
7531 (Call_Node
: Node_Id
;
7532 Node_To_Replace
: Node_Id
) return Boolean;
7533 -- Traverse the list of primitive subprograms looking for a dispatching
7534 -- operation for which the current node is a valid call .
7536 ---------------------
7537 -- Valid_Candidate --
7538 ---------------------
7540 function Valid_Candidate
7543 Subp
: Entity_Id
) return Entity_Id
7545 Arr_Type
: Entity_Id
;
7546 Comp_Type
: Entity_Id
;
7549 -- If the subprogram is a valid interpretation, record it in global
7550 -- variable Subprog, to collect all possible overloadings.
7553 if Subp
/= Entity
(Subprog
) then
7554 Add_One_Interp
(Subprog
, Subp
, Etype
(Subp
));
7558 -- If the call may be an indexed call, retrieve component type of
7559 -- resulting expression, and add possible interpretation.
7564 if Nkind
(Call
) = N_Function_Call
7565 and then Nkind
(Parent
(N
)) = N_Indexed_Component
7566 and then Needs_One_Actual
(Subp
)
7568 if Is_Array_Type
(Etype
(Subp
)) then
7569 Arr_Type
:= Etype
(Subp
);
7571 elsif Is_Access_Type
(Etype
(Subp
))
7572 and then Is_Array_Type
(Designated_Type
(Etype
(Subp
)))
7574 Arr_Type
:= Designated_Type
(Etype
(Subp
));
7578 if Present
(Arr_Type
) then
7580 -- Verify that the actuals (excluding the object) match the types
7588 Actual
:= Next
(First_Actual
(Call
));
7589 Index
:= First_Index
(Arr_Type
);
7590 while Present
(Actual
) and then Present
(Index
) loop
7591 if not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
7596 Next_Actual
(Actual
);
7602 and then Present
(Arr_Type
)
7604 Comp_Type
:= Component_Type
(Arr_Type
);
7608 if Present
(Comp_Type
)
7609 and then Etype
(Subprog
) /= Comp_Type
7611 Add_One_Interp
(Subprog
, Subp
, Comp_Type
);
7615 if Etype
(Call
) /= Any_Type
then
7620 end Valid_Candidate
;
7622 -------------------------------
7623 -- Complete_Object_Operation --
7624 -------------------------------
7626 procedure Complete_Object_Operation
7627 (Call_Node
: Node_Id
;
7628 Node_To_Replace
: Node_Id
)
7630 Control
: constant Entity_Id
:= First_Formal
(Entity
(Subprog
));
7631 Formal_Type
: constant Entity_Id
:= Etype
(Control
);
7632 First_Actual
: Node_Id
;
7635 -- Place the name of the operation, with its interpretations,
7636 -- on the rewritten call.
7638 Set_Name
(Call_Node
, Subprog
);
7640 First_Actual
:= First
(Parameter_Associations
(Call_Node
));
7642 -- For cross-reference purposes, treat the new node as being in the
7643 -- source if the original one is. Set entity and type, even though
7644 -- they may be overwritten during resolution if overloaded.
7646 Set_Comes_From_Source
(Subprog
, Comes_From_Source
(N
));
7647 Set_Comes_From_Source
(Call_Node
, Comes_From_Source
(N
));
7649 if Nkind
(N
) = N_Selected_Component
7650 and then not Inside_A_Generic
7652 Set_Entity
(Selector_Name
(N
), Entity
(Subprog
));
7653 Set_Etype
(Selector_Name
(N
), Etype
(Entity
(Subprog
)));
7656 -- If need be, rewrite first actual as an explicit dereference. If
7657 -- the call is overloaded, the rewriting can only be done once the
7658 -- primitive operation is identified.
7660 if Is_Overloaded
(Subprog
) then
7662 -- The prefix itself may be overloaded, and its interpretations
7663 -- must be propagated to the new actual in the call.
7665 if Is_Overloaded
(Obj
) then
7666 Save_Interps
(Obj
, First_Actual
);
7669 Rewrite
(First_Actual
, Obj
);
7671 elsif not Is_Access_Type
(Formal_Type
)
7672 and then Is_Access_Type
(Etype
(Obj
))
7674 Rewrite
(First_Actual
,
7675 Make_Explicit_Dereference
(Sloc
(Obj
), Obj
));
7676 Analyze
(First_Actual
);
7678 -- If we need to introduce an explicit dereference, verify that
7679 -- the resulting actual is compatible with the mode of the formal.
7681 if Ekind
(First_Formal
(Entity
(Subprog
))) /= E_In_Parameter
7682 and then Is_Access_Constant
(Etype
(Obj
))
7685 ("expect variable in call to&", Prefix
(N
), Entity
(Subprog
));
7688 -- Conversely, if the formal is an access parameter and the object
7689 -- is not, replace the actual with a 'Access reference. Its analysis
7690 -- will check that the object is aliased.
7692 elsif Is_Access_Type
(Formal_Type
)
7693 and then not Is_Access_Type
(Etype
(Obj
))
7695 -- A special case: A.all'access is illegal if A is an access to a
7696 -- constant and the context requires an access to a variable.
7698 if not Is_Access_Constant
(Formal_Type
) then
7699 if (Nkind
(Obj
) = N_Explicit_Dereference
7700 and then Is_Access_Constant
(Etype
(Prefix
(Obj
))))
7701 or else not Is_Variable
(Obj
)
7704 ("actual for & must be a variable", Obj
, Control
);
7708 Rewrite
(First_Actual
,
7709 Make_Attribute_Reference
(Loc
,
7710 Attribute_Name
=> Name_Access
,
7711 Prefix
=> Relocate_Node
(Obj
)));
7713 if not Is_Aliased_View
(Obj
) then
7715 ("object in prefixed call to & must be aliased "
7716 & "(RM 4.1.3 (13 1/2))", Prefix
(First_Actual
), Subprog
);
7719 Analyze
(First_Actual
);
7722 if Is_Overloaded
(Obj
) then
7723 Save_Interps
(Obj
, First_Actual
);
7726 Rewrite
(First_Actual
, Obj
);
7729 -- The operation is obtained from the dispatch table and not by
7730 -- visibility, and may be declared in a unit that is not explicitly
7731 -- referenced in the source, but is nevertheless required in the
7732 -- context of the current unit. Indicate that operation and its scope
7733 -- are referenced, to prevent spurious and misleading warnings. If
7734 -- the operation is overloaded, all primitives are in the same scope
7735 -- and we can use any of them.
7737 Set_Referenced
(Entity
(Subprog
), True);
7738 Set_Referenced
(Scope
(Entity
(Subprog
)), True);
7740 Rewrite
(Node_To_Replace
, Call_Node
);
7742 -- Propagate the interpretations collected in subprog to the new
7743 -- function call node, to be resolved from context.
7745 if Is_Overloaded
(Subprog
) then
7746 Save_Interps
(Subprog
, Node_To_Replace
);
7749 -- The type of the subprogram may be a limited view obtained
7750 -- transitively from another unit. If full view is available,
7751 -- use it to analyze call.
7754 T
: constant Entity_Id
:= Etype
(Subprog
);
7756 if From_Limited_With
(T
) then
7757 Set_Etype
(Entity
(Subprog
), Available_View
(T
));
7761 Analyze
(Node_To_Replace
);
7763 -- If the operation has been rewritten into a call, which may get
7764 -- subsequently an explicit dereference, preserve the type on the
7765 -- original node (selected component or indexed component) for
7766 -- subsequent legality tests, e.g. Is_Variable. which examines
7767 -- the original node.
7769 if Nkind
(Node_To_Replace
) = N_Function_Call
then
7771 (Original_Node
(Node_To_Replace
), Etype
(Node_To_Replace
));
7774 end Complete_Object_Operation
;
7776 ----------------------
7777 -- Report_Ambiguity --
7778 ----------------------
7780 procedure Report_Ambiguity
(Op
: Entity_Id
) is
7781 Access_Actual
: constant Boolean :=
7782 Is_Access_Type
(Etype
(Prefix
(N
)));
7783 Access_Formal
: Boolean := False;
7786 Error_Msg_Sloc
:= Sloc
(Op
);
7788 if Present
(First_Formal
(Op
)) then
7789 Access_Formal
:= Is_Access_Type
(Etype
(First_Formal
(Op
)));
7792 if Access_Formal
and then not Access_Actual
then
7793 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
7795 ("\possible interpretation "
7796 & "(inherited, with implicit 'Access) #", N
);
7799 ("\possible interpretation (with implicit 'Access) #", N
);
7802 elsif not Access_Formal
and then Access_Actual
then
7803 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
7805 ("\possible interpretation "
7806 & "(inherited, with implicit dereference) #", N
);
7809 ("\possible interpretation (with implicit dereference) #", N
);
7813 if Nkind
(Parent
(Op
)) = N_Full_Type_Declaration
then
7814 Error_Msg_N
("\possible interpretation (inherited)#", N
);
7816 Error_Msg_N
-- CODEFIX
7817 ("\possible interpretation#", N
);
7820 end Report_Ambiguity
;
7822 --------------------------------
7823 -- Transform_Object_Operation --
7824 --------------------------------
7826 procedure Transform_Object_Operation
7827 (Call_Node
: out Node_Id
;
7828 Node_To_Replace
: out Node_Id
)
7830 Dummy
: constant Node_Id
:= New_Copy
(Obj
);
7831 -- Placeholder used as a first parameter in the call, replaced
7832 -- eventually by the proper object.
7834 Parent_Node
: constant Node_Id
:= Parent
(N
);
7840 -- Common case covering 1) Call to a procedure and 2) Call to a
7841 -- function that has some additional actuals.
7843 if Nkind
(Parent_Node
) in N_Subprogram_Call
7845 -- N is a selected component node containing the name of the
7846 -- subprogram. If N is not the name of the parent node we must
7847 -- not replace the parent node by the new construct. This case
7848 -- occurs when N is a parameterless call to a subprogram that
7849 -- is an actual parameter of a call to another subprogram. For
7851 -- Some_Subprogram (..., Obj.Operation, ...)
7853 and then Name
(Parent_Node
) = N
7855 Node_To_Replace
:= Parent_Node
;
7857 Actuals
:= Parameter_Associations
(Parent_Node
);
7859 if Present
(Actuals
) then
7860 Prepend
(Dummy
, Actuals
);
7862 Actuals
:= New_List
(Dummy
);
7865 if Nkind
(Parent_Node
) = N_Procedure_Call_Statement
then
7867 Make_Procedure_Call_Statement
(Loc
,
7868 Name
=> New_Copy
(Subprog
),
7869 Parameter_Associations
=> Actuals
);
7873 Make_Function_Call
(Loc
,
7874 Name
=> New_Copy
(Subprog
),
7875 Parameter_Associations
=> Actuals
);
7878 -- Before analysis, a function call appears as an indexed component
7879 -- if there are no named associations.
7881 elsif Nkind
(Parent_Node
) = N_Indexed_Component
7882 and then N
= Prefix
(Parent_Node
)
7884 Node_To_Replace
:= Parent_Node
;
7885 Actuals
:= Expressions
(Parent_Node
);
7887 Actual
:= First
(Actuals
);
7888 while Present
(Actual
) loop
7893 Prepend
(Dummy
, Actuals
);
7896 Make_Function_Call
(Loc
,
7897 Name
=> New_Copy
(Subprog
),
7898 Parameter_Associations
=> Actuals
);
7900 -- Parameterless call: Obj.F is rewritten as F (Obj)
7903 Node_To_Replace
:= N
;
7906 Make_Function_Call
(Loc
,
7907 Name
=> New_Copy
(Subprog
),
7908 Parameter_Associations
=> New_List
(Dummy
));
7910 end Transform_Object_Operation
;
7912 ------------------------------
7913 -- Try_Class_Wide_Operation --
7914 ------------------------------
7916 function Try_Class_Wide_Operation
7917 (Call_Node
: Node_Id
;
7918 Node_To_Replace
: Node_Id
) return Boolean
7920 Anc_Type
: Entity_Id
;
7921 Matching_Op
: Entity_Id
:= Empty
;
7924 procedure Traverse_Homonyms
7925 (Anc_Type
: Entity_Id
;
7926 Error
: out Boolean);
7927 -- Traverse the homonym chain of the subprogram searching for those
7928 -- homonyms whose first formal has the Anc_Type's class-wide type,
7929 -- or an anonymous access type designating the class-wide type. If
7930 -- an ambiguity is detected, then Error is set to True.
7932 procedure Traverse_Interfaces
7933 (Anc_Type
: Entity_Id
;
7934 Error
: out Boolean);
7935 -- Traverse the list of interfaces, if any, associated with Anc_Type
7936 -- and search for acceptable class-wide homonyms associated with each
7937 -- interface. If an ambiguity is detected, then Error is set to True.
7939 -----------------------
7940 -- Traverse_Homonyms --
7941 -----------------------
7943 procedure Traverse_Homonyms
7944 (Anc_Type
: Entity_Id
;
7945 Error
: out Boolean)
7947 Cls_Type
: Entity_Id
;
7955 Cls_Type
:= Class_Wide_Type
(Anc_Type
);
7957 Hom
:= Current_Entity
(Subprog
);
7959 -- Find a non-hidden operation whose first parameter is of the
7960 -- class-wide type, a subtype thereof, or an anonymous access
7961 -- to same. If in an instance, the operation can be considered
7962 -- even if hidden (it may be hidden because the instantiation
7963 -- is expanded after the containing package has been analyzed).
7965 while Present
(Hom
) loop
7966 if Ekind_In
(Hom
, E_Procedure
, E_Function
)
7967 and then (not Is_Hidden
(Hom
) or else In_Instance
)
7968 and then Scope
(Hom
) = Scope
(Anc_Type
)
7969 and then Present
(First_Formal
(Hom
))
7971 (Base_Type
(Etype
(First_Formal
(Hom
))) = Cls_Type
7973 (Is_Access_Type
(Etype
(First_Formal
(Hom
)))
7975 Ekind
(Etype
(First_Formal
(Hom
))) =
7976 E_Anonymous_Access_Type
7979 (Designated_Type
(Etype
(First_Formal
(Hom
)))) =
7982 -- If the context is a procedure call, ignore functions
7983 -- in the name of the call.
7985 if Ekind
(Hom
) = E_Function
7986 and then Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
7987 and then N
= Name
(Parent
(N
))
7991 -- If the context is a function call, ignore procedures
7992 -- in the name of the call.
7994 elsif Ekind
(Hom
) = E_Procedure
7995 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
8000 Set_Etype
(Call_Node
, Any_Type
);
8001 Set_Is_Overloaded
(Call_Node
, False);
8004 if No
(Matching_Op
) then
8005 Hom_Ref
:= New_Occurrence_Of
(Hom
, Sloc
(Subprog
));
8006 Set_Etype
(Call_Node
, Any_Type
);
8007 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
8009 Set_Name
(Call_Node
, Hom_Ref
);
8014 Report
=> Report_Error
,
8016 Skip_First
=> True);
8019 Valid_Candidate
(Success
, Call_Node
, Hom
);
8025 Report
=> Report_Error
,
8027 Skip_First
=> True);
8029 if Present
(Valid_Candidate
(Success
, Call_Node
, Hom
))
8030 and then Nkind
(Call_Node
) /= N_Function_Call
8032 Error_Msg_NE
("ambiguous call to&", N
, Hom
);
8033 Report_Ambiguity
(Matching_Op
);
8034 Report_Ambiguity
(Hom
);
8042 Hom
:= Homonym
(Hom
);
8044 end Traverse_Homonyms
;
8046 -------------------------
8047 -- Traverse_Interfaces --
8048 -------------------------
8050 procedure Traverse_Interfaces
8051 (Anc_Type
: Entity_Id
;
8052 Error
: out Boolean)
8054 Intface_List
: constant List_Id
:=
8055 Abstract_Interface_List
(Anc_Type
);
8061 if Is_Non_Empty_List
(Intface_List
) then
8062 Intface
:= First
(Intface_List
);
8063 while Present
(Intface
) loop
8065 -- Look for acceptable class-wide homonyms associated with
8068 Traverse_Homonyms
(Etype
(Intface
), Error
);
8074 -- Continue the search by looking at each of the interface's
8075 -- associated interface ancestors.
8077 Traverse_Interfaces
(Etype
(Intface
), Error
);
8086 end Traverse_Interfaces
;
8088 -- Start of processing for Try_Class_Wide_Operation
8091 -- If we are searching only for conflicting class-wide subprograms
8092 -- then initialize directly Matching_Op with the target entity.
8094 if CW_Test_Only
then
8095 Matching_Op
:= Entity
(Selector_Name
(N
));
8098 -- Loop through ancestor types (including interfaces), traversing
8099 -- the homonym chain of the subprogram, trying out those homonyms
8100 -- whose first formal has the class-wide type of the ancestor, or
8101 -- an anonymous access type designating the class-wide type.
8103 Anc_Type
:= Obj_Type
;
8105 -- Look for a match among homonyms associated with the ancestor
8107 Traverse_Homonyms
(Anc_Type
, Error
);
8113 -- Continue the search for matches among homonyms associated with
8114 -- any interfaces implemented by the ancestor.
8116 Traverse_Interfaces
(Anc_Type
, Error
);
8122 exit when Etype
(Anc_Type
) = Anc_Type
;
8123 Anc_Type
:= Etype
(Anc_Type
);
8126 if Present
(Matching_Op
) then
8127 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
8130 return Present
(Matching_Op
);
8131 end Try_Class_Wide_Operation
;
8133 -----------------------------------
8134 -- Try_One_Prefix_Interpretation --
8135 -----------------------------------
8137 procedure Try_One_Prefix_Interpretation
(T
: Entity_Id
) is
8141 if Is_Access_Type
(Obj_Type
) then
8142 Obj_Type
:= Designated_Type
(Obj_Type
);
8145 if Ekind
(Obj_Type
) = E_Private_Subtype
then
8146 Obj_Type
:= Base_Type
(Obj_Type
);
8149 if Is_Class_Wide_Type
(Obj_Type
) then
8150 Obj_Type
:= Etype
(Class_Wide_Type
(Obj_Type
));
8153 -- The type may have be obtained through a limited_with clause,
8154 -- in which case the primitive operations are available on its
8155 -- non-limited view. If still incomplete, retrieve full view.
8157 if Ekind
(Obj_Type
) = E_Incomplete_Type
8158 and then From_Limited_With
(Obj_Type
)
8159 and then Has_Non_Limited_View
(Obj_Type
)
8161 Obj_Type
:= Get_Full_View
(Non_Limited_View
(Obj_Type
));
8164 -- If the object is not tagged, or the type is still an incomplete
8165 -- type, this is not a prefixed call.
8167 if not Is_Tagged_Type
(Obj_Type
)
8168 or else Is_Incomplete_Type
(Obj_Type
)
8174 Dup_Call_Node
: constant Node_Id
:= New_Copy
(New_Call_Node
);
8175 CW_Result
: Boolean;
8176 Prim_Result
: Boolean;
8177 pragma Unreferenced
(CW_Result
);
8180 if not CW_Test_Only
then
8182 Try_Primitive_Operation
8183 (Call_Node
=> New_Call_Node
,
8184 Node_To_Replace
=> Node_To_Replace
);
8187 -- Check if there is a class-wide subprogram covering the
8188 -- primitive. This check must be done even if a candidate
8189 -- was found in order to report ambiguous calls.
8191 if not (Prim_Result
) then
8193 Try_Class_Wide_Operation
8194 (Call_Node
=> New_Call_Node
,
8195 Node_To_Replace
=> Node_To_Replace
);
8197 -- If we found a primitive we search for class-wide subprograms
8198 -- using a duplicate of the call node (done to avoid missing its
8199 -- decoration if there is no ambiguity).
8203 Try_Class_Wide_Operation
8204 (Call_Node
=> Dup_Call_Node
,
8205 Node_To_Replace
=> Node_To_Replace
);
8208 end Try_One_Prefix_Interpretation
;
8210 -----------------------------
8211 -- Try_Primitive_Operation --
8212 -----------------------------
8214 function Try_Primitive_Operation
8215 (Call_Node
: Node_Id
;
8216 Node_To_Replace
: Node_Id
) return Boolean
8219 Prim_Op
: Entity_Id
;
8220 Matching_Op
: Entity_Id
:= Empty
;
8221 Prim_Op_Ref
: Node_Id
:= Empty
;
8223 Corr_Type
: Entity_Id
:= Empty
;
8224 -- If the prefix is a synchronized type, the controlling type of
8225 -- the primitive operation is the corresponding record type, else
8226 -- this is the object type itself.
8228 Success
: Boolean := False;
8230 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
;
8231 -- For tagged types the candidate interpretations are found in
8232 -- the list of primitive operations of the type and its ancestors.
8233 -- For formal tagged types we have to find the operations declared
8234 -- in the same scope as the type (including in the generic formal
8235 -- part) because the type itself carries no primitive operations,
8236 -- except for formal derived types that inherit the operations of
8237 -- the parent and progenitors.
8239 -- If the context is a generic subprogram body, the generic formals
8240 -- are visible by name, but are not in the entity list of the
8241 -- subprogram because that list starts with the subprogram formals.
8242 -- We retrieve the candidate operations from the generic declaration.
8244 function Extended_Primitive_Ops
(T
: Entity_Id
) return Elist_Id
;
8245 -- Prefix notation can also be used on operations that are not
8246 -- primitives of the type, but are declared in the same immediate
8247 -- declarative part, which can only mean the corresponding package
8248 -- body (See RM 4.1.3 (9.2/3)). If we are in that body we extend the
8249 -- list of primitives with body operations with the same name that
8250 -- may be candidates, so that Try_Primitive_Operations can examine
8251 -- them if no real primitive is found.
8253 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean;
8254 -- An operation that overrides an inherited operation in the private
8255 -- part of its package may be hidden, but if the inherited operation
8256 -- is visible a direct call to it will dispatch to the private one,
8257 -- which is therefore a valid candidate.
8259 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean;
8260 -- Verify that the prefix, dereferenced if need be, is a valid
8261 -- controlling argument in a call to Op. The remaining actuals
8262 -- are checked in the subsequent call to Analyze_One_Call.
8264 ------------------------------
8265 -- Collect_Generic_Type_Ops --
8266 ------------------------------
8268 function Collect_Generic_Type_Ops
(T
: Entity_Id
) return Elist_Id
is
8269 Bas
: constant Entity_Id
:= Base_Type
(T
);
8270 Candidates
: constant Elist_Id
:= New_Elmt_List
;
8274 procedure Check_Candidate
;
8275 -- The operation is a candidate if its first parameter is a
8276 -- controlling operand of the desired type.
8278 -----------------------
8279 -- Check_Candidate; --
8280 -----------------------
8282 procedure Check_Candidate
is
8284 Formal
:= First_Formal
(Subp
);
8287 and then Is_Controlling_Formal
(Formal
)
8289 (Base_Type
(Etype
(Formal
)) = Bas
8291 (Is_Access_Type
(Etype
(Formal
))
8292 and then Designated_Type
(Etype
(Formal
)) = Bas
))
8294 Append_Elmt
(Subp
, Candidates
);
8296 end Check_Candidate
;
8298 -- Start of processing for Collect_Generic_Type_Ops
8301 if Is_Derived_Type
(T
) then
8302 return Primitive_Operations
(T
);
8304 elsif Ekind_In
(Scope
(T
), E_Procedure
, E_Function
) then
8306 -- Scan the list of generic formals to find subprograms
8307 -- that may have a first controlling formal of the type.
8309 if Nkind
(Unit_Declaration_Node
(Scope
(T
))) =
8310 N_Generic_Subprogram_Declaration
8317 First
(Generic_Formal_Declarations
8318 (Unit_Declaration_Node
(Scope
(T
))));
8319 while Present
(Decl
) loop
8320 if Nkind
(Decl
) in N_Formal_Subprogram_Declaration
then
8321 Subp
:= Defining_Entity
(Decl
);
8332 -- Scan the list of entities declared in the same scope as
8333 -- the type. In general this will be an open scope, given that
8334 -- the call we are analyzing can only appear within a generic
8335 -- declaration or body (either the one that declares T, or a
8338 -- For a subtype representing a generic actual type, go to the
8341 if Is_Generic_Actual_Type
(T
) then
8342 Subp
:= First_Entity
(Scope
(Base_Type
(T
)));
8344 Subp
:= First_Entity
(Scope
(T
));
8347 while Present
(Subp
) loop
8348 if Is_Overloadable
(Subp
) then
8357 end Collect_Generic_Type_Ops
;
8359 ----------------------------
8360 -- Extended_Primitive_Ops --
8361 ----------------------------
8363 function Extended_Primitive_Ops
(T
: Entity_Id
) return Elist_Id
is
8364 Type_Scope
: constant Entity_Id
:= Scope
(T
);
8366 Body_Decls
: List_Id
;
8372 Op_List
:= Primitive_Operations
(T
);
8374 if Ekind
(Type_Scope
) = E_Package
8375 and then In_Package_Body
(Type_Scope
)
8376 and then In_Open_Scopes
(Type_Scope
)
8378 -- Retrieve list of declarations of package body.
8382 (Unit_Declaration_Node
8384 (Unit_Declaration_Node
(Type_Scope
))));
8386 Op
:= Current_Entity
(Subprog
);
8388 while Present
(Op
) loop
8389 if Comes_From_Source
(Op
)
8390 and then Is_Overloadable
(Op
)
8392 -- Exclude overriding primitive operations of a type
8393 -- extension declared in the package body, to prevent
8394 -- duplicates in extended list.
8396 and then not Is_Primitive
(Op
)
8397 and then Is_List_Member
(Unit_Declaration_Node
(Op
))
8398 and then List_Containing
(Unit_Declaration_Node
(Op
)) =
8401 if not Op_Found
then
8403 -- Copy list of primitives so it is not affected for
8406 Op_List
:= New_Copy_Elist
(Op_List
);
8410 Append_Elmt
(Op
, Op_List
);
8418 end Extended_Primitive_Ops
;
8420 ---------------------------
8421 -- Is_Private_Overriding --
8422 ---------------------------
8424 function Is_Private_Overriding
(Op
: Entity_Id
) return Boolean is
8425 Visible_Op
: constant Entity_Id
:= Homonym
(Op
);
8428 return Present
(Visible_Op
)
8429 and then Scope
(Op
) = Scope
(Visible_Op
)
8430 and then not Comes_From_Source
(Visible_Op
)
8431 and then Alias
(Visible_Op
) = Op
8432 and then not Is_Hidden
(Visible_Op
);
8433 end Is_Private_Overriding
;
8435 -----------------------------
8436 -- Valid_First_Argument_Of --
8437 -----------------------------
8439 function Valid_First_Argument_Of
(Op
: Entity_Id
) return Boolean is
8440 Typ
: Entity_Id
:= Etype
(First_Formal
(Op
));
8443 if Is_Concurrent_Type
(Typ
)
8444 and then Present
(Corresponding_Record_Type
(Typ
))
8446 Typ
:= Corresponding_Record_Type
(Typ
);
8449 -- Simple case. Object may be a subtype of the tagged type or
8450 -- may be the corresponding record of a synchronized type.
8452 return Obj_Type
= Typ
8453 or else Base_Type
(Obj_Type
) = Typ
8454 or else Corr_Type
= Typ
8456 -- Prefix can be dereferenced
8459 (Is_Access_Type
(Corr_Type
)
8460 and then Designated_Type
(Corr_Type
) = Typ
)
8462 -- Formal is an access parameter, for which the object
8463 -- can provide an access.
8466 (Ekind
(Typ
) = E_Anonymous_Access_Type
8468 Base_Type
(Designated_Type
(Typ
)) = Base_Type
(Corr_Type
));
8469 end Valid_First_Argument_Of
;
8471 -- Start of processing for Try_Primitive_Operation
8474 -- Look for subprograms in the list of primitive operations. The name
8475 -- must be identical, and the kind of call indicates the expected
8476 -- kind of operation (function or procedure). If the type is a
8477 -- (tagged) synchronized type, the primitive ops are attached to the
8478 -- corresponding record (base) type.
8480 if Is_Concurrent_Type
(Obj_Type
) then
8481 if Present
(Corresponding_Record_Type
(Obj_Type
)) then
8482 Corr_Type
:= Base_Type
(Corresponding_Record_Type
(Obj_Type
));
8483 Elmt
:= First_Elmt
(Primitive_Operations
(Corr_Type
));
8485 Corr_Type
:= Obj_Type
;
8486 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
8489 elsif not Is_Generic_Type
(Obj_Type
) then
8490 Corr_Type
:= Obj_Type
;
8491 Elmt
:= First_Elmt
(Extended_Primitive_Ops
(Obj_Type
));
8494 Corr_Type
:= Obj_Type
;
8495 Elmt
:= First_Elmt
(Collect_Generic_Type_Ops
(Obj_Type
));
8498 while Present
(Elmt
) loop
8499 Prim_Op
:= Node
(Elmt
);
8501 if Chars
(Prim_Op
) = Chars
(Subprog
)
8502 and then Present
(First_Formal
(Prim_Op
))
8503 and then Valid_First_Argument_Of
(Prim_Op
)
8505 (Nkind
(Call_Node
) = N_Function_Call
)
8507 (Ekind
(Prim_Op
) = E_Function
)
8509 -- Ada 2005 (AI-251): If this primitive operation corresponds
8510 -- to an immediate ancestor interface there is no need to add
8511 -- it to the list of interpretations; the corresponding aliased
8512 -- primitive is also in this list of primitive operations and
8513 -- will be used instead.
8515 if (Present
(Interface_Alias
(Prim_Op
))
8516 and then Is_Ancestor
(Find_Dispatching_Type
8517 (Alias
(Prim_Op
)), Corr_Type
))
8519 -- Do not consider hidden primitives unless the type is in an
8520 -- open scope or we are within an instance, where visibility
8521 -- is known to be correct, or else if this is an overriding
8522 -- operation in the private part for an inherited operation.
8524 or else (Is_Hidden
(Prim_Op
)
8525 and then not Is_Immediately_Visible
(Obj_Type
)
8526 and then not In_Instance
8527 and then not Is_Private_Overriding
(Prim_Op
))
8532 Set_Etype
(Call_Node
, Any_Type
);
8533 Set_Is_Overloaded
(Call_Node
, False);
8535 if No
(Matching_Op
) then
8536 Prim_Op_Ref
:= New_Occurrence_Of
(Prim_Op
, Sloc
(Subprog
));
8537 Candidate
:= Prim_Op
;
8539 Set_Parent
(Call_Node
, Parent
(Node_To_Replace
));
8541 Set_Name
(Call_Node
, Prim_Op_Ref
);
8547 Report
=> Report_Error
,
8549 Skip_First
=> True);
8551 Matching_Op
:= Valid_Candidate
(Success
, Call_Node
, Prim_Op
);
8553 -- More than one interpretation, collect for subsequent
8554 -- disambiguation. If this is a procedure call and there
8555 -- is another match, report ambiguity now.
8561 Report
=> Report_Error
,
8563 Skip_First
=> True);
8565 if Present
(Valid_Candidate
(Success
, Call_Node
, Prim_Op
))
8566 and then Nkind
(Call_Node
) /= N_Function_Call
8568 Error_Msg_NE
("ambiguous call to&", N
, Prim_Op
);
8569 Report_Ambiguity
(Matching_Op
);
8570 Report_Ambiguity
(Prim_Op
);
8580 if Present
(Matching_Op
) then
8581 Set_Etype
(Call_Node
, Etype
(Matching_Op
));
8584 return Present
(Matching_Op
);
8585 end Try_Primitive_Operation
;
8587 -- Start of processing for Try_Object_Operation
8590 Analyze_Expression
(Obj
);
8592 -- Analyze the actuals if node is known to be a subprogram call
8594 if Is_Subprg_Call
and then N
= Name
(Parent
(N
)) then
8595 Actual
:= First
(Parameter_Associations
(Parent
(N
)));
8596 while Present
(Actual
) loop
8597 Analyze_Expression
(Actual
);
8602 -- Build a subprogram call node, using a copy of Obj as its first
8603 -- actual. This is a placeholder, to be replaced by an explicit
8604 -- dereference when needed.
8606 Transform_Object_Operation
8607 (Call_Node
=> New_Call_Node
,
8608 Node_To_Replace
=> Node_To_Replace
);
8610 Set_Etype
(New_Call_Node
, Any_Type
);
8611 Set_Etype
(Subprog
, Any_Type
);
8612 Set_Parent
(New_Call_Node
, Parent
(Node_To_Replace
));
8614 if not Is_Overloaded
(Obj
) then
8615 Try_One_Prefix_Interpretation
(Obj_Type
);
8622 Get_First_Interp
(Obj
, I
, It
);
8623 while Present
(It
.Nam
) loop
8624 Try_One_Prefix_Interpretation
(It
.Typ
);
8625 Get_Next_Interp
(I
, It
);
8630 if Etype
(New_Call_Node
) /= Any_Type
then
8632 -- No need to complete the tree transformations if we are only
8633 -- searching for conflicting class-wide subprograms
8635 if CW_Test_Only
then
8638 Complete_Object_Operation
8639 (Call_Node
=> New_Call_Node
,
8640 Node_To_Replace
=> Node_To_Replace
);
8644 elsif Present
(Candidate
) then
8646 -- The argument list is not type correct. Re-analyze with error
8647 -- reporting enabled, and use one of the possible candidates.
8648 -- In All_Errors_Mode, re-analyze all failed interpretations.
8650 if All_Errors_Mode
then
8651 Report_Error
:= True;
8652 if Try_Primitive_Operation
8653 (Call_Node
=> New_Call_Node
,
8654 Node_To_Replace
=> Node_To_Replace
)
8657 Try_Class_Wide_Operation
8658 (Call_Node
=> New_Call_Node
,
8659 Node_To_Replace
=> Node_To_Replace
)
8666 (N
=> New_Call_Node
,
8670 Skip_First
=> True);
8673 -- No need for further errors
8678 -- There was no candidate operation, so report it as an error
8679 -- in the caller: Analyze_Selected_Component.
8683 end Try_Object_Operation
;
8689 procedure wpo
(T
: Entity_Id
) is
8694 if not Is_Tagged_Type
(T
) then
8698 E
:= First_Elmt
(Primitive_Operations
(Base_Type
(T
)));
8699 while Present
(E
) loop
8701 Write_Int
(Int
(Op
));
8702 Write_Str
(" === ");
8703 Write_Name
(Chars
(Op
));
8705 Write_Name
(Chars
(Scope
(Op
)));