1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Contracts
; use Contracts
;
30 with Debug
; use Debug
;
31 with Einfo
; use Einfo
;
32 with Elists
; use Elists
;
33 with Errout
; use Errout
;
34 with Expander
; use Expander
;
35 with Exp_Ch6
; use Exp_Ch6
;
36 with Exp_Ch7
; use Exp_Ch7
;
37 with Exp_Ch9
; use Exp_Ch9
;
38 with Exp_Dbug
; use Exp_Dbug
;
39 with Exp_Disp
; use Exp_Disp
;
40 with Exp_Tss
; use Exp_Tss
;
41 with Exp_Util
; use Exp_Util
;
42 with Fname
; use Fname
;
43 with Freeze
; use Freeze
;
44 with Ghost
; use Ghost
;
45 with Inline
; use Inline
;
46 with Itypes
; use Itypes
;
47 with Lib
.Xref
; use Lib
.Xref
;
48 with Layout
; use Layout
;
49 with Namet
; use Namet
;
51 with Nlists
; use Nlists
;
52 with Nmake
; use Nmake
;
54 with Output
; use Output
;
55 with Restrict
; use Restrict
;
56 with Rident
; use Rident
;
57 with Rtsfind
; use Rtsfind
;
59 with Sem_Aux
; use Sem_Aux
;
60 with Sem_Cat
; use Sem_Cat
;
61 with Sem_Ch3
; use Sem_Ch3
;
62 with Sem_Ch4
; use Sem_Ch4
;
63 with Sem_Ch5
; use Sem_Ch5
;
64 with Sem_Ch8
; use Sem_Ch8
;
65 with Sem_Ch9
; use Sem_Ch9
;
66 with Sem_Ch10
; use Sem_Ch10
;
67 with Sem_Ch12
; use Sem_Ch12
;
68 with Sem_Ch13
; use Sem_Ch13
;
69 with Sem_Dim
; use Sem_Dim
;
70 with Sem_Disp
; use Sem_Disp
;
71 with Sem_Dist
; use Sem_Dist
;
72 with Sem_Elim
; use Sem_Elim
;
73 with Sem_Eval
; use Sem_Eval
;
74 with Sem_Mech
; use Sem_Mech
;
75 with Sem_Prag
; use Sem_Prag
;
76 with Sem_Res
; use Sem_Res
;
77 with Sem_Util
; use Sem_Util
;
78 with Sem_Type
; use Sem_Type
;
79 with Sem_Warn
; use Sem_Warn
;
80 with Sinput
; use Sinput
;
81 with Stand
; use Stand
;
82 with Sinfo
; use Sinfo
;
83 with Sinfo
.CN
; use Sinfo
.CN
;
84 with Snames
; use Snames
;
85 with Stringt
; use Stringt
;
87 with Stylesw
; use Stylesw
;
88 with Tbuild
; use Tbuild
;
89 with Uintp
; use Uintp
;
90 with Urealp
; use Urealp
;
91 with Validsw
; use Validsw
;
93 package body Sem_Ch6
is
95 May_Hide_Profile
: Boolean := False;
96 -- This flag is used to indicate that two formals in two subprograms being
97 -- checked for conformance differ only in that one is an access parameter
98 -- while the other is of a general access type with the same designated
99 -- type. In this case, if the rest of the signatures match, a call to
100 -- either subprogram may be ambiguous, which is worth a warning. The flag
101 -- is set in Compatible_Types, and the warning emitted in
102 -- New_Overloaded_Entity.
104 -----------------------
105 -- Local Subprograms --
106 -----------------------
108 procedure Analyze_Function_Return
(N
: Node_Id
);
109 -- Subsidiary to Analyze_Return_Statement. Called when the return statement
110 -- applies to a [generic] function.
112 procedure Analyze_Generic_Subprogram_Body
(N
: Node_Id
; Gen_Id
: Entity_Id
);
113 -- Analyze a generic subprogram body. N is the body to be analyzed, and
114 -- Gen_Id is the defining entity Id for the corresponding spec.
116 procedure Analyze_Null_Procedure
118 Is_Completion
: out Boolean);
119 -- A null procedure can be a declaration or (Ada 2012) a completion
121 procedure Analyze_Return_Statement
(N
: Node_Id
);
122 -- Common processing for simple and extended return statements
124 procedure Analyze_Return_Type
(N
: Node_Id
);
125 -- Subsidiary to Process_Formals: analyze subtype mark in function
126 -- specification in a context where the formals are visible and hide
129 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
);
130 -- Does all the real work of Analyze_Subprogram_Body. This is split out so
131 -- that we can use RETURN but not skip the debug output at the end.
133 function Can_Override_Operator
(Subp
: Entity_Id
) return Boolean;
134 -- Returns true if Subp can override a predefined operator.
136 procedure Check_Conformance
139 Ctype
: Conformance_Type
;
141 Conforms
: out Boolean;
142 Err_Loc
: Node_Id
:= Empty
;
143 Get_Inst
: Boolean := False;
144 Skip_Controlling_Formals
: Boolean := False);
145 -- Given two entities, this procedure checks that the profiles associated
146 -- with these entities meet the conformance criterion given by the third
147 -- parameter. If they conform, Conforms is set True and control returns
148 -- to the caller. If they do not conform, Conforms is set to False, and
149 -- in addition, if Errmsg is True on the call, proper messages are output
150 -- to complain about the conformance failure. If Err_Loc is non_Empty
151 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
152 -- error messages are placed on the appropriate part of the construct
153 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
154 -- against a formal access-to-subprogram type so Get_Instance_Of must
157 procedure Check_Limited_Return
161 -- Check the appropriate (Ada 95 or Ada 2005) rules for returning limited
162 -- types. Used only for simple return statements. Expr is the expression
165 procedure Check_Subprogram_Order
(N
: Node_Id
);
166 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
167 -- the alpha ordering rule for N if this ordering requirement applicable.
169 procedure Check_Returns
173 Proc
: Entity_Id
:= Empty
);
174 -- Called to check for missing return statements in a function body, or for
175 -- returns present in a procedure body which has No_Return set. HSS is the
176 -- handled statement sequence for the subprogram body. This procedure
177 -- checks all flow paths to make sure they either have return (Mode = 'F',
178 -- used for functions) or do not have a return (Mode = 'P', used for
179 -- No_Return procedures). The flag Err is set if there are any control
180 -- paths not explicitly terminated by a return in the function case, and is
181 -- True otherwise. Proc is the entity for the procedure case and is used
182 -- in posting the warning message.
184 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
);
185 -- In Ada 2012, a primitive equality operator on an untagged record type
186 -- must appear before the type is frozen, and have the same visibility as
187 -- that of the type. This procedure checks that this rule is met, and
188 -- otherwise emits an error on the subprogram declaration and a warning
189 -- on the earlier freeze point if it is easy to locate. In Ada 2012 mode,
190 -- this routine outputs errors (or warnings if -gnatd.E is set). In earlier
191 -- versions of Ada, warnings are output if Warn_On_Ada_2012_Incompatibility
192 -- is set, otherwise the call has no effect.
194 procedure Enter_Overloaded_Entity
(S
: Entity_Id
);
195 -- This procedure makes S, a new overloaded entity, into the first visible
196 -- entity with that name.
198 function Is_Non_Overriding_Operation
200 New_E
: Entity_Id
) return Boolean;
201 -- Enforce the rule given in 12.3(18): a private operation in an instance
202 -- overrides an inherited operation only if the corresponding operation
203 -- was overriding in the generic. This needs to be checked for primitive
204 -- operations of types derived (in the generic unit) from formal private
205 -- or formal derived types.
207 procedure Make_Inequality_Operator
(S
: Entity_Id
);
208 -- Create the declaration for an inequality operator that is implicitly
209 -- created by a user-defined equality operator that yields a boolean.
211 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
);
212 -- Formal_Id is an formal parameter entity. This procedure deals with
213 -- setting the proper validity status for this entity, which depends on
214 -- the kind of parameter and the validity checking mode.
216 ---------------------------------------------
217 -- Analyze_Abstract_Subprogram_Declaration --
218 ---------------------------------------------
220 procedure Analyze_Abstract_Subprogram_Declaration
(N
: Node_Id
) is
221 Scop
: constant Entity_Id
:= Current_Scope
;
222 Subp_Id
: constant Entity_Id
:=
223 Analyze_Subprogram_Specification
(Specification
(N
));
226 Check_SPARK_05_Restriction
("abstract subprogram is not allowed", N
);
228 Generate_Definition
(Subp_Id
);
230 Set_Is_Abstract_Subprogram
(Subp_Id
);
231 New_Overloaded_Entity
(Subp_Id
);
232 Check_Delayed_Subprogram
(Subp_Id
);
234 Set_Categorization_From_Scope
(Subp_Id
, Scop
);
236 if Ekind
(Scope
(Subp_Id
)) = E_Protected_Type
then
237 Error_Msg_N
("abstract subprogram not allowed in protected type", N
);
239 -- Issue a warning if the abstract subprogram is neither a dispatching
240 -- operation nor an operation that overrides an inherited subprogram or
241 -- predefined operator, since this most likely indicates a mistake.
243 elsif Warn_On_Redundant_Constructs
244 and then not Is_Dispatching_Operation
(Subp_Id
)
245 and then not Present
(Overridden_Operation
(Subp_Id
))
246 and then (not Is_Operator_Symbol_Name
(Chars
(Subp_Id
))
247 or else Scop
/= Scope
(Etype
(First_Formal
(Subp_Id
))))
250 ("abstract subprogram is not dispatching or overriding?r?", N
);
253 Generate_Reference_To_Formals
(Subp_Id
);
254 Check_Eliminated
(Subp_Id
);
256 if Has_Aspects
(N
) then
257 Analyze_Aspect_Specifications
(N
, Subp_Id
);
259 end Analyze_Abstract_Subprogram_Declaration
;
261 ---------------------------------
262 -- Analyze_Expression_Function --
263 ---------------------------------
265 procedure Analyze_Expression_Function
(N
: Node_Id
) is
266 Expr
: constant Node_Id
:= Expression
(N
);
267 Loc
: constant Source_Ptr
:= Sloc
(N
);
268 LocX
: constant Source_Ptr
:= Sloc
(Expr
);
269 Spec
: constant Node_Id
:= Specification
(N
);
277 Ret_Type
: Entity_Id
;
280 -- If the expression is a completion, Prev is the entity whose
281 -- declaration is completed. Def_Id is needed to analyze the spec.
284 -- This is one of the occasions on which we transform the tree during
285 -- semantic analysis. If this is a completion, transform the expression
286 -- function into an equivalent subprogram body, and analyze it.
288 -- Expression functions are inlined unconditionally. The back-end will
289 -- determine whether this is possible.
291 Inline_Processing_Required
:= True;
293 -- Create a specification for the generated body. This must be done
294 -- prior to the analysis of the initial declaration.
296 New_Spec
:= Copy_Subprogram_Spec
(Spec
);
297 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
299 -- If there are previous overloadable entities with the same name,
300 -- check whether any of them is completed by the expression function.
301 -- In a generic context a formal subprogram has no completion.
304 and then Is_Overloadable
(Prev
)
305 and then not Is_Formal_Subprogram
(Prev
)
307 Def_Id
:= Analyze_Subprogram_Specification
(Spec
);
308 Prev
:= Find_Corresponding_Spec
(N
);
310 -- The previous entity may be an expression function as well, in
311 -- which case the redeclaration is illegal.
314 and then Nkind
(Original_Node
(Unit_Declaration_Node
(Prev
))) =
315 N_Expression_Function
317 Error_Msg_Sloc
:= Sloc
(Prev
);
318 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
323 Ret
:= Make_Simple_Return_Statement
(LocX
, Expression
(N
));
326 Make_Subprogram_Body
(Loc
,
327 Specification
=> New_Spec
,
328 Declarations
=> Empty_List
,
329 Handled_Statement_Sequence
=>
330 Make_Handled_Sequence_Of_Statements
(LocX
,
331 Statements
=> New_List
(Ret
)));
332 Set_Was_Expression_Function
(New_Body
);
334 -- If the expression completes a generic subprogram, we must create a
335 -- separate node for the body, because at instantiation the original
336 -- node of the generic copy must be a generic subprogram body, and
337 -- cannot be a expression function. Otherwise we just rewrite the
338 -- expression with the non-generic body.
340 if Present
(Prev
) and then Ekind
(Prev
) = E_Generic_Function
then
341 Insert_After
(N
, New_Body
);
343 -- Propagate any aspects or pragmas that apply to the expression
344 -- function to the proper body when the expression function acts
347 if Has_Aspects
(N
) then
348 Move_Aspects
(N
, To
=> New_Body
);
351 Relocate_Pragmas_To_Body
(New_Body
);
353 Rewrite
(N
, Make_Null_Statement
(Loc
));
354 Set_Has_Completion
(Prev
, False);
357 Set_Is_Inlined
(Prev
);
359 -- If the expression function is a completion, the previous declaration
360 -- must come from source. We know already that it appears in the current
361 -- scope. The entity itself may be internally created if within a body
365 and then Comes_From_Source
(Parent
(Prev
))
366 and then not Is_Formal_Subprogram
(Prev
)
368 Set_Has_Completion
(Prev
, False);
369 Set_Is_Inlined
(Prev
);
370 Ret_Type
:= Etype
(Prev
);
372 -- An expression function which acts as a completion freezes the
373 -- expression. This means freezing the return type, and if it is
374 -- an access type, freezing its designated type as well.
376 -- Note that we cannot defer this freezing to the analysis of the
377 -- expression itself, because a freeze node might appear in a nested
378 -- scope, leading to an elaboration order issue in gigi.
380 Freeze_Before
(N
, Ret_Type
);
382 -- An entity can only be frozen if it is complete, so if the type
383 -- is still unfrozen it must still be incomplete in some way, e.g.
384 -- a privte type without a full view, or a type derived from such
385 -- in an enclosing scope. Except in a generic context, such an
386 -- incomplete type is an error.
388 if not Is_Frozen
(Ret_Type
)
389 and then not Is_Generic_Type
(Ret_Type
)
390 and then not Inside_A_Generic
393 ("premature use of private type&",
394 Result_Definition
(Specification
(N
)), Ret_Type
);
397 if Is_Access_Type
(Etype
(Prev
)) then
398 Freeze_Before
(N
, Designated_Type
(Etype
(Prev
)));
401 -- For navigation purposes, indicate that the function is a body
403 Generate_Reference
(Prev
, Defining_Entity
(N
), 'b', Force
=> True);
404 Rewrite
(N
, New_Body
);
406 -- Remove any existing aspects from the original node because the act
407 -- of rewriting causes the list to be shared between the two nodes.
409 Orig_N
:= Original_Node
(N
);
410 Remove_Aspects
(Orig_N
);
412 -- Propagate any pragmas that apply to the expression function to the
413 -- proper body when the expression function acts as a completion.
414 -- Aspects are automatically transfered because of node rewriting.
416 Relocate_Pragmas_To_Body
(N
);
419 -- Once the aspects of the generated body have been analyzed, create
420 -- a copy for ASIS purposes and associate it with the original node.
422 if Has_Aspects
(N
) then
423 Set_Aspect_Specifications
(Orig_N
,
424 New_Copy_List_Tree
(Aspect_Specifications
(N
)));
427 -- Prev is the previous entity with the same name, but it is can
428 -- be an unrelated spec that is not completed by the expression
429 -- function. In that case the relevant entity is the one in the body.
430 -- Not clear that the backend can inline it in this case ???
432 if Has_Completion
(Prev
) then
434 -- The formals of the expression function are body formals,
435 -- and do not appear in the ali file, which will only contain
436 -- references to the formals of the original subprogram spec.
443 F1
:= First_Formal
(Def_Id
);
444 F2
:= First_Formal
(Prev
);
446 while Present
(F1
) loop
447 Set_Spec_Entity
(F1
, F2
);
454 Set_Is_Inlined
(Defining_Entity
(New_Body
));
457 -- If this is not a completion, create both a declaration and a body, so
458 -- that the expression can be inlined whenever possible.
461 -- An expression function that is not a completion is not a
462 -- subprogram declaration, and thus cannot appear in a protected
465 if Nkind
(Parent
(N
)) = N_Protected_Definition
then
467 ("an expression function is not a legal protected operation", N
);
470 Rewrite
(N
, Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
));
472 -- Remove any existing aspects from the original node because the act
473 -- of rewriting causes the list to be shared between the two nodes.
475 Orig_N
:= Original_Node
(N
);
476 Remove_Aspects
(Orig_N
);
480 -- Once the aspects of the generated spec have been analyzed, create
481 -- a copy for ASIS purposes and associate it with the original node.
483 if Has_Aspects
(N
) then
484 Set_Aspect_Specifications
(Orig_N
,
485 New_Copy_List_Tree
(Aspect_Specifications
(N
)));
488 -- If aspect SPARK_Mode was specified on the body, it needs to be
489 -- repeated both on the generated spec and the body.
491 Asp
:= Find_Aspect
(Defining_Unit_Name
(Spec
), Aspect_SPARK_Mode
);
493 if Present
(Asp
) then
494 Asp
:= New_Copy_Tree
(Asp
);
495 Set_Analyzed
(Asp
, False);
496 Set_Aspect_Specifications
(New_Body
, New_List
(Asp
));
499 Def_Id
:= Defining_Entity
(N
);
501 -- Within a generic pre-analyze the original expression for name
502 -- capture. The body is also generated but plays no role in
503 -- this because it is not part of the original source.
505 if Inside_A_Generic
then
506 Set_Has_Completion
(Def_Id
);
508 Install_Formals
(Def_Id
);
509 Preanalyze_Spec_Expression
(Expr
, Etype
(Def_Id
));
513 Set_Is_Inlined
(Defining_Entity
(N
));
515 -- Establish the linkages between the spec and the body. These are
516 -- used when the expression function acts as the prefix of attribute
517 -- 'Access in order to freeze the original expression which has been
518 -- moved to the generated body.
520 Set_Corresponding_Body
(N
, Defining_Entity
(New_Body
));
521 Set_Corresponding_Spec
(New_Body
, Defining_Entity
(N
));
523 -- To prevent premature freeze action, insert the new body at the end
524 -- of the current declarations, or at the end of the package spec.
525 -- However, resolve usage names now, to prevent spurious visibility
526 -- on later entities. Note that the function can now be called in
527 -- the current declarative part, which will appear to be prior to
528 -- the presence of the body in the code. There are nevertheless no
529 -- order of elaboration issues because all name resolution has taken
530 -- place at the point of declaration.
533 Decls
: List_Id
:= List_Containing
(N
);
534 Expr
: constant Node_Id
:= Expression
(Ret
);
535 Par
: constant Node_Id
:= Parent
(Decls
);
536 Typ
: constant Entity_Id
:= Etype
(Def_Id
);
539 -- If this is a wrapper created for in an instance for a formal
540 -- subprogram, insert body after declaration, to be analyzed when
541 -- the enclosing instance is analyzed.
544 and then Is_Generic_Actual_Subprogram
(Defining_Entity
(N
))
546 Insert_After
(N
, New_Body
);
549 if Nkind
(Par
) = N_Package_Specification
550 and then Decls
= Visible_Declarations
(Par
)
551 and then Present
(Private_Declarations
(Par
))
552 and then not Is_Empty_List
(Private_Declarations
(Par
))
554 Decls
:= Private_Declarations
(Par
);
557 Insert_After
(Last
(Decls
), New_Body
);
559 -- Preanalyze the expression for name capture, except in an
560 -- instance, where this has been done during generic analysis,
561 -- and will be redone when analyzing the body.
563 Set_Parent
(Expr
, Ret
);
565 Install_Formals
(Def_Id
);
567 if not In_Instance
then
568 Preanalyze_Spec_Expression
(Expr
, Typ
);
569 Check_Limited_Return
(Original_Node
(N
), Expr
, Typ
);
577 -- If the return expression is a static constant, we suppress warning
578 -- messages on unused formals, which in most cases will be noise.
580 Set_Is_Trivial_Subprogram
581 (Defining_Entity
(New_Body
), Is_OK_Static_Expression
(Expr
));
582 end Analyze_Expression_Function
;
584 ----------------------------------------
585 -- Analyze_Extended_Return_Statement --
586 ----------------------------------------
588 procedure Analyze_Extended_Return_Statement
(N
: Node_Id
) is
590 Check_Compiler_Unit
("extended return statement", N
);
591 Analyze_Return_Statement
(N
);
592 end Analyze_Extended_Return_Statement
;
594 ----------------------------
595 -- Analyze_Function_Call --
596 ----------------------------
598 procedure Analyze_Function_Call
(N
: Node_Id
) is
599 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
600 Func_Nam
: constant Node_Id
:= Name
(N
);
606 -- A call of the form A.B (X) may be an Ada 2005 call, which is
607 -- rewritten as B (A, X). If the rewriting is successful, the call
608 -- has been analyzed and we just return.
610 if Nkind
(Func_Nam
) = N_Selected_Component
611 and then Name
(N
) /= Func_Nam
612 and then Is_Rewrite_Substitution
(N
)
613 and then Present
(Etype
(N
))
618 -- If error analyzing name, then set Any_Type as result type and return
620 if Etype
(Func_Nam
) = Any_Type
then
621 Set_Etype
(N
, Any_Type
);
625 -- Otherwise analyze the parameters
627 if Present
(Actuals
) then
628 Actual
:= First
(Actuals
);
629 while Present
(Actual
) loop
631 Check_Parameterless_Call
(Actual
);
637 end Analyze_Function_Call
;
639 -----------------------------
640 -- Analyze_Function_Return --
641 -----------------------------
643 procedure Analyze_Function_Return
(N
: Node_Id
) is
644 Loc
: constant Source_Ptr
:= Sloc
(N
);
645 Stm_Entity
: constant Entity_Id
:= Return_Statement_Entity
(N
);
646 Scope_Id
: constant Entity_Id
:= Return_Applies_To
(Stm_Entity
);
648 R_Type
: constant Entity_Id
:= Etype
(Scope_Id
);
649 -- Function result subtype
651 procedure Check_Aggregate_Accessibility
(Aggr
: Node_Id
);
652 -- Apply legality rule of 6.5 (5.8) to the access discriminants of an
653 -- aggregate in a return statement.
655 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
);
656 -- Check that the return_subtype_indication properly matches the result
657 -- subtype of the function, as required by RM-6.5(5.1/2-5.3/2).
659 -----------------------------------
660 -- Check_Aggregate_Accessibility --
661 -----------------------------------
663 procedure Check_Aggregate_Accessibility
(Aggr
: Node_Id
) is
664 Typ
: constant Entity_Id
:= Etype
(Aggr
);
671 if Is_Record_Type
(Typ
) and then Has_Discriminants
(Typ
) then
672 Discr
:= First_Discriminant
(Typ
);
673 Assoc
:= First
(Component_Associations
(Aggr
));
674 while Present
(Discr
) loop
675 if Ekind
(Etype
(Discr
)) = E_Anonymous_Access_Type
then
676 Expr
:= Expression
(Assoc
);
678 if Nkind
(Expr
) = N_Attribute_Reference
679 and then Attribute_Name
(Expr
) /= Name_Unrestricted_Access
681 Obj
:= Prefix
(Expr
);
682 while Nkind_In
(Obj
, N_Indexed_Component
,
683 N_Selected_Component
)
688 -- Do not check aliased formals or function calls. A
689 -- run-time check may still be needed ???
691 if Is_Entity_Name
(Obj
)
692 and then Comes_From_Source
(Obj
)
694 if Is_Formal
(Entity
(Obj
))
695 and then Is_Aliased
(Entity
(Obj
))
699 elsif Object_Access_Level
(Obj
) >
700 Scope_Depth
(Scope
(Scope_Id
))
703 ("access discriminant in return aggregate would "
704 & "be a dangling reference", Obj
);
710 Next_Discriminant
(Discr
);
713 end Check_Aggregate_Accessibility
;
715 -------------------------------------
716 -- Check_Return_Subtype_Indication --
717 -------------------------------------
719 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
) is
720 Return_Obj
: constant Node_Id
:= Defining_Identifier
(Obj_Decl
);
722 R_Stm_Type
: constant Entity_Id
:= Etype
(Return_Obj
);
723 -- Subtype given in the extended return statement (must match R_Type)
725 Subtype_Ind
: constant Node_Id
:=
726 Object_Definition
(Original_Node
(Obj_Decl
));
728 R_Type_Is_Anon_Access
: constant Boolean :=
730 E_Anonymous_Access_Subprogram_Type
,
731 E_Anonymous_Access_Protected_Subprogram_Type
,
732 E_Anonymous_Access_Type
);
733 -- True if return type of the function is an anonymous access type
734 -- Can't we make Is_Anonymous_Access_Type in einfo ???
736 R_Stm_Type_Is_Anon_Access
: constant Boolean :=
737 Ekind_In
(R_Stm_Type
,
738 E_Anonymous_Access_Subprogram_Type
,
739 E_Anonymous_Access_Protected_Subprogram_Type
,
740 E_Anonymous_Access_Type
);
741 -- True if type of the return object is an anonymous access type
743 procedure Error_No_Match
(N
: Node_Id
);
744 -- Output error messages for case where types do not statically
745 -- match. N is the location for the messages.
751 procedure Error_No_Match
(N
: Node_Id
) is
754 ("subtype must statically match function result subtype", N
);
756 if not Predicates_Match
(R_Stm_Type
, R_Type
) then
757 Error_Msg_Node_2
:= R_Type
;
759 ("\predicate of& does not match predicate of&",
764 -- Start of processing for Check_Return_Subtype_Indication
767 -- First, avoid cascaded errors
769 if Error_Posted
(Obj_Decl
) or else Error_Posted
(Subtype_Ind
) then
773 -- "return access T" case; check that the return statement also has
774 -- "access T", and that the subtypes statically match:
775 -- if this is an access to subprogram the signatures must match.
777 if R_Type_Is_Anon_Access
then
778 if R_Stm_Type_Is_Anon_Access
then
780 Ekind
(Designated_Type
(R_Stm_Type
)) /= E_Subprogram_Type
782 if Base_Type
(Designated_Type
(R_Stm_Type
)) /=
783 Base_Type
(Designated_Type
(R_Type
))
784 or else not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
)
786 Error_No_Match
(Subtype_Mark
(Subtype_Ind
));
790 -- For two anonymous access to subprogram types, the
791 -- types themselves must be type conformant.
793 if not Conforming_Types
794 (R_Stm_Type
, R_Type
, Fully_Conformant
)
796 Error_No_Match
(Subtype_Ind
);
801 Error_Msg_N
("must use anonymous access type", Subtype_Ind
);
804 -- If the return object is of an anonymous access type, then report
805 -- an error if the function's result type is not also anonymous.
807 elsif R_Stm_Type_Is_Anon_Access
then
808 pragma Assert
(not R_Type_Is_Anon_Access
);
809 Error_Msg_N
("anonymous access not allowed for function with "
810 & "named access result", Subtype_Ind
);
812 -- Subtype indication case: check that the return object's type is
813 -- covered by the result type, and that the subtypes statically match
814 -- when the result subtype is constrained. Also handle record types
815 -- with unknown discriminants for which we have built the underlying
816 -- record view. Coverage is needed to allow specific-type return
817 -- objects when the result type is class-wide (see AI05-32).
819 elsif Covers
(Base_Type
(R_Type
), Base_Type
(R_Stm_Type
))
820 or else (Is_Underlying_Record_View
(Base_Type
(R_Stm_Type
))
824 Underlying_Record_View
(Base_Type
(R_Stm_Type
))))
826 -- A null exclusion may be present on the return type, on the
827 -- function specification, on the object declaration or on the
830 if Is_Access_Type
(R_Type
)
832 (Can_Never_Be_Null
(R_Type
)
833 or else Null_Exclusion_Present
(Parent
(Scope_Id
))) /=
834 Can_Never_Be_Null
(R_Stm_Type
)
836 Error_No_Match
(Subtype_Ind
);
839 -- AI05-103: for elementary types, subtypes must statically match
841 if Is_Constrained
(R_Type
)
842 or else Is_Access_Type
(R_Type
)
844 if not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
) then
845 Error_No_Match
(Subtype_Ind
);
849 -- All remaining cases are illegal
851 -- Note: previous versions of this subprogram allowed the return
852 -- value to be the ancestor of the return type if the return type
853 -- was a null extension. This was plainly incorrect.
857 ("wrong type for return_subtype_indication", Subtype_Ind
);
859 end Check_Return_Subtype_Indication
;
861 ---------------------
862 -- Local Variables --
863 ---------------------
868 -- Start of processing for Analyze_Function_Return
871 Set_Return_Present
(Scope_Id
);
873 if Nkind
(N
) = N_Simple_Return_Statement
then
874 Expr
:= Expression
(N
);
876 -- Guard against a malformed expression. The parser may have tried to
877 -- recover but the node is not analyzable.
879 if Nkind
(Expr
) = N_Error
then
880 Set_Etype
(Expr
, Any_Type
);
881 Expander_Mode_Save_And_Set
(False);
885 -- The resolution of a controlled [extension] aggregate associated
886 -- with a return statement creates a temporary which needs to be
887 -- finalized on function exit. Wrap the return statement inside a
888 -- block so that the finalization machinery can detect this case.
889 -- This early expansion is done only when the return statement is
890 -- not part of a handled sequence of statements.
892 if Nkind_In
(Expr
, N_Aggregate
,
893 N_Extension_Aggregate
)
894 and then Needs_Finalization
(R_Type
)
895 and then Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
898 Make_Block_Statement
(Loc
,
899 Handled_Statement_Sequence
=>
900 Make_Handled_Sequence_Of_Statements
(Loc
,
901 Statements
=> New_List
(Relocate_Node
(N
)))));
909 -- Ada 2005 (AI-251): If the type of the returned object is
910 -- an access to an interface type then we add an implicit type
911 -- conversion to force the displacement of the "this" pointer to
912 -- reference the secondary dispatch table. We cannot delay the
913 -- generation of this implicit conversion until the expansion
914 -- because in this case the type resolution changes the decoration
915 -- of the expression node to match R_Type; by contrast, if the
916 -- returned object is a class-wide interface type then it is too
917 -- early to generate here the implicit conversion since the return
918 -- statement may be rewritten by the expander into an extended
919 -- return statement whose expansion takes care of adding the
920 -- implicit type conversion to displace the pointer to the object.
923 and then Serious_Errors_Detected
= 0
924 and then Is_Access_Type
(R_Type
)
925 and then Nkind
(Expr
) /= N_Null
926 and then Is_Interface
(Designated_Type
(R_Type
))
927 and then Is_Progenitor
(Designated_Type
(R_Type
),
928 Designated_Type
(Etype
(Expr
)))
930 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
934 Resolve
(Expr
, R_Type
);
935 Check_Limited_Return
(N
, Expr
, R_Type
);
937 if Present
(Expr
) and then Nkind
(Expr
) = N_Aggregate
then
938 Check_Aggregate_Accessibility
(Expr
);
942 -- RETURN only allowed in SPARK as the last statement in function
944 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
946 (Nkind
(Parent
(Parent
(N
))) /= N_Subprogram_Body
947 or else Present
(Next
(N
)))
949 Check_SPARK_05_Restriction
950 ("RETURN should be the last statement in function", N
);
954 Check_SPARK_05_Restriction
("extended RETURN is not allowed", N
);
955 Obj_Decl
:= Last
(Return_Object_Declarations
(N
));
957 -- Analyze parts specific to extended_return_statement:
960 Has_Aliased
: constant Boolean := Aliased_Present
(Obj_Decl
);
961 HSS
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
964 Expr
:= Expression
(Obj_Decl
);
966 -- Note: The check for OK_For_Limited_Init will happen in
967 -- Analyze_Object_Declaration; we treat it as a normal
968 -- object declaration.
970 Set_Is_Return_Object
(Defining_Identifier
(Obj_Decl
));
973 Check_Return_Subtype_Indication
(Obj_Decl
);
975 if Present
(HSS
) then
978 if Present
(Exception_Handlers
(HSS
)) then
980 -- ???Has_Nested_Block_With_Handler needs to be set.
981 -- Probably by creating an actual N_Block_Statement.
982 -- Probably in Expand.
988 -- Mark the return object as referenced, since the return is an
989 -- implicit reference of the object.
991 Set_Referenced
(Defining_Identifier
(Obj_Decl
));
993 Check_References
(Stm_Entity
);
995 -- Check RM 6.5 (5.9/3)
998 if Ada_Version
< Ada_2012
then
1000 -- Shouldn't this test Warn_On_Ada_2012_Compatibility ???
1001 -- Can it really happen (extended return???)
1004 ("aliased only allowed for limited return objects "
1005 & "in Ada 2012??", N
);
1007 elsif not Is_Limited_View
(R_Type
) then
1009 ("aliased only allowed for limited return objects", N
);
1015 -- Case of Expr present
1019 -- Defend against previous errors
1021 and then Nkind
(Expr
) /= N_Empty
1022 and then Present
(Etype
(Expr
))
1024 -- Apply constraint check. Note that this is done before the implicit
1025 -- conversion of the expression done for anonymous access types to
1026 -- ensure correct generation of the null-excluding check associated
1027 -- with null-excluding expressions found in return statements.
1029 Apply_Constraint_Check
(Expr
, R_Type
);
1031 -- Ada 2005 (AI-318-02): When the result type is an anonymous access
1032 -- type, apply an implicit conversion of the expression to that type
1033 -- to force appropriate static and run-time accessibility checks.
1035 if Ada_Version
>= Ada_2005
1036 and then Ekind
(R_Type
) = E_Anonymous_Access_Type
1038 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
1039 Analyze_And_Resolve
(Expr
, R_Type
);
1041 -- If this is a local anonymous access to subprogram, the
1042 -- accessibility check can be applied statically. The return is
1043 -- illegal if the access type of the return expression is declared
1044 -- inside of the subprogram (except if it is the subtype indication
1045 -- of an extended return statement).
1047 elsif Ekind
(R_Type
) = E_Anonymous_Access_Subprogram_Type
then
1048 if not Comes_From_Source
(Current_Scope
)
1049 or else Ekind
(Current_Scope
) = E_Return_Statement
1054 Scope_Depth
(Scope
(Etype
(Expr
))) >= Scope_Depth
(Scope_Id
)
1056 Error_Msg_N
("cannot return local access to subprogram", N
);
1059 -- The expression cannot be of a formal incomplete type
1061 elsif Ekind
(Etype
(Expr
)) = E_Incomplete_Type
1062 and then Is_Generic_Type
(Etype
(Expr
))
1065 ("cannot return expression of a formal incomplete type", N
);
1068 -- If the result type is class-wide, then check that the return
1069 -- expression's type is not declared at a deeper level than the
1070 -- function (RM05-6.5(5.6/2)).
1072 if Ada_Version
>= Ada_2005
1073 and then Is_Class_Wide_Type
(R_Type
)
1075 if Type_Access_Level
(Etype
(Expr
)) >
1076 Subprogram_Access_Level
(Scope_Id
)
1079 ("level of return expression type is deeper than "
1080 & "class-wide function!", Expr
);
1084 -- Check incorrect use of dynamically tagged expression
1086 if Is_Tagged_Type
(R_Type
) then
1087 Check_Dynamically_Tagged_Expression
1093 -- ??? A real run-time accessibility check is needed in cases
1094 -- involving dereferences of access parameters. For now we just
1095 -- check the static cases.
1097 if (Ada_Version
< Ada_2005
or else Debug_Flag_Dot_L
)
1098 and then Is_Limited_View
(Etype
(Scope_Id
))
1099 and then Object_Access_Level
(Expr
) >
1100 Subprogram_Access_Level
(Scope_Id
)
1102 -- Suppress the message in a generic, where the rewriting
1105 if Inside_A_Generic
then
1110 Make_Raise_Program_Error
(Loc
,
1111 Reason
=> PE_Accessibility_Check_Failed
));
1114 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1115 Error_Msg_N
("cannot return a local value by reference<<", N
);
1116 Error_Msg_NE
("\& [<<", N
, Standard_Program_Error
);
1120 if Known_Null
(Expr
)
1121 and then Nkind
(Parent
(Scope_Id
)) = N_Function_Specification
1122 and then Null_Exclusion_Present
(Parent
(Scope_Id
))
1124 Apply_Compile_Time_Constraint_Error
1126 Msg
=> "(Ada 2005) null not allowed for "
1127 & "null-excluding return??",
1128 Reason
=> CE_Null_Not_Allowed
);
1131 -- RM 6.5 (5.4/3): accessibility checks also apply if the return object
1132 -- has no initializing expression.
1134 elsif Ada_Version
> Ada_2005
and then Is_Class_Wide_Type
(R_Type
) then
1135 if Type_Access_Level
(Etype
(Defining_Identifier
(Obj_Decl
))) >
1136 Subprogram_Access_Level
(Scope_Id
)
1139 ("level of return expression type is deeper than "
1140 & "class-wide function!", Obj_Decl
);
1143 end Analyze_Function_Return
;
1145 -------------------------------------
1146 -- Analyze_Generic_Subprogram_Body --
1147 -------------------------------------
1149 procedure Analyze_Generic_Subprogram_Body
1153 Gen_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Gen_Id
);
1154 Kind
: constant Entity_Kind
:= Ekind
(Gen_Id
);
1155 Body_Id
: Entity_Id
;
1160 -- Copy body and disable expansion while analyzing the generic For a
1161 -- stub, do not copy the stub (which would load the proper body), this
1162 -- will be done when the proper body is analyzed.
1164 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1165 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
1168 -- Once the contents of the generic copy and the template are
1169 -- swapped, do the same for their respective aspect specifications.
1171 Exchange_Aspects
(N
, New_N
);
1173 -- Collect all contract-related source pragmas found within the
1174 -- template and attach them to the contract of the subprogram body.
1175 -- This contract is used in the capture of global references within
1178 Create_Generic_Contract
(N
);
1183 Spec
:= Specification
(N
);
1185 -- Within the body of the generic, the subprogram is callable, and
1186 -- behaves like the corresponding non-generic unit.
1188 Body_Id
:= Defining_Entity
(Spec
);
1190 if Kind
= E_Generic_Procedure
1191 and then Nkind
(Spec
) /= N_Procedure_Specification
1193 Error_Msg_N
("invalid body for generic procedure ", Body_Id
);
1196 elsif Kind
= E_Generic_Function
1197 and then Nkind
(Spec
) /= N_Function_Specification
1199 Error_Msg_N
("invalid body for generic function ", Body_Id
);
1203 Set_Corresponding_Body
(Gen_Decl
, Body_Id
);
1205 if Has_Completion
(Gen_Id
)
1206 and then Nkind
(Parent
(N
)) /= N_Subunit
1208 Error_Msg_N
("duplicate generic body", N
);
1211 Set_Has_Completion
(Gen_Id
);
1214 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1215 Set_Ekind
(Defining_Entity
(Specification
(N
)), Kind
);
1217 Set_Corresponding_Spec
(N
, Gen_Id
);
1220 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1221 Set_Cunit_Entity
(Current_Sem_Unit
, Defining_Entity
(N
));
1224 -- Make generic parameters immediately visible in the body. They are
1225 -- needed to process the formals declarations. Then make the formals
1226 -- visible in a separate step.
1228 Push_Scope
(Gen_Id
);
1232 First_Ent
: Entity_Id
;
1235 First_Ent
:= First_Entity
(Gen_Id
);
1238 while Present
(E
) and then not Is_Formal
(E
) loop
1243 Set_Use
(Generic_Formal_Declarations
(Gen_Decl
));
1245 -- Now generic formals are visible, and the specification can be
1246 -- analyzed, for subsequent conformance check.
1248 Body_Id
:= Analyze_Subprogram_Specification
(Spec
);
1250 -- Make formal parameters visible
1254 -- E is the first formal parameter, we loop through the formals
1255 -- installing them so that they will be visible.
1257 Set_First_Entity
(Gen_Id
, E
);
1258 while Present
(E
) loop
1264 -- Visible generic entity is callable within its own body
1266 Set_Ekind
(Gen_Id
, Ekind
(Body_Id
));
1267 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
1268 Set_Convention
(Body_Id
, Convention
(Gen_Id
));
1269 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Gen_Id
));
1270 Set_Scope
(Body_Id
, Scope
(Gen_Id
));
1272 Check_Fully_Conformant
(Body_Id
, Gen_Id
, Body_Id
);
1274 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1276 -- No body to analyze, so restore state of generic unit
1278 Set_Ekind
(Gen_Id
, Kind
);
1279 Set_Ekind
(Body_Id
, Kind
);
1281 if Present
(First_Ent
) then
1282 Set_First_Entity
(Gen_Id
, First_Ent
);
1289 -- If this is a compilation unit, it must be made visible explicitly,
1290 -- because the compilation of the declaration, unlike other library
1291 -- unit declarations, does not. If it is not a unit, the following
1292 -- is redundant but harmless.
1294 Set_Is_Immediately_Visible
(Gen_Id
);
1295 Reference_Body_Formals
(Gen_Id
, Body_Id
);
1297 if Is_Child_Unit
(Gen_Id
) then
1298 Generate_Reference
(Gen_Id
, Scope
(Gen_Id
), 'k', False);
1301 Set_Actual_Subtypes
(N
, Current_Scope
);
1303 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
1304 Set_SPARK_Pragma_Inherited
(Body_Id
);
1306 -- Analyze any aspect specifications that appear on the generic
1309 if Has_Aspects
(N
) then
1310 Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
);
1313 Analyze_Declarations
(Declarations
(N
));
1316 -- Process the contract of the subprogram body after all declarations
1317 -- have been analyzed. This ensures that any contract-related pragmas
1318 -- are available through the N_Contract node of the body.
1320 Analyze_Entry_Or_Subprogram_Body_Contract
(Body_Id
);
1322 Analyze
(Handled_Statement_Sequence
(N
));
1323 Save_Global_References
(Original_Node
(N
));
1325 -- Prior to exiting the scope, include generic formals again (if any
1326 -- are present) in the set of local entities.
1328 if Present
(First_Ent
) then
1329 Set_First_Entity
(Gen_Id
, First_Ent
);
1332 Check_References
(Gen_Id
);
1335 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Current_Scope
);
1337 Check_Subprogram_Order
(N
);
1339 -- Outside of its body, unit is generic again
1341 Set_Ekind
(Gen_Id
, Kind
);
1342 Generate_Reference
(Gen_Id
, Body_Id
, 'b', Set_Ref
=> False);
1345 Style
.Check_Identifier
(Body_Id
, Gen_Id
);
1349 end Analyze_Generic_Subprogram_Body
;
1351 ----------------------------
1352 -- Analyze_Null_Procedure --
1353 ----------------------------
1355 procedure Analyze_Null_Procedure
1357 Is_Completion
: out Boolean)
1359 Loc
: constant Source_Ptr
:= Sloc
(N
);
1360 Spec
: constant Node_Id
:= Specification
(N
);
1361 Designator
: Entity_Id
;
1363 Null_Body
: Node_Id
:= Empty
;
1367 -- Capture the profile of the null procedure before analysis, for
1368 -- expansion at the freeze point and at each point of call. The body is
1369 -- used if the procedure has preconditions, or if it is a completion. In
1370 -- the first case the body is analyzed at the freeze point, in the other
1371 -- it replaces the null procedure declaration.
1374 Make_Subprogram_Body
(Loc
,
1375 Specification
=> New_Copy_Tree
(Spec
),
1376 Declarations
=> New_List
,
1377 Handled_Statement_Sequence
=>
1378 Make_Handled_Sequence_Of_Statements
(Loc
,
1379 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
1381 -- Create new entities for body and formals
1383 Set_Defining_Unit_Name
(Specification
(Null_Body
),
1384 Make_Defining_Identifier
1385 (Sloc
(Defining_Entity
(N
)),
1386 Chars
(Defining_Entity
(N
))));
1388 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1389 while Present
(Form
) loop
1390 Set_Defining_Identifier
(Form
,
1391 Make_Defining_Identifier
1392 (Sloc
(Defining_Identifier
(Form
)),
1393 Chars
(Defining_Identifier
(Form
))));
1397 -- Determine whether the null procedure may be a completion of a generic
1398 -- suprogram, in which case we use the new null body as the completion
1399 -- and set minimal semantic information on the original declaration,
1400 -- which is rewritten as a null statement.
1402 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
1404 if Present
(Prev
) and then Is_Generic_Subprogram
(Prev
) then
1405 Insert_Before
(N
, Null_Body
);
1406 Set_Ekind
(Defining_Entity
(N
), Ekind
(Prev
));
1408 Rewrite
(N
, Make_Null_Statement
(Loc
));
1409 Analyze_Generic_Subprogram_Body
(Null_Body
, Prev
);
1410 Is_Completion
:= True;
1414 -- Resolve the types of the formals now, because the freeze point
1415 -- may appear in a different context, e.g. an instantiation.
1417 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1418 while Present
(Form
) loop
1419 if Nkind
(Parameter_Type
(Form
)) /= N_Access_Definition
then
1420 Find_Type
(Parameter_Type
(Form
));
1423 No
(Access_To_Subprogram_Definition
(Parameter_Type
(Form
)))
1425 Find_Type
(Subtype_Mark
(Parameter_Type
(Form
)));
1428 -- The case of a null procedure with a formal that is an
1429 -- access_to_subprogram type, and that is used as an actual
1430 -- in an instantiation is left to the enthusiastic reader.
1439 -- If there are previous overloadable entities with the same name,
1440 -- check whether any of them is completed by the null procedure.
1442 if Present
(Prev
) and then Is_Overloadable
(Prev
) then
1443 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1444 Prev
:= Find_Corresponding_Spec
(N
);
1447 if No
(Prev
) or else not Comes_From_Source
(Prev
) then
1448 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1449 Set_Has_Completion
(Designator
);
1451 -- Signal to caller that this is a procedure declaration
1453 Is_Completion
:= False;
1455 -- Null procedures are always inlined, but generic formal subprograms
1456 -- which appear as such in the internal instance of formal packages,
1457 -- need no completion and are not marked Inline.
1460 and then Nkind
(N
) /= N_Formal_Concrete_Subprogram_Declaration
1462 Set_Corresponding_Body
(N
, Defining_Entity
(Null_Body
));
1463 Set_Body_To_Inline
(N
, Null_Body
);
1464 Set_Is_Inlined
(Designator
);
1468 -- The null procedure is a completion. We unconditionally rewrite
1469 -- this as a null body (even if expansion is not active), because
1470 -- there are various error checks that are applied on this body
1471 -- when it is analyzed (e.g. correct aspect placement).
1473 if Has_Completion
(Prev
) then
1474 Error_Msg_Sloc
:= Sloc
(Prev
);
1475 Error_Msg_NE
("duplicate body for & declared#", N
, Prev
);
1478 Is_Completion
:= True;
1479 Rewrite
(N
, Null_Body
);
1482 end Analyze_Null_Procedure
;
1484 -----------------------------
1485 -- Analyze_Operator_Symbol --
1486 -----------------------------
1488 -- An operator symbol such as "+" or "and" may appear in context where the
1489 -- literal denotes an entity name, such as "+"(x, y) or in context when it
1490 -- is just a string, as in (conjunction = "or"). In these cases the parser
1491 -- generates this node, and the semantics does the disambiguation. Other
1492 -- such case are actuals in an instantiation, the generic unit in an
1493 -- instantiation, and pragma arguments.
1495 procedure Analyze_Operator_Symbol
(N
: Node_Id
) is
1496 Par
: constant Node_Id
:= Parent
(N
);
1499 if (Nkind
(Par
) = N_Function_Call
and then N
= Name
(Par
))
1500 or else Nkind
(Par
) = N_Function_Instantiation
1501 or else (Nkind
(Par
) = N_Indexed_Component
and then N
= Prefix
(Par
))
1502 or else (Nkind
(Par
) = N_Pragma_Argument_Association
1503 and then not Is_Pragma_String_Literal
(Par
))
1504 or else Nkind
(Par
) = N_Subprogram_Renaming_Declaration
1505 or else (Nkind
(Par
) = N_Attribute_Reference
1506 and then Attribute_Name
(Par
) /= Name_Value
)
1508 Find_Direct_Name
(N
);
1511 Change_Operator_Symbol_To_String_Literal
(N
);
1514 end Analyze_Operator_Symbol
;
1516 -----------------------------------
1517 -- Analyze_Parameter_Association --
1518 -----------------------------------
1520 procedure Analyze_Parameter_Association
(N
: Node_Id
) is
1522 Analyze
(Explicit_Actual_Parameter
(N
));
1523 end Analyze_Parameter_Association
;
1525 ----------------------------
1526 -- Analyze_Procedure_Call --
1527 ----------------------------
1529 -- WARNING: This routine manages Ghost regions. Return statements must be
1530 -- replaced by gotos which jump to the end of the routine and restore the
1533 procedure Analyze_Procedure_Call
(N
: Node_Id
) is
1534 procedure Analyze_Call_And_Resolve
;
1535 -- Do Analyze and Resolve calls for procedure call. At the end, check
1536 -- for illegal order dependence.
1537 -- ??? where is the check for illegal order dependencies?
1539 ------------------------------
1540 -- Analyze_Call_And_Resolve --
1541 ------------------------------
1543 procedure Analyze_Call_And_Resolve
is
1545 if Nkind
(N
) = N_Procedure_Call_Statement
then
1547 Resolve
(N
, Standard_Void_Type
);
1551 end Analyze_Call_And_Resolve
;
1555 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
1556 Loc
: constant Source_Ptr
:= Sloc
(N
);
1557 P
: constant Node_Id
:= Name
(N
);
1559 Mode
: Ghost_Mode_Type
;
1562 -- Start of processing for Analyze_Procedure_Call
1565 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
1566 -- a procedure call or an entry call. The prefix may denote an access
1567 -- to subprogram type, in which case an implicit dereference applies.
1568 -- If the prefix is an indexed component (without implicit dereference)
1569 -- then the construct denotes a call to a member of an entire family.
1570 -- If the prefix is a simple name, it may still denote a call to a
1571 -- parameterless member of an entry family. Resolution of these various
1572 -- interpretations is delicate.
1574 -- Do not analyze machine code statements to avoid rejecting them in
1577 if CodePeer_Mode
and then Nkind
(P
) = N_Qualified_Expression
then
1578 Set_Etype
(P
, Standard_Void_Type
);
1583 -- If this is a call of the form Obj.Op, the call may have been analyzed
1584 -- and possibly rewritten into a block, in which case we are done.
1586 if Analyzed
(N
) then
1590 -- If there is an error analyzing the name (which may have been
1591 -- rewritten if the original call was in prefix notation) then error
1592 -- has been emitted already, mark node and return.
1594 if Error_Posted
(N
) or else Etype
(Name
(N
)) = Any_Type
then
1595 Set_Etype
(N
, Any_Type
);
1599 -- A procedure call is Ghost when its name denotes a Ghost procedure.
1600 -- Set the mode now to ensure that any nodes generated during analysis
1601 -- and expansion are properly marked as Ghost.
1603 Mark_And_Set_Ghost_Procedure_Call
(N
, Mode
);
1605 -- Otherwise analyze the parameters
1607 if Present
(Actuals
) then
1608 Actual
:= First
(Actuals
);
1610 while Present
(Actual
) loop
1612 Check_Parameterless_Call
(Actual
);
1617 -- Special processing for Elab_Spec, Elab_Body and Elab_Subp_Body calls
1619 if Nkind
(P
) = N_Attribute_Reference
1620 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Spec
,
1622 Name_Elab_Subp_Body
)
1624 if Present
(Actuals
) then
1626 ("no parameters allowed for this call", First
(Actuals
));
1630 Set_Etype
(N
, Standard_Void_Type
);
1633 elsif Is_Entity_Name
(P
)
1634 and then Is_Record_Type
(Etype
(Entity
(P
)))
1635 and then Remote_AST_I_Dereference
(P
)
1639 elsif Is_Entity_Name
(P
)
1640 and then Ekind
(Entity
(P
)) /= E_Entry_Family
1642 if Is_Access_Type
(Etype
(P
))
1643 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1644 and then No
(Actuals
)
1645 and then Comes_From_Source
(N
)
1647 Error_Msg_N
("missing explicit dereference in call", N
);
1650 Analyze_Call_And_Resolve
;
1652 -- If the prefix is the simple name of an entry family, this is a
1653 -- parameterless call from within the task body itself.
1655 elsif Is_Entity_Name
(P
)
1656 and then Nkind
(P
) = N_Identifier
1657 and then Ekind
(Entity
(P
)) = E_Entry_Family
1658 and then Present
(Actuals
)
1659 and then No
(Next
(First
(Actuals
)))
1661 -- Can be call to parameterless entry family. What appears to be the
1662 -- sole argument is in fact the entry index. Rewrite prefix of node
1663 -- accordingly. Source representation is unchanged by this
1667 Make_Indexed_Component
(Loc
,
1669 Make_Selected_Component
(Loc
,
1670 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(P
)), Loc
),
1671 Selector_Name
=> New_Occurrence_Of
(Entity
(P
), Loc
)),
1672 Expressions
=> Actuals
);
1673 Set_Name
(N
, New_N
);
1674 Set_Etype
(New_N
, Standard_Void_Type
);
1675 Set_Parameter_Associations
(N
, No_List
);
1676 Analyze_Call_And_Resolve
;
1678 elsif Nkind
(P
) = N_Explicit_Dereference
then
1679 if Ekind
(Etype
(P
)) = E_Subprogram_Type
then
1680 Analyze_Call_And_Resolve
;
1682 Error_Msg_N
("expect access to procedure in call", P
);
1685 -- The name can be a selected component or an indexed component that
1686 -- yields an access to subprogram. Such a prefix is legal if the call
1687 -- has parameter associations.
1689 elsif Is_Access_Type
(Etype
(P
))
1690 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1692 if Present
(Actuals
) then
1693 Analyze_Call_And_Resolve
;
1695 Error_Msg_N
("missing explicit dereference in call ", N
);
1698 -- If not an access to subprogram, then the prefix must resolve to the
1699 -- name of an entry, entry family, or protected operation.
1701 -- For the case of a simple entry call, P is a selected component where
1702 -- the prefix is the task and the selector name is the entry. A call to
1703 -- a protected procedure will have the same syntax. If the protected
1704 -- object contains overloaded operations, the entity may appear as a
1705 -- function, the context will select the operation whose type is Void.
1707 elsif Nkind
(P
) = N_Selected_Component
1708 and then Ekind_In
(Entity
(Selector_Name
(P
)), E_Entry
,
1712 -- When front-end inlining is enabled, as with SPARK_Mode, a call
1713 -- in prefix notation may still be missing its controlling argument,
1714 -- so perform the transformation now.
1716 if SPARK_Mode
= On
and then In_Inlined_Body
then
1718 Subp
: constant Entity_Id
:= Entity
(Selector_Name
(P
));
1719 Typ
: constant Entity_Id
:= Etype
(Prefix
(P
));
1722 if Is_Tagged_Type
(Typ
)
1723 and then Present
(First_Formal
(Subp
))
1724 and then Etype
(First_Formal
(Subp
)) = Typ
1725 and then Try_Object_Operation
(P
)
1730 Analyze_Call_And_Resolve
;
1735 Analyze_Call_And_Resolve
;
1738 elsif Nkind
(P
) = N_Selected_Component
1739 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
1740 and then Present
(Actuals
)
1741 and then No
(Next
(First
(Actuals
)))
1743 -- Can be call to parameterless entry family. What appears to be the
1744 -- sole argument is in fact the entry index. Rewrite prefix of node
1745 -- accordingly. Source representation is unchanged by this
1749 Make_Indexed_Component
(Loc
,
1750 Prefix
=> New_Copy
(P
),
1751 Expressions
=> Actuals
);
1752 Set_Name
(N
, New_N
);
1753 Set_Etype
(New_N
, Standard_Void_Type
);
1754 Set_Parameter_Associations
(N
, No_List
);
1755 Analyze_Call_And_Resolve
;
1757 -- For the case of a reference to an element of an entry family, P is
1758 -- an indexed component whose prefix is a selected component (task and
1759 -- entry family), and whose index is the entry family index.
1761 elsif Nkind
(P
) = N_Indexed_Component
1762 and then Nkind
(Prefix
(P
)) = N_Selected_Component
1763 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) = E_Entry_Family
1765 Analyze_Call_And_Resolve
;
1767 -- If the prefix is the name of an entry family, it is a call from
1768 -- within the task body itself.
1770 elsif Nkind
(P
) = N_Indexed_Component
1771 and then Nkind
(Prefix
(P
)) = N_Identifier
1772 and then Ekind
(Entity
(Prefix
(P
))) = E_Entry_Family
1775 Make_Selected_Component
(Loc
,
1776 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(Prefix
(P
))), Loc
),
1777 Selector_Name
=> New_Occurrence_Of
(Entity
(Prefix
(P
)), Loc
));
1778 Rewrite
(Prefix
(P
), New_N
);
1780 Analyze_Call_And_Resolve
;
1782 -- In Ada 2012. a qualified expression is a name, but it cannot be a
1783 -- procedure name, so the construct can only be a qualified expression.
1785 elsif Nkind
(P
) = N_Qualified_Expression
1786 and then Ada_Version
>= Ada_2012
1788 Rewrite
(N
, Make_Code_Statement
(Loc
, Expression
=> P
));
1791 -- Anything else is an error
1794 Error_Msg_N
("invalid procedure or entry call", N
);
1798 Restore_Ghost_Mode
(Mode
);
1799 end Analyze_Procedure_Call
;
1801 ------------------------------
1802 -- Analyze_Return_Statement --
1803 ------------------------------
1805 procedure Analyze_Return_Statement
(N
: Node_Id
) is
1806 pragma Assert
(Nkind_In
(N
, N_Extended_Return_Statement
,
1807 N_Simple_Return_Statement
));
1809 Returns_Object
: constant Boolean :=
1810 Nkind
(N
) = N_Extended_Return_Statement
1812 (Nkind
(N
) = N_Simple_Return_Statement
1813 and then Present
(Expression
(N
)));
1814 -- True if we're returning something; that is, "return <expression>;"
1815 -- or "return Result : T [:= ...]". False for "return;". Used for error
1816 -- checking: If Returns_Object is True, N should apply to a function
1817 -- body; otherwise N should apply to a procedure body, entry body,
1818 -- accept statement, or extended return statement.
1820 function Find_What_It_Applies_To
return Entity_Id
;
1821 -- Find the entity representing the innermost enclosing body, accept
1822 -- statement, or extended return statement. If the result is a callable
1823 -- construct or extended return statement, then this will be the value
1824 -- of the Return_Applies_To attribute. Otherwise, the program is
1825 -- illegal. See RM-6.5(4/2).
1827 -----------------------------
1828 -- Find_What_It_Applies_To --
1829 -----------------------------
1831 function Find_What_It_Applies_To
return Entity_Id
is
1832 Result
: Entity_Id
:= Empty
;
1835 -- Loop outward through the Scope_Stack, skipping blocks, loops,
1836 -- and postconditions.
1838 for J
in reverse 0 .. Scope_Stack
.Last
loop
1839 Result
:= Scope_Stack
.Table
(J
).Entity
;
1840 exit when not Ekind_In
(Result
, E_Block
, E_Loop
)
1841 and then Chars
(Result
) /= Name_uPostconditions
;
1844 pragma Assert
(Present
(Result
));
1846 end Find_What_It_Applies_To
;
1848 -- Local declarations
1850 Scope_Id
: constant Entity_Id
:= Find_What_It_Applies_To
;
1851 Kind
: constant Entity_Kind
:= Ekind
(Scope_Id
);
1852 Loc
: constant Source_Ptr
:= Sloc
(N
);
1853 Stm_Entity
: constant Entity_Id
:=
1855 (E_Return_Statement
, Current_Scope
, Loc
, 'R');
1857 -- Start of processing for Analyze_Return_Statement
1860 Set_Return_Statement_Entity
(N
, Stm_Entity
);
1862 Set_Etype
(Stm_Entity
, Standard_Void_Type
);
1863 Set_Return_Applies_To
(Stm_Entity
, Scope_Id
);
1865 -- Place Return entity on scope stack, to simplify enforcement of 6.5
1866 -- (4/2): an inner return statement will apply to this extended return.
1868 if Nkind
(N
) = N_Extended_Return_Statement
then
1869 Push_Scope
(Stm_Entity
);
1872 -- Check that pragma No_Return is obeyed. Don't complain about the
1873 -- implicitly-generated return that is placed at the end.
1875 if No_Return
(Scope_Id
) and then Comes_From_Source
(N
) then
1876 Error_Msg_N
("RETURN statement not allowed (No_Return)", N
);
1879 -- Warn on any unassigned OUT parameters if in procedure
1881 if Ekind
(Scope_Id
) = E_Procedure
then
1882 Warn_On_Unassigned_Out_Parameter
(N
, Scope_Id
);
1885 -- Check that functions return objects, and other things do not
1887 if Kind
= E_Function
or else Kind
= E_Generic_Function
then
1888 if not Returns_Object
then
1889 Error_Msg_N
("missing expression in return from function", N
);
1892 elsif Kind
= E_Procedure
or else Kind
= E_Generic_Procedure
then
1893 if Returns_Object
then
1894 Error_Msg_N
("procedure cannot return value (use function)", N
);
1897 elsif Kind
= E_Entry
or else Kind
= E_Entry_Family
then
1898 if Returns_Object
then
1899 if Is_Protected_Type
(Scope
(Scope_Id
)) then
1900 Error_Msg_N
("entry body cannot return value", N
);
1902 Error_Msg_N
("accept statement cannot return value", N
);
1906 elsif Kind
= E_Return_Statement
then
1908 -- We are nested within another return statement, which must be an
1909 -- extended_return_statement.
1911 if Returns_Object
then
1912 if Nkind
(N
) = N_Extended_Return_Statement
then
1914 ("extended return statement cannot be nested (use `RETURN;`)",
1917 -- Case of a simple return statement with a value inside extended
1918 -- return statement.
1922 ("return nested in extended return statement cannot return "
1923 & "value (use `RETURN;`)", N
);
1928 Error_Msg_N
("illegal context for return statement", N
);
1931 if Ekind_In
(Kind
, E_Function
, E_Generic_Function
) then
1932 Analyze_Function_Return
(N
);
1934 elsif Ekind_In
(Kind
, E_Procedure
, E_Generic_Procedure
) then
1935 Set_Return_Present
(Scope_Id
);
1938 if Nkind
(N
) = N_Extended_Return_Statement
then
1942 Kill_Current_Values
(Last_Assignment_Only
=> True);
1943 Check_Unreachable_Code
(N
);
1945 Analyze_Dimension
(N
);
1946 end Analyze_Return_Statement
;
1948 -------------------------------------
1949 -- Analyze_Simple_Return_Statement --
1950 -------------------------------------
1952 procedure Analyze_Simple_Return_Statement
(N
: Node_Id
) is
1954 if Present
(Expression
(N
)) then
1955 Mark_Coextensions
(N
, Expression
(N
));
1958 Analyze_Return_Statement
(N
);
1959 end Analyze_Simple_Return_Statement
;
1961 -------------------------
1962 -- Analyze_Return_Type --
1963 -------------------------
1965 procedure Analyze_Return_Type
(N
: Node_Id
) is
1966 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
1967 Typ
: Entity_Id
:= Empty
;
1970 -- Normal case where result definition does not indicate an error
1972 if Result_Definition
(N
) /= Error
then
1973 if Nkind
(Result_Definition
(N
)) = N_Access_Definition
then
1974 Check_SPARK_05_Restriction
1975 ("access result is not allowed", Result_Definition
(N
));
1977 -- Ada 2005 (AI-254): Handle anonymous access to subprograms
1980 AD
: constant Node_Id
:=
1981 Access_To_Subprogram_Definition
(Result_Definition
(N
));
1983 if Present
(AD
) and then Protected_Present
(AD
) then
1984 Typ
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
1986 Typ
:= Access_Definition
(N
, Result_Definition
(N
));
1990 Set_Parent
(Typ
, Result_Definition
(N
));
1991 Set_Is_Local_Anonymous_Access
(Typ
);
1992 Set_Etype
(Designator
, Typ
);
1994 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1996 Null_Exclusion_Static_Checks
(N
);
1998 -- Subtype_Mark case
2001 Find_Type
(Result_Definition
(N
));
2002 Typ
:= Entity
(Result_Definition
(N
));
2003 Set_Etype
(Designator
, Typ
);
2005 -- Unconstrained array as result is not allowed in SPARK
2007 if Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
2008 Check_SPARK_05_Restriction
2009 ("returning an unconstrained array is not allowed",
2010 Result_Definition
(N
));
2013 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
2015 Null_Exclusion_Static_Checks
(N
);
2017 -- If a null exclusion is imposed on the result type, then create
2018 -- a null-excluding itype (an access subtype) and use it as the
2019 -- function's Etype. Note that the null exclusion checks are done
2020 -- right before this, because they don't get applied to types that
2021 -- do not come from source.
2023 if Is_Access_Type
(Typ
) and then Null_Exclusion_Present
(N
) then
2024 Set_Etype
(Designator
,
2025 Create_Null_Excluding_Itype
2028 Scope_Id
=> Scope
(Current_Scope
)));
2030 -- The new subtype must be elaborated before use because
2031 -- it is visible outside of the function. However its base
2032 -- type may not be frozen yet, so the reference that will
2033 -- force elaboration must be attached to the freezing of
2036 -- If the return specification appears on a proper body,
2037 -- the subtype will have been created already on the spec.
2039 if Is_Frozen
(Typ
) then
2040 if Nkind
(Parent
(N
)) = N_Subprogram_Body
2041 and then Nkind
(Parent
(Parent
(N
))) = N_Subunit
2045 Build_Itype_Reference
(Etype
(Designator
), Parent
(N
));
2049 Ensure_Freeze_Node
(Typ
);
2052 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(N
));
2054 Set_Itype
(IR
, Etype
(Designator
));
2055 Append_Freeze_Actions
(Typ
, New_List
(IR
));
2060 Set_Etype
(Designator
, Typ
);
2063 if Ekind
(Typ
) = E_Incomplete_Type
2064 or else (Is_Class_Wide_Type
(Typ
)
2065 and then Ekind
(Root_Type
(Typ
)) = E_Incomplete_Type
)
2067 -- AI05-0151: Tagged incomplete types are allowed in all formal
2068 -- parts. Untagged incomplete types are not allowed in bodies.
2069 -- As a consequence, limited views cannot appear in a basic
2070 -- declaration that is itself within a body, because there is
2071 -- no point at which the non-limited view will become visible.
2073 if Ada_Version
>= Ada_2012
then
2074 if From_Limited_With
(Typ
) and then In_Package_Body
then
2076 ("invalid use of incomplete type&",
2077 Result_Definition
(N
), Typ
);
2079 -- The return type of a subprogram body cannot be of a
2080 -- formal incomplete type.
2082 elsif Is_Generic_Type
(Typ
)
2083 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
2086 ("return type cannot be a formal incomplete type",
2087 Result_Definition
(N
));
2089 elsif Is_Class_Wide_Type
(Typ
)
2090 and then Is_Generic_Type
(Root_Type
(Typ
))
2091 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
2094 ("return type cannot be a formal incomplete type",
2095 Result_Definition
(N
));
2097 elsif Is_Tagged_Type
(Typ
) then
2100 -- Use is legal in a thunk generated for an operation
2101 -- inherited from a progenitor.
2103 elsif Is_Thunk
(Designator
)
2104 and then Present
(Non_Limited_View
(Typ
))
2108 elsif Nkind
(Parent
(N
)) = N_Subprogram_Body
2109 or else Nkind_In
(Parent
(Parent
(N
)), N_Accept_Statement
,
2113 ("invalid use of untagged incomplete type&",
2117 -- The type must be completed in the current package. This
2118 -- is checked at the end of the package declaration when
2119 -- Taft-amendment types are identified. If the return type
2120 -- is class-wide, there is no required check, the type can
2121 -- be a bona fide TAT.
2123 if Ekind
(Scope
(Current_Scope
)) = E_Package
2124 and then In_Private_Part
(Scope
(Current_Scope
))
2125 and then not Is_Class_Wide_Type
(Typ
)
2127 Append_Elmt
(Designator
, Private_Dependents
(Typ
));
2132 ("invalid use of incomplete type&", Designator
, Typ
);
2137 -- Case where result definition does indicate an error
2140 Set_Etype
(Designator
, Any_Type
);
2142 end Analyze_Return_Type
;
2144 -----------------------------
2145 -- Analyze_Subprogram_Body --
2146 -----------------------------
2148 procedure Analyze_Subprogram_Body
(N
: Node_Id
) is
2149 Loc
: constant Source_Ptr
:= Sloc
(N
);
2150 Body_Spec
: constant Node_Id
:= Specification
(N
);
2151 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Spec
);
2154 if Debug_Flag_C
then
2155 Write_Str
("==> subprogram body ");
2156 Write_Name
(Chars
(Body_Id
));
2157 Write_Str
(" from ");
2158 Write_Location
(Loc
);
2163 Trace_Scope
(N
, Body_Id
, " Analyze subprogram: ");
2165 -- The real work is split out into the helper, so it can do "return;"
2166 -- without skipping the debug output:
2168 Analyze_Subprogram_Body_Helper
(N
);
2170 if Debug_Flag_C
then
2172 Write_Str
("<== subprogram body ");
2173 Write_Name
(Chars
(Body_Id
));
2174 Write_Str
(" from ");
2175 Write_Location
(Loc
);
2178 end Analyze_Subprogram_Body
;
2180 ------------------------------------
2181 -- Analyze_Subprogram_Body_Helper --
2182 ------------------------------------
2184 -- This procedure is called for regular subprogram bodies, generic bodies,
2185 -- and for subprogram stubs of both kinds. In the case of stubs, only the
2186 -- specification matters, and is used to create a proper declaration for
2187 -- the subprogram, or to perform conformance checks.
2189 -- WARNING: This routine manages Ghost regions. Return statements must be
2190 -- replaced by gotos which jump to the end of the routine and restore the
2193 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
) is
2194 Body_Spec
: Node_Id
:= Specification
(N
);
2195 Body_Id
: Entity_Id
:= Defining_Entity
(Body_Spec
);
2196 Loc
: constant Source_Ptr
:= Sloc
(N
);
2197 Prev_Id
: constant Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
2199 Conformant
: Boolean;
2200 Desig_View
: Entity_Id
:= Empty
;
2201 Exch_Views
: Elist_Id
:= No_Elist
;
2203 Prot_Typ
: Entity_Id
:= Empty
;
2204 Spec_Decl
: Node_Id
:= Empty
;
2205 Spec_Id
: Entity_Id
;
2207 Last_Real_Spec_Entity
: Entity_Id
:= Empty
;
2208 -- When we analyze a separate spec, the entity chain ends up containing
2209 -- the formals, as well as any itypes generated during analysis of the
2210 -- default expressions for parameters, or the arguments of associated
2211 -- precondition/postcondition pragmas (which are analyzed in the context
2212 -- of the spec since they have visibility on formals).
2214 -- These entities belong with the spec and not the body. However we do
2215 -- the analysis of the body in the context of the spec (again to obtain
2216 -- visibility to the formals), and all the entities generated during
2217 -- this analysis end up also chained to the entity chain of the spec.
2218 -- But they really belong to the body, and there is circuitry to move
2219 -- them from the spec to the body.
2221 -- However, when we do this move, we don't want to move the real spec
2222 -- entities (first para above) to the body. The Last_Real_Spec_Entity
2223 -- variable points to the last real spec entity, so we only move those
2224 -- chained beyond that point. It is initialized to Empty to deal with
2225 -- the case where there is no separate spec.
2227 function Body_Has_Contract
return Boolean;
2228 -- Check whether unanalyzed body has an aspect or pragma that may
2229 -- generate a SPARK contract.
2231 function Body_Has_SPARK_Mode_On
return Boolean;
2232 -- Check whether SPARK_Mode On applies to the subprogram body, either
2233 -- because it is specified directly on the body, or because it is
2234 -- inherited from the enclosing subprogram or package.
2236 procedure Build_Subprogram_Declaration
;
2237 -- Create a matching subprogram declaration for subprogram body N
2239 procedure Check_Anonymous_Return
;
2240 -- Ada 2005: if a function returns an access type that denotes a task,
2241 -- or a type that contains tasks, we must create a master entity for
2242 -- the anonymous type, which typically will be used in an allocator
2243 -- in the body of the function.
2245 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
);
2246 -- Look ahead to recognize a pragma that may appear after the body.
2247 -- If there is a previous spec, check that it appears in the same
2248 -- declarative part. If the pragma is Inline_Always, perform inlining
2249 -- unconditionally, otherwise only if Front_End_Inlining is requested.
2250 -- If the body acts as a spec, and inlining is required, we create a
2251 -- subprogram declaration for it, in order to attach the body to inline.
2252 -- If pragma does not appear after the body, check whether there is
2253 -- an inline pragma before any local declarations.
2255 procedure Check_Missing_Return
;
2256 -- Checks for a function with a no return statements, and also performs
2257 -- the warning checks implemented by Check_Returns. In formal mode, also
2258 -- verify that a function ends with a RETURN and that a procedure does
2259 -- not contain any RETURN.
2261 function Disambiguate_Spec
return Entity_Id
;
2262 -- When a primitive is declared between the private view and the full
2263 -- view of a concurrent type which implements an interface, a special
2264 -- mechanism is used to find the corresponding spec of the primitive
2267 function Exchange_Limited_Views
(Subp_Id
: Entity_Id
) return Elist_Id
;
2268 -- Ada 2012 (AI05-0151): Detect whether the profile of Subp_Id contains
2269 -- incomplete types coming from a limited context and replace their
2270 -- limited views with the non-limited ones. Return the list of changes
2271 -- to be used to undo the transformation.
2273 procedure Freeze_Expr_Types
(Spec_Id
: Entity_Id
);
2274 -- AI12-0103: N is the body associated with an expression function that
2275 -- is a completion, and Spec_Id is its defining entity. Freeze before N
2276 -- all the types referenced by the expression of the function.
2278 function Is_Private_Concurrent_Primitive
2279 (Subp_Id
: Entity_Id
) return Boolean;
2280 -- Determine whether subprogram Subp_Id is a primitive of a concurrent
2281 -- type that implements an interface and has a private view.
2283 procedure Restore_Limited_Views
(Restore_List
: Elist_Id
);
2284 -- Undo the transformation done by Exchange_Limited_Views.
2286 procedure Set_Trivial_Subprogram
(N
: Node_Id
);
2287 -- Sets the Is_Trivial_Subprogram flag in both spec and body of the
2288 -- subprogram whose body is being analyzed. N is the statement node
2289 -- causing the flag to be set, if the following statement is a return
2290 -- of an entity, we mark the entity as set in source to suppress any
2291 -- warning on the stylized use of function stubs with a dummy return.
2293 procedure Verify_Overriding_Indicator
;
2294 -- If there was a previous spec, the entity has been entered in the
2295 -- current scope previously. If the body itself carries an overriding
2296 -- indicator, check that it is consistent with the known status of the
2299 -----------------------
2300 -- Body_Has_Contract --
2301 -----------------------
2303 function Body_Has_Contract
return Boolean is
2304 Decls
: constant List_Id
:= Declarations
(N
);
2308 -- Check for aspects that may generate a contract
2310 if Present
(Aspect_Specifications
(N
)) then
2311 Item
:= First
(Aspect_Specifications
(N
));
2312 while Present
(Item
) loop
2313 if Is_Subprogram_Contract_Annotation
(Item
) then
2321 -- Check for pragmas that may generate a contract
2323 if Present
(Decls
) then
2324 Item
:= First
(Decls
);
2325 while Present
(Item
) loop
2326 if Nkind
(Item
) = N_Pragma
2327 and then Is_Subprogram_Contract_Annotation
(Item
)
2337 end Body_Has_Contract
;
2339 ----------------------------
2340 -- Body_Has_SPARK_Mode_On --
2341 ----------------------------
2343 function Body_Has_SPARK_Mode_On
return Boolean is
2344 Decls
: constant List_Id
:= Declarations
(N
);
2348 -- Check for SPARK_Mode aspect
2350 if Present
(Aspect_Specifications
(N
)) then
2351 Item
:= First
(Aspect_Specifications
(N
));
2352 while Present
(Item
) loop
2353 if Get_Aspect_Id
(Item
) = Aspect_SPARK_Mode
then
2354 return Get_SPARK_Mode_From_Annotation
(Item
) = On
;
2361 -- Check for SPARK_Mode pragma
2363 if Present
(Decls
) then
2364 Item
:= First
(Decls
);
2365 while Present
(Item
) loop
2367 -- Pragmas that apply to a subprogram body are usually grouped
2368 -- together. Look for a potential pragma SPARK_Mode among them.
2370 if Nkind
(Item
) = N_Pragma
then
2371 if Get_Pragma_Id
(Item
) = Pragma_SPARK_Mode
then
2372 return Get_SPARK_Mode_From_Annotation
(Item
) = On
;
2375 -- Otherwise the first non-pragma declarative item terminates
2376 -- the region where pragma SPARK_Mode may appear.
2386 -- Otherwise, the applicable SPARK_Mode is inherited from the
2387 -- enclosing subprogram or package.
2389 return SPARK_Mode
= On
;
2390 end Body_Has_SPARK_Mode_On
;
2392 ----------------------------------
2393 -- Build_Subprogram_Declaration --
2394 ----------------------------------
2396 procedure Build_Subprogram_Declaration
is
2397 procedure Move_Pragmas
(From
: Node_Id
; To
: Node_Id
);
2398 -- Relocate certain categorization pragmas from the declarative list
2399 -- of subprogram body From and insert them after node To. The pragmas
2402 -- Volatile_Function
2403 -- Also copy pragma SPARK_Mode if present in the declarative list
2404 -- of subprogram body From and insert it after node To. This pragma
2405 -- should not be moved, as it applies to the body too.
2411 procedure Move_Pragmas
(From
: Node_Id
; To
: Node_Id
) is
2413 Next_Decl
: Node_Id
;
2416 pragma Assert
(Nkind
(From
) = N_Subprogram_Body
);
2418 -- The destination node must be part of a list, as the pragmas are
2419 -- inserted after it.
2421 pragma Assert
(Is_List_Member
(To
));
2423 -- Inspect the declarations of the subprogram body looking for
2424 -- specific pragmas.
2426 Decl
:= First
(Declarations
(N
));
2427 while Present
(Decl
) loop
2428 Next_Decl
:= Next
(Decl
);
2430 if Nkind
(Decl
) = N_Pragma
then
2431 if Pragma_Name_Unmapped
(Decl
) = Name_SPARK_Mode
then
2432 Insert_After
(To
, New_Copy_Tree
(Decl
));
2434 elsif Nam_In
(Pragma_Name_Unmapped
(Decl
),
2436 Name_Volatile_Function
)
2439 Insert_After
(To
, Decl
);
2450 Subp_Decl
: Node_Id
;
2452 -- Start of processing for Build_Subprogram_Declaration
2455 -- Create a matching subprogram spec using the profile of the body.
2456 -- The structure of the tree is identical, but has new entities for
2457 -- the defining unit name and formal parameters.
2460 Make_Subprogram_Declaration
(Loc
,
2461 Specification
=> Copy_Subprogram_Spec
(Body_Spec
));
2462 Set_Comes_From_Source
(Subp_Decl
, True);
2464 -- Relocate the aspects and relevant pragmas from the subprogram body
2465 -- to the generated spec because it acts as the initial declaration.
2467 Insert_Before
(N
, Subp_Decl
);
2468 Move_Aspects
(N
, To
=> Subp_Decl
);
2469 Move_Pragmas
(N
, To
=> Subp_Decl
);
2471 -- Ensure that the generated corresponding spec and original body
2472 -- share the same SPARK_Mode pragma or aspect. As a result, both have
2473 -- the same SPARK_Mode attributes, and the global SPARK_Mode value is
2474 -- correctly set for local subprograms.
2476 Copy_SPARK_Mode_Aspect
(Subp_Decl
, To
=> N
);
2478 Analyze
(Subp_Decl
);
2480 -- Propagate the attributes Rewritten_For_C and Corresponding_Proc to
2481 -- the body since the expander may generate calls using that entity.
2482 -- Required to ensure that Expand_Call rewrites calls to this
2483 -- function by calls to the built procedure.
2485 if Modify_Tree_For_C
2486 and then Nkind
(Body_Spec
) = N_Function_Specification
2488 Rewritten_For_C
(Defining_Entity
(Specification
(Subp_Decl
)))
2490 Set_Rewritten_For_C
(Defining_Entity
(Body_Spec
));
2491 Set_Corresponding_Procedure
(Defining_Entity
(Body_Spec
),
2492 Corresponding_Procedure
2493 (Defining_Entity
(Specification
(Subp_Decl
))));
2496 -- Analyze any relocated source pragmas or pragmas created for aspect
2499 Decl
:= Next
(Subp_Decl
);
2500 while Present
(Decl
) loop
2502 -- Stop the search for pragmas once the body has been reached as
2503 -- this terminates the region where pragmas may appear.
2508 elsif Nkind
(Decl
) = N_Pragma
then
2515 Spec_Id
:= Defining_Entity
(Subp_Decl
);
2516 Set_Corresponding_Spec
(N
, Spec_Id
);
2518 -- Mark the generated spec as a source construct to ensure that all
2519 -- calls to it are properly registered in ALI files for GNATprove.
2521 Set_Comes_From_Source
(Spec_Id
, True);
2523 -- Ensure that the specs of the subprogram declaration and its body
2524 -- are identical, otherwise they will appear non-conformant due to
2525 -- rewritings in the default values of formal parameters.
2527 Body_Spec
:= Copy_Subprogram_Spec
(Body_Spec
);
2528 Set_Specification
(N
, Body_Spec
);
2529 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
2530 end Build_Subprogram_Declaration
;
2532 ----------------------------
2533 -- Check_Anonymous_Return --
2534 ----------------------------
2536 procedure Check_Anonymous_Return
is
2542 if Present
(Spec_Id
) then
2548 if Ekind
(Scop
) = E_Function
2549 and then Ekind
(Etype
(Scop
)) = E_Anonymous_Access_Type
2550 and then not Is_Thunk
(Scop
)
2552 -- Skip internally built functions which handle the case of
2553 -- a null access (see Expand_Interface_Conversion)
2555 and then not (Is_Interface
(Designated_Type
(Etype
(Scop
)))
2556 and then not Comes_From_Source
(Parent
(Scop
)))
2558 and then (Has_Task
(Designated_Type
(Etype
(Scop
)))
2560 (Is_Class_Wide_Type
(Designated_Type
(Etype
(Scop
)))
2562 Is_Limited_Record
(Designated_Type
(Etype
(Scop
)))))
2563 and then Expander_Active
2565 -- Avoid cases with no tasking support
2567 and then RTE_Available
(RE_Current_Master
)
2568 and then not Restriction_Active
(No_Task_Hierarchy
)
2571 Make_Object_Declaration
(Loc
,
2572 Defining_Identifier
=>
2573 Make_Defining_Identifier
(Loc
, Name_uMaster
),
2574 Constant_Present
=> True,
2575 Object_Definition
=>
2576 New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
2578 Make_Explicit_Dereference
(Loc
,
2579 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
2581 if Present
(Declarations
(N
)) then
2582 Prepend
(Decl
, Declarations
(N
));
2584 Set_Declarations
(N
, New_List
(Decl
));
2587 Set_Master_Id
(Etype
(Scop
), Defining_Identifier
(Decl
));
2588 Set_Has_Master_Entity
(Scop
);
2590 -- Now mark the containing scope as a task master
2593 while Nkind
(Par
) /= N_Compilation_Unit
loop
2594 Par
:= Parent
(Par
);
2595 pragma Assert
(Present
(Par
));
2597 -- If we fall off the top, we are at the outer level, and
2598 -- the environment task is our effective master, so nothing
2602 (Par
, N_Task_Body
, N_Block_Statement
, N_Subprogram_Body
)
2604 Set_Is_Task_Master
(Par
, True);
2609 end Check_Anonymous_Return
;
2611 -------------------------
2612 -- Check_Inline_Pragma --
2613 -------------------------
2615 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
) is
2619 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean;
2620 -- True when N is a pragma Inline or Inline_Always that applies
2621 -- to this subprogram.
2623 -----------------------
2624 -- Is_Inline_Pragma --
2625 -----------------------
2627 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean is
2629 if Nkind
(N
) = N_Pragma
2631 (Pragma_Name_Unmapped
(N
) = Name_Inline_Always
2632 or else (Pragma_Name_Unmapped
(N
) = Name_Inline
2634 (Front_End_Inlining
or else Optimization_Level
> 0)))
2635 and then Present
(Pragma_Argument_Associations
(N
))
2638 Pragma_Arg
: Node_Id
:=
2639 Expression
(First
(Pragma_Argument_Associations
(N
)));
2641 if Nkind
(Pragma_Arg
) = N_Selected_Component
then
2642 Pragma_Arg
:= Selector_Name
(Pragma_Arg
);
2645 return Chars
(Pragma_Arg
) = Chars
(Body_Id
);
2651 end Is_Inline_Pragma
;
2653 -- Start of processing for Check_Inline_Pragma
2656 if not Expander_Active
then
2660 if Is_List_Member
(N
)
2661 and then Present
(Next
(N
))
2662 and then Is_Inline_Pragma
(Next
(N
))
2666 elsif Nkind
(N
) /= N_Subprogram_Body_Stub
2667 and then Present
(Declarations
(N
))
2668 and then Is_Inline_Pragma
(First
(Declarations
(N
)))
2670 Prag
:= First
(Declarations
(N
));
2676 if Present
(Prag
) then
2677 if Present
(Spec_Id
) then
2678 if Is_List_Member
(N
)
2679 and then Is_List_Member
(Unit_Declaration_Node
(Spec_Id
))
2680 and then In_Same_List
(N
, Unit_Declaration_Node
(Spec_Id
))
2686 -- Create a subprogram declaration, to make treatment uniform.
2687 -- Make the sloc of the subprogram name that of the entity in
2688 -- the body, so that style checks find identical strings.
2691 Subp
: constant Entity_Id
:=
2692 Make_Defining_Identifier
2693 (Sloc
(Body_Id
), Chars
(Body_Id
));
2694 Decl
: constant Node_Id
:=
2695 Make_Subprogram_Declaration
(Loc
,
2697 New_Copy_Tree
(Specification
(N
)));
2700 Set_Defining_Unit_Name
(Specification
(Decl
), Subp
);
2702 -- To ensure proper coverage when body is inlined, indicate
2703 -- whether the subprogram comes from source.
2705 Set_Comes_From_Source
(Subp
, Comes_From_Source
(N
));
2707 if Present
(First_Formal
(Body_Id
)) then
2708 Plist
:= Copy_Parameter_List
(Body_Id
);
2709 Set_Parameter_Specifications
2710 (Specification
(Decl
), Plist
);
2713 -- Move aspects to the new spec
2715 if Has_Aspects
(N
) then
2716 Move_Aspects
(N
, To
=> Decl
);
2719 Insert_Before
(N
, Decl
);
2722 Set_Has_Pragma_Inline
(Subp
);
2724 if Pragma_Name
(Prag
) = Name_Inline_Always
then
2725 Set_Is_Inlined
(Subp
);
2726 Set_Has_Pragma_Inline_Always
(Subp
);
2729 -- Prior to copying the subprogram body to create a template
2730 -- for it for subsequent inlining, remove the pragma from
2731 -- the current body so that the copy that will produce the
2732 -- new body will start from a completely unanalyzed tree.
2734 if Nkind
(Parent
(Prag
)) = N_Subprogram_Body
then
2735 Rewrite
(Prag
, Make_Null_Statement
(Sloc
(Prag
)));
2742 end Check_Inline_Pragma
;
2744 --------------------------
2745 -- Check_Missing_Return --
2746 --------------------------
2748 procedure Check_Missing_Return
is
2750 Missing_Ret
: Boolean;
2753 if Nkind
(Body_Spec
) = N_Function_Specification
then
2754 if Present
(Spec_Id
) then
2760 if Return_Present
(Id
) then
2761 Check_Returns
(HSS
, 'F', Missing_Ret
);
2764 Set_Has_Missing_Return
(Id
);
2767 -- Within a premature instantiation of a package with no body, we
2768 -- build completions of the functions therein, with a Raise
2769 -- statement. No point in complaining about a missing return in
2772 elsif Ekind
(Id
) = E_Function
2773 and then In_Instance
2774 and then Present
(Statements
(HSS
))
2775 and then Nkind
(First
(Statements
(HSS
))) = N_Raise_Program_Error
2779 elsif Is_Generic_Subprogram
(Id
)
2780 or else not Is_Machine_Code_Subprogram
(Id
)
2782 Error_Msg_N
("missing RETURN statement in function body", N
);
2785 -- If procedure with No_Return, check returns
2787 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
2788 and then Present
(Spec_Id
)
2789 and then No_Return
(Spec_Id
)
2791 Check_Returns
(HSS
, 'P', Missing_Ret
, Spec_Id
);
2794 -- Special checks in SPARK mode
2796 if Nkind
(Body_Spec
) = N_Function_Specification
then
2798 -- In SPARK mode, last statement of a function should be a return
2801 Stat
: constant Node_Id
:= Last_Source_Statement
(HSS
);
2804 and then not Nkind_In
(Stat
, N_Simple_Return_Statement
,
2805 N_Extended_Return_Statement
)
2807 Check_SPARK_05_Restriction
2808 ("last statement in function should be RETURN", Stat
);
2812 -- In SPARK mode, verify that a procedure has no return
2814 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
then
2815 if Present
(Spec_Id
) then
2821 -- Would be nice to point to return statement here, can we
2822 -- borrow the Check_Returns procedure here ???
2824 if Return_Present
(Id
) then
2825 Check_SPARK_05_Restriction
2826 ("procedure should not have RETURN", N
);
2829 end Check_Missing_Return
;
2831 -----------------------
2832 -- Disambiguate_Spec --
2833 -----------------------
2835 function Disambiguate_Spec
return Entity_Id
is
2836 Priv_Spec
: Entity_Id
;
2839 procedure Replace_Types
(To_Corresponding
: Boolean);
2840 -- Depending on the flag, replace the type of formal parameters of
2841 -- Body_Id if it is a concurrent type implementing interfaces with
2842 -- the corresponding record type or the other way around.
2844 procedure Replace_Types
(To_Corresponding
: Boolean) is
2846 Formal_Typ
: Entity_Id
;
2849 Formal
:= First_Formal
(Body_Id
);
2850 while Present
(Formal
) loop
2851 Formal_Typ
:= Etype
(Formal
);
2853 if Is_Class_Wide_Type
(Formal_Typ
) then
2854 Formal_Typ
:= Root_Type
(Formal_Typ
);
2857 -- From concurrent type to corresponding record
2859 if To_Corresponding
then
2860 if Is_Concurrent_Type
(Formal_Typ
)
2861 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
2864 (Corresponding_Record_Type
(Formal_Typ
)))
2867 Corresponding_Record_Type
(Formal_Typ
));
2870 -- From corresponding record to concurrent type
2873 if Is_Concurrent_Record_Type
(Formal_Typ
)
2874 and then Present
(Interfaces
(Formal_Typ
))
2877 Corresponding_Concurrent_Type
(Formal_Typ
));
2881 Next_Formal
(Formal
);
2885 -- Start of processing for Disambiguate_Spec
2888 -- Try to retrieve the specification of the body as is. All error
2889 -- messages are suppressed because the body may not have a spec in
2890 -- its current state.
2892 Spec_N
:= Find_Corresponding_Spec
(N
, False);
2894 -- It is possible that this is the body of a primitive declared
2895 -- between a private and a full view of a concurrent type. The
2896 -- controlling parameter of the spec carries the concurrent type,
2897 -- not the corresponding record type as transformed by Analyze_
2898 -- Subprogram_Specification. In such cases, we undo the change
2899 -- made by the analysis of the specification and try to find the
2902 -- Note that wrappers already have their corresponding specs and
2903 -- bodies set during their creation, so if the candidate spec is
2904 -- a wrapper, then we definitely need to swap all types to their
2905 -- original concurrent status.
2908 or else Is_Primitive_Wrapper
(Spec_N
)
2910 -- Restore all references of corresponding record types to the
2911 -- original concurrent types.
2913 Replace_Types
(To_Corresponding
=> False);
2914 Priv_Spec
:= Find_Corresponding_Spec
(N
, False);
2916 -- The current body truly belongs to a primitive declared between
2917 -- a private and a full view. We leave the modified body as is,
2918 -- and return the true spec.
2920 if Present
(Priv_Spec
)
2921 and then Is_Private_Primitive
(Priv_Spec
)
2926 -- In case that this is some sort of error, restore the original
2927 -- state of the body.
2929 Replace_Types
(To_Corresponding
=> True);
2933 end Disambiguate_Spec
;
2935 ----------------------------
2936 -- Exchange_Limited_Views --
2937 ----------------------------
2939 function Exchange_Limited_Views
(Subp_Id
: Entity_Id
) return Elist_Id
is
2940 Result
: Elist_Id
:= No_Elist
;
2942 procedure Detect_And_Exchange
(Id
: Entity_Id
);
2943 -- Determine whether Id's type denotes an incomplete type associated
2944 -- with a limited with clause and exchange the limited view with the
2945 -- non-limited one when available. Note that the non-limited view
2946 -- may exist because of a with_clause in another unit in the context,
2947 -- but cannot be used because the current view of the enclosing unit
2948 -- is still a limited view.
2950 -------------------------
2951 -- Detect_And_Exchange --
2952 -------------------------
2954 procedure Detect_And_Exchange
(Id
: Entity_Id
) is
2955 Typ
: constant Entity_Id
:= Etype
(Id
);
2957 if From_Limited_With
(Typ
)
2958 and then Has_Non_Limited_View
(Typ
)
2959 and then not From_Limited_With
(Scope
(Typ
))
2962 Result
:= New_Elmt_List
;
2965 Prepend_Elmt
(Typ
, Result
);
2966 Prepend_Elmt
(Id
, Result
);
2967 Set_Etype
(Id
, Non_Limited_View
(Typ
));
2969 end Detect_And_Exchange
;
2975 -- Start of processing for Exchange_Limited_Views
2978 -- Do not process subprogram bodies as they already use the non-
2979 -- limited view of types.
2981 if not Ekind_In
(Subp_Id
, E_Function
, E_Procedure
) then
2985 -- Examine all formals and swap views when applicable
2987 Formal
:= First_Formal
(Subp_Id
);
2988 while Present
(Formal
) loop
2989 Detect_And_Exchange
(Formal
);
2991 Next_Formal
(Formal
);
2994 -- Process the return type of a function
2996 if Ekind
(Subp_Id
) = E_Function
then
2997 Detect_And_Exchange
(Subp_Id
);
3001 end Exchange_Limited_Views
;
3003 -----------------------
3004 -- Freeze_Expr_Types --
3005 -----------------------
3007 procedure Freeze_Expr_Types
(Spec_Id
: Entity_Id
) is
3008 function Cloned_Expression
return Node_Id
;
3009 -- Build a duplicate of the expression of the return statement that
3010 -- has no defining entities shared with the original expression.
3012 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
;
3013 -- Freeze all types referenced in the subtree rooted at Node
3015 -----------------------
3016 -- Cloned_Expression --
3017 -----------------------
3019 function Cloned_Expression
return Node_Id
is
3020 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
;
3021 -- Tree traversal routine that clones the defining identifier of
3022 -- iterator and loop parameter specification nodes.
3028 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
is
3030 if Nkind_In
(Node
, N_Iterator_Specification
,
3031 N_Loop_Parameter_Specification
)
3033 Set_Defining_Identifier
(Node
,
3034 New_Copy
(Defining_Identifier
(Node
)));
3044 procedure Clone_Def_Ids
is new Traverse_Proc
(Clone_Id
);
3048 Return_Stmt
: constant Node_Id
:=
3050 (Statements
(Handled_Statement_Sequence
(N
)));
3053 -- Start of processing for Cloned_Expression
3056 pragma Assert
(Nkind
(Return_Stmt
) = N_Simple_Return_Statement
);
3058 -- We must duplicate the expression with semantic information to
3059 -- inherit the decoration of global entities in generic instances.
3061 Dup_Expr
:= New_Copy_Tree
(Expression
(Return_Stmt
));
3063 -- Replace the defining identifier of iterators and loop param
3064 -- specifications by a clone to ensure that the cloned expression
3065 -- and the original expression don't have shared identifiers;
3066 -- otherwise, as part of the preanalysis of the expression, these
3067 -- shared identifiers may be left decorated with itypes which
3068 -- will not be available in the tree passed to the backend.
3070 Clone_Def_Ids
(Dup_Expr
);
3073 end Cloned_Expression
;
3075 ----------------------
3076 -- Freeze_Type_Refs --
3077 ----------------------
3079 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
is
3081 if Nkind
(Node
) = N_Identifier
3082 and then Present
(Entity
(Node
))
3084 if Is_Type
(Entity
(Node
)) then
3085 Freeze_Before
(N
, Entity
(Node
));
3087 elsif Ekind_In
(Entity
(Node
), E_Component
,
3090 Freeze_Before
(N
, Scope
(Entity
(Node
)));
3095 end Freeze_Type_Refs
;
3097 procedure Freeze_References
is new Traverse_Proc
(Freeze_Type_Refs
);
3101 Saved_First_Entity
: constant Entity_Id
:= First_Entity
(Spec_Id
);
3102 Saved_Last_Entity
: constant Entity_Id
:= Last_Entity
(Spec_Id
);
3103 Dup_Expr
: constant Node_Id
:= Cloned_Expression
;
3105 -- Start of processing for Freeze_Expr_Types
3108 -- Preanalyze a duplicate of the expression to have available the
3109 -- minimum decoration needed to locate referenced unfrozen types
3110 -- without adding any decoration to the function expression. This
3111 -- preanalysis is performed with errors disabled to avoid reporting
3112 -- spurious errors on Ghost entities (since the expression is not
3115 Push_Scope
(Spec_Id
);
3116 Install_Formals
(Spec_Id
);
3117 Ignore_Errors_Enable
:= Ignore_Errors_Enable
+ 1;
3119 Preanalyze_Spec_Expression
(Dup_Expr
, Etype
(Spec_Id
));
3121 Ignore_Errors_Enable
:= Ignore_Errors_Enable
- 1;
3124 -- Restore certain attributes of Spec_Id since the preanalysis may
3125 -- have introduced itypes to this scope, thus modifying attributes
3126 -- First_Entity and Last_Entity.
3128 Set_First_Entity
(Spec_Id
, Saved_First_Entity
);
3129 Set_Last_Entity
(Spec_Id
, Saved_Last_Entity
);
3131 if Present
(Last_Entity
(Spec_Id
)) then
3132 Set_Next_Entity
(Last_Entity
(Spec_Id
), Empty
);
3135 -- Freeze all types referenced in the expression
3137 Freeze_References
(Dup_Expr
);
3138 end Freeze_Expr_Types
;
3140 -------------------------------------
3141 -- Is_Private_Concurrent_Primitive --
3142 -------------------------------------
3144 function Is_Private_Concurrent_Primitive
3145 (Subp_Id
: Entity_Id
) return Boolean
3147 Formal_Typ
: Entity_Id
;
3150 if Present
(First_Formal
(Subp_Id
)) then
3151 Formal_Typ
:= Etype
(First_Formal
(Subp_Id
));
3153 if Is_Concurrent_Record_Type
(Formal_Typ
) then
3154 if Is_Class_Wide_Type
(Formal_Typ
) then
3155 Formal_Typ
:= Root_Type
(Formal_Typ
);
3158 Formal_Typ
:= Corresponding_Concurrent_Type
(Formal_Typ
);
3161 -- The type of the first formal is a concurrent tagged type with
3165 Is_Concurrent_Type
(Formal_Typ
)
3166 and then Is_Tagged_Type
(Formal_Typ
)
3167 and then Has_Private_Declaration
(Formal_Typ
);
3171 end Is_Private_Concurrent_Primitive
;
3173 ---------------------------
3174 -- Restore_Limited_Views --
3175 ---------------------------
3177 procedure Restore_Limited_Views
(Restore_List
: Elist_Id
) is
3178 Elmt
: Elmt_Id
:= First_Elmt
(Restore_List
);
3182 while Present
(Elmt
) loop
3185 Set_Etype
(Id
, Node
(Elmt
));
3188 end Restore_Limited_Views
;
3190 ----------------------------
3191 -- Set_Trivial_Subprogram --
3192 ----------------------------
3194 procedure Set_Trivial_Subprogram
(N
: Node_Id
) is
3195 Nxt
: constant Node_Id
:= Next
(N
);
3198 Set_Is_Trivial_Subprogram
(Body_Id
);
3200 if Present
(Spec_Id
) then
3201 Set_Is_Trivial_Subprogram
(Spec_Id
);
3205 and then Nkind
(Nxt
) = N_Simple_Return_Statement
3206 and then No
(Next
(Nxt
))
3207 and then Present
(Expression
(Nxt
))
3208 and then Is_Entity_Name
(Expression
(Nxt
))
3210 Set_Never_Set_In_Source
(Entity
(Expression
(Nxt
)), False);
3212 end Set_Trivial_Subprogram
;
3214 ---------------------------------
3215 -- Verify_Overriding_Indicator --
3216 ---------------------------------
3218 procedure Verify_Overriding_Indicator
is
3220 if Must_Override
(Body_Spec
) then
3221 if Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
3222 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
3226 elsif not Present
(Overridden_Operation
(Spec_Id
)) then
3228 ("subprogram& is not overriding", Body_Spec
, Spec_Id
);
3230 -- Overriding indicators aren't allowed for protected subprogram
3231 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
3232 -- this to a warning if -gnatd.E is enabled.
3234 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
3235 Error_Msg_Warn
:= Error_To_Warning
;
3237 ("<<overriding indicator not allowed for protected "
3238 & "subprogram body", Body_Spec
);
3241 elsif Must_Not_Override
(Body_Spec
) then
3242 if Present
(Overridden_Operation
(Spec_Id
)) then
3244 ("subprogram& overrides inherited operation",
3245 Body_Spec
, Spec_Id
);
3247 elsif Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
3248 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
3251 ("subprogram& overrides predefined operator ",
3252 Body_Spec
, Spec_Id
);
3254 -- Overriding indicators aren't allowed for protected subprogram
3255 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
3256 -- this to a warning if -gnatd.E is enabled.
3258 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
3259 Error_Msg_Warn
:= Error_To_Warning
;
3262 ("<<overriding indicator not allowed "
3263 & "for protected subprogram body", Body_Spec
);
3265 -- If this is not a primitive operation, then the overriding
3266 -- indicator is altogether illegal.
3268 elsif not Is_Primitive
(Spec_Id
) then
3270 ("overriding indicator only allowed "
3271 & "if subprogram is primitive", Body_Spec
);
3274 -- If checking the style rule and the operation overrides, then
3275 -- issue a warning about a missing overriding_indicator. Protected
3276 -- subprogram bodies are excluded from this style checking, since
3277 -- they aren't primitives (even though their declarations can
3278 -- override) and aren't allowed to have an overriding_indicator.
3281 and then Present
(Overridden_Operation
(Spec_Id
))
3282 and then Ekind
(Scope
(Spec_Id
)) /= E_Protected_Type
3284 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
3285 Style
.Missing_Overriding
(N
, Body_Id
);
3288 and then Can_Override_Operator
(Spec_Id
)
3289 and then not Is_Predefined_File_Name
3290 (Unit_File_Name
(Get_Source_Unit
(Spec_Id
)))
3292 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
3293 Style
.Missing_Overriding
(N
, Body_Id
);
3295 end Verify_Overriding_Indicator
;
3299 Mode
: Ghost_Mode_Type
;
3300 Mode_Set
: Boolean := False;
3302 -- Start of processing for Analyze_Subprogram_Body_Helper
3305 -- A [generic] subprogram body "freezes" the contract of the nearest
3306 -- enclosing package body and all other contracts encountered in the
3307 -- same declarative part up to and excluding the subprogram body:
3309 -- package body Nearest_Enclosing_Package
3310 -- with Refined_State => (State => Constit)
3314 -- procedure Freezes_Enclosing_Package_Body
3315 -- with Refined_Depends => (Input => Constit) ...
3317 -- This ensures that any annotations referenced by the contract of the
3318 -- [generic] subprogram body are available. This form of "freezing" is
3319 -- decoupled from the usual Freeze_xxx mechanism because it must also
3320 -- work in the context of generics where normal freezing is disabled.
3322 -- Only bodies coming from source should cause this type of "freezing".
3323 -- Expression functions that act as bodies and complete an initial
3324 -- declaration must be included in this category, hence the use of
3327 if Comes_From_Source
(Original_Node
(N
)) then
3328 Analyze_Previous_Contracts
(N
);
3331 -- Generic subprograms are handled separately. They always have a
3332 -- generic specification. Determine whether current scope has a
3333 -- previous declaration.
3335 -- If the subprogram body is defined within an instance of the same
3336 -- name, the instance appears as a package renaming, and will be hidden
3337 -- within the subprogram.
3339 if Present
(Prev_Id
)
3340 and then not Is_Overloadable
(Prev_Id
)
3341 and then (Nkind
(Parent
(Prev_Id
)) /= N_Package_Renaming_Declaration
3342 or else Comes_From_Source
(Prev_Id
))
3344 if Is_Generic_Subprogram
(Prev_Id
) then
3347 -- A subprogram body is Ghost when it is stand alone and subject
3348 -- to pragma Ghost or when the corresponding spec is Ghost. Set
3349 -- the mode now to ensure that any nodes generated during analysis
3350 -- and expansion are properly marked as Ghost.
3352 Mark_And_Set_Ghost_Body
(N
, Spec_Id
, Mode
);
3355 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3356 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3358 Analyze_Generic_Subprogram_Body
(N
, Spec_Id
);
3360 if Nkind
(N
) = N_Subprogram_Body
then
3361 HSS
:= Handled_Statement_Sequence
(N
);
3362 Check_Missing_Return
;
3367 -- Otherwise a previous entity conflicts with the subprogram name.
3368 -- Attempting to enter name will post error.
3371 Enter_Name
(Body_Id
);
3375 -- Non-generic case, find the subprogram declaration, if one was seen,
3376 -- or enter new overloaded entity in the current scope. If the
3377 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
3378 -- part of the context of one of its subunits. No need to redo the
3381 elsif Prev_Id
= Body_Id
and then Has_Completion
(Body_Id
) then
3385 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
3387 if Nkind
(N
) = N_Subprogram_Body_Stub
3388 or else No
(Corresponding_Spec
(N
))
3390 if Is_Private_Concurrent_Primitive
(Body_Id
) then
3391 Spec_Id
:= Disambiguate_Spec
;
3393 -- A subprogram body is Ghost when it is stand alone and
3394 -- subject to pragma Ghost or when the corresponding spec is
3395 -- Ghost. Set the mode now to ensure that any nodes generated
3396 -- during analysis and expansion are properly marked as Ghost.
3398 Mark_And_Set_Ghost_Body
(N
, Spec_Id
, Mode
);
3402 Spec_Id
:= Find_Corresponding_Spec
(N
);
3404 -- A subprogram body is Ghost when it is stand alone and
3405 -- subject to pragma Ghost or when the corresponding spec is
3406 -- Ghost. Set the mode now to ensure that any nodes generated
3407 -- during analysis and expansion are properly marked as Ghost.
3409 Mark_And_Set_Ghost_Body
(N
, Spec_Id
, Mode
);
3412 -- In GNATprove mode, if the body has no previous spec, create
3413 -- one so that the inlining machinery can operate properly.
3414 -- Transfer aspects, if any, to the new spec, so that they
3415 -- are legal and can be processed ahead of the body.
3416 -- We make two copies of the given spec, one for the new
3417 -- declaration, and one for the body.
3419 if No
(Spec_Id
) and then GNATprove_Mode
3421 -- Inlining does not apply during pre-analysis of code
3423 and then Full_Analysis
3425 -- Inlining only applies to full bodies, not stubs
3427 and then Nkind
(N
) /= N_Subprogram_Body_Stub
3429 -- Inlining only applies to bodies in the source code, not to
3430 -- those generated by the compiler. In particular, expression
3431 -- functions, whose body is generated by the compiler, are
3432 -- treated specially by GNATprove.
3434 and then Comes_From_Source
(Body_Id
)
3436 -- This cannot be done for a compilation unit, which is not
3437 -- in a context where we can insert a new spec.
3439 and then Is_List_Member
(N
)
3441 -- Inlining only applies to subprograms without contracts,
3442 -- as a contract is a sign that GNATprove should perform a
3443 -- modular analysis of the subprogram instead of a contextual
3444 -- analysis at each call site. The same test is performed in
3445 -- Inline.Can_Be_Inlined_In_GNATprove_Mode. It is repeated
3446 -- here in another form (because the contract has not been
3447 -- attached to the body) to avoid front-end errors in case
3448 -- pragmas are used instead of aspects, because the
3449 -- corresponding pragmas in the body would not be transferred
3450 -- to the spec, leading to legality errors.
3452 and then not Body_Has_Contract
3453 and then not Inside_A_Generic
3455 Build_Subprogram_Declaration
;
3457 -- If this is a function that returns a constrained array, and
3458 -- we are generating SPARK_For_C, create subprogram declaration
3459 -- to simplify subsequent C generation.
3462 and then Modify_Tree_For_C
3463 and then Nkind
(Body_Spec
) = N_Function_Specification
3464 and then Is_Array_Type
(Etype
(Body_Id
))
3465 and then Is_Constrained
(Etype
(Body_Id
))
3467 Build_Subprogram_Declaration
;
3471 -- If this is a duplicate body, no point in analyzing it
3473 if Error_Posted
(N
) then
3477 -- A subprogram body should cause freezing of its own declaration,
3478 -- but if there was no previous explicit declaration, then the
3479 -- subprogram will get frozen too late (there may be code within
3480 -- the body that depends on the subprogram having been frozen,
3481 -- such as uses of extra formals), so we force it to be frozen
3482 -- here. Same holds if the body and spec are compilation units.
3483 -- Finally, if the return type is an anonymous access to protected
3484 -- subprogram, it must be frozen before the body because its
3485 -- expansion has generated an equivalent type that is used when
3486 -- elaborating the body.
3488 -- An exception in the case of Ada 2012, AI05-177: The bodies
3489 -- created for expression functions do not freeze.
3492 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3494 Freeze_Before
(N
, Body_Id
);
3496 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3497 Freeze_Before
(N
, Spec_Id
);
3499 elsif Is_Access_Subprogram_Type
(Etype
(Body_Id
)) then
3500 Freeze_Before
(N
, Etype
(Body_Id
));
3504 Spec_Id
:= Corresponding_Spec
(N
);
3506 -- A subprogram body is Ghost when it is stand alone and subject
3507 -- to pragma Ghost or when the corresponding spec is Ghost. Set
3508 -- the mode now to ensure that any nodes generated during analysis
3509 -- and expansion are properly marked as Ghost.
3511 Mark_And_Set_Ghost_Body
(N
, Spec_Id
, Mode
);
3516 -- Previously we scanned the body to look for nested subprograms, and
3517 -- rejected an inline directive if nested subprograms were present,
3518 -- because the back-end would generate conflicting symbols for the
3519 -- nested bodies. This is now unnecessary.
3521 -- Look ahead to recognize a pragma Inline that appears after the body
3523 Check_Inline_Pragma
(Spec_Id
);
3525 -- Deal with special case of a fully private operation in the body of
3526 -- the protected type. We must create a declaration for the subprogram,
3527 -- in order to attach the protected subprogram that will be used in
3528 -- internal calls. We exclude compiler generated bodies from the
3529 -- expander since the issue does not arise for those cases.
3532 and then Comes_From_Source
(N
)
3533 and then Is_Protected_Type
(Current_Scope
)
3535 Spec_Id
:= Build_Private_Protected_Declaration
(N
);
3538 -- If we are generating C and this is a function returning a constrained
3539 -- array type for which we must create a procedure with an extra out
3540 -- parameter, build and analyze the body now. The procedure declaration
3541 -- has already been created. We reuse the source body of the function,
3542 -- because in an instance it may contain global references that cannot
3543 -- be reanalyzed. The source function itself is not used any further,
3544 -- so we mark it as having a completion. If the subprogram is a stub the
3545 -- transformation is done later, when the proper body is analyzed.
3548 and then Modify_Tree_For_C
3549 and then Present
(Spec_Id
)
3550 and then Ekind
(Spec_Id
) = E_Function
3551 and then Nkind
(N
) /= N_Subprogram_Body_Stub
3552 and then Rewritten_For_C
(Spec_Id
)
3554 Set_Has_Completion
(Spec_Id
);
3556 Rewrite
(N
, Build_Procedure_Body_Form
(Spec_Id
, N
));
3559 -- The entity for the created procedure must remain invisible, so it
3560 -- does not participate in resolution of subsequent references to the
3563 Set_Is_Immediately_Visible
(Corresponding_Spec
(N
), False);
3567 -- If a separate spec is present, then deal with freezing issues
3569 if Present
(Spec_Id
) then
3570 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
3571 Verify_Overriding_Indicator
;
3573 -- In general, the spec will be frozen when we start analyzing the
3574 -- body. However, for internally generated operations, such as
3575 -- wrapper functions for inherited operations with controlling
3576 -- results, the spec may not have been frozen by the time we expand
3577 -- the freeze actions that include the bodies. In particular, extra
3578 -- formals for accessibility or for return-in-place may need to be
3579 -- generated. Freeze nodes, if any, are inserted before the current
3580 -- body. These freeze actions are also needed in ASIS mode and in
3581 -- Compile_Only mode to enable the proper back-end type annotations.
3582 -- They are necessary in any case to insure order of elaboration
3585 if not Is_Frozen
(Spec_Id
)
3586 and then (Expander_Active
3588 or else (Operating_Mode
= Check_Semantics
3589 and then Serious_Errors_Detected
= 0))
3591 Set_Has_Delayed_Freeze
(Spec_Id
);
3592 Freeze_Before
(N
, Spec_Id
);
3594 -- AI12-0103: At the occurrence of an expression function
3595 -- declaration that is a completion, its expression causes
3598 if Has_Completion
(Spec_Id
)
3599 and then Nkind
(N
) = N_Subprogram_Body
3600 and then Was_Expression_Function
(N
)
3602 Freeze_Expr_Types
(Spec_Id
);
3607 -- Place subprogram on scope stack, and make formals visible. If there
3608 -- is a spec, the visible entity remains that of the spec.
3610 if Present
(Spec_Id
) then
3611 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
3613 if Is_Child_Unit
(Spec_Id
) then
3614 Generate_Reference
(Spec_Id
, Scope
(Spec_Id
), 'k', False);
3618 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
3621 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3622 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3624 if Is_Abstract_Subprogram
(Spec_Id
) then
3625 Error_Msg_N
("an abstract subprogram cannot have a body", N
);
3629 Set_Convention
(Body_Id
, Convention
(Spec_Id
));
3630 Set_Has_Completion
(Spec_Id
);
3632 if Is_Protected_Type
(Scope
(Spec_Id
)) then
3633 Prot_Typ
:= Scope
(Spec_Id
);
3636 -- If this is a body generated for a renaming, do not check for
3637 -- full conformance. The check is redundant, because the spec of
3638 -- the body is a copy of the spec in the renaming declaration,
3639 -- and the test can lead to spurious errors on nested defaults.
3641 if Present
(Spec_Decl
)
3642 and then not Comes_From_Source
(N
)
3644 (Nkind
(Original_Node
(Spec_Decl
)) =
3645 N_Subprogram_Renaming_Declaration
3646 or else (Present
(Corresponding_Body
(Spec_Decl
))
3648 Nkind
(Unit_Declaration_Node
3649 (Corresponding_Body
(Spec_Decl
))) =
3650 N_Subprogram_Renaming_Declaration
))
3654 -- Conversely, the spec may have been generated for specless body
3655 -- with an inline pragma. The entity comes from source, which is
3656 -- both semantically correct and necessary for proper inlining.
3657 -- The subprogram declaration itself is not in the source.
3659 elsif Comes_From_Source
(N
)
3660 and then Present
(Spec_Decl
)
3661 and then not Comes_From_Source
(Spec_Decl
)
3662 and then Has_Pragma_Inline
(Spec_Id
)
3669 Fully_Conformant
, True, Conformant
, Body_Id
);
3672 -- If the body is not fully conformant, we have to decide if we
3673 -- should analyze it or not. If it has a really messed up profile
3674 -- then we probably should not analyze it, since we will get too
3675 -- many bogus messages.
3677 -- Our decision is to go ahead in the non-fully conformant case
3678 -- only if it is at least mode conformant with the spec. Note
3679 -- that the call to Check_Fully_Conformant has issued the proper
3680 -- error messages to complain about the lack of conformance.
3683 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
3689 if Spec_Id
/= Body_Id
then
3690 Reference_Body_Formals
(Spec_Id
, Body_Id
);
3693 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
3695 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3696 Set_Corresponding_Spec_Of_Stub
(N
, Spec_Id
);
3701 Set_Corresponding_Spec
(N
, Spec_Id
);
3703 -- Ada 2005 (AI-345): If the operation is a primitive operation
3704 -- of a concurrent type, the type of the first parameter has been
3705 -- replaced with the corresponding record, which is the proper
3706 -- run-time structure to use. However, within the body there may
3707 -- be uses of the formals that depend on primitive operations
3708 -- of the type (in particular calls in prefixed form) for which
3709 -- we need the original concurrent type. The operation may have
3710 -- several controlling formals, so the replacement must be done
3713 if Comes_From_Source
(Spec_Id
)
3714 and then Present
(First_Entity
(Spec_Id
))
3715 and then Ekind
(Etype
(First_Entity
(Spec_Id
))) = E_Record_Type
3716 and then Is_Tagged_Type
(Etype
(First_Entity
(Spec_Id
)))
3717 and then Present
(Interfaces
(Etype
(First_Entity
(Spec_Id
))))
3718 and then Present
(Corresponding_Concurrent_Type
3719 (Etype
(First_Entity
(Spec_Id
))))
3722 Typ
: constant Entity_Id
:= Etype
(First_Entity
(Spec_Id
));
3726 Form
:= First_Formal
(Spec_Id
);
3727 while Present
(Form
) loop
3728 if Etype
(Form
) = Typ
then
3729 Set_Etype
(Form
, Corresponding_Concurrent_Type
(Typ
));
3737 -- Make the formals visible, and place subprogram on scope stack.
3738 -- This is also the point at which we set Last_Real_Spec_Entity
3739 -- to mark the entities which will not be moved to the body.
3741 Install_Formals
(Spec_Id
);
3742 Last_Real_Spec_Entity
:= Last_Entity
(Spec_Id
);
3744 -- Within an instance, add local renaming declarations so that
3745 -- gdb can retrieve the values of actuals more easily. This is
3746 -- only relevant if generating code (and indeed we definitely
3747 -- do not want these definitions -gnatc mode, because that would
3750 if Is_Generic_Instance
(Spec_Id
)
3751 and then Is_Wrapper_Package
(Current_Scope
)
3752 and then Expander_Active
3754 Build_Subprogram_Instance_Renamings
(N
, Current_Scope
);
3757 Push_Scope
(Spec_Id
);
3759 -- Make sure that the subprogram is immediately visible. For
3760 -- child units that have no separate spec this is indispensable.
3761 -- Otherwise it is safe albeit redundant.
3763 Set_Is_Immediately_Visible
(Spec_Id
);
3766 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
3767 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Spec_Id
));
3768 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
3770 -- Case of subprogram body with no previous spec
3773 -- Check for style warning required
3777 -- Only apply check for source level subprograms for which checks
3778 -- have not been suppressed.
3780 and then Comes_From_Source
(Body_Id
)
3781 and then not Suppress_Style_Checks
(Body_Id
)
3783 -- No warnings within an instance
3785 and then not In_Instance
3787 -- No warnings for expression functions
3789 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3791 Style
.Body_With_No_Spec
(N
);
3794 New_Overloaded_Entity
(Body_Id
);
3796 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
3797 Set_Acts_As_Spec
(N
);
3798 Generate_Definition
(Body_Id
);
3800 (Body_Id
, Body_Id
, 'b', Set_Ref
=> False, Force
=> True);
3802 -- If the body is an entry wrapper created for an entry with
3803 -- preconditions, it must be compiled in the context of the
3804 -- enclosing synchronized object, because it may mention other
3805 -- operations of the type.
3807 if Is_Entry_Wrapper
(Body_Id
) then
3809 Prot
: constant Entity_Id
:= Etype
(First_Entity
(Body_Id
));
3812 Install_Declarations
(Prot
);
3816 Install_Formals
(Body_Id
);
3818 Push_Scope
(Body_Id
);
3821 -- For stubs and bodies with no previous spec, generate references to
3824 Generate_Reference_To_Formals
(Body_Id
);
3827 -- Entry barrier functions are generated outside the protected type and
3828 -- should not carry the SPARK_Mode of the enclosing context.
3830 if Nkind
(N
) = N_Subprogram_Body
3831 and then Is_Entry_Barrier_Function
(N
)
3835 -- The body is generated as part of expression function expansion. When
3836 -- the expression function appears in the visible declarations of a
3837 -- package, the body is added to the private declarations. Since both
3838 -- declarative lists may be subject to a different SPARK_Mode, inherit
3839 -- the mode of the spec.
3841 -- package P with SPARK_Mode is
3842 -- function Expr_Func ... is (...); -- original
3843 -- [function Expr_Func ...;] -- generated spec
3846 -- pragma SPARK_Mode (Off);
3847 -- [function Expr_Func ... is return ...;] -- generated body
3848 -- end P; -- mode is ON
3850 elsif not Comes_From_Source
(N
)
3851 and then Present
(Spec_Id
)
3852 and then Is_Expression_Function
(Spec_Id
)
3854 Set_SPARK_Pragma
(Body_Id
, SPARK_Pragma
(Spec_Id
));
3855 Set_SPARK_Pragma_Inherited
3856 (Body_Id
, SPARK_Pragma_Inherited
(Spec_Id
));
3858 -- Set the SPARK_Mode from the current context (may be overwritten later
3859 -- with explicit pragma). Exclude the case where the SPARK_Mode appears
3860 -- initially on a stand-alone subprogram body, but is then relocated to
3861 -- a generated corresponding spec. In this scenario the mode is shared
3862 -- between the spec and body.
3864 elsif No
(SPARK_Pragma
(Body_Id
)) then
3865 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
3866 Set_SPARK_Pragma_Inherited
(Body_Id
);
3869 -- If this is the proper body of a stub, we must verify that the stub
3870 -- conforms to the body, and to the previous spec if one was present.
3871 -- We know already that the body conforms to that spec. This test is
3872 -- only required for subprograms that come from source.
3874 if Nkind
(Parent
(N
)) = N_Subunit
3875 and then Comes_From_Source
(N
)
3876 and then not Error_Posted
(Body_Id
)
3877 and then Nkind
(Corresponding_Stub
(Parent
(N
))) =
3878 N_Subprogram_Body_Stub
3881 Old_Id
: constant Entity_Id
:=
3883 (Specification
(Corresponding_Stub
(Parent
(N
))));
3885 Conformant
: Boolean := False;
3888 if No
(Spec_Id
) then
3889 Check_Fully_Conformant
(Body_Id
, Old_Id
);
3893 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
3895 if not Conformant
then
3897 -- The stub was taken to be a new declaration. Indicate that
3900 Set_Has_Completion
(Old_Id
, False);
3906 Set_Has_Completion
(Body_Id
);
3907 Check_Eliminated
(Body_Id
);
3909 -- Analyze any aspect specifications that appear on the subprogram body
3910 -- stub. Stop the analysis now as the stub does not have a declarative
3911 -- or a statement part, and it cannot be inlined.
3913 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3914 if Has_Aspects
(N
) then
3915 Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
);
3923 -- Note: Normally we don't do any inlining if expansion is off, since
3924 -- we won't generate code in any case. An exception arises in GNATprove
3925 -- mode where we want to expand some calls in place, even with expansion
3926 -- disabled, since the inlining eases formal verification.
3928 if not GNATprove_Mode
3929 and then Expander_Active
3930 and then Serious_Errors_Detected
= 0
3931 and then Present
(Spec_Id
)
3932 and then Has_Pragma_Inline
(Spec_Id
)
3934 -- Legacy implementation (relying on front-end inlining)
3936 if not Back_End_Inlining
then
3937 if (Has_Pragma_Inline_Always
(Spec_Id
)
3938 and then not Opt
.Disable_FE_Inline_Always
)
3939 or else (Front_End_Inlining
3940 and then not Opt
.Disable_FE_Inline
)
3942 Build_Body_To_Inline
(N
, Spec_Id
);
3945 -- New implementation (relying on back-end inlining)
3948 if Has_Pragma_Inline_Always
(Spec_Id
)
3949 or else Optimization_Level
> 0
3951 -- Handle function returning an unconstrained type
3953 if Comes_From_Source
(Body_Id
)
3954 and then Ekind
(Spec_Id
) = E_Function
3955 and then Returns_Unconstrained_Type
(Spec_Id
)
3957 -- If function builds in place, i.e. returns a limited type,
3958 -- inlining cannot be done.
3960 and then not Is_Limited_Type
(Etype
(Spec_Id
))
3962 Check_And_Split_Unconstrained_Function
(N
, Spec_Id
, Body_Id
);
3966 Subp_Body
: constant Node_Id
:=
3967 Unit_Declaration_Node
(Body_Id
);
3968 Subp_Decl
: constant List_Id
:= Declarations
(Subp_Body
);
3971 -- Do not pass inlining to the backend if the subprogram
3972 -- has declarations or statements which cannot be inlined
3973 -- by the backend. This check is done here to emit an
3974 -- error instead of the generic warning message reported
3975 -- by the GCC backend (ie. "function might not be
3978 if Present
(Subp_Decl
)
3979 and then Has_Excluded_Declaration
(Spec_Id
, Subp_Decl
)
3983 elsif Has_Excluded_Statement
3986 (Handled_Statement_Sequence
(Subp_Body
)))
3990 -- If the backend inlining is available then at this
3991 -- stage we only have to mark the subprogram as inlined.
3992 -- The expander will take care of registering it in the
3993 -- table of subprograms inlined by the backend a part of
3994 -- processing calls to it (cf. Expand_Call)
3997 Set_Is_Inlined
(Spec_Id
);
4004 -- In GNATprove mode, inline only when there is a separate subprogram
4005 -- declaration for now, as inlining of subprogram bodies acting as
4006 -- declarations, or subprogram stubs, are not supported by front-end
4007 -- inlining. This inlining should occur after analysis of the body, so
4008 -- that it is known whether the value of SPARK_Mode, which can be
4009 -- defined by a pragma inside the body, is applicable to the body.
4011 elsif GNATprove_Mode
4012 and then Full_Analysis
4013 and then not Inside_A_Generic
4014 and then Present
(Spec_Id
)
4016 Nkind
(Unit_Declaration_Node
(Spec_Id
)) = N_Subprogram_Declaration
4017 and then Body_Has_SPARK_Mode_On
4018 and then Can_Be_Inlined_In_GNATprove_Mode
(Spec_Id
, Body_Id
)
4019 and then not Body_Has_Contract
4021 Build_Body_To_Inline
(N
, Spec_Id
);
4024 -- When generating code, inherited pre/postconditions are handled when
4025 -- expanding the corresponding contract.
4027 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
4028 -- of the specification we have to install the private withed units.
4029 -- This holds for child units as well.
4031 if Is_Compilation_Unit
(Body_Id
)
4032 or else Nkind
(Parent
(N
)) = N_Compilation_Unit
4034 Install_Private_With_Clauses
(Body_Id
);
4037 Check_Anonymous_Return
;
4039 -- Set the Protected_Formal field of each extra formal of the protected
4040 -- subprogram to reference the corresponding extra formal of the
4041 -- subprogram that implements it. For regular formals this occurs when
4042 -- the protected subprogram's declaration is expanded, but the extra
4043 -- formals don't get created until the subprogram is frozen. We need to
4044 -- do this before analyzing the protected subprogram's body so that any
4045 -- references to the original subprogram's extra formals will be changed
4046 -- refer to the implementing subprogram's formals (see Expand_Formal).
4048 if Present
(Spec_Id
)
4049 and then Is_Protected_Type
(Scope
(Spec_Id
))
4050 and then Present
(Protected_Body_Subprogram
(Spec_Id
))
4053 Impl_Subp
: constant Entity_Id
:=
4054 Protected_Body_Subprogram
(Spec_Id
);
4055 Prot_Ext_Formal
: Entity_Id
:= Extra_Formals
(Spec_Id
);
4056 Impl_Ext_Formal
: Entity_Id
:= Extra_Formals
(Impl_Subp
);
4058 while Present
(Prot_Ext_Formal
) loop
4059 pragma Assert
(Present
(Impl_Ext_Formal
));
4060 Set_Protected_Formal
(Prot_Ext_Formal
, Impl_Ext_Formal
);
4061 Next_Formal_With_Extras
(Prot_Ext_Formal
);
4062 Next_Formal_With_Extras
(Impl_Ext_Formal
);
4067 -- Now we can go on to analyze the body
4069 HSS
:= Handled_Statement_Sequence
(N
);
4070 Set_Actual_Subtypes
(N
, Current_Scope
);
4072 -- Add a declaration for the Protection object, renaming declarations
4073 -- for discriminals and privals and finally a declaration for the entry
4074 -- family index (if applicable). This form of early expansion is done
4075 -- when the Expander is active because Install_Private_Data_Declarations
4076 -- references entities which were created during regular expansion. The
4077 -- subprogram entity must come from source, and not be an internally
4078 -- generated subprogram.
4081 and then Present
(Prot_Typ
)
4082 and then Present
(Spec_Id
)
4083 and then Comes_From_Source
(Spec_Id
)
4084 and then not Is_Eliminated
(Spec_Id
)
4086 Install_Private_Data_Declarations
4087 (Sloc
(N
), Spec_Id
, Prot_Typ
, N
, Declarations
(N
));
4090 -- Ada 2012 (AI05-0151): Incomplete types coming from a limited context
4091 -- may now appear in parameter and result profiles. Since the analysis
4092 -- of a subprogram body may use the parameter and result profile of the
4093 -- spec, swap any limited views with their non-limited counterpart.
4095 if Ada_Version
>= Ada_2012
and then Present
(Spec_Id
) then
4096 Exch_Views
:= Exchange_Limited_Views
(Spec_Id
);
4099 -- If the return type is an anonymous access type whose designated type
4100 -- is the limited view of a class-wide type and the non-limited view is
4101 -- available, update the return type accordingly.
4103 if Ada_Version
>= Ada_2005
and then Present
(Spec_Id
) then
4109 Rtyp
:= Etype
(Spec_Id
);
4111 if Ekind
(Rtyp
) = E_Anonymous_Access_Type
then
4112 Etyp
:= Directly_Designated_Type
(Rtyp
);
4114 if Is_Class_Wide_Type
(Etyp
)
4115 and then From_Limited_With
(Etyp
)
4118 Set_Directly_Designated_Type
(Rtyp
, Available_View
(Etyp
));
4124 -- Analyze any aspect specifications that appear on the subprogram body
4126 if Has_Aspects
(N
) then
4127 Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
);
4130 Analyze_Declarations
(Declarations
(N
));
4132 -- Verify that the SPARK_Mode of the body agrees with that of its spec
4134 if Present
(Spec_Id
) and then Present
(SPARK_Pragma
(Body_Id
)) then
4135 if Present
(SPARK_Pragma
(Spec_Id
)) then
4136 if Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Spec_Id
)) = Off
4138 Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Body_Id
)) = On
4140 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
4141 Error_Msg_N
("incorrect application of SPARK_Mode#", N
);
4142 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Spec_Id
));
4144 ("\value Off was set for SPARK_Mode on & #", N
, Spec_Id
);
4147 elsif Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Body_Stub
then
4151 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
4152 Error_Msg_N
("incorrect application of SPARK_Mode #", N
);
4153 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
4155 ("\no value was set for SPARK_Mode on & #", N
, Spec_Id
);
4159 -- A subprogram body "freezes" its own contract. Analyze the contract
4160 -- after the declarations of the body have been processed as pragmas
4161 -- are now chained on the contract of the subprogram body.
4163 Analyze_Entry_Or_Subprogram_Body_Contract
(Body_Id
);
4165 -- Check completion, and analyze the statements
4168 Inspect_Deferred_Constant_Completion
(Declarations
(N
));
4171 -- Deal with end of scope processing for the body
4173 Process_End_Label
(HSS
, 't', Current_Scope
);
4176 -- If we are compiling an entry wrapper, remove the enclosing
4177 -- synchronized object from the stack.
4179 if Is_Entry_Wrapper
(Body_Id
) then
4183 Check_Subprogram_Order
(N
);
4184 Set_Analyzed
(Body_Id
);
4186 -- If we have a separate spec, then the analysis of the declarations
4187 -- caused the entities in the body to be chained to the spec id, but
4188 -- we want them chained to the body id. Only the formal parameters
4189 -- end up chained to the spec id in this case.
4191 if Present
(Spec_Id
) then
4193 -- We must conform to the categorization of our spec
4195 Validate_Categorization_Dependency
(N
, Spec_Id
);
4197 -- And if this is a child unit, the parent units must conform
4199 if Is_Child_Unit
(Spec_Id
) then
4200 Validate_Categorization_Dependency
4201 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
4204 -- Here is where we move entities from the spec to the body
4206 -- Case where there are entities that stay with the spec
4208 if Present
(Last_Real_Spec_Entity
) then
4210 -- No body entities (happens when the only real spec entities come
4211 -- from precondition and postcondition pragmas).
4213 if No
(Last_Entity
(Body_Id
)) then
4214 Set_First_Entity
(Body_Id
, Next_Entity
(Last_Real_Spec_Entity
));
4216 -- Body entities present (formals), so chain stuff past them
4220 (Last_Entity
(Body_Id
), Next_Entity
(Last_Real_Spec_Entity
));
4223 Set_Next_Entity
(Last_Real_Spec_Entity
, Empty
);
4224 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
4225 Set_Last_Entity
(Spec_Id
, Last_Real_Spec_Entity
);
4227 -- Case where there are no spec entities, in this case there can be
4228 -- no body entities either, so just move everything.
4230 -- If the body is generated for an expression function, it may have
4231 -- been preanalyzed already, if 'access was applied to it.
4234 if Nkind
(Original_Node
(Unit_Declaration_Node
(Spec_Id
))) /=
4235 N_Expression_Function
4237 pragma Assert
(No
(Last_Entity
(Body_Id
)));
4241 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
4242 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
4243 Set_First_Entity
(Spec_Id
, Empty
);
4244 Set_Last_Entity
(Spec_Id
, Empty
);
4248 Check_Missing_Return
;
4250 -- Now we are going to check for variables that are never modified in
4251 -- the body of the procedure. But first we deal with a special case
4252 -- where we want to modify this check. If the body of the subprogram
4253 -- starts with a raise statement or its equivalent, or if the body
4254 -- consists entirely of a null statement, then it is pretty obvious that
4255 -- it is OK to not reference the parameters. For example, this might be
4256 -- the following common idiom for a stubbed function: statement of the
4257 -- procedure raises an exception. In particular this deals with the
4258 -- common idiom of a stubbed function, which appears something like:
4260 -- function F (A : Integer) return Some_Type;
4263 -- raise Program_Error;
4267 -- Here the purpose of X is simply to satisfy the annoying requirement
4268 -- in Ada that there be at least one return, and we certainly do not
4269 -- want to go posting warnings on X that it is not initialized. On
4270 -- the other hand, if X is entirely unreferenced that should still
4273 -- What we do is to detect these cases, and if we find them, flag the
4274 -- subprogram as being Is_Trivial_Subprogram and then use that flag to
4275 -- suppress unwanted warnings. For the case of the function stub above
4276 -- we have a special test to set X as apparently assigned to suppress
4283 -- Skip initial labels (for one thing this occurs when we are in
4284 -- front-end ZCX mode, but in any case it is irrelevant), and also
4285 -- initial Push_xxx_Error_Label nodes, which are also irrelevant.
4287 Stm
:= First
(Statements
(HSS
));
4288 while Nkind
(Stm
) = N_Label
4289 or else Nkind
(Stm
) in N_Push_xxx_Label
4294 -- Do the test on the original statement before expansion
4297 Ostm
: constant Node_Id
:= Original_Node
(Stm
);
4300 -- If explicit raise statement, turn on flag
4302 if Nkind
(Ostm
) = N_Raise_Statement
then
4303 Set_Trivial_Subprogram
(Stm
);
4305 -- If null statement, and no following statements, turn on flag
4307 elsif Nkind
(Stm
) = N_Null_Statement
4308 and then Comes_From_Source
(Stm
)
4309 and then No
(Next
(Stm
))
4311 Set_Trivial_Subprogram
(Stm
);
4313 -- Check for explicit call cases which likely raise an exception
4315 elsif Nkind
(Ostm
) = N_Procedure_Call_Statement
then
4316 if Is_Entity_Name
(Name
(Ostm
)) then
4318 Ent
: constant Entity_Id
:= Entity
(Name
(Ostm
));
4321 -- If the procedure is marked No_Return, then likely it
4322 -- raises an exception, but in any case it is not coming
4323 -- back here, so turn on the flag.
4326 and then Ekind
(Ent
) = E_Procedure
4327 and then No_Return
(Ent
)
4329 Set_Trivial_Subprogram
(Stm
);
4337 -- Check for variables that are never modified
4344 -- If there is a separate spec, then transfer Never_Set_In_Source
4345 -- flags from out parameters to the corresponding entities in the
4346 -- body. The reason we do that is we want to post error flags on
4347 -- the body entities, not the spec entities.
4349 if Present
(Spec_Id
) then
4350 E1
:= First_Entity
(Spec_Id
);
4351 while Present
(E1
) loop
4352 if Ekind
(E1
) = E_Out_Parameter
then
4353 E2
:= First_Entity
(Body_Id
);
4354 while Present
(E2
) loop
4355 exit when Chars
(E1
) = Chars
(E2
);
4359 if Present
(E2
) then
4360 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
4368 -- Check references in body
4370 Check_References
(Body_Id
);
4373 -- Check for nested subprogram, and mark outer level subprogram if so
4379 if Present
(Spec_Id
) then
4386 Ent
:= Enclosing_Subprogram
(Ent
);
4387 exit when No
(Ent
) or else Is_Subprogram
(Ent
);
4390 if Present
(Ent
) then
4391 Set_Has_Nested_Subprogram
(Ent
);
4395 -- Restore the limited views in the spec, if any, to let the back end
4396 -- process it without running into circularities.
4398 if Exch_Views
/= No_Elist
then
4399 Restore_Limited_Views
(Exch_Views
);
4402 if Present
(Desig_View
) then
4403 Set_Directly_Designated_Type
(Etype
(Spec_Id
), Desig_View
);
4408 Restore_Ghost_Mode
(Mode
);
4410 end Analyze_Subprogram_Body_Helper
;
4412 ------------------------------------
4413 -- Analyze_Subprogram_Declaration --
4414 ------------------------------------
4416 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
4417 Scop
: constant Entity_Id
:= Current_Scope
;
4418 Designator
: Entity_Id
;
4420 Is_Completion
: Boolean;
4421 -- Indicates whether a null procedure declaration is a completion
4424 -- Null procedures are not allowed in SPARK
4426 if Nkind
(Specification
(N
)) = N_Procedure_Specification
4427 and then Null_Present
(Specification
(N
))
4429 Check_SPARK_05_Restriction
("null procedure is not allowed", N
);
4431 -- Null procedures are allowed in protected types, following the
4432 -- recent AI12-0147.
4434 if Is_Protected_Type
(Current_Scope
)
4435 and then Ada_Version
< Ada_2012
4437 Error_Msg_N
("protected operation cannot be a null procedure", N
);
4440 Analyze_Null_Procedure
(N
, Is_Completion
);
4442 -- The null procedure acts as a body, nothing further is needed
4444 if Is_Completion
then
4449 Designator
:= Analyze_Subprogram_Specification
(Specification
(N
));
4451 -- A reference may already have been generated for the unit name, in
4452 -- which case the following call is redundant. However it is needed for
4453 -- declarations that are the rewriting of an expression function.
4455 Generate_Definition
(Designator
);
4457 -- Set the SPARK mode from the current context (may be overwritten later
4458 -- with explicit pragma). This is not done for entry barrier functions
4459 -- because they are generated outside the protected type and should not
4460 -- carry the mode of the enclosing context.
4462 if Nkind
(N
) = N_Subprogram_Declaration
4463 and then Is_Entry_Barrier_Function
(N
)
4467 Set_SPARK_Pragma
(Designator
, SPARK_Mode_Pragma
);
4468 Set_SPARK_Pragma_Inherited
(Designator
);
4471 if Debug_Flag_C
then
4472 Write_Str
("==> subprogram spec ");
4473 Write_Name
(Chars
(Designator
));
4474 Write_Str
(" from ");
4475 Write_Location
(Sloc
(N
));
4480 Validate_RCI_Subprogram_Declaration
(N
);
4481 New_Overloaded_Entity
(Designator
);
4482 Check_Delayed_Subprogram
(Designator
);
4484 -- If the type of the first formal of the current subprogram is a non-
4485 -- generic tagged private type, mark the subprogram as being a private
4486 -- primitive. Ditto if this is a function with controlling result, and
4487 -- the return type is currently private. In both cases, the type of the
4488 -- controlling argument or result must be in the current scope for the
4489 -- operation to be primitive.
4491 if Has_Controlling_Result
(Designator
)
4492 and then Is_Private_Type
(Etype
(Designator
))
4493 and then Scope
(Etype
(Designator
)) = Current_Scope
4494 and then not Is_Generic_Actual_Type
(Etype
(Designator
))
4496 Set_Is_Private_Primitive
(Designator
);
4498 elsif Present
(First_Formal
(Designator
)) then
4500 Formal_Typ
: constant Entity_Id
:=
4501 Etype
(First_Formal
(Designator
));
4503 Set_Is_Private_Primitive
(Designator
,
4504 Is_Tagged_Type
(Formal_Typ
)
4505 and then Scope
(Formal_Typ
) = Current_Scope
4506 and then Is_Private_Type
(Formal_Typ
)
4507 and then not Is_Generic_Actual_Type
(Formal_Typ
));
4511 -- Ada 2005 (AI-251): Abstract interface primitives must be abstract
4514 if Ada_Version
>= Ada_2005
4515 and then Comes_From_Source
(N
)
4516 and then Is_Dispatching_Operation
(Designator
)
4523 if Has_Controlling_Result
(Designator
) then
4524 Etyp
:= Etype
(Designator
);
4527 E
:= First_Entity
(Designator
);
4529 and then Is_Formal
(E
)
4530 and then not Is_Controlling_Formal
(E
)
4538 if Is_Access_Type
(Etyp
) then
4539 Etyp
:= Directly_Designated_Type
(Etyp
);
4542 if Is_Interface
(Etyp
)
4543 and then not Is_Abstract_Subprogram
(Designator
)
4544 and then not (Ekind
(Designator
) = E_Procedure
4545 and then Null_Present
(Specification
(N
)))
4547 Error_Msg_Name_1
:= Chars
(Defining_Entity
(N
));
4549 -- Specialize error message based on procedures vs. functions,
4550 -- since functions can't be null subprograms.
4552 if Ekind
(Designator
) = E_Procedure
then
4554 ("interface procedure % must be abstract or null", N
);
4557 ("interface function % must be abstract", N
);
4563 -- What is the following code for, it used to be
4565 -- ??? Set_Suppress_Elaboration_Checks
4566 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
4568 -- The following seems equivalent, but a bit dubious
4570 if Elaboration_Checks_Suppressed
(Designator
) then
4571 Set_Kill_Elaboration_Checks
(Designator
);
4574 if Scop
/= Standard_Standard
and then not Is_Child_Unit
(Designator
) then
4575 Set_Categorization_From_Scope
(Designator
, Scop
);
4578 -- For a compilation unit, check for library-unit pragmas
4580 Push_Scope
(Designator
);
4581 Set_Categorization_From_Pragmas
(N
);
4582 Validate_Categorization_Dependency
(N
, Designator
);
4586 -- For a compilation unit, set body required. This flag will only be
4587 -- reset if a valid Import or Interface pragma is processed later on.
4589 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
4590 Set_Body_Required
(Parent
(N
), True);
4592 if Ada_Version
>= Ada_2005
4593 and then Nkind
(Specification
(N
)) = N_Procedure_Specification
4594 and then Null_Present
(Specification
(N
))
4597 ("null procedure cannot be declared at library level", N
);
4601 Generate_Reference_To_Formals
(Designator
);
4602 Check_Eliminated
(Designator
);
4604 if Debug_Flag_C
then
4606 Write_Str
("<== subprogram spec ");
4607 Write_Name
(Chars
(Designator
));
4608 Write_Str
(" from ");
4609 Write_Location
(Sloc
(N
));
4613 if Is_Protected_Type
(Current_Scope
) then
4615 -- Indicate that this is a protected operation, because it may be
4616 -- used in subsequent declarations within the protected type.
4618 Set_Convention
(Designator
, Convention_Protected
);
4621 List_Inherited_Pre_Post_Aspects
(Designator
);
4623 if Has_Aspects
(N
) then
4624 Analyze_Aspect_Specifications
(N
, Designator
);
4626 end Analyze_Subprogram_Declaration
;
4628 --------------------------------------
4629 -- Analyze_Subprogram_Specification --
4630 --------------------------------------
4632 -- Reminder: N here really is a subprogram specification (not a subprogram
4633 -- declaration). This procedure is called to analyze the specification in
4634 -- both subprogram bodies and subprogram declarations (specs).
4636 function Analyze_Subprogram_Specification
(N
: Node_Id
) return Entity_Id
is
4637 function Is_Invariant_Procedure_Or_Body
(E
: Entity_Id
) return Boolean;
4638 -- Determine whether entity E denotes the spec or body of an invariant
4641 ------------------------------------
4642 -- Is_Invariant_Procedure_Or_Body --
4643 ------------------------------------
4645 function Is_Invariant_Procedure_Or_Body
(E
: Entity_Id
) return Boolean is
4646 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
4650 if Nkind
(Decl
) = N_Subprogram_Body
then
4651 Spec
:= Corresponding_Spec
(Decl
);
4658 and then Ekind
(Spec
) = E_Procedure
4659 and then (Is_Partial_Invariant_Procedure
(Spec
)
4660 or else Is_Invariant_Procedure
(Spec
));
4661 end Is_Invariant_Procedure_Or_Body
;
4665 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
4666 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
4668 -- Start of processing for Analyze_Subprogram_Specification
4671 -- User-defined operator is not allowed in SPARK, except as a renaming
4673 if Nkind
(Defining_Unit_Name
(N
)) = N_Defining_Operator_Symbol
4674 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
4676 Check_SPARK_05_Restriction
4677 ("user-defined operator is not allowed", N
);
4680 -- Proceed with analysis. Do not emit a cross-reference entry if the
4681 -- specification comes from an expression function, because it may be
4682 -- the completion of a previous declaration. It is not, the cross-
4683 -- reference entry will be emitted for the new subprogram declaration.
4685 if Nkind
(Parent
(N
)) /= N_Expression_Function
then
4686 Generate_Definition
(Designator
);
4689 if Nkind
(N
) = N_Function_Specification
then
4690 Set_Ekind
(Designator
, E_Function
);
4691 Set_Mechanism
(Designator
, Default_Mechanism
);
4693 Set_Ekind
(Designator
, E_Procedure
);
4694 Set_Etype
(Designator
, Standard_Void_Type
);
4697 -- Flag Is_Inlined_Always is True by default, and reversed to False for
4698 -- those subprograms which could be inlined in GNATprove mode (because
4699 -- Body_To_Inline is non-Empty) but should not be inlined.
4701 if GNATprove_Mode
then
4702 Set_Is_Inlined_Always
(Designator
);
4705 -- Introduce new scope for analysis of the formals and the return type
4707 Set_Scope
(Designator
, Current_Scope
);
4709 if Present
(Formals
) then
4710 Push_Scope
(Designator
);
4711 Process_Formals
(Formals
, N
);
4713 -- Check dimensions in N for formals with default expression
4715 Analyze_Dimension_Formals
(N
, Formals
);
4717 -- Ada 2005 (AI-345): If this is an overriding operation of an
4718 -- inherited interface operation, and the controlling type is
4719 -- a synchronized type, replace the type with its corresponding
4720 -- record, to match the proper signature of an overriding operation.
4721 -- Same processing for an access parameter whose designated type is
4722 -- derived from a synchronized interface.
4724 -- This modification is not done for invariant procedures because
4725 -- the corresponding record may not necessarely be visible when the
4726 -- concurrent type acts as the full view of a private type.
4729 -- type Prot is private with Type_Invariant => ...;
4730 -- procedure ConcInvariant (Obj : Prot);
4732 -- protected type Prot is ...;
4733 -- type Concurrent_Record_Prot is record ...;
4734 -- procedure ConcInvariant (Obj : Prot) is
4736 -- end ConcInvariant;
4739 -- In the example above, both the spec and body of the invariant
4740 -- procedure must utilize the private type as the controlling type.
4742 if Ada_Version
>= Ada_2005
4743 and then not Is_Invariant_Procedure_Or_Body
(Designator
)
4747 Formal_Typ
: Entity_Id
;
4748 Rec_Typ
: Entity_Id
;
4749 Desig_Typ
: Entity_Id
;
4752 Formal
:= First_Formal
(Designator
);
4753 while Present
(Formal
) loop
4754 Formal_Typ
:= Etype
(Formal
);
4756 if Is_Concurrent_Type
(Formal_Typ
)
4757 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
4759 Rec_Typ
:= Corresponding_Record_Type
(Formal_Typ
);
4761 if Present
(Interfaces
(Rec_Typ
)) then
4762 Set_Etype
(Formal
, Rec_Typ
);
4765 elsif Ekind
(Formal_Typ
) = E_Anonymous_Access_Type
then
4766 Desig_Typ
:= Designated_Type
(Formal_Typ
);
4768 if Is_Concurrent_Type
(Desig_Typ
)
4769 and then Present
(Corresponding_Record_Type
(Desig_Typ
))
4771 Rec_Typ
:= Corresponding_Record_Type
(Desig_Typ
);
4773 if Present
(Interfaces
(Rec_Typ
)) then
4774 Set_Directly_Designated_Type
(Formal_Typ
, Rec_Typ
);
4779 Next_Formal
(Formal
);
4786 -- The subprogram scope is pushed and popped around the processing of
4787 -- the return type for consistency with call above to Process_Formals
4788 -- (which itself can call Analyze_Return_Type), and to ensure that any
4789 -- itype created for the return type will be associated with the proper
4792 elsif Nkind
(N
) = N_Function_Specification
then
4793 Push_Scope
(Designator
);
4794 Analyze_Return_Type
(N
);
4800 if Nkind
(N
) = N_Function_Specification
then
4802 -- Deal with operator symbol case
4804 if Nkind
(Designator
) = N_Defining_Operator_Symbol
then
4805 Valid_Operator_Definition
(Designator
);
4808 May_Need_Actuals
(Designator
);
4810 -- Ada 2005 (AI-251): If the return type is abstract, verify that
4811 -- the subprogram is abstract also. This does not apply to renaming
4812 -- declarations, where abstractness is inherited, and to subprogram
4813 -- bodies generated for stream operations, which become renamings as
4816 -- In case of primitives associated with abstract interface types
4817 -- the check is applied later (see Analyze_Subprogram_Declaration).
4819 if not Nkind_In
(Original_Node
(Parent
(N
)),
4820 N_Abstract_Subprogram_Declaration
,
4821 N_Formal_Abstract_Subprogram_Declaration
,
4822 N_Subprogram_Renaming_Declaration
)
4824 if Is_Abstract_Type
(Etype
(Designator
))
4825 and then not Is_Interface
(Etype
(Designator
))
4828 ("function that returns abstract type must be abstract", N
);
4830 -- Ada 2012 (AI-0073): Extend this test to subprograms with an
4831 -- access result whose designated type is abstract.
4833 elsif Ada_Version
>= Ada_2012
4834 and then Nkind
(Result_Definition
(N
)) = N_Access_Definition
4836 not Is_Class_Wide_Type
(Designated_Type
(Etype
(Designator
)))
4837 and then Is_Abstract_Type
(Designated_Type
(Etype
(Designator
)))
4840 ("function whose access result designates abstract type "
4841 & "must be abstract", N
);
4847 end Analyze_Subprogram_Specification
;
4849 -----------------------
4850 -- Check_Conformance --
4851 -----------------------
4853 procedure Check_Conformance
4854 (New_Id
: Entity_Id
;
4856 Ctype
: Conformance_Type
;
4858 Conforms
: out Boolean;
4859 Err_Loc
: Node_Id
:= Empty
;
4860 Get_Inst
: Boolean := False;
4861 Skip_Controlling_Formals
: Boolean := False)
4863 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
4864 -- Sets Conforms to False. If Errmsg is False, then that's all it does.
4865 -- If Errmsg is True, then processing continues to post an error message
4866 -- for conformance error on given node. Two messages are output. The
4867 -- first message points to the previous declaration with a general "no
4868 -- conformance" message. The second is the detailed reason, supplied as
4869 -- Msg. The parameter N provide information for a possible & insertion
4870 -- in the message, and also provides the location for posting the
4871 -- message in the absence of a specified Err_Loc location.
4873 function Conventions_Match
4875 Id2
: Entity_Id
) return Boolean;
4876 -- Determine whether the conventions of arbitrary entities Id1 and Id2
4879 -----------------------
4880 -- Conformance_Error --
4881 -----------------------
4883 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
4890 if No
(Err_Loc
) then
4896 Error_Msg_Sloc
:= Sloc
(Old_Id
);
4899 when Type_Conformant
=>
4900 Error_Msg_N
-- CODEFIX
4901 ("not type conformant with declaration#!", Enode
);
4903 when Mode_Conformant
=>
4904 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4906 ("not mode conformant with operation inherited#!",
4910 ("not mode conformant with declaration#!", Enode
);
4913 when Subtype_Conformant
=>
4914 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4916 ("not subtype conformant with operation inherited#!",
4920 ("not subtype conformant with declaration#!", Enode
);
4923 when Fully_Conformant
=>
4924 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4925 Error_Msg_N
-- CODEFIX
4926 ("not fully conformant with operation inherited#!",
4929 Error_Msg_N
-- CODEFIX
4930 ("not fully conformant with declaration#!", Enode
);
4934 Error_Msg_NE
(Msg
, Enode
, N
);
4936 end Conformance_Error
;
4938 -----------------------
4939 -- Conventions_Match --
4940 -----------------------
4942 function Conventions_Match
4944 Id2
: Entity_Id
) return Boolean
4947 -- Ignore the conventions of anonymous access-to-subprogram types
4948 -- and subprogram types because these are internally generated and
4949 -- the only way these may receive a convention is if they inherit
4950 -- the convention of a related subprogram.
4952 if Ekind_In
(Id1
, E_Anonymous_Access_Subprogram_Type
,
4955 Ekind_In
(Id2
, E_Anonymous_Access_Subprogram_Type
,
4960 -- Otherwise compare the conventions directly
4963 return Convention
(Id1
) = Convention
(Id2
);
4965 end Conventions_Match
;
4969 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
4970 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
4971 Old_Formal
: Entity_Id
;
4972 New_Formal
: Entity_Id
;
4973 Access_Types_Match
: Boolean;
4974 Old_Formal_Base
: Entity_Id
;
4975 New_Formal_Base
: Entity_Id
;
4977 -- Start of processing for Check_Conformance
4982 -- We need a special case for operators, since they don't appear
4985 if Ctype
= Type_Conformant
then
4986 if Ekind
(New_Id
) = E_Operator
4987 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
4993 -- If both are functions/operators, check return types conform
4995 if Old_Type
/= Standard_Void_Type
4997 New_Type
/= Standard_Void_Type
4999 -- If we are checking interface conformance we omit controlling
5000 -- arguments and result, because we are only checking the conformance
5001 -- of the remaining parameters.
5003 if Has_Controlling_Result
(Old_Id
)
5004 and then Has_Controlling_Result
(New_Id
)
5005 and then Skip_Controlling_Formals
5009 elsif not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
5010 if Ctype
>= Subtype_Conformant
5011 and then not Predicates_Match
(Old_Type
, New_Type
)
5014 ("\predicate of return type does not match!", New_Id
);
5017 ("\return type does not match!", New_Id
);
5023 -- Ada 2005 (AI-231): In case of anonymous access types check the
5024 -- null-exclusion and access-to-constant attributes match.
5026 if Ada_Version
>= Ada_2005
5027 and then Ekind
(Etype
(Old_Type
)) = E_Anonymous_Access_Type
5029 (Can_Never_Be_Null
(Old_Type
) /= Can_Never_Be_Null
(New_Type
)
5030 or else Is_Access_Constant
(Etype
(Old_Type
)) /=
5031 Is_Access_Constant
(Etype
(New_Type
)))
5033 Conformance_Error
("\return type does not match!", New_Id
);
5037 -- If either is a function/operator and the other isn't, error
5039 elsif Old_Type
/= Standard_Void_Type
5040 or else New_Type
/= Standard_Void_Type
5042 Conformance_Error
("\functions can only match functions!", New_Id
);
5046 -- In subtype conformant case, conventions must match (RM 6.3.1(16)).
5047 -- If this is a renaming as body, refine error message to indicate that
5048 -- the conflict is with the original declaration. If the entity is not
5049 -- frozen, the conventions don't have to match, the one of the renamed
5050 -- entity is inherited.
5052 if Ctype
>= Subtype_Conformant
then
5053 if not Conventions_Match
(Old_Id
, New_Id
) then
5054 if not Is_Frozen
(New_Id
) then
5057 elsif Present
(Err_Loc
)
5058 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
5059 and then Present
(Corresponding_Spec
(Err_Loc
))
5061 Error_Msg_Name_1
:= Chars
(New_Id
);
5063 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
5064 Conformance_Error
("\prior declaration for% has convention %!");
5067 Conformance_Error
("\calling conventions do not match!");
5072 elsif Is_Formal_Subprogram
(Old_Id
)
5073 or else Is_Formal_Subprogram
(New_Id
)
5075 Conformance_Error
("\formal subprograms not allowed!");
5080 -- Deal with parameters
5082 -- Note: we use the entity information, rather than going directly
5083 -- to the specification in the tree. This is not only simpler, but
5084 -- absolutely necessary for some cases of conformance tests between
5085 -- operators, where the declaration tree simply does not exist.
5087 Old_Formal
:= First_Formal
(Old_Id
);
5088 New_Formal
:= First_Formal
(New_Id
);
5089 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
5090 if Is_Controlling_Formal
(Old_Formal
)
5091 and then Is_Controlling_Formal
(New_Formal
)
5092 and then Skip_Controlling_Formals
5094 -- The controlling formals will have different types when
5095 -- comparing an interface operation with its match, but both
5096 -- or neither must be access parameters.
5098 if Is_Access_Type
(Etype
(Old_Formal
))
5100 Is_Access_Type
(Etype
(New_Formal
))
5102 goto Skip_Controlling_Formal
;
5105 ("\access parameter does not match!", New_Formal
);
5109 -- Ada 2012: Mode conformance also requires that formal parameters
5110 -- be both aliased, or neither.
5112 if Ctype
>= Mode_Conformant
and then Ada_Version
>= Ada_2012
then
5113 if Is_Aliased
(Old_Formal
) /= Is_Aliased
(New_Formal
) then
5115 ("\aliased parameter mismatch!", New_Formal
);
5119 if Ctype
= Fully_Conformant
then
5121 -- Names must match. Error message is more accurate if we do
5122 -- this before checking that the types of the formals match.
5124 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
5125 Conformance_Error
("\name& does not match!", New_Formal
);
5127 -- Set error posted flag on new formal as well to stop
5128 -- junk cascaded messages in some cases.
5130 Set_Error_Posted
(New_Formal
);
5134 -- Null exclusion must match
5136 if Null_Exclusion_Present
(Parent
(Old_Formal
))
5138 Null_Exclusion_Present
(Parent
(New_Formal
))
5140 -- Only give error if both come from source. This should be
5141 -- investigated some time, since it should not be needed ???
5143 if Comes_From_Source
(Old_Formal
)
5145 Comes_From_Source
(New_Formal
)
5148 ("\null exclusion for& does not match", New_Formal
);
5150 -- Mark error posted on the new formal to avoid duplicated
5151 -- complaint about types not matching.
5153 Set_Error_Posted
(New_Formal
);
5158 -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This
5159 -- case occurs whenever a subprogram is being renamed and one of its
5160 -- parameters imposes a null exclusion. For example:
5162 -- type T is null record;
5163 -- type Acc_T is access T;
5164 -- subtype Acc_T_Sub is Acc_T;
5166 -- procedure P (Obj : not null Acc_T_Sub); -- itype
5167 -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype
5170 Old_Formal_Base
:= Etype
(Old_Formal
);
5171 New_Formal_Base
:= Etype
(New_Formal
);
5174 Old_Formal_Base
:= Get_Instance_Of
(Old_Formal_Base
);
5175 New_Formal_Base
:= Get_Instance_Of
(New_Formal_Base
);
5178 Access_Types_Match
:= Ada_Version
>= Ada_2005
5180 -- Ensure that this rule is only applied when New_Id is a
5181 -- renaming of Old_Id.
5183 and then Nkind
(Parent
(Parent
(New_Id
))) =
5184 N_Subprogram_Renaming_Declaration
5185 and then Nkind
(Name
(Parent
(Parent
(New_Id
)))) in N_Has_Entity
5186 and then Present
(Entity
(Name
(Parent
(Parent
(New_Id
)))))
5187 and then Entity
(Name
(Parent
(Parent
(New_Id
)))) = Old_Id
5189 -- Now handle the allowed access-type case
5191 and then Is_Access_Type
(Old_Formal_Base
)
5192 and then Is_Access_Type
(New_Formal_Base
)
5194 -- The type kinds must match. The only exception occurs with
5195 -- multiple generics of the form:
5198 -- type F is private; type A is private;
5199 -- type F_Ptr is access F; type A_Ptr is access A;
5200 -- with proc F_P (X : F_Ptr); with proc A_P (X : A_Ptr);
5201 -- package F_Pack is ... package A_Pack is
5202 -- package F_Inst is
5203 -- new F_Pack (A, A_Ptr, A_P);
5205 -- When checking for conformance between the parameters of A_P
5206 -- and F_P, the type kinds of F_Ptr and A_Ptr will not match
5207 -- because the compiler has transformed A_Ptr into a subtype of
5208 -- F_Ptr. We catch this case in the code below.
5210 and then (Ekind
(Old_Formal_Base
) = Ekind
(New_Formal_Base
)
5212 (Is_Generic_Type
(Old_Formal_Base
)
5213 and then Is_Generic_Type
(New_Formal_Base
)
5214 and then Is_Internal
(New_Formal_Base
)
5215 and then Etype
(Etype
(New_Formal_Base
)) =
5217 and then Directly_Designated_Type
(Old_Formal_Base
) =
5218 Directly_Designated_Type
(New_Formal_Base
)
5219 and then ((Is_Itype
(Old_Formal_Base
)
5220 and then Can_Never_Be_Null
(Old_Formal_Base
))
5222 (Is_Itype
(New_Formal_Base
)
5223 and then Can_Never_Be_Null
(New_Formal_Base
)));
5225 -- Types must always match. In the visible part of an instance,
5226 -- usual overloading rules for dispatching operations apply, and
5227 -- we check base types (not the actual subtypes).
5229 if In_Instance_Visible_Part
5230 and then Is_Dispatching_Operation
(New_Id
)
5232 if not Conforming_Types
5233 (T1
=> Base_Type
(Etype
(Old_Formal
)),
5234 T2
=> Base_Type
(Etype
(New_Formal
)),
5236 Get_Inst
=> Get_Inst
)
5237 and then not Access_Types_Match
5239 Conformance_Error
("\type of & does not match!", New_Formal
);
5243 elsif not Conforming_Types
5244 (T1
=> Old_Formal_Base
,
5245 T2
=> New_Formal_Base
,
5247 Get_Inst
=> Get_Inst
)
5248 and then not Access_Types_Match
5250 -- Don't give error message if old type is Any_Type. This test
5251 -- avoids some cascaded errors, e.g. in case of a bad spec.
5253 if Errmsg
and then Old_Formal_Base
= Any_Type
then
5256 if Ctype
>= Subtype_Conformant
5258 not Predicates_Match
(Old_Formal_Base
, New_Formal_Base
)
5261 ("\predicate of & does not match!", New_Formal
);
5264 ("\type of & does not match!", New_Formal
);
5271 -- For mode conformance, mode must match
5273 if Ctype
>= Mode_Conformant
then
5274 if Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
) then
5275 if not Ekind_In
(New_Id
, E_Function
, E_Procedure
)
5276 or else not Is_Primitive_Wrapper
(New_Id
)
5278 Conformance_Error
("\mode of & does not match!", New_Formal
);
5282 T
: constant Entity_Id
:= Find_Dispatching_Type
(New_Id
);
5284 if Is_Protected_Type
(Corresponding_Concurrent_Type
(T
))
5286 Error_Msg_PT
(New_Id
, Ultimate_Alias
(Old_Id
));
5289 ("\mode of & does not match!", New_Formal
);
5296 -- Part of mode conformance for access types is having the same
5297 -- constant modifier.
5299 elsif Access_Types_Match
5300 and then Is_Access_Constant
(Old_Formal_Base
) /=
5301 Is_Access_Constant
(New_Formal_Base
)
5304 ("\constant modifier does not match!", New_Formal
);
5309 if Ctype
>= Subtype_Conformant
then
5311 -- Ada 2005 (AI-231): In case of anonymous access types check
5312 -- the null-exclusion and access-to-constant attributes must
5313 -- match. For null exclusion, we test the types rather than the
5314 -- formals themselves, since the attribute is only set reliably
5315 -- on the formals in the Ada 95 case, and we exclude the case
5316 -- where Old_Formal is marked as controlling, to avoid errors
5317 -- when matching completing bodies with dispatching declarations
5318 -- (access formals in the bodies aren't marked Can_Never_Be_Null).
5320 if Ada_Version
>= Ada_2005
5321 and then Ekind
(Etype
(Old_Formal
)) = E_Anonymous_Access_Type
5322 and then Ekind
(Etype
(New_Formal
)) = E_Anonymous_Access_Type
5324 ((Can_Never_Be_Null
(Etype
(Old_Formal
)) /=
5325 Can_Never_Be_Null
(Etype
(New_Formal
))
5327 not Is_Controlling_Formal
(Old_Formal
))
5329 Is_Access_Constant
(Etype
(Old_Formal
)) /=
5330 Is_Access_Constant
(Etype
(New_Formal
)))
5332 -- Do not complain if error already posted on New_Formal. This
5333 -- avoids some redundant error messages.
5335 and then not Error_Posted
(New_Formal
)
5337 -- It is allowed to omit the null-exclusion in case of stream
5338 -- attribute subprograms. We recognize stream subprograms
5339 -- through their TSS-generated suffix.
5342 TSS_Name
: constant TSS_Name_Type
:= Get_TSS_Name
(New_Id
);
5345 if TSS_Name
/= TSS_Stream_Read
5346 and then TSS_Name
/= TSS_Stream_Write
5347 and then TSS_Name
/= TSS_Stream_Input
5348 and then TSS_Name
/= TSS_Stream_Output
5350 -- Here we have a definite conformance error. It is worth
5351 -- special casing the error message for the case of a
5352 -- controlling formal (which excludes null).
5354 if Is_Controlling_Formal
(New_Formal
) then
5355 Error_Msg_Node_2
:= Scope
(New_Formal
);
5357 ("\controlling formal & of & excludes null, "
5358 & "declaration must exclude null as well",
5361 -- Normal case (couldn't we give more detail here???)
5365 ("\type of & does not match!", New_Formal
);
5374 -- Full conformance checks
5376 if Ctype
= Fully_Conformant
then
5378 -- We have checked already that names match
5380 if Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
5382 -- Check default expressions for in parameters
5385 NewD
: constant Boolean :=
5386 Present
(Default_Value
(New_Formal
));
5387 OldD
: constant Boolean :=
5388 Present
(Default_Value
(Old_Formal
));
5390 if NewD
or OldD
then
5392 -- The old default value has been analyzed because the
5393 -- current full declaration will have frozen everything
5394 -- before. The new default value has not been analyzed,
5395 -- so analyze it now before we check for conformance.
5398 Push_Scope
(New_Id
);
5399 Preanalyze_Spec_Expression
5400 (Default_Value
(New_Formal
), Etype
(New_Formal
));
5404 if not (NewD
and OldD
)
5405 or else not Fully_Conformant_Expressions
5406 (Default_Value
(Old_Formal
),
5407 Default_Value
(New_Formal
))
5410 ("\default expression for & does not match!",
5419 -- A couple of special checks for Ada 83 mode. These checks are
5420 -- skipped if either entity is an operator in package Standard,
5421 -- or if either old or new instance is not from the source program.
5423 if Ada_Version
= Ada_83
5424 and then Sloc
(Old_Id
) > Standard_Location
5425 and then Sloc
(New_Id
) > Standard_Location
5426 and then Comes_From_Source
(Old_Id
)
5427 and then Comes_From_Source
(New_Id
)
5430 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
5431 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
5434 -- Explicit IN must be present or absent in both cases. This
5435 -- test is required only in the full conformance case.
5437 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
5438 and then Ctype
= Fully_Conformant
5441 ("\(Ada 83) IN must appear in both declarations",
5446 -- Grouping (use of comma in param lists) must be the same
5447 -- This is where we catch a misconformance like:
5450 -- A : Integer; B : Integer
5452 -- which are represented identically in the tree except
5453 -- for the setting of the flags More_Ids and Prev_Ids.
5455 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
5456 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
5459 ("\grouping of & does not match!", New_Formal
);
5465 -- This label is required when skipping controlling formals
5467 <<Skip_Controlling_Formal
>>
5469 Next_Formal
(Old_Formal
);
5470 Next_Formal
(New_Formal
);
5473 if Present
(Old_Formal
) then
5474 Conformance_Error
("\too few parameters!");
5477 elsif Present
(New_Formal
) then
5478 Conformance_Error
("\too many parameters!", New_Formal
);
5481 end Check_Conformance
;
5483 -----------------------
5484 -- Check_Conventions --
5485 -----------------------
5487 procedure Check_Conventions
(Typ
: Entity_Id
) is
5488 Ifaces_List
: Elist_Id
;
5490 procedure Check_Convention
(Op
: Entity_Id
);
5491 -- Verify that the convention of inherited dispatching operation Op is
5492 -- consistent among all subprograms it overrides. In order to minimize
5493 -- the search, Search_From is utilized to designate a specific point in
5494 -- the list rather than iterating over the whole list once more.
5496 ----------------------
5497 -- Check_Convention --
5498 ----------------------
5500 procedure Check_Convention
(Op
: Entity_Id
) is
5501 Op_Conv
: constant Convention_Id
:= Convention
(Op
);
5502 Iface_Conv
: Convention_Id
;
5503 Iface_Elmt
: Elmt_Id
;
5504 Iface_Prim_Elmt
: Elmt_Id
;
5505 Iface_Prim
: Entity_Id
;
5508 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
5509 while Present
(Iface_Elmt
) loop
5511 First_Elmt
(Primitive_Operations
(Node
(Iface_Elmt
)));
5512 while Present
(Iface_Prim_Elmt
) loop
5513 Iface_Prim
:= Node
(Iface_Prim_Elmt
);
5514 Iface_Conv
:= Convention
(Iface_Prim
);
5516 if Is_Interface_Conformant
(Typ
, Iface_Prim
, Op
)
5517 and then Iface_Conv
/= Op_Conv
5520 ("inconsistent conventions in primitive operations", Typ
);
5522 Error_Msg_Name_1
:= Chars
(Op
);
5523 Error_Msg_Name_2
:= Get_Convention_Name
(Op_Conv
);
5524 Error_Msg_Sloc
:= Sloc
(Op
);
5526 if Comes_From_Source
(Op
) or else No
(Alias
(Op
)) then
5527 if not Present
(Overridden_Operation
(Op
)) then
5528 Error_Msg_N
("\\primitive % defined #", Typ
);
5531 ("\\overriding operation % with "
5532 & "convention % defined #", Typ
);
5535 else pragma Assert
(Present
(Alias
(Op
)));
5536 Error_Msg_Sloc
:= Sloc
(Alias
(Op
));
5537 Error_Msg_N
("\\inherited operation % with "
5538 & "convention % defined #", Typ
);
5541 Error_Msg_Name_1
:= Chars
(Op
);
5542 Error_Msg_Name_2
:= Get_Convention_Name
(Iface_Conv
);
5543 Error_Msg_Sloc
:= Sloc
(Iface_Prim
);
5544 Error_Msg_N
("\\overridden operation % with "
5545 & "convention % defined #", Typ
);
5547 -- Avoid cascading errors
5552 Next_Elmt
(Iface_Prim_Elmt
);
5555 Next_Elmt
(Iface_Elmt
);
5557 end Check_Convention
;
5561 Prim_Op
: Entity_Id
;
5562 Prim_Op_Elmt
: Elmt_Id
;
5564 -- Start of processing for Check_Conventions
5567 if not Has_Interfaces
(Typ
) then
5571 Collect_Interfaces
(Typ
, Ifaces_List
);
5573 -- The algorithm checks every overriding dispatching operation against
5574 -- all the corresponding overridden dispatching operations, detecting
5575 -- differences in conventions.
5577 Prim_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5578 while Present
(Prim_Op_Elmt
) loop
5579 Prim_Op
:= Node
(Prim_Op_Elmt
);
5581 -- A small optimization: skip the predefined dispatching operations
5582 -- since they always have the same convention.
5584 if not Is_Predefined_Dispatching_Operation
(Prim_Op
) then
5585 Check_Convention
(Prim_Op
);
5588 Next_Elmt
(Prim_Op_Elmt
);
5590 end Check_Conventions
;
5592 ------------------------------
5593 -- Check_Delayed_Subprogram --
5594 ------------------------------
5596 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
5599 procedure Possible_Freeze
(T
: Entity_Id
);
5600 -- T is the type of either a formal parameter or of the return type.
5601 -- If T is not yet frozen and needs a delayed freeze, then the
5602 -- subprogram itself must be delayed.
5604 ---------------------
5605 -- Possible_Freeze --
5606 ---------------------
5608 procedure Possible_Freeze
(T
: Entity_Id
) is
5610 if Has_Delayed_Freeze
(T
) and then not Is_Frozen
(T
) then
5611 Set_Has_Delayed_Freeze
(Designator
);
5613 elsif Is_Access_Type
(T
)
5614 and then Has_Delayed_Freeze
(Designated_Type
(T
))
5615 and then not Is_Frozen
(Designated_Type
(T
))
5617 Set_Has_Delayed_Freeze
(Designator
);
5620 end Possible_Freeze
;
5622 -- Start of processing for Check_Delayed_Subprogram
5625 -- All subprograms, including abstract subprograms, may need a freeze
5626 -- node if some formal type or the return type needs one.
5628 Possible_Freeze
(Etype
(Designator
));
5629 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
5631 -- Need delayed freeze if any of the formal types themselves need
5632 -- a delayed freeze and are not yet frozen.
5634 F
:= First_Formal
(Designator
);
5635 while Present
(F
) loop
5636 Possible_Freeze
(Etype
(F
));
5637 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
5641 -- Mark functions that return by reference. Note that it cannot be
5642 -- done for delayed_freeze subprograms because the underlying
5643 -- returned type may not be known yet (for private types)
5645 if not Has_Delayed_Freeze
(Designator
) and then Expander_Active
then
5647 Typ
: constant Entity_Id
:= Etype
(Designator
);
5648 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
5650 if Is_Limited_View
(Typ
) then
5651 Set_Returns_By_Ref
(Designator
);
5652 elsif Present
(Utyp
) and then CW_Or_Has_Controlled_Part
(Utyp
) then
5653 Set_Returns_By_Ref
(Designator
);
5657 end Check_Delayed_Subprogram
;
5659 ------------------------------------
5660 -- Check_Discriminant_Conformance --
5661 ------------------------------------
5663 procedure Check_Discriminant_Conformance
5668 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
5669 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
5670 New_Discr_Id
: Entity_Id
;
5671 New_Discr_Type
: Entity_Id
;
5673 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
5674 -- Post error message for conformance error on given node. Two messages
5675 -- are output. The first points to the previous declaration with a
5676 -- general "no conformance" message. The second is the detailed reason,
5677 -- supplied as Msg. The parameter N provide information for a possible
5678 -- & insertion in the message.
5680 -----------------------
5681 -- Conformance_Error --
5682 -----------------------
5684 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
5686 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
5687 Error_Msg_N
-- CODEFIX
5688 ("not fully conformant with declaration#!", N
);
5689 Error_Msg_NE
(Msg
, N
, N
);
5690 end Conformance_Error
;
5692 -- Start of processing for Check_Discriminant_Conformance
5695 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
5696 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
5698 -- The subtype mark of the discriminant on the full type has not
5699 -- been analyzed so we do it here. For an access discriminant a new
5702 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
5704 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
5707 Analyze
(Discriminant_Type
(New_Discr
));
5708 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
5710 -- Ada 2005: if the discriminant definition carries a null
5711 -- exclusion, create an itype to check properly for consistency
5712 -- with partial declaration.
5714 if Is_Access_Type
(New_Discr_Type
)
5715 and then Null_Exclusion_Present
(New_Discr
)
5718 Create_Null_Excluding_Itype
5719 (T
=> New_Discr_Type
,
5720 Related_Nod
=> New_Discr
,
5721 Scope_Id
=> Current_Scope
);
5725 if not Conforming_Types
5726 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
5728 Conformance_Error
("type of & does not match!", New_Discr_Id
);
5731 -- Treat the new discriminant as an occurrence of the old one,
5732 -- for navigation purposes, and fill in some semantic
5733 -- information, for completeness.
5735 Generate_Reference
(Old_Discr
, New_Discr_Id
, 'r');
5736 Set_Etype
(New_Discr_Id
, Etype
(Old_Discr
));
5737 Set_Scope
(New_Discr_Id
, Scope
(Old_Discr
));
5742 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
5743 Conformance_Error
("name & does not match!", New_Discr_Id
);
5747 -- Default expressions must match
5750 NewD
: constant Boolean :=
5751 Present
(Expression
(New_Discr
));
5752 OldD
: constant Boolean :=
5753 Present
(Expression
(Parent
(Old_Discr
)));
5756 if NewD
or OldD
then
5758 -- The old default value has been analyzed and expanded,
5759 -- because the current full declaration will have frozen
5760 -- everything before. The new default values have not been
5761 -- expanded, so expand now to check conformance.
5764 Preanalyze_Spec_Expression
5765 (Expression
(New_Discr
), New_Discr_Type
);
5768 if not (NewD
and OldD
)
5769 or else not Fully_Conformant_Expressions
5770 (Expression
(Parent
(Old_Discr
)),
5771 Expression
(New_Discr
))
5775 ("default expression for & does not match!",
5782 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
5784 if Ada_Version
= Ada_83
then
5786 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
5789 -- Grouping (use of comma in param lists) must be the same
5790 -- This is where we catch a misconformance like:
5793 -- A : Integer; B : Integer
5795 -- which are represented identically in the tree except
5796 -- for the setting of the flags More_Ids and Prev_Ids.
5798 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
5799 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
5802 ("grouping of & does not match!", New_Discr_Id
);
5808 Next_Discriminant
(Old_Discr
);
5812 if Present
(Old_Discr
) then
5813 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
5816 elsif Present
(New_Discr
) then
5818 ("too many discriminants!", Defining_Identifier
(New_Discr
));
5821 end Check_Discriminant_Conformance
;
5823 ----------------------------
5824 -- Check_Fully_Conformant --
5825 ----------------------------
5827 procedure Check_Fully_Conformant
5828 (New_Id
: Entity_Id
;
5830 Err_Loc
: Node_Id
:= Empty
)
5833 pragma Warnings
(Off
, Result
);
5836 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
5837 end Check_Fully_Conformant
;
5839 --------------------------
5840 -- Check_Limited_Return --
5841 --------------------------
5843 procedure Check_Limited_Return
5849 -- Ada 2005 (AI-318-02): Return-by-reference types have been removed and
5850 -- replaced by anonymous access results. This is an incompatibility with
5851 -- Ada 95. Not clear whether this should be enforced yet or perhaps
5852 -- controllable with special switch. ???
5854 -- A limited interface that is not immutably limited is OK
5856 if Is_Limited_Interface
(R_Type
)
5858 not (Is_Task_Interface
(R_Type
)
5859 or else Is_Protected_Interface
(R_Type
)
5860 or else Is_Synchronized_Interface
(R_Type
))
5864 elsif Is_Limited_Type
(R_Type
)
5865 and then not Is_Interface
(R_Type
)
5866 and then Comes_From_Source
(N
)
5867 and then not In_Instance_Body
5868 and then not OK_For_Limited_Init_In_05
(R_Type
, Expr
)
5870 -- Error in Ada 2005
5872 if Ada_Version
>= Ada_2005
5873 and then not Debug_Flag_Dot_L
5874 and then not GNAT_Mode
5877 ("(Ada 2005) cannot copy object of a limited type "
5878 & "(RM-2005 6.5(5.5/2))", Expr
);
5880 if Is_Limited_View
(R_Type
) then
5882 ("\return by reference not permitted in Ada 2005", Expr
);
5885 -- Warn in Ada 95 mode, to give folks a heads up about this
5888 -- In GNAT mode, this is just a warning, to allow it to be evilly
5889 -- turned off. Otherwise it is a real error.
5891 -- In a generic context, simplify the warning because it makes no
5892 -- sense to discuss pass-by-reference or copy.
5894 elsif Warn_On_Ada_2005_Compatibility
or GNAT_Mode
then
5895 if Inside_A_Generic
then
5897 ("return of limited object not permitted in Ada 2005 "
5898 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
5900 elsif Is_Limited_View
(R_Type
) then
5902 ("return by reference not permitted in Ada 2005 "
5903 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
5906 ("cannot copy object of a limited type in Ada 2005 "
5907 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
5910 -- Ada 95 mode, compatibility warnings disabled
5913 return; -- skip continuation messages below
5916 if not Inside_A_Generic
then
5918 ("\consider switching to return of access type", Expr
);
5919 Explain_Limited_Type
(R_Type
, Expr
);
5922 end Check_Limited_Return
;
5924 ---------------------------
5925 -- Check_Mode_Conformant --
5926 ---------------------------
5928 procedure Check_Mode_Conformant
5929 (New_Id
: Entity_Id
;
5931 Err_Loc
: Node_Id
:= Empty
;
5932 Get_Inst
: Boolean := False)
5935 pragma Warnings
(Off
, Result
);
5938 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
5939 end Check_Mode_Conformant
;
5941 --------------------------------
5942 -- Check_Overriding_Indicator --
5943 --------------------------------
5945 procedure Check_Overriding_Indicator
5947 Overridden_Subp
: Entity_Id
;
5948 Is_Primitive
: Boolean)
5954 -- No overriding indicator for literals
5956 if Ekind
(Subp
) = E_Enumeration_Literal
then
5959 elsif Ekind
(Subp
) = E_Entry
then
5960 Decl
:= Parent
(Subp
);
5962 -- No point in analyzing a malformed operator
5964 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
5965 and then Error_Posted
(Subp
)
5970 Decl
:= Unit_Declaration_Node
(Subp
);
5973 if Nkind_In
(Decl
, N_Subprogram_Body
,
5974 N_Subprogram_Body_Stub
,
5975 N_Subprogram_Declaration
,
5976 N_Abstract_Subprogram_Declaration
,
5977 N_Subprogram_Renaming_Declaration
)
5979 Spec
:= Specification
(Decl
);
5981 elsif Nkind
(Decl
) = N_Entry_Declaration
then
5988 -- The overriding operation is type conformant with the overridden one,
5989 -- but the names of the formals are not required to match. If the names
5990 -- appear permuted in the overriding operation, this is a possible
5991 -- source of confusion that is worth diagnosing. Controlling formals
5992 -- often carry names that reflect the type, and it is not worthwhile
5993 -- requiring that their names match.
5995 if Present
(Overridden_Subp
)
5996 and then Nkind
(Subp
) /= N_Defining_Operator_Symbol
6003 Form1
:= First_Formal
(Subp
);
6004 Form2
:= First_Formal
(Overridden_Subp
);
6006 -- If the overriding operation is a synchronized operation, skip
6007 -- the first parameter of the overridden operation, which is
6008 -- implicit in the new one. If the operation is declared in the
6009 -- body it is not primitive and all formals must match.
6011 if Is_Concurrent_Type
(Scope
(Subp
))
6012 and then Is_Tagged_Type
(Scope
(Subp
))
6013 and then not Has_Completion
(Scope
(Subp
))
6015 Form2
:= Next_Formal
(Form2
);
6018 if Present
(Form1
) then
6019 Form1
:= Next_Formal
(Form1
);
6020 Form2
:= Next_Formal
(Form2
);
6023 while Present
(Form1
) loop
6024 if not Is_Controlling_Formal
(Form1
)
6025 and then Present
(Next_Formal
(Form2
))
6026 and then Chars
(Form1
) = Chars
(Next_Formal
(Form2
))
6028 Error_Msg_Node_2
:= Alias
(Overridden_Subp
);
6029 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
6031 ("& does not match corresponding formal of&#",
6036 Next_Formal
(Form1
);
6037 Next_Formal
(Form2
);
6042 -- If there is an overridden subprogram, then check that there is no
6043 -- "not overriding" indicator, and mark the subprogram as overriding.
6044 -- This is not done if the overridden subprogram is marked as hidden,
6045 -- which can occur for the case of inherited controlled operations
6046 -- (see Derive_Subprogram), unless the inherited subprogram's parent
6047 -- subprogram is not itself hidden. (Note: This condition could probably
6048 -- be simplified, leaving out the testing for the specific controlled
6049 -- cases, but it seems safer and clearer this way, and echoes similar
6050 -- special-case tests of this kind in other places.)
6052 if Present
(Overridden_Subp
)
6053 and then (not Is_Hidden
(Overridden_Subp
)
6055 (Nam_In
(Chars
(Overridden_Subp
), Name_Initialize
,
6058 and then Present
(Alias
(Overridden_Subp
))
6059 and then not Is_Hidden
(Alias
(Overridden_Subp
))))
6061 if Must_Not_Override
(Spec
) then
6062 Error_Msg_Sloc
:= Sloc
(Overridden_Subp
);
6064 if Ekind
(Subp
) = E_Entry
then
6066 ("entry & overrides inherited operation #", Spec
, Subp
);
6069 ("subprogram & overrides inherited operation #", Spec
, Subp
);
6072 -- Special-case to fix a GNAT oddity: Limited_Controlled is declared
6073 -- as an extension of Root_Controlled, and thus has a useless Adjust
6074 -- operation. This operation should not be inherited by other limited
6075 -- controlled types. An explicit Adjust for them is not overriding.
6077 elsif Must_Override
(Spec
)
6078 and then Chars
(Overridden_Subp
) = Name_Adjust
6079 and then Is_Limited_Type
(Etype
(First_Formal
(Subp
)))
6080 and then Present
(Alias
(Overridden_Subp
))
6082 Is_Predefined_File_Name
6083 (Unit_File_Name
(Get_Source_Unit
(Alias
(Overridden_Subp
))))
6085 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6087 elsif Is_Subprogram
(Subp
) then
6088 if Is_Init_Proc
(Subp
) then
6091 elsif No
(Overridden_Operation
(Subp
)) then
6093 -- For entities generated by Derive_Subprograms the overridden
6094 -- operation is the inherited primitive (which is available
6095 -- through the attribute alias)
6097 if (Is_Dispatching_Operation
(Subp
)
6098 or else Is_Dispatching_Operation
(Overridden_Subp
))
6099 and then not Comes_From_Source
(Overridden_Subp
)
6100 and then Find_Dispatching_Type
(Overridden_Subp
) =
6101 Find_Dispatching_Type
(Subp
)
6102 and then Present
(Alias
(Overridden_Subp
))
6103 and then Comes_From_Source
(Alias
(Overridden_Subp
))
6105 Set_Overridden_Operation
(Subp
, Alias
(Overridden_Subp
));
6106 Inherit_Subprogram_Contract
(Subp
, Alias
(Overridden_Subp
));
6109 Set_Overridden_Operation
(Subp
, Overridden_Subp
);
6110 Inherit_Subprogram_Contract
(Subp
, Overridden_Subp
);
6115 -- If primitive flag is set or this is a protected operation, then
6116 -- the operation is overriding at the point of its declaration, so
6117 -- warn if necessary. Otherwise it may have been declared before the
6118 -- operation it overrides and no check is required.
6121 and then not Must_Override
(Spec
)
6122 and then (Is_Primitive
6123 or else Ekind
(Scope
(Subp
)) = E_Protected_Type
)
6125 Style
.Missing_Overriding
(Decl
, Subp
);
6128 -- If Subp is an operator, it may override a predefined operation, if
6129 -- it is defined in the same scope as the type to which it applies.
6130 -- In that case Overridden_Subp is empty because of our implicit
6131 -- representation for predefined operators. We have to check whether the
6132 -- signature of Subp matches that of a predefined operator. Note that
6133 -- first argument provides the name of the operator, and the second
6134 -- argument the signature that may match that of a standard operation.
6135 -- If the indicator is overriding, then the operator must match a
6136 -- predefined signature, because we know already that there is no
6137 -- explicit overridden operation.
6139 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
then
6140 if Must_Not_Override
(Spec
) then
6142 -- If this is not a primitive or a protected subprogram, then
6143 -- "not overriding" is illegal.
6146 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
6148 Error_Msg_N
("overriding indicator only allowed "
6149 & "if subprogram is primitive", Subp
);
6151 elsif Can_Override_Operator
(Subp
) then
6153 ("subprogram& overrides predefined operator ", Spec
, Subp
);
6156 elsif Must_Override
(Spec
) then
6157 if No
(Overridden_Operation
(Subp
))
6158 and then not Can_Override_Operator
(Subp
)
6160 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6163 elsif not Error_Posted
(Subp
)
6164 and then Style_Check
6165 and then Can_Override_Operator
(Subp
)
6167 not Is_Predefined_File_Name
6168 (Unit_File_Name
(Get_Source_Unit
(Subp
)))
6170 -- If style checks are enabled, indicate that the indicator is
6171 -- missing. However, at the point of declaration, the type of
6172 -- which this is a primitive operation may be private, in which
6173 -- case the indicator would be premature.
6175 if Has_Private_Declaration
(Etype
(Subp
))
6176 or else Has_Private_Declaration
(Etype
(First_Formal
(Subp
)))
6180 Style
.Missing_Overriding
(Decl
, Subp
);
6184 elsif Must_Override
(Spec
) then
6185 if Ekind
(Subp
) = E_Entry
then
6186 Error_Msg_NE
("entry & is not overriding", Spec
, Subp
);
6188 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6191 -- If the operation is marked "not overriding" and it's not primitive
6192 -- then an error is issued, unless this is an operation of a task or
6193 -- protected type (RM05-8.3.1(3/2-4/2)). Error cases where "overriding"
6194 -- has been specified have already been checked above.
6196 elsif Must_Not_Override
(Spec
)
6197 and then not Is_Primitive
6198 and then Ekind
(Subp
) /= E_Entry
6199 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
6202 ("overriding indicator only allowed if subprogram is primitive",
6206 end Check_Overriding_Indicator
;
6212 -- Note: this procedure needs to know far too much about how the expander
6213 -- messes with exceptions. The use of the flag Exception_Junk and the
6214 -- incorporation of knowledge of Exp_Ch11.Expand_Local_Exception_Handlers
6215 -- works, but is not very clean. It would be better if the expansion
6216 -- routines would leave Original_Node working nicely, and we could use
6217 -- Original_Node here to ignore all the peculiar expander messing ???
6219 procedure Check_Returns
6223 Proc
: Entity_Id
:= Empty
)
6227 procedure Check_Statement_Sequence
(L
: List_Id
);
6228 -- Internal recursive procedure to check a list of statements for proper
6229 -- termination by a return statement (or a transfer of control or a
6230 -- compound statement that is itself internally properly terminated).
6232 ------------------------------
6233 -- Check_Statement_Sequence --
6234 ------------------------------
6236 procedure Check_Statement_Sequence
(L
: List_Id
) is
6241 function Assert_False
return Boolean;
6242 -- Returns True if Last_Stm is a pragma Assert (False) that has been
6243 -- rewritten as a null statement when assertions are off. The assert
6244 -- is not active, but it is still enough to kill the warning.
6250 function Assert_False
return Boolean is
6251 Orig
: constant Node_Id
:= Original_Node
(Last_Stm
);
6254 if Nkind
(Orig
) = N_Pragma
6255 and then Pragma_Name
(Orig
) = Name_Assert
6256 and then not Error_Posted
(Orig
)
6259 Arg
: constant Node_Id
:=
6260 First
(Pragma_Argument_Associations
(Orig
));
6261 Exp
: constant Node_Id
:= Expression
(Arg
);
6263 return Nkind
(Exp
) = N_Identifier
6264 and then Chars
(Exp
) = Name_False
;
6274 Raise_Exception_Call
: Boolean;
6275 -- Set True if statement sequence terminated by Raise_Exception call
6276 -- or a Reraise_Occurrence call.
6278 -- Start of processing for Check_Statement_Sequence
6281 Raise_Exception_Call
:= False;
6283 -- Get last real statement
6285 Last_Stm
:= Last
(L
);
6287 -- Deal with digging out exception handler statement sequences that
6288 -- have been transformed by the local raise to goto optimization.
6289 -- See Exp_Ch11.Expand_Local_Exception_Handlers for details. If this
6290 -- optimization has occurred, we are looking at something like:
6293 -- original stmts in block
6297 -- goto L1; | omitted if No_Exception_Propagation
6302 -- goto L3; -- skip handler when exception not raised
6304 -- <<L1>> -- target label for local exception
6318 -- and what we have to do is to dig out the estmts1 and estmts2
6319 -- sequences (which were the original sequences of statements in
6320 -- the exception handlers) and check them.
6322 if Nkind
(Last_Stm
) = N_Label
and then Exception_Junk
(Last_Stm
) then
6327 exit when Nkind
(Stm
) /= N_Block_Statement
;
6328 exit when not Exception_Junk
(Stm
);
6331 exit when Nkind
(Stm
) /= N_Label
;
6332 exit when not Exception_Junk
(Stm
);
6333 Check_Statement_Sequence
6334 (Statements
(Handled_Statement_Sequence
(Next
(Stm
))));
6339 exit when Nkind
(Stm
) /= N_Goto_Statement
;
6340 exit when not Exception_Junk
(Stm
);
6344 -- Don't count pragmas
6346 while Nkind
(Last_Stm
) = N_Pragma
6348 -- Don't count call to SS_Release (can happen after Raise_Exception)
6351 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
6353 Nkind
(Name
(Last_Stm
)) = N_Identifier
6355 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
6357 -- Don't count exception junk
6360 (Nkind_In
(Last_Stm
, N_Goto_Statement
,
6362 N_Object_Declaration
)
6363 and then Exception_Junk
(Last_Stm
))
6364 or else Nkind
(Last_Stm
) in N_Push_xxx_Label
6365 or else Nkind
(Last_Stm
) in N_Pop_xxx_Label
6367 -- Inserted code, such as finalization calls, is irrelevant: we only
6368 -- need to check original source.
6370 or else Is_Rewrite_Insertion
(Last_Stm
)
6375 -- Here we have the "real" last statement
6377 Kind
:= Nkind
(Last_Stm
);
6379 -- Transfer of control, OK. Note that in the No_Return procedure
6380 -- case, we already diagnosed any explicit return statements, so
6381 -- we can treat them as OK in this context.
6383 if Is_Transfer
(Last_Stm
) then
6386 -- Check cases of explicit non-indirect procedure calls
6388 elsif Kind
= N_Procedure_Call_Statement
6389 and then Is_Entity_Name
(Name
(Last_Stm
))
6391 -- Check call to Raise_Exception procedure which is treated
6392 -- specially, as is a call to Reraise_Occurrence.
6394 -- We suppress the warning in these cases since it is likely that
6395 -- the programmer really does not expect to deal with the case
6396 -- of Null_Occurrence, and thus would find a warning about a
6397 -- missing return curious, and raising Program_Error does not
6398 -- seem such a bad behavior if this does occur.
6400 -- Note that in the Ada 2005 case for Raise_Exception, the actual
6401 -- behavior will be to raise Constraint_Error (see AI-329).
6403 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
6405 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
6407 Raise_Exception_Call
:= True;
6409 -- For Raise_Exception call, test first argument, if it is
6410 -- an attribute reference for a 'Identity call, then we know
6411 -- that the call cannot possibly return.
6414 Arg
: constant Node_Id
:=
6415 Original_Node
(First_Actual
(Last_Stm
));
6417 if Nkind
(Arg
) = N_Attribute_Reference
6418 and then Attribute_Name
(Arg
) = Name_Identity
6425 -- If statement, need to look inside if there is an else and check
6426 -- each constituent statement sequence for proper termination.
6428 elsif Kind
= N_If_Statement
6429 and then Present
(Else_Statements
(Last_Stm
))
6431 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
6432 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
6434 if Present
(Elsif_Parts
(Last_Stm
)) then
6436 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
6439 while Present
(Elsif_Part
) loop
6440 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
6448 -- Case statement, check each case for proper termination
6450 elsif Kind
= N_Case_Statement
then
6454 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
6455 while Present
(Case_Alt
) loop
6456 Check_Statement_Sequence
(Statements
(Case_Alt
));
6457 Next_Non_Pragma
(Case_Alt
);
6463 -- Block statement, check its handled sequence of statements
6465 elsif Kind
= N_Block_Statement
then
6471 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
6480 -- Loop statement. If there is an iteration scheme, we can definitely
6481 -- fall out of the loop. Similarly if there is an exit statement, we
6482 -- can fall out. In either case we need a following return.
6484 elsif Kind
= N_Loop_Statement
then
6485 if Present
(Iteration_Scheme
(Last_Stm
))
6486 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
6490 -- A loop with no exit statement or iteration scheme is either
6491 -- an infinite loop, or it has some other exit (raise/return).
6492 -- In either case, no warning is required.
6498 -- Timed entry call, check entry call and delay alternatives
6500 -- Note: in expanded code, the timed entry call has been converted
6501 -- to a set of expanded statements on which the check will work
6502 -- correctly in any case.
6504 elsif Kind
= N_Timed_Entry_Call
then
6506 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
6507 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
6510 -- If statement sequence of entry call alternative is missing,
6511 -- then we can definitely fall through, and we post the error
6512 -- message on the entry call alternative itself.
6514 if No
(Statements
(ECA
)) then
6517 -- If statement sequence of delay alternative is missing, then
6518 -- we can definitely fall through, and we post the error
6519 -- message on the delay alternative itself.
6521 -- Note: if both ECA and DCA are missing the return, then we
6522 -- post only one message, should be enough to fix the bugs.
6523 -- If not we will get a message next time on the DCA when the
6526 elsif No
(Statements
(DCA
)) then
6529 -- Else check both statement sequences
6532 Check_Statement_Sequence
(Statements
(ECA
));
6533 Check_Statement_Sequence
(Statements
(DCA
));
6538 -- Conditional entry call, check entry call and else part
6540 -- Note: in expanded code, the conditional entry call has been
6541 -- converted to a set of expanded statements on which the check
6542 -- will work correctly in any case.
6544 elsif Kind
= N_Conditional_Entry_Call
then
6546 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
6549 -- If statement sequence of entry call alternative is missing,
6550 -- then we can definitely fall through, and we post the error
6551 -- message on the entry call alternative itself.
6553 if No
(Statements
(ECA
)) then
6556 -- Else check statement sequence and else part
6559 Check_Statement_Sequence
(Statements
(ECA
));
6560 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
6566 -- If we fall through, issue appropriate message
6570 -- Kill warning if last statement is a raise exception call,
6571 -- or a pragma Assert (False). Note that with assertions enabled,
6572 -- such a pragma has been converted into a raise exception call
6573 -- already, so the Assert_False is for the assertions off case.
6575 if not Raise_Exception_Call
and then not Assert_False
then
6577 -- In GNATprove mode, it is an error to have a missing return
6579 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6581 -- Issue error message or warning
6584 ("RETURN statement missing following this statement<<!",
6587 ("\Program_Error ]<<!", Last_Stm
);
6590 -- Note: we set Err even though we have not issued a warning
6591 -- because we still have a case of a missing return. This is
6592 -- an extremely marginal case, probably will never be noticed
6593 -- but we might as well get it right.
6597 -- Otherwise we have the case of a procedure marked No_Return
6600 if not Raise_Exception_Call
then
6601 if GNATprove_Mode
then
6603 ("implied return after this statement "
6604 & "would have raised Program_Error", Last_Stm
);
6607 ("implied return after this statement "
6608 & "will raise Program_Error??", Last_Stm
);
6611 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6613 ("\procedure & is marked as No_Return<<!", Last_Stm
, Proc
);
6617 RE
: constant Node_Id
:=
6618 Make_Raise_Program_Error
(Sloc
(Last_Stm
),
6619 Reason
=> PE_Implicit_Return
);
6621 Insert_After
(Last_Stm
, RE
);
6625 end Check_Statement_Sequence
;
6627 -- Start of processing for Check_Returns
6631 Check_Statement_Sequence
(Statements
(HSS
));
6633 if Present
(Exception_Handlers
(HSS
)) then
6634 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
6635 while Present
(Handler
) loop
6636 Check_Statement_Sequence
(Statements
(Handler
));
6637 Next_Non_Pragma
(Handler
);
6642 ----------------------------
6643 -- Check_Subprogram_Order --
6644 ----------------------------
6646 procedure Check_Subprogram_Order
(N
: Node_Id
) is
6648 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
6649 -- This is used to check if S1 > S2 in the sense required by this test,
6650 -- for example nameab < namec, but name2 < name10.
6652 -----------------------------
6653 -- Subprogram_Name_Greater --
6654 -----------------------------
6656 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
6661 -- Deal with special case where names are identical except for a
6662 -- numerical suffix. These are handled specially, taking the numeric
6663 -- ordering from the suffix into account.
6666 while S1
(L1
) in '0' .. '9' loop
6671 while S2
(L2
) in '0' .. '9' loop
6675 -- If non-numeric parts non-equal, do straight compare
6677 if S1
(S1
'First .. L1
) /= S2
(S2
'First .. L2
) then
6680 -- If non-numeric parts equal, compare suffixed numeric parts. Note
6681 -- that a missing suffix is treated as numeric zero in this test.
6685 while L1
< S1
'Last loop
6687 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
6691 while L2
< S2
'Last loop
6693 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
6698 end Subprogram_Name_Greater
;
6700 -- Start of processing for Check_Subprogram_Order
6703 -- Check body in alpha order if this is option
6706 and then Style_Check_Order_Subprograms
6707 and then Nkind
(N
) = N_Subprogram_Body
6708 and then Comes_From_Source
(N
)
6709 and then In_Extended_Main_Source_Unit
(N
)
6713 renames Scope_Stack
.Table
6714 (Scope_Stack
.Last
).Last_Subprogram_Name
;
6716 Body_Id
: constant Entity_Id
:=
6717 Defining_Entity
(Specification
(N
));
6720 Get_Decoded_Name_String
(Chars
(Body_Id
));
6723 if Subprogram_Name_Greater
6724 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
6726 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
6732 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
6735 end Check_Subprogram_Order;
6737 ------------------------------
6738 -- Check_Subtype_Conformant --
6739 ------------------------------
6741 procedure Check_Subtype_Conformant
6742 (New_Id : Entity_Id;
6744 Err_Loc : Node_Id := Empty;
6745 Skip_Controlling_Formals : Boolean := False;
6746 Get_Inst : Boolean := False)
6749 pragma Warnings (Off, Result);
6752 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc,
6753 Skip_Controlling_Formals => Skip_Controlling_Formals,
6754 Get_Inst => Get_Inst);
6755 end Check_Subtype_Conformant;
6757 -----------------------------------
6758 -- Check_Synchronized_Overriding --
6759 -----------------------------------
6761 procedure Check_Synchronized_Overriding
6762 (Def_Id : Entity_Id;
6763 Overridden_Subp : out Entity_Id)
6765 Ifaces_List : Elist_Id;
6769 function Matches_Prefixed_View_Profile
6770 (Prim_Params : List_Id;
6771 Iface_Params : List_Id) return Boolean;
6772 -- Determine whether a subprogram's parameter profile Prim_Params
6773 -- matches that of a potentially overridden interface subprogram
6774 -- Iface_Params. Also determine if the type of first parameter of
6775 -- Iface_Params is an implemented interface.
6777 -----------------------------------
6778 -- Matches_Prefixed_View_Profile --
6779 -----------------------------------
6781 function Matches_Prefixed_View_Profile
6782 (Prim_Params : List_Id;
6783 Iface_Params : List_Id) return Boolean
6785 function Is_Implemented
6786 (Ifaces_List : Elist_Id;
6787 Iface : Entity_Id) return Boolean;
6788 -- Determine if Iface is implemented by the current task or
6791 --------------------
6792 -- Is_Implemented --
6793 --------------------
6795 function Is_Implemented
6796 (Ifaces_List : Elist_Id;
6797 Iface : Entity_Id) return Boolean
6799 Iface_Elmt : Elmt_Id;
6802 Iface_Elmt := First_Elmt (Ifaces_List);
6803 while Present (Iface_Elmt) loop
6804 if Node (Iface_Elmt) = Iface then
6808 Next_Elmt (Iface_Elmt);
6816 Iface_Id : Entity_Id;
6817 Iface_Param : Node_Id;
6818 Iface_Typ : Entity_Id;
6819 Prim_Id : Entity_Id;
6820 Prim_Param : Node_Id;
6821 Prim_Typ : Entity_Id;
6823 -- Start of processing for Matches_Prefixed_View_Profile
6826 Iface_Param := First (Iface_Params);
6827 Iface_Typ := Etype (Defining_Identifier (Iface_Param));
6829 if Is_Access_Type (Iface_Typ) then
6830 Iface_Typ := Designated_Type (Iface_Typ);
6833 Prim_Param := First (Prim_Params);
6835 -- The first parameter of the potentially overridden subprogram must
6836 -- be an interface implemented by Prim.
6838 if not Is_Interface (Iface_Typ)
6839 or else not Is_Implemented (Ifaces_List, Iface_Typ)
6844 -- The checks on the object parameters are done, so move on to the
6845 -- rest of the parameters.
6847 if not In_Scope then
6848 Prim_Param := Next (Prim_Param);
6851 Iface_Param := Next (Iface_Param);
6852 while Present (Iface_Param) and then Present (Prim_Param) loop
6853 Iface_Id := Defining_Identifier (Iface_Param);
6854 Iface_Typ := Find_Parameter_Type (Iface_Param);
6856 Prim_Id := Defining_Identifier (Prim_Param);
6857 Prim_Typ := Find_Parameter_Type (Prim_Param);
6859 if Ekind (Iface_Typ) = E_Anonymous_Access_Type
6860 and then Ekind (Prim_Typ) = E_Anonymous_Access_Type
6861 and then Is_Concurrent_Type (Designated_Type (Prim_Typ))
6863 Iface_Typ := Designated_Type (Iface_Typ);
6864 Prim_Typ := Designated_Type (Prim_Typ);
6867 -- Case of multiple interface types inside a parameter profile
6869 -- (Obj_Param : in out Iface; ...; Param : Iface)
6871 -- If the interface type is implemented, then the matching type in
6872 -- the primitive should be the implementing record type.
6874 if Ekind (Iface_Typ) = E_Record_Type
6875 and then Is_Interface (Iface_Typ)
6876 and then Is_Implemented (Ifaces_List, Iface_Typ)
6878 if Prim_Typ /= Typ then
6882 -- The two parameters must be both mode and subtype conformant
6884 elsif Ekind (Iface_Id) /= Ekind (Prim_Id)
6886 Conforming_Types (Iface_Typ, Prim_Typ, Subtype_Conformant)
6895 -- One of the two lists contains more parameters than the other
6897 if Present (Iface_Param) or else Present (Prim_Param) then
6902 end Matches_Prefixed_View_Profile;
6904 -- Start of processing for Check_Synchronized_Overriding
6907 Overridden_Subp := Empty;
6909 -- Def_Id must be an entry or a subprogram. We should skip predefined
6910 -- primitives internally generated by the front end; however at this
6911 -- stage predefined primitives are still not fully decorated. As a
6912 -- minor optimization we skip here internally generated subprograms.
6914 if (Ekind (Def_Id) /= E_Entry
6915 and then Ekind (Def_Id) /= E_Function
6916 and then Ekind (Def_Id) /= E_Procedure)
6917 or else not Comes_From_Source (Def_Id)
6922 -- Search for the concurrent declaration since it contains the list of
6923 -- all implemented interfaces. In this case, the subprogram is declared
6924 -- within the scope of a protected or a task type.
6926 if Present (Scope (Def_Id))
6927 and then Is_Concurrent_Type (Scope (Def_Id))
6928 and then not Is_Generic_Actual_Type (Scope (Def_Id))
6930 Typ := Scope (Def_Id);
6933 -- The enclosing scope is not a synchronized type and the subprogram
6936 elsif No (First_Formal (Def_Id)) then
6939 -- The subprogram has formals and hence it may be a primitive of a
6943 Typ := Etype (First_Formal (Def_Id));
6945 if Is_Access_Type (Typ) then
6946 Typ := Directly_Designated_Type (Typ);
6949 if Is_Concurrent_Type (Typ)
6950 and then not Is_Generic_Actual_Type (Typ)
6954 -- This case occurs when the concurrent type is declared within a
6955 -- generic unit. As a result the corresponding record has been built
6956 -- and used as the type of the first formal, we just have to retrieve
6957 -- the corresponding concurrent type.
6959 elsif Is_Concurrent_Record_Type (Typ)
6960 and then not Is_Class_Wide_Type (Typ)
6961 and then Present (Corresponding_Concurrent_Type (Typ))
6963 Typ := Corresponding_Concurrent_Type (Typ);
6971 -- There is no overriding to check if this is an inherited operation in
6972 -- a type derivation for a generic actual.
6974 Collect_Interfaces (Typ, Ifaces_List);
6976 if Is_Empty_Elmt_List (Ifaces_List) then
6980 -- Determine whether entry or subprogram Def_Id overrides a primitive
6981 -- operation that belongs to one of the interfaces in Ifaces_List.
6984 Candidate : Entity_Id := Empty;
6985 Hom : Entity_Id := Empty;
6986 Subp : Entity_Id := Empty;
6989 -- Traverse the homonym chain, looking for a potentially overridden
6990 -- subprogram that belongs to an implemented interface.
6992 Hom := Current_Entity_In_Scope (Def_Id);
6993 while Present (Hom) loop
6997 or else not Is_Overloadable (Subp)
6998 or else not Is_Primitive (Subp)
6999 or else not Is_Dispatching_Operation (Subp)
7000 or else not Present (Find_Dispatching_Type (Subp))
7001 or else not Is_Interface (Find_Dispatching_Type (Subp))
7005 -- Entries and procedures can override abstract or null interface
7008 elsif Ekind_In (Def_Id, E_Entry, E_Procedure)
7009 and then Ekind (Subp) = E_Procedure
7010 and then Matches_Prefixed_View_Profile
7011 (Parameter_Specifications (Parent (Def_Id)),
7012 Parameter_Specifications (Parent (Subp)))
7016 -- For an overridden subprogram Subp, check whether the mode
7017 -- of its first parameter is correct depending on the kind of
7018 -- synchronized type.
7021 Formal : constant Node_Id := First_Formal (Candidate);
7024 -- In order for an entry or a protected procedure to
7025 -- override, the first parameter of the overridden routine
7026 -- must be of mode "out", "in out", or access-to-variable.
7028 if Ekind_In (Candidate, E_Entry, E_Procedure)
7029 and then Is_Protected_Type (Typ)
7030 and then Ekind (Formal) /= E_In_Out_Parameter
7031 and then Ekind (Formal) /= E_Out_Parameter
7032 and then Nkind (Parameter_Type (Parent (Formal))) /=
7037 -- All other cases are OK since a task entry or routine does
7038 -- not have a restriction on the mode of the first parameter
7039 -- of the overridden interface routine.
7042 Overridden_Subp := Candidate;
7047 -- Functions can override abstract interface functions
7049 elsif Ekind (Def_Id) = E_Function
7050 and then Ekind (Subp) = E_Function
7051 and then Matches_Prefixed_View_Profile
7052 (Parameter_Specifications (Parent (Def_Id)),
7053 Parameter_Specifications (Parent (Subp)))
7054 and then Etype (Def_Id) = Etype (Subp)
7058 -- If an inherited subprogram is implemented by a protected
7059 -- function, then the first parameter of the inherited
7060 -- subprogram shall be of mode in, but not an access-to-
7061 -- variable parameter (RM 9.4(11/9)).
7063 if Present (First_Formal (Subp))
7064 and then Ekind (First_Formal (Subp)) = E_In_Parameter
7066 (not Is_Access_Type (Etype (First_Formal (Subp)))
7068 Is_Access_Constant (Etype (First_Formal (Subp))))
7070 Overridden_Subp := Subp;
7075 Hom := Homonym (Hom);
7078 -- After examining all candidates for overriding, we are left with
7079 -- the best match, which is a mode-incompatible interface routine.
7081 if In_Scope and then Present (Candidate) then
7082 Error_Msg_PT (Def_Id, Candidate);
7085 Overridden_Subp := Candidate;
7088 end Check_Synchronized_Overriding;
7090 ---------------------------
7091 -- Check_Type_Conformant --
7092 ---------------------------
7094 procedure Check_Type_Conformant
7095 (New_Id : Entity_Id;
7097 Err_Loc : Node_Id := Empty)
7100 pragma Warnings (Off, Result);
7103 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
7104 end Check_Type_Conformant;
7106 ---------------------------
7107 -- Can_Override_Operator --
7108 ---------------------------
7110 function Can_Override_Operator (Subp : Entity_Id) return Boolean is
7114 if Nkind (Subp) /= N_Defining_Operator_Symbol then
7118 Typ := Base_Type (Etype (First_Formal (Subp)));
7120 -- Check explicitly that the operation is a primitive of the type
7122 return Operator_Matches_Spec (Subp, Subp)
7123 and then not Is_Generic_Type (Typ)
7124 and then Scope (Subp) = Scope (Typ)
7125 and then not Is_Class_Wide_Type (Typ);
7127 end Can_Override_Operator;
7129 ----------------------
7130 -- Conforming_Types --
7131 ----------------------
7133 function Conforming_Types
7136 Ctype : Conformance_Type;
7137 Get_Inst : Boolean := False) return Boolean
7139 function Base_Types_Match
7141 Typ_2 : Entity_Id) return Boolean;
7142 -- If neither Typ_1 nor Typ_2 are generic actual types, or if they are
7143 -- in different scopes (e.g. parent and child instances), then verify
7144 -- that the base types are equal. Otherwise Typ_1 and Typ_2 must be on
7145 -- the same subtype chain. The whole purpose of this procedure is to
7146 -- prevent spurious ambiguities in an instantiation that may arise if
7147 -- two distinct generic types are instantiated with the same actual.
7149 function Find_Designated_Type (Typ : Entity_Id) return Entity_Id;
7150 -- An access parameter can designate an incomplete type. If the
7151 -- incomplete type is the limited view of a type from a limited_
7152 -- with_clause, check whether the non-limited view is available.
7153 -- If it is a (non-limited) incomplete type, get the full view.
7155 function Matches_Limited_With_View
7157 Typ_2 : Entity_Id) return Boolean;
7158 -- Returns True if and only if either Typ_1 denotes a limited view of
7159 -- Typ_2 or Typ_2 denotes a limited view of Typ_1. This can arise when
7160 -- the limited with view of a type is used in a subprogram declaration
7161 -- and the subprogram body is in the scope of a regular with clause for
7162 -- the same unit. In such a case, the two type entities are considered
7163 -- identical for purposes of conformance checking.
7165 ----------------------
7166 -- Base_Types_Match --
7167 ----------------------
7169 function Base_Types_Match
7171 Typ_2 : Entity_Id) return Boolean
7173 Base_1 : constant Entity_Id := Base_Type (Typ_1);
7174 Base_2 : constant Entity_Id := Base_Type (Typ_2);
7177 if Typ_1 = Typ_2 then
7180 elsif Base_1 = Base_2 then
7182 -- The following is too permissive. A more precise test should
7183 -- check that the generic actual is an ancestor subtype of the
7186 -- See code in Find_Corresponding_Spec that applies an additional
7187 -- filter to handle accidental amiguities in instances.
7190 not Is_Generic_Actual_Type (Typ_1)
7191 or else not Is_Generic_Actual_Type (Typ_2)
7192 or else Scope (Typ_1) /= Scope (Typ_2);
7194 -- If Typ_2 is a generic actual type it is declared as the subtype of
7195 -- the actual. If that actual is itself a subtype we need to use its
7196 -- own base type to check for compatibility.
7198 elsif Ekind (Base_2) = Ekind (Typ_2)
7199 and then Base_1 = Base_Type (Base_2)
7203 elsif Ekind (Base_1) = Ekind (Typ_1)
7204 and then Base_2 = Base_Type (Base_1)
7211 end Base_Types_Match;
7213 --------------------------
7214 -- Find_Designated_Type --
7215 --------------------------
7217 function Find_Designated_Type (Typ : Entity_Id) return Entity_Id is
7221 Desig := Directly_Designated_Type (Typ);
7223 if Ekind (Desig) = E_Incomplete_Type then
7225 -- If regular incomplete type, get full view if available
7227 if Present (Full_View (Desig)) then
7228 Desig := Full_View (Desig);
7230 -- If limited view of a type, get non-limited view if available,
7231 -- and check again for a regular incomplete type.
7233 elsif Present (Non_Limited_View (Desig)) then
7234 Desig := Get_Full_View (Non_Limited_View (Desig));
7239 end Find_Designated_Type;
7241 -------------------------------
7242 -- Matches_Limited_With_View --
7243 -------------------------------
7245 function Matches_Limited_With_View
7247 Typ_2 : Entity_Id) return Boolean
7249 function Is_Matching_Limited_View
7251 View : Entity_Id) return Boolean;
7252 -- Determine whether non-limited view View denotes type Typ in some
7253 -- conformant fashion.
7255 ------------------------------
7256 -- Is_Matching_Limited_View --
7257 ------------------------------
7259 function Is_Matching_Limited_View
7261 View : Entity_Id) return Boolean
7263 Root_Typ : Entity_Id;
7264 Root_View : Entity_Id;
7267 -- The non-limited view directly denotes the type
7272 -- The type is a subtype of the non-limited view
7274 elsif Is_Subtype_Of (Typ, View) then
7277 -- Both the non-limited view and the type denote class-wide types
7279 elsif Is_Class_Wide_Type (Typ)
7280 and then Is_Class_Wide_Type (View)
7282 Root_Typ := Root_Type (Typ);
7283 Root_View := Root_Type (View);
7285 if Root_Typ = Root_View then
7288 -- An incomplete tagged type and its full view may receive two
7289 -- distinct class-wide types when the related package has not
7290 -- been analyzed yet.
7293 -- type T is tagged; -- CW_1
7294 -- type T is tagged null record; -- CW_2
7297 -- This is because the package lacks any semantic information
7298 -- that may eventually link both views of T. As a consequence,
7299 -- a client of the limited view of Pack will see CW_2 while a
7300 -- client of the non-limited view of Pack will see CW_1.
7302 elsif Is_Incomplete_Type (Root_Typ)
7303 and then Present (Full_View (Root_Typ))
7304 and then Full_View (Root_Typ) = Root_View
7308 elsif Is_Incomplete_Type (Root_View)
7309 and then Present (Full_View (Root_View))
7310 and then Full_View (Root_View) = Root_Typ
7317 end Is_Matching_Limited_View;
7319 -- Start of processing for Matches_Limited_With_View
7322 -- In some cases a type imported through a limited_with clause, and
7323 -- its non-limited view are both visible, for example in an anonymous
7324 -- access-to-class-wide type in a formal, or when building the body
7325 -- for a subprogram renaming after the subprogram has been frozen.
7326 -- In these cases both entities designate the same type. In addition,
7327 -- if one of them is an actual in an instance, it may be a subtype of
7328 -- the non-limited view of the other.
7330 if From_Limited_With (Typ_1)
7331 and then From_Limited_With (Typ_2)
7332 and then Available_View (Typ_1) = Available_View (Typ_2)
7336 elsif From_Limited_With (Typ_1) then
7337 return Is_Matching_Limited_View (Typ_2, Available_View (Typ_1));
7339 elsif From_Limited_With (Typ_2) then
7340 return Is_Matching_Limited_View (Typ_1, Available_View (Typ_2));
7345 end Matches_Limited_With_View;
7349 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
7351 Type_1 : Entity_Id := T1;
7352 Type_2 : Entity_Id := T2;
7354 -- Start of processing for Conforming_Types
7357 -- The context is an instance association for a formal access-to-
7358 -- subprogram type; the formal parameter types require mapping because
7359 -- they may denote other formal parameters of the generic unit.
7362 Type_1 := Get_Instance_Of (T1);
7363 Type_2 := Get_Instance_Of (T2);
7366 -- If one of the types is a view of the other introduced by a limited
7367 -- with clause, treat these as conforming for all purposes.
7369 if Matches_Limited_With_View (T1, T2) then
7372 elsif Base_Types_Match (Type_1, Type_2) then
7373 return Ctype <= Mode_Conformant
7374 or else Subtypes_Statically_Match (Type_1, Type_2);
7376 elsif Is_Incomplete_Or_Private_Type (Type_1)
7377 and then Present (Full_View (Type_1))
7378 and then Base_Types_Match (Full_View (Type_1), Type_2)
7380 return Ctype <= Mode_Conformant
7381 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
7383 elsif Ekind (Type_2) = E_Incomplete_Type
7384 and then Present (Full_View (Type_2))
7385 and then Base_Types_Match (Type_1, Full_View (Type_2))
7387 return Ctype <= Mode_Conformant
7388 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
7390 elsif Is_Private_Type (Type_2)
7391 and then In_Instance
7392 and then Present (Full_View (Type_2))
7393 and then Base_Types_Match (Type_1, Full_View (Type_2))
7395 return Ctype <= Mode_Conformant
7396 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
7398 -- Another confusion between views in a nested instance with an
7399 -- actual private type whose full view is not in scope.
7401 elsif Ekind (Type_2) = E_Private_Subtype
7402 and then In_Instance
7403 and then Etype (Type_2) = Type_1
7407 -- In Ada 2012, incomplete types (including limited views) can appear
7408 -- as actuals in instantiations.
7410 elsif Is_Incomplete_Type (Type_1)
7411 and then Is_Incomplete_Type (Type_2)
7412 and then (Used_As_Generic_Actual (Type_1)
7413 or else Used_As_Generic_Actual (Type_2))
7418 -- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be
7419 -- treated recursively because they carry a signature. As far as
7420 -- conformance is concerned, convention plays no role, and either
7421 -- or both could be access to protected subprograms.
7423 Are_Anonymous_Access_To_Subprogram_Types :=
7424 Ekind_In (Type_1, E_Anonymous_Access_Subprogram_Type,
7425 E_Anonymous_Access_Protected_Subprogram_Type)
7427 Ekind_In (Type_2, E_Anonymous_Access_Subprogram_Type,
7428 E_Anonymous_Access_Protected_Subprogram_Type);
7430 -- Test anonymous access type case. For this case, static subtype
7431 -- matching is required for mode conformance (RM 6.3.1(15)). We check
7432 -- the base types because we may have built internal subtype entities
7433 -- to handle null-excluding types (see Process_Formals).
7435 if (Ekind (Base_Type (Type_1)) = E_Anonymous_Access_Type
7437 Ekind (Base_Type (Type_2)) = E_Anonymous_Access_Type)
7439 -- Ada 2005 (AI-254)
7441 or else Are_Anonymous_Access_To_Subprogram_Types
7444 Desig_1 : Entity_Id;
7445 Desig_2 : Entity_Id;
7448 -- In Ada 2005, access constant indicators must match for
7449 -- subtype conformance.
7451 if Ada_Version >= Ada_2005
7452 and then Ctype >= Subtype_Conformant
7454 Is_Access_Constant (Type_1) /= Is_Access_Constant (Type_2)
7459 Desig_1 := Find_Designated_Type (Type_1);
7460 Desig_2 := Find_Designated_Type (Type_2);
7462 -- If the context is an instance association for a formal
7463 -- access-to-subprogram type; formal access parameter designated
7464 -- types require mapping because they may denote other formal
7465 -- parameters of the generic unit.
7468 Desig_1 := Get_Instance_Of (Desig_1);
7469 Desig_2 := Get_Instance_Of (Desig_2);
7472 -- It is possible for a Class_Wide_Type to be introduced for an
7473 -- incomplete type, in which case there is a separate class_ wide
7474 -- type for the full view. The types conform if their Etypes
7475 -- conform, i.e. one may be the full view of the other. This can
7476 -- only happen in the context of an access parameter, other uses
7477 -- of an incomplete Class_Wide_Type are illegal.
7479 if Is_Class_Wide_Type (Desig_1)
7481 Is_Class_Wide_Type (Desig_2)
7485 (Etype (Base_Type (Desig_1)),
7486 Etype (Base_Type (Desig_2)), Ctype);
7488 elsif Are_Anonymous_Access_To_Subprogram_Types then
7489 if Ada_Version < Ada_2005 then
7490 return Ctype = Type_Conformant
7492 Subtypes_Statically_Match (Desig_1, Desig_2);
7494 -- We must check the conformance of the signatures themselves
7498 Conformant : Boolean;
7501 (Desig_1, Desig_2, Ctype, False, Conformant);
7506 -- A limited view of an actual matches the corresponding
7507 -- incomplete formal.
7509 elsif Ekind (Desig_2) = E_Incomplete_Subtype
7510 and then From_Limited_With (Desig_2)
7511 and then Used_As_Generic_Actual (Etype (Desig_2))
7516 return Base_Type (Desig_1) = Base_Type (Desig_2)
7517 and then (Ctype = Type_Conformant
7519 Subtypes_Statically_Match (Desig_1, Desig_2));
7523 -- Otherwise definitely no match
7526 if ((Ekind (Type_1) = E_Anonymous_Access_Type
7527 and then Is_Access_Type (Type_2))
7528 or else (Ekind (Type_2) = E_Anonymous_Access_Type
7529 and then Is_Access_Type (Type_1)))
7532 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
7534 May_Hide_Profile := True;
7539 end Conforming_Types;
7541 --------------------------
7542 -- Create_Extra_Formals --
7543 --------------------------
7545 procedure Create_Extra_Formals (E : Entity_Id) is
7546 First_Extra : Entity_Id := Empty;
7548 Last_Extra : Entity_Id := Empty;
7550 function Add_Extra_Formal
7551 (Assoc_Entity : Entity_Id;
7554 Suffix : String) return Entity_Id;
7555 -- Add an extra formal to the current list of formals and extra formals.
7556 -- The extra formal is added to the end of the list of extra formals,
7557 -- and also returned as the result. These formals are always of mode IN.
7558 -- The new formal has the type Typ, is declared in Scope, and its name
7559 -- is given by a concatenation of the name of Assoc_Entity and Suffix.
7560 -- The following suffixes are currently used. They should not be changed
7561 -- without coordinating with CodePeer, which makes use of these to
7562 -- provide better messages.
7564 -- O denotes the Constrained bit.
7565 -- L denotes the accessibility level.
7566 -- BIP_xxx denotes an extra formal for a build-in-place function. See
7567 -- the full list in exp_ch6.BIP_Formal_Kind.
7569 ----------------------
7570 -- Add_Extra_Formal --
7571 ----------------------
7573 function Add_Extra_Formal
7574 (Assoc_Entity : Entity_Id;
7577 Suffix : String) return Entity_Id
7579 EF : constant Entity_Id :=
7580 Make_Defining_Identifier (Sloc (Assoc_Entity),
7581 Chars => New_External_Name (Chars (Assoc_Entity),
7585 -- A little optimization. Never generate an extra formal for the
7586 -- _init operand of an initialization procedure, since it could
7589 if Chars (Formal) = Name_uInit then
7593 Set_Ekind (EF, E_In_Parameter);
7594 Set_Actual_Subtype (EF, Typ);
7595 Set_Etype (EF, Typ);
7596 Set_Scope (EF, Scope);
7597 Set_Mechanism (EF, Default_Mechanism);
7598 Set_Formal_Validity (EF);
7600 if No (First_Extra) then
7602 Set_Extra_Formals (Scope, First_Extra);
7605 if Present (Last_Extra) then
7606 Set_Extra_Formal (Last_Extra, EF);
7612 end Add_Extra_Formal;
7616 Formal_Type : Entity_Id;
7617 P_Formal : Entity_Id := Empty;
7619 -- Start of processing for Create_Extra_Formals
7622 -- We never generate extra formals if expansion is not active because we
7623 -- don't need them unless we are generating code.
7625 if not Expander_Active then
7629 -- No need to generate extra formals in interface thunks whose target
7630 -- primitive has no extra formals.
7632 if Is_Thunk (E) and then No (Extra_Formals (Thunk_Entity (E))) then
7636 -- If this is a derived subprogram then the subtypes of the parent
7637 -- subprogram's formal parameters will be used to determine the need
7638 -- for extra formals.
7640 if Is_Overloadable (E) and then Present (Alias (E)) then
7641 P_Formal := First_Formal (Alias (E));
7644 Formal := First_Formal (E);
7645 while Present (Formal) loop
7646 Last_Extra := Formal;
7647 Next_Formal (Formal);
7650 -- If Extra_Formals were already created, don't do it again. This
7651 -- situation may arise for subprogram types created as part of
7652 -- dispatching calls (see Expand_Dispatching_Call)
7654 if Present (Last_Extra) and then Present (Extra_Formal (Last_Extra)) then
7658 -- If the subprogram is a predefined dispatching subprogram then don't
7659 -- generate any extra constrained or accessibility level formals. In
7660 -- general we suppress these for internal subprograms (by not calling
7661 -- Freeze_Subprogram and Create_Extra_Formals at all), but internally
7662 -- generated stream attributes do get passed through because extra
7663 -- build-in-place formals are needed in some cases (limited 'Input
).
7665 if Is_Predefined_Internal_Operation
(E
) then
7666 goto Test_For_Func_Result_Extras
;
7669 Formal
:= First_Formal
(E
);
7670 while Present
(Formal
) loop
7672 -- Create extra formal for supporting the attribute 'Constrained.
7673 -- The case of a private type view without discriminants also
7674 -- requires the extra formal if the underlying type has defaulted
7677 if Ekind
(Formal
) /= E_In_Parameter
then
7678 if Present
(P_Formal
) then
7679 Formal_Type
:= Etype
(P_Formal
);
7681 Formal_Type
:= Etype
(Formal
);
7684 -- Do not produce extra formals for Unchecked_Union parameters.
7685 -- Jump directly to the end of the loop.
7687 if Is_Unchecked_Union
(Base_Type
(Formal_Type
)) then
7688 goto Skip_Extra_Formal_Generation
;
7691 if not Has_Discriminants
(Formal_Type
)
7692 and then Ekind
(Formal_Type
) in Private_Kind
7693 and then Present
(Underlying_Type
(Formal_Type
))
7695 Formal_Type
:= Underlying_Type
(Formal_Type
);
7698 -- Suppress the extra formal if formal's subtype is constrained or
7699 -- indefinite, or we're compiling for Ada 2012 and the underlying
7700 -- type is tagged and limited. In Ada 2012, a limited tagged type
7701 -- can have defaulted discriminants, but 'Constrained is required
7702 -- to return True, so the formal is never needed (see AI05-0214).
7703 -- Note that this ensures consistency of calling sequences for
7704 -- dispatching operations when some types in a class have defaults
7705 -- on discriminants and others do not (and requiring the extra
7706 -- formal would introduce distributed overhead).
7708 -- If the type does not have a completion yet, treat as prior to
7709 -- Ada 2012 for consistency.
7711 if Has_Discriminants
(Formal_Type
)
7712 and then not Is_Constrained
(Formal_Type
)
7713 and then Is_Definite_Subtype
(Formal_Type
)
7714 and then (Ada_Version
< Ada_2012
7715 or else No
(Underlying_Type
(Formal_Type
))
7717 (Is_Limited_Type
(Formal_Type
)
7720 (Underlying_Type
(Formal_Type
)))))
7722 Set_Extra_Constrained
7723 (Formal
, Add_Extra_Formal
(Formal
, Standard_Boolean
, E
, "O"));
7727 -- Create extra formal for supporting accessibility checking. This
7728 -- is done for both anonymous access formals and formals of named
7729 -- access types that are marked as controlling formals. The latter
7730 -- case can occur when Expand_Dispatching_Call creates a subprogram
7731 -- type and substitutes the types of access-to-class-wide actuals
7732 -- for the anonymous access-to-specific-type of controlling formals.
7733 -- Base_Type is applied because in cases where there is a null
7734 -- exclusion the formal may have an access subtype.
7736 -- This is suppressed if we specifically suppress accessibility
7737 -- checks at the package level for either the subprogram, or the
7738 -- package in which it resides. However, we do not suppress it
7739 -- simply if the scope has accessibility checks suppressed, since
7740 -- this could cause trouble when clients are compiled with a
7741 -- different suppression setting. The explicit checks at the
7742 -- package level are safe from this point of view.
7744 if (Ekind
(Base_Type
(Etype
(Formal
))) = E_Anonymous_Access_Type
7745 or else (Is_Controlling_Formal
(Formal
)
7746 and then Is_Access_Type
(Base_Type
(Etype
(Formal
)))))
7748 (Explicit_Suppress
(E
, Accessibility_Check
)
7750 Explicit_Suppress
(Scope
(E
), Accessibility_Check
))
7753 or else Present
(Extra_Accessibility
(P_Formal
)))
7755 Set_Extra_Accessibility
7756 (Formal
, Add_Extra_Formal
(Formal
, Standard_Natural
, E
, "L"));
7759 -- This label is required when skipping extra formal generation for
7760 -- Unchecked_Union parameters.
7762 <<Skip_Extra_Formal_Generation
>>
7764 if Present
(P_Formal
) then
7765 Next_Formal
(P_Formal
);
7768 Next_Formal
(Formal
);
7771 <<Test_For_Func_Result_Extras
>>
7773 -- Ada 2012 (AI05-234): "the accessibility level of the result of a
7774 -- function call is ... determined by the point of call ...".
7776 if Needs_Result_Accessibility_Level
(E
) then
7777 Set_Extra_Accessibility_Of_Result
7778 (E
, Add_Extra_Formal
(E
, Standard_Natural
, E
, "L"));
7781 -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add
7782 -- appropriate extra formals. See type Exp_Ch6.BIP_Formal_Kind.
7784 if Ada_Version
>= Ada_2005
and then Is_Build_In_Place_Function
(E
) then
7786 Result_Subt
: constant Entity_Id
:= Etype
(E
);
7787 Full_Subt
: constant Entity_Id
:= Available_View
(Result_Subt
);
7788 Formal_Typ
: Entity_Id
;
7789 Subp_Decl
: Node_Id
;
7791 Discard
: Entity_Id
;
7792 pragma Warnings
(Off
, Discard
);
7795 -- In the case of functions with unconstrained result subtypes,
7796 -- add a 4-state formal indicating whether the return object is
7797 -- allocated by the caller (1), or should be allocated by the
7798 -- callee on the secondary stack (2), in the global heap (3), or
7799 -- in a user-defined storage pool (4). For the moment we just use
7800 -- Natural for the type of this formal. Note that this formal
7801 -- isn't usually needed in the case where the result subtype is
7802 -- constrained, but it is needed when the function has a tagged
7803 -- result, because generally such functions can be called in a
7804 -- dispatching context and such calls must be handled like calls
7805 -- to a class-wide function.
7807 if Needs_BIP_Alloc_Form
(E
) then
7810 (E
, Standard_Natural
,
7811 E
, BIP_Formal_Suffix
(BIP_Alloc_Form
));
7813 -- Add BIP_Storage_Pool, in case BIP_Alloc_Form indicates to
7814 -- use a user-defined pool. This formal is not added on
7815 -- ZFP as those targets do not support pools.
7817 if RTE_Available
(RE_Root_Storage_Pool_Ptr
) then
7820 (E
, RTE
(RE_Root_Storage_Pool_Ptr
),
7821 E
, BIP_Formal_Suffix
(BIP_Storage_Pool
));
7825 -- In the case of functions whose result type needs finalization,
7826 -- add an extra formal which represents the finalization master.
7828 if Needs_BIP_Finalization_Master
(E
) then
7831 (E
, RTE
(RE_Finalization_Master_Ptr
),
7832 E
, BIP_Formal_Suffix
(BIP_Finalization_Master
));
7835 -- When the result type contains tasks, add two extra formals: the
7836 -- master of the tasks to be created, and the caller's activation
7839 if Has_Task
(Full_Subt
) then
7842 (E
, RTE
(RE_Master_Id
),
7843 E
, BIP_Formal_Suffix
(BIP_Task_Master
));
7846 (E
, RTE
(RE_Activation_Chain_Access
),
7847 E
, BIP_Formal_Suffix
(BIP_Activation_Chain
));
7850 -- All build-in-place functions get an extra formal that will be
7851 -- passed the address of the return object within the caller.
7854 Create_Itype
(E_Anonymous_Access_Type
, E
, Scope_Id
=> Scope
(E
));
7856 Set_Directly_Designated_Type
(Formal_Typ
, Result_Subt
);
7857 Set_Etype
(Formal_Typ
, Formal_Typ
);
7858 Set_Depends_On_Private
7859 (Formal_Typ
, Has_Private_Component
(Formal_Typ
));
7860 Set_Is_Public
(Formal_Typ
, Is_Public
(Scope
(Formal_Typ
)));
7861 Set_Is_Access_Constant
(Formal_Typ
, False);
7863 -- Ada 2005 (AI-50217): Propagate the attribute that indicates
7864 -- the designated type comes from the limited view (for back-end
7867 Set_From_Limited_With
7868 (Formal_Typ
, From_Limited_With
(Result_Subt
));
7870 Layout_Type
(Formal_Typ
);
7872 -- Force the definition of the Itype in case of internal function
7873 -- calls within the same or nested scope.
7875 if Is_Subprogram_Or_Generic_Subprogram
(E
) then
7876 Subp_Decl
:= Parent
(E
);
7878 -- The insertion point for an Itype reference should be after
7879 -- the unit declaration node of the subprogram. An exception
7880 -- to this are inherited operations from a parent type in which
7881 -- case the derived type acts as their parent.
7883 if Nkind_In
(Subp_Decl
, N_Function_Specification
,
7884 N_Procedure_Specification
)
7886 Subp_Decl
:= Parent
(Subp_Decl
);
7889 Build_Itype_Reference
(Formal_Typ
, Subp_Decl
);
7894 (E
, Formal_Typ
, E
, BIP_Formal_Suffix
(BIP_Object_Access
));
7897 end Create_Extra_Formals
;
7899 -----------------------------
7900 -- Enter_Overloaded_Entity --
7901 -----------------------------
7903 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
7904 function Matches_Predefined_Op
return Boolean;
7905 -- This returns an approximation of whether S matches a predefined
7906 -- operator, based on the operator symbol, and the parameter and result
7907 -- types. The rules are scattered throughout chapter 4 of the Ada RM.
7909 ---------------------------
7910 -- Matches_Predefined_Op --
7911 ---------------------------
7913 function Matches_Predefined_Op
return Boolean is
7914 Formal_1
: constant Entity_Id
:= First_Formal
(S
);
7915 Formal_2
: constant Entity_Id
:= Next_Formal
(Formal_1
);
7916 Op
: constant Name_Id
:= Chars
(S
);
7917 Result_Type
: constant Entity_Id
:= Base_Type
(Etype
(S
));
7918 Type_1
: constant Entity_Id
:= Base_Type
(Etype
(Formal_1
));
7923 if Present
(Formal_2
) then
7925 Type_2
: constant Entity_Id
:= Base_Type
(Etype
(Formal_2
));
7928 -- All but "&" and "**" have same-types parameters
7937 if Type_1
/= Type_2
then
7942 -- Check parameter and result types
7950 Is_Boolean_Type
(Result_Type
)
7951 and then Result_Type
= Type_1
;
7957 Is_Integer_Type
(Result_Type
)
7958 and then Result_Type
= Type_1
;
7966 Is_Numeric_Type
(Result_Type
)
7967 and then Result_Type
= Type_1
;
7973 Is_Boolean_Type
(Result_Type
)
7974 and then not Is_Limited_Type
(Type_1
);
7982 Is_Boolean_Type
(Result_Type
)
7983 and then (Is_Array_Type
(Type_1
)
7984 or else Is_Scalar_Type
(Type_1
));
7986 when Name_Op_Concat
=>
7987 return Is_Array_Type
(Result_Type
);
7989 when Name_Op_Expon
=>
7991 (Is_Integer_Type
(Result_Type
)
7992 or else Is_Floating_Point_Type
(Result_Type
))
7993 and then Result_Type
= Type_1
7994 and then Type_2
= Standard_Integer
;
7997 raise Program_Error
;
8010 Is_Numeric_Type
(Result_Type
)
8011 and then Result_Type
= Type_1
;
8015 Is_Boolean_Type
(Result_Type
)
8016 and then Result_Type
= Type_1
;
8019 raise Program_Error
;
8022 end Matches_Predefined_Op
;
8026 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
8027 C_E
: Entity_Id
:= Current_Entity
(S
);
8029 -- Start of processing for Enter_Overloaded_Entity
8033 Set_Has_Homonym
(E
);
8034 Set_Has_Homonym
(S
);
8037 Set_Is_Immediately_Visible
(S
);
8038 Set_Scope
(S
, Current_Scope
);
8040 -- Chain new entity if front of homonym in current scope, so that
8041 -- homonyms are contiguous.
8043 if Present
(E
) and then E
/= C_E
then
8044 while Homonym
(C_E
) /= E
loop
8045 C_E
:= Homonym
(C_E
);
8048 Set_Homonym
(C_E
, S
);
8052 Set_Current_Entity
(S
);
8057 if Is_Inherited_Operation
(S
) then
8058 Append_Inherited_Subprogram
(S
);
8060 Append_Entity
(S
, Current_Scope
);
8063 Set_Public_Status
(S
);
8065 if Debug_Flag_E
then
8066 Write_Str
("New overloaded entity chain: ");
8067 Write_Name
(Chars
(S
));
8070 while Present
(E
) loop
8071 Write_Str
(" "); Write_Int
(Int
(E
));
8078 -- Generate warning for hiding
8081 and then Comes_From_Source
(S
)
8082 and then In_Extended_Main_Source_Unit
(S
)
8089 -- Warn unless genuine overloading. Do not emit warning on
8090 -- hiding predefined operators in Standard (these are either an
8091 -- (artifact of our implicit declarations, or simple noise) but
8092 -- keep warning on a operator defined on a local subtype, because
8093 -- of the real danger that different operators may be applied in
8094 -- various parts of the program.
8096 -- Note that if E and S have the same scope, there is never any
8097 -- hiding. Either the two conflict, and the program is illegal,
8098 -- or S is overriding an implicit inherited subprogram.
8100 if Scope
(E
) /= Scope
(S
)
8101 and then (not Is_Overloadable
(E
)
8102 or else Subtype_Conformant
(E
, S
))
8103 and then (Is_Immediately_Visible
(E
)
8104 or else Is_Potentially_Use_Visible
(S
))
8106 if Scope
(E
) = Standard_Standard
then
8107 if Nkind
(S
) = N_Defining_Operator_Symbol
8108 and then Scope
(Base_Type
(Etype
(First_Formal
(S
)))) /=
8110 and then Matches_Predefined_Op
8113 ("declaration of & hides predefined operator?h?", S
);
8116 -- E not immediately within Standard
8119 Error_Msg_Sloc
:= Sloc
(E
);
8120 Error_Msg_N
("declaration of & hides one #?h?", S
);
8125 end Enter_Overloaded_Entity
;
8127 -----------------------------
8128 -- Check_Untagged_Equality --
8129 -----------------------------
8131 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
) is
8132 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Eq_Op
));
8133 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Eq_Op
);
8137 -- This check applies only if we have a subprogram declaration with an
8138 -- untagged record type.
8140 if Nkind
(Decl
) /= N_Subprogram_Declaration
8141 or else not Is_Record_Type
(Typ
)
8142 or else Is_Tagged_Type
(Typ
)
8147 -- In Ada 2012 case, we will output errors or warnings depending on
8148 -- the setting of debug flag -gnatd.E.
8150 if Ada_Version
>= Ada_2012
then
8151 Error_Msg_Warn
:= Debug_Flag_Dot_EE
;
8153 -- In earlier versions of Ada, nothing to do unless we are warning on
8154 -- Ada 2012 incompatibilities (Warn_On_Ada_2012_Incompatibility set).
8157 if not Warn_On_Ada_2012_Compatibility
then
8162 -- Cases where the type has already been frozen
8164 if Is_Frozen
(Typ
) then
8166 -- If the type is not declared in a package, or if we are in the body
8167 -- of the package or in some other scope, the new operation is not
8168 -- primitive, and therefore legal, though suspicious. Should we
8169 -- generate a warning in this case ???
8171 if Ekind
(Scope
(Typ
)) /= E_Package
8172 or else Scope
(Typ
) /= Current_Scope
8176 -- If the type is a generic actual (sub)type, the operation is not
8177 -- primitive either because the base type is declared elsewhere.
8179 elsif Is_Generic_Actual_Type
(Typ
) then
8182 -- Here we have a definite error of declaration after freezing
8185 if Ada_Version
>= Ada_2012
then
8187 ("equality operator must be declared before type & is "
8188 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)<<", Eq_Op
, Typ
);
8190 -- In Ada 2012 mode with error turned to warning, output one
8191 -- more warning to warn that the equality operation may not
8192 -- compose. This is the consequence of ignoring the error.
8194 if Error_Msg_Warn
then
8195 Error_Msg_N
("\equality operation may not compose??", Eq_Op
);
8200 ("equality operator must be declared before type& is "
8201 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)?y?", Eq_Op
, Typ
);
8204 -- If we are in the package body, we could just move the
8205 -- declaration to the package spec, so add a message saying that.
8207 if In_Package_Body
(Scope
(Typ
)) then
8208 if Ada_Version
>= Ada_2012
then
8210 ("\move declaration to package spec<<", Eq_Op
);
8213 ("\move declaration to package spec (Ada 2012)?y?", Eq_Op
);
8216 -- Otherwise try to find the freezing point
8219 Obj_Decl
:= Next
(Parent
(Typ
));
8220 while Present
(Obj_Decl
) and then Obj_Decl
/= Decl
loop
8221 if Nkind
(Obj_Decl
) = N_Object_Declaration
8222 and then Etype
(Defining_Identifier
(Obj_Decl
)) = Typ
8224 -- Freezing point, output warnings
8226 if Ada_Version
>= Ada_2012
then
8228 ("type& is frozen by declaration??", Obj_Decl
, Typ
);
8230 ("\an equality operator cannot be declared after "
8235 ("type& is frozen by declaration (Ada 2012)?y?",
8238 ("\an equality operator cannot be declared after "
8239 & "this point (Ada 2012)?y?",
8251 -- Here if type is not frozen yet. It is illegal to have a primitive
8252 -- equality declared in the private part if the type is visible.
8254 elsif not In_Same_List
(Parent
(Typ
), Decl
)
8255 and then not Is_Limited_Type
(Typ
)
8257 -- Shouldn't we give an RM reference here???
8259 if Ada_Version
>= Ada_2012
then
8261 ("equality operator appears too late<<", Eq_Op
);
8264 ("equality operator appears too late (Ada 2012)?y?", Eq_Op
);
8267 -- No error detected
8272 end Check_Untagged_Equality
;
8274 -----------------------------
8275 -- Find_Corresponding_Spec --
8276 -----------------------------
8278 function Find_Corresponding_Spec
8280 Post_Error
: Boolean := True) return Entity_Id
8282 Spec
: constant Node_Id
:= Specification
(N
);
8283 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
8287 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean;
8288 -- Even if fully conformant, a body may depend on a generic actual when
8289 -- the spec does not, or vice versa, in which case they were distinct
8290 -- entities in the generic.
8292 -------------------------------
8293 -- Different_Generic_Profile --
8294 -------------------------------
8296 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean is
8299 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean;
8300 -- Check that the types of corresponding formals have the same
8301 -- generic actual if any. We have to account for subtypes of a
8302 -- generic formal, declared between a spec and a body, which may
8303 -- appear distinct in an instance but matched in the generic, and
8304 -- the subtype may be used either in the spec or the body of the
8305 -- subprogram being checked.
8307 -------------------------
8308 -- Same_Generic_Actual --
8309 -------------------------
8311 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean is
8313 function Is_Declared_Subtype
(S1
, S2
: Entity_Id
) return Boolean;
8314 -- Predicate to check whether S1 is a subtype of S2 in the source
8317 -------------------------
8318 -- Is_Declared_Subtype --
8319 -------------------------
8321 function Is_Declared_Subtype
(S1
, S2
: Entity_Id
) return Boolean is
8323 return Comes_From_Source
(Parent
(S1
))
8324 and then Nkind
(Parent
(S1
)) = N_Subtype_Declaration
8325 and then Is_Entity_Name
(Subtype_Indication
(Parent
(S1
)))
8326 and then Entity
(Subtype_Indication
(Parent
(S1
))) = S2
;
8327 end Is_Declared_Subtype
;
8329 -- Start of processing for Same_Generic_Actual
8332 return Is_Generic_Actual_Type
(T1
) = Is_Generic_Actual_Type
(T2
)
8333 or else Is_Declared_Subtype
(T1
, T2
)
8334 or else Is_Declared_Subtype
(T2
, T1
);
8335 end Same_Generic_Actual
;
8337 -- Start of processing for Different_Generic_Profile
8340 if not In_Instance
then
8343 elsif Ekind
(E
) = E_Function
8344 and then not Same_Generic_Actual
(Etype
(E
), Etype
(Designator
))
8349 F1
:= First_Formal
(Designator
);
8350 F2
:= First_Formal
(E
);
8351 while Present
(F1
) loop
8352 if not Same_Generic_Actual
(Etype
(F1
), Etype
(F2
)) then
8361 end Different_Generic_Profile
;
8363 -- Start of processing for Find_Corresponding_Spec
8366 E
:= Current_Entity
(Designator
);
8367 while Present
(E
) loop
8369 -- We are looking for a matching spec. It must have the same scope,
8370 -- and the same name, and either be type conformant, or be the case
8371 -- of a library procedure spec and its body (which belong to one
8372 -- another regardless of whether they are type conformant or not).
8374 if Scope
(E
) = Current_Scope
then
8375 if Current_Scope
= Standard_Standard
8376 or else (Ekind
(E
) = Ekind
(Designator
)
8377 and then Type_Conformant
(E
, Designator
))
8379 -- Within an instantiation, we know that spec and body are
8380 -- subtype conformant, because they were subtype conformant in
8381 -- the generic. We choose the subtype-conformant entity here as
8382 -- well, to resolve spurious ambiguities in the instance that
8383 -- were not present in the generic (i.e. when two different
8384 -- types are given the same actual). If we are looking for a
8385 -- spec to match a body, full conformance is expected.
8389 -- Inherit the convention and "ghostness" of the matching
8390 -- spec to ensure proper full and subtype conformance.
8392 Set_Convention
(Designator
, Convention
(E
));
8394 -- Skip past subprogram bodies and subprogram renamings that
8395 -- may appear to have a matching spec, but that aren't fully
8396 -- conformant with it. That can occur in cases where an
8397 -- actual type causes unrelated homographs in the instance.
8399 if Nkind_In
(N
, N_Subprogram_Body
,
8400 N_Subprogram_Renaming_Declaration
)
8401 and then Present
(Homonym
(E
))
8402 and then not Fully_Conformant
(Designator
, E
)
8406 elsif not Subtype_Conformant
(Designator
, E
) then
8409 elsif Different_Generic_Profile
(E
) then
8414 -- Ada 2012 (AI05-0165): For internally generated bodies of
8415 -- null procedures locate the internally generated spec. We
8416 -- enforce mode conformance since a tagged type may inherit
8417 -- from interfaces several null primitives which differ only
8418 -- in the mode of the formals.
8420 if not (Comes_From_Source
(E
))
8421 and then Is_Null_Procedure
(E
)
8422 and then not Mode_Conformant
(Designator
, E
)
8426 -- For null procedures coming from source that are completions,
8427 -- analysis of the generated body will establish the link.
8429 elsif Comes_From_Source
(E
)
8430 and then Nkind
(Spec
) = N_Procedure_Specification
8431 and then Null_Present
(Spec
)
8435 -- Expression functions can be completions, but cannot be
8436 -- completed by an explicit body.
8438 elsif Comes_From_Source
(E
)
8439 and then Comes_From_Source
(N
)
8440 and then Nkind
(N
) = N_Subprogram_Body
8441 and then Nkind
(Original_Node
(Unit_Declaration_Node
(E
))) =
8442 N_Expression_Function
8444 Error_Msg_Sloc
:= Sloc
(E
);
8445 Error_Msg_N
("body conflicts with expression function#", N
);
8448 elsif not Has_Completion
(E
) then
8449 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
8450 Set_Corresponding_Spec
(N
, E
);
8453 Set_Has_Completion
(E
);
8456 elsif Nkind
(Parent
(N
)) = N_Subunit
then
8458 -- If this is the proper body of a subunit, the completion
8459 -- flag is set when analyzing the stub.
8463 -- If E is an internal function with a controlling result that
8464 -- was created for an operation inherited by a null extension,
8465 -- it may be overridden by a body without a previous spec (one
8466 -- more reason why these should be shunned). In that case we
8467 -- remove the generated body if present, because the current
8468 -- one is the explicit overriding.
8470 elsif Ekind
(E
) = E_Function
8471 and then Ada_Version
>= Ada_2005
8472 and then not Comes_From_Source
(E
)
8473 and then Has_Controlling_Result
(E
)
8474 and then Is_Null_Extension
(Etype
(E
))
8475 and then Comes_From_Source
(Spec
)
8477 Set_Has_Completion
(E
, False);
8480 and then Nkind
(Parent
(E
)) = N_Function_Specification
8483 (Unit_Declaration_Node
8484 (Corresponding_Body
(Unit_Declaration_Node
(E
))));
8488 -- If expansion is disabled, or if the wrapper function has
8489 -- not been generated yet, this a late body overriding an
8490 -- inherited operation, or it is an overriding by some other
8491 -- declaration before the controlling result is frozen. In
8492 -- either case this is a declaration of a new entity.
8498 -- If the body already exists, then this is an error unless
8499 -- the previous declaration is the implicit declaration of a
8500 -- derived subprogram. It is also legal for an instance to
8501 -- contain type conformant overloadable declarations (but the
8502 -- generic declaration may not), per 8.3(26/2).
8504 elsif No
(Alias
(E
))
8505 and then not Is_Intrinsic_Subprogram
(E
)
8506 and then not In_Instance
8509 Error_Msg_Sloc
:= Sloc
(E
);
8511 if Is_Imported
(E
) then
8513 ("body not allowed for imported subprogram & declared#",
8516 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
8520 -- Child units cannot be overloaded, so a conformance mismatch
8521 -- between body and a previous spec is an error.
8523 elsif Is_Child_Unit
(E
)
8525 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
8527 Nkind
(Parent
(Unit_Declaration_Node
(Designator
))) =
8532 ("body of child unit does not match previous declaration", N
);
8540 -- On exit, we know that no previous declaration of subprogram exists
8543 end Find_Corresponding_Spec
;
8545 ----------------------
8546 -- Fully_Conformant --
8547 ----------------------
8549 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
8552 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
8554 end Fully_Conformant
;
8556 ----------------------------------
8557 -- Fully_Conformant_Expressions --
8558 ----------------------------------
8560 function Fully_Conformant_Expressions
8561 (Given_E1
: Node_Id
;
8562 Given_E2
: Node_Id
) return Boolean
8564 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
8565 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
8566 -- We always test conformance on original nodes, since it is possible
8567 -- for analysis and/or expansion to make things look as though they
8568 -- conform when they do not, e.g. by converting 1+2 into 3.
8570 function FCE
(Given_E1
, Given_E2
: Node_Id
) return Boolean
8571 renames Fully_Conformant_Expressions
;
8573 function FCL
(L1
, L2
: List_Id
) return Boolean;
8574 -- Compare elements of two lists for conformance. Elements have to be
8575 -- conformant, and actuals inserted as default parameters do not match
8576 -- explicit actuals with the same value.
8578 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean;
8579 -- Compare an operator node with a function call
8585 function FCL
(L1
, L2
: List_Id
) return Boolean is
8589 if L1
= No_List
then
8595 if L2
= No_List
then
8601 -- Compare two lists, skipping rewrite insertions (we want to compare
8602 -- the original trees, not the expanded versions).
8605 if Is_Rewrite_Insertion
(N1
) then
8607 elsif Is_Rewrite_Insertion
(N2
) then
8613 elsif not FCE
(N1
, N2
) then
8626 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean is
8627 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
8632 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
8637 Act
:= First
(Actuals
);
8639 if Nkind
(Op_Node
) in N_Binary_Op
then
8640 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
8647 return Present
(Act
)
8648 and then FCE
(Right_Opnd
(Op_Node
), Act
)
8649 and then No
(Next
(Act
));
8653 -- Start of processing for Fully_Conformant_Expressions
8656 -- Nonconformant if paren count does not match. Note: if some idiot
8657 -- complains that we don't do this right for more than 3 levels of
8658 -- parentheses, they will be treated with the respect they deserve.
8660 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
8663 -- If same entities are referenced, then they are conformant even if
8664 -- they have different forms (RM 8.3.1(19-20)).
8666 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
8667 if Present
(Entity
(E1
)) then
8668 return Entity
(E1
) = Entity
(E2
)
8670 -- One may be a discriminant that has been replaced by
8671 -- the corresponding discriminal.
8673 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
8674 and then Ekind
(Entity
(E1
)) = E_Discriminant
8675 and then Ekind
(Entity
(E2
)) = E_In_Parameter
)
8677 -- AI12-050: The loop variables of quantified expressions
8678 -- match if they have the same identifier, even though they
8679 -- are different entities.
8681 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
8682 and then Ekind
(Entity
(E1
)) = E_Loop_Parameter
8683 and then Ekind
(Entity
(E2
)) = E_Loop_Parameter
);
8685 elsif Nkind
(E1
) = N_Expanded_Name
8686 and then Nkind
(E2
) = N_Expanded_Name
8687 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
8688 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
8690 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
8693 -- Identifiers in component associations don't always have
8694 -- entities, but their names must conform.
8696 return Nkind
(E1
) = N_Identifier
8697 and then Nkind
(E2
) = N_Identifier
8698 and then Chars
(E1
) = Chars
(E2
);
8701 elsif Nkind
(E1
) = N_Character_Literal
8702 and then Nkind
(E2
) = N_Expanded_Name
8704 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
8705 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
8707 elsif Nkind
(E2
) = N_Character_Literal
8708 and then Nkind
(E1
) = N_Expanded_Name
8710 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
8711 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
8713 elsif Nkind
(E1
) in N_Op
and then Nkind
(E2
) = N_Function_Call
then
8714 return FCO
(E1
, E2
);
8716 elsif Nkind
(E2
) in N_Op
and then Nkind
(E1
) = N_Function_Call
then
8717 return FCO
(E2
, E1
);
8719 -- Otherwise we must have the same syntactic entity
8721 elsif Nkind
(E1
) /= Nkind
(E2
) then
8724 -- At this point, we specialize by node type
8730 FCL
(Expressions
(E1
), Expressions
(E2
))
8732 FCL
(Component_Associations
(E1
),
8733 Component_Associations
(E2
));
8736 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
8738 Nkind
(Expression
(E2
)) = N_Qualified_Expression
8740 return FCE
(Expression
(E1
), Expression
(E2
));
8742 -- Check that the subtype marks and any constraints
8747 Indic1
: constant Node_Id
:= Expression
(E1
);
8748 Indic2
: constant Node_Id
:= Expression
(E2
);
8753 if Nkind
(Indic1
) /= N_Subtype_Indication
then
8755 Nkind
(Indic2
) /= N_Subtype_Indication
8756 and then Entity
(Indic1
) = Entity
(Indic2
);
8758 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
8760 Nkind
(Indic1
) /= N_Subtype_Indication
8761 and then Entity
(Indic1
) = Entity
(Indic2
);
8764 if Entity
(Subtype_Mark
(Indic1
)) /=
8765 Entity
(Subtype_Mark
(Indic2
))
8770 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
8771 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
8772 while Present
(Elt1
) and then Present
(Elt2
) loop
8773 if not FCE
(Elt1
, Elt2
) then
8786 when N_Attribute_Reference
=>
8788 Attribute_Name
(E1
) = Attribute_Name
(E2
)
8789 and then FCL
(Expressions
(E1
), Expressions
(E2
));
8793 Entity
(E1
) = Entity
(E2
)
8794 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
8795 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
8797 when N_Membership_Test
8801 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
8803 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
8805 when N_Case_Expression
=>
8811 if not FCE
(Expression
(E1
), Expression
(E2
)) then
8815 Alt1
:= First
(Alternatives
(E1
));
8816 Alt2
:= First
(Alternatives
(E2
));
8818 if Present
(Alt1
) /= Present
(Alt2
) then
8820 elsif No
(Alt1
) then
8824 if not FCE
(Expression
(Alt1
), Expression
(Alt2
))
8825 or else not FCL
(Discrete_Choices
(Alt1
),
8826 Discrete_Choices
(Alt2
))
8837 when N_Character_Literal
=>
8839 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
8841 when N_Component_Association
=>
8843 FCL
(Choices
(E1
), Choices
(E2
))
8845 FCE
(Expression
(E1
), Expression
(E2
));
8847 when N_Explicit_Dereference
=>
8849 FCE
(Prefix
(E1
), Prefix
(E2
));
8851 when N_Extension_Aggregate
=>
8853 FCL
(Expressions
(E1
), Expressions
(E2
))
8854 and then Null_Record_Present
(E1
) =
8855 Null_Record_Present
(E2
)
8856 and then FCL
(Component_Associations
(E1
),
8857 Component_Associations
(E2
));
8859 when N_Function_Call
=>
8861 FCE
(Name
(E1
), Name
(E2
))
8863 FCL
(Parameter_Associations
(E1
),
8864 Parameter_Associations
(E2
));
8866 when N_If_Expression
=>
8868 FCL
(Expressions
(E1
), Expressions
(E2
));
8870 when N_Indexed_Component
=>
8872 FCE
(Prefix
(E1
), Prefix
(E2
))
8874 FCL
(Expressions
(E1
), Expressions
(E2
));
8876 when N_Integer_Literal
=>
8877 return (Intval
(E1
) = Intval
(E2
));
8882 when N_Operator_Symbol
=>
8884 Chars
(E1
) = Chars
(E2
);
8886 when N_Others_Choice
=>
8889 when N_Parameter_Association
=>
8891 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
8892 and then FCE
(Explicit_Actual_Parameter
(E1
),
8893 Explicit_Actual_Parameter
(E2
));
8895 when N_Qualified_Expression
=>
8897 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
8899 FCE
(Expression
(E1
), Expression
(E2
));
8901 when N_Quantified_Expression
=>
8902 if not FCE
(Condition
(E1
), Condition
(E2
)) then
8906 if Present
(Loop_Parameter_Specification
(E1
))
8907 and then Present
(Loop_Parameter_Specification
(E2
))
8910 L1
: constant Node_Id
:=
8911 Loop_Parameter_Specification
(E1
);
8912 L2
: constant Node_Id
:=
8913 Loop_Parameter_Specification
(E2
);
8917 Reverse_Present
(L1
) = Reverse_Present
(L2
)
8919 FCE
(Defining_Identifier
(L1
),
8920 Defining_Identifier
(L2
))
8922 FCE
(Discrete_Subtype_Definition
(L1
),
8923 Discrete_Subtype_Definition
(L2
));
8926 elsif Present
(Iterator_Specification
(E1
))
8927 and then Present
(Iterator_Specification
(E2
))
8930 I1
: constant Node_Id
:= Iterator_Specification
(E1
);
8931 I2
: constant Node_Id
:= Iterator_Specification
(E2
);
8935 FCE
(Defining_Identifier
(I1
),
8936 Defining_Identifier
(I2
))
8938 Of_Present
(I1
) = Of_Present
(I2
)
8940 Reverse_Present
(I1
) = Reverse_Present
(I2
)
8941 and then FCE
(Name
(I1
), Name
(I2
))
8942 and then FCE
(Subtype_Indication
(I1
),
8943 Subtype_Indication
(I2
));
8946 -- The quantified expressions used different specifications to
8947 -- walk their respective ranges.
8955 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
8957 FCE
(High_Bound
(E1
), High_Bound
(E2
));
8959 when N_Real_Literal
=>
8960 return (Realval
(E1
) = Realval
(E2
));
8962 when N_Selected_Component
=>
8964 FCE
(Prefix
(E1
), Prefix
(E2
))
8966 FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
8970 FCE
(Prefix
(E1
), Prefix
(E2
))
8972 FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
8974 when N_String_Literal
=>
8976 S1
: constant String_Id
:= Strval
(E1
);
8977 S2
: constant String_Id
:= Strval
(E2
);
8978 L1
: constant Nat
:= String_Length
(S1
);
8979 L2
: constant Nat
:= String_Length
(S2
);
8986 for J
in 1 .. L1
loop
8987 if Get_String_Char
(S1
, J
) /=
8988 Get_String_Char
(S2
, J
)
8998 when N_Type_Conversion
=>
9000 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
9002 FCE
(Expression
(E1
), Expression
(E2
));
9006 Entity
(E1
) = Entity
(E2
)
9008 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
9010 when N_Unchecked_Type_Conversion
=>
9012 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
9014 FCE
(Expression
(E1
), Expression
(E2
));
9016 -- All other node types cannot appear in this context. Strictly
9017 -- we should raise a fatal internal error. Instead we just ignore
9018 -- the nodes. This means that if anyone makes a mistake in the
9019 -- expander and mucks an expression tree irretrievably, the result
9020 -- will be a failure to detect a (probably very obscure) case
9021 -- of non-conformance, which is better than bombing on some
9022 -- case where two expressions do in fact conform.
9028 end Fully_Conformant_Expressions
;
9030 ----------------------------------------
9031 -- Fully_Conformant_Discrete_Subtypes --
9032 ----------------------------------------
9034 function Fully_Conformant_Discrete_Subtypes
9035 (Given_S1
: Node_Id
;
9036 Given_S2
: Node_Id
) return Boolean
9038 S1
: constant Node_Id
:= Original_Node
(Given_S1
);
9039 S2
: constant Node_Id
:= Original_Node
(Given_S2
);
9041 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean;
9042 -- Special-case for a bound given by a discriminant, which in the body
9043 -- is replaced with the discriminal of the enclosing type.
9045 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean;
9046 -- Check both bounds
9048 -----------------------
9049 -- Conforming_Bounds --
9050 -----------------------
9052 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean is
9054 if Is_Entity_Name
(B1
)
9055 and then Is_Entity_Name
(B2
)
9056 and then Ekind
(Entity
(B1
)) = E_Discriminant
9058 return Chars
(B1
) = Chars
(B2
);
9061 return Fully_Conformant_Expressions
(B1
, B2
);
9063 end Conforming_Bounds
;
9065 -----------------------
9066 -- Conforming_Ranges --
9067 -----------------------
9069 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean is
9072 Conforming_Bounds
(Low_Bound
(R1
), Low_Bound
(R2
))
9074 Conforming_Bounds
(High_Bound
(R1
), High_Bound
(R2
));
9075 end Conforming_Ranges
;
9077 -- Start of processing for Fully_Conformant_Discrete_Subtypes
9080 if Nkind
(S1
) /= Nkind
(S2
) then
9083 elsif Is_Entity_Name
(S1
) then
9084 return Entity
(S1
) = Entity
(S2
);
9086 elsif Nkind
(S1
) = N_Range
then
9087 return Conforming_Ranges
(S1
, S2
);
9089 elsif Nkind
(S1
) = N_Subtype_Indication
then
9091 Entity
(Subtype_Mark
(S1
)) = Entity
(Subtype_Mark
(S2
))
9094 (Range_Expression
(Constraint
(S1
)),
9095 Range_Expression
(Constraint
(S2
)));
9099 end Fully_Conformant_Discrete_Subtypes
;
9101 --------------------
9102 -- Install_Entity --
9103 --------------------
9105 procedure Install_Entity
(E
: Entity_Id
) is
9106 Prev
: constant Entity_Id
:= Current_Entity
(E
);
9108 Set_Is_Immediately_Visible
(E
);
9109 Set_Current_Entity
(E
);
9110 Set_Homonym
(E
, Prev
);
9113 ---------------------
9114 -- Install_Formals --
9115 ---------------------
9117 procedure Install_Formals
(Id
: Entity_Id
) is
9120 F
:= First_Formal
(Id
);
9121 while Present
(F
) loop
9125 end Install_Formals
;
9127 -----------------------------
9128 -- Is_Interface_Conformant --
9129 -----------------------------
9131 function Is_Interface_Conformant
9132 (Tagged_Type
: Entity_Id
;
9133 Iface_Prim
: Entity_Id
;
9134 Prim
: Entity_Id
) return Boolean
9136 -- The operation may in fact be an inherited (implicit) operation
9137 -- rather than the original interface primitive, so retrieve the
9138 -- ultimate ancestor.
9140 Iface
: constant Entity_Id
:=
9141 Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
));
9142 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Prim
);
9144 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
;
9145 -- Return the controlling formal of Prim
9147 ------------------------
9148 -- Controlling_Formal --
9149 ------------------------
9151 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
is
9155 E
:= First_Entity
(Prim
);
9156 while Present
(E
) loop
9157 if Is_Formal
(E
) and then Is_Controlling_Formal
(E
) then
9165 end Controlling_Formal
;
9169 Iface_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Iface_Prim
);
9170 Prim_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Prim
);
9172 -- Start of processing for Is_Interface_Conformant
9175 pragma Assert
(Is_Subprogram
(Iface_Prim
)
9176 and then Is_Subprogram
(Prim
)
9177 and then Is_Dispatching_Operation
(Iface_Prim
)
9178 and then Is_Dispatching_Operation
(Prim
));
9180 pragma Assert
(Is_Interface
(Iface
)
9181 or else (Present
(Alias
(Iface_Prim
))
9184 (Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
)))));
9186 if Prim
= Iface_Prim
9187 or else not Is_Subprogram
(Prim
)
9188 or else Ekind
(Prim
) /= Ekind
(Iface_Prim
)
9189 or else not Is_Dispatching_Operation
(Prim
)
9190 or else Scope
(Prim
) /= Scope
(Tagged_Type
)
9192 or else Base_Type
(Typ
) /= Base_Type
(Tagged_Type
)
9193 or else not Primitive_Names_Match
(Iface_Prim
, Prim
)
9197 -- The mode of the controlling formals must match
9199 elsif Present
(Iface_Ctrl_F
)
9200 and then Present
(Prim_Ctrl_F
)
9201 and then Ekind
(Iface_Ctrl_F
) /= Ekind
(Prim_Ctrl_F
)
9205 -- Case of a procedure, or a function whose result type matches the
9206 -- result type of the interface primitive, or a function that has no
9207 -- controlling result (I or access I).
9209 elsif Ekind
(Iface_Prim
) = E_Procedure
9210 or else Etype
(Prim
) = Etype
(Iface_Prim
)
9211 or else not Has_Controlling_Result
(Prim
)
9213 return Type_Conformant
9214 (Iface_Prim
, Prim
, Skip_Controlling_Formals
=> True);
9216 -- Case of a function returning an interface, or an access to one. Check
9217 -- that the return types correspond.
9219 elsif Implements_Interface
(Typ
, Iface
) then
9220 if (Ekind
(Etype
(Prim
)) = E_Anonymous_Access_Type
)
9222 (Ekind
(Etype
(Iface_Prim
)) = E_Anonymous_Access_Type
)
9227 Type_Conformant
(Prim
, Ultimate_Alias
(Iface_Prim
),
9228 Skip_Controlling_Formals
=> True);
9234 end Is_Interface_Conformant
;
9236 ---------------------------------
9237 -- Is_Non_Overriding_Operation --
9238 ---------------------------------
9240 function Is_Non_Overriding_Operation
9241 (Prev_E
: Entity_Id
;
9242 New_E
: Entity_Id
) return Boolean
9246 G_Typ
: Entity_Id
:= Empty
;
9248 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
9249 -- If F_Type is a derived type associated with a generic actual subtype,
9250 -- then return its Generic_Parent_Type attribute, else return Empty.
9252 function Types_Correspond
9253 (P_Type
: Entity_Id
;
9254 N_Type
: Entity_Id
) return Boolean;
9255 -- Returns true if and only if the types (or designated types in the
9256 -- case of anonymous access types) are the same or N_Type is derived
9257 -- directly or indirectly from P_Type.
9259 -----------------------------
9260 -- Get_Generic_Parent_Type --
9261 -----------------------------
9263 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
9269 if Is_Derived_Type
(F_Typ
)
9270 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
9272 -- The tree must be traversed to determine the parent subtype in
9273 -- the generic unit, which unfortunately isn't always available
9274 -- via semantic attributes. ??? (Note: The use of Original_Node
9275 -- is needed for cases where a full derived type has been
9278 -- If the parent type is a scalar type, the derivation creates
9279 -- an anonymous base type for it, and the source type is its
9282 if Is_Scalar_Type
(F_Typ
)
9283 and then not Comes_From_Source
(F_Typ
)
9287 (Original_Node
(Parent
(First_Subtype
(F_Typ
))));
9289 Defn
:= Type_Definition
(Original_Node
(Parent
(F_Typ
)));
9291 if Nkind
(Defn
) = N_Derived_Type_Definition
then
9292 Indic
:= Subtype_Indication
(Defn
);
9294 if Nkind
(Indic
) = N_Subtype_Indication
then
9295 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
9297 G_Typ
:= Entity
(Indic
);
9300 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
9301 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
9303 return Generic_Parent_Type
(Parent
(G_Typ
));
9309 end Get_Generic_Parent_Type
;
9311 ----------------------
9312 -- Types_Correspond --
9313 ----------------------
9315 function Types_Correspond
9316 (P_Type
: Entity_Id
;
9317 N_Type
: Entity_Id
) return Boolean
9319 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
9320 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
9323 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
9324 Prev_Type
:= Designated_Type
(Prev_Type
);
9327 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
9328 New_Type
:= Designated_Type
(New_Type
);
9331 if Prev_Type
= New_Type
then
9334 elsif not Is_Class_Wide_Type
(New_Type
) then
9335 while Etype
(New_Type
) /= New_Type
loop
9336 New_Type
:= Etype
(New_Type
);
9338 if New_Type
= Prev_Type
then
9344 end Types_Correspond
;
9346 -- Start of processing for Is_Non_Overriding_Operation
9349 -- In the case where both operations are implicit derived subprograms
9350 -- then neither overrides the other. This can only occur in certain
9351 -- obscure cases (e.g., derivation from homographs created in a generic
9354 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
9357 elsif Ekind
(Current_Scope
) = E_Package
9358 and then Is_Generic_Instance
(Current_Scope
)
9359 and then In_Private_Part
(Current_Scope
)
9360 and then Comes_From_Source
(New_E
)
9362 -- We examine the formals and result type of the inherited operation,
9363 -- to determine whether their type is derived from (the instance of)
9364 -- a generic type. The first such formal or result type is the one
9367 Formal
:= First_Formal
(Prev_E
);
9369 while Present
(Formal
) loop
9370 F_Typ
:= Base_Type
(Etype
(Formal
));
9372 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
9373 F_Typ
:= Designated_Type
(F_Typ
);
9376 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
9377 exit when Present
(G_Typ
);
9379 Next_Formal
(Formal
);
9382 -- If the function dispatches on result check the result type
9384 if No
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
9385 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
9392 -- If the generic type is a private type, then the original operation
9393 -- was not overriding in the generic, because there was no primitive
9394 -- operation to override.
9396 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
9397 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
9398 N_Formal_Private_Type_Definition
9402 -- The generic parent type is the ancestor of a formal derived
9403 -- type declaration. We need to check whether it has a primitive
9404 -- operation that should be overridden by New_E in the generic.
9408 P_Formal
: Entity_Id
;
9409 N_Formal
: Entity_Id
;
9413 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
9416 while Present
(Prim_Elt
) loop
9417 P_Prim
:= Node
(Prim_Elt
);
9419 if Chars
(P_Prim
) = Chars
(New_E
)
9420 and then Ekind
(P_Prim
) = Ekind
(New_E
)
9422 P_Formal
:= First_Formal
(P_Prim
);
9423 N_Formal
:= First_Formal
(New_E
);
9424 while Present
(P_Formal
) and then Present
(N_Formal
) loop
9425 P_Typ
:= Etype
(P_Formal
);
9426 N_Typ
:= Etype
(N_Formal
);
9428 if not Types_Correspond
(P_Typ
, N_Typ
) then
9432 Next_Entity
(P_Formal
);
9433 Next_Entity
(N_Formal
);
9436 -- Found a matching primitive operation belonging to the
9437 -- formal ancestor type, so the new subprogram is
9441 and then No
(N_Formal
)
9442 and then (Ekind
(New_E
) /= E_Function
9445 (Etype
(P_Prim
), Etype
(New_E
)))
9451 Next_Elmt
(Prim_Elt
);
9454 -- If no match found, then the new subprogram does not override
9455 -- in the generic (nor in the instance).
9457 -- If the type in question is not abstract, and the subprogram
9458 -- is, this will be an error if the new operation is in the
9459 -- private part of the instance. Emit a warning now, which will
9460 -- make the subsequent error message easier to understand.
9462 if Present
(F_Typ
) and then not Is_Abstract_Type
(F_Typ
)
9463 and then Is_Abstract_Subprogram
(Prev_E
)
9464 and then In_Private_Part
(Current_Scope
)
9466 Error_Msg_Node_2
:= F_Typ
;
9468 ("private operation& in generic unit does not override "
9469 & "any primitive operation of& (RM 12.3 (18))??",
9479 end Is_Non_Overriding_Operation
;
9481 -------------------------------------
9482 -- List_Inherited_Pre_Post_Aspects --
9483 -------------------------------------
9485 procedure List_Inherited_Pre_Post_Aspects
(E
: Entity_Id
) is
9487 if Opt
.List_Inherited_Aspects
9488 and then Is_Subprogram_Or_Generic_Subprogram
(E
)
9491 Subps
: constant Subprogram_List
:= Inherited_Subprograms
(E
);
9496 for Index
in Subps
'Range loop
9497 Items
:= Contract
(Subps
(Index
));
9499 if Present
(Items
) then
9500 Prag
:= Pre_Post_Conditions
(Items
);
9501 while Present
(Prag
) loop
9502 Error_Msg_Sloc
:= Sloc
(Prag
);
9504 if Class_Present
(Prag
)
9505 and then not Split_PPC
(Prag
)
9507 if Pragma_Name
(Prag
) = Name_Precondition
then
9509 ("info: & inherits `Pre''Class` aspect from "
9513 ("info: & inherits `Post''Class` aspect from "
9518 Prag
:= Next_Pragma
(Prag
);
9524 end List_Inherited_Pre_Post_Aspects
;
9526 ------------------------------
9527 -- Make_Inequality_Operator --
9528 ------------------------------
9530 -- S is the defining identifier of an equality operator. We build a
9531 -- subprogram declaration with the right signature. This operation is
9532 -- intrinsic, because it is always expanded as the negation of the
9533 -- call to the equality function.
9535 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
9536 Loc
: constant Source_Ptr
:= Sloc
(S
);
9539 Op_Name
: Entity_Id
;
9541 FF
: constant Entity_Id
:= First_Formal
(S
);
9542 NF
: constant Entity_Id
:= Next_Formal
(FF
);
9545 -- Check that equality was properly defined, ignore call if not
9552 A
: constant Entity_Id
:=
9553 Make_Defining_Identifier
(Sloc
(FF
),
9554 Chars
=> Chars
(FF
));
9556 B
: constant Entity_Id
:=
9557 Make_Defining_Identifier
(Sloc
(NF
),
9558 Chars
=> Chars
(NF
));
9561 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
9563 Formals
:= New_List
(
9564 Make_Parameter_Specification
(Loc
,
9565 Defining_Identifier
=> A
,
9567 New_Occurrence_Of
(Etype
(First_Formal
(S
)),
9568 Sloc
(Etype
(First_Formal
(S
))))),
9570 Make_Parameter_Specification
(Loc
,
9571 Defining_Identifier
=> B
,
9573 New_Occurrence_Of
(Etype
(Next_Formal
(First_Formal
(S
))),
9574 Sloc
(Etype
(Next_Formal
(First_Formal
(S
)))))));
9577 Make_Subprogram_Declaration
(Loc
,
9579 Make_Function_Specification
(Loc
,
9580 Defining_Unit_Name
=> Op_Name
,
9581 Parameter_Specifications
=> Formals
,
9582 Result_Definition
=>
9583 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
9585 -- Insert inequality right after equality if it is explicit or after
9586 -- the derived type when implicit. These entities are created only
9587 -- for visibility purposes, and eventually replaced in the course
9588 -- of expansion, so they do not need to be attached to the tree and
9589 -- seen by the back-end. Keeping them internal also avoids spurious
9590 -- freezing problems. The declaration is inserted in the tree for
9591 -- analysis, and removed afterwards. If the equality operator comes
9592 -- from an explicit declaration, attach the inequality immediately
9593 -- after. Else the equality is inherited from a derived type
9594 -- declaration, so insert inequality after that declaration.
9596 if No
(Alias
(S
)) then
9597 Insert_After
(Unit_Declaration_Node
(S
), Decl
);
9598 elsif Is_List_Member
(Parent
(S
)) then
9599 Insert_After
(Parent
(S
), Decl
);
9601 Insert_After
(Parent
(Etype
(First_Formal
(S
))), Decl
);
9604 Mark_Rewrite_Insertion
(Decl
);
9605 Set_Is_Intrinsic_Subprogram
(Op_Name
);
9608 Set_Has_Completion
(Op_Name
);
9609 Set_Corresponding_Equality
(Op_Name
, S
);
9610 Set_Is_Abstract_Subprogram
(Op_Name
, Is_Abstract_Subprogram
(S
));
9612 end Make_Inequality_Operator
;
9614 ----------------------
9615 -- May_Need_Actuals --
9616 ----------------------
9618 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
9623 F
:= First_Formal
(Fun
);
9625 while Present
(F
) loop
9626 if No
(Default_Value
(F
)) then
9634 Set_Needs_No_Actuals
(Fun
, B
);
9635 end May_Need_Actuals
;
9637 ---------------------
9638 -- Mode_Conformant --
9639 ---------------------
9641 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
9644 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
9646 end Mode_Conformant
;
9648 ---------------------------
9649 -- New_Overloaded_Entity --
9650 ---------------------------
9652 procedure New_Overloaded_Entity
9654 Derived_Type
: Entity_Id
:= Empty
)
9656 Overridden_Subp
: Entity_Id
:= Empty
;
9657 -- Set if the current scope has an operation that is type-conformant
9658 -- with S, and becomes hidden by S.
9660 Is_Primitive_Subp
: Boolean;
9661 -- Set to True if the new subprogram is primitive
9664 -- Entity that S overrides
9666 Prev_Vis
: Entity_Id
:= Empty
;
9667 -- Predecessor of E in Homonym chain
9669 procedure Check_For_Primitive_Subprogram
9670 (Is_Primitive
: out Boolean;
9671 Is_Overriding
: Boolean := False);
9672 -- If the subprogram being analyzed is a primitive operation of the type
9673 -- of a formal or result, set the Has_Primitive_Operations flag on the
9674 -- type, and set Is_Primitive to True (otherwise set to False). Set the
9675 -- corresponding flag on the entity itself for later use.
9677 function Has_Matching_Entry_Or_Subprogram
(E
: Entity_Id
) return Boolean;
9678 -- True if a) E is a subprogram whose first formal is a concurrent type
9679 -- defined in the scope of E that has some entry or subprogram whose
9680 -- profile matches E, or b) E is an internally built dispatching
9681 -- subprogram of a protected type and there is a matching subprogram
9682 -- defined in the enclosing scope of the protected type, or c) E is
9683 -- an entry of a synchronized type and a matching procedure has been
9684 -- previously defined in the enclosing scope of the synchronized type.
9686 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
9687 -- Check that E is declared in the private part of the current package,
9688 -- or in the package body, where it may hide a previous declaration.
9689 -- We can't use In_Private_Part by itself because this flag is also
9690 -- set when freezing entities, so we must examine the place of the
9691 -- declaration in the tree, and recognize wrapper packages as well.
9693 function Is_Overriding_Alias
9695 New_E
: Entity_Id
) return Boolean;
9696 -- Check whether new subprogram and old subprogram are both inherited
9697 -- from subprograms that have distinct dispatch table entries. This can
9698 -- occur with derivations from instances with accidental homonyms. The
9699 -- function is conservative given that the converse is only true within
9700 -- instances that contain accidental overloadings.
9702 procedure Report_Conflict
(S
: Entity_Id
; E
: Entity_Id
);
9703 -- Report conflict between entities S and E
9705 ------------------------------------
9706 -- Check_For_Primitive_Subprogram --
9707 ------------------------------------
9709 procedure Check_For_Primitive_Subprogram
9710 (Is_Primitive
: out Boolean;
9711 Is_Overriding
: Boolean := False)
9717 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
9718 -- Returns true if T is declared in the visible part of the current
9719 -- package scope; otherwise returns false. Assumes that T is declared
9722 procedure Check_Private_Overriding
(T
: Entity_Id
);
9723 -- Checks that if a primitive abstract subprogram of a visible
9724 -- abstract type is declared in a private part, then it must override
9725 -- an abstract subprogram declared in the visible part. Also checks
9726 -- that if a primitive function with a controlling result is declared
9727 -- in a private part, then it must override a function declared in
9728 -- the visible part.
9730 ------------------------------
9731 -- Check_Private_Overriding --
9732 ------------------------------
9734 procedure Check_Private_Overriding
(T
: Entity_Id
) is
9735 function Overrides_Private_Part_Op
return Boolean;
9736 -- This detects the special case where the overriding subprogram
9737 -- is overriding a subprogram that was declared in the same
9738 -- private part. That case is illegal by 3.9.3(10).
9740 function Overrides_Visible_Function
9741 (Partial_View
: Entity_Id
) return Boolean;
9742 -- True if S overrides a function in the visible part. The
9743 -- overridden function could be explicitly or implicitly declared.
9745 -------------------------------
9746 -- Overrides_Private_Part_Op --
9747 -------------------------------
9749 function Overrides_Private_Part_Op
return Boolean is
9750 Over_Decl
: constant Node_Id
:=
9751 Unit_Declaration_Node
(Overridden_Operation
(S
));
9752 Subp_Decl
: constant Node_Id
:= Unit_Declaration_Node
(S
);
9755 pragma Assert
(Is_Overriding
);
9757 (Nkind
(Over_Decl
) = N_Abstract_Subprogram_Declaration
);
9759 (Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
);
9761 return In_Same_List
(Over_Decl
, Subp_Decl
);
9762 end Overrides_Private_Part_Op
;
9764 --------------------------------
9765 -- Overrides_Visible_Function --
9766 --------------------------------
9768 function Overrides_Visible_Function
9769 (Partial_View
: Entity_Id
) return Boolean
9772 if not Is_Overriding
or else not Has_Homonym
(S
) then
9776 if not Present
(Partial_View
) then
9780 -- Search through all the homonyms H of S in the current
9781 -- package spec, and return True if we find one that matches.
9782 -- Note that Parent (H) will be the declaration of the
9783 -- partial view of T for a match.
9790 exit when not Present
(H
) or else Scope
(H
) /= Scope
(S
);
9794 N_Private_Extension_Declaration
,
9795 N_Private_Type_Declaration
)
9796 and then Defining_Identifier
(Parent
(H
)) = Partial_View
9804 end Overrides_Visible_Function
;
9806 -- Start of processing for Check_Private_Overriding
9809 if Is_Package_Or_Generic_Package
(Current_Scope
)
9810 and then In_Private_Part
(Current_Scope
)
9811 and then Visible_Part_Type
(T
)
9812 and then not In_Instance
9814 if Is_Abstract_Type
(T
)
9815 and then Is_Abstract_Subprogram
(S
)
9816 and then (not Is_Overriding
9817 or else not Is_Abstract_Subprogram
(E
)
9818 or else Overrides_Private_Part_Op
)
9821 ("abstract subprograms must be visible (RM 3.9.3(10))!",
9824 elsif Ekind
(S
) = E_Function
then
9826 Partial_View
: constant Entity_Id
:=
9827 Incomplete_Or_Partial_View
(T
);
9830 if not Overrides_Visible_Function
(Partial_View
) then
9832 -- Here, S is "function ... return T;" declared in
9833 -- the private part, not overriding some visible
9834 -- operation. That's illegal in the tagged case
9835 -- (but not if the private type is untagged).
9837 if ((Present
(Partial_View
)
9838 and then Is_Tagged_Type
(Partial_View
))
9839 or else (not Present
(Partial_View
)
9840 and then Is_Tagged_Type
(T
)))
9841 and then T
= Base_Type
(Etype
(S
))
9844 ("private function with tagged result must"
9845 & " override visible-part function", S
);
9847 ("\move subprogram to the visible part"
9848 & " (RM 3.9.3(10))", S
);
9850 -- AI05-0073: extend this test to the case of a
9851 -- function with a controlling access result.
9853 elsif Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
9854 and then Is_Tagged_Type
(Designated_Type
(Etype
(S
)))
9856 not Is_Class_Wide_Type
9857 (Designated_Type
(Etype
(S
)))
9858 and then Ada_Version
>= Ada_2012
9861 ("private function with controlling access "
9862 & "result must override visible-part function",
9865 ("\move subprogram to the visible part"
9866 & " (RM 3.9.3(10))", S
);
9872 end Check_Private_Overriding
;
9874 -----------------------
9875 -- Visible_Part_Type --
9876 -----------------------
9878 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
9879 P
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
9883 -- If the entity is a private type, then it must be declared in a
9886 if Ekind
(T
) in Private_Kind
then
9890 -- Otherwise, we traverse the visible part looking for its
9891 -- corresponding declaration. We cannot use the declaration
9892 -- node directly because in the private part the entity of a
9893 -- private type is the one in the full view, which does not
9894 -- indicate that it is the completion of something visible.
9896 N
:= First
(Visible_Declarations
(Specification
(P
)));
9897 while Present
(N
) loop
9898 if Nkind
(N
) = N_Full_Type_Declaration
9899 and then Present
(Defining_Identifier
(N
))
9900 and then T
= Defining_Identifier
(N
)
9904 elsif Nkind_In
(N
, N_Private_Type_Declaration
,
9905 N_Private_Extension_Declaration
)
9906 and then Present
(Defining_Identifier
(N
))
9907 and then T
= Full_View
(Defining_Identifier
(N
))
9916 end Visible_Part_Type
;
9918 -- Start of processing for Check_For_Primitive_Subprogram
9921 Is_Primitive
:= False;
9923 if not Comes_From_Source
(S
) then
9926 -- If subprogram is at library level, it is not primitive operation
9928 elsif Current_Scope
= Standard_Standard
then
9931 elsif (Is_Package_Or_Generic_Package
(Current_Scope
)
9932 and then not In_Package_Body
(Current_Scope
))
9933 or else Is_Overriding
9935 -- For function, check return type
9937 if Ekind
(S
) = E_Function
then
9938 if Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
then
9939 F_Typ
:= Designated_Type
(Etype
(S
));
9944 B_Typ
:= Base_Type
(F_Typ
);
9946 if Scope
(B_Typ
) = Current_Scope
9947 and then not Is_Class_Wide_Type
(B_Typ
)
9948 and then not Is_Generic_Type
(B_Typ
)
9950 Is_Primitive
:= True;
9951 Set_Has_Primitive_Operations
(B_Typ
);
9952 Set_Is_Primitive
(S
);
9953 Check_Private_Overriding
(B_Typ
);
9955 -- The Ghost policy in effect at the point of declaration
9956 -- or a tagged type and a primitive operation must match
9957 -- (SPARK RM 6.9(16)).
9959 Check_Ghost_Primitive
(S
, B_Typ
);
9963 -- For all subprograms, check formals
9965 Formal
:= First_Formal
(S
);
9966 while Present
(Formal
) loop
9967 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
9968 F_Typ
:= Designated_Type
(Etype
(Formal
));
9970 F_Typ
:= Etype
(Formal
);
9973 B_Typ
:= Base_Type
(F_Typ
);
9975 if Ekind
(B_Typ
) = E_Access_Subtype
then
9976 B_Typ
:= Base_Type
(B_Typ
);
9979 if Scope
(B_Typ
) = Current_Scope
9980 and then not Is_Class_Wide_Type
(B_Typ
)
9981 and then not Is_Generic_Type
(B_Typ
)
9983 Is_Primitive
:= True;
9984 Set_Is_Primitive
(S
);
9985 Set_Has_Primitive_Operations
(B_Typ
);
9986 Check_Private_Overriding
(B_Typ
);
9988 -- The Ghost policy in effect at the point of declaration
9989 -- of a tagged type and a primitive operation must match
9990 -- (SPARK RM 6.9(16)).
9992 Check_Ghost_Primitive
(S
, B_Typ
);
9995 Next_Formal
(Formal
);
9998 -- Special case: An equality function can be redefined for a type
9999 -- occurring in a declarative part, and won't otherwise be treated as
10000 -- a primitive because it doesn't occur in a package spec and doesn't
10001 -- override an inherited subprogram. It's important that we mark it
10002 -- primitive so it can be returned by Collect_Primitive_Operations
10003 -- and be used in composing the equality operation of later types
10004 -- that have a component of the type.
10006 elsif Chars
(S
) = Name_Op_Eq
10007 and then Etype
(S
) = Standard_Boolean
10009 B_Typ
:= Base_Type
(Etype
(First_Formal
(S
)));
10011 if Scope
(B_Typ
) = Current_Scope
10013 Base_Type
(Etype
(Next_Formal
(First_Formal
(S
)))) = B_Typ
10014 and then not Is_Limited_Type
(B_Typ
)
10016 Is_Primitive
:= True;
10017 Set_Is_Primitive
(S
);
10018 Set_Has_Primitive_Operations
(B_Typ
);
10019 Check_Private_Overriding
(B_Typ
);
10021 -- The Ghost policy in effect at the point of declaration of a
10022 -- tagged type and a primitive operation must match
10023 -- (SPARK RM 6.9(16)).
10025 Check_Ghost_Primitive
(S
, B_Typ
);
10028 end Check_For_Primitive_Subprogram
;
10030 --------------------------------------
10031 -- Has_Matching_Entry_Or_Subprogram --
10032 --------------------------------------
10034 function Has_Matching_Entry_Or_Subprogram
10035 (E
: Entity_Id
) return Boolean
10037 function Check_Conforming_Parameters
10038 (E1_Param
: Node_Id
;
10039 E2_Param
: Node_Id
) return Boolean;
10040 -- Starting from the given parameters, check that all the parameters
10041 -- of two entries or subprograms are subtype conformant. Used to skip
10042 -- the check on the controlling argument.
10044 function Matching_Entry_Or_Subprogram
10045 (Conc_Typ
: Entity_Id
;
10046 Subp
: Entity_Id
) return Entity_Id
;
10047 -- Return the first entry or subprogram of the given concurrent type
10048 -- whose name matches the name of Subp and has a profile conformant
10049 -- with Subp; return Empty if not found.
10051 function Matching_Dispatching_Subprogram
10052 (Conc_Typ
: Entity_Id
;
10053 Ent
: Entity_Id
) return Entity_Id
;
10054 -- Return the first dispatching primitive of Conc_Type defined in the
10055 -- enclosing scope of Conc_Type (i.e. before the full definition of
10056 -- this concurrent type) whose name matches the entry Ent and has a
10057 -- profile conformant with the profile of the corresponding (not yet
10058 -- built) dispatching primitive of Ent; return Empty if not found.
10060 function Matching_Original_Protected_Subprogram
10061 (Prot_Typ
: Entity_Id
;
10062 Subp
: Entity_Id
) return Entity_Id
;
10063 -- Return the first subprogram defined in the enclosing scope of
10064 -- Prot_Typ (before the full definition of this protected type)
10065 -- whose name matches the original name of Subp and has a profile
10066 -- conformant with the profile of Subp; return Empty if not found.
10068 ---------------------------------
10069 -- Check_Confirming_Parameters --
10070 ---------------------------------
10072 function Check_Conforming_Parameters
10073 (E1_Param
: Node_Id
;
10074 E2_Param
: Node_Id
) return Boolean
10076 Param_E1
: Node_Id
:= E1_Param
;
10077 Param_E2
: Node_Id
:= E2_Param
;
10080 while Present
(Param_E1
) and then Present
(Param_E2
) loop
10081 if Ekind
(Defining_Identifier
(Param_E1
)) /=
10082 Ekind
(Defining_Identifier
(Param_E2
))
10085 (Find_Parameter_Type
(Param_E1
),
10086 Find_Parameter_Type
(Param_E2
),
10087 Subtype_Conformant
)
10096 -- The candidate is not valid if one of the two lists contains
10097 -- more parameters than the other
10099 return No
(Param_E1
) and then No
(Param_E2
);
10100 end Check_Conforming_Parameters
;
10102 ----------------------------------
10103 -- Matching_Entry_Or_Subprogram --
10104 ----------------------------------
10106 function Matching_Entry_Or_Subprogram
10107 (Conc_Typ
: Entity_Id
;
10108 Subp
: Entity_Id
) return Entity_Id
10113 E
:= First_Entity
(Conc_Typ
);
10114 while Present
(E
) loop
10115 if Chars
(Subp
) = Chars
(E
)
10116 and then (Ekind
(E
) = E_Entry
or else Is_Subprogram
(E
))
10118 Check_Conforming_Parameters
10119 (First
(Parameter_Specifications
(Parent
(E
))),
10120 Next
(First
(Parameter_Specifications
(Parent
(Subp
)))))
10129 end Matching_Entry_Or_Subprogram
;
10131 -------------------------------------
10132 -- Matching_Dispatching_Subprogram --
10133 -------------------------------------
10135 function Matching_Dispatching_Subprogram
10136 (Conc_Typ
: Entity_Id
;
10137 Ent
: Entity_Id
) return Entity_Id
10142 -- Search for entities in the enclosing scope of this synchonized
10145 pragma Assert
(Is_Concurrent_Type
(Conc_Typ
));
10146 Push_Scope
(Scope
(Conc_Typ
));
10147 E
:= Current_Entity_In_Scope
(Ent
);
10150 while Present
(E
) loop
10151 if Scope
(E
) = Scope
(Conc_Typ
)
10152 and then Comes_From_Source
(E
)
10153 and then Ekind
(E
) = E_Procedure
10154 and then Present
(First_Entity
(E
))
10155 and then Is_Controlling_Formal
(First_Entity
(E
))
10156 and then Etype
(First_Entity
(E
)) = Conc_Typ
10158 Check_Conforming_Parameters
10159 (First
(Parameter_Specifications
(Parent
(Ent
))),
10160 Next
(First
(Parameter_Specifications
(Parent
(E
)))))
10169 end Matching_Dispatching_Subprogram
;
10171 --------------------------------------------
10172 -- Matching_Original_Protected_Subprogram --
10173 --------------------------------------------
10175 function Matching_Original_Protected_Subprogram
10176 (Prot_Typ
: Entity_Id
;
10177 Subp
: Entity_Id
) return Entity_Id
10179 ICF
: constant Boolean :=
10180 Is_Controlling_Formal
(First_Entity
(Subp
));
10184 -- Temporarily decorate the first parameter of Subp as controlling
10185 -- formal, required to invoke Subtype_Conformant.
10187 Set_Is_Controlling_Formal
(First_Entity
(Subp
));
10190 Current_Entity_In_Scope
(Original_Protected_Subprogram
(Subp
));
10192 while Present
(E
) loop
10193 if Scope
(E
) = Scope
(Prot_Typ
)
10194 and then Comes_From_Source
(E
)
10195 and then Ekind
(Subp
) = Ekind
(E
)
10196 and then Present
(First_Entity
(E
))
10197 and then Is_Controlling_Formal
(First_Entity
(E
))
10198 and then Etype
(First_Entity
(E
)) = Prot_Typ
10199 and then Subtype_Conformant
(Subp
, E
,
10200 Skip_Controlling_Formals
=> True)
10202 Set_Is_Controlling_Formal
(First_Entity
(Subp
), ICF
);
10209 Set_Is_Controlling_Formal
(First_Entity
(Subp
), ICF
);
10212 end Matching_Original_Protected_Subprogram
;
10214 -- Start of processing for Has_Matching_Entry_Or_Subprogram
10217 -- Case 1: E is a subprogram whose first formal is a concurrent type
10218 -- defined in the scope of E that has an entry or subprogram whose
10219 -- profile matches E.
10221 if Comes_From_Source
(E
)
10222 and then Is_Subprogram
(E
)
10223 and then Present
(First_Entity
(E
))
10224 and then Is_Concurrent_Record_Type
(Etype
(First_Entity
(E
)))
10227 Scope
(Corresponding_Concurrent_Type
10228 (Etype
(First_Entity
(E
))))
10231 (Matching_Entry_Or_Subprogram
10232 (Corresponding_Concurrent_Type
(Etype
(First_Entity
(E
))),
10235 Report_Conflict
(E
,
10236 Matching_Entry_Or_Subprogram
10237 (Corresponding_Concurrent_Type
(Etype
(First_Entity
(E
))),
10242 -- Case 2: E is an internally built dispatching subprogram of a
10243 -- protected type and there is a subprogram defined in the enclosing
10244 -- scope of the protected type that has the original name of E and
10245 -- its profile is conformant with the profile of E. We check the
10246 -- name of the original protected subprogram associated with E since
10247 -- the expander builds dispatching primitives of protected functions
10248 -- and procedures with other names (see Exp_Ch9.Build_Selected_Name).
10250 elsif not Comes_From_Source
(E
)
10251 and then Is_Subprogram
(E
)
10252 and then Present
(First_Entity
(E
))
10253 and then Is_Concurrent_Record_Type
(Etype
(First_Entity
(E
)))
10254 and then Present
(Original_Protected_Subprogram
(E
))
10257 (Matching_Original_Protected_Subprogram
10258 (Corresponding_Concurrent_Type
(Etype
(First_Entity
(E
))),
10261 Report_Conflict
(E
,
10262 Matching_Original_Protected_Subprogram
10263 (Corresponding_Concurrent_Type
(Etype
(First_Entity
(E
))),
10267 -- Case 3: E is an entry of a synchronized type and a matching
10268 -- procedure has been previously defined in the enclosing scope
10269 -- of the synchronized type.
10271 elsif Comes_From_Source
(E
)
10272 and then Ekind
(E
) = E_Entry
10274 Present
(Matching_Dispatching_Subprogram
(Current_Scope
, E
))
10276 Report_Conflict
(E
,
10277 Matching_Dispatching_Subprogram
(Current_Scope
, E
));
10282 end Has_Matching_Entry_Or_Subprogram
;
10284 ----------------------------
10285 -- Is_Private_Declaration --
10286 ----------------------------
10288 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
10289 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
10290 Priv_Decls
: List_Id
;
10293 if Is_Package_Or_Generic_Package
(Current_Scope
)
10294 and then In_Private_Part
(Current_Scope
)
10297 Private_Declarations
(Package_Specification
(Current_Scope
));
10299 return In_Package_Body
(Current_Scope
)
10301 (Is_List_Member
(Decl
)
10302 and then List_Containing
(Decl
) = Priv_Decls
)
10303 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
10305 Is_Compilation_Unit
10306 (Defining_Entity
(Parent
(Decl
)))
10307 and then List_Containing
(Parent
(Parent
(Decl
))) =
10312 end Is_Private_Declaration
;
10314 --------------------------
10315 -- Is_Overriding_Alias --
10316 --------------------------
10318 function Is_Overriding_Alias
10319 (Old_E
: Entity_Id
;
10320 New_E
: Entity_Id
) return Boolean
10322 AO
: constant Entity_Id
:= Alias
(Old_E
);
10323 AN
: constant Entity_Id
:= Alias
(New_E
);
10326 return Scope
(AO
) /= Scope
(AN
)
10327 or else No
(DTC_Entity
(AO
))
10328 or else No
(DTC_Entity
(AN
))
10329 or else DT_Position
(AO
) = DT_Position
(AN
);
10330 end Is_Overriding_Alias
;
10332 ---------------------
10333 -- Report_Conflict --
10334 ---------------------
10336 procedure Report_Conflict
(S
: Entity_Id
; E
: Entity_Id
) is
10338 Error_Msg_Sloc
:= Sloc
(E
);
10340 -- Generate message, with useful additional warning if in generic
10342 if Is_Generic_Unit
(E
) then
10343 Error_Msg_N
("previous generic unit cannot be overloaded", S
);
10344 Error_Msg_N
("\& conflicts with declaration#", S
);
10346 Error_Msg_N
("& conflicts with declaration#", S
);
10348 end Report_Conflict
;
10350 -- Start of processing for New_Overloaded_Entity
10353 -- We need to look for an entity that S may override. This must be a
10354 -- homonym in the current scope, so we look for the first homonym of
10355 -- S in the current scope as the starting point for the search.
10357 E
:= Current_Entity_In_Scope
(S
);
10359 -- Ada 2005 (AI-251): Derivation of abstract interface primitives.
10360 -- They are directly added to the list of primitive operations of
10361 -- Derived_Type, unless this is a rederivation in the private part
10362 -- of an operation that was already derived in the visible part of
10363 -- the current package.
10365 if Ada_Version
>= Ada_2005
10366 and then Present
(Derived_Type
)
10367 and then Present
(Alias
(S
))
10368 and then Is_Dispatching_Operation
(Alias
(S
))
10369 and then Present
(Find_Dispatching_Type
(Alias
(S
)))
10370 and then Is_Interface
(Find_Dispatching_Type
(Alias
(S
)))
10372 -- For private types, when the full-view is processed we propagate to
10373 -- the full view the non-overridden entities whose attribute "alias"
10374 -- references an interface primitive. These entities were added by
10375 -- Derive_Subprograms to ensure that interface primitives are
10378 -- Inside_Freeze_Actions is non zero when S corresponds with an
10379 -- internal entity that links an interface primitive with its
10380 -- covering primitive through attribute Interface_Alias (see
10381 -- Add_Internal_Interface_Entities).
10383 if Inside_Freezing_Actions
= 0
10384 and then Is_Package_Or_Generic_Package
(Current_Scope
)
10385 and then In_Private_Part
(Current_Scope
)
10386 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
10387 and then Nkind
(Parent
(S
)) = N_Full_Type_Declaration
10388 and then Full_View
(Defining_Identifier
(Parent
(E
)))
10389 = Defining_Identifier
(Parent
(S
))
10390 and then Alias
(E
) = Alias
(S
)
10392 Check_Operation_From_Private_View
(S
, E
);
10393 Set_Is_Dispatching_Operation
(S
);
10398 Enter_Overloaded_Entity
(S
);
10399 Check_Dispatching_Operation
(S
, Empty
);
10400 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
10406 -- For synchronized types check conflicts of this entity with previously
10407 -- defined entities.
10409 if Ada_Version
>= Ada_2005
10410 and then Has_Matching_Entry_Or_Subprogram
(S
)
10415 -- If there is no homonym then this is definitely not overriding
10418 Enter_Overloaded_Entity
(S
);
10419 Check_Dispatching_Operation
(S
, Empty
);
10420 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
10422 -- If subprogram has an explicit declaration, check whether it has an
10423 -- overriding indicator.
10425 if Comes_From_Source
(S
) then
10426 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
10428 -- (Ada 2012: AI05-0125-1): If S is a dispatching operation then
10429 -- it may have overridden some hidden inherited primitive. Update
10430 -- Overridden_Subp to avoid spurious errors when checking the
10431 -- overriding indicator.
10433 if Ada_Version
>= Ada_2012
10434 and then No
(Overridden_Subp
)
10435 and then Is_Dispatching_Operation
(S
)
10436 and then Present
(Overridden_Operation
(S
))
10438 Overridden_Subp
:= Overridden_Operation
(S
);
10441 Check_Overriding_Indicator
10442 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
10444 -- The Ghost policy in effect at the point of declaration of a
10445 -- parent subprogram and an overriding subprogram must match
10446 -- (SPARK RM 6.9(17)).
10448 Check_Ghost_Overriding
(S
, Overridden_Subp
);
10451 -- If there is a homonym that is not overloadable, then we have an
10452 -- error, except for the special cases checked explicitly below.
10454 elsif not Is_Overloadable
(E
) then
10456 -- Check for spurious conflict produced by a subprogram that has the
10457 -- same name as that of the enclosing generic package. The conflict
10458 -- occurs within an instance, between the subprogram and the renaming
10459 -- declaration for the package. After the subprogram, the package
10460 -- renaming declaration becomes hidden.
10462 if Ekind
(E
) = E_Package
10463 and then Present
(Renamed_Object
(E
))
10464 and then Renamed_Object
(E
) = Current_Scope
10465 and then Nkind
(Parent
(Renamed_Object
(E
))) =
10466 N_Package_Specification
10467 and then Present
(Generic_Parent
(Parent
(Renamed_Object
(E
))))
10470 Set_Is_Immediately_Visible
(E
, False);
10471 Enter_Overloaded_Entity
(S
);
10472 Set_Homonym
(S
, Homonym
(E
));
10473 Check_Dispatching_Operation
(S
, Empty
);
10474 Check_Overriding_Indicator
(S
, Empty
, Is_Primitive
=> False);
10476 -- If the subprogram is implicit it is hidden by the previous
10477 -- declaration. However if it is dispatching, it must appear in the
10478 -- dispatch table anyway, because it can be dispatched to even if it
10479 -- cannot be called directly.
10481 elsif Present
(Alias
(S
)) and then not Comes_From_Source
(S
) then
10482 Set_Scope
(S
, Current_Scope
);
10484 if Is_Dispatching_Operation
(Alias
(S
)) then
10485 Check_Dispatching_Operation
(S
, Empty
);
10491 Report_Conflict
(S
, E
);
10495 -- E exists and is overloadable
10498 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
10500 -- Loop through E and its homonyms to determine if any of them is
10501 -- the candidate for overriding by S.
10503 while Present
(E
) loop
10505 -- Definitely not interesting if not in the current scope
10507 if Scope
(E
) /= Current_Scope
then
10510 -- A function can overload the name of an abstract state. The
10511 -- state can be viewed as a function with a profile that cannot
10512 -- be matched by anything.
10514 elsif Ekind
(S
) = E_Function
10515 and then Ekind
(E
) = E_Abstract_State
10517 Enter_Overloaded_Entity
(S
);
10520 -- Ada 2012 (AI05-0165): For internally generated bodies of null
10521 -- procedures locate the internally generated spec. We enforce
10522 -- mode conformance since a tagged type may inherit from
10523 -- interfaces several null primitives which differ only in
10524 -- the mode of the formals.
10526 elsif not Comes_From_Source
(S
)
10527 and then Is_Null_Procedure
(S
)
10528 and then not Mode_Conformant
(E
, S
)
10532 -- Check if we have type conformance
10534 elsif Type_Conformant
(E
, S
) then
10536 -- If the old and new entities have the same profile and one
10537 -- is not the body of the other, then this is an error, unless
10538 -- one of them is implicitly declared.
10540 -- There are some cases when both can be implicit, for example
10541 -- when both a literal and a function that overrides it are
10542 -- inherited in a derivation, or when an inherited operation
10543 -- of a tagged full type overrides the inherited operation of
10544 -- a private extension. Ada 83 had a special rule for the
10545 -- literal case. In Ada 95, the later implicit operation hides
10546 -- the former, and the literal is always the former. In the
10547 -- odd case where both are derived operations declared at the
10548 -- same point, both operations should be declared, and in that
10549 -- case we bypass the following test and proceed to the next
10550 -- part. This can only occur for certain obscure cases in
10551 -- instances, when an operation on a type derived from a formal
10552 -- private type does not override a homograph inherited from
10553 -- the actual. In subsequent derivations of such a type, the
10554 -- DT positions of these operations remain distinct, if they
10557 if Present
(Alias
(S
))
10558 and then (No
(Alias
(E
))
10559 or else Comes_From_Source
(E
)
10560 or else Is_Abstract_Subprogram
(S
)
10562 (Is_Dispatching_Operation
(E
)
10563 and then Is_Overriding_Alias
(E
, S
)))
10564 and then Ekind
(E
) /= E_Enumeration_Literal
10566 -- When an derived operation is overloaded it may be due to
10567 -- the fact that the full view of a private extension
10568 -- re-inherits. It has to be dealt with.
10570 if Is_Package_Or_Generic_Package
(Current_Scope
)
10571 and then In_Private_Part
(Current_Scope
)
10573 Check_Operation_From_Private_View
(S
, E
);
10576 -- In any case the implicit operation remains hidden by the
10577 -- existing declaration, which is overriding. Indicate that
10578 -- E overrides the operation from which S is inherited.
10580 if Present
(Alias
(S
)) then
10581 Set_Overridden_Operation
(E
, Alias
(S
));
10582 Inherit_Subprogram_Contract
(E
, Alias
(S
));
10585 Set_Overridden_Operation
(E
, S
);
10586 Inherit_Subprogram_Contract
(E
, S
);
10589 if Comes_From_Source
(E
) then
10590 Check_Overriding_Indicator
(E
, S
, Is_Primitive
=> False);
10592 -- The Ghost policy in effect at the point of declaration
10593 -- of a parent subprogram and an overriding subprogram
10594 -- must match (SPARK RM 6.9(17)).
10596 Check_Ghost_Overriding
(E
, S
);
10601 -- Within an instance, the renaming declarations for actual
10602 -- subprograms may become ambiguous, but they do not hide each
10605 elsif Ekind
(E
) /= E_Entry
10606 and then not Comes_From_Source
(E
)
10607 and then not Is_Generic_Instance
(E
)
10608 and then (Present
(Alias
(E
))
10609 or else Is_Intrinsic_Subprogram
(E
))
10610 and then (not In_Instance
10611 or else No
(Parent
(E
))
10612 or else Nkind
(Unit_Declaration_Node
(E
)) /=
10613 N_Subprogram_Renaming_Declaration
)
10615 -- A subprogram child unit is not allowed to override an
10616 -- inherited subprogram (10.1.1(20)).
10618 if Is_Child_Unit
(S
) then
10620 ("child unit overrides inherited subprogram in parent",
10625 if Is_Non_Overriding_Operation
(E
, S
) then
10626 Enter_Overloaded_Entity
(S
);
10628 if No
(Derived_Type
)
10629 or else Is_Tagged_Type
(Derived_Type
)
10631 Check_Dispatching_Operation
(S
, Empty
);
10637 -- E is a derived operation or an internal operator which
10638 -- is being overridden. Remove E from further visibility.
10639 -- Furthermore, if E is a dispatching operation, it must be
10640 -- replaced in the list of primitive operations of its type
10641 -- (see Override_Dispatching_Operation).
10643 Overridden_Subp
:= E
;
10649 Prev
:= First_Entity
(Current_Scope
);
10650 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
10651 Next_Entity
(Prev
);
10654 -- It is possible for E to be in the current scope and
10655 -- yet not in the entity chain. This can only occur in a
10656 -- generic context where E is an implicit concatenation
10657 -- in the formal part, because in a generic body the
10658 -- entity chain starts with the formals.
10660 -- In GNATprove mode, a wrapper for an operation with
10661 -- axiomatization may be a homonym of another declaration
10662 -- for an actual subprogram (needs refinement ???).
10666 and then GNATprove_Mode
10668 Nkind
(Original_Node
(Unit_Declaration_Node
(S
))) =
10669 N_Subprogram_Renaming_Declaration
10673 pragma Assert
(Chars
(E
) = Name_Op_Concat
);
10678 -- E must be removed both from the entity_list of the
10679 -- current scope, and from the visibility chain.
10681 if Debug_Flag_E
then
10682 Write_Str
("Override implicit operation ");
10683 Write_Int
(Int
(E
));
10687 -- If E is a predefined concatenation, it stands for four
10688 -- different operations. As a result, a single explicit
10689 -- declaration does not hide it. In a possible ambiguous
10690 -- situation, Disambiguate chooses the user-defined op,
10691 -- so it is correct to retain the previous internal one.
10693 if Chars
(E
) /= Name_Op_Concat
10694 or else Ekind
(E
) /= E_Operator
10696 -- For nondispatching derived operations that are
10697 -- overridden by a subprogram declared in the private
10698 -- part of a package, we retain the derived subprogram
10699 -- but mark it as not immediately visible. If the
10700 -- derived operation was declared in the visible part
10701 -- then this ensures that it will still be visible
10702 -- outside the package with the proper signature
10703 -- (calls from outside must also be directed to this
10704 -- version rather than the overriding one, unlike the
10705 -- dispatching case). Calls from inside the package
10706 -- will still resolve to the overriding subprogram
10707 -- since the derived one is marked as not visible
10708 -- within the package.
10710 -- If the private operation is dispatching, we achieve
10711 -- the overriding by keeping the implicit operation
10712 -- but setting its alias to be the overriding one. In
10713 -- this fashion the proper body is executed in all
10714 -- cases, but the original signature is used outside
10717 -- If the overriding is not in the private part, we
10718 -- remove the implicit operation altogether.
10720 if Is_Private_Declaration
(S
) then
10721 if not Is_Dispatching_Operation
(E
) then
10722 Set_Is_Immediately_Visible
(E
, False);
10724 -- Work done in Override_Dispatching_Operation,
10725 -- so nothing else needs to be done here.
10731 -- Find predecessor of E in Homonym chain
10733 if E
= Current_Entity
(E
) then
10736 Prev_Vis
:= Current_Entity
(E
);
10737 while Homonym
(Prev_Vis
) /= E
loop
10738 Prev_Vis
:= Homonym
(Prev_Vis
);
10742 if Prev_Vis
/= Empty
then
10744 -- Skip E in the visibility chain
10746 Set_Homonym
(Prev_Vis
, Homonym
(E
));
10749 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
10752 Set_Next_Entity
(Prev
, Next_Entity
(E
));
10754 if No
(Next_Entity
(Prev
)) then
10755 Set_Last_Entity
(Current_Scope
, Prev
);
10760 Enter_Overloaded_Entity
(S
);
10762 -- For entities generated by Derive_Subprograms the
10763 -- overridden operation is the inherited primitive
10764 -- (which is available through the attribute alias).
10766 if not (Comes_From_Source
(E
))
10767 and then Is_Dispatching_Operation
(E
)
10768 and then Find_Dispatching_Type
(E
) =
10769 Find_Dispatching_Type
(S
)
10770 and then Present
(Alias
(E
))
10771 and then Comes_From_Source
(Alias
(E
))
10773 Set_Overridden_Operation
(S
, Alias
(E
));
10774 Inherit_Subprogram_Contract
(S
, Alias
(E
));
10776 -- Normal case of setting entity as overridden
10778 -- Note: Static_Initialization and Overridden_Operation
10779 -- attributes use the same field in subprogram entities.
10780 -- Static_Initialization is only defined for internal
10781 -- initialization procedures, where Overridden_Operation
10782 -- is irrelevant. Therefore the setting of this attribute
10783 -- must check whether the target is an init_proc.
10785 elsif not Is_Init_Proc
(S
) then
10786 Set_Overridden_Operation
(S
, E
);
10787 Inherit_Subprogram_Contract
(S
, E
);
10790 Check_Overriding_Indicator
(S
, E
, Is_Primitive
=> True);
10792 -- The Ghost policy in effect at the point of declaration
10793 -- of a parent subprogram and an overriding subprogram
10794 -- must match (SPARK RM 6.9(17)).
10796 Check_Ghost_Overriding
(S
, E
);
10798 -- If S is a user-defined subprogram or a null procedure
10799 -- expanded to override an inherited null procedure, or a
10800 -- predefined dispatching primitive then indicate that E
10801 -- overrides the operation from which S is inherited.
10803 if Comes_From_Source
(S
)
10805 (Present
(Parent
(S
))
10807 Nkind
(Parent
(S
)) = N_Procedure_Specification
10809 Null_Present
(Parent
(S
)))
10811 (Present
(Alias
(E
))
10813 Is_Predefined_Dispatching_Operation
(Alias
(E
)))
10815 if Present
(Alias
(E
)) then
10816 Set_Overridden_Operation
(S
, Alias
(E
));
10817 Inherit_Subprogram_Contract
(S
, Alias
(E
));
10821 if Is_Dispatching_Operation
(E
) then
10823 -- An overriding dispatching subprogram inherits the
10824 -- convention of the overridden subprogram (AI-117).
10826 Set_Convention
(S
, Convention
(E
));
10827 Check_Dispatching_Operation
(S
, E
);
10830 Check_Dispatching_Operation
(S
, Empty
);
10833 Check_For_Primitive_Subprogram
10834 (Is_Primitive_Subp
, Is_Overriding
=> True);
10835 goto Check_Inequality
;
10838 -- Apparent redeclarations in instances can occur when two
10839 -- formal types get the same actual type. The subprograms in
10840 -- in the instance are legal, even if not callable from the
10841 -- outside. Calls from within are disambiguated elsewhere.
10842 -- For dispatching operations in the visible part, the usual
10843 -- rules apply, and operations with the same profile are not
10844 -- legal (B830001).
10846 elsif (In_Instance_Visible_Part
10847 and then not Is_Dispatching_Operation
(E
))
10848 or else In_Instance_Not_Visible
10852 -- Here we have a real error (identical profile)
10855 Error_Msg_Sloc
:= Sloc
(E
);
10857 -- Avoid cascaded errors if the entity appears in
10858 -- subsequent calls.
10860 Set_Scope
(S
, Current_Scope
);
10862 -- Generate error, with extra useful warning for the case
10863 -- of a generic instance with no completion.
10865 if Is_Generic_Instance
(S
)
10866 and then not Has_Completion
(E
)
10869 ("instantiation cannot provide body for&", S
);
10870 Error_Msg_N
("\& conflicts with declaration#", S
);
10872 Error_Msg_N
("& conflicts with declaration#", S
);
10879 -- If one subprogram has an access parameter and the other
10880 -- a parameter of an access type, calls to either might be
10881 -- ambiguous. Verify that parameters match except for the
10882 -- access parameter.
10884 if May_Hide_Profile
then
10890 F1
:= First_Formal
(S
);
10891 F2
:= First_Formal
(E
);
10892 while Present
(F1
) and then Present
(F2
) loop
10893 if Is_Access_Type
(Etype
(F1
)) then
10894 if not Is_Access_Type
(Etype
(F2
))
10895 or else not Conforming_Types
10896 (Designated_Type
(Etype
(F1
)),
10897 Designated_Type
(Etype
(F2
)),
10900 May_Hide_Profile
:= False;
10904 not Conforming_Types
10905 (Etype
(F1
), Etype
(F2
), Type_Conformant
)
10907 May_Hide_Profile
:= False;
10914 if May_Hide_Profile
10918 Error_Msg_NE
("calls to& may be ambiguous??", S
, S
);
10927 -- On exit, we know that S is a new entity
10929 Enter_Overloaded_Entity
(S
);
10930 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
10931 Check_Overriding_Indicator
10932 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
10934 -- The Ghost policy in effect at the point of declaration of a parent
10935 -- subprogram and an overriding subprogram must match
10936 -- (SPARK RM 6.9(17)).
10938 Check_Ghost_Overriding
(S
, Overridden_Subp
);
10940 -- Overloading is not allowed in SPARK, except for operators
10942 if Nkind
(S
) /= N_Defining_Operator_Symbol
then
10943 Error_Msg_Sloc
:= Sloc
(Homonym
(S
));
10944 Check_SPARK_05_Restriction
10945 ("overloading not allowed with entity#", S
);
10948 -- If S is a derived operation for an untagged type then by
10949 -- definition it's not a dispatching operation (even if the parent
10950 -- operation was dispatching), so Check_Dispatching_Operation is not
10951 -- called in that case.
10953 if No
(Derived_Type
)
10954 or else Is_Tagged_Type
(Derived_Type
)
10956 Check_Dispatching_Operation
(S
, Empty
);
10960 -- If this is a user-defined equality operator that is not a derived
10961 -- subprogram, create the corresponding inequality. If the operation is
10962 -- dispatching, the expansion is done elsewhere, and we do not create
10963 -- an explicit inequality operation.
10965 <<Check_Inequality
>>
10966 if Chars
(S
) = Name_Op_Eq
10967 and then Etype
(S
) = Standard_Boolean
10968 and then Present
(Parent
(S
))
10969 and then not Is_Dispatching_Operation
(S
)
10971 Make_Inequality_Operator
(S
);
10972 Check_Untagged_Equality
(S
);
10974 end New_Overloaded_Entity
;
10976 ---------------------
10977 -- Process_Formals --
10978 ---------------------
10980 procedure Process_Formals
10982 Related_Nod
: Node_Id
)
10984 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean;
10985 -- Determine whether an access type designates a type coming from a
10988 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean;
10989 -- Check whether the default has a class-wide type. After analysis the
10990 -- default has the type of the formal, so we must also check explicitly
10991 -- for an access attribute.
10993 ----------------------------------
10994 -- Designates_From_Limited_With --
10995 ----------------------------------
10997 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean is
10998 Desig
: Entity_Id
:= Typ
;
11001 if Is_Access_Type
(Desig
) then
11002 Desig
:= Directly_Designated_Type
(Desig
);
11005 if Is_Class_Wide_Type
(Desig
) then
11006 Desig
:= Root_Type
(Desig
);
11010 Ekind
(Desig
) = E_Incomplete_Type
11011 and then From_Limited_With
(Desig
);
11012 end Designates_From_Limited_With
;
11014 ---------------------------
11015 -- Is_Class_Wide_Default --
11016 ---------------------------
11018 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean is
11020 return Is_Class_Wide_Type
(Designated_Type
(Etype
(D
)))
11021 or else (Nkind
(D
) = N_Attribute_Reference
11022 and then Attribute_Name
(D
) = Name_Access
11023 and then Is_Class_Wide_Type
(Etype
(Prefix
(D
))));
11024 end Is_Class_Wide_Default
;
11028 Context
: constant Node_Id
:= Parent
(Parent
(T
));
11030 Formal
: Entity_Id
;
11031 Formal_Type
: Entity_Id
;
11032 Param_Spec
: Node_Id
;
11035 Num_Out_Params
: Nat
:= 0;
11036 First_Out_Param
: Entity_Id
:= Empty
;
11037 -- Used for setting Is_Only_Out_Parameter
11039 -- Start of processing for Process_Formals
11042 -- In order to prevent premature use of the formals in the same formal
11043 -- part, the Ekind is left undefined until all default expressions are
11044 -- analyzed. The Ekind is established in a separate loop at the end.
11046 Param_Spec
:= First
(T
);
11047 while Present
(Param_Spec
) loop
11048 Formal
:= Defining_Identifier
(Param_Spec
);
11049 Set_Never_Set_In_Source
(Formal
, True);
11050 Enter_Name
(Formal
);
11052 -- Case of ordinary parameters
11054 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
11055 Find_Type
(Parameter_Type
(Param_Spec
));
11056 Ptype
:= Parameter_Type
(Param_Spec
);
11058 if Ptype
= Error
then
11062 Formal_Type
:= Entity
(Ptype
);
11064 if Is_Incomplete_Type
(Formal_Type
)
11066 (Is_Class_Wide_Type
(Formal_Type
)
11067 and then Is_Incomplete_Type
(Root_Type
(Formal_Type
)))
11069 -- Ada 2005 (AI-326): Tagged incomplete types allowed in
11070 -- primitive operations, as long as their completion is
11071 -- in the same declarative part. If in the private part
11072 -- this means that the type cannot be a Taft-amendment type.
11073 -- Check is done on package exit. For access to subprograms,
11074 -- the use is legal for Taft-amendment types.
11076 -- Ada 2012: tagged incomplete types are allowed as generic
11077 -- formal types. They do not introduce dependencies and the
11078 -- corresponding generic subprogram does not have a delayed
11079 -- freeze, because it does not need a freeze node. However,
11080 -- it is still the case that untagged incomplete types cannot
11081 -- be Taft-amendment types and must be completed in private
11082 -- part, so the subprogram must appear in the list of private
11083 -- dependents of the type.
11085 if Is_Tagged_Type
(Formal_Type
)
11086 or else (Ada_Version
>= Ada_2012
11087 and then not From_Limited_With
(Formal_Type
)
11088 and then not Is_Generic_Type
(Formal_Type
))
11090 if Ekind
(Scope
(Current_Scope
)) = E_Package
11091 and then not Is_Generic_Type
(Formal_Type
)
11092 and then not Is_Class_Wide_Type
(Formal_Type
)
11095 (Parent
(T
), N_Access_Function_Definition
,
11096 N_Access_Procedure_Definition
)
11098 Append_Elmt
(Current_Scope
,
11099 Private_Dependents
(Base_Type
(Formal_Type
)));
11101 -- Freezing is delayed to ensure that Register_Prim
11102 -- will get called for this operation, which is needed
11103 -- in cases where static dispatch tables aren't built.
11104 -- (Note that the same is done for controlling access
11105 -- parameter cases in function Access_Definition.)
11107 if not Is_Thunk
(Current_Scope
) then
11108 Set_Has_Delayed_Freeze
(Current_Scope
);
11113 elsif not Nkind_In
(Parent
(T
), N_Access_Function_Definition
,
11114 N_Access_Procedure_Definition
)
11116 -- AI05-0151: Tagged incomplete types are allowed in all
11117 -- formal parts. Untagged incomplete types are not allowed
11118 -- in bodies. Limited views of either kind are not allowed
11119 -- if there is no place at which the non-limited view can
11120 -- become available.
11122 -- Incomplete formal untagged types are not allowed in
11123 -- subprogram bodies (but are legal in their declarations).
11124 -- This excludes bodies created for null procedures, which
11125 -- are basic declarations.
11127 if Is_Generic_Type
(Formal_Type
)
11128 and then not Is_Tagged_Type
(Formal_Type
)
11129 and then Nkind
(Parent
(Related_Nod
)) = N_Subprogram_Body
11132 ("invalid use of formal incomplete type", Param_Spec
);
11134 elsif Ada_Version
>= Ada_2012
then
11135 if Is_Tagged_Type
(Formal_Type
)
11136 and then (not From_Limited_With
(Formal_Type
)
11137 or else not In_Package_Body
)
11141 elsif Nkind_In
(Context
, N_Accept_Statement
,
11142 N_Accept_Alternative
,
11144 or else (Nkind
(Context
) = N_Subprogram_Body
11145 and then Comes_From_Source
(Context
))
11148 ("invalid use of untagged incomplete type &",
11149 Ptype
, Formal_Type
);
11154 ("invalid use of incomplete type&",
11155 Param_Spec
, Formal_Type
);
11157 -- Further checks on the legality of incomplete types
11158 -- in formal parts are delayed until the freeze point
11159 -- of the enclosing subprogram or access to subprogram.
11163 elsif Ekind
(Formal_Type
) = E_Void
then
11165 ("premature use of&",
11166 Parameter_Type
(Param_Spec
), Formal_Type
);
11169 -- Ada 2012 (AI-142): Handle aliased parameters
11171 if Ada_Version
>= Ada_2012
11172 and then Aliased_Present
(Param_Spec
)
11174 Set_Is_Aliased
(Formal
);
11177 -- Ada 2005 (AI-231): Create and decorate an internal subtype
11178 -- declaration corresponding to the null-excluding type of the
11179 -- formal in the enclosing scope. Finally, replace the parameter
11180 -- type of the formal with the internal subtype.
11182 if Ada_Version
>= Ada_2005
11183 and then Null_Exclusion_Present
(Param_Spec
)
11185 if not Is_Access_Type
(Formal_Type
) then
11187 ("`NOT NULL` allowed only for an access type", Param_Spec
);
11190 if Can_Never_Be_Null
(Formal_Type
)
11191 and then Comes_From_Source
(Related_Nod
)
11194 ("`NOT NULL` not allowed (& already excludes null)",
11195 Param_Spec
, Formal_Type
);
11199 Create_Null_Excluding_Itype
11201 Related_Nod
=> Related_Nod
,
11202 Scope_Id
=> Scope
(Current_Scope
));
11204 -- If the designated type of the itype is an itype that is
11205 -- not frozen yet, we set the Has_Delayed_Freeze attribute
11206 -- on the access subtype, to prevent order-of-elaboration
11207 -- issues in the backend.
11210 -- type T is access procedure;
11211 -- procedure Op (O : not null T);
11213 if Is_Itype
(Directly_Designated_Type
(Formal_Type
))
11215 not Is_Frozen
(Directly_Designated_Type
(Formal_Type
))
11217 Set_Has_Delayed_Freeze
(Formal_Type
);
11222 -- An access formal type
11226 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
11228 -- No need to continue if we already notified errors
11230 if not Present
(Formal_Type
) then
11234 -- Ada 2005 (AI-254)
11237 AD
: constant Node_Id
:=
11238 Access_To_Subprogram_Definition
11239 (Parameter_Type
(Param_Spec
));
11241 if Present
(AD
) and then Protected_Present
(AD
) then
11243 Replace_Anonymous_Access_To_Protected_Subprogram
11249 Set_Etype
(Formal
, Formal_Type
);
11251 -- Deal with default expression if present
11253 Default
:= Expression
(Param_Spec
);
11255 if Present
(Default
) then
11256 Check_SPARK_05_Restriction
11257 ("default expression is not allowed", Default
);
11259 if Out_Present
(Param_Spec
) then
11261 ("default initialization only allowed for IN parameters",
11265 -- Do the special preanalysis of the expression (see section on
11266 -- "Handling of Default Expressions" in the spec of package Sem).
11268 Preanalyze_Spec_Expression
(Default
, Formal_Type
);
11270 -- An access to constant cannot be the default for
11271 -- an access parameter that is an access to variable.
11273 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
11274 and then not Is_Access_Constant
(Formal_Type
)
11275 and then Is_Access_Type
(Etype
(Default
))
11276 and then Is_Access_Constant
(Etype
(Default
))
11279 ("formal that is access to variable cannot be initialized "
11280 & "with an access-to-constant expression", Default
);
11283 -- Check that the designated type of an access parameter's default
11284 -- is not a class-wide type unless the parameter's designated type
11285 -- is also class-wide.
11287 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
11288 and then not Designates_From_Limited_With
(Formal_Type
)
11289 and then Is_Class_Wide_Default
(Default
)
11290 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
11293 ("access to class-wide expression not allowed here", Default
);
11296 -- Check incorrect use of dynamically tagged expressions
11298 if Is_Tagged_Type
(Formal_Type
) then
11299 Check_Dynamically_Tagged_Expression
11301 Typ
=> Formal_Type
,
11302 Related_Nod
=> Default
);
11306 -- Ada 2005 (AI-231): Static checks
11308 if Ada_Version
>= Ada_2005
11309 and then Is_Access_Type
(Etype
(Formal
))
11310 and then Can_Never_Be_Null
(Etype
(Formal
))
11312 Null_Exclusion_Static_Checks
(Param_Spec
);
11315 -- The following checks are relevant only when SPARK_Mode is on as
11316 -- these are not standard Ada legality rules.
11318 if SPARK_Mode
= On
then
11319 if Ekind_In
(Scope
(Formal
), E_Function
, E_Generic_Function
) then
11321 -- A function cannot have a parameter of mode IN OUT or OUT
11324 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_Out_Parameter
) then
11326 ("function cannot have parameter of mode `OUT` or "
11327 & "`IN OUT`", Formal
);
11330 -- A procedure cannot have an effectively volatile formal
11331 -- parameter of mode IN because it behaves as a constant
11332 -- (SPARK RM 7.1.3(6)). -- ??? maybe 7.1.3(4)
11334 elsif Ekind
(Scope
(Formal
)) = E_Procedure
11335 and then Ekind
(Formal
) = E_In_Parameter
11336 and then Is_Effectively_Volatile
(Formal
)
11339 ("formal parameter of mode `IN` cannot be volatile", Formal
);
11347 -- If this is the formal part of a function specification, analyze the
11348 -- subtype mark in the context where the formals are visible but not
11349 -- yet usable, and may hide outer homographs.
11351 if Nkind
(Related_Nod
) = N_Function_Specification
then
11352 Analyze_Return_Type
(Related_Nod
);
11355 -- Now set the kind (mode) of each formal
11357 Param_Spec
:= First
(T
);
11358 while Present
(Param_Spec
) loop
11359 Formal
:= Defining_Identifier
(Param_Spec
);
11360 Set_Formal_Mode
(Formal
);
11362 if Ekind
(Formal
) = E_In_Parameter
then
11363 Set_Default_Value
(Formal
, Expression
(Param_Spec
));
11365 if Present
(Expression
(Param_Spec
)) then
11366 Default
:= Expression
(Param_Spec
);
11368 if Is_Scalar_Type
(Etype
(Default
)) then
11369 if Nkind
(Parameter_Type
(Param_Spec
)) /=
11370 N_Access_Definition
11372 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
11376 (Related_Nod
, Parameter_Type
(Param_Spec
));
11379 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
11383 elsif Ekind
(Formal
) = E_Out_Parameter
then
11384 Num_Out_Params
:= Num_Out_Params
+ 1;
11386 if Num_Out_Params
= 1 then
11387 First_Out_Param
:= Formal
;
11390 elsif Ekind
(Formal
) = E_In_Out_Parameter
then
11391 Num_Out_Params
:= Num_Out_Params
+ 1;
11394 -- Skip remaining processing if formal type was in error
11396 if Etype
(Formal
) = Any_Type
or else Error_Posted
(Formal
) then
11397 goto Next_Parameter
;
11400 -- Force call by reference if aliased
11403 Conv
: constant Convention_Id
:= Convention
(Etype
(Formal
));
11405 if Is_Aliased
(Formal
) then
11406 Set_Mechanism
(Formal
, By_Reference
);
11408 -- Warn if user asked this to be passed by copy
11410 if Conv
= Convention_Ada_Pass_By_Copy
then
11412 ("cannot pass aliased parameter & by copy??", Formal
);
11415 -- Force mechanism if type has Convention Ada_Pass_By_Ref/Copy
11417 elsif Conv
= Convention_Ada_Pass_By_Copy
then
11418 Set_Mechanism
(Formal
, By_Copy
);
11420 elsif Conv
= Convention_Ada_Pass_By_Reference
then
11421 Set_Mechanism
(Formal
, By_Reference
);
11429 if Present
(First_Out_Param
) and then Num_Out_Params
= 1 then
11430 Set_Is_Only_Out_Parameter
(First_Out_Param
);
11432 end Process_Formals
;
11434 ----------------------------
11435 -- Reference_Body_Formals --
11436 ----------------------------
11438 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
) is
11443 if Error_Posted
(Spec
) then
11447 -- Iterate over both lists. They may be of different lengths if the two
11448 -- specs are not conformant.
11450 Fs
:= First_Formal
(Spec
);
11451 Fb
:= First_Formal
(Bod
);
11452 while Present
(Fs
) and then Present
(Fb
) loop
11453 Generate_Reference
(Fs
, Fb
, 'b');
11455 if Style_Check
then
11456 Style
.Check_Identifier
(Fb
, Fs
);
11459 Set_Spec_Entity
(Fb
, Fs
);
11460 Set_Referenced
(Fs
, False);
11464 end Reference_Body_Formals
;
11466 -------------------------
11467 -- Set_Actual_Subtypes --
11468 -------------------------
11470 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
11472 Formal
: Entity_Id
;
11474 First_Stmt
: Node_Id
:= Empty
;
11475 AS_Needed
: Boolean;
11478 -- If this is an empty initialization procedure, no need to create
11479 -- actual subtypes (small optimization).
11481 if Ekind
(Subp
) = E_Procedure
and then Is_Null_Init_Proc
(Subp
) then
11485 -- The subtype declarations may freeze the formals. The body generated
11486 -- for an expression function is not a freeze point, so do not emit
11487 -- these declarations (small loss of efficiency in rare cases).
11489 if Nkind
(N
) = N_Subprogram_Body
11490 and then Was_Expression_Function
(N
)
11495 Formal
:= First_Formal
(Subp
);
11496 while Present
(Formal
) loop
11497 T
:= Etype
(Formal
);
11499 -- We never need an actual subtype for a constrained formal
11501 if Is_Constrained
(T
) then
11502 AS_Needed
:= False;
11504 -- If we have unknown discriminants, then we do not need an actual
11505 -- subtype, or more accurately we cannot figure it out. Note that
11506 -- all class-wide types have unknown discriminants.
11508 elsif Has_Unknown_Discriminants
(T
) then
11509 AS_Needed
:= False;
11511 -- At this stage we have an unconstrained type that may need an
11512 -- actual subtype. For sure the actual subtype is needed if we have
11513 -- an unconstrained array type. However, in an instance, the type
11514 -- may appear as a subtype of the full view, while the actual is
11515 -- in fact private (in which case no actual subtype is needed) so
11516 -- check the kind of the base type.
11518 elsif Is_Array_Type
(Base_Type
(T
)) then
11521 -- The only other case needing an actual subtype is an unconstrained
11522 -- record type which is an IN parameter (we cannot generate actual
11523 -- subtypes for the OUT or IN OUT case, since an assignment can
11524 -- change the discriminant values. However we exclude the case of
11525 -- initialization procedures, since discriminants are handled very
11526 -- specially in this context, see the section entitled "Handling of
11527 -- Discriminants" in Einfo.
11529 -- We also exclude the case of Discrim_SO_Functions (functions used
11530 -- in front-end layout mode for size/offset values), since in such
11531 -- functions only discriminants are referenced, and not only are such
11532 -- subtypes not needed, but they cannot always be generated, because
11533 -- of order of elaboration issues.
11535 elsif Is_Record_Type
(T
)
11536 and then Ekind
(Formal
) = E_In_Parameter
11537 and then Chars
(Formal
) /= Name_uInit
11538 and then not Is_Unchecked_Union
(T
)
11539 and then not Is_Discrim_SO_Function
(Subp
)
11543 -- All other cases do not need an actual subtype
11546 AS_Needed
:= False;
11549 -- Generate actual subtypes for unconstrained arrays and
11550 -- unconstrained discriminated records.
11553 if Nkind
(N
) = N_Accept_Statement
then
11555 -- If expansion is active, the formal is replaced by a local
11556 -- variable that renames the corresponding entry of the
11557 -- parameter block, and it is this local variable that may
11558 -- require an actual subtype.
11560 if Expander_Active
then
11561 Decl
:= Build_Actual_Subtype
(T
, Renamed_Object
(Formal
));
11563 Decl
:= Build_Actual_Subtype
(T
, Formal
);
11566 if Present
(Handled_Statement_Sequence
(N
)) then
11568 First
(Statements
(Handled_Statement_Sequence
(N
)));
11569 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
11570 Mark_Rewrite_Insertion
(Decl
);
11572 -- If the accept statement has no body, there will be no
11573 -- reference to the actuals, so no need to compute actual
11580 Decl
:= Build_Actual_Subtype
(T
, Formal
);
11581 Prepend
(Decl
, Declarations
(N
));
11582 Mark_Rewrite_Insertion
(Decl
);
11585 -- The declaration uses the bounds of an existing object, and
11586 -- therefore needs no constraint checks.
11588 Analyze
(Decl
, Suppress
=> All_Checks
);
11589 Set_Is_Actual_Subtype
(Defining_Identifier
(Decl
));
11591 -- We need to freeze manually the generated type when it is
11592 -- inserted anywhere else than in a declarative part.
11594 if Present
(First_Stmt
) then
11595 Insert_List_Before_And_Analyze
(First_Stmt
,
11596 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
11598 -- Ditto if the type has a dynamic predicate, because the
11599 -- generated function will mention the actual subtype. The
11600 -- predicate may come from an explicit aspect of be inherited.
11602 elsif Has_Predicates
(T
) then
11603 Insert_List_Before_And_Analyze
(Decl
,
11604 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
11607 if Nkind
(N
) = N_Accept_Statement
11608 and then Expander_Active
11610 Set_Actual_Subtype
(Renamed_Object
(Formal
),
11611 Defining_Identifier
(Decl
));
11613 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
11617 Next_Formal
(Formal
);
11619 end Set_Actual_Subtypes
;
11621 ---------------------
11622 -- Set_Formal_Mode --
11623 ---------------------
11625 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
11626 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
11627 Id
: constant Entity_Id
:= Scope
(Formal_Id
);
11630 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
11631 -- since we ensure that corresponding actuals are always valid at the
11632 -- point of the call.
11634 if Out_Present
(Spec
) then
11635 if Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
11636 or else Is_Subprogram_Or_Generic_Subprogram
(Id
)
11638 Set_Has_Out_Or_In_Out_Parameter
(Id
, True);
11641 if Ekind_In
(Id
, E_Function
, E_Generic_Function
) then
11643 -- [IN] OUT parameters allowed for functions in Ada 2012
11645 if Ada_Version
>= Ada_2012
then
11647 -- Even in Ada 2012 operators can only have IN parameters
11649 if Is_Operator_Symbol_Name
(Chars
(Scope
(Formal_Id
))) then
11650 Error_Msg_N
("operators can only have IN parameters", Spec
);
11653 if In_Present
(Spec
) then
11654 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
11656 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
11659 -- But not in earlier versions of Ada
11662 Error_Msg_N
("functions can only have IN parameters", Spec
);
11663 Set_Ekind
(Formal_Id
, E_In_Parameter
);
11666 elsif In_Present
(Spec
) then
11667 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
11670 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
11671 Set_Never_Set_In_Source
(Formal_Id
, True);
11672 Set_Is_True_Constant
(Formal_Id
, False);
11673 Set_Current_Value
(Formal_Id
, Empty
);
11677 Set_Ekind
(Formal_Id
, E_In_Parameter
);
11680 -- Set Is_Known_Non_Null for access parameters since the language
11681 -- guarantees that access parameters are always non-null. We also set
11682 -- Can_Never_Be_Null, since there is no way to change the value.
11684 if Nkind
(Parameter_Type
(Spec
)) = N_Access_Definition
then
11686 -- Ada 2005 (AI-231): In Ada 95, access parameters are always non-
11687 -- null; In Ada 2005, only if then null_exclusion is explicit.
11689 if Ada_Version
< Ada_2005
11690 or else Can_Never_Be_Null
(Etype
(Formal_Id
))
11692 Set_Is_Known_Non_Null
(Formal_Id
);
11693 Set_Can_Never_Be_Null
(Formal_Id
);
11696 -- Ada 2005 (AI-231): Null-exclusion access subtype
11698 elsif Is_Access_Type
(Etype
(Formal_Id
))
11699 and then Can_Never_Be_Null
(Etype
(Formal_Id
))
11701 Set_Is_Known_Non_Null
(Formal_Id
);
11703 -- We can also set Can_Never_Be_Null (thus preventing some junk
11704 -- access checks) for the case of an IN parameter, which cannot
11705 -- be changed, or for an IN OUT parameter, which can be changed but
11706 -- not to a null value. But for an OUT parameter, the initial value
11707 -- passed in can be null, so we can't set this flag in that case.
11709 if Ekind
(Formal_Id
) /= E_Out_Parameter
then
11710 Set_Can_Never_Be_Null
(Formal_Id
);
11714 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
11715 Set_Formal_Validity
(Formal_Id
);
11716 end Set_Formal_Mode
;
11718 -------------------------
11719 -- Set_Formal_Validity --
11720 -------------------------
11722 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
11724 -- If no validity checking, then we cannot assume anything about the
11725 -- validity of parameters, since we do not know there is any checking
11726 -- of the validity on the call side.
11728 if not Validity_Checks_On
then
11731 -- If validity checking for parameters is enabled, this means we are
11732 -- not supposed to make any assumptions about argument values.
11734 elsif Validity_Check_Parameters
then
11737 -- If we are checking in parameters, we will assume that the caller is
11738 -- also checking parameters, so we can assume the parameter is valid.
11740 elsif Ekind
(Formal_Id
) = E_In_Parameter
11741 and then Validity_Check_In_Params
11743 Set_Is_Known_Valid
(Formal_Id
, True);
11745 -- Similar treatment for IN OUT parameters
11747 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
11748 and then Validity_Check_In_Out_Params
11750 Set_Is_Known_Valid
(Formal_Id
, True);
11752 end Set_Formal_Validity
;
11754 ------------------------
11755 -- Subtype_Conformant --
11756 ------------------------
11758 function Subtype_Conformant
11759 (New_Id
: Entity_Id
;
11760 Old_Id
: Entity_Id
;
11761 Skip_Controlling_Formals
: Boolean := False) return Boolean
11765 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
,
11766 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
11768 end Subtype_Conformant
;
11770 ---------------------
11771 -- Type_Conformant --
11772 ---------------------
11774 function Type_Conformant
11775 (New_Id
: Entity_Id
;
11776 Old_Id
: Entity_Id
;
11777 Skip_Controlling_Formals
: Boolean := False) return Boolean
11781 May_Hide_Profile
:= False;
11783 (New_Id
, Old_Id
, Type_Conformant
, False, Result
,
11784 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
11786 end Type_Conformant
;
11788 -------------------------------
11789 -- Valid_Operator_Definition --
11790 -------------------------------
11792 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
11795 Id
: constant Name_Id
:= Chars
(Designator
);
11799 F
:= First_Formal
(Designator
);
11800 while Present
(F
) loop
11803 if Present
(Default_Value
(F
)) then
11805 ("default values not allowed for operator parameters",
11808 -- For function instantiations that are operators, we must check
11809 -- separately that the corresponding generic only has in-parameters.
11810 -- For subprogram declarations this is done in Set_Formal_Mode. Such
11811 -- an error could not arise in earlier versions of the language.
11813 elsif Ekind
(F
) /= E_In_Parameter
then
11814 Error_Msg_N
("operators can only have IN parameters", F
);
11820 -- Verify that user-defined operators have proper number of arguments
11821 -- First case of operators which can only be unary
11823 if Nam_In
(Id
, Name_Op_Not
, Name_Op_Abs
) then
11826 -- Case of operators which can be unary or binary
11828 elsif Nam_In
(Id
, Name_Op_Add
, Name_Op_Subtract
) then
11829 N_OK
:= (N
in 1 .. 2);
11831 -- All other operators can only be binary
11839 ("incorrect number of arguments for operator", Designator
);
11843 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
11844 and then not Is_Intrinsic_Subprogram
(Designator
)
11847 ("explicit definition of inequality not allowed", Designator
);
11849 end Valid_Operator_Definition
;