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 private type without a full view, or a type derived from such
385 -- in an enclosing scope. Except in a generic context, such use of
386 -- an incomplete type is an error. On the other hand, if this is a
387 -- limited view of a type, the type is declared in another unit and
388 -- frozen there. We must be in a context seeing the nonlimited view
389 -- of the type, which will be installed when the body is compiled.
391 if not Is_Frozen
(Ret_Type
)
392 and then not Is_Generic_Type
(Ret_Type
)
393 and then not Inside_A_Generic
395 if From_Limited_With
(Ret_Type
)
396 and then Present
(Non_Limited_View
(Ret_Type
))
401 ("premature use of private type&",
402 Result_Definition
(Specification
(N
)), Ret_Type
);
406 if Is_Access_Type
(Etype
(Prev
)) then
407 Freeze_Before
(N
, Designated_Type
(Etype
(Prev
)));
410 -- For navigation purposes, indicate that the function is a body
412 Generate_Reference
(Prev
, Defining_Entity
(N
), 'b', Force
=> True);
413 Rewrite
(N
, New_Body
);
415 -- Remove any existing aspects from the original node because the act
416 -- of rewriting causes the list to be shared between the two nodes.
418 Orig_N
:= Original_Node
(N
);
419 Remove_Aspects
(Orig_N
);
421 -- Propagate any pragmas that apply to the expression function to the
422 -- proper body when the expression function acts as a completion.
423 -- Aspects are automatically transfered because of node rewriting.
425 Relocate_Pragmas_To_Body
(N
);
428 -- Once the aspects of the generated body have been analyzed, create
429 -- a copy for ASIS purposes and associate it with the original node.
431 if Has_Aspects
(N
) then
432 Set_Aspect_Specifications
(Orig_N
,
433 New_Copy_List_Tree
(Aspect_Specifications
(N
)));
436 -- Prev is the previous entity with the same name, but it is can
437 -- be an unrelated spec that is not completed by the expression
438 -- function. In that case the relevant entity is the one in the body.
439 -- Not clear that the backend can inline it in this case ???
441 if Has_Completion
(Prev
) then
443 -- The formals of the expression function are body formals,
444 -- and do not appear in the ali file, which will only contain
445 -- references to the formals of the original subprogram spec.
452 F1
:= First_Formal
(Def_Id
);
453 F2
:= First_Formal
(Prev
);
455 while Present
(F1
) loop
456 Set_Spec_Entity
(F1
, F2
);
463 Set_Is_Inlined
(Defining_Entity
(New_Body
));
466 -- If this is not a completion, create both a declaration and a body, so
467 -- that the expression can be inlined whenever possible.
470 -- An expression function that is not a completion is not a
471 -- subprogram declaration, and thus cannot appear in a protected
474 if Nkind
(Parent
(N
)) = N_Protected_Definition
then
476 ("an expression function is not a legal protected operation", N
);
479 Rewrite
(N
, Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
));
481 -- Remove any existing aspects from the original node because the act
482 -- of rewriting causes the list to be shared between the two nodes.
484 Orig_N
:= Original_Node
(N
);
485 Remove_Aspects
(Orig_N
);
489 -- Once the aspects of the generated spec have been analyzed, create
490 -- a copy for ASIS purposes and associate it with the original node.
492 if Has_Aspects
(N
) then
493 Set_Aspect_Specifications
(Orig_N
,
494 New_Copy_List_Tree
(Aspect_Specifications
(N
)));
497 -- If aspect SPARK_Mode was specified on the body, it needs to be
498 -- repeated both on the generated spec and the body.
500 Asp
:= Find_Aspect
(Defining_Unit_Name
(Spec
), Aspect_SPARK_Mode
);
502 if Present
(Asp
) then
503 Asp
:= New_Copy_Tree
(Asp
);
504 Set_Analyzed
(Asp
, False);
505 Set_Aspect_Specifications
(New_Body
, New_List
(Asp
));
508 Def_Id
:= Defining_Entity
(N
);
510 -- Within a generic pre-analyze the original expression for name
511 -- capture. The body is also generated but plays no role in
512 -- this because it is not part of the original source.
514 if Inside_A_Generic
then
515 Set_Has_Completion
(Def_Id
);
517 Install_Formals
(Def_Id
);
518 Preanalyze_Spec_Expression
(Expr
, Etype
(Def_Id
));
522 Set_Is_Inlined
(Defining_Entity
(N
));
524 -- Establish the linkages between the spec and the body. These are
525 -- used when the expression function acts as the prefix of attribute
526 -- 'Access in order to freeze the original expression which has been
527 -- moved to the generated body.
529 Set_Corresponding_Body
(N
, Defining_Entity
(New_Body
));
530 Set_Corresponding_Spec
(New_Body
, Defining_Entity
(N
));
532 -- To prevent premature freeze action, insert the new body at the end
533 -- of the current declarations, or at the end of the package spec.
534 -- However, resolve usage names now, to prevent spurious visibility
535 -- on later entities. Note that the function can now be called in
536 -- the current declarative part, which will appear to be prior to
537 -- the presence of the body in the code. There are nevertheless no
538 -- order of elaboration issues because all name resolution has taken
539 -- place at the point of declaration.
542 Decls
: List_Id
:= List_Containing
(N
);
543 Expr
: constant Node_Id
:= Expression
(Ret
);
544 Par
: constant Node_Id
:= Parent
(Decls
);
545 Typ
: constant Entity_Id
:= Etype
(Def_Id
);
548 -- If this is a wrapper created for in an instance for a formal
549 -- subprogram, insert body after declaration, to be analyzed when
550 -- the enclosing instance is analyzed.
553 and then Is_Generic_Actual_Subprogram
(Defining_Entity
(N
))
555 Insert_After
(N
, New_Body
);
558 if Nkind
(Par
) = N_Package_Specification
559 and then Decls
= Visible_Declarations
(Par
)
560 and then Present
(Private_Declarations
(Par
))
561 and then not Is_Empty_List
(Private_Declarations
(Par
))
563 Decls
:= Private_Declarations
(Par
);
566 Insert_After
(Last
(Decls
), New_Body
);
568 -- Preanalyze the expression for name capture, except in an
569 -- instance, where this has been done during generic analysis,
570 -- and will be redone when analyzing the body.
572 Set_Parent
(Expr
, Ret
);
574 Install_Formals
(Def_Id
);
576 if not In_Instance
then
577 Preanalyze_Spec_Expression
(Expr
, Typ
);
578 Check_Limited_Return
(Original_Node
(N
), Expr
, Typ
);
586 -- If the return expression is a static constant, we suppress warning
587 -- messages on unused formals, which in most cases will be noise.
589 Set_Is_Trivial_Subprogram
590 (Defining_Entity
(New_Body
), Is_OK_Static_Expression
(Expr
));
591 end Analyze_Expression_Function
;
593 ----------------------------------------
594 -- Analyze_Extended_Return_Statement --
595 ----------------------------------------
597 procedure Analyze_Extended_Return_Statement
(N
: Node_Id
) is
599 Check_Compiler_Unit
("extended return statement", N
);
600 Analyze_Return_Statement
(N
);
601 end Analyze_Extended_Return_Statement
;
603 ----------------------------
604 -- Analyze_Function_Call --
605 ----------------------------
607 procedure Analyze_Function_Call
(N
: Node_Id
) is
608 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
609 Func_Nam
: constant Node_Id
:= Name
(N
);
615 -- A call of the form A.B (X) may be an Ada 2005 call, which is
616 -- rewritten as B (A, X). If the rewriting is successful, the call
617 -- has been analyzed and we just return.
619 if Nkind
(Func_Nam
) = N_Selected_Component
620 and then Name
(N
) /= Func_Nam
621 and then Is_Rewrite_Substitution
(N
)
622 and then Present
(Etype
(N
))
627 -- If error analyzing name, then set Any_Type as result type and return
629 if Etype
(Func_Nam
) = Any_Type
then
630 Set_Etype
(N
, Any_Type
);
634 -- Otherwise analyze the parameters
636 if Present
(Actuals
) then
637 Actual
:= First
(Actuals
);
638 while Present
(Actual
) loop
640 Check_Parameterless_Call
(Actual
);
646 end Analyze_Function_Call
;
648 -----------------------------
649 -- Analyze_Function_Return --
650 -----------------------------
652 procedure Analyze_Function_Return
(N
: Node_Id
) is
653 Loc
: constant Source_Ptr
:= Sloc
(N
);
654 Stm_Entity
: constant Entity_Id
:= Return_Statement_Entity
(N
);
655 Scope_Id
: constant Entity_Id
:= Return_Applies_To
(Stm_Entity
);
657 R_Type
: constant Entity_Id
:= Etype
(Scope_Id
);
658 -- Function result subtype
660 procedure Check_Aggregate_Accessibility
(Aggr
: Node_Id
);
661 -- Apply legality rule of 6.5 (5.8) to the access discriminants of an
662 -- aggregate in a return statement.
664 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
);
665 -- Check that the return_subtype_indication properly matches the result
666 -- subtype of the function, as required by RM-6.5(5.1/2-5.3/2).
668 -----------------------------------
669 -- Check_Aggregate_Accessibility --
670 -----------------------------------
672 procedure Check_Aggregate_Accessibility
(Aggr
: Node_Id
) is
673 Typ
: constant Entity_Id
:= Etype
(Aggr
);
680 if Is_Record_Type
(Typ
) and then Has_Discriminants
(Typ
) then
681 Discr
:= First_Discriminant
(Typ
);
682 Assoc
:= First
(Component_Associations
(Aggr
));
683 while Present
(Discr
) loop
684 if Ekind
(Etype
(Discr
)) = E_Anonymous_Access_Type
then
685 Expr
:= Expression
(Assoc
);
687 if Nkind
(Expr
) = N_Attribute_Reference
688 and then Attribute_Name
(Expr
) /= Name_Unrestricted_Access
690 Obj
:= Prefix
(Expr
);
691 while Nkind_In
(Obj
, N_Indexed_Component
,
692 N_Selected_Component
)
697 -- Do not check aliased formals or function calls. A
698 -- run-time check may still be needed ???
700 if Is_Entity_Name
(Obj
)
701 and then Comes_From_Source
(Obj
)
703 if Is_Formal
(Entity
(Obj
))
704 and then Is_Aliased
(Entity
(Obj
))
708 elsif Object_Access_Level
(Obj
) >
709 Scope_Depth
(Scope
(Scope_Id
))
712 ("access discriminant in return aggregate would "
713 & "be a dangling reference", Obj
);
719 Next_Discriminant
(Discr
);
722 end Check_Aggregate_Accessibility
;
724 -------------------------------------
725 -- Check_Return_Subtype_Indication --
726 -------------------------------------
728 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
) is
729 Return_Obj
: constant Node_Id
:= Defining_Identifier
(Obj_Decl
);
731 R_Stm_Type
: constant Entity_Id
:= Etype
(Return_Obj
);
732 -- Subtype given in the extended return statement (must match R_Type)
734 Subtype_Ind
: constant Node_Id
:=
735 Object_Definition
(Original_Node
(Obj_Decl
));
737 R_Type_Is_Anon_Access
: constant Boolean :=
739 E_Anonymous_Access_Subprogram_Type
,
740 E_Anonymous_Access_Protected_Subprogram_Type
,
741 E_Anonymous_Access_Type
);
742 -- True if return type of the function is an anonymous access type
743 -- Can't we make Is_Anonymous_Access_Type in einfo ???
745 R_Stm_Type_Is_Anon_Access
: constant Boolean :=
746 Ekind_In
(R_Stm_Type
,
747 E_Anonymous_Access_Subprogram_Type
,
748 E_Anonymous_Access_Protected_Subprogram_Type
,
749 E_Anonymous_Access_Type
);
750 -- True if type of the return object is an anonymous access type
752 procedure Error_No_Match
(N
: Node_Id
);
753 -- Output error messages for case where types do not statically
754 -- match. N is the location for the messages.
760 procedure Error_No_Match
(N
: Node_Id
) is
763 ("subtype must statically match function result subtype", N
);
765 if not Predicates_Match
(R_Stm_Type
, R_Type
) then
766 Error_Msg_Node_2
:= R_Type
;
768 ("\predicate of& does not match predicate of&",
773 -- Start of processing for Check_Return_Subtype_Indication
776 -- First, avoid cascaded errors
778 if Error_Posted
(Obj_Decl
) or else Error_Posted
(Subtype_Ind
) then
782 -- "return access T" case; check that the return statement also has
783 -- "access T", and that the subtypes statically match:
784 -- if this is an access to subprogram the signatures must match.
786 if R_Type_Is_Anon_Access
then
787 if R_Stm_Type_Is_Anon_Access
then
789 Ekind
(Designated_Type
(R_Stm_Type
)) /= E_Subprogram_Type
791 if Base_Type
(Designated_Type
(R_Stm_Type
)) /=
792 Base_Type
(Designated_Type
(R_Type
))
793 or else not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
)
795 Error_No_Match
(Subtype_Mark
(Subtype_Ind
));
799 -- For two anonymous access to subprogram types, the
800 -- types themselves must be type conformant.
802 if not Conforming_Types
803 (R_Stm_Type
, R_Type
, Fully_Conformant
)
805 Error_No_Match
(Subtype_Ind
);
810 Error_Msg_N
("must use anonymous access type", Subtype_Ind
);
813 -- If the return object is of an anonymous access type, then report
814 -- an error if the function's result type is not also anonymous.
816 elsif R_Stm_Type_Is_Anon_Access
then
817 pragma Assert
(not R_Type_Is_Anon_Access
);
818 Error_Msg_N
("anonymous access not allowed for function with "
819 & "named access result", Subtype_Ind
);
821 -- Subtype indication case: check that the return object's type is
822 -- covered by the result type, and that the subtypes statically match
823 -- when the result subtype is constrained. Also handle record types
824 -- with unknown discriminants for which we have built the underlying
825 -- record view. Coverage is needed to allow specific-type return
826 -- objects when the result type is class-wide (see AI05-32).
828 elsif Covers
(Base_Type
(R_Type
), Base_Type
(R_Stm_Type
))
829 or else (Is_Underlying_Record_View
(Base_Type
(R_Stm_Type
))
833 Underlying_Record_View
(Base_Type
(R_Stm_Type
))))
835 -- A null exclusion may be present on the return type, on the
836 -- function specification, on the object declaration or on the
839 if Is_Access_Type
(R_Type
)
841 (Can_Never_Be_Null
(R_Type
)
842 or else Null_Exclusion_Present
(Parent
(Scope_Id
))) /=
843 Can_Never_Be_Null
(R_Stm_Type
)
845 Error_No_Match
(Subtype_Ind
);
848 -- AI05-103: for elementary types, subtypes must statically match
850 if Is_Constrained
(R_Type
)
851 or else Is_Access_Type
(R_Type
)
853 if not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
) then
854 Error_No_Match
(Subtype_Ind
);
858 -- All remaining cases are illegal
860 -- Note: previous versions of this subprogram allowed the return
861 -- value to be the ancestor of the return type if the return type
862 -- was a null extension. This was plainly incorrect.
866 ("wrong type for return_subtype_indication", Subtype_Ind
);
868 end Check_Return_Subtype_Indication
;
870 ---------------------
871 -- Local Variables --
872 ---------------------
877 -- Start of processing for Analyze_Function_Return
880 Set_Return_Present
(Scope_Id
);
882 if Nkind
(N
) = N_Simple_Return_Statement
then
883 Expr
:= Expression
(N
);
885 -- Guard against a malformed expression. The parser may have tried to
886 -- recover but the node is not analyzable.
888 if Nkind
(Expr
) = N_Error
then
889 Set_Etype
(Expr
, Any_Type
);
890 Expander_Mode_Save_And_Set
(False);
894 -- The resolution of a controlled [extension] aggregate associated
895 -- with a return statement creates a temporary which needs to be
896 -- finalized on function exit. Wrap the return statement inside a
897 -- block so that the finalization machinery can detect this case.
898 -- This early expansion is done only when the return statement is
899 -- not part of a handled sequence of statements.
901 if Nkind_In
(Expr
, N_Aggregate
,
902 N_Extension_Aggregate
)
903 and then Needs_Finalization
(R_Type
)
904 and then Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
907 Make_Block_Statement
(Loc
,
908 Handled_Statement_Sequence
=>
909 Make_Handled_Sequence_Of_Statements
(Loc
,
910 Statements
=> New_List
(Relocate_Node
(N
)))));
918 -- Ada 2005 (AI-251): If the type of the returned object is
919 -- an access to an interface type then we add an implicit type
920 -- conversion to force the displacement of the "this" pointer to
921 -- reference the secondary dispatch table. We cannot delay the
922 -- generation of this implicit conversion until the expansion
923 -- because in this case the type resolution changes the decoration
924 -- of the expression node to match R_Type; by contrast, if the
925 -- returned object is a class-wide interface type then it is too
926 -- early to generate here the implicit conversion since the return
927 -- statement may be rewritten by the expander into an extended
928 -- return statement whose expansion takes care of adding the
929 -- implicit type conversion to displace the pointer to the object.
932 and then Serious_Errors_Detected
= 0
933 and then Is_Access_Type
(R_Type
)
934 and then Nkind
(Expr
) /= N_Null
935 and then Is_Interface
(Designated_Type
(R_Type
))
936 and then Is_Progenitor
(Designated_Type
(R_Type
),
937 Designated_Type
(Etype
(Expr
)))
939 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
943 Resolve
(Expr
, R_Type
);
944 Check_Limited_Return
(N
, Expr
, R_Type
);
946 if Present
(Expr
) and then Nkind
(Expr
) = N_Aggregate
then
947 Check_Aggregate_Accessibility
(Expr
);
951 -- RETURN only allowed in SPARK as the last statement in function
953 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
955 (Nkind
(Parent
(Parent
(N
))) /= N_Subprogram_Body
956 or else Present
(Next
(N
)))
958 Check_SPARK_05_Restriction
959 ("RETURN should be the last statement in function", N
);
963 Check_SPARK_05_Restriction
("extended RETURN is not allowed", N
);
964 Obj_Decl
:= Last
(Return_Object_Declarations
(N
));
966 -- Analyze parts specific to extended_return_statement:
969 Has_Aliased
: constant Boolean := Aliased_Present
(Obj_Decl
);
970 HSS
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
973 Expr
:= Expression
(Obj_Decl
);
975 -- Note: The check for OK_For_Limited_Init will happen in
976 -- Analyze_Object_Declaration; we treat it as a normal
977 -- object declaration.
979 Set_Is_Return_Object
(Defining_Identifier
(Obj_Decl
));
982 Check_Return_Subtype_Indication
(Obj_Decl
);
984 if Present
(HSS
) then
987 if Present
(Exception_Handlers
(HSS
)) then
989 -- ???Has_Nested_Block_With_Handler needs to be set.
990 -- Probably by creating an actual N_Block_Statement.
991 -- Probably in Expand.
997 -- Mark the return object as referenced, since the return is an
998 -- implicit reference of the object.
1000 Set_Referenced
(Defining_Identifier
(Obj_Decl
));
1002 Check_References
(Stm_Entity
);
1004 -- Check RM 6.5 (5.9/3)
1007 if Ada_Version
< Ada_2012
then
1009 -- Shouldn't this test Warn_On_Ada_2012_Compatibility ???
1010 -- Can it really happen (extended return???)
1013 ("aliased only allowed for limited return objects "
1014 & "in Ada 2012??", N
);
1016 elsif not Is_Limited_View
(R_Type
) then
1018 ("aliased only allowed for limited return objects", N
);
1024 -- Case of Expr present
1028 -- Defend against previous errors
1030 and then Nkind
(Expr
) /= N_Empty
1031 and then Present
(Etype
(Expr
))
1033 -- Apply constraint check. Note that this is done before the implicit
1034 -- conversion of the expression done for anonymous access types to
1035 -- ensure correct generation of the null-excluding check associated
1036 -- with null-excluding expressions found in return statements.
1038 Apply_Constraint_Check
(Expr
, R_Type
);
1040 -- Ada 2005 (AI-318-02): When the result type is an anonymous access
1041 -- type, apply an implicit conversion of the expression to that type
1042 -- to force appropriate static and run-time accessibility checks.
1044 if Ada_Version
>= Ada_2005
1045 and then Ekind
(R_Type
) = E_Anonymous_Access_Type
1047 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
1048 Analyze_And_Resolve
(Expr
, R_Type
);
1050 -- If this is a local anonymous access to subprogram, the
1051 -- accessibility check can be applied statically. The return is
1052 -- illegal if the access type of the return expression is declared
1053 -- inside of the subprogram (except if it is the subtype indication
1054 -- of an extended return statement).
1056 elsif Ekind
(R_Type
) = E_Anonymous_Access_Subprogram_Type
then
1057 if not Comes_From_Source
(Current_Scope
)
1058 or else Ekind
(Current_Scope
) = E_Return_Statement
1063 Scope_Depth
(Scope
(Etype
(Expr
))) >= Scope_Depth
(Scope_Id
)
1065 Error_Msg_N
("cannot return local access to subprogram", N
);
1068 -- The expression cannot be of a formal incomplete type
1070 elsif Ekind
(Etype
(Expr
)) = E_Incomplete_Type
1071 and then Is_Generic_Type
(Etype
(Expr
))
1074 ("cannot return expression of a formal incomplete type", N
);
1077 -- If the result type is class-wide, then check that the return
1078 -- expression's type is not declared at a deeper level than the
1079 -- function (RM05-6.5(5.6/2)).
1081 if Ada_Version
>= Ada_2005
1082 and then Is_Class_Wide_Type
(R_Type
)
1084 if Type_Access_Level
(Etype
(Expr
)) >
1085 Subprogram_Access_Level
(Scope_Id
)
1088 ("level of return expression type is deeper than "
1089 & "class-wide function!", Expr
);
1093 -- Check incorrect use of dynamically tagged expression
1095 if Is_Tagged_Type
(R_Type
) then
1096 Check_Dynamically_Tagged_Expression
1102 -- ??? A real run-time accessibility check is needed in cases
1103 -- involving dereferences of access parameters. For now we just
1104 -- check the static cases.
1106 if (Ada_Version
< Ada_2005
or else Debug_Flag_Dot_L
)
1107 and then Is_Limited_View
(Etype
(Scope_Id
))
1108 and then Object_Access_Level
(Expr
) >
1109 Subprogram_Access_Level
(Scope_Id
)
1111 -- Suppress the message in a generic, where the rewriting
1114 if Inside_A_Generic
then
1119 Make_Raise_Program_Error
(Loc
,
1120 Reason
=> PE_Accessibility_Check_Failed
));
1123 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1124 Error_Msg_N
("cannot return a local value by reference<<", N
);
1125 Error_Msg_NE
("\& [<<", N
, Standard_Program_Error
);
1129 if Known_Null
(Expr
)
1130 and then Nkind
(Parent
(Scope_Id
)) = N_Function_Specification
1131 and then Null_Exclusion_Present
(Parent
(Scope_Id
))
1133 Apply_Compile_Time_Constraint_Error
1135 Msg
=> "(Ada 2005) null not allowed for "
1136 & "null-excluding return??",
1137 Reason
=> CE_Null_Not_Allowed
);
1140 -- RM 6.5 (5.4/3): accessibility checks also apply if the return object
1141 -- has no initializing expression.
1143 elsif Ada_Version
> Ada_2005
and then Is_Class_Wide_Type
(R_Type
) then
1144 if Type_Access_Level
(Etype
(Defining_Identifier
(Obj_Decl
))) >
1145 Subprogram_Access_Level
(Scope_Id
)
1148 ("level of return expression type is deeper than "
1149 & "class-wide function!", Obj_Decl
);
1152 end Analyze_Function_Return
;
1154 -------------------------------------
1155 -- Analyze_Generic_Subprogram_Body --
1156 -------------------------------------
1158 procedure Analyze_Generic_Subprogram_Body
1162 Gen_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Gen_Id
);
1163 Kind
: constant Entity_Kind
:= Ekind
(Gen_Id
);
1164 Body_Id
: Entity_Id
;
1169 -- Copy body and disable expansion while analyzing the generic For a
1170 -- stub, do not copy the stub (which would load the proper body), this
1171 -- will be done when the proper body is analyzed.
1173 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1174 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
1177 -- Once the contents of the generic copy and the template are
1178 -- swapped, do the same for their respective aspect specifications.
1180 Exchange_Aspects
(N
, New_N
);
1182 -- Collect all contract-related source pragmas found within the
1183 -- template and attach them to the contract of the subprogram body.
1184 -- This contract is used in the capture of global references within
1187 Create_Generic_Contract
(N
);
1192 Spec
:= Specification
(N
);
1194 -- Within the body of the generic, the subprogram is callable, and
1195 -- behaves like the corresponding non-generic unit.
1197 Body_Id
:= Defining_Entity
(Spec
);
1199 if Kind
= E_Generic_Procedure
1200 and then Nkind
(Spec
) /= N_Procedure_Specification
1202 Error_Msg_N
("invalid body for generic procedure ", Body_Id
);
1205 elsif Kind
= E_Generic_Function
1206 and then Nkind
(Spec
) /= N_Function_Specification
1208 Error_Msg_N
("invalid body for generic function ", Body_Id
);
1212 Set_Corresponding_Body
(Gen_Decl
, Body_Id
);
1214 if Has_Completion
(Gen_Id
)
1215 and then Nkind
(Parent
(N
)) /= N_Subunit
1217 Error_Msg_N
("duplicate generic body", N
);
1220 Set_Has_Completion
(Gen_Id
);
1223 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1224 Set_Ekind
(Defining_Entity
(Specification
(N
)), Kind
);
1226 Set_Corresponding_Spec
(N
, Gen_Id
);
1229 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1230 Set_Cunit_Entity
(Current_Sem_Unit
, Defining_Entity
(N
));
1233 -- Make generic parameters immediately visible in the body. They are
1234 -- needed to process the formals declarations. Then make the formals
1235 -- visible in a separate step.
1237 Push_Scope
(Gen_Id
);
1241 First_Ent
: Entity_Id
;
1244 First_Ent
:= First_Entity
(Gen_Id
);
1247 while Present
(E
) and then not Is_Formal
(E
) loop
1252 Set_Use
(Generic_Formal_Declarations
(Gen_Decl
));
1254 -- Now generic formals are visible, and the specification can be
1255 -- analyzed, for subsequent conformance check.
1257 Body_Id
:= Analyze_Subprogram_Specification
(Spec
);
1259 -- Make formal parameters visible
1263 -- E is the first formal parameter, we loop through the formals
1264 -- installing them so that they will be visible.
1266 Set_First_Entity
(Gen_Id
, E
);
1267 while Present
(E
) loop
1273 -- Visible generic entity is callable within its own body
1275 Set_Ekind
(Gen_Id
, Ekind
(Body_Id
));
1276 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
1277 Set_Convention
(Body_Id
, Convention
(Gen_Id
));
1278 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Gen_Id
));
1279 Set_Scope
(Body_Id
, Scope
(Gen_Id
));
1281 Check_Fully_Conformant
(Body_Id
, Gen_Id
, Body_Id
);
1283 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1285 -- No body to analyze, so restore state of generic unit
1287 Set_Ekind
(Gen_Id
, Kind
);
1288 Set_Ekind
(Body_Id
, Kind
);
1290 if Present
(First_Ent
) then
1291 Set_First_Entity
(Gen_Id
, First_Ent
);
1298 -- If this is a compilation unit, it must be made visible explicitly,
1299 -- because the compilation of the declaration, unlike other library
1300 -- unit declarations, does not. If it is not a unit, the following
1301 -- is redundant but harmless.
1303 Set_Is_Immediately_Visible
(Gen_Id
);
1304 Reference_Body_Formals
(Gen_Id
, Body_Id
);
1306 if Is_Child_Unit
(Gen_Id
) then
1307 Generate_Reference
(Gen_Id
, Scope
(Gen_Id
), 'k', False);
1310 Set_Actual_Subtypes
(N
, Current_Scope
);
1312 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
1313 Set_SPARK_Pragma_Inherited
(Body_Id
);
1315 -- Analyze any aspect specifications that appear on the generic
1318 if Has_Aspects
(N
) then
1319 Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
);
1322 Analyze_Declarations
(Declarations
(N
));
1325 -- Process the contract of the subprogram body after all declarations
1326 -- have been analyzed. This ensures that any contract-related pragmas
1327 -- are available through the N_Contract node of the body.
1329 Analyze_Entry_Or_Subprogram_Body_Contract
(Body_Id
);
1331 Analyze
(Handled_Statement_Sequence
(N
));
1332 Save_Global_References
(Original_Node
(N
));
1334 -- Prior to exiting the scope, include generic formals again (if any
1335 -- are present) in the set of local entities.
1337 if Present
(First_Ent
) then
1338 Set_First_Entity
(Gen_Id
, First_Ent
);
1341 Check_References
(Gen_Id
);
1344 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Current_Scope
);
1346 Check_Subprogram_Order
(N
);
1348 -- Outside of its body, unit is generic again
1350 Set_Ekind
(Gen_Id
, Kind
);
1351 Generate_Reference
(Gen_Id
, Body_Id
, 'b', Set_Ref
=> False);
1354 Style
.Check_Identifier
(Body_Id
, Gen_Id
);
1358 end Analyze_Generic_Subprogram_Body
;
1360 ----------------------------
1361 -- Analyze_Null_Procedure --
1362 ----------------------------
1364 procedure Analyze_Null_Procedure
1366 Is_Completion
: out Boolean)
1368 Loc
: constant Source_Ptr
:= Sloc
(N
);
1369 Spec
: constant Node_Id
:= Specification
(N
);
1370 Designator
: Entity_Id
;
1372 Null_Body
: Node_Id
:= Empty
;
1376 -- Capture the profile of the null procedure before analysis, for
1377 -- expansion at the freeze point and at each point of call. The body is
1378 -- used if the procedure has preconditions, or if it is a completion. In
1379 -- the first case the body is analyzed at the freeze point, in the other
1380 -- it replaces the null procedure declaration.
1383 Make_Subprogram_Body
(Loc
,
1384 Specification
=> New_Copy_Tree
(Spec
),
1385 Declarations
=> New_List
,
1386 Handled_Statement_Sequence
=>
1387 Make_Handled_Sequence_Of_Statements
(Loc
,
1388 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
1390 -- Create new entities for body and formals
1392 Set_Defining_Unit_Name
(Specification
(Null_Body
),
1393 Make_Defining_Identifier
1394 (Sloc
(Defining_Entity
(N
)),
1395 Chars
(Defining_Entity
(N
))));
1397 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1398 while Present
(Form
) loop
1399 Set_Defining_Identifier
(Form
,
1400 Make_Defining_Identifier
1401 (Sloc
(Defining_Identifier
(Form
)),
1402 Chars
(Defining_Identifier
(Form
))));
1406 -- Determine whether the null procedure may be a completion of a generic
1407 -- suprogram, in which case we use the new null body as the completion
1408 -- and set minimal semantic information on the original declaration,
1409 -- which is rewritten as a null statement.
1411 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
1413 if Present
(Prev
) and then Is_Generic_Subprogram
(Prev
) then
1414 Insert_Before
(N
, Null_Body
);
1415 Set_Ekind
(Defining_Entity
(N
), Ekind
(Prev
));
1417 Rewrite
(N
, Make_Null_Statement
(Loc
));
1418 Analyze_Generic_Subprogram_Body
(Null_Body
, Prev
);
1419 Is_Completion
:= True;
1423 -- Resolve the types of the formals now, because the freeze point
1424 -- may appear in a different context, e.g. an instantiation.
1426 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1427 while Present
(Form
) loop
1428 if Nkind
(Parameter_Type
(Form
)) /= N_Access_Definition
then
1429 Find_Type
(Parameter_Type
(Form
));
1432 No
(Access_To_Subprogram_Definition
(Parameter_Type
(Form
)))
1434 Find_Type
(Subtype_Mark
(Parameter_Type
(Form
)));
1437 -- The case of a null procedure with a formal that is an
1438 -- access_to_subprogram type, and that is used as an actual
1439 -- in an instantiation is left to the enthusiastic reader.
1448 -- If there are previous overloadable entities with the same name,
1449 -- check whether any of them is completed by the null procedure.
1451 if Present
(Prev
) and then Is_Overloadable
(Prev
) then
1452 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1453 Prev
:= Find_Corresponding_Spec
(N
);
1456 if No
(Prev
) or else not Comes_From_Source
(Prev
) then
1457 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1458 Set_Has_Completion
(Designator
);
1460 -- Signal to caller that this is a procedure declaration
1462 Is_Completion
:= False;
1464 -- Null procedures are always inlined, but generic formal subprograms
1465 -- which appear as such in the internal instance of formal packages,
1466 -- need no completion and are not marked Inline.
1469 and then Nkind
(N
) /= N_Formal_Concrete_Subprogram_Declaration
1471 Set_Corresponding_Body
(N
, Defining_Entity
(Null_Body
));
1472 Set_Body_To_Inline
(N
, Null_Body
);
1473 Set_Is_Inlined
(Designator
);
1477 -- The null procedure is a completion. We unconditionally rewrite
1478 -- this as a null body (even if expansion is not active), because
1479 -- there are various error checks that are applied on this body
1480 -- when it is analyzed (e.g. correct aspect placement).
1482 if Has_Completion
(Prev
) then
1483 Error_Msg_Sloc
:= Sloc
(Prev
);
1484 Error_Msg_NE
("duplicate body for & declared#", N
, Prev
);
1487 Is_Completion
:= True;
1488 Rewrite
(N
, Null_Body
);
1491 end Analyze_Null_Procedure
;
1493 -----------------------------
1494 -- Analyze_Operator_Symbol --
1495 -----------------------------
1497 -- An operator symbol such as "+" or "and" may appear in context where the
1498 -- literal denotes an entity name, such as "+"(x, y) or in context when it
1499 -- is just a string, as in (conjunction = "or"). In these cases the parser
1500 -- generates this node, and the semantics does the disambiguation. Other
1501 -- such case are actuals in an instantiation, the generic unit in an
1502 -- instantiation, and pragma arguments.
1504 procedure Analyze_Operator_Symbol
(N
: Node_Id
) is
1505 Par
: constant Node_Id
:= Parent
(N
);
1508 if (Nkind
(Par
) = N_Function_Call
and then N
= Name
(Par
))
1509 or else Nkind
(Par
) = N_Function_Instantiation
1510 or else (Nkind
(Par
) = N_Indexed_Component
and then N
= Prefix
(Par
))
1511 or else (Nkind
(Par
) = N_Pragma_Argument_Association
1512 and then not Is_Pragma_String_Literal
(Par
))
1513 or else Nkind
(Par
) = N_Subprogram_Renaming_Declaration
1514 or else (Nkind
(Par
) = N_Attribute_Reference
1515 and then Attribute_Name
(Par
) /= Name_Value
)
1517 Find_Direct_Name
(N
);
1520 Change_Operator_Symbol_To_String_Literal
(N
);
1523 end Analyze_Operator_Symbol
;
1525 -----------------------------------
1526 -- Analyze_Parameter_Association --
1527 -----------------------------------
1529 procedure Analyze_Parameter_Association
(N
: Node_Id
) is
1531 Analyze
(Explicit_Actual_Parameter
(N
));
1532 end Analyze_Parameter_Association
;
1534 ----------------------------
1535 -- Analyze_Procedure_Call --
1536 ----------------------------
1538 -- WARNING: This routine manages Ghost regions. Return statements must be
1539 -- replaced by gotos which jump to the end of the routine and restore the
1542 procedure Analyze_Procedure_Call
(N
: Node_Id
) is
1543 procedure Analyze_Call_And_Resolve
;
1544 -- Do Analyze and Resolve calls for procedure call. At the end, check
1545 -- for illegal order dependence.
1546 -- ??? where is the check for illegal order dependencies?
1548 ------------------------------
1549 -- Analyze_Call_And_Resolve --
1550 ------------------------------
1552 procedure Analyze_Call_And_Resolve
is
1554 if Nkind
(N
) = N_Procedure_Call_Statement
then
1556 Resolve
(N
, Standard_Void_Type
);
1560 end Analyze_Call_And_Resolve
;
1564 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
1565 Loc
: constant Source_Ptr
:= Sloc
(N
);
1566 P
: constant Node_Id
:= Name
(N
);
1568 Mode
: Ghost_Mode_Type
;
1571 -- Start of processing for Analyze_Procedure_Call
1574 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
1575 -- a procedure call or an entry call. The prefix may denote an access
1576 -- to subprogram type, in which case an implicit dereference applies.
1577 -- If the prefix is an indexed component (without implicit dereference)
1578 -- then the construct denotes a call to a member of an entire family.
1579 -- If the prefix is a simple name, it may still denote a call to a
1580 -- parameterless member of an entry family. Resolution of these various
1581 -- interpretations is delicate.
1583 -- Do not analyze machine code statements to avoid rejecting them in
1586 if CodePeer_Mode
and then Nkind
(P
) = N_Qualified_Expression
then
1587 Set_Etype
(P
, Standard_Void_Type
);
1592 -- If this is a call of the form Obj.Op, the call may have been analyzed
1593 -- and possibly rewritten into a block, in which case we are done.
1595 if Analyzed
(N
) then
1599 -- If there is an error analyzing the name (which may have been
1600 -- rewritten if the original call was in prefix notation) then error
1601 -- has been emitted already, mark node and return.
1603 if Error_Posted
(N
) or else Etype
(Name
(N
)) = Any_Type
then
1604 Set_Etype
(N
, Any_Type
);
1608 -- A procedure call is Ghost when its name denotes a Ghost procedure.
1609 -- Set the mode now to ensure that any nodes generated during analysis
1610 -- and expansion are properly marked as Ghost.
1612 Mark_And_Set_Ghost_Procedure_Call
(N
, Mode
);
1614 -- Otherwise analyze the parameters
1616 if Present
(Actuals
) then
1617 Actual
:= First
(Actuals
);
1619 while Present
(Actual
) loop
1621 Check_Parameterless_Call
(Actual
);
1626 -- Special processing for Elab_Spec, Elab_Body and Elab_Subp_Body calls
1628 if Nkind
(P
) = N_Attribute_Reference
1629 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Spec
,
1631 Name_Elab_Subp_Body
)
1633 if Present
(Actuals
) then
1635 ("no parameters allowed for this call", First
(Actuals
));
1639 Set_Etype
(N
, Standard_Void_Type
);
1642 elsif Is_Entity_Name
(P
)
1643 and then Is_Record_Type
(Etype
(Entity
(P
)))
1644 and then Remote_AST_I_Dereference
(P
)
1648 elsif Is_Entity_Name
(P
)
1649 and then Ekind
(Entity
(P
)) /= E_Entry_Family
1651 if Is_Access_Type
(Etype
(P
))
1652 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1653 and then No
(Actuals
)
1654 and then Comes_From_Source
(N
)
1656 Error_Msg_N
("missing explicit dereference in call", N
);
1659 Analyze_Call_And_Resolve
;
1661 -- If the prefix is the simple name of an entry family, this is a
1662 -- parameterless call from within the task body itself.
1664 elsif Is_Entity_Name
(P
)
1665 and then Nkind
(P
) = N_Identifier
1666 and then Ekind
(Entity
(P
)) = E_Entry_Family
1667 and then Present
(Actuals
)
1668 and then No
(Next
(First
(Actuals
)))
1670 -- Can be call to parameterless entry family. What appears to be the
1671 -- sole argument is in fact the entry index. Rewrite prefix of node
1672 -- accordingly. Source representation is unchanged by this
1676 Make_Indexed_Component
(Loc
,
1678 Make_Selected_Component
(Loc
,
1679 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(P
)), Loc
),
1680 Selector_Name
=> New_Occurrence_Of
(Entity
(P
), Loc
)),
1681 Expressions
=> Actuals
);
1682 Set_Name
(N
, New_N
);
1683 Set_Etype
(New_N
, Standard_Void_Type
);
1684 Set_Parameter_Associations
(N
, No_List
);
1685 Analyze_Call_And_Resolve
;
1687 elsif Nkind
(P
) = N_Explicit_Dereference
then
1688 if Ekind
(Etype
(P
)) = E_Subprogram_Type
then
1689 Analyze_Call_And_Resolve
;
1691 Error_Msg_N
("expect access to procedure in call", P
);
1694 -- The name can be a selected component or an indexed component that
1695 -- yields an access to subprogram. Such a prefix is legal if the call
1696 -- has parameter associations.
1698 elsif Is_Access_Type
(Etype
(P
))
1699 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1701 if Present
(Actuals
) then
1702 Analyze_Call_And_Resolve
;
1704 Error_Msg_N
("missing explicit dereference in call ", N
);
1707 -- If not an access to subprogram, then the prefix must resolve to the
1708 -- name of an entry, entry family, or protected operation.
1710 -- For the case of a simple entry call, P is a selected component where
1711 -- the prefix is the task and the selector name is the entry. A call to
1712 -- a protected procedure will have the same syntax. If the protected
1713 -- object contains overloaded operations, the entity may appear as a
1714 -- function, the context will select the operation whose type is Void.
1716 elsif Nkind
(P
) = N_Selected_Component
1717 and then Ekind_In
(Entity
(Selector_Name
(P
)), E_Entry
,
1721 -- When front-end inlining is enabled, as with SPARK_Mode, a call
1722 -- in prefix notation may still be missing its controlling argument,
1723 -- so perform the transformation now.
1725 if SPARK_Mode
= On
and then In_Inlined_Body
then
1727 Subp
: constant Entity_Id
:= Entity
(Selector_Name
(P
));
1728 Typ
: constant Entity_Id
:= Etype
(Prefix
(P
));
1731 if Is_Tagged_Type
(Typ
)
1732 and then Present
(First_Formal
(Subp
))
1733 and then Etype
(First_Formal
(Subp
)) = Typ
1734 and then Try_Object_Operation
(P
)
1739 Analyze_Call_And_Resolve
;
1744 Analyze_Call_And_Resolve
;
1747 elsif Nkind
(P
) = N_Selected_Component
1748 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
1749 and then Present
(Actuals
)
1750 and then No
(Next
(First
(Actuals
)))
1752 -- Can be call to parameterless entry family. What appears to be the
1753 -- sole argument is in fact the entry index. Rewrite prefix of node
1754 -- accordingly. Source representation is unchanged by this
1758 Make_Indexed_Component
(Loc
,
1759 Prefix
=> New_Copy
(P
),
1760 Expressions
=> Actuals
);
1761 Set_Name
(N
, New_N
);
1762 Set_Etype
(New_N
, Standard_Void_Type
);
1763 Set_Parameter_Associations
(N
, No_List
);
1764 Analyze_Call_And_Resolve
;
1766 -- For the case of a reference to an element of an entry family, P is
1767 -- an indexed component whose prefix is a selected component (task and
1768 -- entry family), and whose index is the entry family index.
1770 elsif Nkind
(P
) = N_Indexed_Component
1771 and then Nkind
(Prefix
(P
)) = N_Selected_Component
1772 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) = E_Entry_Family
1774 Analyze_Call_And_Resolve
;
1776 -- If the prefix is the name of an entry family, it is a call from
1777 -- within the task body itself.
1779 elsif Nkind
(P
) = N_Indexed_Component
1780 and then Nkind
(Prefix
(P
)) = N_Identifier
1781 and then Ekind
(Entity
(Prefix
(P
))) = E_Entry_Family
1784 Make_Selected_Component
(Loc
,
1785 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(Prefix
(P
))), Loc
),
1786 Selector_Name
=> New_Occurrence_Of
(Entity
(Prefix
(P
)), Loc
));
1787 Rewrite
(Prefix
(P
), New_N
);
1789 Analyze_Call_And_Resolve
;
1791 -- In Ada 2012. a qualified expression is a name, but it cannot be a
1792 -- procedure name, so the construct can only be a qualified expression.
1794 elsif Nkind
(P
) = N_Qualified_Expression
1795 and then Ada_Version
>= Ada_2012
1797 Rewrite
(N
, Make_Code_Statement
(Loc
, Expression
=> P
));
1800 -- Anything else is an error
1803 Error_Msg_N
("invalid procedure or entry call", N
);
1807 Restore_Ghost_Mode
(Mode
);
1808 end Analyze_Procedure_Call
;
1810 ------------------------------
1811 -- Analyze_Return_Statement --
1812 ------------------------------
1814 procedure Analyze_Return_Statement
(N
: Node_Id
) is
1815 pragma Assert
(Nkind_In
(N
, N_Extended_Return_Statement
,
1816 N_Simple_Return_Statement
));
1818 Returns_Object
: constant Boolean :=
1819 Nkind
(N
) = N_Extended_Return_Statement
1821 (Nkind
(N
) = N_Simple_Return_Statement
1822 and then Present
(Expression
(N
)));
1823 -- True if we're returning something; that is, "return <expression>;"
1824 -- or "return Result : T [:= ...]". False for "return;". Used for error
1825 -- checking: If Returns_Object is True, N should apply to a function
1826 -- body; otherwise N should apply to a procedure body, entry body,
1827 -- accept statement, or extended return statement.
1829 function Find_What_It_Applies_To
return Entity_Id
;
1830 -- Find the entity representing the innermost enclosing body, accept
1831 -- statement, or extended return statement. If the result is a callable
1832 -- construct or extended return statement, then this will be the value
1833 -- of the Return_Applies_To attribute. Otherwise, the program is
1834 -- illegal. See RM-6.5(4/2).
1836 -----------------------------
1837 -- Find_What_It_Applies_To --
1838 -----------------------------
1840 function Find_What_It_Applies_To
return Entity_Id
is
1841 Result
: Entity_Id
:= Empty
;
1844 -- Loop outward through the Scope_Stack, skipping blocks, loops,
1845 -- and postconditions.
1847 for J
in reverse 0 .. Scope_Stack
.Last
loop
1848 Result
:= Scope_Stack
.Table
(J
).Entity
;
1849 exit when not Ekind_In
(Result
, E_Block
, E_Loop
)
1850 and then Chars
(Result
) /= Name_uPostconditions
;
1853 pragma Assert
(Present
(Result
));
1855 end Find_What_It_Applies_To
;
1857 -- Local declarations
1859 Scope_Id
: constant Entity_Id
:= Find_What_It_Applies_To
;
1860 Kind
: constant Entity_Kind
:= Ekind
(Scope_Id
);
1861 Loc
: constant Source_Ptr
:= Sloc
(N
);
1862 Stm_Entity
: constant Entity_Id
:=
1864 (E_Return_Statement
, Current_Scope
, Loc
, 'R');
1866 -- Start of processing for Analyze_Return_Statement
1869 Set_Return_Statement_Entity
(N
, Stm_Entity
);
1871 Set_Etype
(Stm_Entity
, Standard_Void_Type
);
1872 Set_Return_Applies_To
(Stm_Entity
, Scope_Id
);
1874 -- Place Return entity on scope stack, to simplify enforcement of 6.5
1875 -- (4/2): an inner return statement will apply to this extended return.
1877 if Nkind
(N
) = N_Extended_Return_Statement
then
1878 Push_Scope
(Stm_Entity
);
1881 -- Check that pragma No_Return is obeyed. Don't complain about the
1882 -- implicitly-generated return that is placed at the end.
1884 if No_Return
(Scope_Id
) and then Comes_From_Source
(N
) then
1885 Error_Msg_N
("RETURN statement not allowed (No_Return)", N
);
1888 -- Warn on any unassigned OUT parameters if in procedure
1890 if Ekind
(Scope_Id
) = E_Procedure
then
1891 Warn_On_Unassigned_Out_Parameter
(N
, Scope_Id
);
1894 -- Check that functions return objects, and other things do not
1896 if Kind
= E_Function
or else Kind
= E_Generic_Function
then
1897 if not Returns_Object
then
1898 Error_Msg_N
("missing expression in return from function", N
);
1901 elsif Kind
= E_Procedure
or else Kind
= E_Generic_Procedure
then
1902 if Returns_Object
then
1903 Error_Msg_N
("procedure cannot return value (use function)", N
);
1906 elsif Kind
= E_Entry
or else Kind
= E_Entry_Family
then
1907 if Returns_Object
then
1908 if Is_Protected_Type
(Scope
(Scope_Id
)) then
1909 Error_Msg_N
("entry body cannot return value", N
);
1911 Error_Msg_N
("accept statement cannot return value", N
);
1915 elsif Kind
= E_Return_Statement
then
1917 -- We are nested within another return statement, which must be an
1918 -- extended_return_statement.
1920 if Returns_Object
then
1921 if Nkind
(N
) = N_Extended_Return_Statement
then
1923 ("extended return statement cannot be nested (use `RETURN;`)",
1926 -- Case of a simple return statement with a value inside extended
1927 -- return statement.
1931 ("return nested in extended return statement cannot return "
1932 & "value (use `RETURN;`)", N
);
1937 Error_Msg_N
("illegal context for return statement", N
);
1940 if Ekind_In
(Kind
, E_Function
, E_Generic_Function
) then
1941 Analyze_Function_Return
(N
);
1943 elsif Ekind_In
(Kind
, E_Procedure
, E_Generic_Procedure
) then
1944 Set_Return_Present
(Scope_Id
);
1947 if Nkind
(N
) = N_Extended_Return_Statement
then
1951 Kill_Current_Values
(Last_Assignment_Only
=> True);
1952 Check_Unreachable_Code
(N
);
1954 Analyze_Dimension
(N
);
1955 end Analyze_Return_Statement
;
1957 -------------------------------------
1958 -- Analyze_Simple_Return_Statement --
1959 -------------------------------------
1961 procedure Analyze_Simple_Return_Statement
(N
: Node_Id
) is
1963 if Present
(Expression
(N
)) then
1964 Mark_Coextensions
(N
, Expression
(N
));
1967 Analyze_Return_Statement
(N
);
1968 end Analyze_Simple_Return_Statement
;
1970 -------------------------
1971 -- Analyze_Return_Type --
1972 -------------------------
1974 procedure Analyze_Return_Type
(N
: Node_Id
) is
1975 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
1976 Typ
: Entity_Id
:= Empty
;
1979 -- Normal case where result definition does not indicate an error
1981 if Result_Definition
(N
) /= Error
then
1982 if Nkind
(Result_Definition
(N
)) = N_Access_Definition
then
1983 Check_SPARK_05_Restriction
1984 ("access result is not allowed", Result_Definition
(N
));
1986 -- Ada 2005 (AI-254): Handle anonymous access to subprograms
1989 AD
: constant Node_Id
:=
1990 Access_To_Subprogram_Definition
(Result_Definition
(N
));
1992 if Present
(AD
) and then Protected_Present
(AD
) then
1993 Typ
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
1995 Typ
:= Access_Definition
(N
, Result_Definition
(N
));
1999 Set_Parent
(Typ
, Result_Definition
(N
));
2000 Set_Is_Local_Anonymous_Access
(Typ
);
2001 Set_Etype
(Designator
, Typ
);
2003 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
2005 Null_Exclusion_Static_Checks
(N
);
2007 -- Subtype_Mark case
2010 Find_Type
(Result_Definition
(N
));
2011 Typ
:= Entity
(Result_Definition
(N
));
2012 Set_Etype
(Designator
, Typ
);
2014 -- Unconstrained array as result is not allowed in SPARK
2016 if Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
2017 Check_SPARK_05_Restriction
2018 ("returning an unconstrained array is not allowed",
2019 Result_Definition
(N
));
2022 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
2024 Null_Exclusion_Static_Checks
(N
);
2026 -- If a null exclusion is imposed on the result type, then create
2027 -- a null-excluding itype (an access subtype) and use it as the
2028 -- function's Etype. Note that the null exclusion checks are done
2029 -- right before this, because they don't get applied to types that
2030 -- do not come from source.
2032 if Is_Access_Type
(Typ
) and then Null_Exclusion_Present
(N
) then
2033 Set_Etype
(Designator
,
2034 Create_Null_Excluding_Itype
2037 Scope_Id
=> Scope
(Current_Scope
)));
2039 -- The new subtype must be elaborated before use because
2040 -- it is visible outside of the function. However its base
2041 -- type may not be frozen yet, so the reference that will
2042 -- force elaboration must be attached to the freezing of
2045 -- If the return specification appears on a proper body,
2046 -- the subtype will have been created already on the spec.
2048 if Is_Frozen
(Typ
) then
2049 if Nkind
(Parent
(N
)) = N_Subprogram_Body
2050 and then Nkind
(Parent
(Parent
(N
))) = N_Subunit
2054 Build_Itype_Reference
(Etype
(Designator
), Parent
(N
));
2058 Ensure_Freeze_Node
(Typ
);
2061 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(N
));
2063 Set_Itype
(IR
, Etype
(Designator
));
2064 Append_Freeze_Actions
(Typ
, New_List
(IR
));
2069 Set_Etype
(Designator
, Typ
);
2072 if Ekind
(Typ
) = E_Incomplete_Type
2073 or else (Is_Class_Wide_Type
(Typ
)
2074 and then Ekind
(Root_Type
(Typ
)) = E_Incomplete_Type
)
2076 -- AI05-0151: Tagged incomplete types are allowed in all formal
2077 -- parts. Untagged incomplete types are not allowed in bodies.
2078 -- As a consequence, limited views cannot appear in a basic
2079 -- declaration that is itself within a body, because there is
2080 -- no point at which the non-limited view will become visible.
2082 if Ada_Version
>= Ada_2012
then
2083 if From_Limited_With
(Typ
) and then In_Package_Body
then
2085 ("invalid use of incomplete type&",
2086 Result_Definition
(N
), Typ
);
2088 -- The return type of a subprogram body cannot be of a
2089 -- formal incomplete type.
2091 elsif Is_Generic_Type
(Typ
)
2092 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
2095 ("return type cannot be a formal incomplete type",
2096 Result_Definition
(N
));
2098 elsif Is_Class_Wide_Type
(Typ
)
2099 and then Is_Generic_Type
(Root_Type
(Typ
))
2100 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
2103 ("return type cannot be a formal incomplete type",
2104 Result_Definition
(N
));
2106 elsif Is_Tagged_Type
(Typ
) then
2109 -- Use is legal in a thunk generated for an operation
2110 -- inherited from a progenitor.
2112 elsif Is_Thunk
(Designator
)
2113 and then Present
(Non_Limited_View
(Typ
))
2117 elsif Nkind
(Parent
(N
)) = N_Subprogram_Body
2118 or else Nkind_In
(Parent
(Parent
(N
)), N_Accept_Statement
,
2122 ("invalid use of untagged incomplete type&",
2126 -- The type must be completed in the current package. This
2127 -- is checked at the end of the package declaration when
2128 -- Taft-amendment types are identified. If the return type
2129 -- is class-wide, there is no required check, the type can
2130 -- be a bona fide TAT.
2132 if Ekind
(Scope
(Current_Scope
)) = E_Package
2133 and then In_Private_Part
(Scope
(Current_Scope
))
2134 and then not Is_Class_Wide_Type
(Typ
)
2136 Append_Elmt
(Designator
, Private_Dependents
(Typ
));
2141 ("invalid use of incomplete type&", Designator
, Typ
);
2146 -- Case where result definition does indicate an error
2149 Set_Etype
(Designator
, Any_Type
);
2151 end Analyze_Return_Type
;
2153 -----------------------------
2154 -- Analyze_Subprogram_Body --
2155 -----------------------------
2157 procedure Analyze_Subprogram_Body
(N
: Node_Id
) is
2158 Loc
: constant Source_Ptr
:= Sloc
(N
);
2159 Body_Spec
: constant Node_Id
:= Specification
(N
);
2160 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Spec
);
2163 if Debug_Flag_C
then
2164 Write_Str
("==> subprogram body ");
2165 Write_Name
(Chars
(Body_Id
));
2166 Write_Str
(" from ");
2167 Write_Location
(Loc
);
2172 Trace_Scope
(N
, Body_Id
, " Analyze subprogram: ");
2174 -- The real work is split out into the helper, so it can do "return;"
2175 -- without skipping the debug output:
2177 Analyze_Subprogram_Body_Helper
(N
);
2179 if Debug_Flag_C
then
2181 Write_Str
("<== subprogram body ");
2182 Write_Name
(Chars
(Body_Id
));
2183 Write_Str
(" from ");
2184 Write_Location
(Loc
);
2187 end Analyze_Subprogram_Body
;
2189 ------------------------------------
2190 -- Analyze_Subprogram_Body_Helper --
2191 ------------------------------------
2193 -- This procedure is called for regular subprogram bodies, generic bodies,
2194 -- and for subprogram stubs of both kinds. In the case of stubs, only the
2195 -- specification matters, and is used to create a proper declaration for
2196 -- the subprogram, or to perform conformance checks.
2198 -- WARNING: This routine manages Ghost regions. Return statements must be
2199 -- replaced by gotos which jump to the end of the routine and restore the
2202 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
) is
2203 Body_Spec
: Node_Id
:= Specification
(N
);
2204 Body_Id
: Entity_Id
:= Defining_Entity
(Body_Spec
);
2205 Loc
: constant Source_Ptr
:= Sloc
(N
);
2206 Prev_Id
: constant Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
2208 Conformant
: Boolean;
2209 Desig_View
: Entity_Id
:= Empty
;
2210 Exch_Views
: Elist_Id
:= No_Elist
;
2212 Prot_Typ
: Entity_Id
:= Empty
;
2213 Spec_Decl
: Node_Id
:= Empty
;
2214 Spec_Id
: Entity_Id
;
2216 Last_Real_Spec_Entity
: Entity_Id
:= Empty
;
2217 -- When we analyze a separate spec, the entity chain ends up containing
2218 -- the formals, as well as any itypes generated during analysis of the
2219 -- default expressions for parameters, or the arguments of associated
2220 -- precondition/postcondition pragmas (which are analyzed in the context
2221 -- of the spec since they have visibility on formals).
2223 -- These entities belong with the spec and not the body. However we do
2224 -- the analysis of the body in the context of the spec (again to obtain
2225 -- visibility to the formals), and all the entities generated during
2226 -- this analysis end up also chained to the entity chain of the spec.
2227 -- But they really belong to the body, and there is circuitry to move
2228 -- them from the spec to the body.
2230 -- However, when we do this move, we don't want to move the real spec
2231 -- entities (first para above) to the body. The Last_Real_Spec_Entity
2232 -- variable points to the last real spec entity, so we only move those
2233 -- chained beyond that point. It is initialized to Empty to deal with
2234 -- the case where there is no separate spec.
2236 function Body_Has_Contract
return Boolean;
2237 -- Check whether unanalyzed body has an aspect or pragma that may
2238 -- generate a SPARK contract.
2240 function Body_Has_SPARK_Mode_On
return Boolean;
2241 -- Check whether SPARK_Mode On applies to the subprogram body, either
2242 -- because it is specified directly on the body, or because it is
2243 -- inherited from the enclosing subprogram or package.
2245 procedure Build_Subprogram_Declaration
;
2246 -- Create a matching subprogram declaration for subprogram body N
2248 procedure Check_Anonymous_Return
;
2249 -- Ada 2005: if a function returns an access type that denotes a task,
2250 -- or a type that contains tasks, we must create a master entity for
2251 -- the anonymous type, which typically will be used in an allocator
2252 -- in the body of the function.
2254 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
);
2255 -- Look ahead to recognize a pragma that may appear after the body.
2256 -- If there is a previous spec, check that it appears in the same
2257 -- declarative part. If the pragma is Inline_Always, perform inlining
2258 -- unconditionally, otherwise only if Front_End_Inlining is requested.
2259 -- If the body acts as a spec, and inlining is required, we create a
2260 -- subprogram declaration for it, in order to attach the body to inline.
2261 -- If pragma does not appear after the body, check whether there is
2262 -- an inline pragma before any local declarations.
2264 procedure Check_Missing_Return
;
2265 -- Checks for a function with a no return statements, and also performs
2266 -- the warning checks implemented by Check_Returns. In formal mode, also
2267 -- verify that a function ends with a RETURN and that a procedure does
2268 -- not contain any RETURN.
2270 function Disambiguate_Spec
return Entity_Id
;
2271 -- When a primitive is declared between the private view and the full
2272 -- view of a concurrent type which implements an interface, a special
2273 -- mechanism is used to find the corresponding spec of the primitive
2276 function Exchange_Limited_Views
(Subp_Id
: Entity_Id
) return Elist_Id
;
2277 -- Ada 2012 (AI05-0151): Detect whether the profile of Subp_Id contains
2278 -- incomplete types coming from a limited context and replace their
2279 -- limited views with the non-limited ones. Return the list of changes
2280 -- to be used to undo the transformation.
2282 procedure Freeze_Expr_Types
(Spec_Id
: Entity_Id
);
2283 -- AI12-0103: N is the body associated with an expression function that
2284 -- is a completion, and Spec_Id is its defining entity. Freeze before N
2285 -- all the types referenced by the expression of the function.
2287 function Is_Private_Concurrent_Primitive
2288 (Subp_Id
: Entity_Id
) return Boolean;
2289 -- Determine whether subprogram Subp_Id is a primitive of a concurrent
2290 -- type that implements an interface and has a private view.
2292 procedure Restore_Limited_Views
(Restore_List
: Elist_Id
);
2293 -- Undo the transformation done by Exchange_Limited_Views.
2295 procedure Set_Trivial_Subprogram
(N
: Node_Id
);
2296 -- Sets the Is_Trivial_Subprogram flag in both spec and body of the
2297 -- subprogram whose body is being analyzed. N is the statement node
2298 -- causing the flag to be set, if the following statement is a return
2299 -- of an entity, we mark the entity as set in source to suppress any
2300 -- warning on the stylized use of function stubs with a dummy return.
2302 procedure Verify_Overriding_Indicator
;
2303 -- If there was a previous spec, the entity has been entered in the
2304 -- current scope previously. If the body itself carries an overriding
2305 -- indicator, check that it is consistent with the known status of the
2308 -----------------------
2309 -- Body_Has_Contract --
2310 -----------------------
2312 function Body_Has_Contract
return Boolean is
2313 Decls
: constant List_Id
:= Declarations
(N
);
2317 -- Check for aspects that may generate a contract
2319 if Present
(Aspect_Specifications
(N
)) then
2320 Item
:= First
(Aspect_Specifications
(N
));
2321 while Present
(Item
) loop
2322 if Is_Subprogram_Contract_Annotation
(Item
) then
2330 -- Check for pragmas that may generate a contract
2332 if Present
(Decls
) then
2333 Item
:= First
(Decls
);
2334 while Present
(Item
) loop
2335 if Nkind
(Item
) = N_Pragma
2336 and then Is_Subprogram_Contract_Annotation
(Item
)
2346 end Body_Has_Contract
;
2348 ----------------------------
2349 -- Body_Has_SPARK_Mode_On --
2350 ----------------------------
2352 function Body_Has_SPARK_Mode_On
return Boolean is
2353 Decls
: constant List_Id
:= Declarations
(N
);
2357 -- Check for SPARK_Mode aspect
2359 if Present
(Aspect_Specifications
(N
)) then
2360 Item
:= First
(Aspect_Specifications
(N
));
2361 while Present
(Item
) loop
2362 if Get_Aspect_Id
(Item
) = Aspect_SPARK_Mode
then
2363 return Get_SPARK_Mode_From_Annotation
(Item
) = On
;
2370 -- Check for SPARK_Mode pragma
2372 if Present
(Decls
) then
2373 Item
:= First
(Decls
);
2374 while Present
(Item
) loop
2376 -- Pragmas that apply to a subprogram body are usually grouped
2377 -- together. Look for a potential pragma SPARK_Mode among them.
2379 if Nkind
(Item
) = N_Pragma
then
2380 if Get_Pragma_Id
(Item
) = Pragma_SPARK_Mode
then
2381 return Get_SPARK_Mode_From_Annotation
(Item
) = On
;
2384 -- Otherwise the first non-pragma declarative item terminates
2385 -- the region where pragma SPARK_Mode may appear.
2395 -- Otherwise, the applicable SPARK_Mode is inherited from the
2396 -- enclosing subprogram or package.
2398 return SPARK_Mode
= On
;
2399 end Body_Has_SPARK_Mode_On
;
2401 ----------------------------------
2402 -- Build_Subprogram_Declaration --
2403 ----------------------------------
2405 procedure Build_Subprogram_Declaration
is
2406 procedure Move_Pragmas
(From
: Node_Id
; To
: Node_Id
);
2407 -- Relocate certain categorization pragmas from the declarative list
2408 -- of subprogram body From and insert them after node To. The pragmas
2411 -- Volatile_Function
2412 -- Also copy pragma SPARK_Mode if present in the declarative list
2413 -- of subprogram body From and insert it after node To. This pragma
2414 -- should not be moved, as it applies to the body too.
2420 procedure Move_Pragmas
(From
: Node_Id
; To
: Node_Id
) is
2422 Next_Decl
: Node_Id
;
2425 pragma Assert
(Nkind
(From
) = N_Subprogram_Body
);
2427 -- The destination node must be part of a list, as the pragmas are
2428 -- inserted after it.
2430 pragma Assert
(Is_List_Member
(To
));
2432 -- Inspect the declarations of the subprogram body looking for
2433 -- specific pragmas.
2435 Decl
:= First
(Declarations
(N
));
2436 while Present
(Decl
) loop
2437 Next_Decl
:= Next
(Decl
);
2439 if Nkind
(Decl
) = N_Pragma
then
2440 if Pragma_Name_Unmapped
(Decl
) = Name_SPARK_Mode
then
2441 Insert_After
(To
, New_Copy_Tree
(Decl
));
2443 elsif Nam_In
(Pragma_Name_Unmapped
(Decl
),
2445 Name_Volatile_Function
)
2448 Insert_After
(To
, Decl
);
2459 Subp_Decl
: Node_Id
;
2461 -- Start of processing for Build_Subprogram_Declaration
2464 -- Create a matching subprogram spec using the profile of the body.
2465 -- The structure of the tree is identical, but has new entities for
2466 -- the defining unit name and formal parameters.
2469 Make_Subprogram_Declaration
(Loc
,
2470 Specification
=> Copy_Subprogram_Spec
(Body_Spec
));
2471 Set_Comes_From_Source
(Subp_Decl
, True);
2473 -- Relocate the aspects and relevant pragmas from the subprogram body
2474 -- to the generated spec because it acts as the initial declaration.
2476 Insert_Before
(N
, Subp_Decl
);
2477 Move_Aspects
(N
, To
=> Subp_Decl
);
2478 Move_Pragmas
(N
, To
=> Subp_Decl
);
2480 -- Ensure that the generated corresponding spec and original body
2481 -- share the same SPARK_Mode pragma or aspect. As a result, both have
2482 -- the same SPARK_Mode attributes, and the global SPARK_Mode value is
2483 -- correctly set for local subprograms.
2485 Copy_SPARK_Mode_Aspect
(Subp_Decl
, To
=> N
);
2487 Analyze
(Subp_Decl
);
2489 -- Propagate the attributes Rewritten_For_C and Corresponding_Proc to
2490 -- the body since the expander may generate calls using that entity.
2491 -- Required to ensure that Expand_Call rewrites calls to this
2492 -- function by calls to the built procedure.
2494 if Modify_Tree_For_C
2495 and then Nkind
(Body_Spec
) = N_Function_Specification
2497 Rewritten_For_C
(Defining_Entity
(Specification
(Subp_Decl
)))
2499 Set_Rewritten_For_C
(Defining_Entity
(Body_Spec
));
2500 Set_Corresponding_Procedure
(Defining_Entity
(Body_Spec
),
2501 Corresponding_Procedure
2502 (Defining_Entity
(Specification
(Subp_Decl
))));
2505 -- Analyze any relocated source pragmas or pragmas created for aspect
2508 Decl
:= Next
(Subp_Decl
);
2509 while Present
(Decl
) loop
2511 -- Stop the search for pragmas once the body has been reached as
2512 -- this terminates the region where pragmas may appear.
2517 elsif Nkind
(Decl
) = N_Pragma
then
2524 Spec_Id
:= Defining_Entity
(Subp_Decl
);
2525 Set_Corresponding_Spec
(N
, Spec_Id
);
2527 -- Mark the generated spec as a source construct to ensure that all
2528 -- calls to it are properly registered in ALI files for GNATprove.
2530 Set_Comes_From_Source
(Spec_Id
, True);
2532 -- Ensure that the specs of the subprogram declaration and its body
2533 -- are identical, otherwise they will appear non-conformant due to
2534 -- rewritings in the default values of formal parameters.
2536 Body_Spec
:= Copy_Subprogram_Spec
(Body_Spec
);
2537 Set_Specification
(N
, Body_Spec
);
2538 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
2539 end Build_Subprogram_Declaration
;
2541 ----------------------------
2542 -- Check_Anonymous_Return --
2543 ----------------------------
2545 procedure Check_Anonymous_Return
is
2551 if Present
(Spec_Id
) then
2557 if Ekind
(Scop
) = E_Function
2558 and then Ekind
(Etype
(Scop
)) = E_Anonymous_Access_Type
2559 and then not Is_Thunk
(Scop
)
2561 -- Skip internally built functions which handle the case of
2562 -- a null access (see Expand_Interface_Conversion)
2564 and then not (Is_Interface
(Designated_Type
(Etype
(Scop
)))
2565 and then not Comes_From_Source
(Parent
(Scop
)))
2567 and then (Has_Task
(Designated_Type
(Etype
(Scop
)))
2569 (Is_Class_Wide_Type
(Designated_Type
(Etype
(Scop
)))
2571 Is_Limited_Record
(Designated_Type
(Etype
(Scop
)))))
2572 and then Expander_Active
2574 -- Avoid cases with no tasking support
2576 and then RTE_Available
(RE_Current_Master
)
2577 and then not Restriction_Active
(No_Task_Hierarchy
)
2580 Make_Object_Declaration
(Loc
,
2581 Defining_Identifier
=>
2582 Make_Defining_Identifier
(Loc
, Name_uMaster
),
2583 Constant_Present
=> True,
2584 Object_Definition
=>
2585 New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
2587 Make_Explicit_Dereference
(Loc
,
2588 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
2590 if Present
(Declarations
(N
)) then
2591 Prepend
(Decl
, Declarations
(N
));
2593 Set_Declarations
(N
, New_List
(Decl
));
2596 Set_Master_Id
(Etype
(Scop
), Defining_Identifier
(Decl
));
2597 Set_Has_Master_Entity
(Scop
);
2599 -- Now mark the containing scope as a task master
2602 while Nkind
(Par
) /= N_Compilation_Unit
loop
2603 Par
:= Parent
(Par
);
2604 pragma Assert
(Present
(Par
));
2606 -- If we fall off the top, we are at the outer level, and
2607 -- the environment task is our effective master, so nothing
2611 (Par
, N_Task_Body
, N_Block_Statement
, N_Subprogram_Body
)
2613 Set_Is_Task_Master
(Par
, True);
2618 end Check_Anonymous_Return
;
2620 -------------------------
2621 -- Check_Inline_Pragma --
2622 -------------------------
2624 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
) is
2628 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean;
2629 -- True when N is a pragma Inline or Inline_Always that applies
2630 -- to this subprogram.
2632 -----------------------
2633 -- Is_Inline_Pragma --
2634 -----------------------
2636 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean is
2638 if Nkind
(N
) = N_Pragma
2640 (Pragma_Name_Unmapped
(N
) = Name_Inline_Always
2641 or else (Pragma_Name_Unmapped
(N
) = Name_Inline
2643 (Front_End_Inlining
or else Optimization_Level
> 0)))
2644 and then Present
(Pragma_Argument_Associations
(N
))
2647 Pragma_Arg
: Node_Id
:=
2648 Expression
(First
(Pragma_Argument_Associations
(N
)));
2650 if Nkind
(Pragma_Arg
) = N_Selected_Component
then
2651 Pragma_Arg
:= Selector_Name
(Pragma_Arg
);
2654 return Chars
(Pragma_Arg
) = Chars
(Body_Id
);
2660 end Is_Inline_Pragma
;
2662 -- Start of processing for Check_Inline_Pragma
2665 if not Expander_Active
then
2669 if Is_List_Member
(N
)
2670 and then Present
(Next
(N
))
2671 and then Is_Inline_Pragma
(Next
(N
))
2675 elsif Nkind
(N
) /= N_Subprogram_Body_Stub
2676 and then Present
(Declarations
(N
))
2677 and then Is_Inline_Pragma
(First
(Declarations
(N
)))
2679 Prag
:= First
(Declarations
(N
));
2685 if Present
(Prag
) then
2686 if Present
(Spec_Id
) then
2687 if Is_List_Member
(N
)
2688 and then Is_List_Member
(Unit_Declaration_Node
(Spec_Id
))
2689 and then In_Same_List
(N
, Unit_Declaration_Node
(Spec_Id
))
2695 -- Create a subprogram declaration, to make treatment uniform.
2696 -- Make the sloc of the subprogram name that of the entity in
2697 -- the body, so that style checks find identical strings.
2700 Subp
: constant Entity_Id
:=
2701 Make_Defining_Identifier
2702 (Sloc
(Body_Id
), Chars
(Body_Id
));
2703 Decl
: constant Node_Id
:=
2704 Make_Subprogram_Declaration
(Loc
,
2706 New_Copy_Tree
(Specification
(N
)));
2709 Set_Defining_Unit_Name
(Specification
(Decl
), Subp
);
2711 -- To ensure proper coverage when body is inlined, indicate
2712 -- whether the subprogram comes from source.
2714 Set_Comes_From_Source
(Subp
, Comes_From_Source
(N
));
2716 if Present
(First_Formal
(Body_Id
)) then
2717 Plist
:= Copy_Parameter_List
(Body_Id
);
2718 Set_Parameter_Specifications
2719 (Specification
(Decl
), Plist
);
2722 -- Move aspects to the new spec
2724 if Has_Aspects
(N
) then
2725 Move_Aspects
(N
, To
=> Decl
);
2728 Insert_Before
(N
, Decl
);
2731 Set_Has_Pragma_Inline
(Subp
);
2733 if Pragma_Name
(Prag
) = Name_Inline_Always
then
2734 Set_Is_Inlined
(Subp
);
2735 Set_Has_Pragma_Inline_Always
(Subp
);
2738 -- Prior to copying the subprogram body to create a template
2739 -- for it for subsequent inlining, remove the pragma from
2740 -- the current body so that the copy that will produce the
2741 -- new body will start from a completely unanalyzed tree.
2743 if Nkind
(Parent
(Prag
)) = N_Subprogram_Body
then
2744 Rewrite
(Prag
, Make_Null_Statement
(Sloc
(Prag
)));
2751 end Check_Inline_Pragma
;
2753 --------------------------
2754 -- Check_Missing_Return --
2755 --------------------------
2757 procedure Check_Missing_Return
is
2759 Missing_Ret
: Boolean;
2762 if Nkind
(Body_Spec
) = N_Function_Specification
then
2763 if Present
(Spec_Id
) then
2769 if Return_Present
(Id
) then
2770 Check_Returns
(HSS
, 'F', Missing_Ret
);
2773 Set_Has_Missing_Return
(Id
);
2776 -- Within a premature instantiation of a package with no body, we
2777 -- build completions of the functions therein, with a Raise
2778 -- statement. No point in complaining about a missing return in
2781 elsif Ekind
(Id
) = E_Function
2782 and then In_Instance
2783 and then Present
(Statements
(HSS
))
2784 and then Nkind
(First
(Statements
(HSS
))) = N_Raise_Program_Error
2788 elsif Is_Generic_Subprogram
(Id
)
2789 or else not Is_Machine_Code_Subprogram
(Id
)
2791 Error_Msg_N
("missing RETURN statement in function body", N
);
2794 -- If procedure with No_Return, check returns
2796 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
2797 and then Present
(Spec_Id
)
2798 and then No_Return
(Spec_Id
)
2800 Check_Returns
(HSS
, 'P', Missing_Ret
, Spec_Id
);
2803 -- Special checks in SPARK mode
2805 if Nkind
(Body_Spec
) = N_Function_Specification
then
2807 -- In SPARK mode, last statement of a function should be a return
2810 Stat
: constant Node_Id
:= Last_Source_Statement
(HSS
);
2813 and then not Nkind_In
(Stat
, N_Simple_Return_Statement
,
2814 N_Extended_Return_Statement
)
2816 Check_SPARK_05_Restriction
2817 ("last statement in function should be RETURN", Stat
);
2821 -- In SPARK mode, verify that a procedure has no return
2823 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
then
2824 if Present
(Spec_Id
) then
2830 -- Would be nice to point to return statement here, can we
2831 -- borrow the Check_Returns procedure here ???
2833 if Return_Present
(Id
) then
2834 Check_SPARK_05_Restriction
2835 ("procedure should not have RETURN", N
);
2838 end Check_Missing_Return
;
2840 -----------------------
2841 -- Disambiguate_Spec --
2842 -----------------------
2844 function Disambiguate_Spec
return Entity_Id
is
2845 Priv_Spec
: Entity_Id
;
2848 procedure Replace_Types
(To_Corresponding
: Boolean);
2849 -- Depending on the flag, replace the type of formal parameters of
2850 -- Body_Id if it is a concurrent type implementing interfaces with
2851 -- the corresponding record type or the other way around.
2853 procedure Replace_Types
(To_Corresponding
: Boolean) is
2855 Formal_Typ
: Entity_Id
;
2858 Formal
:= First_Formal
(Body_Id
);
2859 while Present
(Formal
) loop
2860 Formal_Typ
:= Etype
(Formal
);
2862 if Is_Class_Wide_Type
(Formal_Typ
) then
2863 Formal_Typ
:= Root_Type
(Formal_Typ
);
2866 -- From concurrent type to corresponding record
2868 if To_Corresponding
then
2869 if Is_Concurrent_Type
(Formal_Typ
)
2870 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
2873 (Corresponding_Record_Type
(Formal_Typ
)))
2876 Corresponding_Record_Type
(Formal_Typ
));
2879 -- From corresponding record to concurrent type
2882 if Is_Concurrent_Record_Type
(Formal_Typ
)
2883 and then Present
(Interfaces
(Formal_Typ
))
2886 Corresponding_Concurrent_Type
(Formal_Typ
));
2890 Next_Formal
(Formal
);
2894 -- Start of processing for Disambiguate_Spec
2897 -- Try to retrieve the specification of the body as is. All error
2898 -- messages are suppressed because the body may not have a spec in
2899 -- its current state.
2901 Spec_N
:= Find_Corresponding_Spec
(N
, False);
2903 -- It is possible that this is the body of a primitive declared
2904 -- between a private and a full view of a concurrent type. The
2905 -- controlling parameter of the spec carries the concurrent type,
2906 -- not the corresponding record type as transformed by Analyze_
2907 -- Subprogram_Specification. In such cases, we undo the change
2908 -- made by the analysis of the specification and try to find the
2911 -- Note that wrappers already have their corresponding specs and
2912 -- bodies set during their creation, so if the candidate spec is
2913 -- a wrapper, then we definitely need to swap all types to their
2914 -- original concurrent status.
2917 or else Is_Primitive_Wrapper
(Spec_N
)
2919 -- Restore all references of corresponding record types to the
2920 -- original concurrent types.
2922 Replace_Types
(To_Corresponding
=> False);
2923 Priv_Spec
:= Find_Corresponding_Spec
(N
, False);
2925 -- The current body truly belongs to a primitive declared between
2926 -- a private and a full view. We leave the modified body as is,
2927 -- and return the true spec.
2929 if Present
(Priv_Spec
)
2930 and then Is_Private_Primitive
(Priv_Spec
)
2935 -- In case that this is some sort of error, restore the original
2936 -- state of the body.
2938 Replace_Types
(To_Corresponding
=> True);
2942 end Disambiguate_Spec
;
2944 ----------------------------
2945 -- Exchange_Limited_Views --
2946 ----------------------------
2948 function Exchange_Limited_Views
(Subp_Id
: Entity_Id
) return Elist_Id
is
2949 Result
: Elist_Id
:= No_Elist
;
2951 procedure Detect_And_Exchange
(Id
: Entity_Id
);
2952 -- Determine whether Id's type denotes an incomplete type associated
2953 -- with a limited with clause and exchange the limited view with the
2954 -- non-limited one when available. Note that the non-limited view
2955 -- may exist because of a with_clause in another unit in the context,
2956 -- but cannot be used because the current view of the enclosing unit
2957 -- is still a limited view.
2959 -------------------------
2960 -- Detect_And_Exchange --
2961 -------------------------
2963 procedure Detect_And_Exchange
(Id
: Entity_Id
) is
2964 Typ
: constant Entity_Id
:= Etype
(Id
);
2966 if From_Limited_With
(Typ
)
2967 and then Has_Non_Limited_View
(Typ
)
2968 and then not From_Limited_With
(Scope
(Typ
))
2971 Result
:= New_Elmt_List
;
2974 Prepend_Elmt
(Typ
, Result
);
2975 Prepend_Elmt
(Id
, Result
);
2976 Set_Etype
(Id
, Non_Limited_View
(Typ
));
2978 end Detect_And_Exchange
;
2984 -- Start of processing for Exchange_Limited_Views
2987 -- Do not process subprogram bodies as they already use the non-
2988 -- limited view of types.
2990 if not Ekind_In
(Subp_Id
, E_Function
, E_Procedure
) then
2994 -- Examine all formals and swap views when applicable
2996 Formal
:= First_Formal
(Subp_Id
);
2997 while Present
(Formal
) loop
2998 Detect_And_Exchange
(Formal
);
3000 Next_Formal
(Formal
);
3003 -- Process the return type of a function
3005 if Ekind
(Subp_Id
) = E_Function
then
3006 Detect_And_Exchange
(Subp_Id
);
3010 end Exchange_Limited_Views
;
3012 -----------------------
3013 -- Freeze_Expr_Types --
3014 -----------------------
3016 procedure Freeze_Expr_Types
(Spec_Id
: Entity_Id
) is
3017 function Cloned_Expression
return Node_Id
;
3018 -- Build a duplicate of the expression of the return statement that
3019 -- has no defining entities shared with the original expression.
3021 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
;
3022 -- Freeze all types referenced in the subtree rooted at Node
3024 -----------------------
3025 -- Cloned_Expression --
3026 -----------------------
3028 function Cloned_Expression
return Node_Id
is
3029 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
;
3030 -- Tree traversal routine that clones the defining identifier of
3031 -- iterator and loop parameter specification nodes.
3037 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
is
3039 if Nkind_In
(Node
, N_Iterator_Specification
,
3040 N_Loop_Parameter_Specification
)
3042 Set_Defining_Identifier
(Node
,
3043 New_Copy
(Defining_Identifier
(Node
)));
3053 procedure Clone_Def_Ids
is new Traverse_Proc
(Clone_Id
);
3057 Return_Stmt
: constant Node_Id
:=
3059 (Statements
(Handled_Statement_Sequence
(N
)));
3062 -- Start of processing for Cloned_Expression
3065 pragma Assert
(Nkind
(Return_Stmt
) = N_Simple_Return_Statement
);
3067 -- We must duplicate the expression with semantic information to
3068 -- inherit the decoration of global entities in generic instances.
3070 Dup_Expr
:= New_Copy_Tree
(Expression
(Return_Stmt
));
3072 -- Replace the defining identifier of iterators and loop param
3073 -- specifications by a clone to ensure that the cloned expression
3074 -- and the original expression don't have shared identifiers;
3075 -- otherwise, as part of the preanalysis of the expression, these
3076 -- shared identifiers may be left decorated with itypes which
3077 -- will not be available in the tree passed to the backend.
3079 Clone_Def_Ids
(Dup_Expr
);
3082 end Cloned_Expression
;
3084 ----------------------
3085 -- Freeze_Type_Refs --
3086 ----------------------
3088 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
is
3090 if Nkind
(Node
) = N_Identifier
3091 and then Present
(Entity
(Node
))
3093 if Is_Type
(Entity
(Node
)) then
3094 Freeze_Before
(N
, Entity
(Node
));
3096 elsif Ekind_In
(Entity
(Node
), E_Component
,
3099 Freeze_Before
(N
, Scope
(Entity
(Node
)));
3104 end Freeze_Type_Refs
;
3106 procedure Freeze_References
is new Traverse_Proc
(Freeze_Type_Refs
);
3110 Saved_First_Entity
: constant Entity_Id
:= First_Entity
(Spec_Id
);
3111 Saved_Last_Entity
: constant Entity_Id
:= Last_Entity
(Spec_Id
);
3112 Dup_Expr
: constant Node_Id
:= Cloned_Expression
;
3114 -- Start of processing for Freeze_Expr_Types
3117 -- Preanalyze a duplicate of the expression to have available the
3118 -- minimum decoration needed to locate referenced unfrozen types
3119 -- without adding any decoration to the function expression. This
3120 -- preanalysis is performed with errors disabled to avoid reporting
3121 -- spurious errors on Ghost entities (since the expression is not
3124 Push_Scope
(Spec_Id
);
3125 Install_Formals
(Spec_Id
);
3126 Ignore_Errors_Enable
:= Ignore_Errors_Enable
+ 1;
3128 Preanalyze_Spec_Expression
(Dup_Expr
, Etype
(Spec_Id
));
3130 Ignore_Errors_Enable
:= Ignore_Errors_Enable
- 1;
3133 -- Restore certain attributes of Spec_Id since the preanalysis may
3134 -- have introduced itypes to this scope, thus modifying attributes
3135 -- First_Entity and Last_Entity.
3137 Set_First_Entity
(Spec_Id
, Saved_First_Entity
);
3138 Set_Last_Entity
(Spec_Id
, Saved_Last_Entity
);
3140 if Present
(Last_Entity
(Spec_Id
)) then
3141 Set_Next_Entity
(Last_Entity
(Spec_Id
), Empty
);
3144 -- Freeze all types referenced in the expression
3146 Freeze_References
(Dup_Expr
);
3147 end Freeze_Expr_Types
;
3149 -------------------------------------
3150 -- Is_Private_Concurrent_Primitive --
3151 -------------------------------------
3153 function Is_Private_Concurrent_Primitive
3154 (Subp_Id
: Entity_Id
) return Boolean
3156 Formal_Typ
: Entity_Id
;
3159 if Present
(First_Formal
(Subp_Id
)) then
3160 Formal_Typ
:= Etype
(First_Formal
(Subp_Id
));
3162 if Is_Concurrent_Record_Type
(Formal_Typ
) then
3163 if Is_Class_Wide_Type
(Formal_Typ
) then
3164 Formal_Typ
:= Root_Type
(Formal_Typ
);
3167 Formal_Typ
:= Corresponding_Concurrent_Type
(Formal_Typ
);
3170 -- The type of the first formal is a concurrent tagged type with
3174 Is_Concurrent_Type
(Formal_Typ
)
3175 and then Is_Tagged_Type
(Formal_Typ
)
3176 and then Has_Private_Declaration
(Formal_Typ
);
3180 end Is_Private_Concurrent_Primitive
;
3182 ---------------------------
3183 -- Restore_Limited_Views --
3184 ---------------------------
3186 procedure Restore_Limited_Views
(Restore_List
: Elist_Id
) is
3187 Elmt
: Elmt_Id
:= First_Elmt
(Restore_List
);
3191 while Present
(Elmt
) loop
3194 Set_Etype
(Id
, Node
(Elmt
));
3197 end Restore_Limited_Views
;
3199 ----------------------------
3200 -- Set_Trivial_Subprogram --
3201 ----------------------------
3203 procedure Set_Trivial_Subprogram
(N
: Node_Id
) is
3204 Nxt
: constant Node_Id
:= Next
(N
);
3207 Set_Is_Trivial_Subprogram
(Body_Id
);
3209 if Present
(Spec_Id
) then
3210 Set_Is_Trivial_Subprogram
(Spec_Id
);
3214 and then Nkind
(Nxt
) = N_Simple_Return_Statement
3215 and then No
(Next
(Nxt
))
3216 and then Present
(Expression
(Nxt
))
3217 and then Is_Entity_Name
(Expression
(Nxt
))
3219 Set_Never_Set_In_Source
(Entity
(Expression
(Nxt
)), False);
3221 end Set_Trivial_Subprogram
;
3223 ---------------------------------
3224 -- Verify_Overriding_Indicator --
3225 ---------------------------------
3227 procedure Verify_Overriding_Indicator
is
3229 if Must_Override
(Body_Spec
) then
3230 if Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
3231 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
3235 elsif not Present
(Overridden_Operation
(Spec_Id
)) then
3237 ("subprogram& is not overriding", Body_Spec
, Spec_Id
);
3239 -- Overriding indicators aren't allowed for protected subprogram
3240 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
3241 -- this to a warning if -gnatd.E is enabled.
3243 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
3244 Error_Msg_Warn
:= Error_To_Warning
;
3246 ("<<overriding indicator not allowed for protected "
3247 & "subprogram body", Body_Spec
);
3250 elsif Must_Not_Override
(Body_Spec
) then
3251 if Present
(Overridden_Operation
(Spec_Id
)) then
3253 ("subprogram& overrides inherited operation",
3254 Body_Spec
, Spec_Id
);
3256 elsif Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
3257 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
3260 ("subprogram& overrides predefined operator ",
3261 Body_Spec
, Spec_Id
);
3263 -- Overriding indicators aren't allowed for protected subprogram
3264 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
3265 -- this to a warning if -gnatd.E is enabled.
3267 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
3268 Error_Msg_Warn
:= Error_To_Warning
;
3271 ("<<overriding indicator not allowed "
3272 & "for protected subprogram body", Body_Spec
);
3274 -- If this is not a primitive operation, then the overriding
3275 -- indicator is altogether illegal.
3277 elsif not Is_Primitive
(Spec_Id
) then
3279 ("overriding indicator only allowed "
3280 & "if subprogram is primitive", Body_Spec
);
3283 -- If checking the style rule and the operation overrides, then
3284 -- issue a warning about a missing overriding_indicator. Protected
3285 -- subprogram bodies are excluded from this style checking, since
3286 -- they aren't primitives (even though their declarations can
3287 -- override) and aren't allowed to have an overriding_indicator.
3290 and then Present
(Overridden_Operation
(Spec_Id
))
3291 and then Ekind
(Scope
(Spec_Id
)) /= E_Protected_Type
3293 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
3294 Style
.Missing_Overriding
(N
, Body_Id
);
3297 and then Can_Override_Operator
(Spec_Id
)
3298 and then not Is_Predefined_File_Name
3299 (Unit_File_Name
(Get_Source_Unit
(Spec_Id
)))
3301 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
3302 Style
.Missing_Overriding
(N
, Body_Id
);
3304 end Verify_Overriding_Indicator
;
3308 Mode
: Ghost_Mode_Type
;
3309 Mode_Set
: Boolean := False;
3311 -- Start of processing for Analyze_Subprogram_Body_Helper
3314 -- A [generic] subprogram body "freezes" the contract of the nearest
3315 -- enclosing package body and all other contracts encountered in the
3316 -- same declarative part up to and excluding the subprogram body:
3318 -- package body Nearest_Enclosing_Package
3319 -- with Refined_State => (State => Constit)
3323 -- procedure Freezes_Enclosing_Package_Body
3324 -- with Refined_Depends => (Input => Constit) ...
3326 -- This ensures that any annotations referenced by the contract of the
3327 -- [generic] subprogram body are available. This form of "freezing" is
3328 -- decoupled from the usual Freeze_xxx mechanism because it must also
3329 -- work in the context of generics where normal freezing is disabled.
3331 -- Only bodies coming from source should cause this type of "freezing".
3332 -- Expression functions that act as bodies and complete an initial
3333 -- declaration must be included in this category, hence the use of
3336 if Comes_From_Source
(Original_Node
(N
)) then
3337 Analyze_Previous_Contracts
(N
);
3340 -- Generic subprograms are handled separately. They always have a
3341 -- generic specification. Determine whether current scope has a
3342 -- previous declaration.
3344 -- If the subprogram body is defined within an instance of the same
3345 -- name, the instance appears as a package renaming, and will be hidden
3346 -- within the subprogram.
3348 if Present
(Prev_Id
)
3349 and then not Is_Overloadable
(Prev_Id
)
3350 and then (Nkind
(Parent
(Prev_Id
)) /= N_Package_Renaming_Declaration
3351 or else Comes_From_Source
(Prev_Id
))
3353 if Is_Generic_Subprogram
(Prev_Id
) then
3356 -- A subprogram body is Ghost when it is stand alone and subject
3357 -- to pragma Ghost or when the corresponding spec is Ghost. Set
3358 -- the mode now to ensure that any nodes generated during analysis
3359 -- and expansion are properly marked as Ghost.
3361 Mark_And_Set_Ghost_Body
(N
, Spec_Id
, Mode
);
3364 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3365 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3367 Analyze_Generic_Subprogram_Body
(N
, Spec_Id
);
3369 if Nkind
(N
) = N_Subprogram_Body
then
3370 HSS
:= Handled_Statement_Sequence
(N
);
3371 Check_Missing_Return
;
3376 -- Otherwise a previous entity conflicts with the subprogram name.
3377 -- Attempting to enter name will post error.
3380 Enter_Name
(Body_Id
);
3384 -- Non-generic case, find the subprogram declaration, if one was seen,
3385 -- or enter new overloaded entity in the current scope. If the
3386 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
3387 -- part of the context of one of its subunits. No need to redo the
3390 elsif Prev_Id
= Body_Id
and then Has_Completion
(Body_Id
) then
3394 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
3396 if Nkind
(N
) = N_Subprogram_Body_Stub
3397 or else No
(Corresponding_Spec
(N
))
3399 if Is_Private_Concurrent_Primitive
(Body_Id
) then
3400 Spec_Id
:= Disambiguate_Spec
;
3402 -- A subprogram body is Ghost when it is stand alone and
3403 -- subject to pragma Ghost or when the corresponding spec is
3404 -- Ghost. Set the mode now to ensure that any nodes generated
3405 -- during analysis and expansion are properly marked as Ghost.
3407 Mark_And_Set_Ghost_Body
(N
, Spec_Id
, Mode
);
3411 Spec_Id
:= Find_Corresponding_Spec
(N
);
3413 -- A subprogram body is Ghost when it is stand alone and
3414 -- subject to pragma Ghost or when the corresponding spec is
3415 -- Ghost. Set the mode now to ensure that any nodes generated
3416 -- during analysis and expansion are properly marked as Ghost.
3418 Mark_And_Set_Ghost_Body
(N
, Spec_Id
, Mode
);
3421 -- In GNATprove mode, if the body has no previous spec, create
3422 -- one so that the inlining machinery can operate properly.
3423 -- Transfer aspects, if any, to the new spec, so that they
3424 -- are legal and can be processed ahead of the body.
3425 -- We make two copies of the given spec, one for the new
3426 -- declaration, and one for the body.
3428 if No
(Spec_Id
) and then GNATprove_Mode
3430 -- Inlining does not apply during pre-analysis of code
3432 and then Full_Analysis
3434 -- Inlining only applies to full bodies, not stubs
3436 and then Nkind
(N
) /= N_Subprogram_Body_Stub
3438 -- Inlining only applies to bodies in the source code, not to
3439 -- those generated by the compiler. In particular, expression
3440 -- functions, whose body is generated by the compiler, are
3441 -- treated specially by GNATprove.
3443 and then Comes_From_Source
(Body_Id
)
3445 -- This cannot be done for a compilation unit, which is not
3446 -- in a context where we can insert a new spec.
3448 and then Is_List_Member
(N
)
3450 -- Inlining only applies to subprograms without contracts,
3451 -- as a contract is a sign that GNATprove should perform a
3452 -- modular analysis of the subprogram instead of a contextual
3453 -- analysis at each call site. The same test is performed in
3454 -- Inline.Can_Be_Inlined_In_GNATprove_Mode. It is repeated
3455 -- here in another form (because the contract has not been
3456 -- attached to the body) to avoid front-end errors in case
3457 -- pragmas are used instead of aspects, because the
3458 -- corresponding pragmas in the body would not be transferred
3459 -- to the spec, leading to legality errors.
3461 and then not Body_Has_Contract
3462 and then not Inside_A_Generic
3464 Build_Subprogram_Declaration
;
3466 -- If this is a function that returns a constrained array, and
3467 -- we are generating SPARK_For_C, create subprogram declaration
3468 -- to simplify subsequent C generation.
3471 and then Modify_Tree_For_C
3472 and then Nkind
(Body_Spec
) = N_Function_Specification
3473 and then Is_Array_Type
(Etype
(Body_Id
))
3474 and then Is_Constrained
(Etype
(Body_Id
))
3476 Build_Subprogram_Declaration
;
3480 -- If this is a duplicate body, no point in analyzing it
3482 if Error_Posted
(N
) then
3486 -- A subprogram body should cause freezing of its own declaration,
3487 -- but if there was no previous explicit declaration, then the
3488 -- subprogram will get frozen too late (there may be code within
3489 -- the body that depends on the subprogram having been frozen,
3490 -- such as uses of extra formals), so we force it to be frozen
3491 -- here. Same holds if the body and spec are compilation units.
3492 -- Finally, if the return type is an anonymous access to protected
3493 -- subprogram, it must be frozen before the body because its
3494 -- expansion has generated an equivalent type that is used when
3495 -- elaborating the body.
3497 -- An exception in the case of Ada 2012, AI05-177: The bodies
3498 -- created for expression functions do not freeze.
3501 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3503 Freeze_Before
(N
, Body_Id
);
3505 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3506 Freeze_Before
(N
, Spec_Id
);
3508 elsif Is_Access_Subprogram_Type
(Etype
(Body_Id
)) then
3509 Freeze_Before
(N
, Etype
(Body_Id
));
3513 Spec_Id
:= Corresponding_Spec
(N
);
3515 -- A subprogram body is Ghost when it is stand alone and subject
3516 -- to pragma Ghost or when the corresponding spec is Ghost. Set
3517 -- the mode now to ensure that any nodes generated during analysis
3518 -- and expansion are properly marked as Ghost.
3520 Mark_And_Set_Ghost_Body
(N
, Spec_Id
, Mode
);
3525 -- Previously we scanned the body to look for nested subprograms, and
3526 -- rejected an inline directive if nested subprograms were present,
3527 -- because the back-end would generate conflicting symbols for the
3528 -- nested bodies. This is now unnecessary.
3530 -- Look ahead to recognize a pragma Inline that appears after the body
3532 Check_Inline_Pragma
(Spec_Id
);
3534 -- Deal with special case of a fully private operation in the body of
3535 -- the protected type. We must create a declaration for the subprogram,
3536 -- in order to attach the protected subprogram that will be used in
3537 -- internal calls. We exclude compiler generated bodies from the
3538 -- expander since the issue does not arise for those cases.
3541 and then Comes_From_Source
(N
)
3542 and then Is_Protected_Type
(Current_Scope
)
3544 Spec_Id
:= Build_Private_Protected_Declaration
(N
);
3547 -- If we are generating C and this is a function returning a constrained
3548 -- array type for which we must create a procedure with an extra out
3549 -- parameter, build and analyze the body now. The procedure declaration
3550 -- has already been created. We reuse the source body of the function,
3551 -- because in an instance it may contain global references that cannot
3552 -- be reanalyzed. The source function itself is not used any further,
3553 -- so we mark it as having a completion. If the subprogram is a stub the
3554 -- transformation is done later, when the proper body is analyzed.
3557 and then Modify_Tree_For_C
3558 and then Present
(Spec_Id
)
3559 and then Ekind
(Spec_Id
) = E_Function
3560 and then Nkind
(N
) /= N_Subprogram_Body_Stub
3561 and then Rewritten_For_C
(Spec_Id
)
3563 Set_Has_Completion
(Spec_Id
);
3565 Rewrite
(N
, Build_Procedure_Body_Form
(Spec_Id
, N
));
3568 -- The entity for the created procedure must remain invisible, so it
3569 -- does not participate in resolution of subsequent references to the
3572 Set_Is_Immediately_Visible
(Corresponding_Spec
(N
), False);
3576 -- If a separate spec is present, then deal with freezing issues
3578 if Present
(Spec_Id
) then
3579 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
3580 Verify_Overriding_Indicator
;
3582 -- In general, the spec will be frozen when we start analyzing the
3583 -- body. However, for internally generated operations, such as
3584 -- wrapper functions for inherited operations with controlling
3585 -- results, the spec may not have been frozen by the time we expand
3586 -- the freeze actions that include the bodies. In particular, extra
3587 -- formals for accessibility or for return-in-place may need to be
3588 -- generated. Freeze nodes, if any, are inserted before the current
3589 -- body. These freeze actions are also needed in ASIS mode and in
3590 -- Compile_Only mode to enable the proper back-end type annotations.
3591 -- They are necessary in any case to insure order of elaboration
3594 if not Is_Frozen
(Spec_Id
)
3595 and then (Expander_Active
3597 or else (Operating_Mode
= Check_Semantics
3598 and then Serious_Errors_Detected
= 0))
3600 Set_Has_Delayed_Freeze
(Spec_Id
);
3601 Freeze_Before
(N
, Spec_Id
);
3603 -- AI12-0103: At the occurrence of an expression function
3604 -- declaration that is a completion, its expression causes
3607 if Has_Completion
(Spec_Id
)
3608 and then Nkind
(N
) = N_Subprogram_Body
3609 and then Was_Expression_Function
(N
)
3611 Freeze_Expr_Types
(Spec_Id
);
3616 -- Place subprogram on scope stack, and make formals visible. If there
3617 -- is a spec, the visible entity remains that of the spec.
3619 if Present
(Spec_Id
) then
3620 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
3622 if Is_Child_Unit
(Spec_Id
) then
3623 Generate_Reference
(Spec_Id
, Scope
(Spec_Id
), 'k', False);
3627 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
3630 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3631 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3633 if Is_Abstract_Subprogram
(Spec_Id
) then
3634 Error_Msg_N
("an abstract subprogram cannot have a body", N
);
3638 Set_Convention
(Body_Id
, Convention
(Spec_Id
));
3639 Set_Has_Completion
(Spec_Id
);
3641 if Is_Protected_Type
(Scope
(Spec_Id
)) then
3642 Prot_Typ
:= Scope
(Spec_Id
);
3645 -- If this is a body generated for a renaming, do not check for
3646 -- full conformance. The check is redundant, because the spec of
3647 -- the body is a copy of the spec in the renaming declaration,
3648 -- and the test can lead to spurious errors on nested defaults.
3650 if Present
(Spec_Decl
)
3651 and then not Comes_From_Source
(N
)
3653 (Nkind
(Original_Node
(Spec_Decl
)) =
3654 N_Subprogram_Renaming_Declaration
3655 or else (Present
(Corresponding_Body
(Spec_Decl
))
3657 Nkind
(Unit_Declaration_Node
3658 (Corresponding_Body
(Spec_Decl
))) =
3659 N_Subprogram_Renaming_Declaration
))
3663 -- Conversely, the spec may have been generated for specless body
3664 -- with an inline pragma. The entity comes from source, which is
3665 -- both semantically correct and necessary for proper inlining.
3666 -- The subprogram declaration itself is not in the source.
3668 elsif Comes_From_Source
(N
)
3669 and then Present
(Spec_Decl
)
3670 and then not Comes_From_Source
(Spec_Decl
)
3671 and then Has_Pragma_Inline
(Spec_Id
)
3678 Fully_Conformant
, True, Conformant
, Body_Id
);
3681 -- If the body is not fully conformant, we have to decide if we
3682 -- should analyze it or not. If it has a really messed up profile
3683 -- then we probably should not analyze it, since we will get too
3684 -- many bogus messages.
3686 -- Our decision is to go ahead in the non-fully conformant case
3687 -- only if it is at least mode conformant with the spec. Note
3688 -- that the call to Check_Fully_Conformant has issued the proper
3689 -- error messages to complain about the lack of conformance.
3692 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
3698 if Spec_Id
/= Body_Id
then
3699 Reference_Body_Formals
(Spec_Id
, Body_Id
);
3702 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
3704 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3705 Set_Corresponding_Spec_Of_Stub
(N
, Spec_Id
);
3710 Set_Corresponding_Spec
(N
, Spec_Id
);
3712 -- Ada 2005 (AI-345): If the operation is a primitive operation
3713 -- of a concurrent type, the type of the first parameter has been
3714 -- replaced with the corresponding record, which is the proper
3715 -- run-time structure to use. However, within the body there may
3716 -- be uses of the formals that depend on primitive operations
3717 -- of the type (in particular calls in prefixed form) for which
3718 -- we need the original concurrent type. The operation may have
3719 -- several controlling formals, so the replacement must be done
3722 if Comes_From_Source
(Spec_Id
)
3723 and then Present
(First_Entity
(Spec_Id
))
3724 and then Ekind
(Etype
(First_Entity
(Spec_Id
))) = E_Record_Type
3725 and then Is_Tagged_Type
(Etype
(First_Entity
(Spec_Id
)))
3726 and then Present
(Interfaces
(Etype
(First_Entity
(Spec_Id
))))
3727 and then Present
(Corresponding_Concurrent_Type
3728 (Etype
(First_Entity
(Spec_Id
))))
3731 Typ
: constant Entity_Id
:= Etype
(First_Entity
(Spec_Id
));
3735 Form
:= First_Formal
(Spec_Id
);
3736 while Present
(Form
) loop
3737 if Etype
(Form
) = Typ
then
3738 Set_Etype
(Form
, Corresponding_Concurrent_Type
(Typ
));
3746 -- Make the formals visible, and place subprogram on scope stack.
3747 -- This is also the point at which we set Last_Real_Spec_Entity
3748 -- to mark the entities which will not be moved to the body.
3750 Install_Formals
(Spec_Id
);
3751 Last_Real_Spec_Entity
:= Last_Entity
(Spec_Id
);
3753 -- Within an instance, add local renaming declarations so that
3754 -- gdb can retrieve the values of actuals more easily. This is
3755 -- only relevant if generating code (and indeed we definitely
3756 -- do not want these definitions -gnatc mode, because that would
3759 if Is_Generic_Instance
(Spec_Id
)
3760 and then Is_Wrapper_Package
(Current_Scope
)
3761 and then Expander_Active
3763 Build_Subprogram_Instance_Renamings
(N
, Current_Scope
);
3766 Push_Scope
(Spec_Id
);
3768 -- Make sure that the subprogram is immediately visible. For
3769 -- child units that have no separate spec this is indispensable.
3770 -- Otherwise it is safe albeit redundant.
3772 Set_Is_Immediately_Visible
(Spec_Id
);
3775 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
3776 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Spec_Id
));
3777 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
3779 -- Case of subprogram body with no previous spec
3782 -- Check for style warning required
3786 -- Only apply check for source level subprograms for which checks
3787 -- have not been suppressed.
3789 and then Comes_From_Source
(Body_Id
)
3790 and then not Suppress_Style_Checks
(Body_Id
)
3792 -- No warnings within an instance
3794 and then not In_Instance
3796 -- No warnings for expression functions
3798 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3800 Style
.Body_With_No_Spec
(N
);
3803 New_Overloaded_Entity
(Body_Id
);
3805 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
3806 Set_Acts_As_Spec
(N
);
3807 Generate_Definition
(Body_Id
);
3809 (Body_Id
, Body_Id
, 'b', Set_Ref
=> False, Force
=> True);
3811 -- If the body is an entry wrapper created for an entry with
3812 -- preconditions, it must be compiled in the context of the
3813 -- enclosing synchronized object, because it may mention other
3814 -- operations of the type.
3816 if Is_Entry_Wrapper
(Body_Id
) then
3818 Prot
: constant Entity_Id
:= Etype
(First_Entity
(Body_Id
));
3821 Install_Declarations
(Prot
);
3825 Install_Formals
(Body_Id
);
3827 Push_Scope
(Body_Id
);
3830 -- For stubs and bodies with no previous spec, generate references to
3833 Generate_Reference_To_Formals
(Body_Id
);
3836 -- Entry barrier functions are generated outside the protected type and
3837 -- should not carry the SPARK_Mode of the enclosing context.
3839 if Nkind
(N
) = N_Subprogram_Body
3840 and then Is_Entry_Barrier_Function
(N
)
3844 -- The body is generated as part of expression function expansion. When
3845 -- the expression function appears in the visible declarations of a
3846 -- package, the body is added to the private declarations. Since both
3847 -- declarative lists may be subject to a different SPARK_Mode, inherit
3848 -- the mode of the spec.
3850 -- package P with SPARK_Mode is
3851 -- function Expr_Func ... is (...); -- original
3852 -- [function Expr_Func ...;] -- generated spec
3855 -- pragma SPARK_Mode (Off);
3856 -- [function Expr_Func ... is return ...;] -- generated body
3857 -- end P; -- mode is ON
3859 elsif not Comes_From_Source
(N
)
3860 and then Present
(Spec_Id
)
3861 and then Is_Expression_Function
(Spec_Id
)
3863 Set_SPARK_Pragma
(Body_Id
, SPARK_Pragma
(Spec_Id
));
3864 Set_SPARK_Pragma_Inherited
3865 (Body_Id
, SPARK_Pragma_Inherited
(Spec_Id
));
3867 -- Set the SPARK_Mode from the current context (may be overwritten later
3868 -- with explicit pragma). Exclude the case where the SPARK_Mode appears
3869 -- initially on a stand-alone subprogram body, but is then relocated to
3870 -- a generated corresponding spec. In this scenario the mode is shared
3871 -- between the spec and body.
3873 elsif No
(SPARK_Pragma
(Body_Id
)) then
3874 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
3875 Set_SPARK_Pragma_Inherited
(Body_Id
);
3878 -- If this is the proper body of a stub, we must verify that the stub
3879 -- conforms to the body, and to the previous spec if one was present.
3880 -- We know already that the body conforms to that spec. This test is
3881 -- only required for subprograms that come from source.
3883 if Nkind
(Parent
(N
)) = N_Subunit
3884 and then Comes_From_Source
(N
)
3885 and then not Error_Posted
(Body_Id
)
3886 and then Nkind
(Corresponding_Stub
(Parent
(N
))) =
3887 N_Subprogram_Body_Stub
3890 Old_Id
: constant Entity_Id
:=
3892 (Specification
(Corresponding_Stub
(Parent
(N
))));
3894 Conformant
: Boolean := False;
3897 if No
(Spec_Id
) then
3898 Check_Fully_Conformant
(Body_Id
, Old_Id
);
3902 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
3904 if not Conformant
then
3906 -- The stub was taken to be a new declaration. Indicate that
3909 Set_Has_Completion
(Old_Id
, False);
3915 Set_Has_Completion
(Body_Id
);
3916 Check_Eliminated
(Body_Id
);
3918 -- Analyze any aspect specifications that appear on the subprogram body
3919 -- stub. Stop the analysis now as the stub does not have a declarative
3920 -- or a statement part, and it cannot be inlined.
3922 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3923 if Has_Aspects
(N
) then
3924 Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
);
3932 -- Note: Normally we don't do any inlining if expansion is off, since
3933 -- we won't generate code in any case. An exception arises in GNATprove
3934 -- mode where we want to expand some calls in place, even with expansion
3935 -- disabled, since the inlining eases formal verification.
3937 if not GNATprove_Mode
3938 and then Expander_Active
3939 and then Serious_Errors_Detected
= 0
3940 and then Present
(Spec_Id
)
3941 and then Has_Pragma_Inline
(Spec_Id
)
3943 -- Legacy implementation (relying on front-end inlining)
3945 if not Back_End_Inlining
then
3946 if (Has_Pragma_Inline_Always
(Spec_Id
)
3947 and then not Opt
.Disable_FE_Inline_Always
)
3948 or else (Front_End_Inlining
3949 and then not Opt
.Disable_FE_Inline
)
3951 Build_Body_To_Inline
(N
, Spec_Id
);
3954 -- New implementation (relying on back-end inlining)
3957 if Has_Pragma_Inline_Always
(Spec_Id
)
3958 or else Optimization_Level
> 0
3960 -- Handle function returning an unconstrained type
3962 if Comes_From_Source
(Body_Id
)
3963 and then Ekind
(Spec_Id
) = E_Function
3964 and then Returns_Unconstrained_Type
(Spec_Id
)
3966 -- If function builds in place, i.e. returns a limited type,
3967 -- inlining cannot be done.
3969 and then not Is_Limited_Type
(Etype
(Spec_Id
))
3971 Check_And_Split_Unconstrained_Function
(N
, Spec_Id
, Body_Id
);
3975 Subp_Body
: constant Node_Id
:=
3976 Unit_Declaration_Node
(Body_Id
);
3977 Subp_Decl
: constant List_Id
:= Declarations
(Subp_Body
);
3980 -- Do not pass inlining to the backend if the subprogram
3981 -- has declarations or statements which cannot be inlined
3982 -- by the backend. This check is done here to emit an
3983 -- error instead of the generic warning message reported
3984 -- by the GCC backend (ie. "function might not be
3987 if Present
(Subp_Decl
)
3988 and then Has_Excluded_Declaration
(Spec_Id
, Subp_Decl
)
3992 elsif Has_Excluded_Statement
3995 (Handled_Statement_Sequence
(Subp_Body
)))
3999 -- If the backend inlining is available then at this
4000 -- stage we only have to mark the subprogram as inlined.
4001 -- The expander will take care of registering it in the
4002 -- table of subprograms inlined by the backend a part of
4003 -- processing calls to it (cf. Expand_Call)
4006 Set_Is_Inlined
(Spec_Id
);
4013 -- In GNATprove mode, inline only when there is a separate subprogram
4014 -- declaration for now, as inlining of subprogram bodies acting as
4015 -- declarations, or subprogram stubs, are not supported by front-end
4016 -- inlining. This inlining should occur after analysis of the body, so
4017 -- that it is known whether the value of SPARK_Mode, which can be
4018 -- defined by a pragma inside the body, is applicable to the body.
4020 elsif GNATprove_Mode
4021 and then Full_Analysis
4022 and then not Inside_A_Generic
4023 and then Present
(Spec_Id
)
4025 Nkind
(Unit_Declaration_Node
(Spec_Id
)) = N_Subprogram_Declaration
4026 and then Body_Has_SPARK_Mode_On
4027 and then Can_Be_Inlined_In_GNATprove_Mode
(Spec_Id
, Body_Id
)
4028 and then not Body_Has_Contract
4030 Build_Body_To_Inline
(N
, Spec_Id
);
4033 -- When generating code, inherited pre/postconditions are handled when
4034 -- expanding the corresponding contract.
4036 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
4037 -- of the specification we have to install the private withed units.
4038 -- This holds for child units as well.
4040 if Is_Compilation_Unit
(Body_Id
)
4041 or else Nkind
(Parent
(N
)) = N_Compilation_Unit
4043 Install_Private_With_Clauses
(Body_Id
);
4046 Check_Anonymous_Return
;
4048 -- Set the Protected_Formal field of each extra formal of the protected
4049 -- subprogram to reference the corresponding extra formal of the
4050 -- subprogram that implements it. For regular formals this occurs when
4051 -- the protected subprogram's declaration is expanded, but the extra
4052 -- formals don't get created until the subprogram is frozen. We need to
4053 -- do this before analyzing the protected subprogram's body so that any
4054 -- references to the original subprogram's extra formals will be changed
4055 -- refer to the implementing subprogram's formals (see Expand_Formal).
4057 if Present
(Spec_Id
)
4058 and then Is_Protected_Type
(Scope
(Spec_Id
))
4059 and then Present
(Protected_Body_Subprogram
(Spec_Id
))
4062 Impl_Subp
: constant Entity_Id
:=
4063 Protected_Body_Subprogram
(Spec_Id
);
4064 Prot_Ext_Formal
: Entity_Id
:= Extra_Formals
(Spec_Id
);
4065 Impl_Ext_Formal
: Entity_Id
:= Extra_Formals
(Impl_Subp
);
4067 while Present
(Prot_Ext_Formal
) loop
4068 pragma Assert
(Present
(Impl_Ext_Formal
));
4069 Set_Protected_Formal
(Prot_Ext_Formal
, Impl_Ext_Formal
);
4070 Next_Formal_With_Extras
(Prot_Ext_Formal
);
4071 Next_Formal_With_Extras
(Impl_Ext_Formal
);
4076 -- Now we can go on to analyze the body
4078 HSS
:= Handled_Statement_Sequence
(N
);
4079 Set_Actual_Subtypes
(N
, Current_Scope
);
4081 -- Add a declaration for the Protection object, renaming declarations
4082 -- for discriminals and privals and finally a declaration for the entry
4083 -- family index (if applicable). This form of early expansion is done
4084 -- when the Expander is active because Install_Private_Data_Declarations
4085 -- references entities which were created during regular expansion. The
4086 -- subprogram entity must come from source, and not be an internally
4087 -- generated subprogram.
4090 and then Present
(Prot_Typ
)
4091 and then Present
(Spec_Id
)
4092 and then Comes_From_Source
(Spec_Id
)
4093 and then not Is_Eliminated
(Spec_Id
)
4095 Install_Private_Data_Declarations
4096 (Sloc
(N
), Spec_Id
, Prot_Typ
, N
, Declarations
(N
));
4099 -- Ada 2012 (AI05-0151): Incomplete types coming from a limited context
4100 -- may now appear in parameter and result profiles. Since the analysis
4101 -- of a subprogram body may use the parameter and result profile of the
4102 -- spec, swap any limited views with their non-limited counterpart.
4104 if Ada_Version
>= Ada_2012
and then Present
(Spec_Id
) then
4105 Exch_Views
:= Exchange_Limited_Views
(Spec_Id
);
4108 -- If the return type is an anonymous access type whose designated type
4109 -- is the limited view of a class-wide type and the non-limited view is
4110 -- available, update the return type accordingly.
4112 if Ada_Version
>= Ada_2005
and then Present
(Spec_Id
) then
4118 Rtyp
:= Etype
(Spec_Id
);
4120 if Ekind
(Rtyp
) = E_Anonymous_Access_Type
then
4121 Etyp
:= Directly_Designated_Type
(Rtyp
);
4123 if Is_Class_Wide_Type
(Etyp
)
4124 and then From_Limited_With
(Etyp
)
4127 Set_Directly_Designated_Type
(Rtyp
, Available_View
(Etyp
));
4133 -- Analyze any aspect specifications that appear on the subprogram body
4135 if Has_Aspects
(N
) then
4136 Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
);
4139 Analyze_Declarations
(Declarations
(N
));
4141 -- Verify that the SPARK_Mode of the body agrees with that of its spec
4143 if Present
(Spec_Id
) and then Present
(SPARK_Pragma
(Body_Id
)) then
4144 if Present
(SPARK_Pragma
(Spec_Id
)) then
4145 if Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Spec_Id
)) = Off
4147 Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Body_Id
)) = On
4149 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
4150 Error_Msg_N
("incorrect application of SPARK_Mode#", N
);
4151 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Spec_Id
));
4153 ("\value Off was set for SPARK_Mode on & #", N
, Spec_Id
);
4156 elsif Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Body_Stub
then
4160 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
4161 Error_Msg_N
("incorrect application of SPARK_Mode #", N
);
4162 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
4164 ("\no value was set for SPARK_Mode on & #", N
, Spec_Id
);
4168 -- A subprogram body "freezes" its own contract. Analyze the contract
4169 -- after the declarations of the body have been processed as pragmas
4170 -- are now chained on the contract of the subprogram body.
4172 Analyze_Entry_Or_Subprogram_Body_Contract
(Body_Id
);
4174 -- Check completion, and analyze the statements
4177 Inspect_Deferred_Constant_Completion
(Declarations
(N
));
4180 -- Deal with end of scope processing for the body
4182 Process_End_Label
(HSS
, 't', Current_Scope
);
4185 -- If we are compiling an entry wrapper, remove the enclosing
4186 -- synchronized object from the stack.
4188 if Is_Entry_Wrapper
(Body_Id
) then
4192 Check_Subprogram_Order
(N
);
4193 Set_Analyzed
(Body_Id
);
4195 -- If we have a separate spec, then the analysis of the declarations
4196 -- caused the entities in the body to be chained to the spec id, but
4197 -- we want them chained to the body id. Only the formal parameters
4198 -- end up chained to the spec id in this case.
4200 if Present
(Spec_Id
) then
4202 -- We must conform to the categorization of our spec
4204 Validate_Categorization_Dependency
(N
, Spec_Id
);
4206 -- And if this is a child unit, the parent units must conform
4208 if Is_Child_Unit
(Spec_Id
) then
4209 Validate_Categorization_Dependency
4210 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
4213 -- Here is where we move entities from the spec to the body
4215 -- Case where there are entities that stay with the spec
4217 if Present
(Last_Real_Spec_Entity
) then
4219 -- No body entities (happens when the only real spec entities come
4220 -- from precondition and postcondition pragmas).
4222 if No
(Last_Entity
(Body_Id
)) then
4223 Set_First_Entity
(Body_Id
, Next_Entity
(Last_Real_Spec_Entity
));
4225 -- Body entities present (formals), so chain stuff past them
4229 (Last_Entity
(Body_Id
), Next_Entity
(Last_Real_Spec_Entity
));
4232 Set_Next_Entity
(Last_Real_Spec_Entity
, Empty
);
4233 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
4234 Set_Last_Entity
(Spec_Id
, Last_Real_Spec_Entity
);
4236 -- Case where there are no spec entities, in this case there can be
4237 -- no body entities either, so just move everything.
4239 -- If the body is generated for an expression function, it may have
4240 -- been preanalyzed already, if 'access was applied to it.
4243 if Nkind
(Original_Node
(Unit_Declaration_Node
(Spec_Id
))) /=
4244 N_Expression_Function
4246 pragma Assert
(No
(Last_Entity
(Body_Id
)));
4250 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
4251 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
4252 Set_First_Entity
(Spec_Id
, Empty
);
4253 Set_Last_Entity
(Spec_Id
, Empty
);
4257 Check_Missing_Return
;
4259 -- Now we are going to check for variables that are never modified in
4260 -- the body of the procedure. But first we deal with a special case
4261 -- where we want to modify this check. If the body of the subprogram
4262 -- starts with a raise statement or its equivalent, or if the body
4263 -- consists entirely of a null statement, then it is pretty obvious that
4264 -- it is OK to not reference the parameters. For example, this might be
4265 -- the following common idiom for a stubbed function: statement of the
4266 -- procedure raises an exception. In particular this deals with the
4267 -- common idiom of a stubbed function, which appears something like:
4269 -- function F (A : Integer) return Some_Type;
4272 -- raise Program_Error;
4276 -- Here the purpose of X is simply to satisfy the annoying requirement
4277 -- in Ada that there be at least one return, and we certainly do not
4278 -- want to go posting warnings on X that it is not initialized. On
4279 -- the other hand, if X is entirely unreferenced that should still
4282 -- What we do is to detect these cases, and if we find them, flag the
4283 -- subprogram as being Is_Trivial_Subprogram and then use that flag to
4284 -- suppress unwanted warnings. For the case of the function stub above
4285 -- we have a special test to set X as apparently assigned to suppress
4292 -- Skip initial labels (for one thing this occurs when we are in
4293 -- front-end ZCX mode, but in any case it is irrelevant), and also
4294 -- initial Push_xxx_Error_Label nodes, which are also irrelevant.
4296 Stm
:= First
(Statements
(HSS
));
4297 while Nkind
(Stm
) = N_Label
4298 or else Nkind
(Stm
) in N_Push_xxx_Label
4303 -- Do the test on the original statement before expansion
4306 Ostm
: constant Node_Id
:= Original_Node
(Stm
);
4309 -- If explicit raise statement, turn on flag
4311 if Nkind
(Ostm
) = N_Raise_Statement
then
4312 Set_Trivial_Subprogram
(Stm
);
4314 -- If null statement, and no following statements, turn on flag
4316 elsif Nkind
(Stm
) = N_Null_Statement
4317 and then Comes_From_Source
(Stm
)
4318 and then No
(Next
(Stm
))
4320 Set_Trivial_Subprogram
(Stm
);
4322 -- Check for explicit call cases which likely raise an exception
4324 elsif Nkind
(Ostm
) = N_Procedure_Call_Statement
then
4325 if Is_Entity_Name
(Name
(Ostm
)) then
4327 Ent
: constant Entity_Id
:= Entity
(Name
(Ostm
));
4330 -- If the procedure is marked No_Return, then likely it
4331 -- raises an exception, but in any case it is not coming
4332 -- back here, so turn on the flag.
4335 and then Ekind
(Ent
) = E_Procedure
4336 and then No_Return
(Ent
)
4338 Set_Trivial_Subprogram
(Stm
);
4346 -- Check for variables that are never modified
4353 -- If there is a separate spec, then transfer Never_Set_In_Source
4354 -- flags from out parameters to the corresponding entities in the
4355 -- body. The reason we do that is we want to post error flags on
4356 -- the body entities, not the spec entities.
4358 if Present
(Spec_Id
) then
4359 E1
:= First_Entity
(Spec_Id
);
4360 while Present
(E1
) loop
4361 if Ekind
(E1
) = E_Out_Parameter
then
4362 E2
:= First_Entity
(Body_Id
);
4363 while Present
(E2
) loop
4364 exit when Chars
(E1
) = Chars
(E2
);
4368 if Present
(E2
) then
4369 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
4377 -- Check references in body
4379 Check_References
(Body_Id
);
4382 -- Check for nested subprogram, and mark outer level subprogram if so
4388 if Present
(Spec_Id
) then
4395 Ent
:= Enclosing_Subprogram
(Ent
);
4396 exit when No
(Ent
) or else Is_Subprogram
(Ent
);
4399 if Present
(Ent
) then
4400 Set_Has_Nested_Subprogram
(Ent
);
4404 -- Restore the limited views in the spec, if any, to let the back end
4405 -- process it without running into circularities.
4407 if Exch_Views
/= No_Elist
then
4408 Restore_Limited_Views
(Exch_Views
);
4411 if Present
(Desig_View
) then
4412 Set_Directly_Designated_Type
(Etype
(Spec_Id
), Desig_View
);
4417 Restore_Ghost_Mode
(Mode
);
4419 end Analyze_Subprogram_Body_Helper
;
4421 ------------------------------------
4422 -- Analyze_Subprogram_Declaration --
4423 ------------------------------------
4425 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
4426 Scop
: constant Entity_Id
:= Current_Scope
;
4427 Designator
: Entity_Id
;
4429 Is_Completion
: Boolean;
4430 -- Indicates whether a null procedure declaration is a completion
4433 -- Null procedures are not allowed in SPARK
4435 if Nkind
(Specification
(N
)) = N_Procedure_Specification
4436 and then Null_Present
(Specification
(N
))
4438 Check_SPARK_05_Restriction
("null procedure is not allowed", N
);
4440 -- Null procedures are allowed in protected types, following the
4441 -- recent AI12-0147.
4443 if Is_Protected_Type
(Current_Scope
)
4444 and then Ada_Version
< Ada_2012
4446 Error_Msg_N
("protected operation cannot be a null procedure", N
);
4449 Analyze_Null_Procedure
(N
, Is_Completion
);
4451 -- The null procedure acts as a body, nothing further is needed
4453 if Is_Completion
then
4458 Designator
:= Analyze_Subprogram_Specification
(Specification
(N
));
4460 -- A reference may already have been generated for the unit name, in
4461 -- which case the following call is redundant. However it is needed for
4462 -- declarations that are the rewriting of an expression function.
4464 Generate_Definition
(Designator
);
4466 -- Set the SPARK mode from the current context (may be overwritten later
4467 -- with explicit pragma). This is not done for entry barrier functions
4468 -- because they are generated outside the protected type and should not
4469 -- carry the mode of the enclosing context.
4471 if Nkind
(N
) = N_Subprogram_Declaration
4472 and then Is_Entry_Barrier_Function
(N
)
4476 Set_SPARK_Pragma
(Designator
, SPARK_Mode_Pragma
);
4477 Set_SPARK_Pragma_Inherited
(Designator
);
4480 if Debug_Flag_C
then
4481 Write_Str
("==> subprogram spec ");
4482 Write_Name
(Chars
(Designator
));
4483 Write_Str
(" from ");
4484 Write_Location
(Sloc
(N
));
4489 Validate_RCI_Subprogram_Declaration
(N
);
4490 New_Overloaded_Entity
(Designator
);
4491 Check_Delayed_Subprogram
(Designator
);
4493 -- If the type of the first formal of the current subprogram is a non-
4494 -- generic tagged private type, mark the subprogram as being a private
4495 -- primitive. Ditto if this is a function with controlling result, and
4496 -- the return type is currently private. In both cases, the type of the
4497 -- controlling argument or result must be in the current scope for the
4498 -- operation to be primitive.
4500 if Has_Controlling_Result
(Designator
)
4501 and then Is_Private_Type
(Etype
(Designator
))
4502 and then Scope
(Etype
(Designator
)) = Current_Scope
4503 and then not Is_Generic_Actual_Type
(Etype
(Designator
))
4505 Set_Is_Private_Primitive
(Designator
);
4507 elsif Present
(First_Formal
(Designator
)) then
4509 Formal_Typ
: constant Entity_Id
:=
4510 Etype
(First_Formal
(Designator
));
4512 Set_Is_Private_Primitive
(Designator
,
4513 Is_Tagged_Type
(Formal_Typ
)
4514 and then Scope
(Formal_Typ
) = Current_Scope
4515 and then Is_Private_Type
(Formal_Typ
)
4516 and then not Is_Generic_Actual_Type
(Formal_Typ
));
4520 -- Ada 2005 (AI-251): Abstract interface primitives must be abstract
4523 if Ada_Version
>= Ada_2005
4524 and then Comes_From_Source
(N
)
4525 and then Is_Dispatching_Operation
(Designator
)
4532 if Has_Controlling_Result
(Designator
) then
4533 Etyp
:= Etype
(Designator
);
4536 E
:= First_Entity
(Designator
);
4538 and then Is_Formal
(E
)
4539 and then not Is_Controlling_Formal
(E
)
4547 if Is_Access_Type
(Etyp
) then
4548 Etyp
:= Directly_Designated_Type
(Etyp
);
4551 if Is_Interface
(Etyp
)
4552 and then not Is_Abstract_Subprogram
(Designator
)
4553 and then not (Ekind
(Designator
) = E_Procedure
4554 and then Null_Present
(Specification
(N
)))
4556 Error_Msg_Name_1
:= Chars
(Defining_Entity
(N
));
4558 -- Specialize error message based on procedures vs. functions,
4559 -- since functions can't be null subprograms.
4561 if Ekind
(Designator
) = E_Procedure
then
4563 ("interface procedure % must be abstract or null", N
);
4566 ("interface function % must be abstract", N
);
4572 -- What is the following code for, it used to be
4574 -- ??? Set_Suppress_Elaboration_Checks
4575 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
4577 -- The following seems equivalent, but a bit dubious
4579 if Elaboration_Checks_Suppressed
(Designator
) then
4580 Set_Kill_Elaboration_Checks
(Designator
);
4583 if Scop
/= Standard_Standard
and then not Is_Child_Unit
(Designator
) then
4584 Set_Categorization_From_Scope
(Designator
, Scop
);
4587 -- For a compilation unit, check for library-unit pragmas
4589 Push_Scope
(Designator
);
4590 Set_Categorization_From_Pragmas
(N
);
4591 Validate_Categorization_Dependency
(N
, Designator
);
4595 -- For a compilation unit, set body required. This flag will only be
4596 -- reset if a valid Import or Interface pragma is processed later on.
4598 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
4599 Set_Body_Required
(Parent
(N
), True);
4601 if Ada_Version
>= Ada_2005
4602 and then Nkind
(Specification
(N
)) = N_Procedure_Specification
4603 and then Null_Present
(Specification
(N
))
4606 ("null procedure cannot be declared at library level", N
);
4610 Generate_Reference_To_Formals
(Designator
);
4611 Check_Eliminated
(Designator
);
4613 if Debug_Flag_C
then
4615 Write_Str
("<== subprogram spec ");
4616 Write_Name
(Chars
(Designator
));
4617 Write_Str
(" from ");
4618 Write_Location
(Sloc
(N
));
4622 if Is_Protected_Type
(Current_Scope
) then
4624 -- Indicate that this is a protected operation, because it may be
4625 -- used in subsequent declarations within the protected type.
4627 Set_Convention
(Designator
, Convention_Protected
);
4630 List_Inherited_Pre_Post_Aspects
(Designator
);
4632 if Has_Aspects
(N
) then
4633 Analyze_Aspect_Specifications
(N
, Designator
);
4635 end Analyze_Subprogram_Declaration
;
4637 --------------------------------------
4638 -- Analyze_Subprogram_Specification --
4639 --------------------------------------
4641 -- Reminder: N here really is a subprogram specification (not a subprogram
4642 -- declaration). This procedure is called to analyze the specification in
4643 -- both subprogram bodies and subprogram declarations (specs).
4645 function Analyze_Subprogram_Specification
(N
: Node_Id
) return Entity_Id
is
4646 function Is_Invariant_Procedure_Or_Body
(E
: Entity_Id
) return Boolean;
4647 -- Determine whether entity E denotes the spec or body of an invariant
4650 ------------------------------------
4651 -- Is_Invariant_Procedure_Or_Body --
4652 ------------------------------------
4654 function Is_Invariant_Procedure_Or_Body
(E
: Entity_Id
) return Boolean is
4655 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
4659 if Nkind
(Decl
) = N_Subprogram_Body
then
4660 Spec
:= Corresponding_Spec
(Decl
);
4667 and then Ekind
(Spec
) = E_Procedure
4668 and then (Is_Partial_Invariant_Procedure
(Spec
)
4669 or else Is_Invariant_Procedure
(Spec
));
4670 end Is_Invariant_Procedure_Or_Body
;
4674 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
4675 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
4677 -- Start of processing for Analyze_Subprogram_Specification
4680 -- User-defined operator is not allowed in SPARK, except as a renaming
4682 if Nkind
(Defining_Unit_Name
(N
)) = N_Defining_Operator_Symbol
4683 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
4685 Check_SPARK_05_Restriction
4686 ("user-defined operator is not allowed", N
);
4689 -- Proceed with analysis. Do not emit a cross-reference entry if the
4690 -- specification comes from an expression function, because it may be
4691 -- the completion of a previous declaration. It is not, the cross-
4692 -- reference entry will be emitted for the new subprogram declaration.
4694 if Nkind
(Parent
(N
)) /= N_Expression_Function
then
4695 Generate_Definition
(Designator
);
4698 if Nkind
(N
) = N_Function_Specification
then
4699 Set_Ekind
(Designator
, E_Function
);
4700 Set_Mechanism
(Designator
, Default_Mechanism
);
4702 Set_Ekind
(Designator
, E_Procedure
);
4703 Set_Etype
(Designator
, Standard_Void_Type
);
4706 -- Flag Is_Inlined_Always is True by default, and reversed to False for
4707 -- those subprograms which could be inlined in GNATprove mode (because
4708 -- Body_To_Inline is non-Empty) but should not be inlined.
4710 if GNATprove_Mode
then
4711 Set_Is_Inlined_Always
(Designator
);
4714 -- Introduce new scope for analysis of the formals and the return type
4716 Set_Scope
(Designator
, Current_Scope
);
4718 if Present
(Formals
) then
4719 Push_Scope
(Designator
);
4720 Process_Formals
(Formals
, N
);
4722 -- Check dimensions in N for formals with default expression
4724 Analyze_Dimension_Formals
(N
, Formals
);
4726 -- Ada 2005 (AI-345): If this is an overriding operation of an
4727 -- inherited interface operation, and the controlling type is
4728 -- a synchronized type, replace the type with its corresponding
4729 -- record, to match the proper signature of an overriding operation.
4730 -- Same processing for an access parameter whose designated type is
4731 -- derived from a synchronized interface.
4733 -- This modification is not done for invariant procedures because
4734 -- the corresponding record may not necessarely be visible when the
4735 -- concurrent type acts as the full view of a private type.
4738 -- type Prot is private with Type_Invariant => ...;
4739 -- procedure ConcInvariant (Obj : Prot);
4741 -- protected type Prot is ...;
4742 -- type Concurrent_Record_Prot is record ...;
4743 -- procedure ConcInvariant (Obj : Prot) is
4745 -- end ConcInvariant;
4748 -- In the example above, both the spec and body of the invariant
4749 -- procedure must utilize the private type as the controlling type.
4751 if Ada_Version
>= Ada_2005
4752 and then not Is_Invariant_Procedure_Or_Body
(Designator
)
4756 Formal_Typ
: Entity_Id
;
4757 Rec_Typ
: Entity_Id
;
4758 Desig_Typ
: Entity_Id
;
4761 Formal
:= First_Formal
(Designator
);
4762 while Present
(Formal
) loop
4763 Formal_Typ
:= Etype
(Formal
);
4765 if Is_Concurrent_Type
(Formal_Typ
)
4766 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
4768 Rec_Typ
:= Corresponding_Record_Type
(Formal_Typ
);
4770 if Present
(Interfaces
(Rec_Typ
)) then
4771 Set_Etype
(Formal
, Rec_Typ
);
4774 elsif Ekind
(Formal_Typ
) = E_Anonymous_Access_Type
then
4775 Desig_Typ
:= Designated_Type
(Formal_Typ
);
4777 if Is_Concurrent_Type
(Desig_Typ
)
4778 and then Present
(Corresponding_Record_Type
(Desig_Typ
))
4780 Rec_Typ
:= Corresponding_Record_Type
(Desig_Typ
);
4782 if Present
(Interfaces
(Rec_Typ
)) then
4783 Set_Directly_Designated_Type
(Formal_Typ
, Rec_Typ
);
4788 Next_Formal
(Formal
);
4795 -- The subprogram scope is pushed and popped around the processing of
4796 -- the return type for consistency with call above to Process_Formals
4797 -- (which itself can call Analyze_Return_Type), and to ensure that any
4798 -- itype created for the return type will be associated with the proper
4801 elsif Nkind
(N
) = N_Function_Specification
then
4802 Push_Scope
(Designator
);
4803 Analyze_Return_Type
(N
);
4809 if Nkind
(N
) = N_Function_Specification
then
4811 -- Deal with operator symbol case
4813 if Nkind
(Designator
) = N_Defining_Operator_Symbol
then
4814 Valid_Operator_Definition
(Designator
);
4817 May_Need_Actuals
(Designator
);
4819 -- Ada 2005 (AI-251): If the return type is abstract, verify that
4820 -- the subprogram is abstract also. This does not apply to renaming
4821 -- declarations, where abstractness is inherited, and to subprogram
4822 -- bodies generated for stream operations, which become renamings as
4825 -- In case of primitives associated with abstract interface types
4826 -- the check is applied later (see Analyze_Subprogram_Declaration).
4828 if not Nkind_In
(Original_Node
(Parent
(N
)),
4829 N_Abstract_Subprogram_Declaration
,
4830 N_Formal_Abstract_Subprogram_Declaration
,
4831 N_Subprogram_Renaming_Declaration
)
4833 if Is_Abstract_Type
(Etype
(Designator
))
4834 and then not Is_Interface
(Etype
(Designator
))
4837 ("function that returns abstract type must be abstract", N
);
4839 -- Ada 2012 (AI-0073): Extend this test to subprograms with an
4840 -- access result whose designated type is abstract.
4842 elsif Ada_Version
>= Ada_2012
4843 and then Nkind
(Result_Definition
(N
)) = N_Access_Definition
4845 not Is_Class_Wide_Type
(Designated_Type
(Etype
(Designator
)))
4846 and then Is_Abstract_Type
(Designated_Type
(Etype
(Designator
)))
4849 ("function whose access result designates abstract type "
4850 & "must be abstract", N
);
4856 end Analyze_Subprogram_Specification
;
4858 -----------------------
4859 -- Check_Conformance --
4860 -----------------------
4862 procedure Check_Conformance
4863 (New_Id
: Entity_Id
;
4865 Ctype
: Conformance_Type
;
4867 Conforms
: out Boolean;
4868 Err_Loc
: Node_Id
:= Empty
;
4869 Get_Inst
: Boolean := False;
4870 Skip_Controlling_Formals
: Boolean := False)
4872 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
4873 -- Sets Conforms to False. If Errmsg is False, then that's all it does.
4874 -- If Errmsg is True, then processing continues to post an error message
4875 -- for conformance error on given node. Two messages are output. The
4876 -- first message points to the previous declaration with a general "no
4877 -- conformance" message. The second is the detailed reason, supplied as
4878 -- Msg. The parameter N provide information for a possible & insertion
4879 -- in the message, and also provides the location for posting the
4880 -- message in the absence of a specified Err_Loc location.
4882 function Conventions_Match
4884 Id2
: Entity_Id
) return Boolean;
4885 -- Determine whether the conventions of arbitrary entities Id1 and Id2
4888 -----------------------
4889 -- Conformance_Error --
4890 -----------------------
4892 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
4899 if No
(Err_Loc
) then
4905 Error_Msg_Sloc
:= Sloc
(Old_Id
);
4908 when Type_Conformant
=>
4909 Error_Msg_N
-- CODEFIX
4910 ("not type conformant with declaration#!", Enode
);
4912 when Mode_Conformant
=>
4913 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4915 ("not mode conformant with operation inherited#!",
4919 ("not mode conformant with declaration#!", Enode
);
4922 when Subtype_Conformant
=>
4923 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4925 ("not subtype conformant with operation inherited#!",
4929 ("not subtype conformant with declaration#!", Enode
);
4932 when Fully_Conformant
=>
4933 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4934 Error_Msg_N
-- CODEFIX
4935 ("not fully conformant with operation inherited#!",
4938 Error_Msg_N
-- CODEFIX
4939 ("not fully conformant with declaration#!", Enode
);
4943 Error_Msg_NE
(Msg
, Enode
, N
);
4945 end Conformance_Error
;
4947 -----------------------
4948 -- Conventions_Match --
4949 -----------------------
4951 function Conventions_Match
4953 Id2
: Entity_Id
) return Boolean
4956 -- Ignore the conventions of anonymous access-to-subprogram types
4957 -- and subprogram types because these are internally generated and
4958 -- the only way these may receive a convention is if they inherit
4959 -- the convention of a related subprogram.
4961 if Ekind_In
(Id1
, E_Anonymous_Access_Subprogram_Type
,
4964 Ekind_In
(Id2
, E_Anonymous_Access_Subprogram_Type
,
4969 -- Otherwise compare the conventions directly
4972 return Convention
(Id1
) = Convention
(Id2
);
4974 end Conventions_Match
;
4978 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
4979 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
4980 Old_Formal
: Entity_Id
;
4981 New_Formal
: Entity_Id
;
4982 Access_Types_Match
: Boolean;
4983 Old_Formal_Base
: Entity_Id
;
4984 New_Formal_Base
: Entity_Id
;
4986 -- Start of processing for Check_Conformance
4991 -- We need a special case for operators, since they don't appear
4994 if Ctype
= Type_Conformant
then
4995 if Ekind
(New_Id
) = E_Operator
4996 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
5002 -- If both are functions/operators, check return types conform
5004 if Old_Type
/= Standard_Void_Type
5006 New_Type
/= Standard_Void_Type
5008 -- If we are checking interface conformance we omit controlling
5009 -- arguments and result, because we are only checking the conformance
5010 -- of the remaining parameters.
5012 if Has_Controlling_Result
(Old_Id
)
5013 and then Has_Controlling_Result
(New_Id
)
5014 and then Skip_Controlling_Formals
5018 elsif not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
5019 if Ctype
>= Subtype_Conformant
5020 and then not Predicates_Match
(Old_Type
, New_Type
)
5023 ("\predicate of return type does not match!", New_Id
);
5026 ("\return type does not match!", New_Id
);
5032 -- Ada 2005 (AI-231): In case of anonymous access types check the
5033 -- null-exclusion and access-to-constant attributes match.
5035 if Ada_Version
>= Ada_2005
5036 and then Ekind
(Etype
(Old_Type
)) = E_Anonymous_Access_Type
5038 (Can_Never_Be_Null
(Old_Type
) /= Can_Never_Be_Null
(New_Type
)
5039 or else Is_Access_Constant
(Etype
(Old_Type
)) /=
5040 Is_Access_Constant
(Etype
(New_Type
)))
5042 Conformance_Error
("\return type does not match!", New_Id
);
5046 -- If either is a function/operator and the other isn't, error
5048 elsif Old_Type
/= Standard_Void_Type
5049 or else New_Type
/= Standard_Void_Type
5051 Conformance_Error
("\functions can only match functions!", New_Id
);
5055 -- In subtype conformant case, conventions must match (RM 6.3.1(16)).
5056 -- If this is a renaming as body, refine error message to indicate that
5057 -- the conflict is with the original declaration. If the entity is not
5058 -- frozen, the conventions don't have to match, the one of the renamed
5059 -- entity is inherited.
5061 if Ctype
>= Subtype_Conformant
then
5062 if not Conventions_Match
(Old_Id
, New_Id
) then
5063 if not Is_Frozen
(New_Id
) then
5066 elsif Present
(Err_Loc
)
5067 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
5068 and then Present
(Corresponding_Spec
(Err_Loc
))
5070 Error_Msg_Name_1
:= Chars
(New_Id
);
5072 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
5073 Conformance_Error
("\prior declaration for% has convention %!");
5076 Conformance_Error
("\calling conventions do not match!");
5081 elsif Is_Formal_Subprogram
(Old_Id
)
5082 or else Is_Formal_Subprogram
(New_Id
)
5084 Conformance_Error
("\formal subprograms not allowed!");
5089 -- Deal with parameters
5091 -- Note: we use the entity information, rather than going directly
5092 -- to the specification in the tree. This is not only simpler, but
5093 -- absolutely necessary for some cases of conformance tests between
5094 -- operators, where the declaration tree simply does not exist.
5096 Old_Formal
:= First_Formal
(Old_Id
);
5097 New_Formal
:= First_Formal
(New_Id
);
5098 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
5099 if Is_Controlling_Formal
(Old_Formal
)
5100 and then Is_Controlling_Formal
(New_Formal
)
5101 and then Skip_Controlling_Formals
5103 -- The controlling formals will have different types when
5104 -- comparing an interface operation with its match, but both
5105 -- or neither must be access parameters.
5107 if Is_Access_Type
(Etype
(Old_Formal
))
5109 Is_Access_Type
(Etype
(New_Formal
))
5111 goto Skip_Controlling_Formal
;
5114 ("\access parameter does not match!", New_Formal
);
5118 -- Ada 2012: Mode conformance also requires that formal parameters
5119 -- be both aliased, or neither.
5121 if Ctype
>= Mode_Conformant
and then Ada_Version
>= Ada_2012
then
5122 if Is_Aliased
(Old_Formal
) /= Is_Aliased
(New_Formal
) then
5124 ("\aliased parameter mismatch!", New_Formal
);
5128 if Ctype
= Fully_Conformant
then
5130 -- Names must match. Error message is more accurate if we do
5131 -- this before checking that the types of the formals match.
5133 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
5134 Conformance_Error
("\name& does not match!", New_Formal
);
5136 -- Set error posted flag on new formal as well to stop
5137 -- junk cascaded messages in some cases.
5139 Set_Error_Posted
(New_Formal
);
5143 -- Null exclusion must match
5145 if Null_Exclusion_Present
(Parent
(Old_Formal
))
5147 Null_Exclusion_Present
(Parent
(New_Formal
))
5149 -- Only give error if both come from source. This should be
5150 -- investigated some time, since it should not be needed ???
5152 if Comes_From_Source
(Old_Formal
)
5154 Comes_From_Source
(New_Formal
)
5157 ("\null exclusion for& does not match", New_Formal
);
5159 -- Mark error posted on the new formal to avoid duplicated
5160 -- complaint about types not matching.
5162 Set_Error_Posted
(New_Formal
);
5167 -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This
5168 -- case occurs whenever a subprogram is being renamed and one of its
5169 -- parameters imposes a null exclusion. For example:
5171 -- type T is null record;
5172 -- type Acc_T is access T;
5173 -- subtype Acc_T_Sub is Acc_T;
5175 -- procedure P (Obj : not null Acc_T_Sub); -- itype
5176 -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype
5179 Old_Formal_Base
:= Etype
(Old_Formal
);
5180 New_Formal_Base
:= Etype
(New_Formal
);
5183 Old_Formal_Base
:= Get_Instance_Of
(Old_Formal_Base
);
5184 New_Formal_Base
:= Get_Instance_Of
(New_Formal_Base
);
5187 Access_Types_Match
:= Ada_Version
>= Ada_2005
5189 -- Ensure that this rule is only applied when New_Id is a
5190 -- renaming of Old_Id.
5192 and then Nkind
(Parent
(Parent
(New_Id
))) =
5193 N_Subprogram_Renaming_Declaration
5194 and then Nkind
(Name
(Parent
(Parent
(New_Id
)))) in N_Has_Entity
5195 and then Present
(Entity
(Name
(Parent
(Parent
(New_Id
)))))
5196 and then Entity
(Name
(Parent
(Parent
(New_Id
)))) = Old_Id
5198 -- Now handle the allowed access-type case
5200 and then Is_Access_Type
(Old_Formal_Base
)
5201 and then Is_Access_Type
(New_Formal_Base
)
5203 -- The type kinds must match. The only exception occurs with
5204 -- multiple generics of the form:
5207 -- type F is private; type A is private;
5208 -- type F_Ptr is access F; type A_Ptr is access A;
5209 -- with proc F_P (X : F_Ptr); with proc A_P (X : A_Ptr);
5210 -- package F_Pack is ... package A_Pack is
5211 -- package F_Inst is
5212 -- new F_Pack (A, A_Ptr, A_P);
5214 -- When checking for conformance between the parameters of A_P
5215 -- and F_P, the type kinds of F_Ptr and A_Ptr will not match
5216 -- because the compiler has transformed A_Ptr into a subtype of
5217 -- F_Ptr. We catch this case in the code below.
5219 and then (Ekind
(Old_Formal_Base
) = Ekind
(New_Formal_Base
)
5221 (Is_Generic_Type
(Old_Formal_Base
)
5222 and then Is_Generic_Type
(New_Formal_Base
)
5223 and then Is_Internal
(New_Formal_Base
)
5224 and then Etype
(Etype
(New_Formal_Base
)) =
5226 and then Directly_Designated_Type
(Old_Formal_Base
) =
5227 Directly_Designated_Type
(New_Formal_Base
)
5228 and then ((Is_Itype
(Old_Formal_Base
)
5229 and then Can_Never_Be_Null
(Old_Formal_Base
))
5231 (Is_Itype
(New_Formal_Base
)
5232 and then Can_Never_Be_Null
(New_Formal_Base
)));
5234 -- Types must always match. In the visible part of an instance,
5235 -- usual overloading rules for dispatching operations apply, and
5236 -- we check base types (not the actual subtypes).
5238 if In_Instance_Visible_Part
5239 and then Is_Dispatching_Operation
(New_Id
)
5241 if not Conforming_Types
5242 (T1
=> Base_Type
(Etype
(Old_Formal
)),
5243 T2
=> Base_Type
(Etype
(New_Formal
)),
5245 Get_Inst
=> Get_Inst
)
5246 and then not Access_Types_Match
5248 Conformance_Error
("\type of & does not match!", New_Formal
);
5252 elsif not Conforming_Types
5253 (T1
=> Old_Formal_Base
,
5254 T2
=> New_Formal_Base
,
5256 Get_Inst
=> Get_Inst
)
5257 and then not Access_Types_Match
5259 -- Don't give error message if old type is Any_Type. This test
5260 -- avoids some cascaded errors, e.g. in case of a bad spec.
5262 if Errmsg
and then Old_Formal_Base
= Any_Type
then
5265 if Ctype
>= Subtype_Conformant
5267 not Predicates_Match
(Old_Formal_Base
, New_Formal_Base
)
5270 ("\predicate of & does not match!", New_Formal
);
5273 ("\type of & does not match!", New_Formal
);
5280 -- For mode conformance, mode must match
5282 if Ctype
>= Mode_Conformant
then
5283 if Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
) then
5284 if not Ekind_In
(New_Id
, E_Function
, E_Procedure
)
5285 or else not Is_Primitive_Wrapper
(New_Id
)
5287 Conformance_Error
("\mode of & does not match!", New_Formal
);
5291 T
: constant Entity_Id
:= Find_Dispatching_Type
(New_Id
);
5293 if Is_Protected_Type
(Corresponding_Concurrent_Type
(T
))
5295 Error_Msg_PT
(New_Id
, Ultimate_Alias
(Old_Id
));
5298 ("\mode of & does not match!", New_Formal
);
5305 -- Part of mode conformance for access types is having the same
5306 -- constant modifier.
5308 elsif Access_Types_Match
5309 and then Is_Access_Constant
(Old_Formal_Base
) /=
5310 Is_Access_Constant
(New_Formal_Base
)
5313 ("\constant modifier does not match!", New_Formal
);
5318 if Ctype
>= Subtype_Conformant
then
5320 -- Ada 2005 (AI-231): In case of anonymous access types check
5321 -- the null-exclusion and access-to-constant attributes must
5322 -- match. For null exclusion, we test the types rather than the
5323 -- formals themselves, since the attribute is only set reliably
5324 -- on the formals in the Ada 95 case, and we exclude the case
5325 -- where Old_Formal is marked as controlling, to avoid errors
5326 -- when matching completing bodies with dispatching declarations
5327 -- (access formals in the bodies aren't marked Can_Never_Be_Null).
5329 if Ada_Version
>= Ada_2005
5330 and then Ekind
(Etype
(Old_Formal
)) = E_Anonymous_Access_Type
5331 and then Ekind
(Etype
(New_Formal
)) = E_Anonymous_Access_Type
5333 ((Can_Never_Be_Null
(Etype
(Old_Formal
)) /=
5334 Can_Never_Be_Null
(Etype
(New_Formal
))
5336 not Is_Controlling_Formal
(Old_Formal
))
5338 Is_Access_Constant
(Etype
(Old_Formal
)) /=
5339 Is_Access_Constant
(Etype
(New_Formal
)))
5341 -- Do not complain if error already posted on New_Formal. This
5342 -- avoids some redundant error messages.
5344 and then not Error_Posted
(New_Formal
)
5346 -- It is allowed to omit the null-exclusion in case of stream
5347 -- attribute subprograms. We recognize stream subprograms
5348 -- through their TSS-generated suffix.
5351 TSS_Name
: constant TSS_Name_Type
:= Get_TSS_Name
(New_Id
);
5354 if TSS_Name
/= TSS_Stream_Read
5355 and then TSS_Name
/= TSS_Stream_Write
5356 and then TSS_Name
/= TSS_Stream_Input
5357 and then TSS_Name
/= TSS_Stream_Output
5359 -- Here we have a definite conformance error. It is worth
5360 -- special casing the error message for the case of a
5361 -- controlling formal (which excludes null).
5363 if Is_Controlling_Formal
(New_Formal
) then
5364 Error_Msg_Node_2
:= Scope
(New_Formal
);
5366 ("\controlling formal & of & excludes null, "
5367 & "declaration must exclude null as well",
5370 -- Normal case (couldn't we give more detail here???)
5374 ("\type of & does not match!", New_Formal
);
5383 -- Full conformance checks
5385 if Ctype
= Fully_Conformant
then
5387 -- We have checked already that names match
5389 if Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
5391 -- Check default expressions for in parameters
5394 NewD
: constant Boolean :=
5395 Present
(Default_Value
(New_Formal
));
5396 OldD
: constant Boolean :=
5397 Present
(Default_Value
(Old_Formal
));
5399 if NewD
or OldD
then
5401 -- The old default value has been analyzed because the
5402 -- current full declaration will have frozen everything
5403 -- before. The new default value has not been analyzed,
5404 -- so analyze it now before we check for conformance.
5407 Push_Scope
(New_Id
);
5408 Preanalyze_Spec_Expression
5409 (Default_Value
(New_Formal
), Etype
(New_Formal
));
5413 if not (NewD
and OldD
)
5414 or else not Fully_Conformant_Expressions
5415 (Default_Value
(Old_Formal
),
5416 Default_Value
(New_Formal
))
5419 ("\default expression for & does not match!",
5428 -- A couple of special checks for Ada 83 mode. These checks are
5429 -- skipped if either entity is an operator in package Standard,
5430 -- or if either old or new instance is not from the source program.
5432 if Ada_Version
= Ada_83
5433 and then Sloc
(Old_Id
) > Standard_Location
5434 and then Sloc
(New_Id
) > Standard_Location
5435 and then Comes_From_Source
(Old_Id
)
5436 and then Comes_From_Source
(New_Id
)
5439 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
5440 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
5443 -- Explicit IN must be present or absent in both cases. This
5444 -- test is required only in the full conformance case.
5446 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
5447 and then Ctype
= Fully_Conformant
5450 ("\(Ada 83) IN must appear in both declarations",
5455 -- Grouping (use of comma in param lists) must be the same
5456 -- This is where we catch a misconformance like:
5459 -- A : Integer; B : Integer
5461 -- which are represented identically in the tree except
5462 -- for the setting of the flags More_Ids and Prev_Ids.
5464 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
5465 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
5468 ("\grouping of & does not match!", New_Formal
);
5474 -- This label is required when skipping controlling formals
5476 <<Skip_Controlling_Formal
>>
5478 Next_Formal
(Old_Formal
);
5479 Next_Formal
(New_Formal
);
5482 if Present
(Old_Formal
) then
5483 Conformance_Error
("\too few parameters!");
5486 elsif Present
(New_Formal
) then
5487 Conformance_Error
("\too many parameters!", New_Formal
);
5490 end Check_Conformance
;
5492 -----------------------
5493 -- Check_Conventions --
5494 -----------------------
5496 procedure Check_Conventions
(Typ
: Entity_Id
) is
5497 Ifaces_List
: Elist_Id
;
5499 procedure Check_Convention
(Op
: Entity_Id
);
5500 -- Verify that the convention of inherited dispatching operation Op is
5501 -- consistent among all subprograms it overrides. In order to minimize
5502 -- the search, Search_From is utilized to designate a specific point in
5503 -- the list rather than iterating over the whole list once more.
5505 ----------------------
5506 -- Check_Convention --
5507 ----------------------
5509 procedure Check_Convention
(Op
: Entity_Id
) is
5510 Op_Conv
: constant Convention_Id
:= Convention
(Op
);
5511 Iface_Conv
: Convention_Id
;
5512 Iface_Elmt
: Elmt_Id
;
5513 Iface_Prim_Elmt
: Elmt_Id
;
5514 Iface_Prim
: Entity_Id
;
5517 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
5518 while Present
(Iface_Elmt
) loop
5520 First_Elmt
(Primitive_Operations
(Node
(Iface_Elmt
)));
5521 while Present
(Iface_Prim_Elmt
) loop
5522 Iface_Prim
:= Node
(Iface_Prim_Elmt
);
5523 Iface_Conv
:= Convention
(Iface_Prim
);
5525 if Is_Interface_Conformant
(Typ
, Iface_Prim
, Op
)
5526 and then Iface_Conv
/= Op_Conv
5529 ("inconsistent conventions in primitive operations", Typ
);
5531 Error_Msg_Name_1
:= Chars
(Op
);
5532 Error_Msg_Name_2
:= Get_Convention_Name
(Op_Conv
);
5533 Error_Msg_Sloc
:= Sloc
(Op
);
5535 if Comes_From_Source
(Op
) or else No
(Alias
(Op
)) then
5536 if not Present
(Overridden_Operation
(Op
)) then
5537 Error_Msg_N
("\\primitive % defined #", Typ
);
5540 ("\\overriding operation % with "
5541 & "convention % defined #", Typ
);
5544 else pragma Assert
(Present
(Alias
(Op
)));
5545 Error_Msg_Sloc
:= Sloc
(Alias
(Op
));
5546 Error_Msg_N
("\\inherited operation % with "
5547 & "convention % defined #", Typ
);
5550 Error_Msg_Name_1
:= Chars
(Op
);
5551 Error_Msg_Name_2
:= Get_Convention_Name
(Iface_Conv
);
5552 Error_Msg_Sloc
:= Sloc
(Iface_Prim
);
5553 Error_Msg_N
("\\overridden operation % with "
5554 & "convention % defined #", Typ
);
5556 -- Avoid cascading errors
5561 Next_Elmt
(Iface_Prim_Elmt
);
5564 Next_Elmt
(Iface_Elmt
);
5566 end Check_Convention
;
5570 Prim_Op
: Entity_Id
;
5571 Prim_Op_Elmt
: Elmt_Id
;
5573 -- Start of processing for Check_Conventions
5576 if not Has_Interfaces
(Typ
) then
5580 Collect_Interfaces
(Typ
, Ifaces_List
);
5582 -- The algorithm checks every overriding dispatching operation against
5583 -- all the corresponding overridden dispatching operations, detecting
5584 -- differences in conventions.
5586 Prim_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5587 while Present
(Prim_Op_Elmt
) loop
5588 Prim_Op
:= Node
(Prim_Op_Elmt
);
5590 -- A small optimization: skip the predefined dispatching operations
5591 -- since they always have the same convention.
5593 if not Is_Predefined_Dispatching_Operation
(Prim_Op
) then
5594 Check_Convention
(Prim_Op
);
5597 Next_Elmt
(Prim_Op_Elmt
);
5599 end Check_Conventions
;
5601 ------------------------------
5602 -- Check_Delayed_Subprogram --
5603 ------------------------------
5605 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
5608 procedure Possible_Freeze
(T
: Entity_Id
);
5609 -- T is the type of either a formal parameter or of the return type.
5610 -- If T is not yet frozen and needs a delayed freeze, then the
5611 -- subprogram itself must be delayed.
5613 ---------------------
5614 -- Possible_Freeze --
5615 ---------------------
5617 procedure Possible_Freeze
(T
: Entity_Id
) is
5619 if Has_Delayed_Freeze
(T
) and then not Is_Frozen
(T
) then
5620 Set_Has_Delayed_Freeze
(Designator
);
5622 elsif Is_Access_Type
(T
)
5623 and then Has_Delayed_Freeze
(Designated_Type
(T
))
5624 and then not Is_Frozen
(Designated_Type
(T
))
5626 Set_Has_Delayed_Freeze
(Designator
);
5629 end Possible_Freeze
;
5631 -- Start of processing for Check_Delayed_Subprogram
5634 -- All subprograms, including abstract subprograms, may need a freeze
5635 -- node if some formal type or the return type needs one.
5637 Possible_Freeze
(Etype
(Designator
));
5638 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
5640 -- Need delayed freeze if any of the formal types themselves need
5641 -- a delayed freeze and are not yet frozen.
5643 F
:= First_Formal
(Designator
);
5644 while Present
(F
) loop
5645 Possible_Freeze
(Etype
(F
));
5646 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
5650 -- Mark functions that return by reference. Note that it cannot be
5651 -- done for delayed_freeze subprograms because the underlying
5652 -- returned type may not be known yet (for private types)
5654 if not Has_Delayed_Freeze
(Designator
) and then Expander_Active
then
5656 Typ
: constant Entity_Id
:= Etype
(Designator
);
5657 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
5659 if Is_Limited_View
(Typ
) then
5660 Set_Returns_By_Ref
(Designator
);
5661 elsif Present
(Utyp
) and then CW_Or_Has_Controlled_Part
(Utyp
) then
5662 Set_Returns_By_Ref
(Designator
);
5666 end Check_Delayed_Subprogram
;
5668 ------------------------------------
5669 -- Check_Discriminant_Conformance --
5670 ------------------------------------
5672 procedure Check_Discriminant_Conformance
5677 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
5678 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
5679 New_Discr_Id
: Entity_Id
;
5680 New_Discr_Type
: Entity_Id
;
5682 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
5683 -- Post error message for conformance error on given node. Two messages
5684 -- are output. The first points to the previous declaration with a
5685 -- general "no conformance" message. The second is the detailed reason,
5686 -- supplied as Msg. The parameter N provide information for a possible
5687 -- & insertion in the message.
5689 -----------------------
5690 -- Conformance_Error --
5691 -----------------------
5693 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
5695 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
5696 Error_Msg_N
-- CODEFIX
5697 ("not fully conformant with declaration#!", N
);
5698 Error_Msg_NE
(Msg
, N
, N
);
5699 end Conformance_Error
;
5701 -- Start of processing for Check_Discriminant_Conformance
5704 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
5705 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
5707 -- The subtype mark of the discriminant on the full type has not
5708 -- been analyzed so we do it here. For an access discriminant a new
5711 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
5713 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
5716 Analyze
(Discriminant_Type
(New_Discr
));
5717 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
5719 -- Ada 2005: if the discriminant definition carries a null
5720 -- exclusion, create an itype to check properly for consistency
5721 -- with partial declaration.
5723 if Is_Access_Type
(New_Discr_Type
)
5724 and then Null_Exclusion_Present
(New_Discr
)
5727 Create_Null_Excluding_Itype
5728 (T
=> New_Discr_Type
,
5729 Related_Nod
=> New_Discr
,
5730 Scope_Id
=> Current_Scope
);
5734 if not Conforming_Types
5735 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
5737 Conformance_Error
("type of & does not match!", New_Discr_Id
);
5740 -- Treat the new discriminant as an occurrence of the old one,
5741 -- for navigation purposes, and fill in some semantic
5742 -- information, for completeness.
5744 Generate_Reference
(Old_Discr
, New_Discr_Id
, 'r');
5745 Set_Etype
(New_Discr_Id
, Etype
(Old_Discr
));
5746 Set_Scope
(New_Discr_Id
, Scope
(Old_Discr
));
5751 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
5752 Conformance_Error
("name & does not match!", New_Discr_Id
);
5756 -- Default expressions must match
5759 NewD
: constant Boolean :=
5760 Present
(Expression
(New_Discr
));
5761 OldD
: constant Boolean :=
5762 Present
(Expression
(Parent
(Old_Discr
)));
5765 if NewD
or OldD
then
5767 -- The old default value has been analyzed and expanded,
5768 -- because the current full declaration will have frozen
5769 -- everything before. The new default values have not been
5770 -- expanded, so expand now to check conformance.
5773 Preanalyze_Spec_Expression
5774 (Expression
(New_Discr
), New_Discr_Type
);
5777 if not (NewD
and OldD
)
5778 or else not Fully_Conformant_Expressions
5779 (Expression
(Parent
(Old_Discr
)),
5780 Expression
(New_Discr
))
5784 ("default expression for & does not match!",
5791 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
5793 if Ada_Version
= Ada_83
then
5795 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
5798 -- Grouping (use of comma in param lists) must be the same
5799 -- This is where we catch a misconformance like:
5802 -- A : Integer; B : Integer
5804 -- which are represented identically in the tree except
5805 -- for the setting of the flags More_Ids and Prev_Ids.
5807 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
5808 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
5811 ("grouping of & does not match!", New_Discr_Id
);
5817 Next_Discriminant
(Old_Discr
);
5821 if Present
(Old_Discr
) then
5822 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
5825 elsif Present
(New_Discr
) then
5827 ("too many discriminants!", Defining_Identifier
(New_Discr
));
5830 end Check_Discriminant_Conformance
;
5832 ----------------------------
5833 -- Check_Fully_Conformant --
5834 ----------------------------
5836 procedure Check_Fully_Conformant
5837 (New_Id
: Entity_Id
;
5839 Err_Loc
: Node_Id
:= Empty
)
5842 pragma Warnings
(Off
, Result
);
5845 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
5846 end Check_Fully_Conformant
;
5848 --------------------------
5849 -- Check_Limited_Return --
5850 --------------------------
5852 procedure Check_Limited_Return
5858 -- Ada 2005 (AI-318-02): Return-by-reference types have been removed and
5859 -- replaced by anonymous access results. This is an incompatibility with
5860 -- Ada 95. Not clear whether this should be enforced yet or perhaps
5861 -- controllable with special switch. ???
5863 -- A limited interface that is not immutably limited is OK
5865 if Is_Limited_Interface
(R_Type
)
5867 not (Is_Task_Interface
(R_Type
)
5868 or else Is_Protected_Interface
(R_Type
)
5869 or else Is_Synchronized_Interface
(R_Type
))
5873 elsif Is_Limited_Type
(R_Type
)
5874 and then not Is_Interface
(R_Type
)
5875 and then Comes_From_Source
(N
)
5876 and then not In_Instance_Body
5877 and then not OK_For_Limited_Init_In_05
(R_Type
, Expr
)
5879 -- Error in Ada 2005
5881 if Ada_Version
>= Ada_2005
5882 and then not Debug_Flag_Dot_L
5883 and then not GNAT_Mode
5886 ("(Ada 2005) cannot copy object of a limited type "
5887 & "(RM-2005 6.5(5.5/2))", Expr
);
5889 if Is_Limited_View
(R_Type
) then
5891 ("\return by reference not permitted in Ada 2005", Expr
);
5894 -- Warn in Ada 95 mode, to give folks a heads up about this
5897 -- In GNAT mode, this is just a warning, to allow it to be evilly
5898 -- turned off. Otherwise it is a real error.
5900 -- In a generic context, simplify the warning because it makes no
5901 -- sense to discuss pass-by-reference or copy.
5903 elsif Warn_On_Ada_2005_Compatibility
or GNAT_Mode
then
5904 if Inside_A_Generic
then
5906 ("return of limited object not permitted in Ada 2005 "
5907 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
5909 elsif Is_Limited_View
(R_Type
) then
5911 ("return by reference not permitted in Ada 2005 "
5912 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
5915 ("cannot copy object of a limited type in Ada 2005 "
5916 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
5919 -- Ada 95 mode, compatibility warnings disabled
5922 return; -- skip continuation messages below
5925 if not Inside_A_Generic
then
5927 ("\consider switching to return of access type", Expr
);
5928 Explain_Limited_Type
(R_Type
, Expr
);
5931 end Check_Limited_Return
;
5933 ---------------------------
5934 -- Check_Mode_Conformant --
5935 ---------------------------
5937 procedure Check_Mode_Conformant
5938 (New_Id
: Entity_Id
;
5940 Err_Loc
: Node_Id
:= Empty
;
5941 Get_Inst
: Boolean := False)
5944 pragma Warnings
(Off
, Result
);
5947 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
5948 end Check_Mode_Conformant
;
5950 --------------------------------
5951 -- Check_Overriding_Indicator --
5952 --------------------------------
5954 procedure Check_Overriding_Indicator
5956 Overridden_Subp
: Entity_Id
;
5957 Is_Primitive
: Boolean)
5963 -- No overriding indicator for literals
5965 if Ekind
(Subp
) = E_Enumeration_Literal
then
5968 elsif Ekind
(Subp
) = E_Entry
then
5969 Decl
:= Parent
(Subp
);
5971 -- No point in analyzing a malformed operator
5973 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
5974 and then Error_Posted
(Subp
)
5979 Decl
:= Unit_Declaration_Node
(Subp
);
5982 if Nkind_In
(Decl
, N_Subprogram_Body
,
5983 N_Subprogram_Body_Stub
,
5984 N_Subprogram_Declaration
,
5985 N_Abstract_Subprogram_Declaration
,
5986 N_Subprogram_Renaming_Declaration
)
5988 Spec
:= Specification
(Decl
);
5990 elsif Nkind
(Decl
) = N_Entry_Declaration
then
5997 -- The overriding operation is type conformant with the overridden one,
5998 -- but the names of the formals are not required to match. If the names
5999 -- appear permuted in the overriding operation, this is a possible
6000 -- source of confusion that is worth diagnosing. Controlling formals
6001 -- often carry names that reflect the type, and it is not worthwhile
6002 -- requiring that their names match.
6004 if Present
(Overridden_Subp
)
6005 and then Nkind
(Subp
) /= N_Defining_Operator_Symbol
6012 Form1
:= First_Formal
(Subp
);
6013 Form2
:= First_Formal
(Overridden_Subp
);
6015 -- If the overriding operation is a synchronized operation, skip
6016 -- the first parameter of the overridden operation, which is
6017 -- implicit in the new one. If the operation is declared in the
6018 -- body it is not primitive and all formals must match.
6020 if Is_Concurrent_Type
(Scope
(Subp
))
6021 and then Is_Tagged_Type
(Scope
(Subp
))
6022 and then not Has_Completion
(Scope
(Subp
))
6024 Form2
:= Next_Formal
(Form2
);
6027 if Present
(Form1
) then
6028 Form1
:= Next_Formal
(Form1
);
6029 Form2
:= Next_Formal
(Form2
);
6032 while Present
(Form1
) loop
6033 if not Is_Controlling_Formal
(Form1
)
6034 and then Present
(Next_Formal
(Form2
))
6035 and then Chars
(Form1
) = Chars
(Next_Formal
(Form2
))
6037 Error_Msg_Node_2
:= Alias
(Overridden_Subp
);
6038 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
6040 ("& does not match corresponding formal of&#",
6045 Next_Formal
(Form1
);
6046 Next_Formal
(Form2
);
6051 -- If there is an overridden subprogram, then check that there is no
6052 -- "not overriding" indicator, and mark the subprogram as overriding.
6053 -- This is not done if the overridden subprogram is marked as hidden,
6054 -- which can occur for the case of inherited controlled operations
6055 -- (see Derive_Subprogram), unless the inherited subprogram's parent
6056 -- subprogram is not itself hidden. (Note: This condition could probably
6057 -- be simplified, leaving out the testing for the specific controlled
6058 -- cases, but it seems safer and clearer this way, and echoes similar
6059 -- special-case tests of this kind in other places.)
6061 if Present
(Overridden_Subp
)
6062 and then (not Is_Hidden
(Overridden_Subp
)
6064 (Nam_In
(Chars
(Overridden_Subp
), Name_Initialize
,
6067 and then Present
(Alias
(Overridden_Subp
))
6068 and then not Is_Hidden
(Alias
(Overridden_Subp
))))
6070 if Must_Not_Override
(Spec
) then
6071 Error_Msg_Sloc
:= Sloc
(Overridden_Subp
);
6073 if Ekind
(Subp
) = E_Entry
then
6075 ("entry & overrides inherited operation #", Spec
, Subp
);
6078 ("subprogram & overrides inherited operation #", Spec
, Subp
);
6081 -- Special-case to fix a GNAT oddity: Limited_Controlled is declared
6082 -- as an extension of Root_Controlled, and thus has a useless Adjust
6083 -- operation. This operation should not be inherited by other limited
6084 -- controlled types. An explicit Adjust for them is not overriding.
6086 elsif Must_Override
(Spec
)
6087 and then Chars
(Overridden_Subp
) = Name_Adjust
6088 and then Is_Limited_Type
(Etype
(First_Formal
(Subp
)))
6089 and then Present
(Alias
(Overridden_Subp
))
6091 Is_Predefined_File_Name
6092 (Unit_File_Name
(Get_Source_Unit
(Alias
(Overridden_Subp
))))
6094 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6096 elsif Is_Subprogram
(Subp
) then
6097 if Is_Init_Proc
(Subp
) then
6100 elsif No
(Overridden_Operation
(Subp
)) then
6102 -- For entities generated by Derive_Subprograms the overridden
6103 -- operation is the inherited primitive (which is available
6104 -- through the attribute alias)
6106 if (Is_Dispatching_Operation
(Subp
)
6107 or else Is_Dispatching_Operation
(Overridden_Subp
))
6108 and then not Comes_From_Source
(Overridden_Subp
)
6109 and then Find_Dispatching_Type
(Overridden_Subp
) =
6110 Find_Dispatching_Type
(Subp
)
6111 and then Present
(Alias
(Overridden_Subp
))
6112 and then Comes_From_Source
(Alias
(Overridden_Subp
))
6114 Set_Overridden_Operation
(Subp
, Alias
(Overridden_Subp
));
6115 Inherit_Subprogram_Contract
(Subp
, Alias
(Overridden_Subp
));
6118 Set_Overridden_Operation
(Subp
, Overridden_Subp
);
6119 Inherit_Subprogram_Contract
(Subp
, Overridden_Subp
);
6124 -- If primitive flag is set or this is a protected operation, then
6125 -- the operation is overriding at the point of its declaration, so
6126 -- warn if necessary. Otherwise it may have been declared before the
6127 -- operation it overrides and no check is required.
6130 and then not Must_Override
(Spec
)
6131 and then (Is_Primitive
6132 or else Ekind
(Scope
(Subp
)) = E_Protected_Type
)
6134 Style
.Missing_Overriding
(Decl
, Subp
);
6137 -- If Subp is an operator, it may override a predefined operation, if
6138 -- it is defined in the same scope as the type to which it applies.
6139 -- In that case Overridden_Subp is empty because of our implicit
6140 -- representation for predefined operators. We have to check whether the
6141 -- signature of Subp matches that of a predefined operator. Note that
6142 -- first argument provides the name of the operator, and the second
6143 -- argument the signature that may match that of a standard operation.
6144 -- If the indicator is overriding, then the operator must match a
6145 -- predefined signature, because we know already that there is no
6146 -- explicit overridden operation.
6148 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
then
6149 if Must_Not_Override
(Spec
) then
6151 -- If this is not a primitive or a protected subprogram, then
6152 -- "not overriding" is illegal.
6155 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
6157 Error_Msg_N
("overriding indicator only allowed "
6158 & "if subprogram is primitive", Subp
);
6160 elsif Can_Override_Operator
(Subp
) then
6162 ("subprogram& overrides predefined operator ", Spec
, Subp
);
6165 elsif Must_Override
(Spec
) then
6166 if No
(Overridden_Operation
(Subp
))
6167 and then not Can_Override_Operator
(Subp
)
6169 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6172 elsif not Error_Posted
(Subp
)
6173 and then Style_Check
6174 and then Can_Override_Operator
(Subp
)
6176 not Is_Predefined_File_Name
6177 (Unit_File_Name
(Get_Source_Unit
(Subp
)))
6179 -- If style checks are enabled, indicate that the indicator is
6180 -- missing. However, at the point of declaration, the type of
6181 -- which this is a primitive operation may be private, in which
6182 -- case the indicator would be premature.
6184 if Has_Private_Declaration
(Etype
(Subp
))
6185 or else Has_Private_Declaration
(Etype
(First_Formal
(Subp
)))
6189 Style
.Missing_Overriding
(Decl
, Subp
);
6193 elsif Must_Override
(Spec
) then
6194 if Ekind
(Subp
) = E_Entry
then
6195 Error_Msg_NE
("entry & is not overriding", Spec
, Subp
);
6197 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6200 -- If the operation is marked "not overriding" and it's not primitive
6201 -- then an error is issued, unless this is an operation of a task or
6202 -- protected type (RM05-8.3.1(3/2-4/2)). Error cases where "overriding"
6203 -- has been specified have already been checked above.
6205 elsif Must_Not_Override
(Spec
)
6206 and then not Is_Primitive
6207 and then Ekind
(Subp
) /= E_Entry
6208 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
6211 ("overriding indicator only allowed if subprogram is primitive",
6215 end Check_Overriding_Indicator
;
6221 -- Note: this procedure needs to know far too much about how the expander
6222 -- messes with exceptions. The use of the flag Exception_Junk and the
6223 -- incorporation of knowledge of Exp_Ch11.Expand_Local_Exception_Handlers
6224 -- works, but is not very clean. It would be better if the expansion
6225 -- routines would leave Original_Node working nicely, and we could use
6226 -- Original_Node here to ignore all the peculiar expander messing ???
6228 procedure Check_Returns
6232 Proc
: Entity_Id
:= Empty
)
6236 procedure Check_Statement_Sequence
(L
: List_Id
);
6237 -- Internal recursive procedure to check a list of statements for proper
6238 -- termination by a return statement (or a transfer of control or a
6239 -- compound statement that is itself internally properly terminated).
6241 ------------------------------
6242 -- Check_Statement_Sequence --
6243 ------------------------------
6245 procedure Check_Statement_Sequence
(L
: List_Id
) is
6250 function Assert_False
return Boolean;
6251 -- Returns True if Last_Stm is a pragma Assert (False) that has been
6252 -- rewritten as a null statement when assertions are off. The assert
6253 -- is not active, but it is still enough to kill the warning.
6259 function Assert_False
return Boolean is
6260 Orig
: constant Node_Id
:= Original_Node
(Last_Stm
);
6263 if Nkind
(Orig
) = N_Pragma
6264 and then Pragma_Name
(Orig
) = Name_Assert
6265 and then not Error_Posted
(Orig
)
6268 Arg
: constant Node_Id
:=
6269 First
(Pragma_Argument_Associations
(Orig
));
6270 Exp
: constant Node_Id
:= Expression
(Arg
);
6272 return Nkind
(Exp
) = N_Identifier
6273 and then Chars
(Exp
) = Name_False
;
6283 Raise_Exception_Call
: Boolean;
6284 -- Set True if statement sequence terminated by Raise_Exception call
6285 -- or a Reraise_Occurrence call.
6287 -- Start of processing for Check_Statement_Sequence
6290 Raise_Exception_Call
:= False;
6292 -- Get last real statement
6294 Last_Stm
:= Last
(L
);
6296 -- Deal with digging out exception handler statement sequences that
6297 -- have been transformed by the local raise to goto optimization.
6298 -- See Exp_Ch11.Expand_Local_Exception_Handlers for details. If this
6299 -- optimization has occurred, we are looking at something like:
6302 -- original stmts in block
6306 -- goto L1; | omitted if No_Exception_Propagation
6311 -- goto L3; -- skip handler when exception not raised
6313 -- <<L1>> -- target label for local exception
6327 -- and what we have to do is to dig out the estmts1 and estmts2
6328 -- sequences (which were the original sequences of statements in
6329 -- the exception handlers) and check them.
6331 if Nkind
(Last_Stm
) = N_Label
and then Exception_Junk
(Last_Stm
) then
6336 exit when Nkind
(Stm
) /= N_Block_Statement
;
6337 exit when not Exception_Junk
(Stm
);
6340 exit when Nkind
(Stm
) /= N_Label
;
6341 exit when not Exception_Junk
(Stm
);
6342 Check_Statement_Sequence
6343 (Statements
(Handled_Statement_Sequence
(Next
(Stm
))));
6348 exit when Nkind
(Stm
) /= N_Goto_Statement
;
6349 exit when not Exception_Junk
(Stm
);
6353 -- Don't count pragmas
6355 while Nkind
(Last_Stm
) = N_Pragma
6357 -- Don't count call to SS_Release (can happen after Raise_Exception)
6360 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
6362 Nkind
(Name
(Last_Stm
)) = N_Identifier
6364 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
6366 -- Don't count exception junk
6369 (Nkind_In
(Last_Stm
, N_Goto_Statement
,
6371 N_Object_Declaration
)
6372 and then Exception_Junk
(Last_Stm
))
6373 or else Nkind
(Last_Stm
) in N_Push_xxx_Label
6374 or else Nkind
(Last_Stm
) in N_Pop_xxx_Label
6376 -- Inserted code, such as finalization calls, is irrelevant: we only
6377 -- need to check original source.
6379 or else Is_Rewrite_Insertion
(Last_Stm
)
6384 -- Here we have the "real" last statement
6386 Kind
:= Nkind
(Last_Stm
);
6388 -- Transfer of control, OK. Note that in the No_Return procedure
6389 -- case, we already diagnosed any explicit return statements, so
6390 -- we can treat them as OK in this context.
6392 if Is_Transfer
(Last_Stm
) then
6395 -- Check cases of explicit non-indirect procedure calls
6397 elsif Kind
= N_Procedure_Call_Statement
6398 and then Is_Entity_Name
(Name
(Last_Stm
))
6400 -- Check call to Raise_Exception procedure which is treated
6401 -- specially, as is a call to Reraise_Occurrence.
6403 -- We suppress the warning in these cases since it is likely that
6404 -- the programmer really does not expect to deal with the case
6405 -- of Null_Occurrence, and thus would find a warning about a
6406 -- missing return curious, and raising Program_Error does not
6407 -- seem such a bad behavior if this does occur.
6409 -- Note that in the Ada 2005 case for Raise_Exception, the actual
6410 -- behavior will be to raise Constraint_Error (see AI-329).
6412 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
6414 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
6416 Raise_Exception_Call
:= True;
6418 -- For Raise_Exception call, test first argument, if it is
6419 -- an attribute reference for a 'Identity call, then we know
6420 -- that the call cannot possibly return.
6423 Arg
: constant Node_Id
:=
6424 Original_Node
(First_Actual
(Last_Stm
));
6426 if Nkind
(Arg
) = N_Attribute_Reference
6427 and then Attribute_Name
(Arg
) = Name_Identity
6434 -- If statement, need to look inside if there is an else and check
6435 -- each constituent statement sequence for proper termination.
6437 elsif Kind
= N_If_Statement
6438 and then Present
(Else_Statements
(Last_Stm
))
6440 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
6441 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
6443 if Present
(Elsif_Parts
(Last_Stm
)) then
6445 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
6448 while Present
(Elsif_Part
) loop
6449 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
6457 -- Case statement, check each case for proper termination
6459 elsif Kind
= N_Case_Statement
then
6463 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
6464 while Present
(Case_Alt
) loop
6465 Check_Statement_Sequence
(Statements
(Case_Alt
));
6466 Next_Non_Pragma
(Case_Alt
);
6472 -- Block statement, check its handled sequence of statements
6474 elsif Kind
= N_Block_Statement
then
6480 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
6489 -- Loop statement. If there is an iteration scheme, we can definitely
6490 -- fall out of the loop. Similarly if there is an exit statement, we
6491 -- can fall out. In either case we need a following return.
6493 elsif Kind
= N_Loop_Statement
then
6494 if Present
(Iteration_Scheme
(Last_Stm
))
6495 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
6499 -- A loop with no exit statement or iteration scheme is either
6500 -- an infinite loop, or it has some other exit (raise/return).
6501 -- In either case, no warning is required.
6507 -- Timed entry call, check entry call and delay alternatives
6509 -- Note: in expanded code, the timed entry call has been converted
6510 -- to a set of expanded statements on which the check will work
6511 -- correctly in any case.
6513 elsif Kind
= N_Timed_Entry_Call
then
6515 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
6516 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
6519 -- If statement sequence of entry call alternative is missing,
6520 -- then we can definitely fall through, and we post the error
6521 -- message on the entry call alternative itself.
6523 if No
(Statements
(ECA
)) then
6526 -- If statement sequence of delay alternative is missing, then
6527 -- we can definitely fall through, and we post the error
6528 -- message on the delay alternative itself.
6530 -- Note: if both ECA and DCA are missing the return, then we
6531 -- post only one message, should be enough to fix the bugs.
6532 -- If not we will get a message next time on the DCA when the
6535 elsif No
(Statements
(DCA
)) then
6538 -- Else check both statement sequences
6541 Check_Statement_Sequence
(Statements
(ECA
));
6542 Check_Statement_Sequence
(Statements
(DCA
));
6547 -- Conditional entry call, check entry call and else part
6549 -- Note: in expanded code, the conditional entry call has been
6550 -- converted to a set of expanded statements on which the check
6551 -- will work correctly in any case.
6553 elsif Kind
= N_Conditional_Entry_Call
then
6555 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
6558 -- If statement sequence of entry call alternative is missing,
6559 -- then we can definitely fall through, and we post the error
6560 -- message on the entry call alternative itself.
6562 if No
(Statements
(ECA
)) then
6565 -- Else check statement sequence and else part
6568 Check_Statement_Sequence
(Statements
(ECA
));
6569 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
6575 -- If we fall through, issue appropriate message
6579 -- Kill warning if last statement is a raise exception call,
6580 -- or a pragma Assert (False). Note that with assertions enabled,
6581 -- such a pragma has been converted into a raise exception call
6582 -- already, so the Assert_False is for the assertions off case.
6584 if not Raise_Exception_Call
and then not Assert_False
then
6586 -- In GNATprove mode, it is an error to have a missing return
6588 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6590 -- Issue error message or warning
6593 ("RETURN statement missing following this statement<<!",
6596 ("\Program_Error ]<<!", Last_Stm
);
6599 -- Note: we set Err even though we have not issued a warning
6600 -- because we still have a case of a missing return. This is
6601 -- an extremely marginal case, probably will never be noticed
6602 -- but we might as well get it right.
6606 -- Otherwise we have the case of a procedure marked No_Return
6609 if not Raise_Exception_Call
then
6610 if GNATprove_Mode
then
6612 ("implied return after this statement "
6613 & "would have raised Program_Error", Last_Stm
);
6616 ("implied return after this statement "
6617 & "will raise Program_Error??", Last_Stm
);
6620 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6622 ("\procedure & is marked as No_Return<<!", Last_Stm
, Proc
);
6626 RE
: constant Node_Id
:=
6627 Make_Raise_Program_Error
(Sloc
(Last_Stm
),
6628 Reason
=> PE_Implicit_Return
);
6630 Insert_After
(Last_Stm
, RE
);
6634 end Check_Statement_Sequence
;
6636 -- Start of processing for Check_Returns
6640 Check_Statement_Sequence
(Statements
(HSS
));
6642 if Present
(Exception_Handlers
(HSS
)) then
6643 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
6644 while Present
(Handler
) loop
6645 Check_Statement_Sequence
(Statements
(Handler
));
6646 Next_Non_Pragma
(Handler
);
6651 ----------------------------
6652 -- Check_Subprogram_Order --
6653 ----------------------------
6655 procedure Check_Subprogram_Order
(N
: Node_Id
) is
6657 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
6658 -- This is used to check if S1 > S2 in the sense required by this test,
6659 -- for example nameab < namec, but name2 < name10.
6661 -----------------------------
6662 -- Subprogram_Name_Greater --
6663 -----------------------------
6665 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
6670 -- Deal with special case where names are identical except for a
6671 -- numerical suffix. These are handled specially, taking the numeric
6672 -- ordering from the suffix into account.
6675 while S1
(L1
) in '0' .. '9' loop
6680 while S2
(L2
) in '0' .. '9' loop
6684 -- If non-numeric parts non-equal, do straight compare
6686 if S1
(S1
'First .. L1
) /= S2
(S2
'First .. L2
) then
6689 -- If non-numeric parts equal, compare suffixed numeric parts. Note
6690 -- that a missing suffix is treated as numeric zero in this test.
6694 while L1
< S1
'Last loop
6696 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
6700 while L2
< S2
'Last loop
6702 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
6707 end Subprogram_Name_Greater
;
6709 -- Start of processing for Check_Subprogram_Order
6712 -- Check body in alpha order if this is option
6715 and then Style_Check_Order_Subprograms
6716 and then Nkind
(N
) = N_Subprogram_Body
6717 and then Comes_From_Source
(N
)
6718 and then In_Extended_Main_Source_Unit
(N
)
6722 renames Scope_Stack
.Table
6723 (Scope_Stack
.Last
).Last_Subprogram_Name
;
6725 Body_Id
: constant Entity_Id
:=
6726 Defining_Entity
(Specification
(N
));
6729 Get_Decoded_Name_String
(Chars
(Body_Id
));
6732 if Subprogram_Name_Greater
6733 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
6735 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
6741 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
6744 end Check_Subprogram_Order;
6746 ------------------------------
6747 -- Check_Subtype_Conformant --
6748 ------------------------------
6750 procedure Check_Subtype_Conformant
6751 (New_Id : Entity_Id;
6753 Err_Loc : Node_Id := Empty;
6754 Skip_Controlling_Formals : Boolean := False;
6755 Get_Inst : Boolean := False)
6758 pragma Warnings (Off, Result);
6761 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc,
6762 Skip_Controlling_Formals => Skip_Controlling_Formals,
6763 Get_Inst => Get_Inst);
6764 end Check_Subtype_Conformant;
6766 -----------------------------------
6767 -- Check_Synchronized_Overriding --
6768 -----------------------------------
6770 procedure Check_Synchronized_Overriding
6771 (Def_Id : Entity_Id;
6772 Overridden_Subp : out Entity_Id)
6774 Ifaces_List : Elist_Id;
6778 function Matches_Prefixed_View_Profile
6779 (Prim_Params : List_Id;
6780 Iface_Params : List_Id) return Boolean;
6781 -- Determine whether a subprogram's parameter profile Prim_Params
6782 -- matches that of a potentially overridden interface subprogram
6783 -- Iface_Params. Also determine if the type of first parameter of
6784 -- Iface_Params is an implemented interface.
6786 -----------------------------------
6787 -- Matches_Prefixed_View_Profile --
6788 -----------------------------------
6790 function Matches_Prefixed_View_Profile
6791 (Prim_Params : List_Id;
6792 Iface_Params : List_Id) return Boolean
6794 function Is_Implemented
6795 (Ifaces_List : Elist_Id;
6796 Iface : Entity_Id) return Boolean;
6797 -- Determine if Iface is implemented by the current task or
6800 --------------------
6801 -- Is_Implemented --
6802 --------------------
6804 function Is_Implemented
6805 (Ifaces_List : Elist_Id;
6806 Iface : Entity_Id) return Boolean
6808 Iface_Elmt : Elmt_Id;
6811 Iface_Elmt := First_Elmt (Ifaces_List);
6812 while Present (Iface_Elmt) loop
6813 if Node (Iface_Elmt) = Iface then
6817 Next_Elmt (Iface_Elmt);
6825 Iface_Id : Entity_Id;
6826 Iface_Param : Node_Id;
6827 Iface_Typ : Entity_Id;
6828 Prim_Id : Entity_Id;
6829 Prim_Param : Node_Id;
6830 Prim_Typ : Entity_Id;
6832 -- Start of processing for Matches_Prefixed_View_Profile
6835 Iface_Param := First (Iface_Params);
6836 Iface_Typ := Etype (Defining_Identifier (Iface_Param));
6838 if Is_Access_Type (Iface_Typ) then
6839 Iface_Typ := Designated_Type (Iface_Typ);
6842 Prim_Param := First (Prim_Params);
6844 -- The first parameter of the potentially overridden subprogram must
6845 -- be an interface implemented by Prim.
6847 if not Is_Interface (Iface_Typ)
6848 or else not Is_Implemented (Ifaces_List, Iface_Typ)
6853 -- The checks on the object parameters are done, so move on to the
6854 -- rest of the parameters.
6856 if not In_Scope then
6857 Prim_Param := Next (Prim_Param);
6860 Iface_Param := Next (Iface_Param);
6861 while Present (Iface_Param) and then Present (Prim_Param) loop
6862 Iface_Id := Defining_Identifier (Iface_Param);
6863 Iface_Typ := Find_Parameter_Type (Iface_Param);
6865 Prim_Id := Defining_Identifier (Prim_Param);
6866 Prim_Typ := Find_Parameter_Type (Prim_Param);
6868 if Ekind (Iface_Typ) = E_Anonymous_Access_Type
6869 and then Ekind (Prim_Typ) = E_Anonymous_Access_Type
6870 and then Is_Concurrent_Type (Designated_Type (Prim_Typ))
6872 Iface_Typ := Designated_Type (Iface_Typ);
6873 Prim_Typ := Designated_Type (Prim_Typ);
6876 -- Case of multiple interface types inside a parameter profile
6878 -- (Obj_Param : in out Iface; ...; Param : Iface)
6880 -- If the interface type is implemented, then the matching type in
6881 -- the primitive should be the implementing record type.
6883 if Ekind (Iface_Typ) = E_Record_Type
6884 and then Is_Interface (Iface_Typ)
6885 and then Is_Implemented (Ifaces_List, Iface_Typ)
6887 if Prim_Typ /= Typ then
6891 -- The two parameters must be both mode and subtype conformant
6893 elsif Ekind (Iface_Id) /= Ekind (Prim_Id)
6895 Conforming_Types (Iface_Typ, Prim_Typ, Subtype_Conformant)
6904 -- One of the two lists contains more parameters than the other
6906 if Present (Iface_Param) or else Present (Prim_Param) then
6911 end Matches_Prefixed_View_Profile;
6913 -- Start of processing for Check_Synchronized_Overriding
6916 Overridden_Subp := Empty;
6918 -- Def_Id must be an entry or a subprogram. We should skip predefined
6919 -- primitives internally generated by the front end; however at this
6920 -- stage predefined primitives are still not fully decorated. As a
6921 -- minor optimization we skip here internally generated subprograms.
6923 if (Ekind (Def_Id) /= E_Entry
6924 and then Ekind (Def_Id) /= E_Function
6925 and then Ekind (Def_Id) /= E_Procedure)
6926 or else not Comes_From_Source (Def_Id)
6931 -- Search for the concurrent declaration since it contains the list of
6932 -- all implemented interfaces. In this case, the subprogram is declared
6933 -- within the scope of a protected or a task type.
6935 if Present (Scope (Def_Id))
6936 and then Is_Concurrent_Type (Scope (Def_Id))
6937 and then not Is_Generic_Actual_Type (Scope (Def_Id))
6939 Typ := Scope (Def_Id);
6942 -- The enclosing scope is not a synchronized type and the subprogram
6945 elsif No (First_Formal (Def_Id)) then
6948 -- The subprogram has formals and hence it may be a primitive of a
6952 Typ := Etype (First_Formal (Def_Id));
6954 if Is_Access_Type (Typ) then
6955 Typ := Directly_Designated_Type (Typ);
6958 if Is_Concurrent_Type (Typ)
6959 and then not Is_Generic_Actual_Type (Typ)
6963 -- This case occurs when the concurrent type is declared within a
6964 -- generic unit. As a result the corresponding record has been built
6965 -- and used as the type of the first formal, we just have to retrieve
6966 -- the corresponding concurrent type.
6968 elsif Is_Concurrent_Record_Type (Typ)
6969 and then not Is_Class_Wide_Type (Typ)
6970 and then Present (Corresponding_Concurrent_Type (Typ))
6972 Typ := Corresponding_Concurrent_Type (Typ);
6980 -- There is no overriding to check if this is an inherited operation in
6981 -- a type derivation for a generic actual.
6983 Collect_Interfaces (Typ, Ifaces_List);
6985 if Is_Empty_Elmt_List (Ifaces_List) then
6989 -- Determine whether entry or subprogram Def_Id overrides a primitive
6990 -- operation that belongs to one of the interfaces in Ifaces_List.
6993 Candidate : Entity_Id := Empty;
6994 Hom : Entity_Id := Empty;
6995 Subp : Entity_Id := Empty;
6998 -- Traverse the homonym chain, looking for a potentially overridden
6999 -- subprogram that belongs to an implemented interface.
7001 Hom := Current_Entity_In_Scope (Def_Id);
7002 while Present (Hom) loop
7006 or else not Is_Overloadable (Subp)
7007 or else not Is_Primitive (Subp)
7008 or else not Is_Dispatching_Operation (Subp)
7009 or else not Present (Find_Dispatching_Type (Subp))
7010 or else not Is_Interface (Find_Dispatching_Type (Subp))
7014 -- Entries and procedures can override abstract or null interface
7017 elsif Ekind_In (Def_Id, E_Entry, E_Procedure)
7018 and then Ekind (Subp) = E_Procedure
7019 and then Matches_Prefixed_View_Profile
7020 (Parameter_Specifications (Parent (Def_Id)),
7021 Parameter_Specifications (Parent (Subp)))
7025 -- For an overridden subprogram Subp, check whether the mode
7026 -- of its first parameter is correct depending on the kind of
7027 -- synchronized type.
7030 Formal : constant Node_Id := First_Formal (Candidate);
7033 -- In order for an entry or a protected procedure to
7034 -- override, the first parameter of the overridden routine
7035 -- must be of mode "out", "in out", or access-to-variable.
7037 if Ekind_In (Candidate, E_Entry, E_Procedure)
7038 and then Is_Protected_Type (Typ)
7039 and then Ekind (Formal) /= E_In_Out_Parameter
7040 and then Ekind (Formal) /= E_Out_Parameter
7041 and then Nkind (Parameter_Type (Parent (Formal))) /=
7046 -- All other cases are OK since a task entry or routine does
7047 -- not have a restriction on the mode of the first parameter
7048 -- of the overridden interface routine.
7051 Overridden_Subp := Candidate;
7056 -- Functions can override abstract interface functions
7058 elsif Ekind (Def_Id) = E_Function
7059 and then Ekind (Subp) = E_Function
7060 and then Matches_Prefixed_View_Profile
7061 (Parameter_Specifications (Parent (Def_Id)),
7062 Parameter_Specifications (Parent (Subp)))
7063 and then Etype (Def_Id) = Etype (Subp)
7067 -- If an inherited subprogram is implemented by a protected
7068 -- function, then the first parameter of the inherited
7069 -- subprogram shall be of mode in, but not an access-to-
7070 -- variable parameter (RM 9.4(11/9)).
7072 if Present (First_Formal (Subp))
7073 and then Ekind (First_Formal (Subp)) = E_In_Parameter
7075 (not Is_Access_Type (Etype (First_Formal (Subp)))
7077 Is_Access_Constant (Etype (First_Formal (Subp))))
7079 Overridden_Subp := Subp;
7084 Hom := Homonym (Hom);
7087 -- After examining all candidates for overriding, we are left with
7088 -- the best match, which is a mode-incompatible interface routine.
7090 if In_Scope and then Present (Candidate) then
7091 Error_Msg_PT (Def_Id, Candidate);
7094 Overridden_Subp := Candidate;
7097 end Check_Synchronized_Overriding;
7099 ---------------------------
7100 -- Check_Type_Conformant --
7101 ---------------------------
7103 procedure Check_Type_Conformant
7104 (New_Id : Entity_Id;
7106 Err_Loc : Node_Id := Empty)
7109 pragma Warnings (Off, Result);
7112 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
7113 end Check_Type_Conformant;
7115 ---------------------------
7116 -- Can_Override_Operator --
7117 ---------------------------
7119 function Can_Override_Operator (Subp : Entity_Id) return Boolean is
7123 if Nkind (Subp) /= N_Defining_Operator_Symbol then
7127 Typ := Base_Type (Etype (First_Formal (Subp)));
7129 -- Check explicitly that the operation is a primitive of the type
7131 return Operator_Matches_Spec (Subp, Subp)
7132 and then not Is_Generic_Type (Typ)
7133 and then Scope (Subp) = Scope (Typ)
7134 and then not Is_Class_Wide_Type (Typ);
7136 end Can_Override_Operator;
7138 ----------------------
7139 -- Conforming_Types --
7140 ----------------------
7142 function Conforming_Types
7145 Ctype : Conformance_Type;
7146 Get_Inst : Boolean := False) return Boolean
7148 function Base_Types_Match
7150 Typ_2 : Entity_Id) return Boolean;
7151 -- If neither Typ_1 nor Typ_2 are generic actual types, or if they are
7152 -- in different scopes (e.g. parent and child instances), then verify
7153 -- that the base types are equal. Otherwise Typ_1 and Typ_2 must be on
7154 -- the same subtype chain. The whole purpose of this procedure is to
7155 -- prevent spurious ambiguities in an instantiation that may arise if
7156 -- two distinct generic types are instantiated with the same actual.
7158 function Find_Designated_Type (Typ : Entity_Id) return Entity_Id;
7159 -- An access parameter can designate an incomplete type. If the
7160 -- incomplete type is the limited view of a type from a limited_
7161 -- with_clause, check whether the non-limited view is available.
7162 -- If it is a (non-limited) incomplete type, get the full view.
7164 function Matches_Limited_With_View
7166 Typ_2 : Entity_Id) return Boolean;
7167 -- Returns True if and only if either Typ_1 denotes a limited view of
7168 -- Typ_2 or Typ_2 denotes a limited view of Typ_1. This can arise when
7169 -- the limited with view of a type is used in a subprogram declaration
7170 -- and the subprogram body is in the scope of a regular with clause for
7171 -- the same unit. In such a case, the two type entities are considered
7172 -- identical for purposes of conformance checking.
7174 ----------------------
7175 -- Base_Types_Match --
7176 ----------------------
7178 function Base_Types_Match
7180 Typ_2 : Entity_Id) return Boolean
7182 Base_1 : constant Entity_Id := Base_Type (Typ_1);
7183 Base_2 : constant Entity_Id := Base_Type (Typ_2);
7186 if Typ_1 = Typ_2 then
7189 elsif Base_1 = Base_2 then
7191 -- The following is too permissive. A more precise test should
7192 -- check that the generic actual is an ancestor subtype of the
7195 -- See code in Find_Corresponding_Spec that applies an additional
7196 -- filter to handle accidental amiguities in instances.
7199 not Is_Generic_Actual_Type (Typ_1)
7200 or else not Is_Generic_Actual_Type (Typ_2)
7201 or else Scope (Typ_1) /= Scope (Typ_2);
7203 -- If Typ_2 is a generic actual type it is declared as the subtype of
7204 -- the actual. If that actual is itself a subtype we need to use its
7205 -- own base type to check for compatibility.
7207 elsif Ekind (Base_2) = Ekind (Typ_2)
7208 and then Base_1 = Base_Type (Base_2)
7212 elsif Ekind (Base_1) = Ekind (Typ_1)
7213 and then Base_2 = Base_Type (Base_1)
7220 end Base_Types_Match;
7222 --------------------------
7223 -- Find_Designated_Type --
7224 --------------------------
7226 function Find_Designated_Type (Typ : Entity_Id) return Entity_Id is
7230 Desig := Directly_Designated_Type (Typ);
7232 if Ekind (Desig) = E_Incomplete_Type then
7234 -- If regular incomplete type, get full view if available
7236 if Present (Full_View (Desig)) then
7237 Desig := Full_View (Desig);
7239 -- If limited view of a type, get non-limited view if available,
7240 -- and check again for a regular incomplete type.
7242 elsif Present (Non_Limited_View (Desig)) then
7243 Desig := Get_Full_View (Non_Limited_View (Desig));
7248 end Find_Designated_Type;
7250 -------------------------------
7251 -- Matches_Limited_With_View --
7252 -------------------------------
7254 function Matches_Limited_With_View
7256 Typ_2 : Entity_Id) return Boolean
7258 function Is_Matching_Limited_View
7260 View : Entity_Id) return Boolean;
7261 -- Determine whether non-limited view View denotes type Typ in some
7262 -- conformant fashion.
7264 ------------------------------
7265 -- Is_Matching_Limited_View --
7266 ------------------------------
7268 function Is_Matching_Limited_View
7270 View : Entity_Id) return Boolean
7272 Root_Typ : Entity_Id;
7273 Root_View : Entity_Id;
7276 -- The non-limited view directly denotes the type
7281 -- The type is a subtype of the non-limited view
7283 elsif Is_Subtype_Of (Typ, View) then
7286 -- Both the non-limited view and the type denote class-wide types
7288 elsif Is_Class_Wide_Type (Typ)
7289 and then Is_Class_Wide_Type (View)
7291 Root_Typ := Root_Type (Typ);
7292 Root_View := Root_Type (View);
7294 if Root_Typ = Root_View then
7297 -- An incomplete tagged type and its full view may receive two
7298 -- distinct class-wide types when the related package has not
7299 -- been analyzed yet.
7302 -- type T is tagged; -- CW_1
7303 -- type T is tagged null record; -- CW_2
7306 -- This is because the package lacks any semantic information
7307 -- that may eventually link both views of T. As a consequence,
7308 -- a client of the limited view of Pack will see CW_2 while a
7309 -- client of the non-limited view of Pack will see CW_1.
7311 elsif Is_Incomplete_Type (Root_Typ)
7312 and then Present (Full_View (Root_Typ))
7313 and then Full_View (Root_Typ) = Root_View
7317 elsif Is_Incomplete_Type (Root_View)
7318 and then Present (Full_View (Root_View))
7319 and then Full_View (Root_View) = Root_Typ
7326 end Is_Matching_Limited_View;
7328 -- Start of processing for Matches_Limited_With_View
7331 -- In some cases a type imported through a limited_with clause, and
7332 -- its non-limited view are both visible, for example in an anonymous
7333 -- access-to-class-wide type in a formal, or when building the body
7334 -- for a subprogram renaming after the subprogram has been frozen.
7335 -- In these cases both entities designate the same type. In addition,
7336 -- if one of them is an actual in an instance, it may be a subtype of
7337 -- the non-limited view of the other.
7339 if From_Limited_With (Typ_1)
7340 and then From_Limited_With (Typ_2)
7341 and then Available_View (Typ_1) = Available_View (Typ_2)
7345 elsif From_Limited_With (Typ_1) then
7346 return Is_Matching_Limited_View (Typ_2, Available_View (Typ_1));
7348 elsif From_Limited_With (Typ_2) then
7349 return Is_Matching_Limited_View (Typ_1, Available_View (Typ_2));
7354 end Matches_Limited_With_View;
7358 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
7360 Type_1 : Entity_Id := T1;
7361 Type_2 : Entity_Id := T2;
7363 -- Start of processing for Conforming_Types
7366 -- The context is an instance association for a formal access-to-
7367 -- subprogram type; the formal parameter types require mapping because
7368 -- they may denote other formal parameters of the generic unit.
7371 Type_1 := Get_Instance_Of (T1);
7372 Type_2 := Get_Instance_Of (T2);
7375 -- If one of the types is a view of the other introduced by a limited
7376 -- with clause, treat these as conforming for all purposes.
7378 if Matches_Limited_With_View (T1, T2) then
7381 elsif Base_Types_Match (Type_1, Type_2) then
7382 return Ctype <= Mode_Conformant
7383 or else Subtypes_Statically_Match (Type_1, Type_2);
7385 elsif Is_Incomplete_Or_Private_Type (Type_1)
7386 and then Present (Full_View (Type_1))
7387 and then Base_Types_Match (Full_View (Type_1), Type_2)
7389 return Ctype <= Mode_Conformant
7390 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
7392 elsif Ekind (Type_2) = E_Incomplete_Type
7393 and then Present (Full_View (Type_2))
7394 and then Base_Types_Match (Type_1, Full_View (Type_2))
7396 return Ctype <= Mode_Conformant
7397 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
7399 elsif Is_Private_Type (Type_2)
7400 and then In_Instance
7401 and then Present (Full_View (Type_2))
7402 and then Base_Types_Match (Type_1, Full_View (Type_2))
7404 return Ctype <= Mode_Conformant
7405 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
7407 -- Another confusion between views in a nested instance with an
7408 -- actual private type whose full view is not in scope.
7410 elsif Ekind (Type_2) = E_Private_Subtype
7411 and then In_Instance
7412 and then Etype (Type_2) = Type_1
7416 -- In Ada 2012, incomplete types (including limited views) can appear
7417 -- as actuals in instantiations.
7419 elsif Is_Incomplete_Type (Type_1)
7420 and then Is_Incomplete_Type (Type_2)
7421 and then (Used_As_Generic_Actual (Type_1)
7422 or else Used_As_Generic_Actual (Type_2))
7427 -- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be
7428 -- treated recursively because they carry a signature. As far as
7429 -- conformance is concerned, convention plays no role, and either
7430 -- or both could be access to protected subprograms.
7432 Are_Anonymous_Access_To_Subprogram_Types :=
7433 Ekind_In (Type_1, E_Anonymous_Access_Subprogram_Type,
7434 E_Anonymous_Access_Protected_Subprogram_Type)
7436 Ekind_In (Type_2, E_Anonymous_Access_Subprogram_Type,
7437 E_Anonymous_Access_Protected_Subprogram_Type);
7439 -- Test anonymous access type case. For this case, static subtype
7440 -- matching is required for mode conformance (RM 6.3.1(15)). We check
7441 -- the base types because we may have built internal subtype entities
7442 -- to handle null-excluding types (see Process_Formals).
7444 if (Ekind (Base_Type (Type_1)) = E_Anonymous_Access_Type
7446 Ekind (Base_Type (Type_2)) = E_Anonymous_Access_Type)
7448 -- Ada 2005 (AI-254)
7450 or else Are_Anonymous_Access_To_Subprogram_Types
7453 Desig_1 : Entity_Id;
7454 Desig_2 : Entity_Id;
7457 -- In Ada 2005, access constant indicators must match for
7458 -- subtype conformance.
7460 if Ada_Version >= Ada_2005
7461 and then Ctype >= Subtype_Conformant
7463 Is_Access_Constant (Type_1) /= Is_Access_Constant (Type_2)
7468 Desig_1 := Find_Designated_Type (Type_1);
7469 Desig_2 := Find_Designated_Type (Type_2);
7471 -- If the context is an instance association for a formal
7472 -- access-to-subprogram type; formal access parameter designated
7473 -- types require mapping because they may denote other formal
7474 -- parameters of the generic unit.
7477 Desig_1 := Get_Instance_Of (Desig_1);
7478 Desig_2 := Get_Instance_Of (Desig_2);
7481 -- It is possible for a Class_Wide_Type to be introduced for an
7482 -- incomplete type, in which case there is a separate class_ wide
7483 -- type for the full view. The types conform if their Etypes
7484 -- conform, i.e. one may be the full view of the other. This can
7485 -- only happen in the context of an access parameter, other uses
7486 -- of an incomplete Class_Wide_Type are illegal.
7488 if Is_Class_Wide_Type (Desig_1)
7490 Is_Class_Wide_Type (Desig_2)
7494 (Etype (Base_Type (Desig_1)),
7495 Etype (Base_Type (Desig_2)), Ctype);
7497 elsif Are_Anonymous_Access_To_Subprogram_Types then
7498 if Ada_Version < Ada_2005 then
7499 return Ctype = Type_Conformant
7501 Subtypes_Statically_Match (Desig_1, Desig_2);
7503 -- We must check the conformance of the signatures themselves
7507 Conformant : Boolean;
7510 (Desig_1, Desig_2, Ctype, False, Conformant);
7515 -- A limited view of an actual matches the corresponding
7516 -- incomplete formal.
7518 elsif Ekind (Desig_2) = E_Incomplete_Subtype
7519 and then From_Limited_With (Desig_2)
7520 and then Used_As_Generic_Actual (Etype (Desig_2))
7525 return Base_Type (Desig_1) = Base_Type (Desig_2)
7526 and then (Ctype = Type_Conformant
7528 Subtypes_Statically_Match (Desig_1, Desig_2));
7532 -- Otherwise definitely no match
7535 if ((Ekind (Type_1) = E_Anonymous_Access_Type
7536 and then Is_Access_Type (Type_2))
7537 or else (Ekind (Type_2) = E_Anonymous_Access_Type
7538 and then Is_Access_Type (Type_1)))
7541 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
7543 May_Hide_Profile := True;
7548 end Conforming_Types;
7550 --------------------------
7551 -- Create_Extra_Formals --
7552 --------------------------
7554 procedure Create_Extra_Formals (E : Entity_Id) is
7555 First_Extra : Entity_Id := Empty;
7557 Last_Extra : Entity_Id := Empty;
7559 function Add_Extra_Formal
7560 (Assoc_Entity : Entity_Id;
7563 Suffix : String) return Entity_Id;
7564 -- Add an extra formal to the current list of formals and extra formals.
7565 -- The extra formal is added to the end of the list of extra formals,
7566 -- and also returned as the result. These formals are always of mode IN.
7567 -- The new formal has the type Typ, is declared in Scope, and its name
7568 -- is given by a concatenation of the name of Assoc_Entity and Suffix.
7569 -- The following suffixes are currently used. They should not be changed
7570 -- without coordinating with CodePeer, which makes use of these to
7571 -- provide better messages.
7573 -- O denotes the Constrained bit.
7574 -- L denotes the accessibility level.
7575 -- BIP_xxx denotes an extra formal for a build-in-place function. See
7576 -- the full list in exp_ch6.BIP_Formal_Kind.
7578 ----------------------
7579 -- Add_Extra_Formal --
7580 ----------------------
7582 function Add_Extra_Formal
7583 (Assoc_Entity : Entity_Id;
7586 Suffix : String) return Entity_Id
7588 EF : constant Entity_Id :=
7589 Make_Defining_Identifier (Sloc (Assoc_Entity),
7590 Chars => New_External_Name (Chars (Assoc_Entity),
7594 -- A little optimization. Never generate an extra formal for the
7595 -- _init operand of an initialization procedure, since it could
7598 if Chars (Formal) = Name_uInit then
7602 Set_Ekind (EF, E_In_Parameter);
7603 Set_Actual_Subtype (EF, Typ);
7604 Set_Etype (EF, Typ);
7605 Set_Scope (EF, Scope);
7606 Set_Mechanism (EF, Default_Mechanism);
7607 Set_Formal_Validity (EF);
7609 if No (First_Extra) then
7611 Set_Extra_Formals (Scope, First_Extra);
7614 if Present (Last_Extra) then
7615 Set_Extra_Formal (Last_Extra, EF);
7621 end Add_Extra_Formal;
7625 Formal_Type : Entity_Id;
7626 P_Formal : Entity_Id := Empty;
7628 -- Start of processing for Create_Extra_Formals
7631 -- We never generate extra formals if expansion is not active because we
7632 -- don't need them unless we are generating code.
7634 if not Expander_Active then
7638 -- No need to generate extra formals in interface thunks whose target
7639 -- primitive has no extra formals.
7641 if Is_Thunk (E) and then No (Extra_Formals (Thunk_Entity (E))) then
7645 -- If this is a derived subprogram then the subtypes of the parent
7646 -- subprogram's formal parameters will be used to determine the need
7647 -- for extra formals.
7649 if Is_Overloadable (E) and then Present (Alias (E)) then
7650 P_Formal := First_Formal (Alias (E));
7653 Formal := First_Formal (E);
7654 while Present (Formal) loop
7655 Last_Extra := Formal;
7656 Next_Formal (Formal);
7659 -- If Extra_Formals were already created, don't do it again. This
7660 -- situation may arise for subprogram types created as part of
7661 -- dispatching calls (see Expand_Dispatching_Call)
7663 if Present (Last_Extra) and then Present (Extra_Formal (Last_Extra)) then
7667 -- If the subprogram is a predefined dispatching subprogram then don't
7668 -- generate any extra constrained or accessibility level formals. In
7669 -- general we suppress these for internal subprograms (by not calling
7670 -- Freeze_Subprogram and Create_Extra_Formals at all), but internally
7671 -- generated stream attributes do get passed through because extra
7672 -- build-in-place formals are needed in some cases (limited 'Input
).
7674 if Is_Predefined_Internal_Operation
(E
) then
7675 goto Test_For_Func_Result_Extras
;
7678 Formal
:= First_Formal
(E
);
7679 while Present
(Formal
) loop
7681 -- Create extra formal for supporting the attribute 'Constrained.
7682 -- The case of a private type view without discriminants also
7683 -- requires the extra formal if the underlying type has defaulted
7686 if Ekind
(Formal
) /= E_In_Parameter
then
7687 if Present
(P_Formal
) then
7688 Formal_Type
:= Etype
(P_Formal
);
7690 Formal_Type
:= Etype
(Formal
);
7693 -- Do not produce extra formals for Unchecked_Union parameters.
7694 -- Jump directly to the end of the loop.
7696 if Is_Unchecked_Union
(Base_Type
(Formal_Type
)) then
7697 goto Skip_Extra_Formal_Generation
;
7700 if not Has_Discriminants
(Formal_Type
)
7701 and then Ekind
(Formal_Type
) in Private_Kind
7702 and then Present
(Underlying_Type
(Formal_Type
))
7704 Formal_Type
:= Underlying_Type
(Formal_Type
);
7707 -- Suppress the extra formal if formal's subtype is constrained or
7708 -- indefinite, or we're compiling for Ada 2012 and the underlying
7709 -- type is tagged and limited. In Ada 2012, a limited tagged type
7710 -- can have defaulted discriminants, but 'Constrained is required
7711 -- to return True, so the formal is never needed (see AI05-0214).
7712 -- Note that this ensures consistency of calling sequences for
7713 -- dispatching operations when some types in a class have defaults
7714 -- on discriminants and others do not (and requiring the extra
7715 -- formal would introduce distributed overhead).
7717 -- If the type does not have a completion yet, treat as prior to
7718 -- Ada 2012 for consistency.
7720 if Has_Discriminants
(Formal_Type
)
7721 and then not Is_Constrained
(Formal_Type
)
7722 and then Is_Definite_Subtype
(Formal_Type
)
7723 and then (Ada_Version
< Ada_2012
7724 or else No
(Underlying_Type
(Formal_Type
))
7726 (Is_Limited_Type
(Formal_Type
)
7729 (Underlying_Type
(Formal_Type
)))))
7731 Set_Extra_Constrained
7732 (Formal
, Add_Extra_Formal
(Formal
, Standard_Boolean
, E
, "O"));
7736 -- Create extra formal for supporting accessibility checking. This
7737 -- is done for both anonymous access formals and formals of named
7738 -- access types that are marked as controlling formals. The latter
7739 -- case can occur when Expand_Dispatching_Call creates a subprogram
7740 -- type and substitutes the types of access-to-class-wide actuals
7741 -- for the anonymous access-to-specific-type of controlling formals.
7742 -- Base_Type is applied because in cases where there is a null
7743 -- exclusion the formal may have an access subtype.
7745 -- This is suppressed if we specifically suppress accessibility
7746 -- checks at the package level for either the subprogram, or the
7747 -- package in which it resides. However, we do not suppress it
7748 -- simply if the scope has accessibility checks suppressed, since
7749 -- this could cause trouble when clients are compiled with a
7750 -- different suppression setting. The explicit checks at the
7751 -- package level are safe from this point of view.
7753 if (Ekind
(Base_Type
(Etype
(Formal
))) = E_Anonymous_Access_Type
7754 or else (Is_Controlling_Formal
(Formal
)
7755 and then Is_Access_Type
(Base_Type
(Etype
(Formal
)))))
7757 (Explicit_Suppress
(E
, Accessibility_Check
)
7759 Explicit_Suppress
(Scope
(E
), Accessibility_Check
))
7762 or else Present
(Extra_Accessibility
(P_Formal
)))
7764 Set_Extra_Accessibility
7765 (Formal
, Add_Extra_Formal
(Formal
, Standard_Natural
, E
, "L"));
7768 -- This label is required when skipping extra formal generation for
7769 -- Unchecked_Union parameters.
7771 <<Skip_Extra_Formal_Generation
>>
7773 if Present
(P_Formal
) then
7774 Next_Formal
(P_Formal
);
7777 Next_Formal
(Formal
);
7780 <<Test_For_Func_Result_Extras
>>
7782 -- Ada 2012 (AI05-234): "the accessibility level of the result of a
7783 -- function call is ... determined by the point of call ...".
7785 if Needs_Result_Accessibility_Level
(E
) then
7786 Set_Extra_Accessibility_Of_Result
7787 (E
, Add_Extra_Formal
(E
, Standard_Natural
, E
, "L"));
7790 -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add
7791 -- appropriate extra formals. See type Exp_Ch6.BIP_Formal_Kind.
7793 if Ada_Version
>= Ada_2005
and then Is_Build_In_Place_Function
(E
) then
7795 Result_Subt
: constant Entity_Id
:= Etype
(E
);
7796 Full_Subt
: constant Entity_Id
:= Available_View
(Result_Subt
);
7797 Formal_Typ
: Entity_Id
;
7798 Subp_Decl
: Node_Id
;
7800 Discard
: Entity_Id
;
7801 pragma Warnings
(Off
, Discard
);
7804 -- In the case of functions with unconstrained result subtypes,
7805 -- add a 4-state formal indicating whether the return object is
7806 -- allocated by the caller (1), or should be allocated by the
7807 -- callee on the secondary stack (2), in the global heap (3), or
7808 -- in a user-defined storage pool (4). For the moment we just use
7809 -- Natural for the type of this formal. Note that this formal
7810 -- isn't usually needed in the case where the result subtype is
7811 -- constrained, but it is needed when the function has a tagged
7812 -- result, because generally such functions can be called in a
7813 -- dispatching context and such calls must be handled like calls
7814 -- to a class-wide function.
7816 if Needs_BIP_Alloc_Form
(E
) then
7819 (E
, Standard_Natural
,
7820 E
, BIP_Formal_Suffix
(BIP_Alloc_Form
));
7822 -- Add BIP_Storage_Pool, in case BIP_Alloc_Form indicates to
7823 -- use a user-defined pool. This formal is not added on
7824 -- ZFP as those targets do not support pools.
7826 if RTE_Available
(RE_Root_Storage_Pool_Ptr
) then
7829 (E
, RTE
(RE_Root_Storage_Pool_Ptr
),
7830 E
, BIP_Formal_Suffix
(BIP_Storage_Pool
));
7834 -- In the case of functions whose result type needs finalization,
7835 -- add an extra formal which represents the finalization master.
7837 if Needs_BIP_Finalization_Master
(E
) then
7840 (E
, RTE
(RE_Finalization_Master_Ptr
),
7841 E
, BIP_Formal_Suffix
(BIP_Finalization_Master
));
7844 -- When the result type contains tasks, add two extra formals: the
7845 -- master of the tasks to be created, and the caller's activation
7848 if Has_Task
(Full_Subt
) then
7851 (E
, RTE
(RE_Master_Id
),
7852 E
, BIP_Formal_Suffix
(BIP_Task_Master
));
7855 (E
, RTE
(RE_Activation_Chain_Access
),
7856 E
, BIP_Formal_Suffix
(BIP_Activation_Chain
));
7859 -- All build-in-place functions get an extra formal that will be
7860 -- passed the address of the return object within the caller.
7863 Create_Itype
(E_Anonymous_Access_Type
, E
, Scope_Id
=> Scope
(E
));
7865 Set_Directly_Designated_Type
(Formal_Typ
, Result_Subt
);
7866 Set_Etype
(Formal_Typ
, Formal_Typ
);
7867 Set_Depends_On_Private
7868 (Formal_Typ
, Has_Private_Component
(Formal_Typ
));
7869 Set_Is_Public
(Formal_Typ
, Is_Public
(Scope
(Formal_Typ
)));
7870 Set_Is_Access_Constant
(Formal_Typ
, False);
7872 -- Ada 2005 (AI-50217): Propagate the attribute that indicates
7873 -- the designated type comes from the limited view (for back-end
7876 Set_From_Limited_With
7877 (Formal_Typ
, From_Limited_With
(Result_Subt
));
7879 Layout_Type
(Formal_Typ
);
7881 -- Force the definition of the Itype in case of internal function
7882 -- calls within the same or nested scope.
7884 if Is_Subprogram_Or_Generic_Subprogram
(E
) then
7885 Subp_Decl
:= Parent
(E
);
7887 -- The insertion point for an Itype reference should be after
7888 -- the unit declaration node of the subprogram. An exception
7889 -- to this are inherited operations from a parent type in which
7890 -- case the derived type acts as their parent.
7892 if Nkind_In
(Subp_Decl
, N_Function_Specification
,
7893 N_Procedure_Specification
)
7895 Subp_Decl
:= Parent
(Subp_Decl
);
7898 Build_Itype_Reference
(Formal_Typ
, Subp_Decl
);
7903 (E
, Formal_Typ
, E
, BIP_Formal_Suffix
(BIP_Object_Access
));
7906 end Create_Extra_Formals
;
7908 -----------------------------
7909 -- Enter_Overloaded_Entity --
7910 -----------------------------
7912 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
7913 function Matches_Predefined_Op
return Boolean;
7914 -- This returns an approximation of whether S matches a predefined
7915 -- operator, based on the operator symbol, and the parameter and result
7916 -- types. The rules are scattered throughout chapter 4 of the Ada RM.
7918 ---------------------------
7919 -- Matches_Predefined_Op --
7920 ---------------------------
7922 function Matches_Predefined_Op
return Boolean is
7923 Formal_1
: constant Entity_Id
:= First_Formal
(S
);
7924 Formal_2
: constant Entity_Id
:= Next_Formal
(Formal_1
);
7925 Op
: constant Name_Id
:= Chars
(S
);
7926 Result_Type
: constant Entity_Id
:= Base_Type
(Etype
(S
));
7927 Type_1
: constant Entity_Id
:= Base_Type
(Etype
(Formal_1
));
7932 if Present
(Formal_2
) then
7934 Type_2
: constant Entity_Id
:= Base_Type
(Etype
(Formal_2
));
7937 -- All but "&" and "**" have same-types parameters
7946 if Type_1
/= Type_2
then
7951 -- Check parameter and result types
7959 Is_Boolean_Type
(Result_Type
)
7960 and then Result_Type
= Type_1
;
7966 Is_Integer_Type
(Result_Type
)
7967 and then Result_Type
= Type_1
;
7975 Is_Numeric_Type
(Result_Type
)
7976 and then Result_Type
= Type_1
;
7982 Is_Boolean_Type
(Result_Type
)
7983 and then not Is_Limited_Type
(Type_1
);
7991 Is_Boolean_Type
(Result_Type
)
7992 and then (Is_Array_Type
(Type_1
)
7993 or else Is_Scalar_Type
(Type_1
));
7995 when Name_Op_Concat
=>
7996 return Is_Array_Type
(Result_Type
);
7998 when Name_Op_Expon
=>
8000 (Is_Integer_Type
(Result_Type
)
8001 or else Is_Floating_Point_Type
(Result_Type
))
8002 and then Result_Type
= Type_1
8003 and then Type_2
= Standard_Integer
;
8006 raise Program_Error
;
8019 Is_Numeric_Type
(Result_Type
)
8020 and then Result_Type
= Type_1
;
8024 Is_Boolean_Type
(Result_Type
)
8025 and then Result_Type
= Type_1
;
8028 raise Program_Error
;
8031 end Matches_Predefined_Op
;
8035 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
8036 C_E
: Entity_Id
:= Current_Entity
(S
);
8038 -- Start of processing for Enter_Overloaded_Entity
8042 Set_Has_Homonym
(E
);
8043 Set_Has_Homonym
(S
);
8046 Set_Is_Immediately_Visible
(S
);
8047 Set_Scope
(S
, Current_Scope
);
8049 -- Chain new entity if front of homonym in current scope, so that
8050 -- homonyms are contiguous.
8052 if Present
(E
) and then E
/= C_E
then
8053 while Homonym
(C_E
) /= E
loop
8054 C_E
:= Homonym
(C_E
);
8057 Set_Homonym
(C_E
, S
);
8061 Set_Current_Entity
(S
);
8066 if Is_Inherited_Operation
(S
) then
8067 Append_Inherited_Subprogram
(S
);
8069 Append_Entity
(S
, Current_Scope
);
8072 Set_Public_Status
(S
);
8074 if Debug_Flag_E
then
8075 Write_Str
("New overloaded entity chain: ");
8076 Write_Name
(Chars
(S
));
8079 while Present
(E
) loop
8080 Write_Str
(" "); Write_Int
(Int
(E
));
8087 -- Generate warning for hiding
8090 and then Comes_From_Source
(S
)
8091 and then In_Extended_Main_Source_Unit
(S
)
8098 -- Warn unless genuine overloading. Do not emit warning on
8099 -- hiding predefined operators in Standard (these are either an
8100 -- (artifact of our implicit declarations, or simple noise) but
8101 -- keep warning on a operator defined on a local subtype, because
8102 -- of the real danger that different operators may be applied in
8103 -- various parts of the program.
8105 -- Note that if E and S have the same scope, there is never any
8106 -- hiding. Either the two conflict, and the program is illegal,
8107 -- or S is overriding an implicit inherited subprogram.
8109 if Scope
(E
) /= Scope
(S
)
8110 and then (not Is_Overloadable
(E
)
8111 or else Subtype_Conformant
(E
, S
))
8112 and then (Is_Immediately_Visible
(E
)
8113 or else Is_Potentially_Use_Visible
(S
))
8115 if Scope
(E
) = Standard_Standard
then
8116 if Nkind
(S
) = N_Defining_Operator_Symbol
8117 and then Scope
(Base_Type
(Etype
(First_Formal
(S
)))) /=
8119 and then Matches_Predefined_Op
8122 ("declaration of & hides predefined operator?h?", S
);
8125 -- E not immediately within Standard
8128 Error_Msg_Sloc
:= Sloc
(E
);
8129 Error_Msg_N
("declaration of & hides one #?h?", S
);
8134 end Enter_Overloaded_Entity
;
8136 -----------------------------
8137 -- Check_Untagged_Equality --
8138 -----------------------------
8140 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
) is
8141 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Eq_Op
));
8142 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Eq_Op
);
8146 -- This check applies only if we have a subprogram declaration with an
8147 -- untagged record type.
8149 if Nkind
(Decl
) /= N_Subprogram_Declaration
8150 or else not Is_Record_Type
(Typ
)
8151 or else Is_Tagged_Type
(Typ
)
8156 -- In Ada 2012 case, we will output errors or warnings depending on
8157 -- the setting of debug flag -gnatd.E.
8159 if Ada_Version
>= Ada_2012
then
8160 Error_Msg_Warn
:= Debug_Flag_Dot_EE
;
8162 -- In earlier versions of Ada, nothing to do unless we are warning on
8163 -- Ada 2012 incompatibilities (Warn_On_Ada_2012_Incompatibility set).
8166 if not Warn_On_Ada_2012_Compatibility
then
8171 -- Cases where the type has already been frozen
8173 if Is_Frozen
(Typ
) then
8175 -- If the type is not declared in a package, or if we are in the body
8176 -- of the package or in some other scope, the new operation is not
8177 -- primitive, and therefore legal, though suspicious. Should we
8178 -- generate a warning in this case ???
8180 if Ekind
(Scope
(Typ
)) /= E_Package
8181 or else Scope
(Typ
) /= Current_Scope
8185 -- If the type is a generic actual (sub)type, the operation is not
8186 -- primitive either because the base type is declared elsewhere.
8188 elsif Is_Generic_Actual_Type
(Typ
) then
8191 -- Here we have a definite error of declaration after freezing
8194 if Ada_Version
>= Ada_2012
then
8196 ("equality operator must be declared before type & is "
8197 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)<<", Eq_Op
, Typ
);
8199 -- In Ada 2012 mode with error turned to warning, output one
8200 -- more warning to warn that the equality operation may not
8201 -- compose. This is the consequence of ignoring the error.
8203 if Error_Msg_Warn
then
8204 Error_Msg_N
("\equality operation may not compose??", Eq_Op
);
8209 ("equality operator must be declared before type& is "
8210 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)?y?", Eq_Op
, Typ
);
8213 -- If we are in the package body, we could just move the
8214 -- declaration to the package spec, so add a message saying that.
8216 if In_Package_Body
(Scope
(Typ
)) then
8217 if Ada_Version
>= Ada_2012
then
8219 ("\move declaration to package spec<<", Eq_Op
);
8222 ("\move declaration to package spec (Ada 2012)?y?", Eq_Op
);
8225 -- Otherwise try to find the freezing point
8228 Obj_Decl
:= Next
(Parent
(Typ
));
8229 while Present
(Obj_Decl
) and then Obj_Decl
/= Decl
loop
8230 if Nkind
(Obj_Decl
) = N_Object_Declaration
8231 and then Etype
(Defining_Identifier
(Obj_Decl
)) = Typ
8233 -- Freezing point, output warnings
8235 if Ada_Version
>= Ada_2012
then
8237 ("type& is frozen by declaration??", Obj_Decl
, Typ
);
8239 ("\an equality operator cannot be declared after "
8244 ("type& is frozen by declaration (Ada 2012)?y?",
8247 ("\an equality operator cannot be declared after "
8248 & "this point (Ada 2012)?y?",
8260 -- Here if type is not frozen yet. It is illegal to have a primitive
8261 -- equality declared in the private part if the type is visible.
8263 elsif not In_Same_List
(Parent
(Typ
), Decl
)
8264 and then not Is_Limited_Type
(Typ
)
8266 -- Shouldn't we give an RM reference here???
8268 if Ada_Version
>= Ada_2012
then
8270 ("equality operator appears too late<<", Eq_Op
);
8273 ("equality operator appears too late (Ada 2012)?y?", Eq_Op
);
8276 -- No error detected
8281 end Check_Untagged_Equality
;
8283 -----------------------------
8284 -- Find_Corresponding_Spec --
8285 -----------------------------
8287 function Find_Corresponding_Spec
8289 Post_Error
: Boolean := True) return Entity_Id
8291 Spec
: constant Node_Id
:= Specification
(N
);
8292 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
8296 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean;
8297 -- Even if fully conformant, a body may depend on a generic actual when
8298 -- the spec does not, or vice versa, in which case they were distinct
8299 -- entities in the generic.
8301 -------------------------------
8302 -- Different_Generic_Profile --
8303 -------------------------------
8305 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean is
8308 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean;
8309 -- Check that the types of corresponding formals have the same
8310 -- generic actual if any. We have to account for subtypes of a
8311 -- generic formal, declared between a spec and a body, which may
8312 -- appear distinct in an instance but matched in the generic, and
8313 -- the subtype may be used either in the spec or the body of the
8314 -- subprogram being checked.
8316 -------------------------
8317 -- Same_Generic_Actual --
8318 -------------------------
8320 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean is
8322 function Is_Declared_Subtype
(S1
, S2
: Entity_Id
) return Boolean;
8323 -- Predicate to check whether S1 is a subtype of S2 in the source
8326 -------------------------
8327 -- Is_Declared_Subtype --
8328 -------------------------
8330 function Is_Declared_Subtype
(S1
, S2
: Entity_Id
) return Boolean is
8332 return Comes_From_Source
(Parent
(S1
))
8333 and then Nkind
(Parent
(S1
)) = N_Subtype_Declaration
8334 and then Is_Entity_Name
(Subtype_Indication
(Parent
(S1
)))
8335 and then Entity
(Subtype_Indication
(Parent
(S1
))) = S2
;
8336 end Is_Declared_Subtype
;
8338 -- Start of processing for Same_Generic_Actual
8341 return Is_Generic_Actual_Type
(T1
) = Is_Generic_Actual_Type
(T2
)
8342 or else Is_Declared_Subtype
(T1
, T2
)
8343 or else Is_Declared_Subtype
(T2
, T1
);
8344 end Same_Generic_Actual
;
8346 -- Start of processing for Different_Generic_Profile
8349 if not In_Instance
then
8352 elsif Ekind
(E
) = E_Function
8353 and then not Same_Generic_Actual
(Etype
(E
), Etype
(Designator
))
8358 F1
:= First_Formal
(Designator
);
8359 F2
:= First_Formal
(E
);
8360 while Present
(F1
) loop
8361 if not Same_Generic_Actual
(Etype
(F1
), Etype
(F2
)) then
8370 end Different_Generic_Profile
;
8372 -- Start of processing for Find_Corresponding_Spec
8375 E
:= Current_Entity
(Designator
);
8376 while Present
(E
) loop
8378 -- We are looking for a matching spec. It must have the same scope,
8379 -- and the same name, and either be type conformant, or be the case
8380 -- of a library procedure spec and its body (which belong to one
8381 -- another regardless of whether they are type conformant or not).
8383 if Scope
(E
) = Current_Scope
then
8384 if Current_Scope
= Standard_Standard
8385 or else (Ekind
(E
) = Ekind
(Designator
)
8386 and then Type_Conformant
(E
, Designator
))
8388 -- Within an instantiation, we know that spec and body are
8389 -- subtype conformant, because they were subtype conformant in
8390 -- the generic. We choose the subtype-conformant entity here as
8391 -- well, to resolve spurious ambiguities in the instance that
8392 -- were not present in the generic (i.e. when two different
8393 -- types are given the same actual). If we are looking for a
8394 -- spec to match a body, full conformance is expected.
8398 -- Inherit the convention and "ghostness" of the matching
8399 -- spec to ensure proper full and subtype conformance.
8401 Set_Convention
(Designator
, Convention
(E
));
8403 -- Skip past subprogram bodies and subprogram renamings that
8404 -- may appear to have a matching spec, but that aren't fully
8405 -- conformant with it. That can occur in cases where an
8406 -- actual type causes unrelated homographs in the instance.
8408 if Nkind_In
(N
, N_Subprogram_Body
,
8409 N_Subprogram_Renaming_Declaration
)
8410 and then Present
(Homonym
(E
))
8411 and then not Fully_Conformant
(Designator
, E
)
8415 elsif not Subtype_Conformant
(Designator
, E
) then
8418 elsif Different_Generic_Profile
(E
) then
8423 -- Ada 2012 (AI05-0165): For internally generated bodies of
8424 -- null procedures locate the internally generated spec. We
8425 -- enforce mode conformance since a tagged type may inherit
8426 -- from interfaces several null primitives which differ only
8427 -- in the mode of the formals.
8429 if not (Comes_From_Source
(E
))
8430 and then Is_Null_Procedure
(E
)
8431 and then not Mode_Conformant
(Designator
, E
)
8435 -- For null procedures coming from source that are completions,
8436 -- analysis of the generated body will establish the link.
8438 elsif Comes_From_Source
(E
)
8439 and then Nkind
(Spec
) = N_Procedure_Specification
8440 and then Null_Present
(Spec
)
8444 -- Expression functions can be completions, but cannot be
8445 -- completed by an explicit body.
8447 elsif Comes_From_Source
(E
)
8448 and then Comes_From_Source
(N
)
8449 and then Nkind
(N
) = N_Subprogram_Body
8450 and then Nkind
(Original_Node
(Unit_Declaration_Node
(E
))) =
8451 N_Expression_Function
8453 Error_Msg_Sloc
:= Sloc
(E
);
8454 Error_Msg_N
("body conflicts with expression function#", N
);
8457 elsif not Has_Completion
(E
) then
8458 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
8459 Set_Corresponding_Spec
(N
, E
);
8462 Set_Has_Completion
(E
);
8465 elsif Nkind
(Parent
(N
)) = N_Subunit
then
8467 -- If this is the proper body of a subunit, the completion
8468 -- flag is set when analyzing the stub.
8472 -- If E is an internal function with a controlling result that
8473 -- was created for an operation inherited by a null extension,
8474 -- it may be overridden by a body without a previous spec (one
8475 -- more reason why these should be shunned). In that case we
8476 -- remove the generated body if present, because the current
8477 -- one is the explicit overriding.
8479 elsif Ekind
(E
) = E_Function
8480 and then Ada_Version
>= Ada_2005
8481 and then not Comes_From_Source
(E
)
8482 and then Has_Controlling_Result
(E
)
8483 and then Is_Null_Extension
(Etype
(E
))
8484 and then Comes_From_Source
(Spec
)
8486 Set_Has_Completion
(E
, False);
8489 and then Nkind
(Parent
(E
)) = N_Function_Specification
8492 (Unit_Declaration_Node
8493 (Corresponding_Body
(Unit_Declaration_Node
(E
))));
8497 -- If expansion is disabled, or if the wrapper function has
8498 -- not been generated yet, this a late body overriding an
8499 -- inherited operation, or it is an overriding by some other
8500 -- declaration before the controlling result is frozen. In
8501 -- either case this is a declaration of a new entity.
8507 -- If the body already exists, then this is an error unless
8508 -- the previous declaration is the implicit declaration of a
8509 -- derived subprogram. It is also legal for an instance to
8510 -- contain type conformant overloadable declarations (but the
8511 -- generic declaration may not), per 8.3(26/2).
8513 elsif No
(Alias
(E
))
8514 and then not Is_Intrinsic_Subprogram
(E
)
8515 and then not In_Instance
8518 Error_Msg_Sloc
:= Sloc
(E
);
8520 if Is_Imported
(E
) then
8522 ("body not allowed for imported subprogram & declared#",
8525 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
8529 -- Child units cannot be overloaded, so a conformance mismatch
8530 -- between body and a previous spec is an error.
8532 elsif Is_Child_Unit
(E
)
8534 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
8536 Nkind
(Parent
(Unit_Declaration_Node
(Designator
))) =
8541 ("body of child unit does not match previous declaration", N
);
8549 -- On exit, we know that no previous declaration of subprogram exists
8552 end Find_Corresponding_Spec
;
8554 ----------------------
8555 -- Fully_Conformant --
8556 ----------------------
8558 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
8561 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
8563 end Fully_Conformant
;
8565 ----------------------------------
8566 -- Fully_Conformant_Expressions --
8567 ----------------------------------
8569 function Fully_Conformant_Expressions
8570 (Given_E1
: Node_Id
;
8571 Given_E2
: Node_Id
) return Boolean
8573 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
8574 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
8575 -- We always test conformance on original nodes, since it is possible
8576 -- for analysis and/or expansion to make things look as though they
8577 -- conform when they do not, e.g. by converting 1+2 into 3.
8579 function FCE
(Given_E1
, Given_E2
: Node_Id
) return Boolean
8580 renames Fully_Conformant_Expressions
;
8582 function FCL
(L1
, L2
: List_Id
) return Boolean;
8583 -- Compare elements of two lists for conformance. Elements have to be
8584 -- conformant, and actuals inserted as default parameters do not match
8585 -- explicit actuals with the same value.
8587 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean;
8588 -- Compare an operator node with a function call
8594 function FCL
(L1
, L2
: List_Id
) return Boolean is
8598 if L1
= No_List
then
8604 if L2
= No_List
then
8610 -- Compare two lists, skipping rewrite insertions (we want to compare
8611 -- the original trees, not the expanded versions).
8614 if Is_Rewrite_Insertion
(N1
) then
8616 elsif Is_Rewrite_Insertion
(N2
) then
8622 elsif not FCE
(N1
, N2
) then
8635 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean is
8636 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
8641 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
8646 Act
:= First
(Actuals
);
8648 if Nkind
(Op_Node
) in N_Binary_Op
then
8649 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
8656 return Present
(Act
)
8657 and then FCE
(Right_Opnd
(Op_Node
), Act
)
8658 and then No
(Next
(Act
));
8662 -- Start of processing for Fully_Conformant_Expressions
8665 -- Nonconformant if paren count does not match. Note: if some idiot
8666 -- complains that we don't do this right for more than 3 levels of
8667 -- parentheses, they will be treated with the respect they deserve.
8669 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
8672 -- If same entities are referenced, then they are conformant even if
8673 -- they have different forms (RM 8.3.1(19-20)).
8675 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
8676 if Present
(Entity
(E1
)) then
8677 return Entity
(E1
) = Entity
(E2
)
8679 -- One may be a discriminant that has been replaced by
8680 -- the corresponding discriminal.
8682 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
8683 and then Ekind
(Entity
(E1
)) = E_Discriminant
8684 and then Ekind
(Entity
(E2
)) = E_In_Parameter
)
8686 -- AI12-050: The loop variables of quantified expressions
8687 -- match if they have the same identifier, even though they
8688 -- are different entities.
8690 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
8691 and then Ekind
(Entity
(E1
)) = E_Loop_Parameter
8692 and then Ekind
(Entity
(E2
)) = E_Loop_Parameter
);
8694 elsif Nkind
(E1
) = N_Expanded_Name
8695 and then Nkind
(E2
) = N_Expanded_Name
8696 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
8697 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
8699 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
8702 -- Identifiers in component associations don't always have
8703 -- entities, but their names must conform.
8705 return Nkind
(E1
) = N_Identifier
8706 and then Nkind
(E2
) = N_Identifier
8707 and then Chars
(E1
) = Chars
(E2
);
8710 elsif Nkind
(E1
) = N_Character_Literal
8711 and then Nkind
(E2
) = N_Expanded_Name
8713 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
8714 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
8716 elsif Nkind
(E2
) = N_Character_Literal
8717 and then Nkind
(E1
) = N_Expanded_Name
8719 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
8720 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
8722 elsif Nkind
(E1
) in N_Op
and then Nkind
(E2
) = N_Function_Call
then
8723 return FCO
(E1
, E2
);
8725 elsif Nkind
(E2
) in N_Op
and then Nkind
(E1
) = N_Function_Call
then
8726 return FCO
(E2
, E1
);
8728 -- Otherwise we must have the same syntactic entity
8730 elsif Nkind
(E1
) /= Nkind
(E2
) then
8733 -- At this point, we specialize by node type
8739 FCL
(Expressions
(E1
), Expressions
(E2
))
8741 FCL
(Component_Associations
(E1
),
8742 Component_Associations
(E2
));
8745 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
8747 Nkind
(Expression
(E2
)) = N_Qualified_Expression
8749 return FCE
(Expression
(E1
), Expression
(E2
));
8751 -- Check that the subtype marks and any constraints
8756 Indic1
: constant Node_Id
:= Expression
(E1
);
8757 Indic2
: constant Node_Id
:= Expression
(E2
);
8762 if Nkind
(Indic1
) /= N_Subtype_Indication
then
8764 Nkind
(Indic2
) /= N_Subtype_Indication
8765 and then Entity
(Indic1
) = Entity
(Indic2
);
8767 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
8769 Nkind
(Indic1
) /= N_Subtype_Indication
8770 and then Entity
(Indic1
) = Entity
(Indic2
);
8773 if Entity
(Subtype_Mark
(Indic1
)) /=
8774 Entity
(Subtype_Mark
(Indic2
))
8779 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
8780 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
8781 while Present
(Elt1
) and then Present
(Elt2
) loop
8782 if not FCE
(Elt1
, Elt2
) then
8795 when N_Attribute_Reference
=>
8797 Attribute_Name
(E1
) = Attribute_Name
(E2
)
8798 and then FCL
(Expressions
(E1
), Expressions
(E2
));
8802 Entity
(E1
) = Entity
(E2
)
8803 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
8804 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
8806 when N_Membership_Test
8810 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
8812 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
8814 when N_Case_Expression
=>
8820 if not FCE
(Expression
(E1
), Expression
(E2
)) then
8824 Alt1
:= First
(Alternatives
(E1
));
8825 Alt2
:= First
(Alternatives
(E2
));
8827 if Present
(Alt1
) /= Present
(Alt2
) then
8829 elsif No
(Alt1
) then
8833 if not FCE
(Expression
(Alt1
), Expression
(Alt2
))
8834 or else not FCL
(Discrete_Choices
(Alt1
),
8835 Discrete_Choices
(Alt2
))
8846 when N_Character_Literal
=>
8848 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
8850 when N_Component_Association
=>
8852 FCL
(Choices
(E1
), Choices
(E2
))
8854 FCE
(Expression
(E1
), Expression
(E2
));
8856 when N_Explicit_Dereference
=>
8858 FCE
(Prefix
(E1
), Prefix
(E2
));
8860 when N_Extension_Aggregate
=>
8862 FCL
(Expressions
(E1
), Expressions
(E2
))
8863 and then Null_Record_Present
(E1
) =
8864 Null_Record_Present
(E2
)
8865 and then FCL
(Component_Associations
(E1
),
8866 Component_Associations
(E2
));
8868 when N_Function_Call
=>
8870 FCE
(Name
(E1
), Name
(E2
))
8872 FCL
(Parameter_Associations
(E1
),
8873 Parameter_Associations
(E2
));
8875 when N_If_Expression
=>
8877 FCL
(Expressions
(E1
), Expressions
(E2
));
8879 when N_Indexed_Component
=>
8881 FCE
(Prefix
(E1
), Prefix
(E2
))
8883 FCL
(Expressions
(E1
), Expressions
(E2
));
8885 when N_Integer_Literal
=>
8886 return (Intval
(E1
) = Intval
(E2
));
8891 when N_Operator_Symbol
=>
8893 Chars
(E1
) = Chars
(E2
);
8895 when N_Others_Choice
=>
8898 when N_Parameter_Association
=>
8900 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
8901 and then FCE
(Explicit_Actual_Parameter
(E1
),
8902 Explicit_Actual_Parameter
(E2
));
8904 when N_Qualified_Expression
=>
8906 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
8908 FCE
(Expression
(E1
), Expression
(E2
));
8910 when N_Quantified_Expression
=>
8911 if not FCE
(Condition
(E1
), Condition
(E2
)) then
8915 if Present
(Loop_Parameter_Specification
(E1
))
8916 and then Present
(Loop_Parameter_Specification
(E2
))
8919 L1
: constant Node_Id
:=
8920 Loop_Parameter_Specification
(E1
);
8921 L2
: constant Node_Id
:=
8922 Loop_Parameter_Specification
(E2
);
8926 Reverse_Present
(L1
) = Reverse_Present
(L2
)
8928 FCE
(Defining_Identifier
(L1
),
8929 Defining_Identifier
(L2
))
8931 FCE
(Discrete_Subtype_Definition
(L1
),
8932 Discrete_Subtype_Definition
(L2
));
8935 elsif Present
(Iterator_Specification
(E1
))
8936 and then Present
(Iterator_Specification
(E2
))
8939 I1
: constant Node_Id
:= Iterator_Specification
(E1
);
8940 I2
: constant Node_Id
:= Iterator_Specification
(E2
);
8944 FCE
(Defining_Identifier
(I1
),
8945 Defining_Identifier
(I2
))
8947 Of_Present
(I1
) = Of_Present
(I2
)
8949 Reverse_Present
(I1
) = Reverse_Present
(I2
)
8950 and then FCE
(Name
(I1
), Name
(I2
))
8951 and then FCE
(Subtype_Indication
(I1
),
8952 Subtype_Indication
(I2
));
8955 -- The quantified expressions used different specifications to
8956 -- walk their respective ranges.
8964 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
8966 FCE
(High_Bound
(E1
), High_Bound
(E2
));
8968 when N_Real_Literal
=>
8969 return (Realval
(E1
) = Realval
(E2
));
8971 when N_Selected_Component
=>
8973 FCE
(Prefix
(E1
), Prefix
(E2
))
8975 FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
8979 FCE
(Prefix
(E1
), Prefix
(E2
))
8981 FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
8983 when N_String_Literal
=>
8985 S1
: constant String_Id
:= Strval
(E1
);
8986 S2
: constant String_Id
:= Strval
(E2
);
8987 L1
: constant Nat
:= String_Length
(S1
);
8988 L2
: constant Nat
:= String_Length
(S2
);
8995 for J
in 1 .. L1
loop
8996 if Get_String_Char
(S1
, J
) /=
8997 Get_String_Char
(S2
, J
)
9007 when N_Type_Conversion
=>
9009 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
9011 FCE
(Expression
(E1
), Expression
(E2
));
9015 Entity
(E1
) = Entity
(E2
)
9017 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
9019 when N_Unchecked_Type_Conversion
=>
9021 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
9023 FCE
(Expression
(E1
), Expression
(E2
));
9025 -- All other node types cannot appear in this context. Strictly
9026 -- we should raise a fatal internal error. Instead we just ignore
9027 -- the nodes. This means that if anyone makes a mistake in the
9028 -- expander and mucks an expression tree irretrievably, the result
9029 -- will be a failure to detect a (probably very obscure) case
9030 -- of non-conformance, which is better than bombing on some
9031 -- case where two expressions do in fact conform.
9037 end Fully_Conformant_Expressions
;
9039 ----------------------------------------
9040 -- Fully_Conformant_Discrete_Subtypes --
9041 ----------------------------------------
9043 function Fully_Conformant_Discrete_Subtypes
9044 (Given_S1
: Node_Id
;
9045 Given_S2
: Node_Id
) return Boolean
9047 S1
: constant Node_Id
:= Original_Node
(Given_S1
);
9048 S2
: constant Node_Id
:= Original_Node
(Given_S2
);
9050 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean;
9051 -- Special-case for a bound given by a discriminant, which in the body
9052 -- is replaced with the discriminal of the enclosing type.
9054 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean;
9055 -- Check both bounds
9057 -----------------------
9058 -- Conforming_Bounds --
9059 -----------------------
9061 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean is
9063 if Is_Entity_Name
(B1
)
9064 and then Is_Entity_Name
(B2
)
9065 and then Ekind
(Entity
(B1
)) = E_Discriminant
9067 return Chars
(B1
) = Chars
(B2
);
9070 return Fully_Conformant_Expressions
(B1
, B2
);
9072 end Conforming_Bounds
;
9074 -----------------------
9075 -- Conforming_Ranges --
9076 -----------------------
9078 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean is
9081 Conforming_Bounds
(Low_Bound
(R1
), Low_Bound
(R2
))
9083 Conforming_Bounds
(High_Bound
(R1
), High_Bound
(R2
));
9084 end Conforming_Ranges
;
9086 -- Start of processing for Fully_Conformant_Discrete_Subtypes
9089 if Nkind
(S1
) /= Nkind
(S2
) then
9092 elsif Is_Entity_Name
(S1
) then
9093 return Entity
(S1
) = Entity
(S2
);
9095 elsif Nkind
(S1
) = N_Range
then
9096 return Conforming_Ranges
(S1
, S2
);
9098 elsif Nkind
(S1
) = N_Subtype_Indication
then
9100 Entity
(Subtype_Mark
(S1
)) = Entity
(Subtype_Mark
(S2
))
9103 (Range_Expression
(Constraint
(S1
)),
9104 Range_Expression
(Constraint
(S2
)));
9108 end Fully_Conformant_Discrete_Subtypes
;
9110 --------------------
9111 -- Install_Entity --
9112 --------------------
9114 procedure Install_Entity
(E
: Entity_Id
) is
9115 Prev
: constant Entity_Id
:= Current_Entity
(E
);
9117 Set_Is_Immediately_Visible
(E
);
9118 Set_Current_Entity
(E
);
9119 Set_Homonym
(E
, Prev
);
9122 ---------------------
9123 -- Install_Formals --
9124 ---------------------
9126 procedure Install_Formals
(Id
: Entity_Id
) is
9129 F
:= First_Formal
(Id
);
9130 while Present
(F
) loop
9134 end Install_Formals
;
9136 -----------------------------
9137 -- Is_Interface_Conformant --
9138 -----------------------------
9140 function Is_Interface_Conformant
9141 (Tagged_Type
: Entity_Id
;
9142 Iface_Prim
: Entity_Id
;
9143 Prim
: Entity_Id
) return Boolean
9145 -- The operation may in fact be an inherited (implicit) operation
9146 -- rather than the original interface primitive, so retrieve the
9147 -- ultimate ancestor.
9149 Iface
: constant Entity_Id
:=
9150 Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
));
9151 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Prim
);
9153 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
;
9154 -- Return the controlling formal of Prim
9156 ------------------------
9157 -- Controlling_Formal --
9158 ------------------------
9160 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
is
9164 E
:= First_Entity
(Prim
);
9165 while Present
(E
) loop
9166 if Is_Formal
(E
) and then Is_Controlling_Formal
(E
) then
9174 end Controlling_Formal
;
9178 Iface_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Iface_Prim
);
9179 Prim_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Prim
);
9181 -- Start of processing for Is_Interface_Conformant
9184 pragma Assert
(Is_Subprogram
(Iface_Prim
)
9185 and then Is_Subprogram
(Prim
)
9186 and then Is_Dispatching_Operation
(Iface_Prim
)
9187 and then Is_Dispatching_Operation
(Prim
));
9189 pragma Assert
(Is_Interface
(Iface
)
9190 or else (Present
(Alias
(Iface_Prim
))
9193 (Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
)))));
9195 if Prim
= Iface_Prim
9196 or else not Is_Subprogram
(Prim
)
9197 or else Ekind
(Prim
) /= Ekind
(Iface_Prim
)
9198 or else not Is_Dispatching_Operation
(Prim
)
9199 or else Scope
(Prim
) /= Scope
(Tagged_Type
)
9201 or else Base_Type
(Typ
) /= Base_Type
(Tagged_Type
)
9202 or else not Primitive_Names_Match
(Iface_Prim
, Prim
)
9206 -- The mode of the controlling formals must match
9208 elsif Present
(Iface_Ctrl_F
)
9209 and then Present
(Prim_Ctrl_F
)
9210 and then Ekind
(Iface_Ctrl_F
) /= Ekind
(Prim_Ctrl_F
)
9214 -- Case of a procedure, or a function whose result type matches the
9215 -- result type of the interface primitive, or a function that has no
9216 -- controlling result (I or access I).
9218 elsif Ekind
(Iface_Prim
) = E_Procedure
9219 or else Etype
(Prim
) = Etype
(Iface_Prim
)
9220 or else not Has_Controlling_Result
(Prim
)
9222 return Type_Conformant
9223 (Iface_Prim
, Prim
, Skip_Controlling_Formals
=> True);
9225 -- Case of a function returning an interface, or an access to one. Check
9226 -- that the return types correspond.
9228 elsif Implements_Interface
(Typ
, Iface
) then
9229 if (Ekind
(Etype
(Prim
)) = E_Anonymous_Access_Type
)
9231 (Ekind
(Etype
(Iface_Prim
)) = E_Anonymous_Access_Type
)
9236 Type_Conformant
(Prim
, Ultimate_Alias
(Iface_Prim
),
9237 Skip_Controlling_Formals
=> True);
9243 end Is_Interface_Conformant
;
9245 ---------------------------------
9246 -- Is_Non_Overriding_Operation --
9247 ---------------------------------
9249 function Is_Non_Overriding_Operation
9250 (Prev_E
: Entity_Id
;
9251 New_E
: Entity_Id
) return Boolean
9255 G_Typ
: Entity_Id
:= Empty
;
9257 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
9258 -- If F_Type is a derived type associated with a generic actual subtype,
9259 -- then return its Generic_Parent_Type attribute, else return Empty.
9261 function Types_Correspond
9262 (P_Type
: Entity_Id
;
9263 N_Type
: Entity_Id
) return Boolean;
9264 -- Returns true if and only if the types (or designated types in the
9265 -- case of anonymous access types) are the same or N_Type is derived
9266 -- directly or indirectly from P_Type.
9268 -----------------------------
9269 -- Get_Generic_Parent_Type --
9270 -----------------------------
9272 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
9278 if Is_Derived_Type
(F_Typ
)
9279 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
9281 -- The tree must be traversed to determine the parent subtype in
9282 -- the generic unit, which unfortunately isn't always available
9283 -- via semantic attributes. ??? (Note: The use of Original_Node
9284 -- is needed for cases where a full derived type has been
9287 -- If the parent type is a scalar type, the derivation creates
9288 -- an anonymous base type for it, and the source type is its
9291 if Is_Scalar_Type
(F_Typ
)
9292 and then not Comes_From_Source
(F_Typ
)
9296 (Original_Node
(Parent
(First_Subtype
(F_Typ
))));
9298 Defn
:= Type_Definition
(Original_Node
(Parent
(F_Typ
)));
9300 if Nkind
(Defn
) = N_Derived_Type_Definition
then
9301 Indic
:= Subtype_Indication
(Defn
);
9303 if Nkind
(Indic
) = N_Subtype_Indication
then
9304 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
9306 G_Typ
:= Entity
(Indic
);
9309 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
9310 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
9312 return Generic_Parent_Type
(Parent
(G_Typ
));
9318 end Get_Generic_Parent_Type
;
9320 ----------------------
9321 -- Types_Correspond --
9322 ----------------------
9324 function Types_Correspond
9325 (P_Type
: Entity_Id
;
9326 N_Type
: Entity_Id
) return Boolean
9328 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
9329 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
9332 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
9333 Prev_Type
:= Designated_Type
(Prev_Type
);
9336 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
9337 New_Type
:= Designated_Type
(New_Type
);
9340 if Prev_Type
= New_Type
then
9343 elsif not Is_Class_Wide_Type
(New_Type
) then
9344 while Etype
(New_Type
) /= New_Type
loop
9345 New_Type
:= Etype
(New_Type
);
9347 if New_Type
= Prev_Type
then
9353 end Types_Correspond
;
9355 -- Start of processing for Is_Non_Overriding_Operation
9358 -- In the case where both operations are implicit derived subprograms
9359 -- then neither overrides the other. This can only occur in certain
9360 -- obscure cases (e.g., derivation from homographs created in a generic
9363 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
9366 elsif Ekind
(Current_Scope
) = E_Package
9367 and then Is_Generic_Instance
(Current_Scope
)
9368 and then In_Private_Part
(Current_Scope
)
9369 and then Comes_From_Source
(New_E
)
9371 -- We examine the formals and result type of the inherited operation,
9372 -- to determine whether their type is derived from (the instance of)
9373 -- a generic type. The first such formal or result type is the one
9376 Formal
:= First_Formal
(Prev_E
);
9378 while Present
(Formal
) loop
9379 F_Typ
:= Base_Type
(Etype
(Formal
));
9381 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
9382 F_Typ
:= Designated_Type
(F_Typ
);
9385 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
9386 exit when Present
(G_Typ
);
9388 Next_Formal
(Formal
);
9391 -- If the function dispatches on result check the result type
9393 if No
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
9394 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
9401 -- If the generic type is a private type, then the original operation
9402 -- was not overriding in the generic, because there was no primitive
9403 -- operation to override.
9405 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
9406 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
9407 N_Formal_Private_Type_Definition
9411 -- The generic parent type is the ancestor of a formal derived
9412 -- type declaration. We need to check whether it has a primitive
9413 -- operation that should be overridden by New_E in the generic.
9417 P_Formal
: Entity_Id
;
9418 N_Formal
: Entity_Id
;
9422 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
9425 while Present
(Prim_Elt
) loop
9426 P_Prim
:= Node
(Prim_Elt
);
9428 if Chars
(P_Prim
) = Chars
(New_E
)
9429 and then Ekind
(P_Prim
) = Ekind
(New_E
)
9431 P_Formal
:= First_Formal
(P_Prim
);
9432 N_Formal
:= First_Formal
(New_E
);
9433 while Present
(P_Formal
) and then Present
(N_Formal
) loop
9434 P_Typ
:= Etype
(P_Formal
);
9435 N_Typ
:= Etype
(N_Formal
);
9437 if not Types_Correspond
(P_Typ
, N_Typ
) then
9441 Next_Entity
(P_Formal
);
9442 Next_Entity
(N_Formal
);
9445 -- Found a matching primitive operation belonging to the
9446 -- formal ancestor type, so the new subprogram is
9450 and then No
(N_Formal
)
9451 and then (Ekind
(New_E
) /= E_Function
9454 (Etype
(P_Prim
), Etype
(New_E
)))
9460 Next_Elmt
(Prim_Elt
);
9463 -- If no match found, then the new subprogram does not override
9464 -- in the generic (nor in the instance).
9466 -- If the type in question is not abstract, and the subprogram
9467 -- is, this will be an error if the new operation is in the
9468 -- private part of the instance. Emit a warning now, which will
9469 -- make the subsequent error message easier to understand.
9471 if Present
(F_Typ
) and then not Is_Abstract_Type
(F_Typ
)
9472 and then Is_Abstract_Subprogram
(Prev_E
)
9473 and then In_Private_Part
(Current_Scope
)
9475 Error_Msg_Node_2
:= F_Typ
;
9477 ("private operation& in generic unit does not override "
9478 & "any primitive operation of& (RM 12.3 (18))??",
9488 end Is_Non_Overriding_Operation
;
9490 -------------------------------------
9491 -- List_Inherited_Pre_Post_Aspects --
9492 -------------------------------------
9494 procedure List_Inherited_Pre_Post_Aspects
(E
: Entity_Id
) is
9496 if Opt
.List_Inherited_Aspects
9497 and then Is_Subprogram_Or_Generic_Subprogram
(E
)
9500 Subps
: constant Subprogram_List
:= Inherited_Subprograms
(E
);
9505 for Index
in Subps
'Range loop
9506 Items
:= Contract
(Subps
(Index
));
9508 if Present
(Items
) then
9509 Prag
:= Pre_Post_Conditions
(Items
);
9510 while Present
(Prag
) loop
9511 Error_Msg_Sloc
:= Sloc
(Prag
);
9513 if Class_Present
(Prag
)
9514 and then not Split_PPC
(Prag
)
9516 if Pragma_Name
(Prag
) = Name_Precondition
then
9518 ("info: & inherits `Pre''Class` aspect from "
9522 ("info: & inherits `Post''Class` aspect from "
9527 Prag
:= Next_Pragma
(Prag
);
9533 end List_Inherited_Pre_Post_Aspects
;
9535 ------------------------------
9536 -- Make_Inequality_Operator --
9537 ------------------------------
9539 -- S is the defining identifier of an equality operator. We build a
9540 -- subprogram declaration with the right signature. This operation is
9541 -- intrinsic, because it is always expanded as the negation of the
9542 -- call to the equality function.
9544 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
9545 Loc
: constant Source_Ptr
:= Sloc
(S
);
9548 Op_Name
: Entity_Id
;
9550 FF
: constant Entity_Id
:= First_Formal
(S
);
9551 NF
: constant Entity_Id
:= Next_Formal
(FF
);
9554 -- Check that equality was properly defined, ignore call if not
9561 A
: constant Entity_Id
:=
9562 Make_Defining_Identifier
(Sloc
(FF
),
9563 Chars
=> Chars
(FF
));
9565 B
: constant Entity_Id
:=
9566 Make_Defining_Identifier
(Sloc
(NF
),
9567 Chars
=> Chars
(NF
));
9570 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
9572 Formals
:= New_List
(
9573 Make_Parameter_Specification
(Loc
,
9574 Defining_Identifier
=> A
,
9576 New_Occurrence_Of
(Etype
(First_Formal
(S
)),
9577 Sloc
(Etype
(First_Formal
(S
))))),
9579 Make_Parameter_Specification
(Loc
,
9580 Defining_Identifier
=> B
,
9582 New_Occurrence_Of
(Etype
(Next_Formal
(First_Formal
(S
))),
9583 Sloc
(Etype
(Next_Formal
(First_Formal
(S
)))))));
9586 Make_Subprogram_Declaration
(Loc
,
9588 Make_Function_Specification
(Loc
,
9589 Defining_Unit_Name
=> Op_Name
,
9590 Parameter_Specifications
=> Formals
,
9591 Result_Definition
=>
9592 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
9594 -- Insert inequality right after equality if it is explicit or after
9595 -- the derived type when implicit. These entities are created only
9596 -- for visibility purposes, and eventually replaced in the course
9597 -- of expansion, so they do not need to be attached to the tree and
9598 -- seen by the back-end. Keeping them internal also avoids spurious
9599 -- freezing problems. The declaration is inserted in the tree for
9600 -- analysis, and removed afterwards. If the equality operator comes
9601 -- from an explicit declaration, attach the inequality immediately
9602 -- after. Else the equality is inherited from a derived type
9603 -- declaration, so insert inequality after that declaration.
9605 if No
(Alias
(S
)) then
9606 Insert_After
(Unit_Declaration_Node
(S
), Decl
);
9607 elsif Is_List_Member
(Parent
(S
)) then
9608 Insert_After
(Parent
(S
), Decl
);
9610 Insert_After
(Parent
(Etype
(First_Formal
(S
))), Decl
);
9613 Mark_Rewrite_Insertion
(Decl
);
9614 Set_Is_Intrinsic_Subprogram
(Op_Name
);
9617 Set_Has_Completion
(Op_Name
);
9618 Set_Corresponding_Equality
(Op_Name
, S
);
9619 Set_Is_Abstract_Subprogram
(Op_Name
, Is_Abstract_Subprogram
(S
));
9621 end Make_Inequality_Operator
;
9623 ----------------------
9624 -- May_Need_Actuals --
9625 ----------------------
9627 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
9632 F
:= First_Formal
(Fun
);
9634 while Present
(F
) loop
9635 if No
(Default_Value
(F
)) then
9643 Set_Needs_No_Actuals
(Fun
, B
);
9644 end May_Need_Actuals
;
9646 ---------------------
9647 -- Mode_Conformant --
9648 ---------------------
9650 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
9653 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
9655 end Mode_Conformant
;
9657 ---------------------------
9658 -- New_Overloaded_Entity --
9659 ---------------------------
9661 procedure New_Overloaded_Entity
9663 Derived_Type
: Entity_Id
:= Empty
)
9665 Overridden_Subp
: Entity_Id
:= Empty
;
9666 -- Set if the current scope has an operation that is type-conformant
9667 -- with S, and becomes hidden by S.
9669 Is_Primitive_Subp
: Boolean;
9670 -- Set to True if the new subprogram is primitive
9673 -- Entity that S overrides
9675 Prev_Vis
: Entity_Id
:= Empty
;
9676 -- Predecessor of E in Homonym chain
9678 procedure Check_For_Primitive_Subprogram
9679 (Is_Primitive
: out Boolean;
9680 Is_Overriding
: Boolean := False);
9681 -- If the subprogram being analyzed is a primitive operation of the type
9682 -- of a formal or result, set the Has_Primitive_Operations flag on the
9683 -- type, and set Is_Primitive to True (otherwise set to False). Set the
9684 -- corresponding flag on the entity itself for later use.
9686 function Has_Matching_Entry_Or_Subprogram
(E
: Entity_Id
) return Boolean;
9687 -- True if a) E is a subprogram whose first formal is a concurrent type
9688 -- defined in the scope of E that has some entry or subprogram whose
9689 -- profile matches E, or b) E is an internally built dispatching
9690 -- subprogram of a protected type and there is a matching subprogram
9691 -- defined in the enclosing scope of the protected type, or c) E is
9692 -- an entry of a synchronized type and a matching procedure has been
9693 -- previously defined in the enclosing scope of the synchronized type.
9695 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
9696 -- Check that E is declared in the private part of the current package,
9697 -- or in the package body, where it may hide a previous declaration.
9698 -- We can't use In_Private_Part by itself because this flag is also
9699 -- set when freezing entities, so we must examine the place of the
9700 -- declaration in the tree, and recognize wrapper packages as well.
9702 function Is_Overriding_Alias
9704 New_E
: Entity_Id
) return Boolean;
9705 -- Check whether new subprogram and old subprogram are both inherited
9706 -- from subprograms that have distinct dispatch table entries. This can
9707 -- occur with derivations from instances with accidental homonyms. The
9708 -- function is conservative given that the converse is only true within
9709 -- instances that contain accidental overloadings.
9711 procedure Report_Conflict
(S
: Entity_Id
; E
: Entity_Id
);
9712 -- Report conflict between entities S and E
9714 ------------------------------------
9715 -- Check_For_Primitive_Subprogram --
9716 ------------------------------------
9718 procedure Check_For_Primitive_Subprogram
9719 (Is_Primitive
: out Boolean;
9720 Is_Overriding
: Boolean := False)
9726 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
9727 -- Returns true if T is declared in the visible part of the current
9728 -- package scope; otherwise returns false. Assumes that T is declared
9731 procedure Check_Private_Overriding
(T
: Entity_Id
);
9732 -- Checks that if a primitive abstract subprogram of a visible
9733 -- abstract type is declared in a private part, then it must override
9734 -- an abstract subprogram declared in the visible part. Also checks
9735 -- that if a primitive function with a controlling result is declared
9736 -- in a private part, then it must override a function declared in
9737 -- the visible part.
9739 ------------------------------
9740 -- Check_Private_Overriding --
9741 ------------------------------
9743 procedure Check_Private_Overriding
(T
: Entity_Id
) is
9744 function Overrides_Private_Part_Op
return Boolean;
9745 -- This detects the special case where the overriding subprogram
9746 -- is overriding a subprogram that was declared in the same
9747 -- private part. That case is illegal by 3.9.3(10).
9749 function Overrides_Visible_Function
9750 (Partial_View
: Entity_Id
) return Boolean;
9751 -- True if S overrides a function in the visible part. The
9752 -- overridden function could be explicitly or implicitly declared.
9754 -------------------------------
9755 -- Overrides_Private_Part_Op --
9756 -------------------------------
9758 function Overrides_Private_Part_Op
return Boolean is
9759 Over_Decl
: constant Node_Id
:=
9760 Unit_Declaration_Node
(Overridden_Operation
(S
));
9761 Subp_Decl
: constant Node_Id
:= Unit_Declaration_Node
(S
);
9764 pragma Assert
(Is_Overriding
);
9766 (Nkind
(Over_Decl
) = N_Abstract_Subprogram_Declaration
);
9768 (Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
);
9770 return In_Same_List
(Over_Decl
, Subp_Decl
);
9771 end Overrides_Private_Part_Op
;
9773 --------------------------------
9774 -- Overrides_Visible_Function --
9775 --------------------------------
9777 function Overrides_Visible_Function
9778 (Partial_View
: Entity_Id
) return Boolean
9781 if not Is_Overriding
or else not Has_Homonym
(S
) then
9785 if not Present
(Partial_View
) then
9789 -- Search through all the homonyms H of S in the current
9790 -- package spec, and return True if we find one that matches.
9791 -- Note that Parent (H) will be the declaration of the
9792 -- partial view of T for a match.
9799 exit when not Present
(H
) or else Scope
(H
) /= Scope
(S
);
9803 N_Private_Extension_Declaration
,
9804 N_Private_Type_Declaration
)
9805 and then Defining_Identifier
(Parent
(H
)) = Partial_View
9813 end Overrides_Visible_Function
;
9815 -- Start of processing for Check_Private_Overriding
9818 if Is_Package_Or_Generic_Package
(Current_Scope
)
9819 and then In_Private_Part
(Current_Scope
)
9820 and then Visible_Part_Type
(T
)
9821 and then not In_Instance
9823 if Is_Abstract_Type
(T
)
9824 and then Is_Abstract_Subprogram
(S
)
9825 and then (not Is_Overriding
9826 or else not Is_Abstract_Subprogram
(E
)
9827 or else Overrides_Private_Part_Op
)
9830 ("abstract subprograms must be visible (RM 3.9.3(10))!",
9833 elsif Ekind
(S
) = E_Function
then
9835 Partial_View
: constant Entity_Id
:=
9836 Incomplete_Or_Partial_View
(T
);
9839 if not Overrides_Visible_Function
(Partial_View
) then
9841 -- Here, S is "function ... return T;" declared in
9842 -- the private part, not overriding some visible
9843 -- operation. That's illegal in the tagged case
9844 -- (but not if the private type is untagged).
9846 if ((Present
(Partial_View
)
9847 and then Is_Tagged_Type
(Partial_View
))
9848 or else (not Present
(Partial_View
)
9849 and then Is_Tagged_Type
(T
)))
9850 and then T
= Base_Type
(Etype
(S
))
9853 ("private function with tagged result must"
9854 & " override visible-part function", S
);
9856 ("\move subprogram to the visible part"
9857 & " (RM 3.9.3(10))", S
);
9859 -- AI05-0073: extend this test to the case of a
9860 -- function with a controlling access result.
9862 elsif Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
9863 and then Is_Tagged_Type
(Designated_Type
(Etype
(S
)))
9865 not Is_Class_Wide_Type
9866 (Designated_Type
(Etype
(S
)))
9867 and then Ada_Version
>= Ada_2012
9870 ("private function with controlling access "
9871 & "result must override visible-part function",
9874 ("\move subprogram to the visible part"
9875 & " (RM 3.9.3(10))", S
);
9881 end Check_Private_Overriding
;
9883 -----------------------
9884 -- Visible_Part_Type --
9885 -----------------------
9887 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
9888 P
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
9892 -- If the entity is a private type, then it must be declared in a
9895 if Ekind
(T
) in Private_Kind
then
9899 -- Otherwise, we traverse the visible part looking for its
9900 -- corresponding declaration. We cannot use the declaration
9901 -- node directly because in the private part the entity of a
9902 -- private type is the one in the full view, which does not
9903 -- indicate that it is the completion of something visible.
9905 N
:= First
(Visible_Declarations
(Specification
(P
)));
9906 while Present
(N
) loop
9907 if Nkind
(N
) = N_Full_Type_Declaration
9908 and then Present
(Defining_Identifier
(N
))
9909 and then T
= Defining_Identifier
(N
)
9913 elsif Nkind_In
(N
, N_Private_Type_Declaration
,
9914 N_Private_Extension_Declaration
)
9915 and then Present
(Defining_Identifier
(N
))
9916 and then T
= Full_View
(Defining_Identifier
(N
))
9925 end Visible_Part_Type
;
9927 -- Start of processing for Check_For_Primitive_Subprogram
9930 Is_Primitive
:= False;
9932 if not Comes_From_Source
(S
) then
9935 -- If subprogram is at library level, it is not primitive operation
9937 elsif Current_Scope
= Standard_Standard
then
9940 elsif (Is_Package_Or_Generic_Package
(Current_Scope
)
9941 and then not In_Package_Body
(Current_Scope
))
9942 or else Is_Overriding
9944 -- For function, check return type
9946 if Ekind
(S
) = E_Function
then
9947 if Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
then
9948 F_Typ
:= Designated_Type
(Etype
(S
));
9953 B_Typ
:= Base_Type
(F_Typ
);
9955 if Scope
(B_Typ
) = Current_Scope
9956 and then not Is_Class_Wide_Type
(B_Typ
)
9957 and then not Is_Generic_Type
(B_Typ
)
9959 Is_Primitive
:= True;
9960 Set_Has_Primitive_Operations
(B_Typ
);
9961 Set_Is_Primitive
(S
);
9962 Check_Private_Overriding
(B_Typ
);
9964 -- The Ghost policy in effect at the point of declaration
9965 -- or a tagged type and a primitive operation must match
9966 -- (SPARK RM 6.9(16)).
9968 Check_Ghost_Primitive
(S
, B_Typ
);
9972 -- For all subprograms, check formals
9974 Formal
:= First_Formal
(S
);
9975 while Present
(Formal
) loop
9976 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
9977 F_Typ
:= Designated_Type
(Etype
(Formal
));
9979 F_Typ
:= Etype
(Formal
);
9982 B_Typ
:= Base_Type
(F_Typ
);
9984 if Ekind
(B_Typ
) = E_Access_Subtype
then
9985 B_Typ
:= Base_Type
(B_Typ
);
9988 if Scope
(B_Typ
) = Current_Scope
9989 and then not Is_Class_Wide_Type
(B_Typ
)
9990 and then not Is_Generic_Type
(B_Typ
)
9992 Is_Primitive
:= True;
9993 Set_Is_Primitive
(S
);
9994 Set_Has_Primitive_Operations
(B_Typ
);
9995 Check_Private_Overriding
(B_Typ
);
9997 -- The Ghost policy in effect at the point of declaration
9998 -- of a tagged type and a primitive operation must match
9999 -- (SPARK RM 6.9(16)).
10001 Check_Ghost_Primitive
(S
, B_Typ
);
10004 Next_Formal
(Formal
);
10007 -- Special case: An equality function can be redefined for a type
10008 -- occurring in a declarative part, and won't otherwise be treated as
10009 -- a primitive because it doesn't occur in a package spec and doesn't
10010 -- override an inherited subprogram. It's important that we mark it
10011 -- primitive so it can be returned by Collect_Primitive_Operations
10012 -- and be used in composing the equality operation of later types
10013 -- that have a component of the type.
10015 elsif Chars
(S
) = Name_Op_Eq
10016 and then Etype
(S
) = Standard_Boolean
10018 B_Typ
:= Base_Type
(Etype
(First_Formal
(S
)));
10020 if Scope
(B_Typ
) = Current_Scope
10022 Base_Type
(Etype
(Next_Formal
(First_Formal
(S
)))) = B_Typ
10023 and then not Is_Limited_Type
(B_Typ
)
10025 Is_Primitive
:= True;
10026 Set_Is_Primitive
(S
);
10027 Set_Has_Primitive_Operations
(B_Typ
);
10028 Check_Private_Overriding
(B_Typ
);
10030 -- The Ghost policy in effect at the point of declaration of a
10031 -- tagged type and a primitive operation must match
10032 -- (SPARK RM 6.9(16)).
10034 Check_Ghost_Primitive
(S
, B_Typ
);
10037 end Check_For_Primitive_Subprogram
;
10039 --------------------------------------
10040 -- Has_Matching_Entry_Or_Subprogram --
10041 --------------------------------------
10043 function Has_Matching_Entry_Or_Subprogram
10044 (E
: Entity_Id
) return Boolean
10046 function Check_Conforming_Parameters
10047 (E1_Param
: Node_Id
;
10048 E2_Param
: Node_Id
) return Boolean;
10049 -- Starting from the given parameters, check that all the parameters
10050 -- of two entries or subprograms are subtype conformant. Used to skip
10051 -- the check on the controlling argument.
10053 function Matching_Entry_Or_Subprogram
10054 (Conc_Typ
: Entity_Id
;
10055 Subp
: Entity_Id
) return Entity_Id
;
10056 -- Return the first entry or subprogram of the given concurrent type
10057 -- whose name matches the name of Subp and has a profile conformant
10058 -- with Subp; return Empty if not found.
10060 function Matching_Dispatching_Subprogram
10061 (Conc_Typ
: Entity_Id
;
10062 Ent
: Entity_Id
) return Entity_Id
;
10063 -- Return the first dispatching primitive of Conc_Type defined in the
10064 -- enclosing scope of Conc_Type (i.e. before the full definition of
10065 -- this concurrent type) whose name matches the entry Ent and has a
10066 -- profile conformant with the profile of the corresponding (not yet
10067 -- built) dispatching primitive of Ent; return Empty if not found.
10069 function Matching_Original_Protected_Subprogram
10070 (Prot_Typ
: Entity_Id
;
10071 Subp
: Entity_Id
) return Entity_Id
;
10072 -- Return the first subprogram defined in the enclosing scope of
10073 -- Prot_Typ (before the full definition of this protected type)
10074 -- whose name matches the original name of Subp and has a profile
10075 -- conformant with the profile of Subp; return Empty if not found.
10077 ---------------------------------
10078 -- Check_Confirming_Parameters --
10079 ---------------------------------
10081 function Check_Conforming_Parameters
10082 (E1_Param
: Node_Id
;
10083 E2_Param
: Node_Id
) return Boolean
10085 Param_E1
: Node_Id
:= E1_Param
;
10086 Param_E2
: Node_Id
:= E2_Param
;
10089 while Present
(Param_E1
) and then Present
(Param_E2
) loop
10090 if Ekind
(Defining_Identifier
(Param_E1
)) /=
10091 Ekind
(Defining_Identifier
(Param_E2
))
10094 (Find_Parameter_Type
(Param_E1
),
10095 Find_Parameter_Type
(Param_E2
),
10096 Subtype_Conformant
)
10105 -- The candidate is not valid if one of the two lists contains
10106 -- more parameters than the other
10108 return No
(Param_E1
) and then No
(Param_E2
);
10109 end Check_Conforming_Parameters
;
10111 ----------------------------------
10112 -- Matching_Entry_Or_Subprogram --
10113 ----------------------------------
10115 function Matching_Entry_Or_Subprogram
10116 (Conc_Typ
: Entity_Id
;
10117 Subp
: Entity_Id
) return Entity_Id
10122 E
:= First_Entity
(Conc_Typ
);
10123 while Present
(E
) loop
10124 if Chars
(Subp
) = Chars
(E
)
10125 and then (Ekind
(E
) = E_Entry
or else Is_Subprogram
(E
))
10127 Check_Conforming_Parameters
10128 (First
(Parameter_Specifications
(Parent
(E
))),
10129 Next
(First
(Parameter_Specifications
(Parent
(Subp
)))))
10138 end Matching_Entry_Or_Subprogram
;
10140 -------------------------------------
10141 -- Matching_Dispatching_Subprogram --
10142 -------------------------------------
10144 function Matching_Dispatching_Subprogram
10145 (Conc_Typ
: Entity_Id
;
10146 Ent
: Entity_Id
) return Entity_Id
10151 -- Search for entities in the enclosing scope of this synchonized
10154 pragma Assert
(Is_Concurrent_Type
(Conc_Typ
));
10155 Push_Scope
(Scope
(Conc_Typ
));
10156 E
:= Current_Entity_In_Scope
(Ent
);
10159 while Present
(E
) loop
10160 if Scope
(E
) = Scope
(Conc_Typ
)
10161 and then Comes_From_Source
(E
)
10162 and then Ekind
(E
) = E_Procedure
10163 and then Present
(First_Entity
(E
))
10164 and then Is_Controlling_Formal
(First_Entity
(E
))
10165 and then Etype
(First_Entity
(E
)) = Conc_Typ
10167 Check_Conforming_Parameters
10168 (First
(Parameter_Specifications
(Parent
(Ent
))),
10169 Next
(First
(Parameter_Specifications
(Parent
(E
)))))
10178 end Matching_Dispatching_Subprogram
;
10180 --------------------------------------------
10181 -- Matching_Original_Protected_Subprogram --
10182 --------------------------------------------
10184 function Matching_Original_Protected_Subprogram
10185 (Prot_Typ
: Entity_Id
;
10186 Subp
: Entity_Id
) return Entity_Id
10188 ICF
: constant Boolean :=
10189 Is_Controlling_Formal
(First_Entity
(Subp
));
10193 -- Temporarily decorate the first parameter of Subp as controlling
10194 -- formal, required to invoke Subtype_Conformant.
10196 Set_Is_Controlling_Formal
(First_Entity
(Subp
));
10199 Current_Entity_In_Scope
(Original_Protected_Subprogram
(Subp
));
10201 while Present
(E
) loop
10202 if Scope
(E
) = Scope
(Prot_Typ
)
10203 and then Comes_From_Source
(E
)
10204 and then Ekind
(Subp
) = Ekind
(E
)
10205 and then Present
(First_Entity
(E
))
10206 and then Is_Controlling_Formal
(First_Entity
(E
))
10207 and then Etype
(First_Entity
(E
)) = Prot_Typ
10208 and then Subtype_Conformant
(Subp
, E
,
10209 Skip_Controlling_Formals
=> True)
10211 Set_Is_Controlling_Formal
(First_Entity
(Subp
), ICF
);
10218 Set_Is_Controlling_Formal
(First_Entity
(Subp
), ICF
);
10221 end Matching_Original_Protected_Subprogram
;
10223 -- Start of processing for Has_Matching_Entry_Or_Subprogram
10226 -- Case 1: E is a subprogram whose first formal is a concurrent type
10227 -- defined in the scope of E that has an entry or subprogram whose
10228 -- profile matches E.
10230 if Comes_From_Source
(E
)
10231 and then Is_Subprogram
(E
)
10232 and then Present
(First_Entity
(E
))
10233 and then Is_Concurrent_Record_Type
(Etype
(First_Entity
(E
)))
10236 Scope
(Corresponding_Concurrent_Type
10237 (Etype
(First_Entity
(E
))))
10240 (Matching_Entry_Or_Subprogram
10241 (Corresponding_Concurrent_Type
(Etype
(First_Entity
(E
))),
10244 Report_Conflict
(E
,
10245 Matching_Entry_Or_Subprogram
10246 (Corresponding_Concurrent_Type
(Etype
(First_Entity
(E
))),
10251 -- Case 2: E is an internally built dispatching subprogram of a
10252 -- protected type and there is a subprogram defined in the enclosing
10253 -- scope of the protected type that has the original name of E and
10254 -- its profile is conformant with the profile of E. We check the
10255 -- name of the original protected subprogram associated with E since
10256 -- the expander builds dispatching primitives of protected functions
10257 -- and procedures with other names (see Exp_Ch9.Build_Selected_Name).
10259 elsif not Comes_From_Source
(E
)
10260 and then Is_Subprogram
(E
)
10261 and then Present
(First_Entity
(E
))
10262 and then Is_Concurrent_Record_Type
(Etype
(First_Entity
(E
)))
10263 and then Present
(Original_Protected_Subprogram
(E
))
10266 (Matching_Original_Protected_Subprogram
10267 (Corresponding_Concurrent_Type
(Etype
(First_Entity
(E
))),
10270 Report_Conflict
(E
,
10271 Matching_Original_Protected_Subprogram
10272 (Corresponding_Concurrent_Type
(Etype
(First_Entity
(E
))),
10276 -- Case 3: E is an entry of a synchronized type and a matching
10277 -- procedure has been previously defined in the enclosing scope
10278 -- of the synchronized type.
10280 elsif Comes_From_Source
(E
)
10281 and then Ekind
(E
) = E_Entry
10283 Present
(Matching_Dispatching_Subprogram
(Current_Scope
, E
))
10285 Report_Conflict
(E
,
10286 Matching_Dispatching_Subprogram
(Current_Scope
, E
));
10291 end Has_Matching_Entry_Or_Subprogram
;
10293 ----------------------------
10294 -- Is_Private_Declaration --
10295 ----------------------------
10297 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
10298 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
10299 Priv_Decls
: List_Id
;
10302 if Is_Package_Or_Generic_Package
(Current_Scope
)
10303 and then In_Private_Part
(Current_Scope
)
10306 Private_Declarations
(Package_Specification
(Current_Scope
));
10308 return In_Package_Body
(Current_Scope
)
10310 (Is_List_Member
(Decl
)
10311 and then List_Containing
(Decl
) = Priv_Decls
)
10312 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
10314 Is_Compilation_Unit
10315 (Defining_Entity
(Parent
(Decl
)))
10316 and then List_Containing
(Parent
(Parent
(Decl
))) =
10321 end Is_Private_Declaration
;
10323 --------------------------
10324 -- Is_Overriding_Alias --
10325 --------------------------
10327 function Is_Overriding_Alias
10328 (Old_E
: Entity_Id
;
10329 New_E
: Entity_Id
) return Boolean
10331 AO
: constant Entity_Id
:= Alias
(Old_E
);
10332 AN
: constant Entity_Id
:= Alias
(New_E
);
10335 return Scope
(AO
) /= Scope
(AN
)
10336 or else No
(DTC_Entity
(AO
))
10337 or else No
(DTC_Entity
(AN
))
10338 or else DT_Position
(AO
) = DT_Position
(AN
);
10339 end Is_Overriding_Alias
;
10341 ---------------------
10342 -- Report_Conflict --
10343 ---------------------
10345 procedure Report_Conflict
(S
: Entity_Id
; E
: Entity_Id
) is
10347 Error_Msg_Sloc
:= Sloc
(E
);
10349 -- Generate message, with useful additional warning if in generic
10351 if Is_Generic_Unit
(E
) then
10352 Error_Msg_N
("previous generic unit cannot be overloaded", S
);
10353 Error_Msg_N
("\& conflicts with declaration#", S
);
10355 Error_Msg_N
("& conflicts with declaration#", S
);
10357 end Report_Conflict
;
10359 -- Start of processing for New_Overloaded_Entity
10362 -- We need to look for an entity that S may override. This must be a
10363 -- homonym in the current scope, so we look for the first homonym of
10364 -- S in the current scope as the starting point for the search.
10366 E
:= Current_Entity_In_Scope
(S
);
10368 -- Ada 2005 (AI-251): Derivation of abstract interface primitives.
10369 -- They are directly added to the list of primitive operations of
10370 -- Derived_Type, unless this is a rederivation in the private part
10371 -- of an operation that was already derived in the visible part of
10372 -- the current package.
10374 if Ada_Version
>= Ada_2005
10375 and then Present
(Derived_Type
)
10376 and then Present
(Alias
(S
))
10377 and then Is_Dispatching_Operation
(Alias
(S
))
10378 and then Present
(Find_Dispatching_Type
(Alias
(S
)))
10379 and then Is_Interface
(Find_Dispatching_Type
(Alias
(S
)))
10381 -- For private types, when the full-view is processed we propagate to
10382 -- the full view the non-overridden entities whose attribute "alias"
10383 -- references an interface primitive. These entities were added by
10384 -- Derive_Subprograms to ensure that interface primitives are
10387 -- Inside_Freeze_Actions is non zero when S corresponds with an
10388 -- internal entity that links an interface primitive with its
10389 -- covering primitive through attribute Interface_Alias (see
10390 -- Add_Internal_Interface_Entities).
10392 if Inside_Freezing_Actions
= 0
10393 and then Is_Package_Or_Generic_Package
(Current_Scope
)
10394 and then In_Private_Part
(Current_Scope
)
10395 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
10396 and then Nkind
(Parent
(S
)) = N_Full_Type_Declaration
10397 and then Full_View
(Defining_Identifier
(Parent
(E
)))
10398 = Defining_Identifier
(Parent
(S
))
10399 and then Alias
(E
) = Alias
(S
)
10401 Check_Operation_From_Private_View
(S
, E
);
10402 Set_Is_Dispatching_Operation
(S
);
10407 Enter_Overloaded_Entity
(S
);
10408 Check_Dispatching_Operation
(S
, Empty
);
10409 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
10415 -- For synchronized types check conflicts of this entity with previously
10416 -- defined entities.
10418 if Ada_Version
>= Ada_2005
10419 and then Has_Matching_Entry_Or_Subprogram
(S
)
10424 -- If there is no homonym then this is definitely not overriding
10427 Enter_Overloaded_Entity
(S
);
10428 Check_Dispatching_Operation
(S
, Empty
);
10429 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
10431 -- If subprogram has an explicit declaration, check whether it has an
10432 -- overriding indicator.
10434 if Comes_From_Source
(S
) then
10435 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
10437 -- (Ada 2012: AI05-0125-1): If S is a dispatching operation then
10438 -- it may have overridden some hidden inherited primitive. Update
10439 -- Overridden_Subp to avoid spurious errors when checking the
10440 -- overriding indicator.
10442 if Ada_Version
>= Ada_2012
10443 and then No
(Overridden_Subp
)
10444 and then Is_Dispatching_Operation
(S
)
10445 and then Present
(Overridden_Operation
(S
))
10447 Overridden_Subp
:= Overridden_Operation
(S
);
10450 Check_Overriding_Indicator
10451 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
10453 -- The Ghost policy in effect at the point of declaration of a
10454 -- parent subprogram and an overriding subprogram must match
10455 -- (SPARK RM 6.9(17)).
10457 Check_Ghost_Overriding
(S
, Overridden_Subp
);
10460 -- If there is a homonym that is not overloadable, then we have an
10461 -- error, except for the special cases checked explicitly below.
10463 elsif not Is_Overloadable
(E
) then
10465 -- Check for spurious conflict produced by a subprogram that has the
10466 -- same name as that of the enclosing generic package. The conflict
10467 -- occurs within an instance, between the subprogram and the renaming
10468 -- declaration for the package. After the subprogram, the package
10469 -- renaming declaration becomes hidden.
10471 if Ekind
(E
) = E_Package
10472 and then Present
(Renamed_Object
(E
))
10473 and then Renamed_Object
(E
) = Current_Scope
10474 and then Nkind
(Parent
(Renamed_Object
(E
))) =
10475 N_Package_Specification
10476 and then Present
(Generic_Parent
(Parent
(Renamed_Object
(E
))))
10479 Set_Is_Immediately_Visible
(E
, False);
10480 Enter_Overloaded_Entity
(S
);
10481 Set_Homonym
(S
, Homonym
(E
));
10482 Check_Dispatching_Operation
(S
, Empty
);
10483 Check_Overriding_Indicator
(S
, Empty
, Is_Primitive
=> False);
10485 -- If the subprogram is implicit it is hidden by the previous
10486 -- declaration. However if it is dispatching, it must appear in the
10487 -- dispatch table anyway, because it can be dispatched to even if it
10488 -- cannot be called directly.
10490 elsif Present
(Alias
(S
)) and then not Comes_From_Source
(S
) then
10491 Set_Scope
(S
, Current_Scope
);
10493 if Is_Dispatching_Operation
(Alias
(S
)) then
10494 Check_Dispatching_Operation
(S
, Empty
);
10500 Report_Conflict
(S
, E
);
10504 -- E exists and is overloadable
10507 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
10509 -- Loop through E and its homonyms to determine if any of them is
10510 -- the candidate for overriding by S.
10512 while Present
(E
) loop
10514 -- Definitely not interesting if not in the current scope
10516 if Scope
(E
) /= Current_Scope
then
10519 -- A function can overload the name of an abstract state. The
10520 -- state can be viewed as a function with a profile that cannot
10521 -- be matched by anything.
10523 elsif Ekind
(S
) = E_Function
10524 and then Ekind
(E
) = E_Abstract_State
10526 Enter_Overloaded_Entity
(S
);
10529 -- Ada 2012 (AI05-0165): For internally generated bodies of null
10530 -- procedures locate the internally generated spec. We enforce
10531 -- mode conformance since a tagged type may inherit from
10532 -- interfaces several null primitives which differ only in
10533 -- the mode of the formals.
10535 elsif not Comes_From_Source
(S
)
10536 and then Is_Null_Procedure
(S
)
10537 and then not Mode_Conformant
(E
, S
)
10541 -- Check if we have type conformance
10543 elsif Type_Conformant
(E
, S
) then
10545 -- If the old and new entities have the same profile and one
10546 -- is not the body of the other, then this is an error, unless
10547 -- one of them is implicitly declared.
10549 -- There are some cases when both can be implicit, for example
10550 -- when both a literal and a function that overrides it are
10551 -- inherited in a derivation, or when an inherited operation
10552 -- of a tagged full type overrides the inherited operation of
10553 -- a private extension. Ada 83 had a special rule for the
10554 -- literal case. In Ada 95, the later implicit operation hides
10555 -- the former, and the literal is always the former. In the
10556 -- odd case where both are derived operations declared at the
10557 -- same point, both operations should be declared, and in that
10558 -- case we bypass the following test and proceed to the next
10559 -- part. This can only occur for certain obscure cases in
10560 -- instances, when an operation on a type derived from a formal
10561 -- private type does not override a homograph inherited from
10562 -- the actual. In subsequent derivations of such a type, the
10563 -- DT positions of these operations remain distinct, if they
10566 if Present
(Alias
(S
))
10567 and then (No
(Alias
(E
))
10568 or else Comes_From_Source
(E
)
10569 or else Is_Abstract_Subprogram
(S
)
10571 (Is_Dispatching_Operation
(E
)
10572 and then Is_Overriding_Alias
(E
, S
)))
10573 and then Ekind
(E
) /= E_Enumeration_Literal
10575 -- When an derived operation is overloaded it may be due to
10576 -- the fact that the full view of a private extension
10577 -- re-inherits. It has to be dealt with.
10579 if Is_Package_Or_Generic_Package
(Current_Scope
)
10580 and then In_Private_Part
(Current_Scope
)
10582 Check_Operation_From_Private_View
(S
, E
);
10585 -- In any case the implicit operation remains hidden by the
10586 -- existing declaration, which is overriding. Indicate that
10587 -- E overrides the operation from which S is inherited.
10589 if Present
(Alias
(S
)) then
10590 Set_Overridden_Operation
(E
, Alias
(S
));
10591 Inherit_Subprogram_Contract
(E
, Alias
(S
));
10594 Set_Overridden_Operation
(E
, S
);
10595 Inherit_Subprogram_Contract
(E
, S
);
10598 if Comes_From_Source
(E
) then
10599 Check_Overriding_Indicator
(E
, S
, Is_Primitive
=> False);
10601 -- The Ghost policy in effect at the point of declaration
10602 -- of a parent subprogram and an overriding subprogram
10603 -- must match (SPARK RM 6.9(17)).
10605 Check_Ghost_Overriding
(E
, S
);
10610 -- Within an instance, the renaming declarations for actual
10611 -- subprograms may become ambiguous, but they do not hide each
10614 elsif Ekind
(E
) /= E_Entry
10615 and then not Comes_From_Source
(E
)
10616 and then not Is_Generic_Instance
(E
)
10617 and then (Present
(Alias
(E
))
10618 or else Is_Intrinsic_Subprogram
(E
))
10619 and then (not In_Instance
10620 or else No
(Parent
(E
))
10621 or else Nkind
(Unit_Declaration_Node
(E
)) /=
10622 N_Subprogram_Renaming_Declaration
)
10624 -- A subprogram child unit is not allowed to override an
10625 -- inherited subprogram (10.1.1(20)).
10627 if Is_Child_Unit
(S
) then
10629 ("child unit overrides inherited subprogram in parent",
10634 if Is_Non_Overriding_Operation
(E
, S
) then
10635 Enter_Overloaded_Entity
(S
);
10637 if No
(Derived_Type
)
10638 or else Is_Tagged_Type
(Derived_Type
)
10640 Check_Dispatching_Operation
(S
, Empty
);
10646 -- E is a derived operation or an internal operator which
10647 -- is being overridden. Remove E from further visibility.
10648 -- Furthermore, if E is a dispatching operation, it must be
10649 -- replaced in the list of primitive operations of its type
10650 -- (see Override_Dispatching_Operation).
10652 Overridden_Subp
:= E
;
10658 Prev
:= First_Entity
(Current_Scope
);
10659 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
10660 Next_Entity
(Prev
);
10663 -- It is possible for E to be in the current scope and
10664 -- yet not in the entity chain. This can only occur in a
10665 -- generic context where E is an implicit concatenation
10666 -- in the formal part, because in a generic body the
10667 -- entity chain starts with the formals.
10669 -- In GNATprove mode, a wrapper for an operation with
10670 -- axiomatization may be a homonym of another declaration
10671 -- for an actual subprogram (needs refinement ???).
10675 and then GNATprove_Mode
10677 Nkind
(Original_Node
(Unit_Declaration_Node
(S
))) =
10678 N_Subprogram_Renaming_Declaration
10682 pragma Assert
(Chars
(E
) = Name_Op_Concat
);
10687 -- E must be removed both from the entity_list of the
10688 -- current scope, and from the visibility chain.
10690 if Debug_Flag_E
then
10691 Write_Str
("Override implicit operation ");
10692 Write_Int
(Int
(E
));
10696 -- If E is a predefined concatenation, it stands for four
10697 -- different operations. As a result, a single explicit
10698 -- declaration does not hide it. In a possible ambiguous
10699 -- situation, Disambiguate chooses the user-defined op,
10700 -- so it is correct to retain the previous internal one.
10702 if Chars
(E
) /= Name_Op_Concat
10703 or else Ekind
(E
) /= E_Operator
10705 -- For nondispatching derived operations that are
10706 -- overridden by a subprogram declared in the private
10707 -- part of a package, we retain the derived subprogram
10708 -- but mark it as not immediately visible. If the
10709 -- derived operation was declared in the visible part
10710 -- then this ensures that it will still be visible
10711 -- outside the package with the proper signature
10712 -- (calls from outside must also be directed to this
10713 -- version rather than the overriding one, unlike the
10714 -- dispatching case). Calls from inside the package
10715 -- will still resolve to the overriding subprogram
10716 -- since the derived one is marked as not visible
10717 -- within the package.
10719 -- If the private operation is dispatching, we achieve
10720 -- the overriding by keeping the implicit operation
10721 -- but setting its alias to be the overriding one. In
10722 -- this fashion the proper body is executed in all
10723 -- cases, but the original signature is used outside
10726 -- If the overriding is not in the private part, we
10727 -- remove the implicit operation altogether.
10729 if Is_Private_Declaration
(S
) then
10730 if not Is_Dispatching_Operation
(E
) then
10731 Set_Is_Immediately_Visible
(E
, False);
10733 -- Work done in Override_Dispatching_Operation,
10734 -- so nothing else needs to be done here.
10740 -- Find predecessor of E in Homonym chain
10742 if E
= Current_Entity
(E
) then
10745 Prev_Vis
:= Current_Entity
(E
);
10746 while Homonym
(Prev_Vis
) /= E
loop
10747 Prev_Vis
:= Homonym
(Prev_Vis
);
10751 if Prev_Vis
/= Empty
then
10753 -- Skip E in the visibility chain
10755 Set_Homonym
(Prev_Vis
, Homonym
(E
));
10758 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
10761 Set_Next_Entity
(Prev
, Next_Entity
(E
));
10763 if No
(Next_Entity
(Prev
)) then
10764 Set_Last_Entity
(Current_Scope
, Prev
);
10769 Enter_Overloaded_Entity
(S
);
10771 -- For entities generated by Derive_Subprograms the
10772 -- overridden operation is the inherited primitive
10773 -- (which is available through the attribute alias).
10775 if not (Comes_From_Source
(E
))
10776 and then Is_Dispatching_Operation
(E
)
10777 and then Find_Dispatching_Type
(E
) =
10778 Find_Dispatching_Type
(S
)
10779 and then Present
(Alias
(E
))
10780 and then Comes_From_Source
(Alias
(E
))
10782 Set_Overridden_Operation
(S
, Alias
(E
));
10783 Inherit_Subprogram_Contract
(S
, Alias
(E
));
10785 -- Normal case of setting entity as overridden
10787 -- Note: Static_Initialization and Overridden_Operation
10788 -- attributes use the same field in subprogram entities.
10789 -- Static_Initialization is only defined for internal
10790 -- initialization procedures, where Overridden_Operation
10791 -- is irrelevant. Therefore the setting of this attribute
10792 -- must check whether the target is an init_proc.
10794 elsif not Is_Init_Proc
(S
) then
10795 Set_Overridden_Operation
(S
, E
);
10796 Inherit_Subprogram_Contract
(S
, E
);
10799 Check_Overriding_Indicator
(S
, E
, Is_Primitive
=> True);
10801 -- The Ghost policy in effect at the point of declaration
10802 -- of a parent subprogram and an overriding subprogram
10803 -- must match (SPARK RM 6.9(17)).
10805 Check_Ghost_Overriding
(S
, E
);
10807 -- If S is a user-defined subprogram or a null procedure
10808 -- expanded to override an inherited null procedure, or a
10809 -- predefined dispatching primitive then indicate that E
10810 -- overrides the operation from which S is inherited.
10812 if Comes_From_Source
(S
)
10814 (Present
(Parent
(S
))
10816 Nkind
(Parent
(S
)) = N_Procedure_Specification
10818 Null_Present
(Parent
(S
)))
10820 (Present
(Alias
(E
))
10822 Is_Predefined_Dispatching_Operation
(Alias
(E
)))
10824 if Present
(Alias
(E
)) then
10825 Set_Overridden_Operation
(S
, Alias
(E
));
10826 Inherit_Subprogram_Contract
(S
, Alias
(E
));
10830 if Is_Dispatching_Operation
(E
) then
10832 -- An overriding dispatching subprogram inherits the
10833 -- convention of the overridden subprogram (AI-117).
10835 Set_Convention
(S
, Convention
(E
));
10836 Check_Dispatching_Operation
(S
, E
);
10839 Check_Dispatching_Operation
(S
, Empty
);
10842 Check_For_Primitive_Subprogram
10843 (Is_Primitive_Subp
, Is_Overriding
=> True);
10844 goto Check_Inequality
;
10847 -- Apparent redeclarations in instances can occur when two
10848 -- formal types get the same actual type. The subprograms in
10849 -- in the instance are legal, even if not callable from the
10850 -- outside. Calls from within are disambiguated elsewhere.
10851 -- For dispatching operations in the visible part, the usual
10852 -- rules apply, and operations with the same profile are not
10853 -- legal (B830001).
10855 elsif (In_Instance_Visible_Part
10856 and then not Is_Dispatching_Operation
(E
))
10857 or else In_Instance_Not_Visible
10861 -- Here we have a real error (identical profile)
10864 Error_Msg_Sloc
:= Sloc
(E
);
10866 -- Avoid cascaded errors if the entity appears in
10867 -- subsequent calls.
10869 Set_Scope
(S
, Current_Scope
);
10871 -- Generate error, with extra useful warning for the case
10872 -- of a generic instance with no completion.
10874 if Is_Generic_Instance
(S
)
10875 and then not Has_Completion
(E
)
10878 ("instantiation cannot provide body for&", S
);
10879 Error_Msg_N
("\& conflicts with declaration#", S
);
10881 Error_Msg_N
("& conflicts with declaration#", S
);
10888 -- If one subprogram has an access parameter and the other
10889 -- a parameter of an access type, calls to either might be
10890 -- ambiguous. Verify that parameters match except for the
10891 -- access parameter.
10893 if May_Hide_Profile
then
10899 F1
:= First_Formal
(S
);
10900 F2
:= First_Formal
(E
);
10901 while Present
(F1
) and then Present
(F2
) loop
10902 if Is_Access_Type
(Etype
(F1
)) then
10903 if not Is_Access_Type
(Etype
(F2
))
10904 or else not Conforming_Types
10905 (Designated_Type
(Etype
(F1
)),
10906 Designated_Type
(Etype
(F2
)),
10909 May_Hide_Profile
:= False;
10913 not Conforming_Types
10914 (Etype
(F1
), Etype
(F2
), Type_Conformant
)
10916 May_Hide_Profile
:= False;
10923 if May_Hide_Profile
10927 Error_Msg_NE
("calls to& may be ambiguous??", S
, S
);
10936 -- On exit, we know that S is a new entity
10938 Enter_Overloaded_Entity
(S
);
10939 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
10940 Check_Overriding_Indicator
10941 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
10943 -- The Ghost policy in effect at the point of declaration of a parent
10944 -- subprogram and an overriding subprogram must match
10945 -- (SPARK RM 6.9(17)).
10947 Check_Ghost_Overriding
(S
, Overridden_Subp
);
10949 -- Overloading is not allowed in SPARK, except for operators
10951 if Nkind
(S
) /= N_Defining_Operator_Symbol
then
10952 Error_Msg_Sloc
:= Sloc
(Homonym
(S
));
10953 Check_SPARK_05_Restriction
10954 ("overloading not allowed with entity#", S
);
10957 -- If S is a derived operation for an untagged type then by
10958 -- definition it's not a dispatching operation (even if the parent
10959 -- operation was dispatching), so Check_Dispatching_Operation is not
10960 -- called in that case.
10962 if No
(Derived_Type
)
10963 or else Is_Tagged_Type
(Derived_Type
)
10965 Check_Dispatching_Operation
(S
, Empty
);
10969 -- If this is a user-defined equality operator that is not a derived
10970 -- subprogram, create the corresponding inequality. If the operation is
10971 -- dispatching, the expansion is done elsewhere, and we do not create
10972 -- an explicit inequality operation.
10974 <<Check_Inequality
>>
10975 if Chars
(S
) = Name_Op_Eq
10976 and then Etype
(S
) = Standard_Boolean
10977 and then Present
(Parent
(S
))
10978 and then not Is_Dispatching_Operation
(S
)
10980 Make_Inequality_Operator
(S
);
10981 Check_Untagged_Equality
(S
);
10983 end New_Overloaded_Entity
;
10985 ---------------------
10986 -- Process_Formals --
10987 ---------------------
10989 procedure Process_Formals
10991 Related_Nod
: Node_Id
)
10993 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean;
10994 -- Determine whether an access type designates a type coming from a
10997 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean;
10998 -- Check whether the default has a class-wide type. After analysis the
10999 -- default has the type of the formal, so we must also check explicitly
11000 -- for an access attribute.
11002 ----------------------------------
11003 -- Designates_From_Limited_With --
11004 ----------------------------------
11006 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean is
11007 Desig
: Entity_Id
:= Typ
;
11010 if Is_Access_Type
(Desig
) then
11011 Desig
:= Directly_Designated_Type
(Desig
);
11014 if Is_Class_Wide_Type
(Desig
) then
11015 Desig
:= Root_Type
(Desig
);
11019 Ekind
(Desig
) = E_Incomplete_Type
11020 and then From_Limited_With
(Desig
);
11021 end Designates_From_Limited_With
;
11023 ---------------------------
11024 -- Is_Class_Wide_Default --
11025 ---------------------------
11027 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean is
11029 return Is_Class_Wide_Type
(Designated_Type
(Etype
(D
)))
11030 or else (Nkind
(D
) = N_Attribute_Reference
11031 and then Attribute_Name
(D
) = Name_Access
11032 and then Is_Class_Wide_Type
(Etype
(Prefix
(D
))));
11033 end Is_Class_Wide_Default
;
11037 Context
: constant Node_Id
:= Parent
(Parent
(T
));
11039 Formal
: Entity_Id
;
11040 Formal_Type
: Entity_Id
;
11041 Param_Spec
: Node_Id
;
11044 Num_Out_Params
: Nat
:= 0;
11045 First_Out_Param
: Entity_Id
:= Empty
;
11046 -- Used for setting Is_Only_Out_Parameter
11048 -- Start of processing for Process_Formals
11051 -- In order to prevent premature use of the formals in the same formal
11052 -- part, the Ekind is left undefined until all default expressions are
11053 -- analyzed. The Ekind is established in a separate loop at the end.
11055 Param_Spec
:= First
(T
);
11056 while Present
(Param_Spec
) loop
11057 Formal
:= Defining_Identifier
(Param_Spec
);
11058 Set_Never_Set_In_Source
(Formal
, True);
11059 Enter_Name
(Formal
);
11061 -- Case of ordinary parameters
11063 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
11064 Find_Type
(Parameter_Type
(Param_Spec
));
11065 Ptype
:= Parameter_Type
(Param_Spec
);
11067 if Ptype
= Error
then
11071 Formal_Type
:= Entity
(Ptype
);
11073 if Is_Incomplete_Type
(Formal_Type
)
11075 (Is_Class_Wide_Type
(Formal_Type
)
11076 and then Is_Incomplete_Type
(Root_Type
(Formal_Type
)))
11078 -- Ada 2005 (AI-326): Tagged incomplete types allowed in
11079 -- primitive operations, as long as their completion is
11080 -- in the same declarative part. If in the private part
11081 -- this means that the type cannot be a Taft-amendment type.
11082 -- Check is done on package exit. For access to subprograms,
11083 -- the use is legal for Taft-amendment types.
11085 -- Ada 2012: tagged incomplete types are allowed as generic
11086 -- formal types. They do not introduce dependencies and the
11087 -- corresponding generic subprogram does not have a delayed
11088 -- freeze, because it does not need a freeze node. However,
11089 -- it is still the case that untagged incomplete types cannot
11090 -- be Taft-amendment types and must be completed in private
11091 -- part, so the subprogram must appear in the list of private
11092 -- dependents of the type.
11094 if Is_Tagged_Type
(Formal_Type
)
11095 or else (Ada_Version
>= Ada_2012
11096 and then not From_Limited_With
(Formal_Type
)
11097 and then not Is_Generic_Type
(Formal_Type
))
11099 if Ekind
(Scope
(Current_Scope
)) = E_Package
11100 and then not Is_Generic_Type
(Formal_Type
)
11101 and then not Is_Class_Wide_Type
(Formal_Type
)
11104 (Parent
(T
), N_Access_Function_Definition
,
11105 N_Access_Procedure_Definition
)
11107 Append_Elmt
(Current_Scope
,
11108 Private_Dependents
(Base_Type
(Formal_Type
)));
11110 -- Freezing is delayed to ensure that Register_Prim
11111 -- will get called for this operation, which is needed
11112 -- in cases where static dispatch tables aren't built.
11113 -- (Note that the same is done for controlling access
11114 -- parameter cases in function Access_Definition.)
11116 if not Is_Thunk
(Current_Scope
) then
11117 Set_Has_Delayed_Freeze
(Current_Scope
);
11122 elsif not Nkind_In
(Parent
(T
), N_Access_Function_Definition
,
11123 N_Access_Procedure_Definition
)
11125 -- AI05-0151: Tagged incomplete types are allowed in all
11126 -- formal parts. Untagged incomplete types are not allowed
11127 -- in bodies. Limited views of either kind are not allowed
11128 -- if there is no place at which the non-limited view can
11129 -- become available.
11131 -- Incomplete formal untagged types are not allowed in
11132 -- subprogram bodies (but are legal in their declarations).
11133 -- This excludes bodies created for null procedures, which
11134 -- are basic declarations.
11136 if Is_Generic_Type
(Formal_Type
)
11137 and then not Is_Tagged_Type
(Formal_Type
)
11138 and then Nkind
(Parent
(Related_Nod
)) = N_Subprogram_Body
11141 ("invalid use of formal incomplete type", Param_Spec
);
11143 elsif Ada_Version
>= Ada_2012
then
11144 if Is_Tagged_Type
(Formal_Type
)
11145 and then (not From_Limited_With
(Formal_Type
)
11146 or else not In_Package_Body
)
11150 elsif Nkind_In
(Context
, N_Accept_Statement
,
11151 N_Accept_Alternative
,
11153 or else (Nkind
(Context
) = N_Subprogram_Body
11154 and then Comes_From_Source
(Context
))
11157 ("invalid use of untagged incomplete type &",
11158 Ptype
, Formal_Type
);
11163 ("invalid use of incomplete type&",
11164 Param_Spec
, Formal_Type
);
11166 -- Further checks on the legality of incomplete types
11167 -- in formal parts are delayed until the freeze point
11168 -- of the enclosing subprogram or access to subprogram.
11172 elsif Ekind
(Formal_Type
) = E_Void
then
11174 ("premature use of&",
11175 Parameter_Type
(Param_Spec
), Formal_Type
);
11178 -- Ada 2012 (AI-142): Handle aliased parameters
11180 if Ada_Version
>= Ada_2012
11181 and then Aliased_Present
(Param_Spec
)
11183 Set_Is_Aliased
(Formal
);
11186 -- Ada 2005 (AI-231): Create and decorate an internal subtype
11187 -- declaration corresponding to the null-excluding type of the
11188 -- formal in the enclosing scope. Finally, replace the parameter
11189 -- type of the formal with the internal subtype.
11191 if Ada_Version
>= Ada_2005
11192 and then Null_Exclusion_Present
(Param_Spec
)
11194 if not Is_Access_Type
(Formal_Type
) then
11196 ("`NOT NULL` allowed only for an access type", Param_Spec
);
11199 if Can_Never_Be_Null
(Formal_Type
)
11200 and then Comes_From_Source
(Related_Nod
)
11203 ("`NOT NULL` not allowed (& already excludes null)",
11204 Param_Spec
, Formal_Type
);
11208 Create_Null_Excluding_Itype
11210 Related_Nod
=> Related_Nod
,
11211 Scope_Id
=> Scope
(Current_Scope
));
11213 -- If the designated type of the itype is an itype that is
11214 -- not frozen yet, we set the Has_Delayed_Freeze attribute
11215 -- on the access subtype, to prevent order-of-elaboration
11216 -- issues in the backend.
11219 -- type T is access procedure;
11220 -- procedure Op (O : not null T);
11222 if Is_Itype
(Directly_Designated_Type
(Formal_Type
))
11224 not Is_Frozen
(Directly_Designated_Type
(Formal_Type
))
11226 Set_Has_Delayed_Freeze
(Formal_Type
);
11231 -- An access formal type
11235 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
11237 -- No need to continue if we already notified errors
11239 if not Present
(Formal_Type
) then
11243 -- Ada 2005 (AI-254)
11246 AD
: constant Node_Id
:=
11247 Access_To_Subprogram_Definition
11248 (Parameter_Type
(Param_Spec
));
11250 if Present
(AD
) and then Protected_Present
(AD
) then
11252 Replace_Anonymous_Access_To_Protected_Subprogram
11258 Set_Etype
(Formal
, Formal_Type
);
11260 -- Deal with default expression if present
11262 Default
:= Expression
(Param_Spec
);
11264 if Present
(Default
) then
11265 Check_SPARK_05_Restriction
11266 ("default expression is not allowed", Default
);
11268 if Out_Present
(Param_Spec
) then
11270 ("default initialization only allowed for IN parameters",
11274 -- Do the special preanalysis of the expression (see section on
11275 -- "Handling of Default Expressions" in the spec of package Sem).
11277 Preanalyze_Spec_Expression
(Default
, Formal_Type
);
11279 -- An access to constant cannot be the default for
11280 -- an access parameter that is an access to variable.
11282 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
11283 and then not Is_Access_Constant
(Formal_Type
)
11284 and then Is_Access_Type
(Etype
(Default
))
11285 and then Is_Access_Constant
(Etype
(Default
))
11288 ("formal that is access to variable cannot be initialized "
11289 & "with an access-to-constant expression", Default
);
11292 -- Check that the designated type of an access parameter's default
11293 -- is not a class-wide type unless the parameter's designated type
11294 -- is also class-wide.
11296 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
11297 and then not Designates_From_Limited_With
(Formal_Type
)
11298 and then Is_Class_Wide_Default
(Default
)
11299 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
11302 ("access to class-wide expression not allowed here", Default
);
11305 -- Check incorrect use of dynamically tagged expressions
11307 if Is_Tagged_Type
(Formal_Type
) then
11308 Check_Dynamically_Tagged_Expression
11310 Typ
=> Formal_Type
,
11311 Related_Nod
=> Default
);
11315 -- Ada 2005 (AI-231): Static checks
11317 if Ada_Version
>= Ada_2005
11318 and then Is_Access_Type
(Etype
(Formal
))
11319 and then Can_Never_Be_Null
(Etype
(Formal
))
11321 Null_Exclusion_Static_Checks
(Param_Spec
);
11324 -- The following checks are relevant only when SPARK_Mode is on as
11325 -- these are not standard Ada legality rules.
11327 if SPARK_Mode
= On
then
11328 if Ekind_In
(Scope
(Formal
), E_Function
, E_Generic_Function
) then
11330 -- A function cannot have a parameter of mode IN OUT or OUT
11333 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_Out_Parameter
) then
11335 ("function cannot have parameter of mode `OUT` or "
11336 & "`IN OUT`", Formal
);
11339 -- A procedure cannot have an effectively volatile formal
11340 -- parameter of mode IN because it behaves as a constant
11341 -- (SPARK RM 7.1.3(6)). -- ??? maybe 7.1.3(4)
11343 elsif Ekind
(Scope
(Formal
)) = E_Procedure
11344 and then Ekind
(Formal
) = E_In_Parameter
11345 and then Is_Effectively_Volatile
(Formal
)
11348 ("formal parameter of mode `IN` cannot be volatile", Formal
);
11356 -- If this is the formal part of a function specification, analyze the
11357 -- subtype mark in the context where the formals are visible but not
11358 -- yet usable, and may hide outer homographs.
11360 if Nkind
(Related_Nod
) = N_Function_Specification
then
11361 Analyze_Return_Type
(Related_Nod
);
11364 -- Now set the kind (mode) of each formal
11366 Param_Spec
:= First
(T
);
11367 while Present
(Param_Spec
) loop
11368 Formal
:= Defining_Identifier
(Param_Spec
);
11369 Set_Formal_Mode
(Formal
);
11371 if Ekind
(Formal
) = E_In_Parameter
then
11372 Set_Default_Value
(Formal
, Expression
(Param_Spec
));
11374 if Present
(Expression
(Param_Spec
)) then
11375 Default
:= Expression
(Param_Spec
);
11377 if Is_Scalar_Type
(Etype
(Default
)) then
11378 if Nkind
(Parameter_Type
(Param_Spec
)) /=
11379 N_Access_Definition
11381 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
11385 (Related_Nod
, Parameter_Type
(Param_Spec
));
11388 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
11392 elsif Ekind
(Formal
) = E_Out_Parameter
then
11393 Num_Out_Params
:= Num_Out_Params
+ 1;
11395 if Num_Out_Params
= 1 then
11396 First_Out_Param
:= Formal
;
11399 elsif Ekind
(Formal
) = E_In_Out_Parameter
then
11400 Num_Out_Params
:= Num_Out_Params
+ 1;
11403 -- Skip remaining processing if formal type was in error
11405 if Etype
(Formal
) = Any_Type
or else Error_Posted
(Formal
) then
11406 goto Next_Parameter
;
11409 -- Force call by reference if aliased
11412 Conv
: constant Convention_Id
:= Convention
(Etype
(Formal
));
11414 if Is_Aliased
(Formal
) then
11415 Set_Mechanism
(Formal
, By_Reference
);
11417 -- Warn if user asked this to be passed by copy
11419 if Conv
= Convention_Ada_Pass_By_Copy
then
11421 ("cannot pass aliased parameter & by copy??", Formal
);
11424 -- Force mechanism if type has Convention Ada_Pass_By_Ref/Copy
11426 elsif Conv
= Convention_Ada_Pass_By_Copy
then
11427 Set_Mechanism
(Formal
, By_Copy
);
11429 elsif Conv
= Convention_Ada_Pass_By_Reference
then
11430 Set_Mechanism
(Formal
, By_Reference
);
11438 if Present
(First_Out_Param
) and then Num_Out_Params
= 1 then
11439 Set_Is_Only_Out_Parameter
(First_Out_Param
);
11441 end Process_Formals
;
11443 ----------------------------
11444 -- Reference_Body_Formals --
11445 ----------------------------
11447 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
) is
11452 if Error_Posted
(Spec
) then
11456 -- Iterate over both lists. They may be of different lengths if the two
11457 -- specs are not conformant.
11459 Fs
:= First_Formal
(Spec
);
11460 Fb
:= First_Formal
(Bod
);
11461 while Present
(Fs
) and then Present
(Fb
) loop
11462 Generate_Reference
(Fs
, Fb
, 'b');
11464 if Style_Check
then
11465 Style
.Check_Identifier
(Fb
, Fs
);
11468 Set_Spec_Entity
(Fb
, Fs
);
11469 Set_Referenced
(Fs
, False);
11473 end Reference_Body_Formals
;
11475 -------------------------
11476 -- Set_Actual_Subtypes --
11477 -------------------------
11479 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
11481 Formal
: Entity_Id
;
11483 First_Stmt
: Node_Id
:= Empty
;
11484 AS_Needed
: Boolean;
11487 -- If this is an empty initialization procedure, no need to create
11488 -- actual subtypes (small optimization).
11490 if Ekind
(Subp
) = E_Procedure
and then Is_Null_Init_Proc
(Subp
) then
11494 -- The subtype declarations may freeze the formals. The body generated
11495 -- for an expression function is not a freeze point, so do not emit
11496 -- these declarations (small loss of efficiency in rare cases).
11498 if Nkind
(N
) = N_Subprogram_Body
11499 and then Was_Expression_Function
(N
)
11504 Formal
:= First_Formal
(Subp
);
11505 while Present
(Formal
) loop
11506 T
:= Etype
(Formal
);
11508 -- We never need an actual subtype for a constrained formal
11510 if Is_Constrained
(T
) then
11511 AS_Needed
:= False;
11513 -- If we have unknown discriminants, then we do not need an actual
11514 -- subtype, or more accurately we cannot figure it out. Note that
11515 -- all class-wide types have unknown discriminants.
11517 elsif Has_Unknown_Discriminants
(T
) then
11518 AS_Needed
:= False;
11520 -- At this stage we have an unconstrained type that may need an
11521 -- actual subtype. For sure the actual subtype is needed if we have
11522 -- an unconstrained array type. However, in an instance, the type
11523 -- may appear as a subtype of the full view, while the actual is
11524 -- in fact private (in which case no actual subtype is needed) so
11525 -- check the kind of the base type.
11527 elsif Is_Array_Type
(Base_Type
(T
)) then
11530 -- The only other case needing an actual subtype is an unconstrained
11531 -- record type which is an IN parameter (we cannot generate actual
11532 -- subtypes for the OUT or IN OUT case, since an assignment can
11533 -- change the discriminant values. However we exclude the case of
11534 -- initialization procedures, since discriminants are handled very
11535 -- specially in this context, see the section entitled "Handling of
11536 -- Discriminants" in Einfo.
11538 -- We also exclude the case of Discrim_SO_Functions (functions used
11539 -- in front-end layout mode for size/offset values), since in such
11540 -- functions only discriminants are referenced, and not only are such
11541 -- subtypes not needed, but they cannot always be generated, because
11542 -- of order of elaboration issues.
11544 elsif Is_Record_Type
(T
)
11545 and then Ekind
(Formal
) = E_In_Parameter
11546 and then Chars
(Formal
) /= Name_uInit
11547 and then not Is_Unchecked_Union
(T
)
11548 and then not Is_Discrim_SO_Function
(Subp
)
11552 -- All other cases do not need an actual subtype
11555 AS_Needed
:= False;
11558 -- Generate actual subtypes for unconstrained arrays and
11559 -- unconstrained discriminated records.
11562 if Nkind
(N
) = N_Accept_Statement
then
11564 -- If expansion is active, the formal is replaced by a local
11565 -- variable that renames the corresponding entry of the
11566 -- parameter block, and it is this local variable that may
11567 -- require an actual subtype.
11569 if Expander_Active
then
11570 Decl
:= Build_Actual_Subtype
(T
, Renamed_Object
(Formal
));
11572 Decl
:= Build_Actual_Subtype
(T
, Formal
);
11575 if Present
(Handled_Statement_Sequence
(N
)) then
11577 First
(Statements
(Handled_Statement_Sequence
(N
)));
11578 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
11579 Mark_Rewrite_Insertion
(Decl
);
11581 -- If the accept statement has no body, there will be no
11582 -- reference to the actuals, so no need to compute actual
11589 Decl
:= Build_Actual_Subtype
(T
, Formal
);
11590 Prepend
(Decl
, Declarations
(N
));
11591 Mark_Rewrite_Insertion
(Decl
);
11594 -- The declaration uses the bounds of an existing object, and
11595 -- therefore needs no constraint checks.
11597 Analyze
(Decl
, Suppress
=> All_Checks
);
11598 Set_Is_Actual_Subtype
(Defining_Identifier
(Decl
));
11600 -- We need to freeze manually the generated type when it is
11601 -- inserted anywhere else than in a declarative part.
11603 if Present
(First_Stmt
) then
11604 Insert_List_Before_And_Analyze
(First_Stmt
,
11605 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
11607 -- Ditto if the type has a dynamic predicate, because the
11608 -- generated function will mention the actual subtype. The
11609 -- predicate may come from an explicit aspect of be inherited.
11611 elsif Has_Predicates
(T
) then
11612 Insert_List_Before_And_Analyze
(Decl
,
11613 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
11616 if Nkind
(N
) = N_Accept_Statement
11617 and then Expander_Active
11619 Set_Actual_Subtype
(Renamed_Object
(Formal
),
11620 Defining_Identifier
(Decl
));
11622 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
11626 Next_Formal
(Formal
);
11628 end Set_Actual_Subtypes
;
11630 ---------------------
11631 -- Set_Formal_Mode --
11632 ---------------------
11634 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
11635 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
11636 Id
: constant Entity_Id
:= Scope
(Formal_Id
);
11639 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
11640 -- since we ensure that corresponding actuals are always valid at the
11641 -- point of the call.
11643 if Out_Present
(Spec
) then
11644 if Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
11645 or else Is_Subprogram_Or_Generic_Subprogram
(Id
)
11647 Set_Has_Out_Or_In_Out_Parameter
(Id
, True);
11650 if Ekind_In
(Id
, E_Function
, E_Generic_Function
) then
11652 -- [IN] OUT parameters allowed for functions in Ada 2012
11654 if Ada_Version
>= Ada_2012
then
11656 -- Even in Ada 2012 operators can only have IN parameters
11658 if Is_Operator_Symbol_Name
(Chars
(Scope
(Formal_Id
))) then
11659 Error_Msg_N
("operators can only have IN parameters", Spec
);
11662 if In_Present
(Spec
) then
11663 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
11665 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
11668 -- But not in earlier versions of Ada
11671 Error_Msg_N
("functions can only have IN parameters", Spec
);
11672 Set_Ekind
(Formal_Id
, E_In_Parameter
);
11675 elsif In_Present
(Spec
) then
11676 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
11679 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
11680 Set_Never_Set_In_Source
(Formal_Id
, True);
11681 Set_Is_True_Constant
(Formal_Id
, False);
11682 Set_Current_Value
(Formal_Id
, Empty
);
11686 Set_Ekind
(Formal_Id
, E_In_Parameter
);
11689 -- Set Is_Known_Non_Null for access parameters since the language
11690 -- guarantees that access parameters are always non-null. We also set
11691 -- Can_Never_Be_Null, since there is no way to change the value.
11693 if Nkind
(Parameter_Type
(Spec
)) = N_Access_Definition
then
11695 -- Ada 2005 (AI-231): In Ada 95, access parameters are always non-
11696 -- null; In Ada 2005, only if then null_exclusion is explicit.
11698 if Ada_Version
< Ada_2005
11699 or else Can_Never_Be_Null
(Etype
(Formal_Id
))
11701 Set_Is_Known_Non_Null
(Formal_Id
);
11702 Set_Can_Never_Be_Null
(Formal_Id
);
11705 -- Ada 2005 (AI-231): Null-exclusion access subtype
11707 elsif Is_Access_Type
(Etype
(Formal_Id
))
11708 and then Can_Never_Be_Null
(Etype
(Formal_Id
))
11710 Set_Is_Known_Non_Null
(Formal_Id
);
11712 -- We can also set Can_Never_Be_Null (thus preventing some junk
11713 -- access checks) for the case of an IN parameter, which cannot
11714 -- be changed, or for an IN OUT parameter, which can be changed but
11715 -- not to a null value. But for an OUT parameter, the initial value
11716 -- passed in can be null, so we can't set this flag in that case.
11718 if Ekind
(Formal_Id
) /= E_Out_Parameter
then
11719 Set_Can_Never_Be_Null
(Formal_Id
);
11723 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
11724 Set_Formal_Validity
(Formal_Id
);
11725 end Set_Formal_Mode
;
11727 -------------------------
11728 -- Set_Formal_Validity --
11729 -------------------------
11731 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
11733 -- If no validity checking, then we cannot assume anything about the
11734 -- validity of parameters, since we do not know there is any checking
11735 -- of the validity on the call side.
11737 if not Validity_Checks_On
then
11740 -- If validity checking for parameters is enabled, this means we are
11741 -- not supposed to make any assumptions about argument values.
11743 elsif Validity_Check_Parameters
then
11746 -- If we are checking in parameters, we will assume that the caller is
11747 -- also checking parameters, so we can assume the parameter is valid.
11749 elsif Ekind
(Formal_Id
) = E_In_Parameter
11750 and then Validity_Check_In_Params
11752 Set_Is_Known_Valid
(Formal_Id
, True);
11754 -- Similar treatment for IN OUT parameters
11756 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
11757 and then Validity_Check_In_Out_Params
11759 Set_Is_Known_Valid
(Formal_Id
, True);
11761 end Set_Formal_Validity
;
11763 ------------------------
11764 -- Subtype_Conformant --
11765 ------------------------
11767 function Subtype_Conformant
11768 (New_Id
: Entity_Id
;
11769 Old_Id
: Entity_Id
;
11770 Skip_Controlling_Formals
: Boolean := False) return Boolean
11774 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
,
11775 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
11777 end Subtype_Conformant
;
11779 ---------------------
11780 -- Type_Conformant --
11781 ---------------------
11783 function Type_Conformant
11784 (New_Id
: Entity_Id
;
11785 Old_Id
: Entity_Id
;
11786 Skip_Controlling_Formals
: Boolean := False) return Boolean
11790 May_Hide_Profile
:= False;
11792 (New_Id
, Old_Id
, Type_Conformant
, False, Result
,
11793 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
11795 end Type_Conformant
;
11797 -------------------------------
11798 -- Valid_Operator_Definition --
11799 -------------------------------
11801 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
11804 Id
: constant Name_Id
:= Chars
(Designator
);
11808 F
:= First_Formal
(Designator
);
11809 while Present
(F
) loop
11812 if Present
(Default_Value
(F
)) then
11814 ("default values not allowed for operator parameters",
11817 -- For function instantiations that are operators, we must check
11818 -- separately that the corresponding generic only has in-parameters.
11819 -- For subprogram declarations this is done in Set_Formal_Mode. Such
11820 -- an error could not arise in earlier versions of the language.
11822 elsif Ekind
(F
) /= E_In_Parameter
then
11823 Error_Msg_N
("operators can only have IN parameters", F
);
11829 -- Verify that user-defined operators have proper number of arguments
11830 -- First case of operators which can only be unary
11832 if Nam_In
(Id
, Name_Op_Not
, Name_Op_Abs
) then
11835 -- Case of operators which can be unary or binary
11837 elsif Nam_In
(Id
, Name_Op_Add
, Name_Op_Subtract
) then
11838 N_OK
:= (N
in 1 .. 2);
11840 -- All other operators can only be binary
11848 ("incorrect number of arguments for operator", Designator
);
11852 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
11853 and then not Is_Intrinsic_Subprogram
(Designator
)
11856 ("explicit definition of inequality not allowed", Designator
);
11858 end Valid_Operator_Definition
;