1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 Accessibility
; use Accessibility
;
27 with Aspects
; use Aspects
;
28 with Atree
; use Atree
;
29 with Checks
; use Checks
;
30 with Contracts
; use Contracts
;
31 with Debug
; use Debug
;
32 with Einfo
; use Einfo
;
33 with Einfo
.Entities
; use Einfo
.Entities
;
34 with Einfo
.Utils
; use Einfo
.Utils
;
35 with Elists
; use Elists
;
36 with Errout
; use Errout
;
37 with Expander
; use Expander
;
38 with Exp_Ch3
; use Exp_Ch3
;
39 with Exp_Ch6
; use Exp_Ch6
;
40 with Exp_Ch9
; use Exp_Ch9
;
41 with Exp_Dbug
; use Exp_Dbug
;
42 with Exp_Tss
; use Exp_Tss
;
43 with Exp_Util
; use Exp_Util
;
44 with Freeze
; use Freeze
;
45 with Ghost
; use Ghost
;
46 with Inline
; use Inline
;
47 with Itypes
; use Itypes
;
48 with Lib
.Xref
; use Lib
.Xref
;
49 with Layout
; use Layout
;
50 with Namet
; use Namet
;
52 with Nlists
; use Nlists
;
53 with Nmake
; use Nmake
;
55 with Output
; use Output
;
56 with Rtsfind
; use Rtsfind
;
58 with Sem_Aux
; use Sem_Aux
;
59 with Sem_Cat
; use Sem_Cat
;
60 with Sem_Ch3
; use Sem_Ch3
;
61 with Sem_Ch4
; use Sem_Ch4
;
62 with Sem_Ch5
; use Sem_Ch5
;
63 with Sem_Ch8
; use Sem_Ch8
;
64 with Sem_Ch9
; use Sem_Ch9
;
65 with Sem_Ch10
; use Sem_Ch10
;
66 with Sem_Ch12
; use Sem_Ch12
;
67 with Sem_Ch13
; use Sem_Ch13
;
68 with Sem_Dim
; use Sem_Dim
;
69 with Sem_Disp
; use Sem_Disp
;
70 with Sem_Dist
; use Sem_Dist
;
71 with Sem_Elim
; use Sem_Elim
;
72 with Sem_Eval
; use Sem_Eval
;
73 with Sem_Mech
; use Sem_Mech
;
74 with Sem_Prag
; use Sem_Prag
;
75 with Sem_Res
; use Sem_Res
;
76 with Sem_Util
; use Sem_Util
;
77 with Sem_Type
; use Sem_Type
;
78 with Sem_Warn
; use Sem_Warn
;
79 with Sinput
; use Sinput
;
80 with Stand
; use Stand
;
81 with Sinfo
; use Sinfo
;
82 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
83 with Sinfo
.Utils
; use Sinfo
.Utils
;
84 with Sinfo
.CN
; use Sinfo
.CN
;
85 with Snames
; use Snames
;
86 with Stringt
; use Stringt
;
88 with Stylesw
; use Stylesw
;
89 with Tbuild
; use Tbuild
;
90 with Uintp
; use Uintp
;
91 with Urealp
; use Urealp
;
92 with Validsw
; use Validsw
;
93 with Warnsw
; use Warnsw
;
95 package body Sem_Ch6
is
97 May_Hide_Profile
: Boolean := False;
98 -- This flag is used to indicate that two formals in two subprograms being
99 -- checked for conformance differ only in that one is an access parameter
100 -- while the other is of a general access type with the same designated
101 -- type. In this case, if the rest of the signatures match, a call to
102 -- either subprogram may be ambiguous, which is worth a warning. The flag
103 -- is set in Compatible_Types, and the warning emitted in
104 -- New_Overloaded_Entity.
106 -----------------------
107 -- Local Subprograms --
108 -----------------------
110 procedure Analyze_Function_Return
(N
: Node_Id
);
111 -- Subsidiary to Analyze_Return_Statement. Called when the return statement
112 -- applies to a [generic] function.
114 procedure Analyze_Generic_Subprogram_Body
(N
: Node_Id
; Gen_Id
: Entity_Id
);
115 -- Analyze a generic subprogram body. N is the body to be analyzed, and
116 -- Gen_Id is the defining entity Id for the corresponding spec.
118 procedure Analyze_Null_Procedure
120 Is_Completion
: out Boolean);
121 -- A null procedure can be a declaration or (Ada 2012) a completion
123 procedure Analyze_Return_Statement
(N
: Node_Id
);
124 -- Common processing for simple and extended return statements
126 procedure Analyze_Return_Type
(N
: Node_Id
);
127 -- Subsidiary to Process_Formals: analyze subtype mark in function
128 -- specification in a context where the formals are visible and hide
131 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
);
132 -- Does all the real work of Analyze_Subprogram_Body. This is split out so
133 -- that we can use RETURN but not skip the debug output at the end.
135 procedure Check_Conformance
138 Ctype
: Conformance_Type
;
140 Conforms
: out Boolean;
141 Err_Loc
: Node_Id
:= Empty
;
142 Get_Inst
: Boolean := False;
143 Skip_Controlling_Formals
: Boolean := False);
144 -- Given two entities, this procedure checks that the profiles associated
145 -- with these entities meet the conformance criterion given by the third
146 -- parameter. If they conform, Conforms is set True and control returns
147 -- to the caller. If they do not conform, Conforms is set to False, and
148 -- in addition, if Errmsg is True on the call, proper messages are output
149 -- to complain about the conformance failure. If Err_Loc is non_Empty
150 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
151 -- error messages are placed on the appropriate part of the construct
152 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
153 -- against a formal access-to-subprogram type so Get_Instance_Of must
156 procedure Check_Formal_Subprogram_Conformance
161 Conforms
: out Boolean);
162 -- Core implementation of Check_Formal_Subprogram_Conformance from spec.
163 -- Errmsg can be set to False to not emit error messages.
164 -- Conforms is set to True if there is conformance, False otherwise.
166 procedure Check_Limited_Return
170 -- Check the appropriate (Ada 95 or Ada 2005) rules for returning limited
171 -- types. Used only for simple return statements. Expr is the expression
174 procedure Check_Subprogram_Order
(N
: Node_Id
);
175 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
176 -- the alpha ordering rule for N if this ordering requirement applicable.
178 procedure Check_Returns
182 Proc
: Entity_Id
:= Empty
);
183 -- Called to check for missing return statements in a function body, or for
184 -- returns present in a procedure body which has No_Return set. HSS is the
185 -- handled statement sequence for the subprogram body. This procedure
186 -- checks all flow paths to make sure they either have return (Mode = 'F',
187 -- used for functions) or do not have a return (Mode = 'P', used for
188 -- No_Return procedures). The flag Err is set if there are any control
189 -- paths not explicitly terminated by a return in the function case, and is
190 -- True otherwise. Proc is the entity for the procedure case and is used
191 -- in posting the warning message.
193 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
);
194 -- In Ada 2012, a primitive equality operator for an untagged record type
195 -- must appear before the type is frozen. This procedure checks that this
196 -- rule is met, and otherwise gives an error on the subprogram declaration
197 -- and a warning on the earlier freeze point if it is easy to pinpoint. In
198 -- earlier versions of Ada, the call has not effect, unless compatibility
199 -- warnings are requested by means of Warn_On_Ada_2012_Incompatibility.
201 procedure Enter_Overloaded_Entity
(S
: Entity_Id
);
202 -- This procedure makes S, a new overloaded entity, into the first visible
203 -- entity with that name.
205 function Has_Reliable_Extra_Formals
(E
: Entity_Id
) return Boolean;
206 -- E is the entity for a subprogram spec. Returns False for abstract
207 -- predefined dispatching primitives of Root_Controlled since they
208 -- cannot have extra formals (this is required to build the runtime);
209 -- it also returns False for predefined stream dispatching operations
210 -- not emitted by the frontend. Otherwise returns True.
212 function Is_Non_Overriding_Operation
214 New_E
: Entity_Id
) return Boolean;
215 -- Enforce the rule given in 12.3(18): a private operation in an instance
216 -- overrides an inherited operation only if the corresponding operation
217 -- was overriding in the generic. This needs to be checked for primitive
218 -- operations of types derived (in the generic unit) from formal private
219 -- or formal derived types.
221 procedure Make_Inequality_Operator
(S
: Entity_Id
);
222 -- Create the declaration for an inequality operator that is implicitly
223 -- created by a user-defined equality operator that yields a boolean.
225 procedure Preanalyze_Formal_Expression
(N
: Node_Id
; T
: Entity_Id
);
226 -- Preanalysis of default expressions of subprogram formals. N is the
227 -- expression to be analyzed and T is the expected type.
229 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
);
230 -- Set proper Ekind to reflect formal mode (in, out, in out), and set
231 -- miscellaneous other attributes.
233 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
);
234 -- Formal_Id is an formal parameter entity. This procedure deals with
235 -- setting the proper validity status for this entity, which depends on
236 -- the kind of parameter and the validity checking mode.
238 ---------------------------------------------
239 -- Analyze_Abstract_Subprogram_Declaration --
240 ---------------------------------------------
242 procedure Analyze_Abstract_Subprogram_Declaration
(N
: Node_Id
) is
243 Scop
: constant Entity_Id
:= Current_Scope
;
244 Subp_Id
: constant Entity_Id
:=
245 Analyze_Subprogram_Specification
(Specification
(N
));
248 Generate_Definition
(Subp_Id
);
250 -- Set the SPARK mode from the current context (may be overwritten later
251 -- with explicit pragma).
253 Set_SPARK_Pragma
(Subp_Id
, SPARK_Mode_Pragma
);
254 Set_SPARK_Pragma_Inherited
(Subp_Id
);
256 -- Preserve relevant elaboration-related attributes of the context which
257 -- are no longer available or very expensive to recompute once analysis,
258 -- resolution, and expansion are over.
260 Mark_Elaboration_Attributes
265 Set_Is_Abstract_Subprogram
(Subp_Id
);
266 New_Overloaded_Entity
(Subp_Id
);
267 Check_Delayed_Subprogram
(Subp_Id
);
269 Set_Categorization_From_Scope
(Subp_Id
, Scop
);
271 if Ekind
(Scope
(Subp_Id
)) = E_Protected_Type
then
272 Error_Msg_N
("abstract subprogram not allowed in protected type", N
);
274 -- Issue a warning if the abstract subprogram is neither a dispatching
275 -- operation nor an operation that overrides an inherited subprogram or
276 -- predefined operator, since this most likely indicates a mistake.
278 elsif Warn_On_Redundant_Constructs
279 and then not Is_Dispatching_Operation
(Subp_Id
)
280 and then No
(Overridden_Operation
(Subp_Id
))
281 and then (not Is_Operator_Symbol_Name
(Chars
(Subp_Id
))
282 or else Scop
/= Scope
(Etype
(First_Formal
(Subp_Id
))))
285 ("abstract subprogram is not dispatching or overriding?r?", N
);
288 Generate_Reference_To_Formals
(Subp_Id
);
289 Check_Eliminated
(Subp_Id
);
291 if Has_Aspects
(N
) then
292 Analyze_Aspect_Specifications
(N
, Subp_Id
);
294 end Analyze_Abstract_Subprogram_Declaration
;
296 ---------------------------------
297 -- Analyze_Expression_Function --
298 ---------------------------------
300 procedure Analyze_Expression_Function
(N
: Node_Id
) is
301 Expr
: constant Node_Id
:= Expression
(N
);
302 Loc
: constant Source_Ptr
:= Sloc
(N
);
303 LocX
: constant Source_Ptr
:= Sloc
(Expr
);
304 Spec
: constant Node_Id
:= Specification
(N
);
311 Orig_N
: Node_Id
:= Empty
;
313 Typ
: Entity_Id
:= Empty
;
315 Def_Id
: Entity_Id
:= Empty
;
317 -- If the expression is a completion, Prev is the entity whose
318 -- declaration is completed. Def_Id is needed to analyze the spec.
321 -- This is one of the occasions on which we transform the tree during
322 -- semantic analysis. If this is a completion, transform the expression
323 -- function into an equivalent subprogram body, and analyze it.
325 -- Expression functions are inlined unconditionally. The back-end will
326 -- determine whether this is possible.
328 Inline_Processing_Required
:= True;
330 -- Create a specification for the generated body. This must be done
331 -- prior to the analysis of the initial declaration.
333 New_Spec
:= Copy_Subprogram_Spec
(Spec
);
334 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
336 -- If there are previous overloadable entities with the same name,
337 -- check whether any of them is completed by the expression function.
338 -- In a generic context a formal subprogram has no completion.
341 and then Is_Overloadable
(Prev
)
342 and then not Is_Formal_Subprogram
(Prev
)
344 Def_Id
:= Analyze_Subprogram_Specification
(Spec
);
345 Prev
:= Find_Corresponding_Spec
(N
);
347 Typ
:= Etype
(Def_Id
);
349 -- The previous entity may be an expression function as well, in
350 -- which case the redeclaration is illegal.
353 and then Nkind
(Original_Node
(Unit_Declaration_Node
(Prev
))) =
354 N_Expression_Function
356 Error_Msg_Sloc
:= Sloc
(Prev
);
357 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
362 Ret
:= Make_Simple_Return_Statement
(LocX
, Expr
);
364 -- Remove parens around the expression, so that if the expression will
365 -- appear without them when pretty-printed in error messages.
367 if Paren_Count
(Expr
) > 0 then
368 Set_Paren_Count
(Expr
, Paren_Count
(Expr
) - 1);
372 Make_Subprogram_Body
(Loc
,
373 Specification
=> New_Spec
,
374 Declarations
=> Empty_List
,
375 Handled_Statement_Sequence
=>
376 Make_Handled_Sequence_Of_Statements
(LocX
,
377 Statements
=> New_List
(Ret
)));
378 Set_Was_Expression_Function
(New_Body
);
380 -- If the expression completes a generic subprogram, we must create a
381 -- separate node for the body, because at instantiation the original
382 -- node of the generic copy must be a generic subprogram body, and
383 -- cannot be a expression function. Otherwise we just rewrite the
384 -- expression with the non-generic body.
386 if Present
(Prev
) and then Ekind
(Prev
) = E_Generic_Function
then
387 Insert_After
(N
, New_Body
);
389 -- Propagate any aspects or pragmas that apply to the expression
390 -- function to the proper body when the expression function acts
393 Move_Aspects
(N
, To
=> New_Body
);
395 Relocate_Pragmas_To_Body
(New_Body
);
397 Rewrite
(N
, Make_Null_Statement
(Loc
));
398 Set_Has_Completion
(Prev
, False);
401 Set_Is_Inlined
(Prev
);
404 and then Is_Overloadable
(Prev
)
405 and then not Is_Formal_Subprogram
(Prev
)
407 Set_Has_Completion
(Prev
, False);
408 Set_Is_Inlined
(Prev
);
410 -- AI12-0103: Expression functions that are a completion freeze their
411 -- expression but don't freeze anything else (unlike regular bodies).
413 -- Note that we cannot defer this freezing to the analysis of the
414 -- expression itself, because a freeze node might appear in a nested
415 -- scope, leading to an elaboration order issue in gigi.
416 -- As elsewhere, we do not emit freeze nodes within a generic unit.
418 if not Inside_A_Generic
then
426 -- For navigation purposes, indicate that the function is a body
428 Generate_Reference
(Prev
, Defining_Entity
(N
), 'b', Force
=> True);
429 Rewrite
(N
, New_Body
);
431 -- Remove any existing aspects from the original node because the act
432 -- of rewriting causes the list to be shared between the two nodes.
434 Orig_N
:= Original_Node
(N
);
435 Remove_Aspects
(Orig_N
);
437 -- Propagate any pragmas that apply to expression function to the
438 -- proper body when the expression function acts as a completion.
439 -- Aspects are automatically transfered because of node rewriting.
441 Relocate_Pragmas_To_Body
(N
);
444 -- Prev is the previous entity with the same name, but it is can
445 -- be an unrelated spec that is not completed by the expression
446 -- function. In that case the relevant entity is the one in the body.
447 -- Not clear that the backend can inline it in this case ???
449 if Has_Completion
(Prev
) then
451 -- The formals of the expression function are body formals,
452 -- and do not appear in the ali file, which will only contain
453 -- references to the formals of the original subprogram spec.
460 F1
:= First_Formal
(Def_Id
);
461 F2
:= First_Formal
(Prev
);
463 while Present
(F1
) loop
464 Set_Spec_Entity
(F1
, F2
);
471 Set_Is_Inlined
(Defining_Entity
(New_Body
));
474 -- If this is not a completion, create both a declaration and a body, so
475 -- that the expression can be inlined whenever possible.
478 -- An expression function that is not a completion is not a
479 -- subprogram declaration, and thus cannot appear in a protected
482 if Nkind
(Parent
(N
)) = N_Protected_Definition
then
484 ("an expression function is not a legal protected operation", N
);
487 Rewrite
(N
, Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
));
489 -- Remove any existing aspects from the original node because the act
490 -- of rewriting causes the list to be shared between the two nodes.
492 Orig_N
:= Original_Node
(N
);
493 Remove_Aspects
(Orig_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
);
509 Set_Is_Inlined
(Def_Id
);
511 Typ
:= Etype
(Def_Id
);
513 -- Establish the linkages between the spec and the body. These are
514 -- used when the expression function acts as the prefix of attribute
515 -- 'Access in order to freeze the original expression which has been
516 -- moved to the generated body.
518 Set_Corresponding_Body
(N
, Defining_Entity
(New_Body
));
519 Set_Corresponding_Spec
(New_Body
, Def_Id
);
521 -- Within a generic preanalyze the original expression for name
522 -- capture. The body is also generated but plays no role in
523 -- this because it is not part of the original source.
524 -- If this is an ignored Ghost entity, analysis of the generated
525 -- body is needed to hide external references (as is done in
526 -- Analyze_Subprogram_Body) after which the subprogram profile
527 -- can be frozen, which is needed to expand calls to such an ignored
530 if Inside_A_Generic
then
531 Set_Has_Completion
(Def_Id
, not Is_Ignored_Ghost_Entity
(Def_Id
));
533 Install_Formals
(Def_Id
);
534 Preanalyze_Spec_Expression
(Expr
, Typ
);
538 Install_Formals
(Def_Id
);
539 Preanalyze_Formal_Expression
(Expr
, Typ
);
540 Check_Limited_Return
(Orig_N
, Expr
, Typ
);
544 -- If this is a wrapper created in an instance for a formal
545 -- subprogram, insert body after declaration, to be analyzed when the
546 -- enclosing instance is analyzed.
549 and then Is_Generic_Actual_Subprogram
(Def_Id
)
551 Insert_After
(N
, New_Body
);
553 -- To prevent premature freeze action, insert the new body at the end
554 -- of the current declarations, or at the end of the package spec.
555 -- However, resolve usage names now, to prevent spurious visibility
556 -- on later entities. Note that the function can now be called in
557 -- the current declarative part, which will appear to be prior to the
558 -- presence of the body in the code. There are nevertheless no order
559 -- of elaboration issues because all name resolution has taken place
560 -- at the point of declaration.
564 Decls
: List_Id
:= List_Containing
(N
);
565 Par
: constant Node_Id
:= Parent
(Decls
);
568 if Nkind
(Par
) = N_Package_Specification
569 and then Decls
= Visible_Declarations
(Par
)
570 and then not Is_Empty_List
(Private_Declarations
(Par
))
572 Decls
:= Private_Declarations
(Par
);
575 Insert_After
(Last
(Decls
), New_Body
);
579 -- In the case of an expression function marked with the aspect
580 -- Static, we need to check the requirement that the function's
581 -- expression is a potentially static expression. This is done
582 -- by making a full copy of the expression tree and performing
583 -- a special preanalysis on that tree with the global flag
584 -- Checking_Potentially_Static_Expression enabled. If the
585 -- resulting expression is static, then it's OK, but if not, that
586 -- means the expression violates the requirements of the Ada 2022
587 -- RM in 4.9(3.2/5-3.4/5) and we flag an error.
589 if Is_Static_Function
(Def_Id
) then
591 -- If a potentially static expr like "Parameter / 0"
592 -- is transformed into "(raise Constraint_Error)", then we
593 -- need to copy the Original_Node.
594 function Make_Expr_Copy
return Node_Id
is
595 (New_Copy_Tree
(if Expr
in N_Raise_xxx_Error_Id
596 then Original_Node
(Expr
)
599 if not Is_Static_Expression
(Expr
) then
601 Exp_Copy
: constant Node_Id
:= Make_Expr_Copy
;
603 Set_Checking_Potentially_Static_Expression
(True);
605 Preanalyze_Formal_Expression
(Exp_Copy
, Typ
);
607 if not Is_Static_Expression
(Exp_Copy
) then
609 ("static expression function requires "
610 & "potentially static expression", Expr
);
613 Set_Checking_Potentially_Static_Expression
(False);
617 -- We also make an additional copy of the expression and
618 -- replace the expression of the expression function with
619 -- this copy, because the currently present expression is
620 -- now associated with the body created for the static
621 -- expression function, which will later be analyzed and
622 -- possibly rewritten, and we need to have the separate
623 -- unanalyzed copy available for use with later static
627 (Original_Node
(Subprogram_Spec
(Def_Id
)),
630 -- Mark static expression functions as inlined, to ensure
631 -- that even calls with nonstatic actuals will be inlined.
633 Set_Has_Pragma_Inline
(Def_Id
);
634 Set_Is_Inlined
(Def_Id
);
639 -- Check incorrect use of dynamically tagged expression. This doesn't
640 -- fall out automatically when analyzing the generated function body,
641 -- because Check_Dynamically_Tagged_Expression deliberately ignores
642 -- nodes that don't come from source.
645 and then Is_Tagged_Type
(Typ
)
647 Check_Dynamically_Tagged_Expression
650 Related_Nod
=> Orig_N
);
653 -- We must enforce checks for unreferenced formals in our newly
654 -- generated function, so we propagate the referenced flag from the
655 -- original spec to the new spec as well as setting Comes_From_Source.
657 if Present
(Parameter_Specifications
(New_Spec
)) then
659 Form_New_Def
: Entity_Id
;
660 Form_New_Spec
: Node_Id
;
661 Form_Old_Def
: Entity_Id
;
662 Form_Old_Spec
: Node_Id
;
665 Form_New_Spec
:= First
(Parameter_Specifications
(New_Spec
));
666 Form_Old_Spec
:= First
(Parameter_Specifications
(Spec
));
668 while Present
(Form_New_Spec
) and then Present
(Form_Old_Spec
) loop
669 Form_New_Def
:= Defining_Identifier
(Form_New_Spec
);
670 Form_Old_Def
:= Defining_Identifier
(Form_Old_Spec
);
672 Set_Comes_From_Source
(Form_New_Def
, True);
674 -- Because of the usefulness of unreferenced controlling
675 -- formals we exempt them from unreferenced warnings by marking
676 -- them as always referenced.
678 Set_Referenced
(Form_Old_Def
,
679 (Is_Formal
(Form_Old_Def
)
680 and then Is_Controlling_Formal
(Form_Old_Def
))
681 or else Referenced
(Form_Old_Def
));
683 Next
(Form_New_Spec
);
684 Next
(Form_Old_Spec
);
688 end Analyze_Expression_Function
;
690 ---------------------------------------
691 -- Analyze_Extended_Return_Statement --
692 ---------------------------------------
694 procedure Analyze_Extended_Return_Statement
(N
: Node_Id
) is
696 Analyze_Return_Statement
(N
);
697 end Analyze_Extended_Return_Statement
;
699 ----------------------------
700 -- Analyze_Function_Call --
701 ----------------------------
703 procedure Analyze_Function_Call
(N
: Node_Id
) is
704 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
705 Func_Nam
: constant Node_Id
:= Name
(N
);
711 -- A call of the form A.B (X) may be an Ada 2005 call, which is
712 -- rewritten as B (A, X). If the rewriting is successful, the call
713 -- has been analyzed and we just return.
715 if Nkind
(Func_Nam
) = N_Selected_Component
716 and then Name
(N
) /= Func_Nam
717 and then Is_Rewrite_Substitution
(N
)
718 and then Present
(Etype
(N
))
723 -- If error analyzing name, then set Any_Type as result type and return
725 if Etype
(Func_Nam
) = Any_Type
then
726 Set_Etype
(N
, Any_Type
);
730 -- Otherwise analyze the parameters
732 Actual
:= First
(Actuals
);
733 while Present
(Actual
) loop
735 Check_Parameterless_Call
(Actual
);
740 end Analyze_Function_Call
;
742 -----------------------------
743 -- Analyze_Function_Return --
744 -----------------------------
746 procedure Analyze_Function_Return
(N
: Node_Id
) is
747 Loc
: constant Source_Ptr
:= Sloc
(N
);
748 Stm_Entity
: constant Entity_Id
:= Return_Statement_Entity
(N
);
749 Scope_Id
: constant Entity_Id
:= Return_Applies_To
(Stm_Entity
);
751 R_Type
: constant Entity_Id
:= Etype
(Scope_Id
);
752 -- Function result subtype
754 procedure Check_No_Return_Expression
(Return_Expr
: Node_Id
);
755 -- Ada 2022: Check that the return expression in a No_Return function
756 -- meets the conditions specified by RM 6.5.1(5.1/5).
758 --------------------------------
759 -- Check_No_Return_Expression --
760 --------------------------------
762 procedure Check_No_Return_Expression
(Return_Expr
: Node_Id
) is
763 Kind
: constant Node_Kind
:= Nkind
(Return_Expr
);
766 if Kind
= N_Raise_Expression
then
769 elsif Kind
= N_Function_Call
770 and then Is_Entity_Name
(Name
(Return_Expr
))
771 and then Ekind
(Entity
(Name
(Return_Expr
))) in
772 E_Function | E_Generic_Function
773 and then No_Return
(Entity
(Name
(Return_Expr
)))
779 ("illegal expression in RETURN statement of No_Return function",
782 ("\must be raise expression or call to No_Return (RM 6.5.1(5.1/5))",
784 end Check_No_Return_Expression
;
786 ---------------------
787 -- Local Variables --
788 ---------------------
791 Obj_Decl
: Node_Id
:= Empty
;
793 -- Start of processing for Analyze_Function_Return
796 Set_Return_Present
(Scope_Id
);
798 if Nkind
(N
) = N_Simple_Return_Statement
then
799 Expr
:= Expression
(N
);
801 -- Guard against a malformed expression. The parser may have tried to
802 -- recover but the node is not analyzable.
804 if Nkind
(Expr
) = N_Error
then
805 Set_Etype
(Expr
, Any_Type
);
806 Expander_Mode_Save_And_Set
(False);
810 -- The resolution of a controlled [extension] aggregate associated
811 -- with a return statement creates a temporary which needs to be
812 -- finalized on function exit. Wrap the return statement inside a
813 -- block so that the finalization machinery can detect this case.
814 -- This early expansion is done only when the return statement is
815 -- not part of a handled sequence of statements.
817 if Nkind
(Expr
) in N_Aggregate | N_Extension_Aggregate
818 and then Needs_Finalization
(R_Type
)
819 and then Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
822 Make_Block_Statement
(Loc
,
823 Handled_Statement_Sequence
=>
824 Make_Handled_Sequence_Of_Statements
(Loc
,
825 Statements
=> New_List
(Relocate_Node
(N
)))));
833 -- Ada 2005 (AI-251): If the type of the returned object is
834 -- an access to an interface type then we add an implicit type
835 -- conversion to force the displacement of the "this" pointer to
836 -- reference the secondary dispatch table. We cannot delay the
837 -- generation of this implicit conversion until the expansion
838 -- because in this case the type resolution changes the decoration
839 -- of the expression node to match R_Type; by contrast, if the
840 -- returned object is a class-wide interface type then it is too
841 -- early to generate here the implicit conversion since the return
842 -- statement may be rewritten by the expander into an extended
843 -- return statement whose expansion takes care of adding the
844 -- implicit type conversion to displace the pointer to the object.
847 and then Serious_Errors_Detected
= 0
848 and then Is_Access_Type
(R_Type
)
849 and then Nkind
(Expr
) not in N_Null | N_Raise_Expression
850 and then Is_Access_Type
(Etype
(Expr
))
851 and then Is_Interface
(Designated_Type
(R_Type
))
852 and then Is_Progenitor
(Designated_Type
(R_Type
),
853 Designated_Type
(Etype
(Expr
)))
855 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
859 Resolve
(Expr
, R_Type
);
860 Check_Limited_Return
(N
, Expr
, R_Type
);
862 Check_Return_Construct_Accessibility
(N
, Stm_Entity
);
864 -- Ada 2022 (AI12-0269): Any return statement that applies to a
865 -- nonreturning function shall be a simple_return_statement with
866 -- an expression that is a raise_expression, or else a call on a
867 -- nonreturning function, or else a parenthesized expression of
870 if Ada_Version
>= Ada_2022
871 and then No_Return
(Scope_Id
)
872 and then Comes_From_Source
(N
)
874 Check_No_Return_Expression
(Original_Node
(Expr
));
878 Obj_Decl
:= Last
(Return_Object_Declarations
(N
));
880 -- Analyze parts specific to extended_return_statement:
883 Has_Aliased
: constant Boolean := Aliased_Present
(Obj_Decl
);
884 HSS
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
887 Expr
:= Expression
(Obj_Decl
);
889 -- Note: The check for OK_For_Limited_Init will happen in
890 -- Analyze_Object_Declaration; we treat it as a normal
891 -- object declaration.
893 Set_Is_Return_Object
(Defining_Identifier
(Obj_Decl
));
896 if Present
(HSS
) then
899 if Present
(Exception_Handlers
(HSS
)) then
901 -- ???Has_Nested_Block_With_Handler needs to be set.
902 -- Probably by creating an actual N_Block_Statement.
903 -- Probably in Expand.
909 -- Mark the return object as referenced, since the return is an
910 -- implicit reference of the object.
912 Set_Referenced
(Defining_Identifier
(Obj_Decl
));
914 Check_References
(Stm_Entity
);
916 Check_Return_Construct_Accessibility
(N
, Stm_Entity
);
918 -- Check RM 6.5 (5.9/3)
920 if Has_Aliased
and then not Is_Immutably_Limited_Type
(R_Type
) then
921 if Ada_Version
< Ada_2012
922 and then Warn_On_Ada_2012_Compatibility
925 ("ALIASED only allowed for immutably limited return " &
926 "objects in Ada 2012?y?", N
);
930 ("ALIASED only allowed for immutably limited return " &
935 -- Ada 2022 (AI12-0269): Any return statement that applies to a
936 -- nonreturning function shall be a simple_return_statement.
938 if Ada_Version
>= Ada_2022
939 and then No_Return
(Scope_Id
)
940 and then Comes_From_Source
(N
)
943 ("extended RETURN statement not allowed in No_Return "
949 -- Case of Expr present
951 if Present
(Expr
) then
953 -- Defend against previous errors
955 if Nkind
(Expr
) = N_Empty
956 or else No
(Etype
(Expr
))
961 -- Apply constraint check. Note that this is done before the implicit
962 -- conversion of the expression done for anonymous access types to
963 -- ensure correct generation of the null-excluding check associated
964 -- with null-excluding expressions found in return statements. We
965 -- don't need a check if the subtype of the return object is the
966 -- same as the result subtype of the function.
968 if Nkind
(N
) /= N_Extended_Return_Statement
969 or else Nkind
(Obj_Decl
) /= N_Object_Declaration
970 or else Nkind
(Object_Definition
(Obj_Decl
)) not in N_Has_Entity
971 or else Entity
(Object_Definition
(Obj_Decl
)) /= R_Type
973 Apply_Constraint_Check
(Expr
, R_Type
);
976 -- The return value is converted to the return type of the function,
977 -- which implies a predicate check if the return type is predicated.
978 -- We do not apply the check for an extended return statement because
979 -- Analyze_Object_Declaration has already done it on Obj_Decl above.
980 -- We do not apply the check to a case expression because it will
981 -- be expanded into a series of return statements, each of which
982 -- will receive a predicate check.
984 if Nkind
(N
) /= N_Extended_Return_Statement
985 and then Nkind
(Expr
) /= N_Case_Expression
987 Apply_Predicate_Check
(Expr
, R_Type
);
990 -- Ada 2005 (AI-318-02): When the result type is an anonymous access
991 -- type, apply an implicit conversion of the expression to that type
992 -- to force appropriate static and run-time accessibility checks.
993 -- But we want to apply the checks to an extended return statement
994 -- only once, i.e. not to the simple return statement generated at
995 -- the end of its expansion because, prior to leaving the function,
996 -- the accessibility level of the return object changes to be a level
997 -- determined by the point of call (RM 3.10.2(10.8/3)).
999 if Ada_Version
>= Ada_2005
1000 and then Ekind
(R_Type
) = E_Anonymous_Access_Type
1001 and then (Nkind
(N
) = N_Extended_Return_Statement
1002 or else not Comes_From_Extended_Return_Statement
(N
))
1004 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
1005 Analyze_And_Resolve
(Expr
, R_Type
);
1007 -- If this is a local anonymous access to subprogram, the
1008 -- accessibility check can be applied statically. The return is
1009 -- illegal if the access type of the return expression is declared
1010 -- inside of the subprogram (except if it is the subtype indication
1011 -- of an extended return statement).
1013 elsif Ekind
(R_Type
) = E_Anonymous_Access_Subprogram_Type
then
1014 if not Comes_From_Source
(Current_Scope
)
1015 or else Ekind
(Current_Scope
) = E_Return_Statement
1020 Scope_Depth
(Scope
(Etype
(Expr
))) >= Scope_Depth
(Scope_Id
)
1022 Error_Msg_N
("cannot return local access to subprogram", N
);
1025 -- The expression cannot be of a formal incomplete type
1027 elsif Ekind
(Etype
(Expr
)) = E_Incomplete_Type
1028 and then Is_Generic_Type
(Etype
(Expr
))
1031 ("cannot return expression of a formal incomplete type", N
);
1034 -- If the result type is class-wide, then check that the return
1035 -- expression's type is not declared at a deeper level than the
1036 -- function (RM05-6.5(5.6/2)).
1038 if Ada_Version
>= Ada_2005
1039 and then Is_Class_Wide_Type
(R_Type
)
1041 if Type_Access_Level
(Etype
(Expr
)) >
1042 Subprogram_Access_Level
(Scope_Id
)
1045 ("level of return expression type is deeper than "
1046 & "class-wide function!", Expr
);
1050 -- Check incorrect use of dynamically tagged expression
1052 if Is_Tagged_Type
(R_Type
) then
1053 Check_Dynamically_Tagged_Expression
1059 -- Perform static accessibility checks for cases involving
1060 -- dereferences of access parameters. Runtime accessibility checks
1061 -- get generated elsewhere.
1063 if (Ada_Version
< Ada_2005
or else Debug_Flag_Dot_L
)
1064 and then Is_Limited_View
(Etype
(Scope_Id
))
1065 and then Static_Accessibility_Level
(Expr
, Zero_On_Dynamic_Level
)
1066 > Subprogram_Access_Level
(Scope_Id
)
1068 -- Suppress the message in a generic, where the rewriting
1071 if Inside_A_Generic
then
1076 Make_Raise_Program_Error
(Loc
,
1077 Reason
=> PE_Accessibility_Check_Failed
));
1080 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1081 Error_Msg_N
("cannot return a local value by reference<<", N
);
1082 Error_Msg_N
("\Program_Error [<<", N
);
1086 if Known_Null
(Expr
)
1087 and then Nkind
(Parent
(Scope_Id
)) = N_Function_Specification
1088 and then Null_Exclusion_Present
(Parent
(Scope_Id
))
1090 Apply_Compile_Time_Constraint_Error
1092 Msg
=> "(Ada 2005) null not allowed for "
1093 & "null-excluding return??",
1094 Reason
=> CE_Null_Not_Allowed
);
1097 -- RM 6.5 (5.4/3): accessibility checks also apply if the return object
1098 -- has no initializing expression.
1100 elsif Ada_Version
> Ada_2005
and then Is_Class_Wide_Type
(R_Type
) then
1101 if Type_Access_Level
(Etype
(Defining_Identifier
(Obj_Decl
))) >
1102 Subprogram_Access_Level
(Scope_Id
)
1105 ("level of return expression type is deeper than "
1106 & "class-wide function!", Obj_Decl
);
1109 end Analyze_Function_Return
;
1111 -------------------------------------
1112 -- Analyze_Generic_Subprogram_Body --
1113 -------------------------------------
1115 procedure Analyze_Generic_Subprogram_Body
1119 Gen_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Gen_Id
);
1120 Kind
: constant Entity_Kind
:= Ekind
(Gen_Id
);
1121 Body_Id
: Entity_Id
;
1126 -- Copy body and disable expansion while analyzing the generic For a
1127 -- stub, do not copy the stub (which would load the proper body), this
1128 -- will be done when the proper body is analyzed.
1130 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1131 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
1134 -- Once the contents of the generic copy and the template are
1135 -- swapped, do the same for their respective aspect specifications.
1137 Exchange_Aspects
(N
, New_N
);
1139 -- Collect all contract-related source pragmas found within the
1140 -- template and attach them to the contract of the subprogram body.
1141 -- This contract is used in the capture of global references within
1144 Create_Generic_Contract
(N
);
1149 Spec
:= Specification
(N
);
1151 -- Within the body of the generic, the subprogram is callable, and
1152 -- behaves like the corresponding non-generic unit.
1154 Body_Id
:= Defining_Entity
(Spec
);
1156 if Kind
= E_Generic_Procedure
1157 and then Nkind
(Spec
) /= N_Procedure_Specification
1159 Error_Msg_N
("invalid body for generic procedure", Body_Id
);
1162 elsif Kind
= E_Generic_Function
1163 and then Nkind
(Spec
) /= N_Function_Specification
1165 Error_Msg_N
("invalid body for generic function", Body_Id
);
1169 Set_Corresponding_Body
(Gen_Decl
, Body_Id
);
1171 if Has_Completion
(Gen_Id
)
1172 and then Nkind
(Parent
(N
)) /= N_Subunit
1174 Error_Msg_N
("duplicate generic body", N
);
1177 Set_Has_Completion
(Gen_Id
);
1180 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1181 Mutate_Ekind
(Defining_Entity
(Specification
(N
)), Kind
);
1183 Set_Corresponding_Spec
(N
, Gen_Id
);
1186 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1187 Set_Cunit_Entity
(Current_Sem_Unit
, Defining_Entity
(N
));
1190 -- Make generic parameters immediately visible in the body. They are
1191 -- needed to process the formals declarations. Then make the formals
1192 -- visible in a separate step.
1194 Push_Scope
(Gen_Id
);
1198 First_Ent
: Entity_Id
;
1201 First_Ent
:= First_Entity
(Gen_Id
);
1204 while Present
(E
) and then not Is_Formal
(E
) loop
1209 Set_Use
(Generic_Formal_Declarations
(Gen_Decl
));
1211 -- Now generic formals are visible, and the specification can be
1212 -- analyzed, for subsequent conformance check.
1214 Body_Id
:= Analyze_Subprogram_Specification
(Spec
);
1216 -- Make formal parameters visible
1220 -- E is the first formal parameter, we loop through the formals
1221 -- installing them so that they will be visible.
1223 Set_First_Entity
(Gen_Id
, E
);
1224 while Present
(E
) loop
1230 -- Visible generic entity is callable within its own body
1232 Mutate_Ekind
(Gen_Id
, Ekind
(Body_Id
));
1233 Reinit_Field_To_Zero
(Body_Id
, F_Has_Out_Or_In_Out_Parameter
,
1235 (E_Function | E_Procedure |
1236 E_Generic_Function | E_Generic_Procedure
=> True,
1238 Reinit_Field_To_Zero
(Body_Id
, F_Needs_No_Actuals
);
1239 if Ekind
(Body_Id
) in E_Function | E_Procedure
then
1240 Reinit_Field_To_Zero
(Body_Id
, F_Is_Inlined_Always
);
1242 Mutate_Ekind
(Body_Id
, E_Subprogram_Body
);
1243 Set_Convention
(Body_Id
, Convention
(Gen_Id
));
1244 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Gen_Id
));
1245 Set_Scope
(Body_Id
, Scope
(Gen_Id
));
1247 Check_Fully_Conformant
(Body_Id
, Gen_Id
, Body_Id
);
1249 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1251 -- No body to analyze, so restore state of generic unit
1253 Mutate_Ekind
(Gen_Id
, Kind
);
1254 Mutate_Ekind
(Body_Id
, Kind
);
1256 if Present
(First_Ent
) then
1257 Set_First_Entity
(Gen_Id
, First_Ent
);
1264 -- If this is a compilation unit, it must be made visible explicitly,
1265 -- because the compilation of the declaration, unlike other library
1266 -- unit declarations, does not. If it is not a unit, the following
1267 -- is redundant but harmless.
1269 Set_Is_Immediately_Visible
(Gen_Id
);
1270 Reference_Body_Formals
(Gen_Id
, Body_Id
);
1272 if Is_Child_Unit
(Gen_Id
) then
1273 Generate_Reference
(Gen_Id
, Scope
(Gen_Id
), 'k', False);
1276 Set_Actual_Subtypes
(N
, Current_Scope
);
1278 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
1279 Set_SPARK_Pragma_Inherited
(Body_Id
);
1281 -- Analyze any aspect specifications that appear on the generic
1284 if Has_Aspects
(N
) then
1285 Analyze_Aspects_On_Subprogram_Body_Or_Stub
(N
);
1288 -- Process the contract of the subprogram body after analyzing all
1289 -- the contract-related pragmas within the declarations.
1291 Analyze_Pragmas_In_Declarations
(Body_Id
);
1292 Analyze_Entry_Or_Subprogram_Body_Contract
(Body_Id
);
1294 -- Continue on with analyzing the declarations and statements once
1295 -- contract expansion is done and we are done expanding contract
1296 -- related wrappers.
1298 Analyze_Declarations
(Declarations
(N
));
1301 Analyze
(Handled_Statement_Sequence
(N
));
1302 Save_Global_References
(Original_Node
(N
));
1304 -- Prior to exiting the scope, include generic formals again (if any
1305 -- are present) in the set of local entities.
1307 if Present
(First_Ent
) then
1308 Set_First_Entity
(Gen_Id
, First_Ent
);
1311 Check_References
(Gen_Id
);
1314 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Current_Scope
);
1315 Update_Use_Clause_Chain
;
1316 Validate_Categorization_Dependency
(N
, Gen_Id
);
1318 Check_Subprogram_Order
(N
);
1320 -- Outside of its body, unit is generic again
1322 Reinit_Field_To_Zero
(Gen_Id
, F_Has_Nested_Subprogram
,
1323 Old_Ekind
=> (E_Function | E_Procedure
=> True, others => False));
1324 Mutate_Ekind
(Gen_Id
, Kind
);
1325 Generate_Reference
(Gen_Id
, Body_Id
, 'b', Set_Ref
=> False);
1328 Style
.Check_Identifier
(Body_Id
, Gen_Id
);
1332 end Analyze_Generic_Subprogram_Body
;
1334 ----------------------------
1335 -- Analyze_Null_Procedure --
1336 ----------------------------
1338 -- WARNING: This routine manages Ghost regions. Return statements must be
1339 -- replaced by gotos that jump to the end of the routine and restore the
1342 procedure Analyze_Null_Procedure
1344 Is_Completion
: out Boolean)
1346 Loc
: constant Source_Ptr
:= Sloc
(N
);
1347 Spec
: constant Node_Id
:= Specification
(N
);
1349 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
1350 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
1351 Saved_ISMP
: constant Boolean :=
1352 Ignore_SPARK_Mode_Pragmas_In_Instance
;
1353 -- Save the Ghost and SPARK mode-related data to restore on exit
1355 Designator
: Entity_Id
;
1357 Null_Body
: Node_Id
:= Empty
;
1358 Null_Stmt
: Node_Id
:= Null_Statement
(Spec
);
1362 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
1364 -- A null procedure is Ghost when it is stand-alone and is subject to
1365 -- pragma Ghost, or when the corresponding spec is Ghost. Set the mode
1366 -- now, to ensure that any nodes generated during analysis and expansion
1367 -- are properly marked as Ghost.
1369 if Present
(Prev
) then
1370 Mark_And_Set_Ghost_Body
(N
, Prev
);
1373 -- Capture the profile of the null procedure before analysis, for
1374 -- expansion at the freeze point and at each point of call. The body is
1375 -- used if the procedure has preconditions, or if it is a completion. In
1376 -- the first case the body is analyzed at the freeze point, in the other
1377 -- it replaces the null procedure declaration.
1379 -- For a null procedure that comes from source, a NULL statement is
1380 -- provided by the parser, which carries the source location of the
1381 -- NULL keyword, and has Comes_From_Source set. For a null procedure
1382 -- from expansion, create one now.
1384 if No
(Null_Stmt
) then
1385 Null_Stmt
:= Make_Null_Statement
(Loc
);
1389 Make_Subprogram_Body
(Loc
,
1390 Specification
=> New_Copy_Tree
(Spec
),
1391 Declarations
=> New_List
,
1392 Handled_Statement_Sequence
=>
1393 Make_Handled_Sequence_Of_Statements
(Loc
,
1394 Statements
=> New_List
(Null_Stmt
)));
1396 -- Create new entities for body and formals
1398 Set_Defining_Unit_Name
(Specification
(Null_Body
),
1399 Make_Defining_Identifier
1400 (Sloc
(Defining_Entity
(N
)),
1401 Chars
(Defining_Entity
(N
))));
1403 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1404 while Present
(Form
) loop
1405 Set_Defining_Identifier
(Form
,
1406 Make_Defining_Identifier
1407 (Sloc
(Defining_Identifier
(Form
)),
1408 Chars
(Defining_Identifier
(Form
))));
1412 -- Determine whether the null procedure may be a completion of a generic
1413 -- subprogram, in which case we use the new null body as the completion
1414 -- and set minimal semantic information on the original declaration,
1415 -- which is rewritten as a null statement.
1417 if Present
(Prev
) and then Is_Generic_Subprogram
(Prev
) then
1418 Insert_Before
(N
, Null_Body
);
1419 Mutate_Ekind
(Defining_Entity
(N
), Ekind
(Prev
));
1421 Rewrite
(N
, Make_Null_Statement
(Loc
));
1422 Analyze_Generic_Subprogram_Body
(Null_Body
, Prev
);
1423 Is_Completion
:= True;
1425 -- Mark the newly generated subprogram body as trivial
1427 Set_Is_Trivial_Subprogram
1428 (Defining_Unit_Name
(Specification
(Null_Body
)));
1433 -- Resolve the types of the formals now, because the freeze point may
1434 -- appear in a different context, e.g. an instantiation.
1436 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1437 while Present
(Form
) loop
1438 if Nkind
(Parameter_Type
(Form
)) /= N_Access_Definition
then
1439 Find_Type
(Parameter_Type
(Form
));
1441 elsif No
(Access_To_Subprogram_Definition
1442 (Parameter_Type
(Form
)))
1444 Find_Type
(Subtype_Mark
(Parameter_Type
(Form
)));
1446 -- The case of a null procedure with a formal that is an
1447 -- access-to-subprogram type, and that is used as an actual
1448 -- in an instantiation is left to the enthusiastic reader.
1458 -- If there are previous overloadable entities with the same name, check
1459 -- whether any of them is completed by the null procedure.
1461 if Present
(Prev
) and then Is_Overloadable
(Prev
) then
1462 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1463 Prev
:= Find_Corresponding_Spec
(N
);
1466 if No
(Prev
) or else not Comes_From_Source
(Prev
) then
1467 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1468 Set_Has_Completion
(Designator
);
1470 -- Signal to caller that this is a procedure declaration
1472 Is_Completion
:= False;
1474 -- Null procedures are always inlined, but generic formal subprograms
1475 -- which appear as such in the internal instance of formal packages,
1476 -- need no completion and are not marked Inline.
1479 and then Nkind
(N
) /= N_Formal_Concrete_Subprogram_Declaration
1481 Set_Corresponding_Body
(N
, Defining_Entity
(Null_Body
));
1482 Set_Body_To_Inline
(N
, Null_Body
);
1483 Set_Is_Inlined
(Designator
);
1487 -- The null procedure is a completion. We unconditionally rewrite
1488 -- this as a null body (even if expansion is not active), because
1489 -- there are various error checks that are applied on this body
1490 -- when it is analyzed (e.g. correct aspect placement).
1492 if Has_Completion
(Prev
) then
1493 Error_Msg_Sloc
:= Sloc
(Prev
);
1494 Error_Msg_NE
("duplicate body for & declared#", N
, Prev
);
1497 Check_Previous_Null_Procedure
(N
, Prev
);
1499 Is_Completion
:= True;
1500 Rewrite
(N
, Null_Body
);
1505 Ignore_SPARK_Mode_Pragmas_In_Instance
:= Saved_ISMP
;
1506 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
1507 end Analyze_Null_Procedure
;
1509 -----------------------------
1510 -- Analyze_Operator_Symbol --
1511 -----------------------------
1513 -- An operator symbol such as "+" or "and" may appear in context where the
1514 -- literal denotes an entity name, such as "+"(x, y) or in context when it
1515 -- is just a string, as in (conjunction = "or"). In these cases the parser
1516 -- generates this node, and the semantics does the disambiguation. Other
1517 -- such case are actuals in an instantiation, the generic unit in an
1518 -- instantiation, pragma arguments, and aspect specifications.
1520 procedure Analyze_Operator_Symbol
(N
: Node_Id
) is
1521 Par
: constant Node_Id
:= Parent
(N
);
1523 Maybe_Aspect_Spec
: Node_Id
:= Par
;
1525 if Nkind
(Maybe_Aspect_Spec
) /= N_Aspect_Specification
then
1526 -- deal with N_Aggregate nodes
1527 Maybe_Aspect_Spec
:= Parent
(Maybe_Aspect_Spec
);
1530 if (Nkind
(Par
) = N_Function_Call
and then N
= Name
(Par
))
1531 or else Nkind
(Par
) = N_Function_Instantiation
1532 or else (Nkind
(Par
) = N_Indexed_Component
and then N
= Prefix
(Par
))
1533 or else (Nkind
(Par
) = N_Pragma_Argument_Association
1534 and then not Is_Pragma_String_Literal
(Par
))
1535 or else Nkind
(Par
) = N_Subprogram_Renaming_Declaration
1536 or else (Nkind
(Par
) = N_Attribute_Reference
1537 and then Attribute_Name
(Par
) /= Name_Value
)
1538 or else (Nkind
(Maybe_Aspect_Spec
) = N_Aspect_Specification
1539 and then Get_Aspect_Id
(Maybe_Aspect_Spec
)
1541 -- Include aspects that can be specified by a
1542 -- subprogram name, which can be an operator.
1544 in Aspect_Stable_Properties
1545 | Aspect_Integer_Literal
1546 | Aspect_Real_Literal
1547 | Aspect_String_Literal
1550 Find_Direct_Name
(N
);
1553 Change_Operator_Symbol_To_String_Literal
(N
);
1556 end Analyze_Operator_Symbol
;
1558 -----------------------------------
1559 -- Analyze_Parameter_Association --
1560 -----------------------------------
1562 procedure Analyze_Parameter_Association
(N
: Node_Id
) is
1564 Analyze
(Explicit_Actual_Parameter
(N
));
1565 end Analyze_Parameter_Association
;
1567 ----------------------------
1568 -- Analyze_Procedure_Call --
1569 ----------------------------
1571 -- WARNING: This routine manages Ghost regions. Return statements must be
1572 -- replaced by gotos that jump to the end of the routine and restore the
1575 procedure Analyze_Procedure_Call
(N
: Node_Id
) is
1576 procedure Analyze_Call_And_Resolve
;
1577 -- Do Analyze and Resolve calls for procedure call. At the end, check
1578 -- for illegal order dependence.
1579 -- ??? where is the check for illegal order dependencies?
1581 ------------------------------
1582 -- Analyze_Call_And_Resolve --
1583 ------------------------------
1585 procedure Analyze_Call_And_Resolve
is
1587 if Nkind
(N
) = N_Procedure_Call_Statement
then
1589 Resolve
(N
, Standard_Void_Type
);
1593 end Analyze_Call_And_Resolve
;
1597 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
1598 Loc
: constant Source_Ptr
:= Sloc
(N
);
1599 P
: constant Node_Id
:= Name
(N
);
1601 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
1602 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
1603 -- Save the Ghost-related attributes to restore on exit
1608 -- Start of processing for Analyze_Procedure_Call
1611 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
1612 -- a procedure call or an entry call. The prefix may denote an access
1613 -- to subprogram type, in which case an implicit dereference applies.
1614 -- If the prefix is an indexed component (without implicit dereference)
1615 -- then the construct denotes a call to a member of an entire family.
1616 -- If the prefix is a simple name, it may still denote a call to a
1617 -- parameterless member of an entry family. Resolution of these various
1618 -- interpretations is delicate.
1620 -- Do not analyze machine code statements to avoid rejecting them in
1623 if CodePeer_Mode
and then Nkind
(P
) = N_Qualified_Expression
then
1624 Set_Etype
(P
, Standard_Void_Type
);
1629 -- If this is a call of the form Obj.Op, the call may have been analyzed
1630 -- and possibly rewritten into a block, in which case we are done.
1632 if Analyzed
(N
) then
1635 -- If there is an error analyzing the name (which may have been
1636 -- rewritten if the original call was in prefix notation) then error
1637 -- has been emitted already, mark node and return.
1639 elsif Error_Posted
(N
) or else Etype
(Name
(N
)) = Any_Type
then
1640 Set_Etype
(N
, Any_Type
);
1644 -- A procedure call is Ghost when its name denotes a Ghost procedure.
1645 -- Set the mode now to ensure that any nodes generated during analysis
1646 -- and expansion are properly marked as Ghost.
1648 Mark_And_Set_Ghost_Procedure_Call
(N
);
1650 -- Otherwise analyze the parameters
1652 Actual
:= First
(Actuals
);
1654 while Present
(Actual
) loop
1656 Check_Parameterless_Call
(Actual
);
1660 -- Special processing for Elab_Spec, Elab_Body and Elab_Subp_Body calls
1662 if Nkind
(P
) = N_Attribute_Reference
1663 and then Attribute_Name
(P
) in Name_Elab_Spec
1665 | Name_Elab_Subp_Body
1667 if Present
(Actuals
) then
1669 ("no parameters allowed for this call", First
(Actuals
));
1673 Set_Etype
(N
, Standard_Void_Type
);
1676 elsif Is_Entity_Name
(P
)
1677 and then Is_Record_Type
(Etype
(Entity
(P
)))
1678 and then Remote_AST_I_Dereference
(P
)
1682 elsif Is_Entity_Name
(P
)
1683 and then Ekind
(Entity
(P
)) /= E_Entry_Family
1685 if Is_Access_Type
(Etype
(P
))
1686 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1687 and then No
(Actuals
)
1688 and then Comes_From_Source
(N
)
1690 Error_Msg_N
("missing explicit dereference in call", N
);
1692 elsif Ekind
(Entity
(P
)) = E_Operator
then
1693 Error_Msg_Name_1
:= Chars
(P
);
1694 Error_Msg_N
("operator % cannot be used as a procedure", N
);
1697 Analyze_Call_And_Resolve
;
1699 -- If the prefix is the simple name of an entry family, this is a
1700 -- parameterless call from within the task body itself.
1702 elsif Is_Entity_Name
(P
)
1703 and then Nkind
(P
) = N_Identifier
1704 and then Ekind
(Entity
(P
)) = E_Entry_Family
1705 and then Present
(Actuals
)
1706 and then No
(Next
(First
(Actuals
)))
1708 -- Can be call to parameterless entry family. What appears to be the
1709 -- sole argument is in fact the entry index. Rewrite prefix of node
1710 -- accordingly. Source representation is unchanged by this
1714 Make_Indexed_Component
(Loc
,
1716 Make_Selected_Component
(Loc
,
1717 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(P
)), Loc
),
1718 Selector_Name
=> New_Occurrence_Of
(Entity
(P
), Loc
)),
1719 Expressions
=> Actuals
);
1720 Set_Name
(N
, New_N
);
1721 Set_Etype
(New_N
, Standard_Void_Type
);
1722 Set_Parameter_Associations
(N
, No_List
);
1723 Analyze_Call_And_Resolve
;
1725 elsif Nkind
(P
) = N_Explicit_Dereference
then
1726 if Ekind
(Etype
(P
)) = E_Subprogram_Type
then
1727 Analyze_Call_And_Resolve
;
1729 Error_Msg_N
("expect access to procedure in call", P
);
1732 -- The name can be a selected component or an indexed component that
1733 -- yields an access to subprogram. Such a prefix is legal if the call
1734 -- has parameter associations.
1736 elsif Is_Access_Type
(Etype
(P
))
1737 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1739 if Present
(Actuals
) then
1740 Analyze_Call_And_Resolve
;
1742 Error_Msg_N
("missing explicit dereference in call", N
);
1745 -- If not an access to subprogram, then the prefix must resolve to the
1746 -- name of an entry, entry family, or protected operation.
1748 -- For the case of a simple entry call, P is a selected component where
1749 -- the prefix is the task and the selector name is the entry. A call to
1750 -- a protected procedure will have the same syntax. If the protected
1751 -- object contains overloaded operations, the entity may appear as a
1752 -- function, the context will select the operation whose type is Void.
1754 elsif Nkind
(P
) = N_Selected_Component
1755 and then Ekind
(Entity
(Selector_Name
(P
)))
1756 in E_Entry | E_Function | E_Procedure
1758 -- When front-end inlining is enabled, as with SPARK_Mode, a call
1759 -- in prefix notation may still be missing its controlling argument,
1760 -- so perform the transformation now.
1762 if SPARK_Mode
= On
and then In_Inlined_Body
then
1764 Subp
: constant Entity_Id
:= Entity
(Selector_Name
(P
));
1765 Typ
: constant Entity_Id
:= Etype
(Prefix
(P
));
1768 if Is_Tagged_Type
(Typ
)
1769 and then Present
(First_Formal
(Subp
))
1770 and then (Etype
(First_Formal
(Subp
)) = Typ
1772 Class_Wide_Type
(Etype
(First_Formal
(Subp
))) = Typ
)
1773 and then Try_Object_Operation
(P
)
1778 Analyze_Call_And_Resolve
;
1783 Analyze_Call_And_Resolve
;
1786 elsif Nkind
(P
) = N_Selected_Component
1787 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
1788 and then Present
(Actuals
)
1789 and then No
(Next
(First
(Actuals
)))
1791 -- Can be call to parameterless entry family. What appears to be the
1792 -- sole argument is in fact the entry index. Rewrite prefix of node
1793 -- accordingly. Source representation is unchanged by this
1797 Make_Indexed_Component
(Loc
,
1798 Prefix
=> New_Copy
(P
),
1799 Expressions
=> Actuals
);
1800 Set_Name
(N
, New_N
);
1801 Set_Etype
(New_N
, Standard_Void_Type
);
1802 Set_Parameter_Associations
(N
, No_List
);
1803 Analyze_Call_And_Resolve
;
1805 -- For the case of a reference to an element of an entry family, P is
1806 -- an indexed component whose prefix is a selected component (task and
1807 -- entry family), and whose index is the entry family index.
1809 elsif Nkind
(P
) = N_Indexed_Component
1810 and then Nkind
(Prefix
(P
)) = N_Selected_Component
1811 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) = E_Entry_Family
1813 Analyze_Call_And_Resolve
;
1815 -- If the prefix is the name of an entry family, it is a call from
1816 -- within the task body itself.
1818 elsif Nkind
(P
) = N_Indexed_Component
1819 and then Nkind
(Prefix
(P
)) = N_Identifier
1820 and then Ekind
(Entity
(Prefix
(P
))) = E_Entry_Family
1823 Make_Selected_Component
(Loc
,
1825 New_Occurrence_Of
(Scope
(Entity
(Prefix
(P
))), Loc
),
1826 Selector_Name
=> New_Occurrence_Of
(Entity
(Prefix
(P
)), Loc
));
1827 Rewrite
(Prefix
(P
), New_N
);
1829 Analyze_Call_And_Resolve
;
1831 -- In Ada 2012. a qualified expression is a name, but it cannot be a
1832 -- procedure name, so the construct can only be a qualified expression.
1834 elsif Nkind
(P
) = N_Qualified_Expression
1835 and then Ada_Version
>= Ada_2012
1837 Rewrite
(N
, Make_Code_Statement
(Loc
, Expression
=> P
));
1840 -- Anything else is an error
1843 Error_Msg_N
("invalid procedure or entry call", N
);
1845 -- Specialize the error message in the case where both a primitive
1846 -- operation and a record component are visible at the same time.
1848 if Nkind
(P
) = N_Selected_Component
1849 and then Is_Entity_Name
(Selector_Name
(P
))
1852 Sel
: constant Entity_Id
:= Entity
(Selector_Name
(P
));
1854 if Ekind
(Sel
) = E_Component
1855 and then Present
(Homonym
(Sel
))
1856 and then Ekind
(Homonym
(Sel
)) = E_Procedure
1858 Error_Msg_NE
("\component & conflicts with"
1859 & " homonym procedure (RM 4.1.3 (9.2/3))",
1860 Selector_Name
(P
), Sel
);
1867 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
1868 end Analyze_Procedure_Call
;
1870 ------------------------------
1871 -- Analyze_Return_Statement --
1872 ------------------------------
1874 procedure Analyze_Return_Statement
(N
: Node_Id
) is
1876 (Nkind
(N
) in N_Extended_Return_Statement | N_Simple_Return_Statement
);
1878 Returns_Object
: constant Boolean :=
1879 Nkind
(N
) = N_Extended_Return_Statement
1881 (Nkind
(N
) = N_Simple_Return_Statement
1882 and then Present
(Expression
(N
)));
1883 -- True if we're returning something; that is, "return <expression>;"
1884 -- or "return Result : T [:= ...]". False for "return;". Used for error
1885 -- checking: If Returns_Object is True, N should apply to a function
1886 -- body; otherwise N should apply to a procedure body, entry body,
1887 -- accept statement, or extended return statement.
1889 function Find_What_It_Applies_To
return Entity_Id
;
1890 -- Find the entity representing the innermost enclosing body, accept
1891 -- statement, or extended return statement. If the result is a callable
1892 -- construct or extended return statement, then this will be the value
1893 -- of the Return_Applies_To attribute. Otherwise, the program is
1894 -- illegal. See RM-6.5(4/2).
1896 -----------------------------
1897 -- Find_What_It_Applies_To --
1898 -----------------------------
1900 function Find_What_It_Applies_To
return Entity_Id
is
1901 Result
: Entity_Id
:= Empty
;
1904 -- Loop outward through the Scope_Stack, skipping blocks, and loops
1906 for J
in reverse 0 .. Scope_Stack
.Last
loop
1907 Result
:= Scope_Stack
.Table
(J
).Entity
;
1908 exit when Ekind
(Result
) not in E_Block | E_Loop
;
1911 pragma Assert
(Present
(Result
));
1913 end Find_What_It_Applies_To
;
1915 -- Local declarations
1917 Scope_Id
: constant Entity_Id
:= Find_What_It_Applies_To
;
1918 Kind
: constant Entity_Kind
:= Ekind
(Scope_Id
);
1919 Loc
: constant Source_Ptr
:= Sloc
(N
);
1920 Stm_Entity
: constant Entity_Id
:=
1922 (E_Return_Statement
, Current_Scope
, Loc
, 'R');
1924 -- Start of processing for Analyze_Return_Statement
1927 Set_Return_Statement_Entity
(N
, Stm_Entity
);
1929 Set_Etype
(Stm_Entity
, Standard_Void_Type
);
1930 Set_Return_Applies_To
(Stm_Entity
, Scope_Id
);
1932 -- Place Return entity on scope stack, to simplify enforcement of 6.5
1933 -- (4/2): an inner return statement will apply to this extended return.
1935 if Nkind
(N
) = N_Extended_Return_Statement
then
1936 Push_Scope
(Stm_Entity
);
1939 -- Check that pragma No_Return is obeyed. Don't complain about the
1940 -- implicitly-generated return that is placed at the end.
1942 if No_Return
(Scope_Id
)
1943 and then Kind
in E_Procedure | E_Generic_Procedure
1944 and then Comes_From_Source
(N
)
1947 ("RETURN statement not allowed in No_Return procedure", N
);
1950 -- Warn on any unassigned OUT parameters if in procedure
1952 if Ekind
(Scope_Id
) = E_Procedure
then
1953 Warn_On_Unassigned_Out_Parameter
(N
, Scope_Id
);
1956 -- Check that functions return objects, and other things do not
1958 if Kind
in E_Function | E_Generic_Function
then
1959 if not Returns_Object
then
1960 Error_Msg_N
("missing expression in return from function", N
);
1963 elsif Kind
in E_Procedure | E_Generic_Procedure
then
1964 if Returns_Object
then
1965 Error_Msg_N
("procedure cannot return value (use function)", N
);
1968 elsif Kind
in E_Entry | E_Entry_Family
then
1969 if Returns_Object
then
1970 if Is_Protected_Type
(Scope
(Scope_Id
)) then
1971 Error_Msg_N
("entry body cannot return value", N
);
1973 Error_Msg_N
("accept statement cannot return value", N
);
1977 elsif Kind
= E_Return_Statement
then
1979 -- We are nested within another return statement, which must be an
1980 -- extended_return_statement.
1982 if Returns_Object
then
1983 if Nkind
(N
) = N_Extended_Return_Statement
then
1985 ("extended return statement cannot be nested (use `RETURN;`)",
1988 -- Case of a simple return statement with a value inside extended
1989 -- return statement.
1993 ("return nested in extended return statement cannot return "
1994 & "value (use `RETURN;`)", N
);
1999 Error_Msg_N
("illegal context for return statement", N
);
2002 if Kind
in E_Function | E_Generic_Function
then
2003 Analyze_Function_Return
(N
);
2005 elsif Kind
in E_Procedure | E_Generic_Procedure
then
2006 Set_Return_Present
(Scope_Id
);
2009 if Nkind
(N
) = N_Extended_Return_Statement
then
2013 Kill_Current_Values
(Last_Assignment_Only
=> True);
2014 Check_Unreachable_Code
(N
);
2016 Analyze_Dimension
(N
);
2017 end Analyze_Return_Statement
;
2019 -----------------------------------
2020 -- Analyze_Return_When_Statement --
2021 -----------------------------------
2023 procedure Analyze_Return_When_Statement
(N
: Node_Id
) is
2025 -- Verify the condition is a Boolean expression
2027 Analyze_And_Resolve
(Condition
(N
), Any_Boolean
);
2028 Check_Unset_Reference
(Condition
(N
));
2029 end Analyze_Return_When_Statement
;
2031 -------------------------------------
2032 -- Analyze_Simple_Return_Statement --
2033 -------------------------------------
2035 procedure Analyze_Simple_Return_Statement
(N
: Node_Id
) is
2037 if Present
(Expression
(N
)) then
2038 Mark_Coextensions
(N
, Expression
(N
));
2041 Analyze_Return_Statement
(N
);
2042 end Analyze_Simple_Return_Statement
;
2044 -------------------------
2045 -- Analyze_Return_Type --
2046 -------------------------
2048 procedure Analyze_Return_Type
(N
: Node_Id
) is
2049 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
2053 -- Normal case where result definition does not indicate an error
2055 if Result_Definition
(N
) /= Error
then
2056 if Nkind
(Result_Definition
(N
)) = N_Access_Definition
then
2058 -- Ada 2005 (AI-254): Handle anonymous access to subprograms
2061 AD
: constant Node_Id
:=
2062 Access_To_Subprogram_Definition
(Result_Definition
(N
));
2064 if Present
(AD
) and then Protected_Present
(AD
) then
2065 Typ
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
2067 Typ
:= Access_Definition
(N
, Result_Definition
(N
));
2071 Set_Parent
(Typ
, Result_Definition
(N
));
2072 Set_Is_Local_Anonymous_Access
(Typ
);
2073 Set_Etype
(Designator
, Typ
);
2075 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
2077 Null_Exclusion_Static_Checks
(N
);
2079 -- Subtype_Mark case
2082 Find_Type
(Result_Definition
(N
));
2083 Typ
:= Entity
(Result_Definition
(N
));
2084 Set_Etype
(Designator
, Typ
);
2086 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
2088 Null_Exclusion_Static_Checks
(N
);
2090 -- If a null exclusion is imposed on the result type, then create
2091 -- a null-excluding itype (an access subtype) and use it as the
2092 -- function's Etype. Note that the null exclusion checks are done
2093 -- right before this, because they don't get applied to types that
2094 -- do not come from source.
2096 if Is_Access_Type
(Typ
) and then Null_Exclusion_Present
(N
) then
2097 Set_Etype
(Designator
,
2098 Create_Null_Excluding_Itype
2101 Scope_Id
=> Scope
(Current_Scope
)));
2103 -- The new subtype must be elaborated before use because
2104 -- it is visible outside of the function. However its base
2105 -- type may not be frozen yet, so the reference that will
2106 -- force elaboration must be attached to the freezing of
2109 -- If the return specification appears on a proper body,
2110 -- the subtype will have been created already on the spec.
2112 if Is_Frozen
(Typ
) then
2113 if Nkind
(Parent
(N
)) = N_Subprogram_Body
2114 and then Nkind
(Parent
(Parent
(N
))) = N_Subunit
2118 Build_Itype_Reference
(Etype
(Designator
), Parent
(N
));
2123 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(N
));
2125 Set_Itype
(IR
, Etype
(Designator
));
2126 Append_Freeze_Action
(Typ
, IR
);
2131 Set_Etype
(Designator
, Typ
);
2134 if Ekind
(Typ
) = E_Incomplete_Type
2135 or else (Is_Class_Wide_Type
(Typ
)
2136 and then Ekind
(Root_Type
(Typ
)) = E_Incomplete_Type
)
2138 -- AI05-0151: Tagged incomplete types are allowed in all formal
2139 -- parts. Untagged incomplete types are not allowed in bodies.
2140 -- As a consequence, limited views cannot appear in a basic
2141 -- declaration that is itself within a body, because there is
2142 -- no point at which the non-limited view will become visible.
2144 if Ada_Version
>= Ada_2012
then
2145 if From_Limited_With
(Typ
) and then In_Package_Body
then
2147 ("invalid use of incomplete type&",
2148 Result_Definition
(N
), Typ
);
2150 -- The return type of a subprogram body cannot be of a
2151 -- formal incomplete type.
2153 elsif Is_Generic_Type
(Typ
)
2154 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
2157 ("return type cannot be a formal incomplete type",
2158 Result_Definition
(N
));
2160 elsif Is_Class_Wide_Type
(Typ
)
2161 and then Is_Generic_Type
(Root_Type
(Typ
))
2162 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
2165 ("return type cannot be a formal incomplete type",
2166 Result_Definition
(N
));
2168 elsif Is_Tagged_Type
(Typ
) then
2171 -- Use is legal in a thunk generated for an operation
2172 -- inherited from a progenitor.
2174 elsif Is_Thunk
(Designator
)
2175 and then Present
(Non_Limited_View
(Typ
))
2179 elsif Nkind
(Parent
(N
)) = N_Subprogram_Body
2180 or else Nkind
(Parent
(Parent
(N
))) in
2181 N_Accept_Statement | N_Entry_Body
2184 ("invalid use of untagged incomplete type&",
2188 -- The type must be completed in the current package. This
2189 -- is checked at the end of the package declaration when
2190 -- Taft-amendment types are identified. If the return type
2191 -- is class-wide, there is no required check, the type can
2192 -- be a bona fide TAT.
2194 if Ekind
(Scope
(Current_Scope
)) = E_Package
2195 and then In_Private_Part
(Scope
(Current_Scope
))
2196 and then not Is_Class_Wide_Type
(Typ
)
2198 Append_Elmt
(Designator
, Private_Dependents
(Typ
));
2203 ("invalid use of incomplete type&", Designator
, Typ
);
2208 -- Case where result definition does indicate an error
2211 Set_Etype
(Designator
, Any_Type
);
2213 end Analyze_Return_Type
;
2215 -----------------------------
2216 -- Analyze_Subprogram_Body --
2217 -----------------------------
2219 procedure Analyze_Subprogram_Body
(N
: Node_Id
) is
2220 Loc
: constant Source_Ptr
:= Sloc
(N
);
2221 Body_Spec
: constant Node_Id
:= Specification
(N
);
2222 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Spec
);
2225 if Debug_Flag_C
then
2226 Write_Str
("==> subprogram body ");
2227 Write_Name
(Chars
(Body_Id
));
2228 Write_Str
(" from ");
2229 Write_Location
(Loc
);
2234 Trace_Scope
(N
, Body_Id
, " Analyze subprogram: ");
2236 -- The real work is split out into the helper, so it can do "return;"
2237 -- without skipping the debug output:
2239 Analyze_Subprogram_Body_Helper
(N
);
2241 if Debug_Flag_C
then
2243 Write_Str
("<== subprogram body ");
2244 Write_Name
(Chars
(Body_Id
));
2245 Write_Str
(" from ");
2246 Write_Location
(Loc
);
2249 end Analyze_Subprogram_Body
;
2251 ------------------------------------
2252 -- Analyze_Subprogram_Body_Helper --
2253 ------------------------------------
2255 -- This procedure is called for regular subprogram bodies, generic bodies,
2256 -- and for subprogram stubs of both kinds. In the case of stubs, only the
2257 -- specification matters, and is used to create a proper declaration for
2258 -- the subprogram, or to perform conformance checks.
2260 -- WARNING: This routine manages Ghost regions. Return statements must be
2261 -- replaced by gotos that jump to the end of the routine and restore the
2264 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
) is
2265 Body_Spec
: Node_Id
:= Specification
(N
);
2266 Body_Id
: Entity_Id
:= Defining_Entity
(Body_Spec
);
2267 Loc
: constant Source_Ptr
:= Sloc
(N
);
2268 Prev_Id
: constant Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
2270 Body_Nod
: Node_Id
:= Empty
;
2271 Minimum_Acc_Objs
: List_Id
:= No_List
;
2273 Conformant
: Boolean;
2274 Desig_View
: Entity_Id
:= Empty
;
2275 Exch_Views
: Elist_Id
:= No_Elist
;
2276 Mask_Types
: Elist_Id
:= No_Elist
;
2277 Prot_Typ
: Entity_Id
:= Empty
;
2278 Spec_Decl
: Node_Id
:= Empty
;
2279 Spec_Id
: Entity_Id
:= Empty
;
2281 Last_Real_Spec_Entity
: Entity_Id
:= Empty
;
2282 -- When we analyze a separate spec, the entity chain ends up containing
2283 -- the formals, as well as any itypes generated during analysis of the
2284 -- default expressions for parameters, or the arguments of associated
2285 -- precondition/postcondition pragmas (which are analyzed in the context
2286 -- of the spec since they have visibility on formals).
2288 -- These entities belong with the spec and not the body. However we do
2289 -- the analysis of the body in the context of the spec (again to obtain
2290 -- visibility to the formals), and all the entities generated during
2291 -- this analysis end up also chained to the entity chain of the spec.
2292 -- But they really belong to the body, and there is circuitry to move
2293 -- them from the spec to the body.
2295 -- However, when we do this move, we don't want to move the real spec
2296 -- entities (first para above) to the body. The Last_Real_Spec_Entity
2297 -- variable points to the last real spec entity, so we only move those
2298 -- chained beyond that point. It is initialized to Empty to deal with
2299 -- the case where there is no separate spec.
2301 function Body_Has_Contract
return Boolean;
2302 -- Check whether unanalyzed body has an aspect or pragma that may
2303 -- generate a SPARK contract.
2305 function Body_Has_SPARK_Mode_On
return Boolean;
2306 -- Check whether SPARK_Mode On applies to the subprogram body, either
2307 -- because it is specified directly on the body, or because it is
2308 -- inherited from the enclosing subprogram or package.
2310 function Build_Internal_Protected_Declaration
2311 (N
: Node_Id
) return Entity_Id
;
2312 -- A subprogram body without a previous spec that appears in a protected
2313 -- body must be expanded separately to create a subprogram declaration
2314 -- for it, in order to resolve internal calls to it from other protected
2317 -- Possibly factor this with Exp_Dist.Copy_Specification ???
2319 procedure Build_Subprogram_Declaration
;
2320 -- Create a matching subprogram declaration for subprogram body N
2322 procedure Check_Anonymous_Return
;
2323 -- Ada 2005: if a function returns an access type that denotes a task,
2324 -- or a type that contains tasks, we must create a master entity for
2325 -- the anonymous type, which typically will be used in an allocator
2326 -- in the body of the function.
2328 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
);
2329 -- Look ahead to recognize a pragma that may appear after the body.
2330 -- If there is a previous spec, check that it appears in the same
2331 -- declarative part. If the pragma is Inline_Always, perform inlining
2332 -- unconditionally, otherwise only if Front_End_Inlining is requested.
2333 -- If the body acts as a spec, and inlining is required, we create a
2334 -- subprogram declaration for it, in order to attach the body to inline.
2335 -- If pragma does not appear after the body, check whether there is
2336 -- an inline pragma before any local declarations.
2338 procedure Check_Missing_Return
;
2339 -- Checks for a function with a no return statements, and also performs
2340 -- the warning checks implemented by Check_Returns.
2342 function Disambiguate_Spec
return Entity_Id
;
2343 -- When a primitive is declared between the private view and the full
2344 -- view of a concurrent type which implements an interface, a special
2345 -- mechanism is used to find the corresponding spec of the primitive
2348 function Exchange_Limited_Views
(Subp_Id
: Entity_Id
) return Elist_Id
;
2349 -- Ada 2012 (AI05-0151): Detect whether the profile of Subp_Id contains
2350 -- incomplete types coming from a limited context and replace their
2351 -- limited views with the non-limited ones. Return the list of changes
2352 -- to be used to undo the transformation.
2354 procedure Generate_Minimum_Accessibility
2355 (Extra_Access
: Entity_Id
;
2356 Related_Form
: Entity_Id
:= Empty
);
2357 -- Generate a minimum accessibility object for a given extra
2358 -- accessibility formal (Extra_Access) and its related formal if it
2361 function Is_Private_Concurrent_Primitive
2362 (Subp_Id
: Entity_Id
) return Boolean;
2363 -- Determine whether subprogram Subp_Id is a primitive of a concurrent
2364 -- type that implements an interface and has a private view.
2366 function Mask_Unfrozen_Types
(Spec_Id
: Entity_Id
) return Elist_Id
;
2367 -- N is the body generated for an expression function that is not a
2368 -- completion and Spec_Id the defining entity of its spec. Mark all
2369 -- the not-yet-frozen types referenced by the simple return statement
2370 -- of the function as formally frozen.
2372 procedure Move_Pragmas
(From
: Node_Id
; To
: Node_Id
);
2373 -- Find all suitable source pragmas at the top of subprogram body
2374 -- From's declarations and move them after arbitrary node To.
2375 -- One exception is pragma SPARK_Mode which is copied rather than moved,
2376 -- as it applies to the body too.
2378 procedure Restore_Limited_Views
(Restore_List
: Elist_Id
);
2379 -- Undo the transformation done by Exchange_Limited_Views.
2381 procedure Set_Trivial_Subprogram
(N
: Node_Id
);
2382 -- Sets the Is_Trivial_Subprogram flag in both spec and body of the
2383 -- subprogram whose body is being analyzed. N is the statement node
2384 -- causing the flag to be set, if the following statement is a return
2385 -- of an entity, we mark the entity as set in source to suppress any
2386 -- warning on the stylized use of function stubs with a dummy return.
2388 procedure Unmask_Unfrozen_Types
(Unmask_List
: Elist_Id
);
2389 -- Undo the transformation done by Mask_Unfrozen_Types
2391 procedure Verify_Overriding_Indicator
;
2392 -- If there was a previous spec, the entity has been entered in the
2393 -- current scope previously. If the body itself carries an overriding
2394 -- indicator, check that it is consistent with the known status of the
2397 -----------------------
2398 -- Body_Has_Contract --
2399 -----------------------
2401 function Body_Has_Contract
return Boolean is
2402 Decls
: constant List_Id
:= Declarations
(N
);
2406 -- Check for aspects that may generate a contract
2408 Item
:= First
(Aspect_Specifications
(N
));
2409 while Present
(Item
) loop
2410 if Is_Subprogram_Contract_Annotation
(Item
) then
2417 -- Check for pragmas that may generate a contract
2419 Item
:= First
(Decls
);
2420 while Present
(Item
) loop
2421 if Nkind
(Item
) = N_Pragma
2422 and then Is_Subprogram_Contract_Annotation
(Item
)
2431 end Body_Has_Contract
;
2433 ----------------------------
2434 -- Body_Has_SPARK_Mode_On --
2435 ----------------------------
2437 function Body_Has_SPARK_Mode_On
return Boolean is
2438 Decls
: constant List_Id
:= Declarations
(N
);
2442 -- Check for SPARK_Mode aspect
2444 Item
:= First
(Aspect_Specifications
(N
));
2445 while Present
(Item
) loop
2446 if Get_Aspect_Id
(Item
) = Aspect_SPARK_Mode
then
2447 return Get_SPARK_Mode_From_Annotation
(Item
) = On
;
2453 -- Check for SPARK_Mode pragma
2455 Item
:= First
(Decls
);
2456 while Present
(Item
) loop
2458 -- Pragmas that apply to a subprogram body are usually grouped
2459 -- together. Look for a potential pragma SPARK_Mode among them.
2461 if Nkind
(Item
) = N_Pragma
then
2462 if Get_Pragma_Id
(Item
) = Pragma_SPARK_Mode
then
2463 return Get_SPARK_Mode_From_Annotation
(Item
) = On
;
2466 -- Otherwise the first non-pragma declarative item terminates the
2467 -- region where pragma SPARK_Mode may appear.
2476 -- Otherwise, the applicable SPARK_Mode is inherited from the
2477 -- enclosing subprogram or package.
2479 return SPARK_Mode
= On
;
2480 end Body_Has_SPARK_Mode_On
;
2482 ------------------------------------------
2483 -- Build_Internal_Protected_Declaration --
2484 ------------------------------------------
2486 function Build_Internal_Protected_Declaration
2487 (N
: Node_Id
) return Entity_Id
2489 procedure Analyze_Pragmas
(From
: Node_Id
);
2490 -- Analyze all pragmas which follow arbitrary node From
2492 ---------------------
2493 -- Analyze_Pragmas --
2494 ---------------------
2496 procedure Analyze_Pragmas
(From
: Node_Id
) is
2500 Decl
:= Next
(From
);
2501 while Present
(Decl
) loop
2502 if Nkind
(Decl
) = N_Pragma
then
2503 Analyze_Pragma
(Decl
);
2505 -- No candidate pragmas are available for analysis
2513 end Analyze_Pragmas
;
2517 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
2518 Loc
: constant Source_Ptr
:= Sloc
(N
);
2523 Spec_Id
: Entity_Id
;
2525 -- Start of processing for Build_Internal_Protected_Declaration
2528 Formal
:= First_Formal
(Body_Id
);
2530 -- The protected operation always has at least one formal, namely the
2531 -- object itself, but it is only placed in the parameter list if
2532 -- expansion is enabled.
2534 if Present
(Formal
) or else Expander_Active
then
2535 Formals
:= Copy_Parameter_List
(Body_Id
);
2541 Make_Defining_Identifier
(Sloc
(Body_Id
),
2542 Chars
=> Chars
(Body_Id
));
2544 -- Indicate that the entity comes from source, to ensure that cross-
2545 -- reference information is properly generated. The body itself is
2546 -- rewritten during expansion, and the body entity will not appear in
2547 -- calls to the operation.
2549 Set_Comes_From_Source
(Spec_Id
, True);
2551 if Nkind
(Specification
(N
)) = N_Procedure_Specification
then
2553 Make_Procedure_Specification
(Loc
,
2554 Defining_Unit_Name
=> Spec_Id
,
2555 Parameter_Specifications
=> Formals
);
2558 Make_Function_Specification
(Loc
,
2559 Defining_Unit_Name
=> Spec_Id
,
2560 Parameter_Specifications
=> Formals
,
2561 Result_Definition
=>
2562 New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
2565 Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
2566 Set_Corresponding_Body
(Decl
, Body_Id
);
2567 Set_Corresponding_Spec
(N
, Spec_Id
);
2569 Insert_Before
(N
, Decl
);
2571 -- Associate all aspects and pragmas of the body with the spec. This
2572 -- ensures that these annotations apply to the initial declaration of
2573 -- the subprogram body.
2575 Move_Aspects
(From
=> N
, To
=> Decl
);
2576 Move_Pragmas
(From
=> N
, To
=> Decl
);
2580 -- The analysis of the spec may generate pragmas which require manual
2581 -- analysis. Since the generation of the spec and the relocation of
2582 -- the annotations is driven by the expansion of the stand-alone
2583 -- body, the pragmas will not be analyzed in a timely manner. Do this
2586 Analyze_Pragmas
(Decl
);
2588 -- This subprogram has convention Intrinsic as per RM 6.3.1(10/2)
2589 -- ensuring in particular that 'Access is illegal.
2591 Set_Convention
(Spec_Id
, Convention_Intrinsic
);
2592 Set_Has_Completion
(Spec_Id
);
2595 end Build_Internal_Protected_Declaration
;
2597 ----------------------------------
2598 -- Build_Subprogram_Declaration --
2599 ----------------------------------
2601 procedure Build_Subprogram_Declaration
is
2603 Subp_Decl
: Node_Id
;
2606 -- Create a matching subprogram spec using the profile of the body.
2607 -- The structure of the tree is identical, but has new entities for
2608 -- the defining unit name and formal parameters.
2611 Make_Subprogram_Declaration
(Loc
,
2612 Specification
=> Copy_Subprogram_Spec
(Body_Spec
));
2613 Set_Comes_From_Source
(Subp_Decl
, True);
2615 -- Also mark parameters as coming from source
2617 if Present
(Parameter_Specifications
(Specification
(Subp_Decl
))) then
2622 First
(Parameter_Specifications
(Specification
(Subp_Decl
)));
2624 while Present
(Form
) loop
2625 Set_Comes_From_Source
(Defining_Identifier
(Form
), True);
2631 -- Relocate the aspects and relevant pragmas from the subprogram body
2632 -- to the generated spec because it acts as the initial declaration.
2634 Insert_Before
(N
, Subp_Decl
);
2635 Move_Aspects
(N
, To
=> Subp_Decl
);
2636 Move_Pragmas
(N
, To
=> Subp_Decl
);
2638 -- Ensure that the generated corresponding spec and original body
2639 -- share the same SPARK_Mode pragma or aspect. As a result, both have
2640 -- the same SPARK_Mode attributes, and the global SPARK_Mode value is
2641 -- correctly set for local subprograms.
2643 Copy_SPARK_Mode_Aspect
(Subp_Decl
, To
=> N
);
2645 Analyze
(Subp_Decl
);
2647 -- Propagate the attributes Rewritten_For_C and Corresponding_Proc to
2648 -- the body since the expander may generate calls using that entity.
2649 -- Required to ensure that Expand_Call rewrites calls to this
2650 -- function by calls to the built procedure.
2652 if Transform_Function_Array
2653 and then Nkind
(Body_Spec
) = N_Function_Specification
2655 Rewritten_For_C
(Defining_Entity
(Specification
(Subp_Decl
)))
2657 Set_Rewritten_For_C
(Defining_Entity
(Body_Spec
));
2658 Set_Corresponding_Procedure
(Defining_Entity
(Body_Spec
),
2659 Corresponding_Procedure
2660 (Defining_Entity
(Specification
(Subp_Decl
))));
2663 -- Analyze any relocated source pragmas or pragmas created for aspect
2666 Decl
:= Next
(Subp_Decl
);
2667 while Present
(Decl
) loop
2669 -- Stop the search for pragmas once the body has been reached as
2670 -- this terminates the region where pragmas may appear.
2675 elsif Nkind
(Decl
) = N_Pragma
then
2682 Spec_Id
:= Defining_Entity
(Subp_Decl
);
2683 Set_Corresponding_Spec
(N
, Spec_Id
);
2685 -- Mark the generated spec as a source construct to ensure that all
2686 -- calls to it are properly registered in ALI files for GNATprove.
2688 Set_Comes_From_Source
(Spec_Id
, True);
2690 -- Ensure that the specs of the subprogram declaration and its body
2691 -- are identical, otherwise they will appear non-conformant due to
2692 -- rewritings in the default values of formal parameters.
2694 Body_Spec
:= Copy_Subprogram_Spec
(Body_Spec
);
2695 Set_Specification
(N
, Body_Spec
);
2696 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
2697 end Build_Subprogram_Declaration
;
2699 ----------------------------
2700 -- Check_Anonymous_Return --
2701 ----------------------------
2703 procedure Check_Anonymous_Return
is
2709 if Present
(Spec_Id
) then
2715 if Ekind
(Scop
) = E_Function
2716 and then Ekind
(Etype
(Scop
)) = E_Anonymous_Access_Type
2717 and then not Is_Thunk
(Scop
)
2719 -- Skip internally built functions which handle the case of
2720 -- a null access (see Expand_Interface_Conversion)
2722 and then not (Is_Interface
(Designated_Type
(Etype
(Scop
)))
2723 and then not Comes_From_Source
(Parent
(Scop
)))
2725 and then (Has_Task
(Designated_Type
(Etype
(Scop
)))
2727 (Is_Class_Wide_Type
(Designated_Type
(Etype
(Scop
)))
2730 (Etype
(Designated_Type
(Etype
(Scop
))))))
2731 and then Expander_Active
2733 Decl
:= Build_Master_Declaration
(Loc
);
2735 if Present
(Declarations
(N
)) then
2736 Prepend
(Decl
, Declarations
(N
));
2738 Set_Declarations
(N
, New_List
(Decl
));
2741 Set_Master_Id
(Etype
(Scop
), Defining_Identifier
(Decl
));
2742 Set_Has_Master_Entity
(Scop
);
2744 -- Now mark the containing scope as a task master
2747 while Nkind
(Par
) /= N_Compilation_Unit
loop
2748 Par
:= Parent
(Par
);
2749 pragma Assert
(Present
(Par
));
2751 -- If we fall off the top, we are at the outer level, and
2752 -- the environment task is our effective master, so nothing
2756 in N_Task_Body | N_Block_Statement | N_Subprogram_Body
2758 Set_Is_Task_Master
(Par
, True);
2763 end Check_Anonymous_Return
;
2765 -------------------------
2766 -- Check_Inline_Pragma --
2767 -------------------------
2769 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
) is
2773 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean;
2774 -- True when N is a pragma Inline or Inline_Always that applies
2775 -- to this subprogram.
2777 -----------------------
2778 -- Is_Inline_Pragma --
2779 -----------------------
2781 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean is
2783 if Nkind
(N
) = N_Pragma
2785 (Pragma_Name_Unmapped
(N
) = Name_Inline_Always
2786 or else (Pragma_Name_Unmapped
(N
) = Name_Inline
2788 (Front_End_Inlining
or else Optimization_Level
> 0)))
2789 and then Present
(Pragma_Argument_Associations
(N
))
2792 Pragma_Arg
: Node_Id
:=
2793 Expression
(First
(Pragma_Argument_Associations
(N
)));
2795 if Nkind
(Pragma_Arg
) = N_Selected_Component
then
2796 Pragma_Arg
:= Selector_Name
(Pragma_Arg
);
2799 return Chars
(Pragma_Arg
) = Chars
(Body_Id
);
2805 end Is_Inline_Pragma
;
2807 -- Start of processing for Check_Inline_Pragma
2810 if not Expander_Active
then
2814 if Is_List_Member
(N
)
2815 and then Present
(Next
(N
))
2816 and then Is_Inline_Pragma
(Next
(N
))
2820 elsif Nkind
(N
) /= N_Subprogram_Body_Stub
2821 and then Present
(Declarations
(N
))
2822 and then Is_Inline_Pragma
(First
(Declarations
(N
)))
2824 Prag
:= First
(Declarations
(N
));
2830 if Present
(Prag
) and then Is_List_Member
(N
) then
2831 if Present
(Spec_Id
) then
2832 if Is_List_Member
(Unit_Declaration_Node
(Spec_Id
))
2833 and then In_Same_List
(N
, Unit_Declaration_Node
(Spec_Id
))
2838 -- Create a subprogram declaration, to make treatment uniform.
2839 -- Make the sloc of the subprogram name that of the entity in
2840 -- the body, so that style checks find identical strings.
2843 Subp
: constant Entity_Id
:=
2844 Make_Defining_Identifier
2845 (Sloc
(Body_Id
), Chars
(Body_Id
));
2846 Decl
: constant Node_Id
:=
2847 Make_Subprogram_Declaration
(Loc
,
2849 New_Copy_Tree
(Specification
(N
)));
2852 -- Link the body and the generated spec
2854 Set_Corresponding_Body
(Decl
, Body_Id
);
2856 if Nkind
(N
) = N_Subprogram_Body_Stub
then
2857 Set_Corresponding_Spec_Of_Stub
(N
, Subp
);
2859 Set_Corresponding_Spec
(N
, Subp
);
2862 Set_Defining_Unit_Name
(Specification
(Decl
), Subp
);
2864 -- To ensure proper coverage when body is inlined, indicate
2865 -- whether the subprogram comes from source.
2867 Preserve_Comes_From_Source
(Subp
, N
);
2869 if Present
(First_Formal
(Body_Id
)) then
2870 Plist
:= Copy_Parameter_List
(Body_Id
);
2871 Set_Parameter_Specifications
2872 (Specification
(Decl
), Plist
);
2875 -- Move aspects to the new spec
2877 Move_Aspects
(N
, To
=> Decl
);
2879 Insert_Before
(N
, Decl
);
2882 Set_Has_Pragma_Inline
(Subp
);
2884 if Pragma_Name
(Prag
) = Name_Inline_Always
then
2885 Set_Is_Inlined
(Subp
);
2886 Set_Has_Pragma_Inline_Always
(Subp
);
2889 -- Prior to copying the subprogram body to create a template
2890 -- for it for subsequent inlining, remove the pragma from
2891 -- the current body so that the copy that will produce the
2892 -- new body will start from a completely unanalyzed tree.
2894 if Nkind
(Parent
(Prag
)) = N_Subprogram_Body
then
2895 Rewrite
(Prag
, Make_Null_Statement
(Sloc
(Prag
)));
2902 end Check_Inline_Pragma
;
2904 --------------------------
2905 -- Check_Missing_Return --
2906 --------------------------
2908 procedure Check_Missing_Return
is
2909 HSS
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
2912 Missing_Ret
: Boolean;
2915 if Nkind
(Body_Spec
) = N_Function_Specification
then
2916 if Present
(Spec_Id
) then
2922 -- A function body shall contain at least one return statement
2923 -- that applies to the function body, unless the function contains
2924 -- code_statements; RM 6.5(5).
2926 if Return_Present
(Id
) then
2927 Check_Returns
(HSS
, 'F', Missing_Ret
);
2930 Set_Has_Missing_Return
(Id
);
2933 -- Within a premature instantiation of a package with no body, we
2934 -- build completions of the functions therein, with a Raise
2935 -- statement. No point in complaining about a missing return in
2938 elsif Ekind
(Id
) = E_Function
2939 and then In_Instance
2940 and then Present
(Statements
(HSS
))
2941 and then Nkind
(First
(Statements
(HSS
))) = N_Raise_Program_Error
2945 elsif Is_Generic_Subprogram
(Id
)
2946 or else not Is_Machine_Code_Subprogram
(Id
)
2948 Error_Msg_N
("missing RETURN statement in function body", N
);
2951 -- If procedure with No_Return, check returns
2953 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
then
2954 if Present
(Spec_Id
) then
2960 if No_Return
(Id
) then
2961 Check_Returns
(HSS
, 'P', Missing_Ret
, Id
);
2964 end Check_Missing_Return
;
2966 -----------------------
2967 -- Disambiguate_Spec --
2968 -----------------------
2970 function Disambiguate_Spec
return Entity_Id
is
2971 Priv_Spec
: Entity_Id
;
2974 procedure Replace_Types
(To_Corresponding
: Boolean);
2975 -- Depending on the flag, replace the type of formal parameters of
2976 -- Body_Id if it is a concurrent type implementing interfaces with
2977 -- the corresponding record type or the other way around.
2979 procedure Replace_Types
(To_Corresponding
: Boolean) is
2981 Formal_Typ
: Entity_Id
;
2984 Formal
:= First_Formal
(Body_Id
);
2985 while Present
(Formal
) loop
2986 Formal_Typ
:= Etype
(Formal
);
2988 if Is_Class_Wide_Type
(Formal_Typ
) then
2989 Formal_Typ
:= Root_Type
(Formal_Typ
);
2992 -- From concurrent type to corresponding record
2994 if To_Corresponding
then
2995 if Is_Concurrent_Type
(Formal_Typ
)
2996 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
2999 (Corresponding_Record_Type
(Formal_Typ
)))
3002 Corresponding_Record_Type
(Formal_Typ
));
3005 -- From corresponding record to concurrent type
3008 if Is_Concurrent_Record_Type
(Formal_Typ
)
3009 and then Present
(Interfaces
(Formal_Typ
))
3012 Corresponding_Concurrent_Type
(Formal_Typ
));
3016 Next_Formal
(Formal
);
3020 -- Start of processing for Disambiguate_Spec
3023 -- Try to retrieve the specification of the body as is. All error
3024 -- messages are suppressed because the body may not have a spec in
3025 -- its current state.
3027 Spec_N
:= Find_Corresponding_Spec
(N
, False);
3029 -- It is possible that this is the body of a primitive declared
3030 -- between a private and a full view of a concurrent type. The
3031 -- controlling parameter of the spec carries the concurrent type,
3032 -- not the corresponding record type as transformed by Analyze_
3033 -- Subprogram_Specification. In such cases, we undo the change
3034 -- made by the analysis of the specification and try to find the
3037 -- Note that wrappers already have their corresponding specs and
3038 -- bodies set during their creation, so if the candidate spec is
3039 -- a wrapper, then we definitely need to swap all types to their
3040 -- original concurrent status.
3043 or else Is_Primitive_Wrapper
(Spec_N
)
3045 -- Restore all references of corresponding record types to the
3046 -- original concurrent types.
3048 Replace_Types
(To_Corresponding
=> False);
3049 Priv_Spec
:= Find_Corresponding_Spec
(N
, False);
3051 -- The current body truly belongs to a primitive declared between
3052 -- a private and a full view. We leave the modified body as is,
3053 -- and return the true spec.
3055 if Present
(Priv_Spec
)
3056 and then Is_Private_Primitive
(Priv_Spec
)
3061 -- In case that this is some sort of error, restore the original
3062 -- state of the body.
3064 Replace_Types
(To_Corresponding
=> True);
3068 end Disambiguate_Spec
;
3070 ----------------------------
3071 -- Exchange_Limited_Views --
3072 ----------------------------
3074 function Exchange_Limited_Views
(Subp_Id
: Entity_Id
) return Elist_Id
is
3075 Result
: Elist_Id
:= No_Elist
;
3077 procedure Detect_And_Exchange
(Id
: Entity_Id
);
3078 -- Determine whether Id's type denotes an incomplete type associated
3079 -- with a limited with clause and exchange the limited view with the
3080 -- non-limited one when available. Note that the non-limited view
3081 -- may exist because of a with_clause in another unit in the context,
3082 -- but cannot be used because the current view of the enclosing unit
3083 -- is still a limited view.
3085 -------------------------
3086 -- Detect_And_Exchange --
3087 -------------------------
3089 procedure Detect_And_Exchange
(Id
: Entity_Id
) is
3090 Typ
: constant Entity_Id
:= Etype
(Id
);
3093 if From_Limited_With
(Typ
)
3094 and then Has_Non_Limited_View
(Typ
)
3095 and then not From_Limited_With
(Scope
(Typ
))
3098 Result
:= New_Elmt_List
;
3101 Prepend_Elmt
(Typ
, Result
);
3102 Prepend_Elmt
(Id
, Result
);
3103 Set_Etype
(Id
, Non_Limited_View
(Typ
));
3105 end Detect_And_Exchange
;
3111 -- Start of processing for Exchange_Limited_Views
3114 -- Do not process subprogram bodies as they already use the non-
3115 -- limited view of types.
3117 if Ekind
(Subp_Id
) not in E_Function | E_Procedure
then
3121 -- Examine all formals and swap views when applicable
3123 Formal
:= First_Formal
(Subp_Id
);
3124 while Present
(Formal
) loop
3125 Detect_And_Exchange
(Formal
);
3127 Next_Formal
(Formal
);
3130 -- Process the return type of a function
3132 if Ekind
(Subp_Id
) = E_Function
then
3133 Detect_And_Exchange
(Subp_Id
);
3137 end Exchange_Limited_Views
;
3139 ------------------------------------
3140 -- Generate_Minimum_Accessibility --
3141 ------------------------------------
3143 procedure Generate_Minimum_Accessibility
3144 (Extra_Access
: Entity_Id
;
3145 Related_Form
: Entity_Id
:= Empty
)
3147 Loc
: constant Source_Ptr
:= Sloc
(Body_Nod
);
3151 -- When no related formal exists then we are dealing with an
3152 -- extra accessibility formal for a function result.
3154 if No
(Related_Form
) then
3155 Form
:= Extra_Access
;
3157 Form
:= Related_Form
;
3160 -- Create the minimum accessibility object
3163 Make_Object_Declaration
(Loc
,
3164 Defining_Identifier
=>
3166 (Loc
, 'A', Extra_Access
),
3167 Object_Definition
=> New_Occurrence_Of
3168 (Standard_Natural
, Loc
),
3170 Make_Attribute_Reference
(Loc
,
3171 Prefix
=> New_Occurrence_Of
3172 (Standard_Natural
, Loc
),
3173 Attribute_Name
=> Name_Min
,
3174 Expressions
=> New_List
(
3175 Make_Integer_Literal
(Loc
,
3176 Scope_Depth
(Body_Id
)),
3178 (Extra_Access
, Loc
))));
3180 -- Add the new local object to the Minimum_Acc_Obj to
3181 -- be later prepended to the subprogram's list of
3182 -- declarations after we are sure all expansion is
3185 if Present
(Minimum_Acc_Objs
) then
3186 Prepend
(Obj_Node
, Minimum_Acc_Objs
);
3188 Minimum_Acc_Objs
:= New_List
(Obj_Node
);
3191 -- Register the object and analyze it
3193 Set_Minimum_Accessibility
3194 (Form
, Defining_Identifier
(Obj_Node
));
3197 end Generate_Minimum_Accessibility
;
3199 -------------------------------------
3200 -- Is_Private_Concurrent_Primitive --
3201 -------------------------------------
3203 function Is_Private_Concurrent_Primitive
3204 (Subp_Id
: Entity_Id
) return Boolean
3206 Formal_Typ
: Entity_Id
;
3209 if Present
(First_Formal
(Subp_Id
)) then
3210 Formal_Typ
:= Etype
(First_Formal
(Subp_Id
));
3212 if Is_Concurrent_Record_Type
(Formal_Typ
) then
3213 if Is_Class_Wide_Type
(Formal_Typ
) then
3214 Formal_Typ
:= Root_Type
(Formal_Typ
);
3217 Formal_Typ
:= Corresponding_Concurrent_Type
(Formal_Typ
);
3220 -- The type of the first formal is a concurrent tagged type with
3224 Is_Concurrent_Type
(Formal_Typ
)
3225 and then Is_Tagged_Type
(Formal_Typ
)
3226 and then Has_Private_Declaration
(Formal_Typ
);
3230 end Is_Private_Concurrent_Primitive
;
3232 -------------------------
3233 -- Mask_Unfrozen_Types --
3234 -------------------------
3236 function Mask_Unfrozen_Types
(Spec_Id
: Entity_Id
) return Elist_Id
is
3237 Result
: Elist_Id
:= No_Elist
;
3239 function Mask_Type_Refs
(Node
: Node_Id
) return Traverse_Result
;
3240 -- Mask all types referenced in the subtree rooted at Node as
3243 --------------------
3244 -- Mask_Type_Refs --
3245 --------------------
3247 function Mask_Type_Refs
(Node
: Node_Id
) return Traverse_Result
is
3248 procedure Mask_Type
(Typ
: Entity_Id
);
3249 -- Mask a given type as formally frozen when outside the current
3250 -- scope, or else freeze the type.
3256 procedure Mask_Type
(Typ
: Entity_Id
) is
3258 -- Skip Itypes created by the preanalysis
3261 and then Scope_Within_Or_Same
(Scope
(Typ
), Spec_Id
)
3266 if not Is_Frozen
(Typ
) then
3267 if Scope
(Typ
) /= Current_Scope
then
3268 Set_Is_Frozen
(Typ
);
3269 Append_New_Elmt
(Typ
, Result
);
3271 Freeze_Before
(N
, Typ
);
3276 -- Start of processing for Mask_Type_Refs
3279 if Is_Entity_Name
(Node
) and then Present
(Entity
(Node
)) then
3280 Mask_Type
(Etype
(Entity
(Node
)));
3282 if Ekind
(Entity
(Node
)) in E_Component | E_Discriminant
then
3283 Mask_Type
(Scope
(Entity
(Node
)));
3286 elsif Nkind
(Node
) in N_Aggregate | N_Null | N_Type_Conversion
3287 and then Present
(Etype
(Node
))
3289 Mask_Type
(Etype
(Node
));
3295 procedure Mask_References
is new Traverse_Proc
(Mask_Type_Refs
);
3299 Return_Stmt
: constant Node_Id
:=
3300 First
(Statements
(Handled_Statement_Sequence
(N
)));
3302 -- Start of processing for Mask_Unfrozen_Types
3305 pragma Assert
(Nkind
(Return_Stmt
) = N_Simple_Return_Statement
);
3307 Mask_References
(Expression
(Return_Stmt
));
3310 end Mask_Unfrozen_Types
;
3316 procedure Move_Pragmas
(From
: Node_Id
; To
: Node_Id
) is
3318 Insert_Nod
: Node_Id
;
3319 Next_Decl
: Node_Id
;
3322 pragma Assert
(Nkind
(From
) = N_Subprogram_Body
);
3324 -- The pragmas are moved in an order-preserving fashion
3328 -- Inspect the declarations of the subprogram body and relocate all
3329 -- candidate pragmas.
3331 Decl
:= First
(Declarations
(From
));
3332 while Present
(Decl
) loop
3334 -- Preserve the following declaration for iteration purposes, due
3335 -- to possible relocation of a pragma.
3337 Next_Decl
:= Next
(Decl
);
3339 if Nkind
(Decl
) = N_Pragma
then
3340 -- Copy pragma SPARK_Mode if present in the declarative list
3341 -- of subprogram body From and insert it after node To. This
3342 -- pragma should not be moved, as it applies to the body too.
3344 if Pragma_Name_Unmapped
(Decl
) = Name_SPARK_Mode
then
3345 Insert_After
(Insert_Nod
, New_Copy_Tree
(Decl
));
3347 -- Move relevant pragmas to the spec
3350 Pragma_Significant_To_Subprograms
3351 (Get_Pragma_Id
(Decl
))
3354 Insert_After
(Insert_Nod
, Decl
);
3358 -- Skip internally generated code
3360 elsif not Comes_From_Source
(Decl
) then
3363 -- No candidate pragmas are available for relocation
3373 ---------------------------
3374 -- Restore_Limited_Views --
3375 ---------------------------
3377 procedure Restore_Limited_Views
(Restore_List
: Elist_Id
) is
3378 Elmt
: Elmt_Id
:= First_Elmt
(Restore_List
);
3382 while Present
(Elmt
) loop
3385 Set_Etype
(Id
, Node
(Elmt
));
3388 end Restore_Limited_Views
;
3390 ----------------------------
3391 -- Set_Trivial_Subprogram --
3392 ----------------------------
3394 procedure Set_Trivial_Subprogram
(N
: Node_Id
) is
3395 Nxt
: constant Node_Id
:= Next
(N
);
3398 Set_Is_Trivial_Subprogram
(Body_Id
);
3400 if Present
(Spec_Id
) then
3401 Set_Is_Trivial_Subprogram
(Spec_Id
);
3405 and then Nkind
(Nxt
) = N_Simple_Return_Statement
3406 and then No
(Next
(Nxt
))
3407 and then Present
(Expression
(Nxt
))
3408 and then Is_Entity_Name
(Expression
(Nxt
))
3410 Set_Never_Set_In_Source
(Entity
(Expression
(Nxt
)), False);
3412 end Set_Trivial_Subprogram
;
3414 ---------------------------
3415 -- Unmask_Unfrozen_Types --
3416 ---------------------------
3418 procedure Unmask_Unfrozen_Types
(Unmask_List
: Elist_Id
) is
3419 Elmt
: Elmt_Id
:= First_Elmt
(Unmask_List
);
3422 while Present
(Elmt
) loop
3423 Set_Is_Frozen
(Node
(Elmt
), False);
3426 end Unmask_Unfrozen_Types
;
3428 ---------------------------------
3429 -- Verify_Overriding_Indicator --
3430 ---------------------------------
3432 procedure Verify_Overriding_Indicator
is
3434 if Must_Override
(Body_Spec
) then
3435 if Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
3436 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
3440 -- Overridden controlled primitives may have had their
3441 -- Overridden_Operation field cleared according to the setting of
3442 -- the Is_Hidden flag. An issue arises, however, when analyzing
3443 -- an instance that may have manipulated the flag during
3444 -- expansion. As a result, we add an exception for this case.
3446 elsif No
(Overridden_Operation
(Spec_Id
))
3447 and then not (Chars
(Spec_Id
) in Name_Adjust
3450 and then In_Instance
)
3453 ("subprogram& is not overriding", Body_Spec
, Spec_Id
);
3455 -- Overriding indicators aren't allowed for protected subprogram
3456 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
3457 -- this to a warning if -gnatd.E is enabled.
3459 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
3460 Error_Msg_Warn
:= Error_To_Warning
;
3462 ("<<overriding indicator not allowed for protected "
3463 & "subprogram body", Body_Spec
);
3466 elsif Must_Not_Override
(Body_Spec
) then
3467 if Present
(Overridden_Operation
(Spec_Id
)) then
3469 ("subprogram& overrides inherited operation",
3470 Body_Spec
, Spec_Id
);
3472 elsif Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
3473 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
3476 ("subprogram& overrides predefined operator",
3477 Body_Spec
, Spec_Id
);
3479 -- Overriding indicators aren't allowed for protected subprogram
3480 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
3481 -- this to a warning if -gnatd.E is enabled.
3483 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
3484 Error_Msg_Warn
:= Error_To_Warning
;
3487 ("<<overriding indicator not allowed "
3488 & "for protected subprogram body", Body_Spec
);
3490 -- If this is not a primitive operation, then the overriding
3491 -- indicator is altogether illegal.
3493 elsif not Is_Primitive
(Spec_Id
) then
3495 ("overriding indicator only allowed "
3496 & "if subprogram is primitive", Body_Spec
);
3499 -- If checking the style rule and the operation overrides, then
3500 -- issue a warning about a missing overriding_indicator. Protected
3501 -- subprogram bodies are excluded from this style checking, since
3502 -- they aren't primitives (even though their declarations can
3503 -- override) and aren't allowed to have an overriding_indicator.
3506 and then Present
(Overridden_Operation
(Spec_Id
))
3507 and then Ekind
(Scope
(Spec_Id
)) /= E_Protected_Type
3509 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
3510 Style
.Missing_Overriding
(N
, Body_Id
);
3513 and then Can_Override_Operator
(Spec_Id
)
3514 and then not In_Predefined_Unit
(Spec_Id
)
3516 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
3517 Style
.Missing_Overriding
(N
, Body_Id
);
3519 end Verify_Overriding_Indicator
;
3523 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
3524 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
3525 Saved_EA
: constant Boolean := Expander_Active
;
3526 Saved_ISMP
: constant Boolean :=
3527 Ignore_SPARK_Mode_Pragmas_In_Instance
;
3528 -- Save the Ghost and SPARK mode-related data to restore on exit
3530 -- Start of processing for Analyze_Subprogram_Body_Helper
3533 -- A [generic] subprogram body freezes the contract of the nearest
3534 -- enclosing package body and all other contracts encountered in the
3535 -- same declarative part up to and excluding the subprogram body:
3537 -- package body Nearest_Enclosing_Package
3538 -- with Refined_State => (State => Constit)
3542 -- procedure Freezes_Enclosing_Package_Body
3543 -- with Refined_Depends => (Input => Constit) ...
3545 -- This ensures that any annotations referenced by the contract of the
3546 -- [generic] subprogram body are available. This form of freezing is
3547 -- decoupled from the usual Freeze_xxx mechanism because it must also
3548 -- work in the context of generics where normal freezing is disabled.
3550 -- Only bodies coming from source should cause this type of freezing.
3551 -- Expression functions that act as bodies and complete an initial
3552 -- declaration must be included in this category, hence the use of
3555 if Comes_From_Source
(Original_Node
(N
)) then
3556 Freeze_Previous_Contracts
(N
);
3559 -- Generic subprograms are handled separately. They always have a
3560 -- generic specification. Determine whether current scope has a
3561 -- previous declaration.
3563 -- If the subprogram body is defined within an instance of the same
3564 -- name, the instance appears as a package renaming, and will be hidden
3565 -- within the subprogram.
3567 if Present
(Prev_Id
)
3568 and then not Is_Overloadable
(Prev_Id
)
3569 and then (Nkind
(Parent
(Prev_Id
)) /= N_Package_Renaming_Declaration
3570 or else Comes_From_Source
(Prev_Id
))
3572 if Is_Generic_Subprogram
(Prev_Id
) then
3575 -- A subprogram body is Ghost when it is stand-alone and subject
3576 -- to pragma Ghost or when the corresponding spec is Ghost. Set
3577 -- the mode now to ensure that any nodes generated during analysis
3578 -- and expansion are properly marked as Ghost.
3580 Mark_And_Set_Ghost_Body
(N
, Spec_Id
);
3582 -- If the body completes the initial declaration of a compilation
3583 -- unit which is subject to pragma Elaboration_Checks, set the
3584 -- model specified by the pragma because it applies to all parts
3587 Install_Elaboration_Model
(Spec_Id
);
3589 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3590 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3592 Analyze_Generic_Subprogram_Body
(N
, Spec_Id
);
3594 if Nkind
(N
) = N_Subprogram_Body
then
3595 Check_Missing_Return
;
3600 -- Otherwise a previous entity conflicts with the subprogram name.
3601 -- Attempting to enter name will post error.
3604 Enter_Name
(Body_Id
);
3608 -- Non-generic case, find the subprogram declaration, if one was seen,
3609 -- or enter new overloaded entity in the current scope. If the
3610 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
3611 -- part of the context of one of its subunits. No need to redo the
3614 elsif Prev_Id
= Body_Id
and then Has_Completion
(Body_Id
) then
3618 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
3620 if Nkind
(N
) = N_Subprogram_Body_Stub
3621 or else No
(Corresponding_Spec
(N
))
3623 if Is_Private_Concurrent_Primitive
(Body_Id
) then
3624 Spec_Id
:= Disambiguate_Spec
;
3626 -- A subprogram body is Ghost when it is stand-alone and
3627 -- subject to pragma Ghost or when the corresponding spec is
3628 -- Ghost. Set the mode now to ensure that any nodes generated
3629 -- during analysis and expansion are properly marked as Ghost.
3631 Mark_And_Set_Ghost_Body
(N
, Spec_Id
);
3633 -- If the body completes a compilation unit which is subject
3634 -- to pragma Elaboration_Checks, set the model specified by
3635 -- the pragma because it applies to all parts of the unit.
3637 Install_Elaboration_Model
(Spec_Id
);
3640 Spec_Id
:= Find_Corresponding_Spec
(N
);
3642 -- A subprogram body is Ghost when it is stand-alone and
3643 -- subject to pragma Ghost or when the corresponding spec is
3644 -- Ghost. Set the mode now to ensure that any nodes generated
3645 -- during analysis and expansion are properly marked as Ghost.
3647 Mark_And_Set_Ghost_Body
(N
, Spec_Id
);
3649 -- If the body completes a compilation unit which is subject
3650 -- to pragma Elaboration_Checks, set the model specified by
3651 -- the pragma because it applies to all parts of the unit.
3653 Install_Elaboration_Model
(Spec_Id
);
3655 -- In GNATprove mode, if the body has no previous spec, create
3656 -- one so that the inlining machinery can operate properly.
3657 -- Transfer aspects, if any, to the new spec, so that they
3658 -- are legal and can be processed ahead of the body.
3659 -- We make two copies of the given spec, one for the new
3660 -- declaration, and one for the body.
3661 -- ??? This should be conditioned on front-end inlining rather
3662 -- than GNATprove_Mode.
3664 if No
(Spec_Id
) and then GNATprove_Mode
3666 -- Inlining does not apply during preanalysis of code
3668 and then Full_Analysis
3670 -- Inlining only applies to full bodies, not stubs
3672 and then Nkind
(N
) /= N_Subprogram_Body_Stub
3674 -- Inlining only applies to bodies in the source code, not to
3675 -- those generated by the compiler. In particular, expression
3676 -- functions, whose body is generated by the compiler, are
3677 -- treated specially by GNATprove.
3679 and then Comes_From_Source
(Body_Id
)
3681 -- This cannot be done for a compilation unit, which is not
3682 -- in a context where we can insert a new spec.
3684 and then Is_List_Member
(N
)
3686 -- Inlining only applies to subprograms without contracts,
3687 -- as a contract is a sign that GNATprove should perform a
3688 -- modular analysis of the subprogram instead of a contextual
3689 -- analysis at each call site. The same test is performed in
3690 -- Inline.Can_Be_Inlined_In_GNATprove_Mode. It is repeated
3691 -- here in another form (because the contract has not been
3692 -- attached to the body) to avoid front-end errors in case
3693 -- pragmas are used instead of aspects, because the
3694 -- corresponding pragmas in the body would not be transferred
3695 -- to the spec, leading to legality errors.
3697 and then not Body_Has_Contract
3698 and then not Inside_A_Generic
3700 Build_Subprogram_Declaration
;
3702 -- If this is a function that returns a constrained array, and
3703 -- Transform_Function_Array is set, create subprogram
3704 -- declaration to simplify e.g. subsequent C generation.
3707 and then Transform_Function_Array
3708 and then Nkind
(Body_Spec
) = N_Function_Specification
3709 and then Is_Array_Type
(Etype
(Body_Id
))
3710 and then Is_Constrained
(Etype
(Body_Id
))
3712 Build_Subprogram_Declaration
;
3716 -- If this is a duplicate body, no point in analyzing it
3718 if Error_Posted
(N
) then
3722 -- A subprogram body should cause freezing of its own declaration,
3723 -- so, if the body and spec are compilation units, we must do it
3724 -- manually here. Moreover, if the return type is anonymous access
3725 -- to protected subprogram, it must be frozen before the body
3726 -- because its expansion has generated an equivalent type that is
3727 -- used when elaborating the body.
3729 if Present
(Spec_Id
)
3730 and then Nkind
(Parent
(N
)) = N_Compilation_Unit
3732 Freeze_Before
(N
, Spec_Id
);
3734 elsif Is_Access_Subprogram_Type
(Etype
(Body_Id
)) then
3735 Freeze_Before
(N
, Etype
(Body_Id
));
3739 Spec_Id
:= Corresponding_Spec
(N
);
3741 -- A subprogram body is Ghost when it is stand-alone and subject
3742 -- to pragma Ghost or when the corresponding spec is Ghost. Set
3743 -- the mode now to ensure that any nodes generated during analysis
3744 -- and expansion are properly marked as Ghost.
3746 Mark_And_Set_Ghost_Body
(N
, Spec_Id
);
3748 -- If the body completes the initial declaration of a compilation
3749 -- unit which is subject to pragma Elaboration_Checks, set the
3750 -- model specified by the pragma because it applies to all parts
3753 Install_Elaboration_Model
(Spec_Id
);
3757 -- Deactivate expansion inside the body of ignored Ghost entities,
3758 -- as this code will ultimately be ignored. This avoids requiring the
3759 -- presence of run-time units which are not needed. Only do this for
3760 -- user entities, as internally generated entitities might still need
3761 -- to be expanded (e.g. those generated for types).
3763 if Present
(Ignored_Ghost_Region
)
3764 and then Comes_From_Source
(Body_Id
)
3766 Expander_Active
:= False;
3769 -- Previously we scanned the body to look for nested subprograms, and
3770 -- rejected an inline directive if nested subprograms were present,
3771 -- because the back-end would generate conflicting symbols for the
3772 -- nested bodies. This is now unnecessary.
3774 -- Look ahead to recognize a pragma Inline that appears after the body
3776 Check_Inline_Pragma
(Spec_Id
);
3778 -- Deal with special case of a fully private operation in the body of
3779 -- the protected type. We must create a declaration for the subprogram,
3780 -- in order to attach the subprogram that will be used in internal
3781 -- calls. We exclude compiler generated bodies from the expander since
3782 -- the issue does not arise for those cases.
3785 and then Comes_From_Source
(N
)
3786 and then Is_Protected_Type
(Current_Scope
)
3788 Spec_Id
:= Build_Internal_Protected_Declaration
(N
);
3791 -- If Transform_Function_Array is set and this is a function returning a
3792 -- constrained array type for which we must create a procedure with an
3793 -- extra out parameter, build and analyze the body now. The procedure
3794 -- declaration has already been created. We reuse the source body of the
3795 -- function, because in an instance it may contain global references
3796 -- that cannot be reanalyzed. The source function itself is not used any
3797 -- further, so we mark it as having a completion. If the subprogram is a
3798 -- stub the transformation is done later, when the proper body is
3802 and then Transform_Function_Array
3803 and then Nkind
(N
) /= N_Subprogram_Body_Stub
3806 S
: constant Entity_Id
:=
3807 (if Present
(Spec_Id
)
3809 else Defining_Unit_Name
(Specification
(N
)));
3810 Proc_Body
: Node_Id
;
3813 if Ekind
(S
) = E_Function
and then Rewritten_For_C
(S
) then
3814 Set_Has_Completion
(S
);
3815 Proc_Body
:= Build_Procedure_Body_Form
(S
, N
);
3817 if Present
(Spec_Id
) then
3818 Rewrite
(N
, Proc_Body
);
3821 -- The entity for the created procedure must remain
3822 -- invisible, so it does not participate in resolution of
3823 -- subsequent references to the function.
3825 Set_Is_Immediately_Visible
(Corresponding_Spec
(N
), False);
3827 -- If we do not have a separate spec for N, build one and
3828 -- insert the new body right after.
3832 Make_Subprogram_Declaration
(Loc
,
3833 Specification
=> Relocate_Node
(Specification
(N
))));
3835 Insert_After_And_Analyze
(N
, Proc_Body
);
3836 Set_Is_Immediately_Visible
3837 (Corresponding_Spec
(Proc_Body
), False);
3845 -- If a separate spec is present, then deal with freezing issues
3847 if Present
(Spec_Id
) then
3848 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
3849 Verify_Overriding_Indicator
;
3851 -- For functions with separate spec, if their return type was visible
3852 -- through a limited-with context clause, their extra formals were
3853 -- not added when the spec was frozen. Now the full view must be
3854 -- available, and the extra formals can be created and Returns_By_Ref
3855 -- computed (required to generate its return statements).
3857 if Ekind
(Spec_Id
) = E_Function
3858 and then From_Limited_With
(Etype
(Spec_Id
))
3859 and then Is_Build_In_Place_Function
(Spec_Id
)
3860 and then not Has_BIP_Formals
(Spec_Id
)
3862 Create_Extra_Formals
(Spec_Id
);
3863 Compute_Returns_By_Ref
(Spec_Id
);
3866 -- In general, the spec will be frozen when we start analyzing the
3867 -- body. However, for internally generated operations, such as
3868 -- wrapper functions for inherited operations with controlling
3869 -- results, the spec may not have been frozen by the time we expand
3870 -- the freeze actions that include the bodies. In particular, extra
3871 -- formals for accessibility or for return-in-place may need to be
3872 -- generated. Freeze nodes, if any, are inserted before the current
3873 -- body. These freeze actions are also needed in Compile_Only mode to
3874 -- enable the proper back-end type annotations.
3875 -- They are necessary in any case to ensure proper elaboration order
3878 if Nkind
(N
) = N_Subprogram_Body
3879 and then Was_Expression_Function
(N
)
3880 and then not Has_Completion
(Spec_Id
)
3881 and then Serious_Errors_Detected
= 0
3882 and then (Expander_Active
3883 or else Operating_Mode
= Check_Semantics
3884 or else Is_Ignored_Ghost_Entity
(Spec_Id
))
3886 -- The body generated for an expression function that is not a
3887 -- completion is a freeze point neither for the profile nor for
3888 -- anything else. That's why, in order to prevent any freezing
3889 -- during analysis, we need to mask types declared outside the
3890 -- expression (and in an outer scope) that are not yet frozen.
3891 -- This also needs to be done in the case of an ignored Ghost
3892 -- expression function, where the expander isn't active.
3894 -- A further complication arises if the expression function is
3895 -- a primitive operation of a tagged type: in that case the
3896 -- function entity must be frozen before the dispatch table for
3897 -- the type is constructed, so it will be frozen like other local
3898 -- entities, at the end of the current scope.
3900 if not Is_Dispatching_Operation
(Spec_Id
) then
3901 Set_Is_Frozen
(Spec_Id
);
3904 Mask_Types
:= Mask_Unfrozen_Types
(Spec_Id
);
3906 elsif not Is_Frozen
(Spec_Id
)
3907 and then Serious_Errors_Detected
= 0
3909 Set_Has_Delayed_Freeze
(Spec_Id
);
3910 Freeze_Before
(N
, Spec_Id
);
3914 -- Place subprogram on scope stack, and make formals visible. If there
3915 -- is a spec, the visible entity remains that of the spec.
3917 if Present
(Spec_Id
) then
3918 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
3920 if Is_Child_Unit
(Spec_Id
) then
3921 Generate_Reference
(Spec_Id
, Scope
(Spec_Id
), 'k', False);
3925 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
3928 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3929 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3931 if Is_Abstract_Subprogram
(Spec_Id
) then
3932 Error_Msg_N
("an abstract subprogram cannot have a body", N
);
3936 Set_Convention
(Body_Id
, Convention
(Spec_Id
));
3937 Set_Has_Completion
(Spec_Id
);
3939 if Is_Protected_Type
(Scope
(Spec_Id
)) then
3940 Prot_Typ
:= Scope
(Spec_Id
);
3943 -- If this is a body generated for a renaming, do not check for
3944 -- full conformance. The check is redundant, because the spec of
3945 -- the body is a copy of the spec in the renaming declaration,
3946 -- and the test can lead to spurious errors on nested defaults.
3948 if Present
(Spec_Decl
)
3949 and then not Comes_From_Source
(N
)
3951 (Nkind
(Original_Node
(Spec_Decl
)) =
3952 N_Subprogram_Renaming_Declaration
3953 or else (Present
(Corresponding_Body
(Spec_Decl
))
3955 Nkind
(Unit_Declaration_Node
3956 (Corresponding_Body
(Spec_Decl
))) =
3957 N_Subprogram_Renaming_Declaration
))
3961 -- Conversely, the spec may have been generated for specless body
3962 -- with an inline pragma. The entity comes from source, which is
3963 -- both semantically correct and necessary for proper inlining.
3964 -- The subprogram declaration itself is not in the source.
3966 elsif Comes_From_Source
(N
)
3967 and then Present
(Spec_Decl
)
3968 and then not Comes_From_Source
(Spec_Decl
)
3969 and then Has_Pragma_Inline
(Spec_Id
)
3973 -- Finally, a body generated for an expression function copies
3974 -- the profile of the function and no check is needed either.
3975 -- If the body is the completion of a previous function
3976 -- declared elsewhere, the conformance check is required.
3978 elsif Nkind
(N
) = N_Subprogram_Body
3979 and then Was_Expression_Function
(N
)
3980 and then Sloc
(Spec_Id
) = Sloc
(Body_Id
)
3987 Fully_Conformant
, True, Conformant
, Body_Id
);
3990 -- If the body is not fully conformant, we have to decide if we
3991 -- should analyze it or not. If it has a really messed up profile
3992 -- then we probably should not analyze it, since we will get too
3993 -- many bogus messages.
3995 -- Our decision is to go ahead in the non-fully conformant case
3996 -- only if it is at least mode conformant with the spec. Note
3997 -- that the call to Check_Fully_Conformant has issued the proper
3998 -- error messages to complain about the lack of conformance.
4001 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
4007 -- In the case we are dealing with an expression function we check
4008 -- the formals attached to the spec instead of the body - so we don't
4009 -- reference body formals.
4011 if Spec_Id
/= Body_Id
4012 and then not Is_Expression_Function
(Spec_Id
)
4014 Reference_Body_Formals
(Spec_Id
, Body_Id
);
4017 Reinit_Field_To_Zero
(Body_Id
, F_Has_Out_Or_In_Out_Parameter
,
4018 Old_Ekind
=> (E_Function | E_Procedure
=> True, others => False));
4019 Reinit_Field_To_Zero
(Body_Id
, F_Needs_No_Actuals
);
4020 Reinit_Field_To_Zero
(Body_Id
, F_Is_Predicate_Function
);
4021 Reinit_Field_To_Zero
(Body_Id
, F_Protected_Subprogram
);
4022 Reinit_Field_To_Zero
(Body_Id
, F_Is_Inlined_Always
);
4023 Reinit_Field_To_Zero
(Body_Id
, F_Is_Generic_Actual_Subprogram
);
4024 Reinit_Field_To_Zero
(Body_Id
, F_Is_Primitive_Wrapper
);
4025 Reinit_Field_To_Zero
(Body_Id
, F_Is_Private_Primitive
);
4026 Reinit_Field_To_Zero
(Body_Id
, F_Original_Protected_Subprogram
);
4027 Reinit_Field_To_Zero
(Body_Id
, F_Wrapped_Entity
);
4029 if Ekind
(Body_Id
) = E_Procedure
then
4030 Reinit_Field_To_Zero
(Body_Id
, F_Receiving_Entry
);
4033 Mutate_Ekind
(Body_Id
, E_Subprogram_Body
);
4035 if Nkind
(N
) = N_Subprogram_Body_Stub
then
4036 Set_Corresponding_Spec_Of_Stub
(N
, Spec_Id
);
4041 Set_Corresponding_Spec
(N
, Spec_Id
);
4043 -- Ada 2005 (AI-345): If the operation is a primitive operation
4044 -- of a concurrent type, the type of the first parameter has been
4045 -- replaced with the corresponding record, which is the proper
4046 -- run-time structure to use. However, within the body there may
4047 -- be uses of the formals that depend on primitive operations
4048 -- of the type (in particular calls in prefixed form) for which
4049 -- we need the original concurrent type. The operation may have
4050 -- several controlling formals, so the replacement must be done
4053 if Comes_From_Source
(Spec_Id
)
4054 and then Present
(First_Entity
(Spec_Id
))
4055 and then Ekind
(Etype
(First_Entity
(Spec_Id
))) = E_Record_Type
4056 and then Is_Tagged_Type
(Etype
(First_Entity
(Spec_Id
)))
4057 and then Present
(Interfaces
(Etype
(First_Entity
(Spec_Id
))))
4058 and then Present
(Corresponding_Concurrent_Type
4059 (Etype
(First_Entity
(Spec_Id
))))
4062 Typ
: constant Entity_Id
:= Etype
(First_Entity
(Spec_Id
));
4066 Form
:= First_Formal
(Spec_Id
);
4067 while Present
(Form
) loop
4068 if Etype
(Form
) = Typ
then
4069 Set_Etype
(Form
, Corresponding_Concurrent_Type
(Typ
));
4077 -- Make the formals visible, and place subprogram on scope stack.
4078 -- This is also the point at which we set Last_Real_Spec_Entity
4079 -- to mark the entities which will not be moved to the body.
4081 Install_Formals
(Spec_Id
);
4082 Last_Real_Spec_Entity
:= Last_Entity
(Spec_Id
);
4084 -- Within an instance, add local renaming declarations so that
4085 -- gdb can retrieve the values of actuals more easily. This is
4086 -- only relevant if generating code.
4088 if Is_Generic_Instance
(Spec_Id
)
4089 and then Is_Wrapper_Package
(Current_Scope
)
4090 and then Expander_Active
4092 Build_Subprogram_Instance_Renamings
(N
, Current_Scope
);
4095 Push_Scope
(Spec_Id
);
4097 -- Make sure that the subprogram is immediately visible. For
4098 -- child units that have no separate spec this is indispensable.
4099 -- Otherwise it is safe albeit redundant.
4101 Set_Is_Immediately_Visible
(Spec_Id
);
4104 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
4105 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Spec_Id
));
4106 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
4108 -- Case of subprogram body with no previous spec
4111 -- Check for style warning required
4115 -- Only apply check for source level subprograms for which checks
4116 -- have not been suppressed.
4118 and then Comes_From_Source
(Body_Id
)
4119 and then not Suppress_Style_Checks
(Body_Id
)
4121 -- No warnings within an instance
4123 and then not In_Instance
4125 -- No warnings for expression functions
4127 and then (Nkind
(N
) /= N_Subprogram_Body
4128 or else not Was_Expression_Function
(N
))
4130 Style
.Body_With_No_Spec
(N
);
4133 -- First set Acts_As_Spec if appropriate
4135 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
4136 Set_Acts_As_Spec
(N
);
4139 New_Overloaded_Entity
(Body_Id
);
4141 -- A subprogram body should cause freezing of its own declaration,
4142 -- but if there was no previous explicit declaration, then the
4143 -- subprogram will get frozen too late (there may be code within
4144 -- the body that depends on the subprogram having been frozen,
4145 -- such as uses of extra formals), so we force it to be frozen here.
4146 -- An exception in Ada 2012 is that the body created for expression
4147 -- functions does not freeze.
4149 if Nkind
(N
) /= N_Subprogram_Body
4150 or else not Was_Expression_Function
(N
)
4152 -- First clear the Is_Public flag on thunks since they are only
4153 -- referenced locally by dispatch tables and thus never inlined.
4155 if Is_Thunk
(Body_Id
) then
4156 Set_Is_Public
(Body_Id
, False);
4159 Freeze_Before
(N
, Body_Id
);
4162 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
4163 Generate_Definition
(Body_Id
);
4165 (Body_Id
, Body_Id
, 'b', Set_Ref
=> False, Force
=> True);
4167 -- If the body is an entry wrapper created for an entry with
4168 -- preconditions, it must be compiled in the context of the
4169 -- enclosing synchronized object, because it may mention other
4170 -- operations of the type.
4172 if Is_Entry_Wrapper
(Body_Id
) then
4174 Prot
: constant Entity_Id
:= Etype
(First_Entity
(Body_Id
));
4177 Install_Declarations
(Prot
);
4181 Install_Formals
(Body_Id
);
4183 Push_Scope
(Body_Id
);
4186 -- For stubs and bodies with no previous spec, generate references to
4189 Generate_Reference_To_Formals
(Body_Id
);
4192 -- Entry barrier functions are generated outside the protected type and
4193 -- should not carry the SPARK_Mode of the enclosing context.
4195 if Nkind
(N
) = N_Subprogram_Body
4196 and then Is_Entry_Barrier_Function
(N
)
4200 -- The body is generated as part of expression function expansion. When
4201 -- the expression function appears in the visible declarations of a
4202 -- package, the body is added to the private declarations. Since both
4203 -- declarative lists may be subject to a different SPARK_Mode, inherit
4204 -- the mode of the spec.
4206 -- package P with SPARK_Mode is
4207 -- function Expr_Func ... is (...); -- original
4208 -- [function Expr_Func ...;] -- generated spec
4211 -- pragma SPARK_Mode (Off);
4212 -- [function Expr_Func ... is return ...;] -- generated body
4213 -- end P; -- mode is ON
4215 elsif not Comes_From_Source
(N
)
4216 and then Present
(Spec_Id
)
4217 and then Is_Expression_Function
(Spec_Id
)
4219 Set_SPARK_Pragma
(Body_Id
, SPARK_Pragma
(Spec_Id
));
4220 Set_SPARK_Pragma_Inherited
4221 (Body_Id
, SPARK_Pragma_Inherited
(Spec_Id
));
4223 -- Set the SPARK_Mode from the current context (may be overwritten later
4224 -- with explicit pragma). Exclude the case where the SPARK_Mode appears
4225 -- initially on a stand-alone subprogram body, but is then relocated to
4226 -- a generated corresponding spec. In this scenario the mode is shared
4227 -- between the spec and body.
4229 elsif No
(SPARK_Pragma
(Body_Id
)) then
4230 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
4231 Set_SPARK_Pragma_Inherited
(Body_Id
);
4234 -- A subprogram body may be instantiated or inlined at a later pass.
4235 -- Restore the state of Ignore_SPARK_Mode_Pragmas_In_Instance when it
4236 -- applied to the initial declaration of the body.
4238 if Present
(Spec_Id
) then
4239 if Ignore_SPARK_Mode_Pragmas
(Spec_Id
) then
4240 Ignore_SPARK_Mode_Pragmas_In_Instance
:= True;
4244 -- Save the state of flag Ignore_SPARK_Mode_Pragmas_In_Instance in
4245 -- case the body is instantiated or inlined later and out of context.
4246 -- The body uses this attribute to restore the value of the global
4249 if Ignore_SPARK_Mode_Pragmas_In_Instance
then
4250 Set_Ignore_SPARK_Mode_Pragmas
(Body_Id
);
4252 elsif Ignore_SPARK_Mode_Pragmas
(Body_Id
) then
4253 Ignore_SPARK_Mode_Pragmas_In_Instance
:= True;
4257 -- Preserve relevant elaboration-related attributes of the context which
4258 -- are no longer available or very expensive to recompute once analysis,
4259 -- resolution, and expansion are over.
4261 if No
(Spec_Id
) then
4262 Mark_Elaboration_Attributes
4268 -- If this is the proper body of a stub, we must verify that the stub
4269 -- conforms to the body, and to the previous spec if one was present.
4270 -- We know already that the body conforms to that spec. This test is
4271 -- only required for subprograms that come from source.
4273 if Nkind
(Parent
(N
)) = N_Subunit
4274 and then Comes_From_Source
(N
)
4275 and then not Error_Posted
(Body_Id
)
4276 and then Nkind
(Corresponding_Stub
(Parent
(N
))) =
4277 N_Subprogram_Body_Stub
4280 Old_Id
: constant Entity_Id
:=
4282 (Specification
(Corresponding_Stub
(Parent
(N
))));
4284 Conformant
: Boolean := False;
4287 if No
(Spec_Id
) then
4288 Check_Fully_Conformant
(Body_Id
, Old_Id
);
4292 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
4294 if not Conformant
then
4296 -- The stub was taken to be a new declaration. Indicate that
4299 Set_Has_Completion
(Old_Id
, False);
4305 Set_Has_Completion
(Body_Id
);
4306 Check_Eliminated
(Body_Id
);
4308 -- Analyze any aspect specifications that appear on the subprogram body
4309 -- stub. Stop the analysis now as the stub does not have a declarative
4310 -- or a statement part, and it cannot be inlined.
4312 if Nkind
(N
) = N_Subprogram_Body_Stub
then
4313 if Has_Aspects
(N
) then
4314 Analyze_Aspects_On_Subprogram_Body_Or_Stub
(N
);
4323 and then Serious_Errors_Detected
= 0
4324 and then Present
(Spec_Id
)
4325 and then Has_Pragma_Inline
(Spec_Id
)
4327 -- Legacy implementation (relying on front-end inlining)
4329 if not Back_End_Inlining
then
4330 if Has_Pragma_Inline_Always
(Spec_Id
)
4331 or else (Front_End_Inlining
4332 and then not Opt
.Disable_FE_Inline
)
4334 Build_Body_To_Inline
(N
, Spec_Id
);
4337 -- New implementation (relying on back-end inlining)
4340 if Has_Pragma_Inline_Always
(Spec_Id
)
4341 or else Optimization_Level
> 0
4343 -- Handle function returning an unconstrained type
4345 if Comes_From_Source
(Body_Id
)
4346 and then Ekind
(Spec_Id
) = E_Function
4347 and then Returns_Unconstrained_Type
(Spec_Id
)
4349 -- If function builds in place, i.e. returns a limited type,
4350 -- inlining cannot be done.
4352 and then not Is_Limited_Type
(Etype
(Spec_Id
))
4354 Check_And_Split_Unconstrained_Function
(N
, Spec_Id
, Body_Id
);
4358 Subp_Body
: constant Node_Id
:=
4359 Unit_Declaration_Node
(Body_Id
);
4360 Subp_Decl
: constant List_Id
:= Declarations
(Subp_Body
);
4363 -- Do not pass inlining to the backend if the subprogram
4364 -- has declarations or statements which cannot be inlined
4365 -- by the backend. This check is done here to emit an
4366 -- error instead of the generic warning message reported
4367 -- by the GCC backend (ie. "function might not be
4370 if Has_Excluded_Declaration
(Spec_Id
, Subp_Decl
) then
4373 elsif Has_Excluded_Statement
4376 (Handled_Statement_Sequence
(Subp_Body
)))
4380 -- If the backend inlining is available then at this
4381 -- stage we only have to mark the subprogram as inlined.
4382 -- The expander will take care of registering it in the
4383 -- table of subprograms inlined by the backend a part of
4384 -- processing calls to it (cf. Expand_Call)
4387 Set_Is_Inlined
(Spec_Id
);
4394 -- In GNATprove mode, inline only when there is a separate subprogram
4395 -- declaration for now, as inlining of subprogram bodies acting as
4396 -- declarations, or subprogram stubs, are not supported by front-end
4397 -- inlining. This inlining should occur after analysis of the body, so
4398 -- that it is known whether the value of SPARK_Mode, which can be
4399 -- defined by a pragma inside the body, is applicable to the body.
4400 -- Inlining can be disabled with switch -gnatdm
4402 elsif GNATprove_Mode
4403 and then Full_Analysis
4404 and then not Inside_A_Generic
4405 and then Present
(Spec_Id
)
4407 Nkind
(Unit_Declaration_Node
(Spec_Id
)) = N_Subprogram_Declaration
4408 and then Body_Has_SPARK_Mode_On
4409 and then Can_Be_Inlined_In_GNATprove_Mode
(Spec_Id
, Body_Id
)
4410 and then not Body_Has_Contract
4411 and then not Debug_Flag_M
4413 Build_Body_To_Inline
(N
, Spec_Id
);
4416 -- When generating code, inherited pre/postconditions are handled when
4417 -- expanding the corresponding contract.
4419 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
4420 -- of the specification we have to install the private withed units.
4421 -- This holds for child units as well.
4423 if Is_Compilation_Unit
(Body_Id
)
4424 or else Nkind
(Parent
(N
)) = N_Compilation_Unit
4426 Install_Private_With_Clauses
(Body_Id
);
4429 Check_Anonymous_Return
;
4431 -- Set the Protected_Formal field of each extra formal of the protected
4432 -- subprogram to reference the corresponding extra formal of the
4433 -- subprogram that implements it. For regular formals this occurs when
4434 -- the protected subprogram's declaration is expanded, but the extra
4435 -- formals don't get created until the subprogram is frozen. We need to
4436 -- do this before analyzing the protected subprogram's body so that any
4437 -- references to the original subprogram's extra formals will be changed
4438 -- refer to the implementing subprogram's formals (see Expand_Formal).
4440 if Present
(Spec_Id
)
4441 and then Is_Protected_Type
(Scope
(Spec_Id
))
4442 and then Present
(Protected_Body_Subprogram
(Spec_Id
))
4445 Impl_Subp
: constant Entity_Id
:=
4446 Protected_Body_Subprogram
(Spec_Id
);
4447 Prot_Ext_Formal
: Entity_Id
:= Extra_Formals
(Spec_Id
);
4448 Impl_Ext_Formal
: Entity_Id
:= Extra_Formals
(Impl_Subp
);
4451 while Present
(Prot_Ext_Formal
) loop
4452 pragma Assert
(Present
(Impl_Ext_Formal
));
4453 Set_Protected_Formal
(Prot_Ext_Formal
, Impl_Ext_Formal
);
4454 Next_Formal_With_Extras
(Prot_Ext_Formal
);
4455 Next_Formal_With_Extras
(Impl_Ext_Formal
);
4460 -- Generate minimum accessibility local objects to correspond with
4461 -- any extra formal added for anonymous access types. This new local
4462 -- object can then be used instead of the formal in case it is used
4463 -- in an actual to a call to a nested subprogram.
4465 -- This method is used to supplement our "small integer model" for
4466 -- accessibility-check generation (for more information see
4467 -- Accessibility_Level).
4469 -- Because we allow accessibility values greater than our expected value
4470 -- passing along the same extra accessibility formal as an actual
4471 -- to a nested subprogram becomes a problem because high values mean
4472 -- different things to the callee even though they are the same to the
4473 -- caller. So, as described in the first section, we create a local
4474 -- object representing the minimum of the accessibility level value that
4475 -- is passed in and the accessibility level of the callee's parameter
4476 -- and locals and use it in the case of a call to a nested subprogram.
4477 -- This generated object is referred to as a "minimum accessibility
4480 if Present
(Spec_Id
) or else Present
(Body_Id
) then
4481 Body_Nod
:= Unit_Declaration_Node
(Body_Id
);
4486 -- Grab the appropriate formal depending on whether there exists
4487 -- an actual spec for the subprogram or whether we are dealing
4488 -- with a protected subprogram.
4490 if Present
(Spec_Id
) then
4491 if Present
(Protected_Body_Subprogram
(Spec_Id
)) then
4492 Form
:= First_Formal
(Protected_Body_Subprogram
(Spec_Id
));
4494 Form
:= First_Formal
(Spec_Id
);
4497 Form
:= First_Formal
(Body_Id
);
4500 -- Loop through formals if the subprogram is capable of accepting
4501 -- a generated local object. If it is not then it is also not
4502 -- capable of having local subprograms meaning it would not need
4503 -- a minimum accessibility level object anyway.
4505 if Present
(Body_Nod
)
4506 and then Has_Declarations
(Body_Nod
)
4507 and then Nkind
(Body_Nod
) /= N_Package_Specification
4509 while Present
(Form
) loop
4511 if Present
(Extra_Accessibility
(Form
))
4512 and then No
(Minimum_Accessibility
(Form
))
4514 -- Generate the minimum accessibility level object
4516 -- A60b : constant natural := natural'min(1, paramL);
4518 Generate_Minimum_Accessibility
4519 (Extra_Accessibility
(Form
), Form
);
4525 -- Generate the minimum accessibility level object for the
4526 -- function's Extra_Accessibility_Of_Result.
4528 -- A31b : constant natural := natural'min (2, funcL);
4530 if Ekind
(Body_Id
) = E_Function
4531 and then Present
(Extra_Accessibility_Of_Result
(Body_Id
))
4533 Generate_Minimum_Accessibility
4534 (Extra_Accessibility_Of_Result
(Body_Id
));
4536 -- Replace the Extra_Accessibility_Of_Result with the new
4537 -- minimum accessibility object.
4539 Set_Extra_Accessibility_Of_Result
4540 (Body_Id
, Minimum_Accessibility
4541 (Extra_Accessibility_Of_Result
(Body_Id
)));
4547 -- Ada 2012 (AI05-0151): Incomplete types coming from a limited context
4548 -- may now appear in parameter and result profiles. Since the analysis
4549 -- of a subprogram body may use the parameter and result profile of the
4550 -- spec, swap any limited views with their non-limited counterpart.
4552 if Ada_Version
>= Ada_2012
and then Present
(Spec_Id
) then
4553 Exch_Views
:= Exchange_Limited_Views
(Spec_Id
);
4556 -- Analyze any aspect specifications that appear on the subprogram body
4558 if Has_Aspects
(N
) then
4559 Analyze_Aspects_On_Subprogram_Body_Or_Stub
(N
);
4562 -- Process the contract of the subprogram body after analyzing all the
4563 -- contract-related pragmas within the declarations.
4565 Analyze_Pragmas_In_Declarations
(Body_Id
);
4566 Analyze_Entry_Or_Subprogram_Body_Contract
(Body_Id
);
4568 Set_Actual_Subtypes
(N
, Current_Scope
);
4570 -- Add a declaration for the Protection object, renaming declarations
4571 -- for discriminals and privals and finally a declaration for the entry
4572 -- family index (if applicable). This form of early expansion is done
4573 -- when the Expander is active because Install_Private_Data_Declarations
4574 -- references entities which were created during regular expansion. The
4575 -- subprogram entity must come from source, and not be an internally
4576 -- generated subprogram.
4579 and then Present
(Prot_Typ
)
4580 and then Present
(Spec_Id
)
4581 and then Comes_From_Source
(Spec_Id
)
4582 and then not Is_Eliminated
(Spec_Id
)
4584 Install_Private_Data_Declarations
4585 (Sloc
(N
), Spec_Id
, Prot_Typ
, N
, Declarations
(N
));
4588 -- If the return type is an anonymous access type whose designated type
4589 -- is the limited view of a class-wide type and the non-limited view is
4590 -- available, update the return type accordingly.
4592 if Ada_Version
>= Ada_2005
4593 and then Present
(Spec_Id
)
4594 and then Ekind
(Etype
(Spec_Id
)) = E_Anonymous_Access_Type
4600 Etyp
:= Directly_Designated_Type
(Etype
(Spec_Id
));
4602 if Is_Class_Wide_Type
(Etyp
)
4603 and then From_Limited_With
(Etyp
)
4604 and then Has_Non_Limited_View
(Etyp
)
4607 Etyp
:= Non_Limited_View
(Etyp
);
4609 -- If the class-wide type has been created by the completion of
4610 -- an incomplete tagged type declaration, get the class-wide
4611 -- type of the incomplete tagged type to match Find_Type_Name.
4613 if Nkind
(Parent
(Etyp
)) = N_Full_Type_Declaration
4614 and then Present
(Incomplete_View
(Parent
(Etyp
)))
4616 Etyp
:= Class_Wide_Type
(Incomplete_View
(Parent
(Etyp
)));
4619 Set_Directly_Designated_Type
(Etype
(Spec_Id
), Etyp
);
4624 Analyze_Declarations
(Declarations
(N
));
4626 -- Verify that the SPARK_Mode of the body agrees with that of its spec
4628 if Present
(Spec_Id
) and then Present
(SPARK_Pragma
(Body_Id
)) then
4629 if Present
(SPARK_Pragma
(Spec_Id
)) then
4630 if Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Spec_Id
)) = Off
4632 Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Body_Id
)) = On
4634 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
4635 Error_Msg_N
("incorrect application of SPARK_Mode#", N
);
4636 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Spec_Id
));
4638 ("\value Off was set for SPARK_Mode on & #", N
, Spec_Id
);
4641 elsif Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Body_Stub
then
4644 -- SPARK_Mode Off could complete no SPARK_Mode in a generic, either
4645 -- as specified in source code, or because SPARK_Mode On is ignored
4646 -- in an instance where the context is SPARK_Mode Off/Auto.
4648 elsif Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Body_Id
)) = Off
4649 and then (Is_Generic_Unit
(Spec_Id
) or else In_Instance
)
4654 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
4655 Error_Msg_N
("incorrect application of SPARK_Mode #", N
);
4656 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
4658 ("\no value was set for SPARK_Mode on & #", N
, Spec_Id
);
4662 -- Check completion, and analyze the statements
4665 Inspect_Deferred_Constant_Completion
(Declarations
(N
));
4666 Analyze
(Handled_Statement_Sequence
(N
));
4668 -- Add the generated minimum accessibility objects to the subprogram
4669 -- body's list of declarations after analysis of the statements and
4672 while Is_Non_Empty_List
(Minimum_Acc_Objs
) loop
4673 if Present
(Declarations
(Body_Nod
)) then
4674 Prepend
(Remove_Head
(Minimum_Acc_Objs
), Declarations
(Body_Nod
));
4677 (Body_Nod
, New_List
(Remove_Head
(Minimum_Acc_Objs
)));
4681 -- Deal with end of scope processing for the body
4684 (Handled_Statement_Sequence
(N
), 't', Current_Scope
);
4685 Update_Use_Clause_Chain
;
4688 -- If we are compiling an entry wrapper, remove the enclosing
4689 -- synchronized object from the stack.
4691 if Is_Entry_Wrapper
(Body_Id
) then
4695 Check_Subprogram_Order
(N
);
4696 Set_Analyzed
(Body_Id
);
4698 -- If we have a separate spec, then the analysis of the declarations
4699 -- caused the entities in the body to be chained to the spec id, but
4700 -- we want them chained to the body id. Only the formal parameters
4701 -- end up chained to the spec id in this case.
4703 if Present
(Spec_Id
) then
4705 -- We must conform to the categorization of our spec
4707 Validate_Categorization_Dependency
(N
, Spec_Id
);
4709 -- And if this is a child unit, the parent units must conform
4711 if Is_Child_Unit
(Spec_Id
) then
4712 Validate_Categorization_Dependency
4713 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
4716 -- Here is where we move entities from the spec to the body
4718 -- Case where there are entities that stay with the spec
4720 if Present
(Last_Real_Spec_Entity
) then
4722 -- No body entities (happens when the only real spec entities come
4723 -- from precondition and postcondition pragmas).
4725 if No
(Last_Entity
(Body_Id
)) then
4726 Set_First_Entity
(Body_Id
, Next_Entity
(Last_Real_Spec_Entity
));
4728 -- Body entities present (formals), so chain stuff past them
4732 (Last_Entity
(Body_Id
), Next_Entity
(Last_Real_Spec_Entity
));
4735 Set_Next_Entity
(Last_Real_Spec_Entity
, Empty
);
4736 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
4737 Set_Last_Entity
(Spec_Id
, Last_Real_Spec_Entity
);
4739 -- Case where there are no spec entities, in this case there can be
4740 -- no body entities either, so just move everything.
4742 -- If the body is generated for an expression function, it may have
4743 -- been preanalyzed already, if 'access was applied to it.
4746 if Nkind
(Original_Node
(Unit_Declaration_Node
(Spec_Id
))) /=
4747 N_Expression_Function
4749 pragma Assert
(No
(Last_Entity
(Body_Id
)));
4753 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
4754 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
4755 Set_First_Entity
(Spec_Id
, Empty
);
4756 Set_Last_Entity
(Spec_Id
, Empty
);
4759 -- Otherwise the body does not complete a previous declaration. Check
4760 -- the categorization of the body against the units it withs.
4763 Validate_Categorization_Dependency
(N
, Body_Id
);
4766 Check_Missing_Return
;
4768 -- Now we are going to check for variables that are never modified in
4769 -- the body of the procedure. But first we deal with a special case
4770 -- where we want to modify this check. If the body of the subprogram
4771 -- starts with a raise statement or its equivalent, or if the body
4772 -- consists entirely of a null statement, then it is pretty obvious that
4773 -- it is OK to not reference the parameters. For example, this might be
4774 -- the following common idiom for a stubbed function: statement of the
4775 -- procedure raises an exception. In particular this deals with the
4776 -- common idiom of a stubbed function, which appears something like:
4778 -- function F (A : Integer) return Some_Type;
4781 -- raise Program_Error;
4785 -- Here the purpose of X is simply to satisfy the annoying requirement
4786 -- in Ada that there be at least one return, and we certainly do not
4787 -- want to go posting warnings on X that it is not initialized. On
4788 -- the other hand, if X is entirely unreferenced that should still
4791 -- What we do is to detect these cases, and if we find them, flag the
4792 -- subprogram as being Is_Trivial_Subprogram and then use that flag to
4793 -- suppress unwanted warnings. For the case of the function stub above
4794 -- we have a special test to set X as apparently assigned to suppress
4798 Stm
: Node_Id
:= First
(Statements
(Handled_Statement_Sequence
(N
)));
4800 -- Skip call markers installed by the ABE mechanism, labels, and
4801 -- Push_xxx_Error_Label to find the first real statement.
4803 while Nkind
(Stm
) in N_Call_Marker | N_Label | N_Push_xxx_Label
loop
4807 -- Do the test on the original statement before expansion
4810 Ostm
: constant Node_Id
:= Original_Node
(Stm
);
4813 -- If explicit raise statement, turn on flag
4815 if Nkind
(Ostm
) = N_Raise_Statement
then
4816 Set_Trivial_Subprogram
(Stm
);
4818 -- If null statement, and no following statements, turn on flag
4820 elsif Nkind
(Stm
) = N_Null_Statement
4821 and then Comes_From_Source
(Stm
)
4822 and then No
(Next
(Stm
))
4824 Set_Trivial_Subprogram
(Stm
);
4826 -- Check for explicit call cases which likely raise an exception
4828 elsif Nkind
(Ostm
) = N_Procedure_Call_Statement
then
4829 if Is_Entity_Name
(Name
(Ostm
)) then
4831 Ent
: constant Entity_Id
:= Entity
(Name
(Ostm
));
4834 -- If the procedure is marked No_Return, then likely it
4835 -- raises an exception, but in any case it is not coming
4836 -- back here, so turn on the flag.
4839 and then Ekind
(Ent
) = E_Procedure
4840 and then No_Return
(Ent
)
4842 Set_Trivial_Subprogram
(Stm
);
4850 -- Check if a Body_To_Inline was created, but the subprogram has
4851 -- references to object renamings which will be replaced by the special
4852 -- SPARK expansion into nodes of a different kind, which is not expected
4853 -- by the inlining mechanism. In that case, the Body_To_Inline is
4854 -- deleted prior to being analyzed. This check needs to take place
4855 -- after analysis of the subprogram body.
4858 and then Present
(Spec_Id
)
4860 Nkind
(Unit_Declaration_Node
(Spec_Id
)) = N_Subprogram_Declaration
4861 and then Present
(Body_To_Inline
(Unit_Declaration_Node
(Spec_Id
)))
4863 Check_Object_Renaming_In_GNATprove_Mode
(Spec_Id
);
4866 -- Check for variables that are never modified
4873 -- If there is a separate spec, then transfer Never_Set_In_Source
4874 -- flags from out parameters to the corresponding entities in the
4875 -- body. The reason we do that is we want to post error flags on
4876 -- the body entities, not the spec entities.
4878 if Present
(Spec_Id
) then
4879 F1
:= First_Formal
(Spec_Id
);
4880 while Present
(F1
) loop
4881 if Ekind
(F1
) = E_Out_Parameter
then
4882 F2
:= First_Formal
(Body_Id
);
4883 while Present
(F2
) loop
4884 exit when Chars
(F1
) = Chars
(F2
);
4888 if Present
(F2
) then
4889 Set_Never_Set_In_Source
(F2
, Never_Set_In_Source
(F1
));
4897 -- Check references of the subprogram spec when we are dealing with
4898 -- an expression function due to it having a generated body.
4900 if Present
(Spec_Id
)
4901 and then Is_Expression_Function
(Spec_Id
)
4903 Check_References
(Spec_Id
);
4905 -- Skip the check for subprograms generated for protected subprograms
4906 -- because it is also done for the protected subprograms themselves.
4908 elsif Present
(Spec_Id
)
4909 and then Present
(Protected_Subprogram
(Spec_Id
))
4913 -- Otherwise, we simply check the formals of the subprogram body.
4916 Check_References
(Body_Id
);
4920 -- Check for nested subprogram, and mark outer level subprogram if so
4926 if Present
(Spec_Id
) then
4933 Ent
:= Enclosing_Subprogram
(Ent
);
4934 exit when No
(Ent
) or else Is_Subprogram
(Ent
);
4937 if Present
(Ent
) then
4938 Set_Has_Nested_Subprogram
(Ent
);
4942 -- Restore the limited views in the spec, if any, to let the back end
4943 -- process it without running into circularities.
4945 if Present
(Exch_Views
) then
4946 Restore_Limited_Views
(Exch_Views
);
4949 if Present
(Mask_Types
) then
4950 Unmask_Unfrozen_Types
(Mask_Types
);
4953 if Present
(Desig_View
) then
4954 Set_Directly_Designated_Type
(Etype
(Spec_Id
), Desig_View
);
4958 if Present
(Ignored_Ghost_Region
) then
4959 Expander_Active
:= Saved_EA
;
4962 Ignore_SPARK_Mode_Pragmas_In_Instance
:= Saved_ISMP
;
4963 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
4964 end Analyze_Subprogram_Body_Helper
;
4966 ------------------------------------
4967 -- Analyze_Subprogram_Declaration --
4968 ------------------------------------
4970 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
4971 Scop
: constant Entity_Id
:= Current_Scope
;
4972 Designator
: Entity_Id
;
4974 Is_Completion
: Boolean;
4975 -- Indicates whether a null procedure declaration is a completion
4978 -- Null procedures are not allowed in SPARK
4980 if Nkind
(Specification
(N
)) = N_Procedure_Specification
4981 and then Null_Present
(Specification
(N
))
4983 -- Null procedures are allowed in protected types, following the
4984 -- recent AI12-0147.
4986 if Is_Protected_Type
(Current_Scope
)
4987 and then Ada_Version
< Ada_2012
4989 Error_Msg_N
("protected operation cannot be a null procedure", N
);
4992 Analyze_Null_Procedure
(N
, Is_Completion
);
4994 -- The null procedure acts as a body, nothing further is needed
4996 if Is_Completion
then
5001 Designator
:= Analyze_Subprogram_Specification
(Specification
(N
));
5003 -- A reference may already have been generated for the unit name, in
5004 -- which case the following call is redundant. However it is needed for
5005 -- declarations that are the rewriting of an expression function.
5007 Generate_Definition
(Designator
);
5009 -- Set the SPARK mode from the current context (may be overwritten later
5010 -- with explicit pragma). This is not done for entry barrier functions
5011 -- because they are generated outside the protected type and should not
5012 -- carry the mode of the enclosing context.
5014 if Nkind
(N
) = N_Subprogram_Declaration
5015 and then Is_Entry_Barrier_Function
(N
)
5020 Set_SPARK_Pragma
(Designator
, SPARK_Mode_Pragma
);
5021 Set_SPARK_Pragma_Inherited
(Designator
);
5024 -- Save the state of flag Ignore_SPARK_Mode_Pragmas_In_Instance in case
5025 -- the body of this subprogram is instantiated or inlined later and out
5026 -- of context. The body uses this attribute to restore the value of the
5029 if Ignore_SPARK_Mode_Pragmas_In_Instance
then
5030 Set_Ignore_SPARK_Mode_Pragmas
(Designator
);
5033 -- Preserve relevant elaboration-related attributes of the context which
5034 -- are no longer available or very expensive to recompute once analysis,
5035 -- resolution, and expansion are over.
5037 Mark_Elaboration_Attributes
5038 (N_Id
=> Designator
,
5042 if Debug_Flag_C
then
5043 Write_Str
("==> subprogram spec ");
5044 Write_Name
(Chars
(Designator
));
5045 Write_Str
(" from ");
5046 Write_Location
(Sloc
(N
));
5051 Validate_RCI_Subprogram_Declaration
(N
);
5052 New_Overloaded_Entity
(Designator
);
5053 Check_Delayed_Subprogram
(Designator
);
5055 -- If the type of the first formal of the current subprogram is a non-
5056 -- generic tagged private type, mark the subprogram as being a private
5057 -- primitive. Ditto if this is a function with controlling result, and
5058 -- the return type is currently private. In both cases, the type of the
5059 -- controlling argument or result must be in the current scope for the
5060 -- operation to be primitive.
5062 if Has_Controlling_Result
(Designator
)
5063 and then Is_Private_Type
(Etype
(Designator
))
5064 and then Scope
(Etype
(Designator
)) = Current_Scope
5065 and then not Is_Generic_Actual_Type
(Etype
(Designator
))
5067 Set_Is_Private_Primitive
(Designator
);
5069 elsif Present
(First_Formal
(Designator
)) then
5071 Formal_Typ
: constant Entity_Id
:=
5072 Etype
(First_Formal
(Designator
));
5074 Set_Is_Private_Primitive
(Designator
,
5075 Is_Tagged_Type
(Formal_Typ
)
5076 and then Scope
(Formal_Typ
) = Current_Scope
5077 and then Is_Private_Type
(Formal_Typ
)
5078 and then not Is_Generic_Actual_Type
(Formal_Typ
));
5082 -- Ada 2005 (AI-251): Abstract interface primitives must be abstract
5085 if Ada_Version
>= Ada_2005
5086 and then Comes_From_Source
(N
)
5087 and then Is_Dispatching_Operation
(Designator
)
5094 if Has_Controlling_Result
(Designator
) then
5095 Etyp
:= Etype
(Designator
);
5098 E
:= First_Entity
(Designator
);
5100 and then Is_Formal
(E
)
5101 and then not Is_Controlling_Formal
(E
)
5109 if Is_Access_Type
(Etyp
) then
5110 Etyp
:= Directly_Designated_Type
(Etyp
);
5113 if Is_Interface
(Etyp
)
5114 and then not Is_Abstract_Subprogram
(Designator
)
5115 and then not (Ekind
(Designator
) = E_Procedure
5116 and then Null_Present
(Specification
(N
)))
5118 Error_Msg_Name_1
:= Chars
(Defining_Entity
(N
));
5120 -- Specialize error message based on procedures vs. functions,
5121 -- since functions can't be null subprograms.
5123 if Ekind
(Designator
) = E_Procedure
then
5125 ("interface procedure % must be abstract or null", N
);
5128 ("interface function % must be abstract", N
);
5134 -- For a compilation unit, set body required. This flag will only be
5135 -- reset if a valid Import or Interface pragma is processed later on.
5137 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
5138 Set_Body_Required
(Parent
(N
), True);
5140 if Ada_Version
>= Ada_2005
5141 and then Nkind
(Specification
(N
)) = N_Procedure_Specification
5142 and then Null_Present
(Specification
(N
))
5145 ("null procedure cannot be declared at library level", N
);
5149 Generate_Reference_To_Formals
(Designator
);
5150 Check_Eliminated
(Designator
);
5152 if Debug_Flag_C
then
5154 Write_Str
("<== subprogram spec ");
5155 Write_Name
(Chars
(Designator
));
5156 Write_Str
(" from ");
5157 Write_Location
(Sloc
(N
));
5161 -- Indicate that this is a protected operation, because it may be used
5162 -- in subsequent declarations within the protected type.
5164 if Is_Protected_Type
(Current_Scope
) then
5165 Set_Convention
(Designator
, Convention_Protected
);
5168 List_Inherited_Pre_Post_Aspects
(Designator
);
5170 -- Process the aspects before establishing the proper categorization in
5171 -- case the subprogram is a compilation unit and one of its aspects is
5172 -- converted into a categorization pragma.
5174 if Has_Aspects
(N
) then
5175 Analyze_Aspect_Specifications
(N
, Designator
);
5178 if Scop
/= Standard_Standard
and then not Is_Child_Unit
(Designator
) then
5179 Set_Categorization_From_Scope
(Designator
, Scop
);
5181 -- Otherwise the unit is a compilation unit and/or a child unit. Set the
5182 -- proper categorization of the unit based on its pragmas.
5185 Push_Scope
(Designator
);
5186 Set_Categorization_From_Pragmas
(N
);
5187 Validate_Categorization_Dependency
(N
, Designator
);
5190 end Analyze_Subprogram_Declaration
;
5192 --------------------------------------
5193 -- Analyze_Subprogram_Specification --
5194 --------------------------------------
5196 -- Reminder: N here really is a subprogram specification (not a subprogram
5197 -- declaration). This procedure is called to analyze the specification in
5198 -- both subprogram bodies and subprogram declarations (specs).
5200 function Analyze_Subprogram_Specification
(N
: Node_Id
) return Entity_Id
is
5201 function Is_Invariant_Procedure_Or_Body
(E
: Entity_Id
) return Boolean;
5202 -- Determine whether entity E denotes the spec or body of an invariant
5205 ------------------------------------
5206 -- Is_Invariant_Procedure_Or_Body --
5207 ------------------------------------
5209 function Is_Invariant_Procedure_Or_Body
(E
: Entity_Id
) return Boolean is
5210 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
5214 if Nkind
(Decl
) = N_Subprogram_Body
then
5215 Spec
:= Corresponding_Spec
(Decl
);
5222 and then Ekind
(Spec
) = E_Procedure
5223 and then (Is_Partial_Invariant_Procedure
(Spec
)
5224 or else Is_Invariant_Procedure
(Spec
));
5225 end Is_Invariant_Procedure_Or_Body
;
5229 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
5230 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
5232 -- Start of processing for Analyze_Subprogram_Specification
5235 -- Proceed with analysis. Do not emit a cross-reference entry if the
5236 -- specification comes from an expression function, because it may be
5237 -- the completion of a previous declaration. If it is not, the cross-
5238 -- reference entry will be emitted for the new subprogram declaration.
5240 if Nkind
(Parent
(N
)) /= N_Expression_Function
then
5241 Generate_Definition
(Designator
);
5244 if Nkind
(N
) = N_Function_Specification
then
5245 Mutate_Ekind
(Designator
, E_Function
);
5246 Set_Mechanism
(Designator
, Default_Mechanism
);
5248 Mutate_Ekind
(Designator
, E_Procedure
);
5249 Set_Etype
(Designator
, Standard_Void_Type
);
5252 Set_Is_Not_Self_Hidden
(Designator
);
5254 -- Flag Is_Inlined_Always is True by default, and reversed to False for
5255 -- those subprograms which could be inlined in GNATprove mode (because
5256 -- Body_To_Inline is non-Empty) but should not be inlined.
5258 if GNATprove_Mode
then
5259 Set_Is_Inlined_Always
(Designator
);
5262 -- Introduce new scope for analysis of the formals and the return type
5264 Set_Scope
(Designator
, Current_Scope
);
5266 if Present
(Formals
) then
5267 Push_Scope
(Designator
);
5268 Process_Formals
(Formals
, N
);
5270 -- Check dimensions in N for formals with default expression
5272 Analyze_Dimension_Formals
(N
, Formals
);
5274 -- Ada 2005 (AI-345): If this is an overriding operation of an
5275 -- inherited interface operation, and the controlling type is
5276 -- a synchronized type, replace the type with its corresponding
5277 -- record, to match the proper signature of an overriding operation.
5278 -- Same processing for an access parameter whose designated type is
5279 -- derived from a synchronized interface.
5281 -- This modification is not done for invariant procedures because
5282 -- the corresponding record may not necessarely be visible when the
5283 -- concurrent type acts as the full view of a private type.
5286 -- type Prot is private with Type_Invariant => ...;
5287 -- procedure ConcInvariant (Obj : Prot);
5289 -- protected type Prot is ...;
5290 -- type Concurrent_Record_Prot is record ...;
5291 -- procedure ConcInvariant (Obj : Prot) is
5293 -- end ConcInvariant;
5296 -- In the example above, both the spec and body of the invariant
5297 -- procedure must utilize the private type as the controlling type.
5299 if Ada_Version
>= Ada_2005
5300 and then not Is_Invariant_Procedure_Or_Body
(Designator
)
5304 Formal_Typ
: Entity_Id
;
5305 Rec_Typ
: Entity_Id
;
5306 Desig_Typ
: Entity_Id
;
5309 Formal
:= First_Formal
(Designator
);
5310 while Present
(Formal
) loop
5311 Formal_Typ
:= Etype
(Formal
);
5313 if Is_Concurrent_Type
(Formal_Typ
)
5314 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
5316 Rec_Typ
:= Corresponding_Record_Type
(Formal_Typ
);
5318 if Present
(Interfaces
(Rec_Typ
)) then
5319 Set_Etype
(Formal
, Rec_Typ
);
5322 elsif Ekind
(Formal_Typ
) = E_Anonymous_Access_Type
then
5323 Desig_Typ
:= Designated_Type
(Formal_Typ
);
5325 if Is_Concurrent_Type
(Desig_Typ
)
5326 and then Present
(Corresponding_Record_Type
(Desig_Typ
))
5328 Rec_Typ
:= Corresponding_Record_Type
(Desig_Typ
);
5330 if Present
(Interfaces
(Rec_Typ
)) then
5331 Set_Directly_Designated_Type
(Formal_Typ
, Rec_Typ
);
5336 Next_Formal
(Formal
);
5343 -- The subprogram scope is pushed and popped around the processing of
5344 -- the return type for consistency with call above to Process_Formals
5345 -- (which itself can call Analyze_Return_Type), and to ensure that any
5346 -- itype created for the return type will be associated with the proper
5349 elsif Nkind
(N
) = N_Function_Specification
then
5350 Push_Scope
(Designator
);
5351 Analyze_Return_Type
(N
);
5357 if Nkind
(N
) = N_Function_Specification
then
5359 -- Deal with operator symbol case
5361 if Nkind
(Designator
) = N_Defining_Operator_Symbol
then
5362 Valid_Operator_Definition
(Designator
);
5365 May_Need_Actuals
(Designator
);
5367 -- Ada 2005 (AI-251): If the return type is abstract, verify that
5368 -- the subprogram is abstract also. This does not apply to renaming
5369 -- declarations, where abstractness is inherited, and to subprogram
5370 -- bodies generated for stream operations, which become renamings as
5371 -- bodies. We also skip the check for thunks.
5373 -- In case of primitives associated with abstract interface types
5374 -- the check is applied later (see Analyze_Subprogram_Declaration).
5376 if Nkind
(Original_Node
(Parent
(N
))) not in
5377 N_Abstract_Subprogram_Declaration |
5378 N_Formal_Abstract_Subprogram_Declaration |
5379 N_Subprogram_Renaming_Declaration
5380 and then not Is_Thunk
(Designator
)
5382 if Is_Abstract_Type
(Etype
(Designator
)) then
5384 ("function that returns abstract type must be abstract", N
);
5386 -- Ada 2012 (AI-0073): Extend this test to subprograms with an
5387 -- access result whose designated type is abstract.
5389 elsif Ada_Version
>= Ada_2012
5390 and then Nkind
(Result_Definition
(N
)) = N_Access_Definition
5392 not Is_Class_Wide_Type
(Designated_Type
(Etype
(Designator
)))
5393 and then Is_Abstract_Type
(Designated_Type
(Etype
(Designator
)))
5396 ("function whose access result designates abstract type "
5397 & "must be abstract", N
);
5403 end Analyze_Subprogram_Specification
;
5405 -----------------------
5406 -- Check_Conformance --
5407 -----------------------
5409 procedure Check_Conformance
5410 (New_Id
: Entity_Id
;
5412 Ctype
: Conformance_Type
;
5414 Conforms
: out Boolean;
5415 Err_Loc
: Node_Id
:= Empty
;
5416 Get_Inst
: Boolean := False;
5417 Skip_Controlling_Formals
: Boolean := False)
5419 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
5420 -- Sets Conforms to False. If Errmsg is False, then that's all it does.
5421 -- If Errmsg is True, then processing continues to post an error message
5422 -- for conformance error on given node. Two messages are output. The
5423 -- first message points to the previous declaration with a general "no
5424 -- conformance" message. The second is the detailed reason, supplied as
5425 -- Msg. The parameter N provide information for a possible & insertion
5426 -- in the message, and also provides the location for posting the
5427 -- message in the absence of a specified Err_Loc location.
5429 function Conventions_Match
(Id1
, Id2
: Entity_Id
) return Boolean;
5430 -- True if the conventions of entities Id1 and Id2 match.
5432 function Null_Exclusions_Match
(F1
, F2
: Entity_Id
) return Boolean;
5433 -- True if the null exclusions of two formals of anonymous access type
5436 function Subprogram_Subtypes_Have_Same_Declaration
5438 Decl_Subtype
: Entity_Id
;
5439 Body_Subtype
: Entity_Id
) return Boolean;
5440 -- Checks whether corresponding subtypes named within a subprogram
5441 -- declaration and body originate from the same declaration, and returns
5442 -- True when they do. In the case of anonymous access-to-object types,
5443 -- checks the designated types. Also returns True when GNAT_Mode is
5444 -- enabled, or when the subprogram is marked Is_Internal or occurs
5445 -- within a generic instantiation or internal unit (GNAT library unit).
5447 -----------------------
5448 -- Conformance_Error --
5449 -----------------------
5451 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
5458 if No
(Err_Loc
) then
5464 Error_Msg_Sloc
:= Sloc
(Old_Id
);
5467 when Type_Conformant
=>
5468 Error_Msg_N
-- CODEFIX
5469 ("not type conformant with declaration#!", Enode
);
5471 when Mode_Conformant
=>
5472 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
5474 ("not mode conformant with operation inherited#!",
5478 ("not mode conformant with declaration#!", Enode
);
5481 when Subtype_Conformant
=>
5482 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
5484 ("not subtype conformant with operation inherited#!",
5488 ("not subtype conformant with declaration#!", Enode
);
5491 when Fully_Conformant
=>
5492 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
5493 Error_Msg_N
-- CODEFIX
5494 ("not fully conformant with operation inherited#!",
5497 Error_Msg_N
-- CODEFIX
5498 ("not fully conformant with declaration#!", Enode
);
5502 Error_Msg_NE
(Msg
, Enode
, N
);
5504 end Conformance_Error
;
5506 -----------------------
5507 -- Conventions_Match --
5508 -----------------------
5510 function Conventions_Match
5512 Id2
: Entity_Id
) return Boolean
5515 -- Ignore the conventions of anonymous access-to-subprogram types
5516 -- and subprogram types because these are internally generated and
5517 -- the only way these may receive a convention is if they inherit
5518 -- the convention of a related subprogram.
5520 if Ekind
(Id1
) in E_Anonymous_Access_Subprogram_Type
5523 Ekind
(Id2
) in E_Anonymous_Access_Subprogram_Type
5528 -- Otherwise compare the conventions directly
5531 return Convention
(Id1
) = Convention
(Id2
);
5533 end Conventions_Match
;
5535 ---------------------------
5536 -- Null_Exclusions_Match --
5537 ---------------------------
5539 function Null_Exclusions_Match
(F1
, F2
: Entity_Id
) return Boolean is
5541 if not Is_Anonymous_Access_Type
(Etype
(F1
))
5542 or else not Is_Anonymous_Access_Type
(Etype
(F2
))
5547 -- AI12-0289-1: Case of controlling access parameter; False if the
5548 -- partial view is untagged, the full view is tagged, and no explicit
5549 -- "not null". Note that at this point, we're processing the package
5550 -- body, so private/full types have been swapped. The Sloc test below
5551 -- is to detect the (legal) case where F1 comes after the full type
5552 -- declaration. This part is disabled pre-2005, because "not null" is
5553 -- not allowed on those language versions.
5555 if Ada_Version
>= Ada_2005
5556 and then Is_Controlling_Formal
(F1
)
5557 and then not Null_Exclusion_Present
(Parent
(F1
))
5558 and then not Null_Exclusion_Present
(Parent
(F2
))
5561 D
: constant Entity_Id
:= Directly_Designated_Type
(Etype
(F1
));
5562 Partial_View_Of_Desig
: constant Entity_Id
:=
5563 Incomplete_Or_Partial_View
(D
);
5565 return No
(Partial_View_Of_Desig
)
5566 or else Is_Tagged_Type
(Partial_View_Of_Desig
)
5567 or else Sloc
(D
) < Sloc
(F1
);
5570 -- Not a controlling parameter, or one or both views have an explicit
5574 return Null_Exclusion_Present
(Parent
(F1
)) =
5575 Null_Exclusion_Present
(Parent
(F2
));
5577 end Null_Exclusions_Match
;
5579 function Subprogram_Subtypes_Have_Same_Declaration
5581 Decl_Subtype
: Entity_Id
;
5582 Body_Subtype
: Entity_Id
) return Boolean
5585 function Nonlimited_View_Of_Subtype
5586 (Subt
: Entity_Id
) return Entity_Id
;
5587 -- Returns the nonlimited view of a type or subtype that is an
5588 -- incomplete or class-wide type that comes from a limited view of
5589 -- a package (From_Limited_With is True for the entity), or the
5590 -- full view when the subtype is an incomplete type. Otherwise
5591 -- returns the entity passed in.
5593 function Nonlimited_View_Of_Subtype
5594 (Subt
: Entity_Id
) return Entity_Id
5596 Subt_Temp
: Entity_Id
:= Subt
;
5598 if Ekind
(Subt
) in Incomplete_Kind | E_Class_Wide_Type
5599 and then From_Limited_With
(Subt
)
5601 Subt_Temp
:= Non_Limited_View
(Subt
);
5604 -- If the subtype is incomplete, return full view if present
5605 -- (and accounts for the case where a type from a limited view
5606 -- is itself an incomplete type).
5608 if Ekind
(Subt_Temp
) in Incomplete_Kind
5609 and then Present
(Full_View
(Subt_Temp
))
5611 Subt_Temp
:= Full_View
(Subt_Temp
);
5615 end Nonlimited_View_Of_Subtype
;
5617 -- Start of processing for Subprogram_Subtypes_Have_Same_Declaration
5621 and then not In_Internal_Unit
(Subp
)
5622 and then not Is_Internal
(Subp
)
5623 and then not GNAT_Mode
5625 Ekind
(Etype
(Decl_Subtype
)) not in Access_Subprogram_Kind
5627 if Ekind
(Etype
(Decl_Subtype
)) = E_Anonymous_Access_Type
then
5628 if Nonlimited_View_Of_Subtype
(Designated_Type
(Decl_Subtype
))
5629 /= Nonlimited_View_Of_Subtype
(Designated_Type
(Body_Subtype
))
5634 elsif Nonlimited_View_Of_Subtype
(Decl_Subtype
)
5635 /= Nonlimited_View_Of_Subtype
(Body_Subtype
)
5637 -- Avoid returning False (and a false-positive warning) for
5638 -- the case of "not null" itypes, which will appear to be
5639 -- different subtypes even when the subtype_marks denote
5640 -- the same subtype.
5642 if Ekind
(Decl_Subtype
) = E_Access_Subtype
5643 and then Ekind
(Body_Subtype
) = E_Access_Subtype
5644 and then Is_Itype
(Body_Subtype
)
5645 and then Can_Never_Be_Null
(Body_Subtype
)
5646 and then Etype
(Decl_Subtype
) = Etype
(Body_Subtype
)
5657 end Subprogram_Subtypes_Have_Same_Declaration
;
5661 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
5662 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
5663 Old_Formal
: Entity_Id
;
5664 New_Formal
: Entity_Id
;
5665 Old_Formal_Base
: Entity_Id
;
5666 New_Formal_Base
: Entity_Id
;
5668 -- Start of processing for Check_Conformance
5673 -- We need a special case for operators, since they don't appear
5676 if Ctype
= Type_Conformant
then
5677 if Ekind
(New_Id
) = E_Operator
5678 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
5684 -- If both are functions/operators, check return types conform
5686 if Old_Type
/= Standard_Void_Type
5688 New_Type
/= Standard_Void_Type
5690 -- If we are checking interface conformance we omit controlling
5691 -- arguments and result, because we are only checking the conformance
5692 -- of the remaining parameters.
5694 if Has_Controlling_Result
(Old_Id
)
5695 and then Has_Controlling_Result
(New_Id
)
5696 and then Skip_Controlling_Formals
5700 elsif not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
5701 if Ctype
>= Subtype_Conformant
5702 and then not Predicates_Match
(Old_Type
, New_Type
)
5705 ("\predicate of return type does not match!", New_Id
);
5708 ("\return type does not match!", New_Id
);
5713 -- If the result subtypes conform and pedantic checks are enabled,
5714 -- check to see whether the subtypes originate from different
5715 -- declarations, and issue a warning when they do.
5717 elsif Ctype
= Fully_Conformant
5718 and then Warn_On_Pedantic_Checks
5719 and then not Subprogram_Subtypes_Have_Same_Declaration
5720 (Old_Id
, Old_Type
, New_Type
)
5722 Error_Msg_N
("result subtypes conform but come from different "
5723 & "declarations?_p?", New_Id
);
5726 -- Ada 2005 (AI-231): In case of anonymous access types check the
5727 -- null-exclusion and access-to-constant attributes match.
5729 if Ada_Version
>= Ada_2005
5730 and then Ekind
(Etype
(Old_Type
)) = E_Anonymous_Access_Type
5732 (Can_Never_Be_Null
(Old_Type
) /= Can_Never_Be_Null
(New_Type
)
5733 or else Is_Access_Constant
(Etype
(Old_Type
)) /=
5734 Is_Access_Constant
(Etype
(New_Type
)))
5736 Conformance_Error
("\return type does not match!", New_Id
);
5740 -- If either is a function/operator and the other isn't, error
5742 elsif Old_Type
/= Standard_Void_Type
5743 or else New_Type
/= Standard_Void_Type
5745 Conformance_Error
("\functions can only match functions!", New_Id
);
5749 -- In subtype conformant case, conventions must match (RM 6.3.1(16)).
5750 -- If this is a renaming as body, refine error message to indicate that
5751 -- the conflict is with the original declaration. If the entity is not
5752 -- frozen, the conventions don't have to match, the one of the renamed
5753 -- entity is inherited.
5755 if Ctype
>= Subtype_Conformant
then
5756 if not Conventions_Match
(Old_Id
, New_Id
) then
5757 if not Is_Frozen
(New_Id
) then
5760 elsif Present
(Err_Loc
)
5761 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
5762 and then Present
(Corresponding_Spec
(Err_Loc
))
5764 Error_Msg_Name_1
:= Chars
(New_Id
);
5766 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
5767 Conformance_Error
("\prior declaration for% has convention %!");
5771 Conformance_Error
("\calling conventions do not match!");
5775 Check_Formal_Subprogram_Conformance
5776 (New_Id
, Old_Id
, Err_Loc
, Errmsg
, Conforms
);
5778 if not Conforms
then
5784 -- Deal with parameters
5786 -- Note: we use the entity information, rather than going directly
5787 -- to the specification in the tree. This is not only simpler, but
5788 -- absolutely necessary for some cases of conformance tests between
5789 -- operators, where the declaration tree simply does not exist.
5791 Old_Formal
:= First_Formal
(Old_Id
);
5792 New_Formal
:= First_Formal
(New_Id
);
5793 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
5794 if Is_Controlling_Formal
(Old_Formal
)
5795 and then Is_Controlling_Formal
(New_Formal
)
5796 and then Skip_Controlling_Formals
5798 -- The controlling formals will have different types when
5799 -- comparing an interface operation with its match, but both
5800 -- or neither must be access parameters.
5802 if Is_Access_Type
(Etype
(Old_Formal
))
5804 Is_Access_Type
(Etype
(New_Formal
))
5806 goto Skip_Controlling_Formal
;
5809 ("\access parameter does not match!", New_Formal
);
5813 -- Ada 2012: Mode conformance also requires that formal parameters
5814 -- be both aliased, or neither.
5816 if Ctype
>= Mode_Conformant
and then Ada_Version
>= Ada_2012
then
5817 if Is_Aliased
(Old_Formal
) /= Is_Aliased
(New_Formal
) then
5819 ("\aliased parameter mismatch!", New_Formal
);
5823 if Ctype
= Fully_Conformant
then
5825 -- Names must match. Error message is more accurate if we do
5826 -- this before checking that the types of the formals match.
5828 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
5829 Conformance_Error
("\name& does not match!", New_Formal
);
5831 -- Set error posted flag on new formal as well to stop
5832 -- junk cascaded messages in some cases.
5834 Set_Error_Posted
(New_Formal
);
5838 -- Null exclusion must match
5840 if not Relaxed_RM_Semantics
5841 and then not Null_Exclusions_Match
(Old_Formal
, New_Formal
)
5844 ("\null exclusion for& does not match", New_Formal
);
5846 -- Mark error posted on the new formal to avoid duplicated
5847 -- complaint about types not matching.
5849 Set_Error_Posted
(New_Formal
);
5853 -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This
5854 -- case occurs whenever a subprogram is being renamed and one of its
5855 -- parameters imposes a null exclusion. For example:
5857 -- type T is null record;
5858 -- type Acc_T is access T;
5859 -- subtype Acc_T_Sub is Acc_T;
5861 -- procedure P (Obj : not null Acc_T_Sub); -- itype
5862 -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype
5865 Old_Formal_Base
:= Etype
(Old_Formal
);
5866 New_Formal_Base
:= Etype
(New_Formal
);
5869 Old_Formal_Base
:= Get_Instance_Of
(Old_Formal_Base
);
5870 New_Formal_Base
:= Get_Instance_Of
(New_Formal_Base
);
5873 -- Types must always match. In the visible part of an instance,
5874 -- usual overloading rules for dispatching operations apply, and
5875 -- we check base types (not the actual subtypes).
5877 if In_Instance_Visible_Part
5878 and then Is_Dispatching_Operation
(New_Id
)
5880 if not Conforming_Types
5881 (T1
=> Base_Type
(Etype
(Old_Formal
)),
5882 T2
=> Base_Type
(Etype
(New_Formal
)),
5884 Get_Inst
=> Get_Inst
)
5886 Conformance_Error
("\type of & does not match!", New_Formal
);
5890 elsif not Conforming_Types
5891 (T1
=> Old_Formal_Base
,
5892 T2
=> New_Formal_Base
,
5894 Get_Inst
=> Get_Inst
)
5896 -- Don't give error message if old type is Any_Type. This test
5897 -- avoids some cascaded errors, e.g. in case of a bad spec.
5899 if Errmsg
and then Old_Formal_Base
= Any_Type
then
5902 if Ctype
>= Subtype_Conformant
5904 not Predicates_Match
(Old_Formal_Base
, New_Formal_Base
)
5907 ("\predicate of & does not match!", New_Formal
);
5910 ("\type of & does not match!", New_Formal
);
5912 if not Dimensions_Match
(Old_Formal_Base
, New_Formal_Base
)
5914 Error_Msg_N
("\dimensions mismatch!", New_Formal
);
5921 -- If the formals' subtypes conform and pedantic checks are enabled,
5922 -- check to see whether the subtypes originate from different
5923 -- declarations, and issue a warning when they do.
5925 elsif Ctype
= Fully_Conformant
5926 and then Warn_On_Pedantic_Checks
5927 and then not Subprogram_Subtypes_Have_Same_Declaration
5928 (Old_Id
, Old_Formal_Base
, New_Formal_Base
)
5930 Error_Msg_N
("formal subtypes conform but come from "
5931 & "different declarations?_p?", New_Formal
);
5934 -- For mode conformance, mode must match
5936 if Ctype
>= Mode_Conformant
then
5937 if Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
) then
5938 if Ekind
(New_Id
) not in E_Function | E_Procedure
5939 or else not Is_Primitive_Wrapper
(New_Id
)
5941 Conformance_Error
("\mode of & does not match!", New_Formal
);
5945 T
: constant Entity_Id
:= Find_Dispatching_Type
(New_Id
);
5947 if Is_Protected_Type
(Corresponding_Concurrent_Type
(T
))
5952 Error_Msg_PT
(New_Id
, Ultimate_Alias
(Old_Id
));
5956 ("\mode of & does not match!", New_Formal
);
5963 elsif Is_Access_Type
(Old_Formal_Base
)
5964 and then Is_Access_Type
(New_Formal_Base
)
5965 and then Is_Access_Constant
(Old_Formal_Base
) /=
5966 Is_Access_Constant
(New_Formal_Base
)
5969 ("\constant modifier does not match!", New_Formal
);
5974 if Ctype
>= Subtype_Conformant
then
5976 -- Ada 2005 (AI-231): In case of anonymous access types check
5977 -- the null-exclusion and access-to-constant attributes must
5978 -- match. For null exclusion, we test the types rather than the
5979 -- formals themselves, since the attribute is only set reliably
5980 -- on the formals in the Ada 95 case, and we exclude the case
5981 -- where Old_Formal is marked as controlling, to avoid errors
5982 -- when matching completing bodies with dispatching declarations
5983 -- (access formals in the bodies aren't marked Can_Never_Be_Null).
5985 if Ada_Version
>= Ada_2005
5986 and then Is_Anonymous_Access_Type
(Etype
(Old_Formal
))
5987 and then Is_Anonymous_Access_Type
(Etype
(New_Formal
))
5989 ((Can_Never_Be_Null
(Etype
(Old_Formal
)) /=
5990 Can_Never_Be_Null
(Etype
(New_Formal
))
5992 not Is_Controlling_Formal
(Old_Formal
))
5994 Is_Access_Constant
(Etype
(Old_Formal
)) /=
5995 Is_Access_Constant
(Etype
(New_Formal
)))
5997 -- Do not complain if error already posted on New_Formal. This
5998 -- avoids some redundant error messages.
6000 and then not Error_Posted
(New_Formal
)
6002 -- It is allowed to omit the null-exclusion in case of stream
6003 -- attribute subprograms. We recognize stream subprograms
6004 -- through their TSS-generated suffix.
6007 TSS_Name
: constant TSS_Name_Type
:= Get_TSS_Name
(New_Id
);
6010 if TSS_Name
/= TSS_Stream_Read
6011 and then TSS_Name
/= TSS_Stream_Write
6012 and then TSS_Name
/= TSS_Stream_Input
6013 and then TSS_Name
/= TSS_Stream_Output
6015 -- Here we have a definite conformance error. It is worth
6016 -- special casing the error message for the case of a
6017 -- controlling formal (which excludes null).
6019 if Is_Controlling_Formal
(New_Formal
) then
6020 Error_Msg_Node_2
:= Scope
(New_Formal
);
6022 ("\controlling formal & of & excludes null, "
6023 & "declaration must exclude null as well",
6026 -- Normal case (couldn't we give more detail here???)
6030 ("\type of & does not match!", New_Formal
);
6039 -- Full conformance checks
6041 if Ctype
= Fully_Conformant
then
6043 -- We have checked already that names match
6045 if Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
6047 -- Check default expressions for in parameters
6050 NewD
: constant Boolean :=
6051 Present
(Default_Value
(New_Formal
));
6052 OldD
: constant Boolean :=
6053 Present
(Default_Value
(Old_Formal
));
6055 if NewD
or OldD
then
6057 -- The old default value has been analyzed because the
6058 -- current full declaration will have frozen everything
6059 -- before. The new default value has not been analyzed,
6060 -- so analyze it now before we check for conformance.
6063 Push_Scope
(New_Id
);
6064 Preanalyze_Spec_Expression
6065 (Default_Value
(New_Formal
), Etype
(New_Formal
));
6069 if not (NewD
and OldD
)
6070 or else not Fully_Conformant_Expressions
6071 (Default_Value
(Old_Formal
),
6072 Default_Value
(New_Formal
))
6075 ("\default expression for & does not match!",
6084 -- A couple of special checks for Ada 83 mode. These checks are
6085 -- skipped if either entity is an operator in package Standard,
6086 -- or if either old or new instance is not from the source program.
6088 if Ada_Version
= Ada_83
6089 and then Sloc
(Old_Id
) > Standard_Location
6090 and then Sloc
(New_Id
) > Standard_Location
6091 and then Comes_From_Source
(Old_Id
)
6092 and then Comes_From_Source
(New_Id
)
6095 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
6096 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
6099 -- Explicit IN must be present or absent in both cases. This
6100 -- test is required only in the full conformance case.
6102 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
6103 and then Ctype
= Fully_Conformant
6106 ("\(Ada 83) IN must appear in both declarations",
6111 -- Grouping (use of comma in param lists) must be the same
6112 -- This is where we catch a misconformance like:
6115 -- A : Integer; B : Integer
6117 -- which are represented identically in the tree except
6118 -- for the setting of the flags More_Ids and Prev_Ids.
6120 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
6121 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
6124 ("\grouping of & does not match!", New_Formal
);
6130 -- This label is required when skipping controlling formals
6132 <<Skip_Controlling_Formal
>>
6134 Next_Formal
(Old_Formal
);
6135 Next_Formal
(New_Formal
);
6138 if Present
(Old_Formal
) then
6139 Conformance_Error
("\too few parameters!");
6142 elsif Present
(New_Formal
) then
6143 Conformance_Error
("\too many parameters!", New_Formal
);
6146 end Check_Conformance
;
6148 -----------------------
6149 -- Check_Conventions --
6150 -----------------------
6152 procedure Check_Conventions
(Typ
: Entity_Id
) is
6153 Ifaces_List
: Elist_Id
;
6155 procedure Check_Convention
(Op
: Entity_Id
);
6156 -- Verify that the convention of inherited dispatching operation Op is
6157 -- consistent among all subprograms it overrides. In order to minimize
6158 -- the search, Search_From is utilized to designate a specific point in
6159 -- the list rather than iterating over the whole list once more.
6161 ----------------------
6162 -- Check_Convention --
6163 ----------------------
6165 procedure Check_Convention
(Op
: Entity_Id
) is
6166 Op_Conv
: constant Convention_Id
:= Convention
(Op
);
6167 Iface_Conv
: Convention_Id
;
6168 Iface_Elmt
: Elmt_Id
;
6169 Iface_Prim_Elmt
: Elmt_Id
;
6170 Iface_Prim
: Entity_Id
;
6173 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
6174 while Present
(Iface_Elmt
) loop
6176 First_Elmt
(Primitive_Operations
(Node
(Iface_Elmt
)));
6177 while Present
(Iface_Prim_Elmt
) loop
6178 Iface_Prim
:= Node
(Iface_Prim_Elmt
);
6179 Iface_Conv
:= Convention
(Iface_Prim
);
6181 if Is_Interface_Conformant
(Typ
, Iface_Prim
, Op
)
6182 and then Iface_Conv
/= Op_Conv
6185 ("inconsistent conventions in primitive operations", Typ
);
6187 Error_Msg_Name_1
:= Chars
(Op
);
6188 Error_Msg_Name_2
:= Get_Convention_Name
(Op_Conv
);
6189 Error_Msg_Sloc
:= Sloc
(Op
);
6191 if Comes_From_Source
(Op
) or else No
(Alias
(Op
)) then
6192 if No
(Overridden_Operation
(Op
)) then
6193 Error_Msg_N
("\\primitive % defined #", Typ
);
6196 ("\\overriding operation % with "
6197 & "convention % defined #", Typ
);
6200 else pragma Assert
(Present
(Alias
(Op
)));
6201 Error_Msg_Sloc
:= Sloc
(Alias
(Op
));
6202 Error_Msg_N
("\\inherited operation % with "
6203 & "convention % defined #", Typ
);
6206 Error_Msg_Name_1
:= Chars
(Op
);
6207 Error_Msg_Name_2
:= Get_Convention_Name
(Iface_Conv
);
6208 Error_Msg_Sloc
:= Sloc
(Iface_Prim
);
6209 Error_Msg_N
("\\overridden operation % with "
6210 & "convention % defined #", Typ
);
6212 -- Avoid cascading errors
6217 Next_Elmt
(Iface_Prim_Elmt
);
6220 Next_Elmt
(Iface_Elmt
);
6222 end Check_Convention
;
6226 Prim_Op
: Entity_Id
;
6227 Prim_Op_Elmt
: Elmt_Id
;
6229 -- Start of processing for Check_Conventions
6232 if not Has_Interfaces
(Typ
) then
6236 Collect_Interfaces
(Typ
, Ifaces_List
);
6238 -- The algorithm checks every overriding dispatching operation against
6239 -- all the corresponding overridden dispatching operations, detecting
6240 -- differences in conventions.
6242 Prim_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6243 while Present
(Prim_Op_Elmt
) loop
6244 Prim_Op
:= Node
(Prim_Op_Elmt
);
6246 -- A small optimization: skip the predefined dispatching operations
6247 -- since they always have the same convention.
6249 if not Is_Predefined_Dispatching_Operation
(Prim_Op
) then
6250 Check_Convention
(Prim_Op
);
6253 Next_Elmt
(Prim_Op_Elmt
);
6255 end Check_Conventions
;
6257 ------------------------------
6258 -- Check_Delayed_Subprogram --
6259 ------------------------------
6261 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
6262 procedure Possible_Freeze
(T
: Entity_Id
);
6263 -- T is the type of either a formal parameter or of the return type. If
6264 -- T is not yet frozen and needs a delayed freeze, then the subprogram
6265 -- itself must be delayed.
6267 ---------------------
6268 -- Possible_Freeze --
6269 ---------------------
6271 procedure Possible_Freeze
(T
: Entity_Id
) is
6272 Scop
: constant Entity_Id
:= Scope
(Designator
);
6275 -- If the subprogram appears within a package instance (which may be
6276 -- the wrapper package of a subprogram instance) the freeze node for
6277 -- that package will freeze the subprogram at the proper place, so
6278 -- do not emit a freeze node for the subprogram, given that it may
6279 -- appear in the wrong scope.
6281 if Ekind
(Scop
) = E_Package
6282 and then not Comes_From_Source
(Scop
)
6283 and then Is_Generic_Instance
(Scop
)
6287 elsif Has_Delayed_Freeze
(T
) and then not Is_Frozen
(T
) then
6288 Set_Has_Delayed_Freeze
(Designator
);
6290 elsif Is_Access_Type
(T
)
6291 and then Has_Delayed_Freeze
(Designated_Type
(T
))
6292 and then not Is_Frozen
(Designated_Type
(T
))
6294 Set_Has_Delayed_Freeze
(Designator
);
6296 end Possible_Freeze
;
6302 -- Start of processing for Check_Delayed_Subprogram
6305 -- All subprograms, including abstract subprograms, may need a freeze
6306 -- node if some formal type or the return type needs one.
6308 Possible_Freeze
(Etype
(Designator
));
6309 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
6311 -- Need delayed freeze if any of the formal types themselves need a
6312 -- delayed freeze and are not yet frozen.
6314 F
:= First_Formal
(Designator
);
6315 while Present
(F
) loop
6316 Possible_Freeze
(Etype
(F
));
6317 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
6321 -- Mark functions that return by reference. Note that it cannot be done
6322 -- for delayed_freeze subprograms because the underlying returned type
6323 -- may not be known yet (for private types).
6325 if not Has_Delayed_Freeze
(Designator
) and then Expander_Active
then
6326 Compute_Returns_By_Ref
(Designator
);
6328 end Check_Delayed_Subprogram
;
6330 ------------------------------------
6331 -- Check_Discriminant_Conformance --
6332 ------------------------------------
6334 procedure Check_Discriminant_Conformance
6339 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
6340 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
6341 New_Discr_Id
: Entity_Id
;
6342 New_Discr_Type
: Entity_Id
;
6344 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
6345 -- Post error message for conformance error on given node. Two messages
6346 -- are output. The first points to the previous declaration with a
6347 -- general "no conformance" message. The second is the detailed reason,
6348 -- supplied as Msg. The parameter N provide information for a possible
6349 -- & insertion in the message.
6351 -----------------------
6352 -- Conformance_Error --
6353 -----------------------
6355 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
6357 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
6358 Error_Msg_N
-- CODEFIX
6359 ("not fully conformant with declaration#!", N
);
6360 Error_Msg_NE
(Msg
, N
, N
);
6361 end Conformance_Error
;
6363 -- Start of processing for Check_Discriminant_Conformance
6366 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
6367 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
6369 -- The subtype mark of the discriminant on the full type has not
6370 -- been analyzed so we do it here. For an access discriminant a new
6373 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
6375 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
6378 Find_Type
(Discriminant_Type
(New_Discr
));
6379 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
6381 -- Ada 2005: if the discriminant definition carries a null
6382 -- exclusion, create an itype to check properly for consistency
6383 -- with partial declaration.
6385 if Is_Access_Type
(New_Discr_Type
)
6386 and then Null_Exclusion_Present
(New_Discr
)
6389 Create_Null_Excluding_Itype
6390 (T
=> New_Discr_Type
,
6391 Related_Nod
=> New_Discr
,
6392 Scope_Id
=> Current_Scope
);
6396 if not Conforming_Types
6397 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
6399 Conformance_Error
("type of & does not match!", New_Discr_Id
);
6402 -- Treat the new discriminant as an occurrence of the old one,
6403 -- for navigation purposes, and fill in some semantic
6404 -- information, for completeness.
6406 Generate_Reference
(Old_Discr
, New_Discr_Id
, 'r');
6407 Set_Etype
(New_Discr_Id
, Etype
(Old_Discr
));
6408 Set_Scope
(New_Discr_Id
, Scope
(Old_Discr
));
6413 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
6414 Conformance_Error
("name & does not match!", New_Discr_Id
);
6418 -- Default expressions must match
6421 NewD
: constant Boolean :=
6422 Present
(Expression
(New_Discr
));
6423 OldD
: constant Boolean :=
6424 Present
(Expression
(Parent
(Old_Discr
)));
6427 if NewD
or OldD
then
6429 -- The old default value has been analyzed and expanded,
6430 -- because the current full declaration will have frozen
6431 -- everything before. The new default values have not been
6432 -- expanded, so expand now to check conformance.
6435 Preanalyze_Spec_Expression
6436 (Expression
(New_Discr
), New_Discr_Type
);
6439 if not (NewD
and OldD
)
6440 or else not Fully_Conformant_Expressions
6441 (Expression
(Parent
(Old_Discr
)),
6442 Expression
(New_Discr
))
6446 ("default expression for & does not match!",
6453 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
6455 if Ada_Version
= Ada_83
then
6457 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
6460 -- Grouping (use of comma in param lists) must be the same
6461 -- This is where we catch a misconformance like:
6464 -- A : Integer; B : Integer
6466 -- which are represented identically in the tree except
6467 -- for the setting of the flags More_Ids and Prev_Ids.
6469 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
6470 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
6473 ("grouping of & does not match!", New_Discr_Id
);
6479 Next_Discriminant
(Old_Discr
);
6483 if Present
(Old_Discr
) then
6484 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
6487 elsif Present
(New_Discr
) then
6489 ("too many discriminants!", Defining_Identifier
(New_Discr
));
6492 end Check_Discriminant_Conformance
;
6494 -----------------------------------------
6495 -- Check_Formal_Subprogram_Conformance --
6496 -----------------------------------------
6498 procedure Check_Formal_Subprogram_Conformance
6499 (New_Id
: Entity_Id
;
6503 Conforms
: out Boolean)
6509 if Is_Formal_Subprogram
(Old_Id
)
6510 or else Is_Formal_Subprogram
(New_Id
)
6511 or else (Is_Subprogram
(New_Id
)
6512 and then Present
(Alias
(New_Id
))
6513 and then Is_Formal_Subprogram
(Alias
(New_Id
)))
6515 if Present
(Err_Loc
) then
6524 Error_Msg_Sloc
:= Sloc
(Old_Id
);
6525 Error_Msg_N
("not subtype conformant with declaration#!", N
);
6527 ("\formal subprograms are not subtype conformant "
6528 & "(RM 6.3.1 (17/3))", N
, New_Id
);
6531 end Check_Formal_Subprogram_Conformance
;
6533 procedure Check_Formal_Subprogram_Conformance
6534 (New_Id
: Entity_Id
;
6536 Err_Loc
: Node_Id
:= Empty
)
6540 Check_Formal_Subprogram_Conformance
6541 (New_Id
, Old_Id
, Err_Loc
, True, Ignore
);
6542 end Check_Formal_Subprogram_Conformance
;
6544 ----------------------------
6545 -- Check_Fully_Conformant --
6546 ----------------------------
6548 procedure Check_Fully_Conformant
6549 (New_Id
: Entity_Id
;
6551 Err_Loc
: Node_Id
:= Empty
)
6554 pragma Warnings
(Off
, Result
);
6557 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
6558 end Check_Fully_Conformant
;
6560 --------------------------
6561 -- Check_Limited_Return --
6562 --------------------------
6564 procedure Check_Limited_Return
6570 -- Ada 2005 (AI-318-02): Return-by-reference types have been removed and
6571 -- replaced by anonymous access results. This is an incompatibility with
6572 -- Ada 95. Not clear whether this should be enforced yet or perhaps
6573 -- controllable with special switch. ???
6575 -- A limited interface that is not immutably limited is OK
6577 if Is_Limited_Interface
(R_Type
)
6578 and then not Is_Concurrent_Interface
(R_Type
)
6582 elsif Is_Limited_Type
(R_Type
)
6583 and then not Is_Interface
(R_Type
)
6584 and then not (Nkind
(N
) = N_Simple_Return_Statement
6585 and then Comes_From_Extended_Return_Statement
(N
))
6586 and then not In_Instance_Body
6587 and then not OK_For_Limited_Init_In_05
(R_Type
, Expr
)
6589 -- Error in Ada 2005
6591 if Ada_Version
>= Ada_2005
6592 and then not Debug_Flag_Dot_L
6593 and then not GNAT_Mode
6596 ("(Ada 2005) cannot copy object of a limited type "
6597 & "(RM-2005 6.5(5.5/2))", Expr
);
6599 if Is_Limited_View
(R_Type
) then
6601 ("\return by reference not permitted in Ada 2005", Expr
);
6604 -- Warn in Ada 95 mode, to give folks a heads up about this
6607 -- In GNAT mode, this is just a warning, to allow it to be evilly
6608 -- turned off. Otherwise it is a real error.
6610 -- In a generic context, simplify the warning because it makes no
6611 -- sense to discuss pass-by-reference or copy.
6613 elsif Warn_On_Ada_2005_Compatibility
or GNAT_Mode
then
6614 if Inside_A_Generic
then
6616 ("return of limited object not permitted in Ada 2005 "
6617 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
6619 elsif Is_Limited_View
(R_Type
) then
6621 ("return by reference not permitted in Ada 2005 "
6622 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
6625 ("cannot copy object of a limited type in Ada 2005 "
6626 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
6629 -- Ada 95 mode, and compatibility warnings disabled
6632 pragma Assert
(Ada_Version
<= Ada_95
);
6633 pragma Assert
(not (Warn_On_Ada_2005_Compatibility
or GNAT_Mode
));
6634 return; -- skip continuation messages below
6637 if not Inside_A_Generic
then
6639 ("\consider switching to return of access type", Expr
);
6640 Explain_Limited_Type
(R_Type
, Expr
);
6643 end Check_Limited_Return
;
6645 ---------------------------
6646 -- Check_Mode_Conformant --
6647 ---------------------------
6649 procedure Check_Mode_Conformant
6650 (New_Id
: Entity_Id
;
6652 Err_Loc
: Node_Id
:= Empty
;
6653 Get_Inst
: Boolean := False)
6656 pragma Warnings
(Off
, Result
);
6659 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
6660 end Check_Mode_Conformant
;
6662 --------------------------------
6663 -- Check_Overriding_Indicator --
6664 --------------------------------
6666 procedure Check_Overriding_Indicator
6668 Overridden_Subp
: Entity_Id
;
6669 Is_Primitive
: Boolean)
6675 -- No overriding indicator for literals
6677 if Ekind
(Subp
) = E_Enumeration_Literal
then
6680 elsif Ekind
(Subp
) = E_Entry
then
6681 Decl
:= Parent
(Subp
);
6683 -- No point in analyzing a malformed operator
6685 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
6686 and then Error_Posted
(Subp
)
6691 Decl
:= Unit_Declaration_Node
(Subp
);
6694 if Nkind
(Decl
) in N_Subprogram_Body
6695 | N_Subprogram_Body_Stub
6696 | N_Subprogram_Declaration
6697 | N_Abstract_Subprogram_Declaration
6698 | N_Subprogram_Renaming_Declaration
6700 Spec
:= Specification
(Decl
);
6702 elsif Nkind
(Decl
) = N_Entry_Declaration
then
6709 -- An overriding indication is illegal on a subprogram declared
6710 -- in a protected body, where there is no operation to override.
6712 if (Must_Override
(Spec
) or else Must_Not_Override
(Spec
))
6713 and then Is_List_Member
(Decl
)
6714 and then Present
(Parent
(List_Containing
(Decl
)))
6715 and then Nkind
(Parent
(List_Containing
(Decl
))) = N_Protected_Body
6718 ("illegal overriding indication in protected body", Decl
);
6722 -- The overriding operation is type conformant with the overridden one,
6723 -- but the names of the formals are not required to match. If the names
6724 -- appear permuted in the overriding operation, this is a possible
6725 -- source of confusion that is worth diagnosing. Controlling formals
6726 -- often carry names that reflect the type, and it is not worthwhile
6727 -- requiring that their names match.
6729 if Present
(Overridden_Subp
)
6730 and then Nkind
(Subp
) /= N_Defining_Operator_Symbol
6737 Form1
:= First_Formal
(Subp
);
6738 Form2
:= First_Formal
(Overridden_Subp
);
6740 -- If the overriding operation is a synchronized operation, skip
6741 -- the first parameter of the overridden operation, which is
6742 -- implicit in the new one. If the operation is declared in the
6743 -- body it is not primitive and all formals must match.
6745 if Is_Concurrent_Type
(Scope
(Subp
))
6746 and then Is_Tagged_Type
(Scope
(Subp
))
6747 and then not Has_Completion
(Scope
(Subp
))
6749 Form2
:= Next_Formal
(Form2
);
6752 if Present
(Form1
) then
6753 Form1
:= Next_Formal
(Form1
);
6754 Form2
:= Next_Formal
(Form2
);
6757 while Present
(Form1
) loop
6758 if not Is_Controlling_Formal
(Form1
)
6759 and then Present
(Next_Formal
(Form2
))
6760 and then Chars
(Form1
) = Chars
(Next_Formal
(Form2
))
6762 Error_Msg_Node_2
:= Alias
(Overridden_Subp
);
6763 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
6765 ("& does not match corresponding formal of&#",
6770 Next_Formal
(Form1
);
6771 Next_Formal
(Form2
);
6776 -- If there is an overridden subprogram, then check that there is no
6777 -- "not overriding" indicator, and mark the subprogram as overriding.
6779 -- This is not done if the overridden subprogram is marked as hidden,
6780 -- which can occur for the case of inherited controlled operations
6781 -- (see Derive_Subprogram), unless the inherited subprogram's parent
6782 -- subprogram is not itself hidden or we are within a generic instance,
6783 -- in which case the hidden flag may have been modified for the
6784 -- expansion of the instance.
6786 -- (Note: This condition could probably be simplified, leaving out the
6787 -- testing for the specific controlled cases, but it seems safer and
6788 -- clearer this way, and echoes similar special-case tests of this
6789 -- kind in other places.)
6791 if Present
(Overridden_Subp
)
6792 and then (not Is_Hidden
(Overridden_Subp
)
6794 (Chars
(Overridden_Subp
) in Name_Initialize
6797 and then Present
(Alias
(Overridden_Subp
))
6798 and then (not Is_Hidden
(Alias
(Overridden_Subp
))
6799 or else In_Instance
)))
6801 if Must_Not_Override
(Spec
) then
6802 Error_Msg_Sloc
:= Sloc
(Overridden_Subp
);
6804 if Ekind
(Subp
) = E_Entry
then
6806 ("entry & overrides inherited operation #", Spec
, Subp
);
6809 ("subprogram & overrides inherited operation #", Spec
, Subp
);
6812 -- Special-case to fix a GNAT oddity: Limited_Controlled is declared
6813 -- as an extension of Root_Controlled, and thus has a useless Adjust
6814 -- operation. This operation should not be inherited by other limited
6815 -- controlled types. An explicit Adjust for them is not overriding.
6817 elsif Must_Override
(Spec
)
6818 and then Chars
(Overridden_Subp
) = Name_Adjust
6819 and then Is_Limited_Type
(Etype
(First_Formal
(Subp
)))
6820 and then Present
(Alias
(Overridden_Subp
))
6821 and then In_Predefined_Unit
(Alias
(Overridden_Subp
))
6824 (Unit_File_Name
(Get_Source_Unit
(Alias
(Overridden_Subp
))));
6825 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6827 elsif Is_Subprogram
(Subp
) then
6828 if Is_Init_Proc
(Subp
) then
6831 elsif No
(Overridden_Operation
(Subp
)) then
6833 -- For entities generated by Derive_Subprograms the overridden
6834 -- operation is the inherited primitive (which is available
6835 -- through the attribute alias)
6837 if (Is_Dispatching_Operation
(Subp
)
6838 or else Is_Dispatching_Operation
(Overridden_Subp
))
6839 and then not Comes_From_Source
(Overridden_Subp
)
6840 and then Find_Dispatching_Type
(Overridden_Subp
) =
6841 Find_Dispatching_Type
(Subp
)
6842 and then Present
(Alias
(Overridden_Subp
))
6843 and then Comes_From_Source
(Alias
(Overridden_Subp
))
6845 Set_Overridden_Operation
(Subp
, Alias
(Overridden_Subp
));
6846 Inherit_Subprogram_Contract
(Subp
, Alias
(Overridden_Subp
));
6847 Set_Is_Ada_2022_Only
(Subp
,
6848 Is_Ada_2022_Only
(Alias
(Overridden_Subp
)));
6851 Set_Overridden_Operation
(Subp
, Overridden_Subp
);
6852 Inherit_Subprogram_Contract
(Subp
, Overridden_Subp
);
6853 Set_Is_Ada_2022_Only
(Subp
,
6854 Is_Ada_2022_Only
(Overridden_Subp
));
6859 -- If primitive flag is set or this is a protected operation, then
6860 -- the operation is overriding at the point of its declaration, so
6861 -- warn if necessary. Otherwise it may have been declared before the
6862 -- operation it overrides and no check is required.
6865 and then not Must_Override
(Spec
)
6866 and then (Is_Primitive
6867 or else Ekind
(Scope
(Subp
)) = E_Protected_Type
)
6869 Style
.Missing_Overriding
(Decl
, Subp
);
6872 -- If Subp is an operator, it may override a predefined operation, if
6873 -- it is defined in the same scope as the type to which it applies.
6874 -- In that case Overridden_Subp is empty because of our implicit
6875 -- representation for predefined operators. We have to check whether the
6876 -- signature of Subp matches that of a predefined operator. Note that
6877 -- first argument provides the name of the operator, and the second
6878 -- argument the signature that may match that of a standard operation.
6879 -- If the indicator is overriding, then the operator must match a
6880 -- predefined signature, because we know already that there is no
6881 -- explicit overridden operation.
6883 elsif Chars
(Subp
) in Any_Operator_Name
then
6884 if Must_Not_Override
(Spec
) then
6886 -- If this is not a primitive or a protected subprogram, then
6887 -- "not overriding" is illegal.
6890 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
6892 Error_Msg_N
("overriding indicator only allowed "
6893 & "if subprogram is primitive", Subp
);
6895 elsif Can_Override_Operator
(Subp
) then
6897 ("subprogram& overrides predefined operator", Spec
, Subp
);
6900 elsif Must_Override
(Spec
) then
6901 if No
(Overridden_Operation
(Subp
))
6902 and then not Can_Override_Operator
(Subp
)
6904 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6907 elsif not Error_Posted
(Subp
)
6908 and then Style_Check
6909 and then Can_Override_Operator
(Subp
)
6910 and then not In_Predefined_Unit
(Subp
)
6912 -- If style checks are enabled, indicate that the indicator is
6913 -- missing. However, at the point of declaration, the type of
6914 -- which this is a primitive operation may be private, in which
6915 -- case the indicator would be premature.
6917 if Has_Private_Declaration
(Etype
(Subp
))
6918 or else Has_Private_Declaration
(Etype
(First_Formal
(Subp
)))
6922 Style
.Missing_Overriding
(Decl
, Subp
);
6926 elsif Must_Override
(Spec
) then
6927 if Ekind
(Subp
) = E_Entry
then
6928 Error_Msg_NE
("entry & is not overriding", Spec
, Subp
);
6930 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6933 -- If the operation is marked "not overriding" and it's not primitive
6934 -- then an error is issued, unless this is an operation of a task or
6935 -- protected type (RM05-8.3.1(3/2-4/2)). Error cases where "overriding"
6936 -- has been specified have already been checked above.
6938 elsif Must_Not_Override
(Spec
)
6939 and then not Is_Primitive
6940 and then Ekind
(Subp
) /= E_Entry
6941 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
6944 ("overriding indicator only allowed if subprogram is primitive",
6948 end Check_Overriding_Indicator
;
6954 -- Note: this procedure needs to know far too much about how the expander
6955 -- messes with exceptions. The use of the flag Exception_Junk and the
6956 -- incorporation of knowledge of Exp_Ch11.Expand_Local_Exception_Handlers
6957 -- works, but is not very clean. It would be better if the expansion
6958 -- routines would leave Original_Node working nicely, and we could use
6959 -- Original_Node here to ignore all the peculiar expander messing ???
6961 procedure Check_Returns
6965 Proc
: Entity_Id
:= Empty
)
6967 pragma Assert
(Mode
in 'F' |
'P');
6968 pragma Assert
(if Mode
= 'F' then No
(Proc
));
6971 procedure Check_Statement_Sequence
(L
: List_Id
);
6972 -- Internal recursive procedure to check a list of statements for proper
6973 -- termination by a return statement (or a transfer of control or a
6974 -- compound statement that is itself internally properly terminated).
6976 ------------------------------
6977 -- Check_Statement_Sequence --
6978 ------------------------------
6980 procedure Check_Statement_Sequence
(L
: List_Id
) is
6985 function Assert_False
return Boolean;
6986 -- Returns True if Last_Stm is a pragma Assert (False) that has been
6987 -- rewritten as a null statement when assertions are off. The assert
6988 -- is not active, but it is still enough to kill the warning.
6994 function Assert_False
return Boolean is
6995 Orig
: constant Node_Id
:= Original_Node
(Last_Stm
);
6998 if Nkind
(Orig
) = N_Pragma
6999 and then Pragma_Name
(Orig
) = Name_Assert
7000 and then not Error_Posted
(Orig
)
7003 Arg
: constant Node_Id
:=
7004 First
(Pragma_Argument_Associations
(Orig
));
7005 Exp
: constant Node_Id
:= Expression
(Arg
);
7007 return Nkind
(Exp
) = N_Identifier
7008 and then Chars
(Exp
) = Name_False
;
7018 Raise_Exception_Call
: Boolean := False;
7019 -- Set True if statement sequence terminated by Raise_Exception call
7020 -- or a Reraise_Occurrence call.
7022 -- Start of processing for Check_Statement_Sequence
7025 -- Get last real statement
7027 Last_Stm
:= Last
(L
);
7029 -- Deal with digging out exception handler statement sequences that
7030 -- have been transformed by the local raise to goto optimization.
7031 -- See Exp_Ch11.Expand_Local_Exception_Handlers for details. If this
7032 -- optimization has occurred, we are looking at something like:
7035 -- original stmts in block
7039 -- goto L1; | omitted if No_Exception_Propagation
7044 -- goto L3; -- skip handler when exception not raised
7046 -- <<L1>> -- target label for local exception
7060 -- and what we have to do is to dig out the estmts1 and estmts2
7061 -- sequences (which were the original sequences of statements in
7062 -- the exception handlers) and check them.
7064 if Nkind
(Last_Stm
) = N_Label
and then Exception_Junk
(Last_Stm
) then
7069 exit when Nkind
(Stm
) /= N_Block_Statement
;
7070 exit when not Exception_Junk
(Stm
);
7073 exit when Nkind
(Stm
) /= N_Label
;
7074 exit when not Exception_Junk
(Stm
);
7075 Check_Statement_Sequence
7076 (Statements
(Handled_Statement_Sequence
(Next
(Stm
))));
7081 exit when Nkind
(Stm
) /= N_Goto_Statement
;
7082 exit when not Exception_Junk
(Stm
);
7086 -- Don't count pragmas
7088 while Nkind
(Last_Stm
) = N_Pragma
7090 -- Don't count call to SS_Release (can happen after
7091 -- Raise_Exception).
7094 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
7096 Nkind
(Name
(Last_Stm
)) = N_Identifier
7098 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
7100 -- Don't count exception junk
7103 (Nkind
(Last_Stm
) in
7104 N_Goto_Statement | N_Label | N_Object_Declaration
7105 and then Exception_Junk
(Last_Stm
))
7106 or else Nkind
(Last_Stm
) in N_Push_xxx_Label | N_Pop_xxx_Label
7108 -- Inserted code, such as finalization calls, is irrelevant; we
7109 -- only need to check original source. If we see a transfer of
7110 -- control, we stop.
7112 or else (Is_Rewrite_Insertion
(Last_Stm
)
7113 and then not Is_Transfer
(Last_Stm
))
7118 -- Here we have the "real" last statement
7120 Kind
:= Nkind
(Last_Stm
);
7122 -- Transfer of control, OK. Note that in the No_Return procedure
7123 -- case, we already diagnosed any explicit return statements, so
7124 -- we can treat them as OK in this context.
7126 if Is_Transfer
(Last_Stm
) then
7129 -- Check cases of explicit non-indirect procedure calls
7131 elsif Kind
= N_Procedure_Call_Statement
7132 and then Is_Entity_Name
(Name
(Last_Stm
))
7134 -- Check call to Raise_Exception procedure which is treated
7135 -- specially, as is a call to Reraise_Occurrence.
7137 -- We suppress the warning in these cases since it is likely that
7138 -- the programmer really does not expect to deal with the case
7139 -- of Null_Occurrence, and thus would find a warning about a
7140 -- missing return curious, and raising Program_Error does not
7141 -- seem such a bad behavior if this does occur.
7143 -- Note that in the Ada 2005 case for Raise_Exception, the actual
7144 -- behavior will be to raise Constraint_Error (see AI-329).
7146 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
7148 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
7150 Raise_Exception_Call
:= True;
7152 -- For Raise_Exception call, test first argument, if it is
7153 -- an attribute reference for a 'Identity call, then we know
7154 -- that the call cannot possibly return.
7157 Arg
: constant Node_Id
:=
7158 Original_Node
(First_Actual
(Last_Stm
));
7160 if Nkind
(Arg
) = N_Attribute_Reference
7161 and then Attribute_Name
(Arg
) = Name_Identity
7168 -- If statement, need to look inside if there is an else and check
7169 -- each constituent statement sequence for proper termination.
7171 elsif Kind
= N_If_Statement
7172 and then Present
(Else_Statements
(Last_Stm
))
7174 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
7175 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
7178 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
7181 while Present
(Elsif_Part
) loop
7182 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
7189 -- Case statement, check each case for proper termination
7191 elsif Kind
= N_Case_Statement
then
7195 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
7196 while Present
(Case_Alt
) loop
7197 Check_Statement_Sequence
(Statements
(Case_Alt
));
7198 Next_Non_Pragma
(Case_Alt
);
7204 -- Block statement, check its handled sequence of statements
7206 elsif Kind
= N_Block_Statement
then
7212 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
7221 -- Loop statement. If there is an iteration scheme, we can definitely
7222 -- fall out of the loop. Similarly if there is an exit statement, we
7223 -- can fall out. In either case we need a following return.
7225 elsif Kind
= N_Loop_Statement
then
7226 if Present
(Iteration_Scheme
(Last_Stm
))
7227 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
7231 -- A loop with no exit statement or iteration scheme is either
7232 -- an infinite loop, or it has some other exit (raise/return).
7233 -- In either case, no warning is required.
7239 -- Timed entry call, check entry call and delay alternatives
7241 -- Note: in expanded code, the timed entry call has been converted
7242 -- to a set of expanded statements on which the check will work
7243 -- correctly in any case.
7245 elsif Kind
= N_Timed_Entry_Call
then
7247 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
7248 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
7251 -- If statement sequence of entry call alternative is missing,
7252 -- then we can definitely fall through, and we post the error
7253 -- message on the entry call alternative itself.
7255 if No
(Statements
(ECA
)) then
7258 -- If statement sequence of delay alternative is missing, then
7259 -- we can definitely fall through, and we post the error
7260 -- message on the delay alternative itself.
7262 -- Note: if both ECA and DCA are missing the return, then we
7263 -- post only one message, should be enough to fix the bugs.
7264 -- If not we will get a message next time on the DCA when the
7267 elsif No
(Statements
(DCA
)) then
7270 -- Else check both statement sequences
7273 Check_Statement_Sequence
(Statements
(ECA
));
7274 Check_Statement_Sequence
(Statements
(DCA
));
7279 -- Conditional entry call, check entry call and else part
7281 -- Note: in expanded code, the conditional entry call has been
7282 -- converted to a set of expanded statements on which the check
7283 -- will work correctly in any case.
7285 elsif Kind
= N_Conditional_Entry_Call
then
7287 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
7290 -- If statement sequence of entry call alternative is missing,
7291 -- then we can definitely fall through, and we post the error
7292 -- message on the entry call alternative itself.
7294 if No
(Statements
(ECA
)) then
7297 -- Else check statement sequence and else part
7300 Check_Statement_Sequence
(Statements
(ECA
));
7301 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
7307 -- If we fall through, issue appropriate message
7311 -- Kill warning if last statement is a raise exception call,
7312 -- or a pragma Assert (False). Note that with assertions enabled,
7313 -- such a pragma has been converted into a raise exception call
7314 -- already, so the Assert_False is for the assertions off case.
7316 if not Raise_Exception_Call
and then not Assert_False
then
7318 -- In GNATprove mode, it is an error to have a missing return
7320 Error_Msg_Warn
:= SPARK_Mode
/= On
;
7322 -- Issue error message or warning
7325 ("RETURN statement missing following this statement<<!",
7328 ("\Program_Error [<<!", Last_Stm
);
7331 -- Note: we set Err even though we have not issued a warning
7332 -- because we still have a case of a missing return. This is
7333 -- an extremely marginal case, probably will never be noticed
7334 -- but we might as well get it right.
7338 -- Otherwise we have the case of a procedure marked No_Return
7341 if not Raise_Exception_Call
then
7342 if GNATprove_Mode
then
7344 ("implied return after this statement would have raised "
7345 & "Program_Error", Last_Stm
);
7347 -- In normal compilation mode, do not warn on a generated call
7348 -- (e.g. in the body of a renaming as completion).
7350 elsif Comes_From_Source
(Last_Stm
) then
7352 ("implied return after this statement will raise "
7353 & "Program_Error??", Last_Stm
);
7356 Error_Msg_Warn
:= SPARK_Mode
/= On
;
7358 ("\procedure & is marked as No_Return<<!", Last_Stm
, Proc
);
7362 RE
: constant Node_Id
:=
7363 Make_Raise_Program_Error
(Sloc
(Last_Stm
),
7364 Reason
=> PE_Implicit_Return
);
7366 Insert_After
(Last_Stm
, RE
);
7370 end Check_Statement_Sequence
;
7372 -- Start of processing for Check_Returns
7376 Check_Statement_Sequence
(Statements
(HSS
));
7378 if Present
(Exception_Handlers
(HSS
)) then
7379 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
7380 while Present
(Handler
) loop
7381 Check_Statement_Sequence
(Statements
(Handler
));
7382 Next_Non_Pragma
(Handler
);
7387 ----------------------------
7388 -- Check_Subprogram_Order --
7389 ----------------------------
7391 procedure Check_Subprogram_Order
(N
: Node_Id
) is
7393 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
7394 -- This is used to check if S1 > S2 in the sense required by this test,
7395 -- for example nameab < namec, but name2 < name10.
7397 -----------------------------
7398 -- Subprogram_Name_Greater --
7399 -----------------------------
7401 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
7406 -- Deal with special case where names are identical except for a
7407 -- numerical suffix. These are handled specially, taking the numeric
7408 -- ordering from the suffix into account.
7411 while S1
(L1
) in '0' .. '9' loop
7416 while S2
(L2
) in '0' .. '9' loop
7420 -- If non-numeric parts non-equal, do straight compare
7422 if S1
(S1
'First .. L1
) /= S2
(S2
'First .. L2
) then
7425 -- If non-numeric parts equal, compare suffixed numeric parts. Note
7426 -- that a missing suffix is treated as numeric zero in this test.
7430 while L1
< S1
'Last loop
7432 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
7436 while L2
< S2
'Last loop
7438 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
7443 end Subprogram_Name_Greater
;
7445 -- Start of processing for Check_Subprogram_Order
7448 -- Check body in alpha order if this is option
7451 and then Style_Check_Order_Subprograms
7452 and then Nkind
(N
) = N_Subprogram_Body
7453 and then Comes_From_Source
(N
)
7454 and then In_Extended_Main_Source_Unit
(N
)
7458 renames Scope_Stack
.Table
7459 (Scope_Stack
.Last
).Last_Subprogram_Name
;
7461 Body_Id
: constant Entity_Id
:=
7462 Defining_Entity
(Specification
(N
));
7465 Get_Decoded_Name_String
(Chars
(Body_Id
));
7468 if Subprogram_Name_Greater
7469 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
7471 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
7477 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
7480 end Check_Subprogram_Order;
7482 ------------------------------
7483 -- Check_Subtype_Conformant --
7484 ------------------------------
7486 procedure Check_Subtype_Conformant
7487 (New_Id : Entity_Id;
7489 Err_Loc : Node_Id := Empty;
7490 Skip_Controlling_Formals : Boolean := False;
7491 Get_Inst : Boolean := False)
7494 pragma Warnings (Off, Result);
7497 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc,
7498 Skip_Controlling_Formals => Skip_Controlling_Formals,
7499 Get_Inst => Get_Inst);
7500 end Check_Subtype_Conformant;
7502 -----------------------------------
7503 -- Check_Synchronized_Overriding --
7504 -----------------------------------
7506 procedure Check_Synchronized_Overriding
7507 (Def_Id : Entity_Id;
7508 Overridden_Subp : out Entity_Id)
7510 Ifaces_List : Elist_Id;
7514 function Is_Valid_Formal (F : Entity_Id) return Boolean;
7515 -- Predicate for legality rule in 9.4 (11.9/2): If an inherited
7516 -- subprogram is implemented by a protected procedure or entry,
7517 -- its first parameter must be out, in out, or access-to-variable.
7519 function Matches_Prefixed_View_Profile
7520 (Prim_Params : List_Id;
7521 Iface_Params : List_Id) return Boolean;
7522 -- Determine whether a subprogram's parameter profile Prim_Params
7523 -- matches that of a potentially overridden interface subprogram
7524 -- Iface_Params. Also determine if the type of first parameter of
7525 -- Iface_Params is an implemented interface.
7527 ----------------------
7528 -- Is_Valid_Formal --
7529 ----------------------
7531 function Is_Valid_Formal (F : Entity_Id) return Boolean is
7534 Ekind (F) in E_In_Out_Parameter | E_Out_Parameter
7536 (Nkind (Parameter_Type (Parent (F))) = N_Access_Definition
7537 and then not Constant_Present (Parameter_Type (Parent (F))));
7538 end Is_Valid_Formal;
7540 -----------------------------------
7541 -- Matches_Prefixed_View_Profile --
7542 -----------------------------------
7544 function Matches_Prefixed_View_Profile
7545 (Prim_Params : List_Id;
7546 Iface_Params : List_Id) return Boolean
7548 function Is_Implemented
7549 (Ifaces_List : Elist_Id;
7550 Iface : Entity_Id) return Boolean;
7551 -- Determine if Iface is implemented by the current task or
7554 --------------------
7555 -- Is_Implemented --
7556 --------------------
7558 function Is_Implemented
7559 (Ifaces_List : Elist_Id;
7560 Iface : Entity_Id) return Boolean
7562 Iface_Elmt : Elmt_Id;
7565 Iface_Elmt := First_Elmt (Ifaces_List);
7566 while Present (Iface_Elmt) loop
7567 if Node (Iface_Elmt) = Iface then
7571 Next_Elmt (Iface_Elmt);
7579 Iface_Id : Entity_Id;
7580 Iface_Param : Node_Id;
7581 Iface_Typ : Entity_Id;
7582 Prim_Id : Entity_Id;
7583 Prim_Param : Node_Id;
7584 Prim_Typ : Entity_Id;
7586 -- Start of processing for Matches_Prefixed_View_Profile
7589 Iface_Param := First (Iface_Params);
7590 Iface_Typ := Etype (Defining_Identifier (Iface_Param));
7592 if Is_Access_Type (Iface_Typ) then
7593 Iface_Typ := Designated_Type (Iface_Typ);
7596 Prim_Param := First (Prim_Params);
7598 -- The first parameter of the potentially overridden subprogram must
7599 -- be an interface implemented by Prim.
7601 if not Is_Interface (Iface_Typ)
7602 or else not Is_Implemented (Ifaces_List, Iface_Typ)
7607 -- The checks on the object parameters are done, so move on to the
7608 -- rest of the parameters.
7610 if not In_Scope then
7615 while Present (Iface_Param) and then Present (Prim_Param) loop
7616 Iface_Id := Defining_Identifier (Iface_Param);
7617 Iface_Typ := Find_Parameter_Type (Iface_Param);
7619 Prim_Id := Defining_Identifier (Prim_Param);
7620 Prim_Typ := Find_Parameter_Type (Prim_Param);
7622 if Ekind (Iface_Typ) = E_Anonymous_Access_Type
7623 and then Ekind (Prim_Typ) = E_Anonymous_Access_Type
7624 and then Is_Concurrent_Type (Designated_Type (Prim_Typ))
7626 Iface_Typ := Designated_Type (Iface_Typ);
7627 Prim_Typ := Designated_Type (Prim_Typ);
7630 -- Case of multiple interface types inside a parameter profile
7632 -- (Obj_Param : in out Iface; ...; Param : Iface)
7634 -- If the interface type is implemented, then the matching type in
7635 -- the primitive should be the implementing record type.
7637 if Ekind (Iface_Typ) = E_Record_Type
7638 and then Is_Interface (Iface_Typ)
7639 and then Is_Implemented (Ifaces_List, Iface_Typ)
7641 if Prim_Typ /= Typ then
7645 -- The two parameters must be both mode and subtype conformant
7647 elsif Ekind (Iface_Id) /= Ekind (Prim_Id)
7649 Conforming_Types (Iface_Typ, Prim_Typ, Subtype_Conformant)
7658 -- One of the two lists contains more parameters than the other
7660 if Present (Iface_Param) or else Present (Prim_Param) then
7665 end Matches_Prefixed_View_Profile;
7667 -- Start of processing for Check_Synchronized_Overriding
7670 Overridden_Subp := Empty;
7672 -- Def_Id must be an entry or a subprogram. We should skip predefined
7673 -- primitives internally generated by the front end; however at this
7674 -- stage predefined primitives are still not fully decorated. As a
7675 -- minor optimization we skip here internally generated subprograms.
7677 if (Ekind (Def_Id) /= E_Entry
7678 and then Ekind (Def_Id) /= E_Function
7679 and then Ekind (Def_Id) /= E_Procedure)
7680 or else not Comes_From_Source (Def_Id)
7685 -- Search for the concurrent declaration since it contains the list of
7686 -- all implemented interfaces. In this case, the subprogram is declared
7687 -- within the scope of a protected or a task type.
7689 if Present (Scope (Def_Id))
7690 and then Is_Concurrent_Type (Scope (Def_Id))
7691 and then not Is_Generic_Actual_Type (Scope (Def_Id))
7693 Typ := Scope (Def_Id);
7696 -- The enclosing scope is not a synchronized type and the subprogram
7699 elsif No (First_Formal (Def_Id)) then
7702 -- The subprogram has formals and hence it may be a primitive of a
7706 Typ := Etype (First_Formal (Def_Id));
7708 if Is_Access_Type (Typ) then
7709 Typ := Directly_Designated_Type (Typ);
7712 if Is_Concurrent_Type (Typ)
7713 and then not Is_Generic_Actual_Type (Typ)
7717 -- This case occurs when the concurrent type is declared within a
7718 -- generic unit. As a result the corresponding record has been built
7719 -- and used as the type of the first formal, we just have to retrieve
7720 -- the corresponding concurrent type.
7722 elsif Is_Concurrent_Record_Type (Typ)
7723 and then not Is_Class_Wide_Type (Typ)
7724 and then Present (Corresponding_Concurrent_Type (Typ))
7726 Typ := Corresponding_Concurrent_Type (Typ);
7734 -- There is no overriding to check if this is an inherited operation in
7735 -- a type derivation for a generic actual.
7737 Collect_Interfaces (Typ, Ifaces_List);
7739 if Is_Empty_Elmt_List (Ifaces_List) then
7743 -- Determine whether entry or subprogram Def_Id overrides a primitive
7744 -- operation that belongs to one of the interfaces in Ifaces_List.
7747 Candidate : Entity_Id := Empty;
7748 Hom : Entity_Id := Empty;
7749 Subp : Entity_Id := Empty;
7752 -- Traverse the homonym chain, looking for a potentially overridden
7753 -- subprogram that belongs to an implemented interface.
7755 Hom := Current_Entity_In_Scope (Def_Id);
7756 while Present (Hom) loop
7760 or else not Is_Overloadable (Subp)
7761 or else not Is_Primitive (Subp)
7762 or else not Is_Dispatching_Operation (Subp)
7763 or else No (Find_Dispatching_Type (Subp))
7764 or else not Is_Interface (Find_Dispatching_Type (Subp))
7768 -- Entries and procedures can override abstract or null interface
7771 elsif Ekind (Def_Id) in E_Entry | E_Procedure
7772 and then Ekind (Subp) = E_Procedure
7773 and then Matches_Prefixed_View_Profile
7774 (Parameter_Specifications (Parent (Def_Id)),
7775 Parameter_Specifications (Parent (Subp)))
7779 -- For an overridden subprogram Subp, check whether the mode
7780 -- of its first parameter is correct depending on the kind of
7781 -- synchronized type.
7784 Formal : constant Node_Id := First_Formal (Candidate);
7787 -- In order for an entry or a protected procedure to
7788 -- override, the first parameter of the overridden routine
7789 -- must be of mode "out", "in out", or access-to-variable.
7791 if Ekind (Candidate) in E_Entry | E_Procedure
7792 and then Is_Protected_Type (Typ)
7793 and then not Is_Valid_Formal (Formal)
7797 -- All other cases are OK since a task entry or routine does
7798 -- not have a restriction on the mode of the first parameter
7799 -- of the overridden interface routine.
7802 Overridden_Subp := Candidate;
7807 -- Functions can override abstract interface functions. Return
7808 -- types must be subtype conformant.
7810 elsif Ekind (Def_Id) = E_Function
7811 and then Ekind (Subp) = E_Function
7812 and then Matches_Prefixed_View_Profile
7813 (Parameter_Specifications (Parent (Def_Id)),
7814 Parameter_Specifications (Parent (Subp)))
7815 and then Conforming_Types
7816 (Etype (Def_Id), Etype (Subp), Subtype_Conformant)
7820 -- If an inherited subprogram is implemented by a protected
7821 -- function, then the first parameter of the inherited
7822 -- subprogram shall be of mode in, but not an access-to-
7823 -- variable parameter (RM 9.4(11/9)).
7825 if Present (First_Formal (Subp))
7826 and then Ekind (First_Formal (Subp)) = E_In_Parameter
7828 (not Is_Access_Type (Etype (First_Formal (Subp)))
7830 Is_Access_Constant (Etype (First_Formal (Subp))))
7832 Overridden_Subp := Subp;
7837 Hom := Homonym (Hom);
7840 -- After examining all candidates for overriding, we are left with
7841 -- the best match, which is a mode-incompatible interface routine.
7843 if In_Scope and then Present (Candidate) then
7844 Error_Msg_PT (Def_Id, Candidate);
7847 Overridden_Subp := Candidate;
7850 end Check_Synchronized_Overriding;
7852 ---------------------------
7853 -- Check_Type_Conformant --
7854 ---------------------------
7856 procedure Check_Type_Conformant
7857 (New_Id : Entity_Id;
7859 Err_Loc : Node_Id := Empty)
7862 pragma Warnings (Off, Result);
7865 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
7866 end Check_Type_Conformant;
7868 -----------------------------
7869 -- Check_Untagged_Equality --
7870 -----------------------------
7872 procedure Check_Untagged_Equality (Eq_Op : Entity_Id) is
7873 Eq_Decl : constant Node_Id := Unit_Declaration_Node (Eq_Op);
7874 Typ : constant Entity_Id := Etype (First_Formal (Eq_Op));
7876 procedure Freezing_Point_Warning (N : Node_Id; S : String);
7877 -- Output a warning about the freezing point N of Typ
7879 function Is_Actual_Of_Instantiation
7881 Inst : Node_Id) return Boolean;
7882 -- Return True if E is an actual parameter of instantiation Inst
7884 -----------------------------------
7885 -- Output_Freezing_Point_Warning --
7886 -----------------------------------
7888 procedure Freezing_Point_Warning (N : Node_Id; S : String) is
7890 Error_Msg_String (1 .. S'Length) := S;
7891 Error_Msg_Strlen := S'Length;
7893 if Ada_Version >= Ada_2012 then
7894 Error_Msg_NE ("type& is frozen by ~??", N, Typ);
7896 ("\an equality operator cannot be declared after this point??",
7900 Error_Msg_NE ("type& is frozen by ~ (Ada 2012)?y?", N, Typ);
7902 ("\an equality operator cannot be declared after this point"
7903 & " (Ada 2012)?y?", N);
7905 end Freezing_Point_Warning;
7907 --------------------------------
7908 -- Is_Actual_Of_Instantiation --
7909 --------------------------------
7911 function Is_Actual_Of_Instantiation
7913 Inst : Node_Id) return Boolean
7918 if Present (Generic_Associations (Inst)) then
7919 Assoc := First (Generic_Associations (Inst));
7921 while Present (Assoc) loop
7922 if Present (Explicit_Generic_Actual_Parameter (Assoc))
7924 Is_Entity_Name (Explicit_Generic_Actual_Parameter (Assoc))
7926 Entity (Explicit_Generic_Actual_Parameter (Assoc)) = E
7936 end Is_Actual_Of_Instantiation;
7942 -- Start of processing for Check_Untagged_Equality
7945 -- This check applies only if we have a subprogram declaration or a
7946 -- subprogram body that is not a completion, for an untagged record
7947 -- type, and that is conformant with the predefined operator.
7949 if (Nkind (Eq_Decl) /= N_Subprogram_Declaration
7950 and then not (Nkind (Eq_Decl) = N_Subprogram_Body
7951 and then Acts_As_Spec (Eq_Decl)))
7952 or else not Is_Record_Type (Typ)
7953 or else Is_Tagged_Type (Typ)
7954 or else not Is_User_Defined_Equality (Eq_Op)
7959 -- In Ada 2012 case, we will output errors or warnings depending on
7960 -- the setting of debug flag -gnatd.E.
7962 if Ada_Version >= Ada_2012 then
7963 Error_Msg_Warn := Debug_Flag_Dot_EE;
7965 -- In earlier versions of Ada, nothing to do unless we are warning on
7966 -- Ada 2012 incompatibilities (Warn_On_Ada_2012_Incompatibility set).
7969 if not Warn_On_Ada_2012_Compatibility then
7974 -- Cases where the type has already been frozen
7976 if Is_Frozen (Typ) then
7978 -- The check applies to a primitive operation, so check that type
7979 -- and equality operation are in the same scope.
7981 if Scope (Typ) /= Current_Scope then
7984 -- If the type is a generic actual (sub)type, the operation is not
7985 -- primitive either because the base type is declared elsewhere.
7987 elsif Is_Generic_Actual_Type (Typ) then
7990 -- Here we may have an error of declaration after freezing, but we
7991 -- must make sure not to flag the equality operator itself causing
7992 -- the freezing when it is a subprogram body.
7995 Decl := Next (Declaration_Node (Typ));
7997 while Present (Decl) and then Decl /= Eq_Decl loop
7999 -- The declaration of an object of the type
8001 if Nkind (Decl) = N_Object_Declaration
8002 and then Etype (Defining_Identifier (Decl)) = Typ
8004 Freezing_Point_Warning (Decl, "declaration");
8007 -- The instantiation of a generic on the type
8009 elsif Nkind (Decl) in N_Generic_Instantiation
8010 and then Is_Actual_Of_Instantiation (Typ, Decl)
8012 Freezing_Point_Warning (Decl, "instantiation");
8015 -- A noninstance proper body, body stub or entry body
8017 elsif Nkind (Decl) in N_Proper_Body
8020 and then not Is_Generic_Instance (Defining_Entity (Decl))
8022 Freezing_Point_Warning (Decl, "body");
8025 -- If we have reached the freeze node and immediately after we
8026 -- have the body or generated code for the body, then it is the
8027 -- body that caused the freezing and this is legal.
8029 elsif Nkind (Decl) = N_Freeze_Entity
8030 and then Entity (Decl) = Typ
8031 and then (Next (Decl) = Eq_Decl
8033 Sloc (Next (Decl)) = Sloc (Eq_Decl))
8041 -- Here we have a definite error of declaration after freezing
8043 if Ada_Version >= Ada_2012 then
8045 ("equality operator must be declared before type & is "
8046 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)<<", Eq_Op, Typ);
8048 -- In Ada 2012 mode with error turned to warning, output one
8049 -- more warning to warn that the equality operation may not
8050 -- compose. This is the consequence of ignoring the error.
8052 if Error_Msg_Warn then
8053 Error_Msg_N ("\equality operation may not compose??", Eq_Op);
8058 ("equality operator must be declared before type& is "
8059 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)?y?", Eq_Op, Typ);
8062 -- If we have found no freezing point and the declaration of the
8063 -- operator could not be reached from that of the type and we are
8064 -- in a package body, this must be because the type is declared
8065 -- in the spec of the package. Add a message tailored to this.
8067 if No (Decl) and then In_Package_Body (Scope (Typ)) then
8068 if Ada_Version >= Ada_2012 then
8069 if Nkind (Eq_Decl) = N_Subprogram_Body then
8071 ("\put declaration in package spec<<", Eq_Op);
8074 ("\move declaration to package spec<<", Eq_Op);
8078 if Nkind (Eq_Decl) = N_Subprogram_Body then
8080 ("\put declaration in package spec (Ada 2012)?y?",
8084 ("\move declaration to package spec (Ada 2012)?y?",
8091 -- Now check for AI12-0352: the declaration of a user-defined primitive
8092 -- equality operation for a record type T is illegal if it occurs after
8093 -- a type has been derived from T.
8096 Decl := Next (Declaration_Node (Typ));
8098 while Present (Decl) and then Decl /= Eq_Decl loop
8099 if Nkind (Decl) = N_Full_Type_Declaration
8100 and then Etype (Defining_Identifier (Decl)) = Typ
8103 ("equality operator cannot appear after derivation", Eq_Op);
8105 ("an equality operator for& cannot be declared after "
8113 end Check_Untagged_Equality;
8115 ---------------------------
8116 -- Can_Override_Operator --
8117 ---------------------------
8119 function Can_Override_Operator (Subp : Entity_Id) return Boolean is
8123 -- Return False if not an operator. We test the name rather than testing
8124 -- that the Nkind is N_Defining_Operator_Symbol, because there are cases
8125 -- where an operator entity can be an N_Defining_Identifier (such as for
8126 -- function instantiations).
8128 if Chars (Subp) not in Any_Operator_Name then
8132 Typ := Base_Type (Etype (First_Formal (Subp)));
8134 -- Check explicitly that the operation is a primitive of the type
8136 return Operator_Matches_Spec (Subp, Subp)
8137 and then not Is_Generic_Type (Typ)
8138 and then Scope (Subp) = Scope (Typ)
8139 and then not Is_Class_Wide_Type (Typ);
8141 end Can_Override_Operator;
8143 ----------------------
8144 -- Conforming_Types --
8145 ----------------------
8147 function Conforming_Types
8150 Ctype : Conformance_Type;
8151 Get_Inst : Boolean := False) return Boolean
8153 function Base_Types_Match
8155 Typ_2 : Entity_Id) return Boolean;
8156 -- If neither Typ_1 nor Typ_2 are generic actual types, or if they are
8157 -- in different scopes (e.g. parent and child instances), then verify
8158 -- that the base types are equal. Otherwise Typ_1 and Typ_2 must be on
8159 -- the same subtype chain. The whole purpose of this procedure is to
8160 -- prevent spurious ambiguities in an instantiation that may arise if
8161 -- two distinct generic types are instantiated with the same actual.
8163 function Find_Designated_Type (Typ : Entity_Id) return Entity_Id;
8164 -- An access parameter can designate an incomplete type. If the
8165 -- incomplete type is the limited view of a type from a limited_
8166 -- with_clause, check whether the non-limited view is available.
8167 -- If it is a (non-limited) incomplete type, get the full view.
8169 function Matches_Limited_With_View
8171 Typ_2 : Entity_Id) return Boolean;
8172 -- Returns True if and only if either Typ_1 denotes a limited view of
8173 -- Typ_2 or Typ_2 denotes a limited view of Typ_1. This can arise when
8174 -- the limited with view of a type is used in a subprogram declaration
8175 -- and the subprogram body is in the scope of a regular with clause for
8176 -- the same unit. In such a case, the two type entities are considered
8177 -- identical for purposes of conformance checking.
8179 ----------------------
8180 -- Base_Types_Match --
8181 ----------------------
8183 function Base_Types_Match
8185 Typ_2 : Entity_Id) return Boolean
8187 Base_1 : constant Entity_Id := Base_Type (Typ_1);
8188 Base_2 : constant Entity_Id := Base_Type (Typ_2);
8191 if Typ_1 = Typ_2 then
8194 elsif Base_1 = Base_2 then
8196 -- The following is too permissive. A more precise test should
8197 -- check that the generic actual is an ancestor subtype of the
8200 -- See code in Find_Corresponding_Spec that applies an additional
8201 -- filter to handle accidental amiguities in instances.
8204 not Is_Generic_Actual_Type (Typ_1)
8205 or else not Is_Generic_Actual_Type (Typ_2)
8206 or else Scope (Typ_1) /= Scope (Typ_2);
8208 -- If Typ_2 is a generic actual type it is declared as the subtype of
8209 -- the actual. If that actual is itself a subtype we need to use its
8210 -- own base type to check for compatibility.
8212 elsif Ekind (Base_2) = Ekind (Typ_2)
8213 and then Base_1 = Base_Type (Base_2)
8217 elsif Ekind (Base_1) = Ekind (Typ_1)
8218 and then Base_2 = Base_Type (Base_1)
8225 end Base_Types_Match;
8227 --------------------------
8228 -- Find_Designated_Type --
8229 --------------------------
8231 function Find_Designated_Type (Typ : Entity_Id) return Entity_Id is
8235 Desig := Directly_Designated_Type (Typ);
8237 if Ekind (Desig) = E_Incomplete_Type then
8239 -- If regular incomplete type, get full view if available
8241 if Present (Full_View (Desig)) then
8242 Desig := Full_View (Desig);
8244 -- If limited view of a type, get non-limited view if available,
8245 -- and check again for a regular incomplete type.
8247 elsif Present (Non_Limited_View (Desig)) then
8248 Desig := Get_Full_View (Non_Limited_View (Desig));
8253 end Find_Designated_Type;
8255 -------------------------------
8256 -- Matches_Limited_With_View --
8257 -------------------------------
8259 function Matches_Limited_With_View
8261 Typ_2 : Entity_Id) return Boolean
8263 function Is_Matching_Limited_View
8265 View : Entity_Id) return Boolean;
8266 -- Determine whether non-limited view View denotes type Typ in some
8267 -- conformant fashion.
8269 ------------------------------
8270 -- Is_Matching_Limited_View --
8271 ------------------------------
8273 function Is_Matching_Limited_View
8275 View : Entity_Id) return Boolean
8277 Root_Typ : Entity_Id;
8278 Root_View : Entity_Id;
8281 -- The non-limited view directly denotes the type
8286 -- The type is a subtype of the non-limited view
8288 elsif Is_Subtype_Of (Typ, View) then
8291 -- Both the non-limited view and the type denote class-wide types
8293 elsif Is_Class_Wide_Type (Typ)
8294 and then Is_Class_Wide_Type (View)
8296 Root_Typ := Root_Type (Typ);
8297 Root_View := Root_Type (View);
8299 if Root_Typ = Root_View then
8302 -- An incomplete tagged type and its full view may receive two
8303 -- distinct class-wide types when the related package has not
8304 -- been analyzed yet.
8307 -- type T is tagged; -- CW_1
8308 -- type T is tagged null record; -- CW_2
8311 -- This is because the package lacks any semantic information
8312 -- that may eventually link both views of T. As a consequence,
8313 -- a client of the limited view of Pack will see CW_2 while a
8314 -- client of the non-limited view of Pack will see CW_1.
8316 elsif Is_Incomplete_Type (Root_Typ)
8317 and then Present (Full_View (Root_Typ))
8318 and then Full_View (Root_Typ) = Root_View
8322 elsif Is_Incomplete_Type (Root_View)
8323 and then Present (Full_View (Root_View))
8324 and then Full_View (Root_View) = Root_Typ
8331 end Is_Matching_Limited_View;
8333 -- Start of processing for Matches_Limited_With_View
8336 -- In some cases a type imported through a limited_with clause, and
8337 -- its non-limited view are both visible, for example in an anonymous
8338 -- access-to-class-wide type in a formal, or when building the body
8339 -- for a subprogram renaming after the subprogram has been frozen.
8340 -- In these cases both entities designate the same type. In addition,
8341 -- if one of them is an actual in an instance, it may be a subtype of
8342 -- the non-limited view of the other.
8344 if From_Limited_With (Typ_1)
8345 and then From_Limited_With (Typ_2)
8346 and then Available_View (Typ_1) = Available_View (Typ_2)
8350 elsif From_Limited_With (Typ_1) then
8351 return Is_Matching_Limited_View (Typ_2, Available_View (Typ_1));
8353 elsif From_Limited_With (Typ_2) then
8354 return Is_Matching_Limited_View (Typ_1, Available_View (Typ_2));
8359 end Matches_Limited_With_View;
8363 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
8365 Type_1 : Entity_Id := T1;
8366 Type_2 : Entity_Id := T2;
8368 -- Start of processing for Conforming_Types
8371 -- The context is an instance association for a formal access-to-
8372 -- subprogram type; the formal parameter types require mapping because
8373 -- they may denote other formal parameters of the generic unit.
8376 Type_1 := Get_Instance_Of (T1);
8377 Type_2 := Get_Instance_Of (T2);
8380 -- If one of the types is a view of the other introduced by a limited
8381 -- with clause, treat these as conforming for all purposes.
8383 if Matches_Limited_With_View (T1, T2) then
8386 elsif Base_Types_Match (Type_1, Type_2) then
8387 if Ctype <= Mode_Conformant then
8392 Subtypes_Statically_Match (Type_1, Type_2)
8393 and then Dimensions_Match (Type_1, Type_2);
8396 elsif Is_Incomplete_Or_Private_Type (Type_1)
8397 and then Present (Full_View (Type_1))
8398 and then Base_Types_Match (Full_View (Type_1), Type_2)
8401 Ctype <= Mode_Conformant
8402 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
8404 elsif Ekind (Type_2) = E_Incomplete_Type
8405 and then Present (Full_View (Type_2))
8406 and then Base_Types_Match (Type_1, Full_View (Type_2))
8409 Ctype <= Mode_Conformant
8410 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
8412 elsif Is_Private_Type (Type_2)
8413 and then In_Instance
8414 and then Present (Full_View (Type_2))
8415 and then Base_Types_Match (Type_1, Full_View (Type_2))
8418 Ctype <= Mode_Conformant
8419 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
8421 -- Another confusion between views in a nested instance with an
8422 -- actual private type whose full view is not in scope.
8424 elsif Ekind (Type_2) = E_Private_Subtype
8425 and then In_Instance
8426 and then Etype (Type_2) = Type_1
8430 -- In Ada 2012, incomplete types (including limited views) can appear
8431 -- as actuals in instantiations, where they are conformant to the
8432 -- corresponding incomplete formal.
8434 elsif Is_Incomplete_Type (Type_1)
8435 and then Is_Incomplete_Type (Type_2)
8436 and then In_Instance
8437 and then (Used_As_Generic_Actual (Type_1)
8438 or else Used_As_Generic_Actual (Type_2))
8443 -- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be
8444 -- treated recursively because they carry a signature. As far as
8445 -- conformance is concerned, convention plays no role, and either
8446 -- or both could be access to protected subprograms.
8448 Are_Anonymous_Access_To_Subprogram_Types :=
8449 Ekind (Type_1) in E_Anonymous_Access_Subprogram_Type
8450 | E_Anonymous_Access_Protected_Subprogram_Type
8452 Ekind (Type_2) in E_Anonymous_Access_Subprogram_Type
8453 | E_Anonymous_Access_Protected_Subprogram_Type;
8455 -- Test anonymous access type case. For this case, static subtype
8456 -- matching is required for mode conformance (RM 6.3.1(15)). We check
8457 -- the base types because we may have built internal subtype entities
8458 -- to handle null-excluding types (see Process_Formals).
8460 if (Ekind (Base_Type (Type_1)) = E_Anonymous_Access_Type
8462 Ekind (Base_Type (Type_2)) = E_Anonymous_Access_Type)
8464 -- Ada 2005 (AI-254)
8466 or else Are_Anonymous_Access_To_Subprogram_Types
8469 Desig_1 : Entity_Id;
8470 Desig_2 : Entity_Id;
8473 -- In Ada 2005, access constant indicators must match for
8474 -- subtype conformance.
8476 if Ada_Version >= Ada_2005
8477 and then Ctype >= Subtype_Conformant
8479 Is_Access_Constant (Type_1) /= Is_Access_Constant (Type_2)
8484 Desig_1 := Find_Designated_Type (Type_1);
8485 Desig_2 := Find_Designated_Type (Type_2);
8487 -- If the context is an instance association for a formal
8488 -- access-to-subprogram type; formal access parameter designated
8489 -- types require mapping because they may denote other formal
8490 -- parameters of the generic unit.
8493 Desig_1 := Get_Instance_Of (Desig_1);
8494 Desig_2 := Get_Instance_Of (Desig_2);
8497 -- It is possible for a Class_Wide_Type to be introduced for an
8498 -- incomplete type, in which case there is a separate class_ wide
8499 -- type for the full view. The types conform if their Etypes
8500 -- conform, i.e. one may be the full view of the other. This can
8501 -- only happen in the context of an access parameter, other uses
8502 -- of an incomplete Class_Wide_Type are illegal.
8504 if Is_Class_Wide_Type (Desig_1)
8506 Is_Class_Wide_Type (Desig_2)
8510 (Etype (Base_Type (Desig_1)),
8511 Etype (Base_Type (Desig_2)), Ctype);
8513 elsif Are_Anonymous_Access_To_Subprogram_Types then
8514 if Ada_Version < Ada_2005 then
8516 Ctype = Type_Conformant
8517 or else Subtypes_Statically_Match (Desig_1, Desig_2);
8519 -- We must check the conformance of the signatures themselves
8523 Conformant : Boolean;
8526 (Desig_1, Desig_2, Ctype, False, Conformant);
8531 -- A limited view of an actual matches the corresponding
8532 -- incomplete formal.
8534 elsif Ekind (Desig_2) = E_Incomplete_Subtype
8535 and then From_Limited_With (Desig_2)
8536 and then Used_As_Generic_Actual (Etype (Desig_2))
8541 return Base_Type (Desig_1) = Base_Type (Desig_2)
8542 and then (Ctype = Type_Conformant
8544 Subtypes_Statically_Match (Desig_1, Desig_2));
8548 -- Otherwise definitely no match
8551 if ((Ekind (Type_1) = E_Anonymous_Access_Type
8552 and then Is_Access_Type (Type_2))
8553 or else (Ekind (Type_2) = E_Anonymous_Access_Type
8554 and then Is_Access_Type (Type_1)))
8557 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
8559 May_Hide_Profile := True;
8564 end Conforming_Types;
8566 --------------------------
8567 -- Create_Extra_Formals --
8568 --------------------------
8570 procedure Create_Extra_Formals (E : Entity_Id) is
8571 First_Extra : Entity_Id := Empty;
8573 Last_Extra : Entity_Id := Empty;
8575 function Add_Extra_Formal
8576 (Assoc_Entity : Entity_Id;
8579 Suffix : String) return Entity_Id;
8580 -- Add an extra formal to the current list of formals and extra formals.
8581 -- The extra formal is added to the end of the list of extra formals,
8582 -- and also returned as the result. These formals are always of mode IN.
8583 -- The new formal has the type Typ, is declared in Scope, and its name
8584 -- is given by a concatenation of the name of Assoc_Entity and Suffix.
8585 -- The following suffixes are currently used. They should not be changed
8586 -- without coordinating with CodePeer, which makes use of these to
8587 -- provide better messages.
8589 -- O denotes the Constrained bit.
8590 -- L denotes the accessibility level.
8591 -- BIP_xxx denotes an extra formal for a build-in-place function. See
8592 -- the full list in exp_ch6.BIP_Formal_Kind.
8594 function Has_Extra_Formals (E : Entity_Id) return Boolean;
8595 -- Determines if E has its extra formals
8597 function Needs_Accessibility_Check_Extra
8599 Formal : Node_Id) return Boolean;
8600 -- Determines whether the given formal of E needs an extra formal for
8601 -- supporting accessibility checking. Returns True for both anonymous
8602 -- access formals and formals of named access types that are marked as
8603 -- controlling formals. The latter case can occur when the subprogram
8604 -- Expand_Dispatching_Call creates a subprogram-type and substitutes
8605 -- the types of access-to-class-wide actuals for the anonymous access-
8606 -- to-specific-type of controlling formals.
8608 function Parent_Subprogram (Subp_Id : Entity_Id) return Entity_Id;
8609 -- Subp_Id is a subprogram of a derived type; return its parent
8610 -- subprogram if Subp_Id overrides a parent primitive or derives
8611 -- from a parent primitive, and such parent primitive can have extra
8612 -- formals. Otherwise return Empty.
8614 ----------------------
8615 -- Add_Extra_Formal --
8616 ----------------------
8618 function Add_Extra_Formal
8619 (Assoc_Entity : Entity_Id;
8622 Suffix : String) return Entity_Id
8627 -- A little optimization. Never generate an extra formal for the
8628 -- _init operand of an initialization procedure, since it could
8631 if Chars (Formal) = Name_uInit then
8635 EF := Make_Defining_Identifier (Sloc (Assoc_Entity),
8636 Chars => New_External_Name (Chars (Assoc_Entity),
8639 Mutate_Ekind (EF, E_In_Parameter);
8640 Set_Actual_Subtype (EF, Typ);
8641 Set_Etype (EF, Typ);
8642 Set_Scope (EF, Scope);
8643 Set_Mechanism (EF, Default_Mechanism);
8644 Set_Formal_Validity (EF);
8646 if No (First_Extra) then
8648 Set_Extra_Formals (Scope, EF);
8651 if Present (Last_Extra) then
8652 Set_Extra_Formal (Last_Extra, EF);
8658 end Add_Extra_Formal;
8660 -----------------------
8661 -- Has_Extra_Formals --
8662 -----------------------
8664 function Has_Extra_Formals (E : Entity_Id) return Boolean is
8666 return Present (Extra_Formals (E))
8668 (Ekind (E) = E_Function
8669 and then Present (Extra_Accessibility_Of_Result (E)));
8670 end Has_Extra_Formals;
8672 -------------------------------------
8673 -- Needs_Accessibility_Check_Extra --
8674 -------------------------------------
8676 function Needs_Accessibility_Check_Extra
8678 Formal : Node_Id) return Boolean is
8681 -- For dispatching operations this extra formal is not suppressed
8682 -- since all the derivations must have matching formals.
8684 -- For nondispatching operations it is suppressed if we specifically
8685 -- suppress accessibility checks at the package level for either the
8686 -- subprogram, or the package in which it resides. However, we do
8687 -- not suppress it simply if the scope has accessibility checks
8688 -- suppressed, since this could cause trouble when clients are
8689 -- compiled with a different suppression setting. The explicit checks
8690 -- at the package level are safe from this point of view.
8692 if not Is_Dispatching_Operation (E)
8694 (Explicit_Suppress (E, Accessibility_Check)
8695 or else Explicit_Suppress (Scope (E), Accessibility_Check))
8700 -- Base_Type is applied to handle cases where there is a null
8701 -- exclusion the formal may have an access subtype.
8704 Ekind (Base_Type (Etype (Formal))) = E_Anonymous_Access_Type
8706 (Is_Controlling_Formal (Formal)
8707 and then Is_Access_Type (Base_Type (Etype (Formal))));
8708 end Needs_Accessibility_Check_Extra;
8710 -----------------------
8711 -- Parent_Subprogram --
8712 -----------------------
8714 function Parent_Subprogram (Subp_Id : Entity_Id) return Entity_Id is
8715 pragma Assert (not Is_Thunk (Subp_Id));
8716 Ovr_E : Entity_Id := Overridden_Operation (Subp_Id);
8717 Ovr_Alias : Entity_Id;
8720 if Present (Ovr_E) then
8721 Ovr_Alias := Ultimate_Alias (Ovr_E);
8723 -- There is no real overridden subprogram if there is a mutual
8724 -- reference between the E and its overridden operation. This
8725 -- weird scenery occurs in the following cases:
8727 -- 1) Controlling function wrappers internally built by
8728 -- Make_Controlling_Function_Wrappers.
8730 -- 2) Hidden overridden primitives of type extensions or private
8731 -- extensions (cf. Find_Hidden_Overridden_Primitive). These
8732 -- hidden primitives have suffix 'P
'.
8734 -- 3) Overriding primitives of stub types (see the subprogram
8735 -- Add_RACW_Primitive_Declarations_And_Bodies).
8737 if Ovr_Alias = Subp_Id then
8739 ((Is_Wrapper (Subp_Id)
8740 and then Has_Controlling_Result (Subp_Id))
8741 or else Has_Suffix (Ovr_E, 'P
')
8742 or else Is_RACW_Stub_Type
8743 (Find_Dispatching_Type (Subp_Id)));
8745 if Present (Overridden_Operation (Ovr_E)) then
8746 Ovr_E := Overridden_Operation (Ovr_E);
8748 -- Ovr_E is an internal entity built by Derive_Subprogram and
8749 -- we have no direct way to climb to the corresponding parent
8750 -- subprogram but this internal entity has the extra formals
8751 -- (if any) required for the purpose of checking the extra
8752 -- formals of Subp_Id.
8755 pragma Assert (not Comes_From_Source (Ovr_E));
8758 -- Use as our reference entity the ultimate renaming of the
8759 -- overridden subprogram.
8761 elsif Present (Alias (Ovr_E)) then
8762 pragma Assert (No (Overridden_Operation (Ovr_Alias))
8763 or else Overridden_Operation (Ovr_Alias) /= Ovr_E);
8769 if Present (Ovr_E) and then Has_Reliable_Extra_Formals (Ovr_E) then
8774 end Parent_Subprogram;
8778 Formal_Type : Entity_Id;
8779 May_Have_Alias : Boolean;
8780 Alias_Formal : Entity_Id := Empty;
8781 Alias_Subp : Entity_Id := Empty;
8782 Parent_Formal : Entity_Id := Empty;
8783 Parent_Subp : Entity_Id := Empty;
8786 -- Start of processing for Create_Extra_Formals
8789 pragma Assert (Is_Subprogram_Or_Entry (E)
8790 or else Ekind (E) in E_Subprogram_Type);
8792 -- We never generate extra formals if expansion is not active because we
8793 -- don't need them unless we are generating code.
8795 if not Expander_Active then
8798 -- Enumeration literals have no extra formal; this case occurs when
8799 -- a function renames it.
8801 elsif Ekind (E) = E_Function
8802 and then Ekind (Ultimate_Alias (E)) = E_Enumeration_Literal
8806 -- Initialization procedures don't have extra formals
8808 elsif Is_Init_Proc (E) then
8811 -- No need to generate extra formals in thunks whose target has no extra
8812 -- formals, but we can have two of them chained (interface and stack).
8814 elsif Is_Thunk (E) and then No (Extra_Formals (Thunk_Target (E))) then
8817 -- If Extra_Formals were already created, don't do it again. This
8818 -- situation may arise for subprogram types created as part of
8819 -- dispatching calls (see Expand_Dispatching_Call).
8821 elsif Has_Extra_Formals (E) then
8824 -- Extra formals of renamings of generic actual subprograms and
8825 -- renamings of instances of generic subprograms are shared. The
8826 -- check performed on the last formal is required to ensure that
8827 -- this is the renaming built by Analyze_Instance_And_Renamings
8828 -- (which shares all the formals); otherwise this would be wrong.
8830 elsif Ekind (E) in E_Function | E_Procedure
8831 and then Is_Generic_Instance (E)
8832 and then Present (Alias (E))
8833 and then Last_Formal (Ultimate_Alias (E)) = Last_Formal (E)
8835 pragma Assert (Is_Generic_Instance (E)
8836 = Is_Generic_Instance (Ultimate_Alias (E)));
8838 Create_Extra_Formals (Ultimate_Alias (E));
8840 -- Share the extra formals
8842 Set_Extra_Formals (E, Extra_Formals (Ultimate_Alias (E)));
8844 if Ekind (E) = E_Function then
8845 Set_Extra_Accessibility_Of_Result (E,
8846 Extra_Accessibility_Of_Result (Ultimate_Alias (E)));
8849 pragma Assert (Extra_Formals_OK (E));
8853 -- Locate the last formal; required by Add_Extra_Formal.
8855 Formal := First_Formal (E);
8856 while Present (Formal) loop
8857 Last_Extra := Formal;
8858 Next_Formal (Formal);
8861 -- We rely on three entities to ensure consistency of extra formals of
8864 -- 1. A reference entity (Ref_E). For thunks it is their target
8865 -- primitive since this ensures that they have exactly the
8866 -- same extra formals; otherwise it is the identity.
8868 -- 2. The parent subprogram; only for derived types and references
8869 -- either the overridden subprogram or the internal entity built
8870 -- by Derive_Subprogram that has the extra formals of the parent
8871 -- subprogram; otherwise it is Empty. This entity ensures matching
8872 -- extra formals in derived types.
8874 -- 3. For renamings, their ultimate alias; this ensures taking the
8875 -- same decision in all the renamings (independently of the Ada
8876 -- mode on which they are compiled). For example:
8879 -- function Id_A (I : access Integer) return access Integer;
8882 -- function Id_B (I : access Integer) return access Integer
8885 if Is_Thunk (E) then
8886 Ref_E := Thunk_Target (E);
8891 if Is_Subprogram (Ref_E) then
8892 Parent_Subp := Parent_Subprogram (Ref_E);
8896 (Is_Subprogram (Ref_E) or else Ekind (Ref_E) = E_Subprogram_Type);
8898 -- If the parent subprogram is available then its ultimate alias of
8899 -- Ref_E is not needed since it will not be used to check its extra
8903 and then May_Have_Alias
8904 and then Present (Alias (Ref_E))
8905 and then Has_Reliable_Extra_Formals (Ultimate_Alias (Ref_E))
8907 Alias_Subp := Ultimate_Alias (Ref_E);
8910 -- Cannot add extra formals to subprograms and access types that have
8911 -- foreign convention nor to subprograms overriding primitives that
8912 -- have foreign convention since the foreign language does not know
8913 -- how to handle these extra formals; same for renamings of entities
8914 -- with foreign convention.
8916 if Has_Foreign_Convention (Ref_E)
8917 or else (Present (Alias_Subp)
8918 and then Has_Foreign_Convention (Alias_Subp))
8923 -- If the subprogram is a predefined dispatching subprogram then don't
8924 -- generate any extra constrained or accessibility level formals. In
8925 -- general we suppress these for internal subprograms (by not calling
8926 -- Freeze_Subprogram and Create_Extra_Formals at all), but internally
8927 -- generated stream attributes do get passed through because extra
8928 -- build-in-place formals are needed in some cases (limited 'Input
).
8930 if Is_Predefined_Internal_Operation
(E
) then
8931 goto Test_For_Func_Result_Extras
;
8934 -- Process the formals relying on the formals of our reference entities:
8935 -- Parent_Formal, Alias_Formal and Formal. Notice that we don't use the
8936 -- formal of Ref_E; we must use the formal of E which is the entity to
8937 -- which we are adding the extra formals.
8939 -- If this is a derived subprogram then the subtypes of the parent
8940 -- subprogram's formal parameters will be used to determine the need
8941 -- for extra formals.
8943 if Present
(Parent_Subp
) then
8944 Parent_Formal
:= First_Formal
(Parent_Subp
);
8946 -- For concurrent types, the controlling argument of a dispatching
8947 -- primitive implementing an interface primitive is implicit. For
8950 -- type Iface is protected interface;
8953 -- Value : Integer) return Natural is abstract;
8955 -- protected type PO is new Iface with
8956 -- function Prim (Value : Integer) return Natural;
8959 if Convention
(Ref_E
) = Convention_Protected
8960 and then Is_Abstract_Subprogram
(Parent_Subp
)
8961 and then Is_Interface
(Find_Dispatching_Type
(Parent_Subp
))
8963 Parent_Formal
:= Next_Formal
(Parent_Formal
);
8965 -- This is the nondispatching subprogram of a concurrent type
8966 -- that overrides the interface primitive; the expander will
8967 -- create the dispatching primitive (without Convention_Protected)
8968 -- with all the matching formals (see exp_ch9.Build_Wrapper_Specs)
8970 pragma Assert
(not Is_Dispatching_Operation
(Ref_E
));
8973 -- Ensure that the ultimate alias has all its extra formals
8975 elsif Present
(Alias_Subp
) then
8976 Create_Extra_Formals
(Alias_Subp
);
8977 Alias_Formal
:= First_Formal
(Alias_Subp
);
8980 Formal
:= First_Formal
(E
);
8981 while Present
(Formal
) loop
8983 -- Here we establish our priority for deciding on the extra
8984 -- formals: 1) Parent primitive 2) Aliased primitive 3) Identity
8986 if Present
(Parent_Formal
) then
8987 Formal_Type
:= Etype
(Parent_Formal
);
8989 elsif Present
(Alias_Formal
) then
8990 Formal_Type
:= Etype
(Alias_Formal
);
8993 Formal_Type
:= Etype
(Formal
);
8996 -- Create extra formal for supporting the attribute 'Constrained.
8997 -- The case of a private type view without discriminants also
8998 -- requires the extra formal if the underlying type has defaulted
9001 if Ekind
(Formal
) /= E_In_Parameter
then
9003 -- Do not produce extra formals for Unchecked_Union parameters.
9004 -- Jump directly to the end of the loop.
9006 if Is_Unchecked_Union
(Base_Type
(Formal_Type
)) then
9007 goto Skip_Extra_Formal_Generation
;
9010 if not Has_Discriminants
(Formal_Type
)
9011 and then Is_Private_Type
(Formal_Type
)
9012 and then Present
(Underlying_Type
(Formal_Type
))
9014 Formal_Type
:= Underlying_Type
(Formal_Type
);
9017 -- Suppress the extra formal if formal's subtype is constrained or
9018 -- indefinite, or we're compiling for Ada 2012 and the underlying
9019 -- type is tagged and limited. In Ada 2012, a limited tagged type
9020 -- can have defaulted discriminants, but 'Constrained is required
9021 -- to return True, so the formal is never needed (see AI05-0214).
9022 -- Note that this ensures consistency of calling sequences for
9023 -- dispatching operations when some types in a class have defaults
9024 -- on discriminants and others do not (and requiring the extra
9025 -- formal would introduce distributed overhead).
9027 -- If the type does not have a completion yet, treat as prior to
9028 -- Ada 2012 for consistency.
9030 if Has_Discriminants
(Formal_Type
)
9031 and then not Is_Constrained
(Formal_Type
)
9032 and then Is_Definite_Subtype
(Formal_Type
)
9033 and then (Ada_Version
< Ada_2012
9034 or else No
(Underlying_Type
(Formal_Type
))
9036 (Is_Limited_Type
(Formal_Type
)
9039 (Underlying_Type
(Formal_Type
))))
9041 Set_Extra_Constrained
9042 (Formal
, Add_Extra_Formal
(Formal
, Standard_Boolean
, E
, "O"));
9046 -- Extra formal for supporting accessibility checking
9048 if Needs_Accessibility_Check_Extra
(Ref_E
, Formal
) then
9049 pragma Assert
(No
(Parent_Formal
)
9050 or else Present
(Extra_Accessibility
(Parent_Formal
)));
9051 pragma Assert
(No
(Alias_Formal
)
9052 or else Present
(Extra_Accessibility
(Alias_Formal
)));
9054 Set_Extra_Accessibility
9055 (Formal
, Add_Extra_Formal
(Formal
, Standard_Natural
, E
, "L"));
9058 pragma Assert
(No
(Parent_Formal
)
9059 or else No
(Extra_Accessibility
(Parent_Formal
)));
9060 pragma Assert
(No
(Alias_Formal
)
9061 or else No
(Extra_Accessibility
(Alias_Formal
)));
9064 -- This label is required when skipping extra formal generation for
9065 -- Unchecked_Union parameters.
9067 <<Skip_Extra_Formal_Generation
>>
9069 if Present
(Parent_Formal
) then
9070 Next_Formal
(Parent_Formal
);
9073 if Present
(Alias_Formal
) then
9074 Next_Formal
(Alias_Formal
);
9077 Next_Formal
(Formal
);
9080 <<Test_For_Func_Result_Extras
>>
9082 -- Assume the worst case (Ada 2022) to evaluate this extra formal;
9083 -- required to ensure matching of extra formals between subprograms
9084 -- and access-to-subprogram types in projects with mixed Ada dialects.
9087 Save_Ada_Version
: constant Ada_Version_Type
:= Ada_Version
;
9090 Ada_Version
:= Ada_2022
;
9092 if Needs_Result_Accessibility_Level
(Ref_E
) then
9093 pragma Assert
(No
(Parent_Subp
)
9094 or else Needs_Result_Accessibility_Level
(Parent_Subp
));
9095 pragma Assert
(No
(Alias_Subp
)
9096 or else Needs_Result_Accessibility_Level
(Alias_Subp
));
9098 Set_Extra_Accessibility_Of_Result
(E
,
9099 Add_Extra_Formal
(E
, Standard_Natural
, E
, "L"));
9102 pragma Assert
(No
(Parent_Subp
)
9103 or else not Needs_Result_Accessibility_Level
(Parent_Subp
));
9104 pragma Assert
(No
(Alias_Subp
)
9105 or else not Needs_Result_Accessibility_Level
(Alias_Subp
));
9108 Ada_Version
:= Save_Ada_Version
;
9111 -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add
9112 -- appropriate extra formals. See type Exp_Ch6.BIP_Formal_Kind.
9114 if (Present
(Parent_Subp
) and then Has_BIP_Formals
(Parent_Subp
))
9116 (Present
(Alias_Subp
) and then Has_BIP_Formals
(Alias_Subp
))
9118 (Is_Build_In_Place_Function
(Ref_E
)
9119 and then Has_Reliable_Extra_Formals
(Ref_E
))
9122 Result_Subt
: constant Entity_Id
:= Etype
(Ref_E
);
9123 Formal_Typ
: Entity_Id
;
9124 Subp_Decl
: Node_Id
;
9125 Discard
: Entity_Id
;
9128 -- In the case of functions with unconstrained result subtypes,
9129 -- add a 4-state formal indicating whether the return object is
9130 -- allocated by the caller (1), or should be allocated by the
9131 -- callee on the secondary stack (2), in the global heap (3), or
9132 -- in a user-defined storage pool (4). For the moment we just use
9133 -- Natural for the type of this formal. Note that this formal
9134 -- isn't usually needed in the case where the result subtype is
9135 -- constrained, but it is needed when the function has a tagged
9136 -- result, because generally such functions can be called in a
9137 -- dispatching context and such calls must be handled like calls
9138 -- to a class-wide function.
9140 if Needs_BIP_Alloc_Form
(Ref_E
) then
9141 pragma Assert
(No
(Parent_Subp
)
9142 or else Has_BIP_Extra_Formal
(Parent_Subp
, BIP_Alloc_Form
,
9143 Must_Be_Frozen
=> False));
9144 pragma Assert
(No
(Alias_Subp
)
9145 or else Has_BIP_Extra_Formal
(Alias_Subp
, BIP_Alloc_Form
,
9146 Must_Be_Frozen
=> False));
9150 (E
, Standard_Natural
,
9151 E
, BIP_Formal_Suffix
(BIP_Alloc_Form
));
9153 -- Add BIP_Storage_Pool, in case BIP_Alloc_Form indicates to
9154 -- use a user-defined pool. This formal is not added on
9155 -- ZFP as those targets do not support pools.
9157 if RTE_Available
(RE_Root_Storage_Pool_Ptr
) then
9160 (E
, RTE
(RE_Root_Storage_Pool_Ptr
),
9161 E
, BIP_Formal_Suffix
(BIP_Storage_Pool
));
9165 pragma Assert
(No
(Parent_Subp
)
9167 Has_BIP_Extra_Formal
(Parent_Subp
, BIP_Alloc_Form
,
9168 Must_Be_Frozen
=> False));
9169 pragma Assert
(No
(Alias_Subp
)
9171 Has_BIP_Extra_Formal
(Alias_Subp
, BIP_Alloc_Form
,
9172 Must_Be_Frozen
=> False));
9175 -- In the case of functions whose result type needs finalization,
9176 -- add an extra formal which represents the finalization master.
9178 if Needs_BIP_Finalization_Master
(Ref_E
) then
9179 pragma Assert
(No
(Parent_Subp
)
9180 or else Has_BIP_Extra_Formal
(Parent_Subp
,
9181 Kind
=> BIP_Finalization_Master
,
9182 Must_Be_Frozen
=> False));
9183 pragma Assert
(No
(Alias_Subp
)
9184 or else Has_BIP_Extra_Formal
(Alias_Subp
,
9185 Kind
=> BIP_Finalization_Master
,
9186 Must_Be_Frozen
=> False));
9190 (E
, RTE
(RE_Finalization_Master_Ptr
),
9191 E
, BIP_Formal_Suffix
(BIP_Finalization_Master
));
9194 pragma Assert
(No
(Parent_Subp
)
9196 Has_BIP_Extra_Formal
(Parent_Subp
,
9197 Kind
=> BIP_Finalization_Master
,
9198 Must_Be_Frozen
=> False));
9199 pragma Assert
(No
(Alias_Subp
)
9201 Has_BIP_Extra_Formal
(Alias_Subp
,
9202 Kind
=> BIP_Finalization_Master
,
9203 Must_Be_Frozen
=> False));
9206 -- When the result type contains tasks, add two extra formals: the
9207 -- master of the tasks to be created, and the caller's activation
9210 if Needs_BIP_Task_Actuals
(Ref_E
) then
9211 pragma Assert
(No
(Parent_Subp
)
9212 or else Has_BIP_Extra_Formal
(Parent_Subp
, BIP_Task_Master
,
9213 Must_Be_Frozen
=> False));
9214 pragma Assert
(No
(Alias_Subp
)
9215 or else Has_BIP_Extra_Formal
(Alias_Subp
, BIP_Task_Master
,
9216 Must_Be_Frozen
=> False)
9218 (Is_Abstract_Subprogram
(Ref_E
)
9219 and then Is_Predefined_Dispatching_Operation
(Ref_E
)
9220 and then Is_Interface
9221 (Find_Dispatching_Type
(Alias_Subp
))));
9225 (E
, Standard_Integer
,
9226 E
, BIP_Formal_Suffix
(BIP_Task_Master
));
9228 Set_Has_Master_Entity
(E
);
9232 (E
, RTE
(RE_Activation_Chain_Access
),
9233 E
, BIP_Formal_Suffix
(BIP_Activation_Chain
));
9236 pragma Assert
(No
(Parent_Subp
)
9238 Has_BIP_Extra_Formal
(Parent_Subp
, BIP_Task_Master
,
9239 Must_Be_Frozen
=> False));
9240 pragma Assert
(No
(Alias_Subp
)
9242 Has_BIP_Extra_Formal
(Alias_Subp
, BIP_Task_Master
,
9243 Must_Be_Frozen
=> False));
9246 -- All build-in-place functions get an extra formal that will be
9247 -- passed the address of the return object within the caller.
9250 Create_Itype
(E_Anonymous_Access_Type
, E
, Scope_Id
=> Scope
(E
));
9252 -- Incomplete_View_From_Limited_With is needed here because
9253 -- gigi gets confused if the designated type is the full view
9254 -- coming from a limited-with'ed package. In the normal case,
9255 -- (no limited with) Incomplete_View_From_Limited_With
9256 -- returns Result_Subt.
9258 Set_Directly_Designated_Type
9259 (Formal_Typ
, Incomplete_View_From_Limited_With
(Result_Subt
));
9260 Set_Etype
(Formal_Typ
, Formal_Typ
);
9261 Set_Depends_On_Private
9262 (Formal_Typ
, Has_Private_Component
(Formal_Typ
));
9263 Set_Is_Public
(Formal_Typ
, Is_Public
(Scope
(Formal_Typ
)));
9264 Set_Is_Access_Constant
(Formal_Typ
, False);
9266 -- Ada 2005 (AI-50217): Propagate the attribute that indicates
9267 -- the designated type comes from the limited view (for back-end
9270 Set_From_Limited_With
9271 (Formal_Typ
, From_Limited_With
(Result_Subt
));
9273 Layout_Type
(Formal_Typ
);
9275 -- Force the definition of the Itype in case of internal function
9276 -- calls within the same or nested scope.
9278 if Is_Subprogram_Or_Generic_Subprogram
(E
)
9279 and then not Is_Compilation_Unit
(E
)
9281 Subp_Decl
:= Parent
(E
);
9283 -- The insertion point for an Itype reference should be after
9284 -- the unit declaration node of the subprogram. An exception
9285 -- to this are inherited operations from a parent type in which
9286 -- case the derived type acts as their parent.
9288 if Nkind
(Subp_Decl
) in N_Function_Specification
9289 | N_Procedure_Specification
9291 Subp_Decl
:= Parent
(Subp_Decl
);
9294 Build_Itype_Reference
(Formal_Typ
, Subp_Decl
);
9299 (E
, Formal_Typ
, E
, BIP_Formal_Suffix
(BIP_Object_Access
));
9303 -- If this is an instance of a generic, we need to have extra formals
9306 if Is_Generic_Instance
(E
) and then Present
(Alias
(E
)) then
9307 Set_Extra_Formals
(Alias
(E
), Extra_Formals
(E
));
9310 pragma Assert
(No
(Alias_Subp
)
9311 or else Extra_Formals_Match_OK
(E
, Alias_Subp
));
9313 pragma Assert
(No
(Parent_Subp
)
9314 or else Extra_Formals_Match_OK
(E
, Parent_Subp
));
9316 pragma Assert
(Extra_Formals_OK
(E
));
9317 end Create_Extra_Formals
;
9319 -----------------------------
9320 -- Enter_Overloaded_Entity --
9321 -----------------------------
9323 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
9324 function Matches_Predefined_Op
return Boolean;
9325 -- This returns an approximation of whether S matches a predefined
9326 -- operator, based on the operator symbol, and the parameter and result
9327 -- types. The rules are scattered throughout chapter 4 of the Ada RM.
9329 ---------------------------
9330 -- Matches_Predefined_Op --
9331 ---------------------------
9333 function Matches_Predefined_Op
return Boolean is
9334 Formal_1
: constant Entity_Id
:= First_Formal
(S
);
9335 Formal_2
: constant Entity_Id
:= Next_Formal
(Formal_1
);
9336 Op
: constant Name_Id
:= Chars
(S
);
9337 Result_Type
: constant Entity_Id
:= Base_Type
(Etype
(S
));
9338 Type_1
: constant Entity_Id
:= Base_Type
(Etype
(Formal_1
));
9343 if Present
(Formal_2
) then
9345 Type_2
: constant Entity_Id
:= Base_Type
(Etype
(Formal_2
));
9348 -- All but "&" and "**" have same-types parameters
9357 if Type_1
/= Type_2
then
9362 -- Check parameter and result types
9370 Is_Boolean_Type
(Result_Type
)
9371 and then Result_Type
= Type_1
;
9377 Is_Integer_Type
(Result_Type
)
9378 and then Result_Type
= Type_1
;
9386 Is_Numeric_Type
(Result_Type
)
9387 and then Result_Type
= Type_1
;
9393 Is_Boolean_Type
(Result_Type
)
9394 and then not Is_Limited_Type
(Type_1
);
9402 Is_Boolean_Type
(Result_Type
)
9403 and then (Is_Array_Type
(Type_1
)
9404 or else Is_Scalar_Type
(Type_1
));
9406 when Name_Op_Concat
=>
9407 return Is_Array_Type
(Result_Type
);
9409 when Name_Op_Expon
=>
9411 (Is_Integer_Type
(Result_Type
)
9412 or else Is_Floating_Point_Type
(Result_Type
))
9413 and then Result_Type
= Type_1
9414 and then Type_2
= Standard_Integer
;
9417 raise Program_Error
;
9430 Is_Numeric_Type
(Result_Type
)
9431 and then Result_Type
= Type_1
;
9435 Is_Boolean_Type
(Result_Type
)
9436 and then Result_Type
= Type_1
;
9439 raise Program_Error
;
9442 end Matches_Predefined_Op
;
9446 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
9447 C_E
: Entity_Id
:= Current_Entity
(S
);
9449 -- Start of processing for Enter_Overloaded_Entity
9453 Set_Has_Homonym
(E
);
9454 Set_Has_Homonym
(S
);
9457 Set_Is_Immediately_Visible
(S
);
9458 Set_Scope
(S
, Current_Scope
);
9460 -- Chain new entity if front of homonym in current scope, so that
9461 -- homonyms are contiguous.
9463 if Present
(E
) and then E
/= C_E
then
9464 while Homonym
(C_E
) /= E
loop
9465 C_E
:= Homonym
(C_E
);
9468 Set_Homonym
(C_E
, S
);
9472 Set_Current_Entity
(S
);
9477 if Is_Inherited_Operation
(S
) then
9478 Append_Inherited_Subprogram
(S
);
9480 Append_Entity
(S
, Current_Scope
);
9483 Set_Public_Status
(S
);
9485 if Debug_Flag_E
then
9486 Write_Str
("New overloaded entity chain: ");
9487 Write_Name
(Chars
(S
));
9490 while Present
(E
) loop
9491 Write_Str
(" "); Write_Int
(Int
(E
));
9498 -- Generate warning for hiding
9501 and then Comes_From_Source
(S
)
9502 and then In_Extended_Main_Source_Unit
(S
)
9509 -- Warn unless genuine overloading. Do not emit warning on
9510 -- hiding predefined operators in Standard (these are either an
9511 -- artifact of our implicit declarations, or simple noise) but
9512 -- keep warning on a operator defined on a local subtype, because
9513 -- of the real danger that different operators may be applied in
9514 -- various parts of the program.
9516 -- Note that if E and S have the same scope, there is never any
9517 -- hiding. Either the two conflict, and the program is illegal,
9518 -- or S is overriding an implicit inherited subprogram.
9520 if Scope
(E
) /= Scope
(S
)
9521 and then (not Is_Overloadable
(E
)
9522 or else Subtype_Conformant
(E
, S
))
9523 and then (Is_Immediately_Visible
(E
)
9524 or else Is_Potentially_Use_Visible
(S
))
9526 if Scope
(E
) = Standard_Standard
then
9527 if Nkind
(S
) = N_Defining_Operator_Symbol
9528 and then Scope
(Base_Type
(Etype
(First_Formal
(S
)))) /=
9530 and then Matches_Predefined_Op
9533 ("declaration of & hides predefined operator?h?", S
);
9536 -- E not immediately within Standard
9539 Error_Msg_Sloc
:= Sloc
(E
);
9540 Error_Msg_N
("declaration of & hides one #?h?", S
);
9545 end Enter_Overloaded_Entity
;
9547 ----------------------------
9548 -- Extra_Formals_Match_OK --
9549 ----------------------------
9551 function Extra_Formals_Match_OK
9553 Ref_E
: Entity_Id
) return Boolean is
9555 pragma Assert
(Is_Subprogram
(E
));
9557 -- Cases where no check can be performed:
9558 -- 1) When expansion is not active (since we never generate extra
9559 -- formals if expansion is not active because we don't need them
9560 -- unless we are generating code).
9561 -- 2) On abstract predefined dispatching operations of Root_Controlled
9562 -- and predefined stream operations not emitted by the frontend.
9563 -- 3) On renamings of abstract predefined dispatching operations of
9564 -- interface types (since limitedness is not inherited in such
9566 -- 4) The controlling formal of the nondispatching subprogram of
9567 -- a concurrent type that overrides an interface primitive is
9568 -- implicit and hence we cannot check here if all its extra
9569 -- formals match; the expander will create the dispatching
9570 -- primitive (without Convention_Protected) with the matching
9571 -- formals (see exp_ch9.Build_Wrapper_Specs) which will be
9574 if Debug_Flag_Underscore_XX
9575 or else not Expander_Active
9577 (Is_Predefined_Dispatching_Operation
(E
)
9578 and then (not Has_Reliable_Extra_Formals
(E
)
9579 or else not Has_Reliable_Extra_Formals
(Ref_E
)))
9581 (Is_Predefined_Dispatching_Operation
(E
)
9582 and then Is_Abstract_Subprogram
(E
)
9583 and then Is_Interface
(Find_Dispatching_Type
(Ref_E
)))
9587 elsif Convention
(E
) = Convention_Protected
9588 and then not Is_Dispatching_Operation
(E
)
9589 and then Is_Abstract_Subprogram
(Ref_E
)
9590 and then Is_Interface
(Find_Dispatching_Type
(Ref_E
))
9595 -- Perform the checks
9597 if No
(Extra_Formals
(E
)) then
9598 return No
(Extra_Formals
(Ref_E
));
9601 if Ekind
(E
) in E_Function | E_Subprogram_Type
9602 and then Present
(Extra_Accessibility_Of_Result
(E
))
9603 /= Present
(Extra_Accessibility_Of_Result
(Ref_E
))
9609 Formal_1
: Entity_Id
:= Extra_Formals
(E
);
9610 Formal_2
: Entity_Id
:= Extra_Formals
(Ref_E
);
9613 while Present
(Formal_1
) and then Present
(Formal_2
) loop
9614 if Has_Suffix
(Formal_1
, 'L') then
9615 if not Has_Suffix
(Formal_2
, 'L') then
9619 elsif Has_Suffix
(Formal_1
, 'O') then
9620 if not Has_Suffix
(Formal_2
, 'O') then
9624 elsif BIP_Suffix_Kind
(Formal_1
) /= BIP_Suffix_Kind
(Formal_2
) then
9628 Formal_1
:= Next_Formal_With_Extras
(Formal_1
);
9629 Formal_2
:= Next_Formal_With_Extras
(Formal_2
);
9632 return No
(Formal_1
) and then No
(Formal_2
);
9634 end Extra_Formals_Match_OK
;
9636 ----------------------
9637 -- Extra_Formals_OK --
9638 ----------------------
9640 function Extra_Formals_OK
(E
: Entity_Id
) return Boolean is
9641 Last_Formal
: Entity_Id
:= Empty
;
9643 Has_Extra_Formals
: Boolean := False;
9646 -- No check required if explicitly disabled
9648 if Debug_Flag_Underscore_XX
then
9651 -- No check required if expansion is disabled because extra
9652 -- formals are only generated when we are generating code.
9653 -- See Create_Extra_Formals.
9655 elsif not Expander_Active
then
9659 -- Check attribute Extra_Formal: If available, it must be set only
9660 -- on the last formal of E.
9662 Formal
:= First_Formal
(E
);
9663 while Present
(Formal
) loop
9664 if Present
(Extra_Formal
(Formal
)) then
9665 if Has_Extra_Formals
then
9669 Has_Extra_Formals
:= True;
9672 Last_Formal
:= Formal
;
9673 Next_Formal
(Formal
);
9676 -- Check attribute Extra_Accessibility_Of_Result
9678 if Ekind
(E
) in E_Function | E_Subprogram_Type
9679 and then Needs_Result_Accessibility_Level
(E
)
9680 and then No
(Extra_Accessibility_Of_Result
(E
))
9685 -- Check attribute Extra_Formals: If E has extra formals, then this
9686 -- attribute must point to the first extra formal of E.
9688 if Has_Extra_Formals
then
9689 return Present
(Extra_Formals
(E
))
9690 and then Present
(Extra_Formal
(Last_Formal
))
9691 and then Extra_Formal
(Last_Formal
) = Extra_Formals
(E
);
9693 -- When E has no formals, the first extra formal is available through
9694 -- the Extra_Formals attribute.
9696 elsif Present
(Extra_Formals
(E
)) then
9697 return No
(First_Formal
(E
));
9702 end Extra_Formals_OK
;
9704 -----------------------------
9705 -- Find_Corresponding_Spec --
9706 -----------------------------
9708 function Find_Corresponding_Spec
9710 Post_Error
: Boolean := True) return Entity_Id
9712 Spec
: constant Node_Id
:= Specification
(N
);
9713 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
9717 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean;
9718 -- Even if fully conformant, a body may depend on a generic actual when
9719 -- the spec does not, or vice versa, in which case they were distinct
9720 -- entities in the generic.
9722 -------------------------------
9723 -- Different_Generic_Profile --
9724 -------------------------------
9726 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean is
9729 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean;
9730 -- Check that the types of corresponding formals have the same
9731 -- generic actual if any. We have to account for subtypes of a
9732 -- generic formal, declared between a spec and a body, which may
9733 -- appear distinct in an instance but matched in the generic, and
9734 -- the subtype may be used either in the spec or the body of the
9735 -- subprogram being checked.
9737 -------------------------
9738 -- Same_Generic_Actual --
9739 -------------------------
9741 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean is
9743 function Is_Declared_Subtype
(S1
, S2
: Entity_Id
) return Boolean;
9744 -- Predicate to check whether S1 is a subtype of S2 in the source
9747 -------------------------
9748 -- Is_Declared_Subtype --
9749 -------------------------
9751 function Is_Declared_Subtype
(S1
, S2
: Entity_Id
) return Boolean is
9753 return Comes_From_Source
(Parent
(S1
))
9754 and then Nkind
(Parent
(S1
)) = N_Subtype_Declaration
9755 and then Is_Entity_Name
(Subtype_Indication
(Parent
(S1
)))
9756 and then Entity
(Subtype_Indication
(Parent
(S1
))) = S2
;
9757 end Is_Declared_Subtype
;
9759 -- Start of processing for Same_Generic_Actual
9762 return Is_Generic_Actual_Type
(T1
) = Is_Generic_Actual_Type
(T2
)
9763 or else Is_Declared_Subtype
(T1
, T2
)
9764 or else Is_Declared_Subtype
(T2
, T1
);
9765 end Same_Generic_Actual
;
9767 -- Start of processing for Different_Generic_Profile
9770 if not In_Instance
then
9773 elsif Ekind
(E
) = E_Function
9774 and then not Same_Generic_Actual
(Etype
(E
), Etype
(Designator
))
9779 F1
:= First_Formal
(Designator
);
9780 F2
:= First_Formal
(E
);
9781 while Present
(F1
) loop
9782 if not Same_Generic_Actual
(Etype
(F1
), Etype
(F2
)) then
9791 end Different_Generic_Profile
;
9793 -- Start of processing for Find_Corresponding_Spec
9796 E
:= Current_Entity
(Designator
);
9797 while Present
(E
) loop
9799 -- We are looking for a matching spec. It must have the same scope,
9800 -- and the same name, and either be type conformant, or be the case
9801 -- of a library procedure spec and its body (which belong to one
9802 -- another regardless of whether they are type conformant or not).
9804 if Scope
(E
) = Current_Scope
then
9805 if Current_Scope
= Standard_Standard
9806 or else (Ekind
(E
) = Ekind
(Designator
)
9807 and then Type_Conformant
(E
, Designator
))
9809 -- Within an instantiation, we know that spec and body are
9810 -- subtype conformant, because they were subtype conformant in
9811 -- the generic. We choose the subtype-conformant entity here as
9812 -- well, to resolve spurious ambiguities in the instance that
9813 -- were not present in the generic (i.e. when two different
9814 -- types are given the same actual). If we are looking for a
9815 -- spec to match a body, full conformance is expected.
9819 -- Inherit the convention and "ghostness" of the matching
9820 -- spec to ensure proper full and subtype conformance.
9822 Set_Convention
(Designator
, Convention
(E
));
9824 -- Skip past subprogram bodies and subprogram renamings that
9825 -- may appear to have a matching spec, but that aren't fully
9826 -- conformant with it. That can occur in cases where an
9827 -- actual type causes unrelated homographs in the instance.
9829 if Nkind
(N
) in N_Subprogram_Body
9830 | N_Subprogram_Renaming_Declaration
9831 and then Present
(Homonym
(E
))
9832 and then not Fully_Conformant
(Designator
, E
)
9836 elsif not Subtype_Conformant
(Designator
, E
) then
9839 elsif Different_Generic_Profile
(E
) then
9844 -- Ada 2012 (AI05-0165): For internally generated bodies of
9845 -- null procedures locate the internally generated spec. We
9846 -- enforce mode conformance since a tagged type may inherit
9847 -- from interfaces several null primitives which differ only
9848 -- in the mode of the formals.
9850 if not (Comes_From_Source
(E
))
9851 and then Is_Null_Procedure
(E
)
9852 and then not Mode_Conformant
(Designator
, E
)
9856 -- For null procedures coming from source that are completions,
9857 -- analysis of the generated body will establish the link.
9859 elsif Comes_From_Source
(E
)
9860 and then Nkind
(Spec
) = N_Procedure_Specification
9861 and then Null_Present
(Spec
)
9865 -- Expression functions can be completions, but cannot be
9866 -- completed by an explicit body.
9868 elsif Comes_From_Source
(E
)
9869 and then Comes_From_Source
(N
)
9870 and then Nkind
(N
) = N_Subprogram_Body
9871 and then Nkind
(Original_Node
(Unit_Declaration_Node
(E
))) =
9872 N_Expression_Function
9874 Error_Msg_Sloc
:= Sloc
(E
);
9875 Error_Msg_N
("body conflicts with expression function#", N
);
9878 elsif not Has_Completion
(E
) then
9879 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
9880 Set_Corresponding_Spec
(N
, E
);
9883 Set_Has_Completion
(E
);
9886 elsif Nkind
(Parent
(N
)) = N_Subunit
then
9888 -- If this is the proper body of a subunit, the completion
9889 -- flag is set when analyzing the stub.
9893 -- If E is an internal function with a controlling result that
9894 -- was created for an operation inherited by a null extension,
9895 -- it may be overridden by a body without a previous spec (one
9896 -- more reason why these should be shunned). In that case we
9897 -- remove the generated body if present, because the current
9898 -- one is the explicit overriding.
9900 elsif Ekind
(E
) = E_Function
9901 and then Ada_Version
>= Ada_2005
9902 and then not Comes_From_Source
(E
)
9903 and then Has_Controlling_Result
(E
)
9904 and then (not Is_Class_Wide_Type
(Etype
(E
))
9905 and then Is_Null_Extension
(Etype
(E
)))
9906 and then Comes_From_Source
(Spec
)
9908 Set_Has_Completion
(E
, False);
9911 and then Nkind
(Parent
(E
)) = N_Function_Specification
9914 (Unit_Declaration_Node
9915 (Corresponding_Body
(Unit_Declaration_Node
(E
))));
9919 -- If expansion is disabled, or if the wrapper function has
9920 -- not been generated yet, this a late body overriding an
9921 -- inherited operation, or it is an overriding by some other
9922 -- declaration before the controlling result is frozen. In
9923 -- either case this is a declaration of a new entity.
9929 -- If the body already exists, then this is an error unless
9930 -- the previous declaration is the implicit declaration of a
9931 -- derived subprogram. It is also legal for an instance to
9932 -- contain type conformant overloadable declarations (but the
9933 -- generic declaration may not), per 8.3(26/2).
9935 elsif No
(Alias
(E
))
9936 and then not Is_Intrinsic_Subprogram
(E
)
9937 and then not In_Instance
9940 Error_Msg_Sloc
:= Sloc
(E
);
9942 if Is_Imported
(E
) then
9944 ("body not allowed for imported subprogram & declared#",
9947 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
9951 -- Child units cannot be overloaded, so a conformance mismatch
9952 -- between body and a previous spec is an error.
9954 elsif Is_Child_Unit
(E
)
9956 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
9958 Nkind
(Parent
(Unit_Declaration_Node
(Designator
))) =
9963 ("body of child unit does not match previous declaration", N
);
9971 -- On exit, we know that no previous declaration of subprogram exists
9974 end Find_Corresponding_Spec
;
9976 ----------------------
9977 -- Fully_Conformant --
9978 ----------------------
9980 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
9983 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
9985 end Fully_Conformant
;
9987 ----------------------------------
9988 -- Fully_Conformant_Expressions --
9989 ----------------------------------
9991 function Fully_Conformant_Expressions
9992 (Given_E1
: Node_Id
;
9994 Report
: Boolean := False) return Boolean
9996 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
9997 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
9998 -- We always test conformance on original nodes, since it is possible
9999 -- for analysis and/or expansion to make things look as though they
10000 -- conform when they do not, e.g. by converting 1+2 into 3.
10002 function FCE
(Given_E1
: Node_Id
; Given_E2
: Node_Id
) return Boolean;
10003 -- Convenience function to abbreviate recursive calls to
10004 -- Fully_Conformant_Expressions without having to pass Report.
10006 function FCL
(L1
: List_Id
; L2
: List_Id
) return Boolean;
10007 -- Compare elements of two lists for conformance. Elements have to be
10008 -- conformant, and actuals inserted as default parameters do not match
10009 -- explicit actuals with the same value.
10011 function FCO
(Op_Node
: Node_Id
; Call_Node
: Node_Id
) return Boolean;
10012 -- Compare an operator node with a function call
10018 function FCE
(Given_E1
: Node_Id
; Given_E2
: Node_Id
) return Boolean is
10020 return Fully_Conformant_Expressions
(Given_E1
, Given_E2
, Report
);
10027 function FCL
(L1
: List_Id
; L2
: List_Id
) return Boolean is
10035 -- Compare two lists, skipping rewrite insertions (we want to compare
10036 -- the original trees, not the expanded versions).
10039 if Is_Rewrite_Insertion
(N1
) then
10041 elsif Is_Rewrite_Insertion
(N2
) then
10047 elsif not FCE
(N1
, N2
) then
10060 function FCO
(Op_Node
: Node_Id
; Call_Node
: Node_Id
) return Boolean is
10061 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
10066 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
10071 Act
:= First
(Actuals
);
10073 if Nkind
(Op_Node
) in N_Binary_Op
then
10074 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
10081 return Present
(Act
)
10082 and then FCE
(Right_Opnd
(Op_Node
), Act
)
10083 and then No
(Next
(Act
));
10087 function User_Defined_Numeric_Literal_Mismatch
return Boolean;
10088 -- Usually literals with the same value like 12345 and 12_345
10089 -- or 123.0 and 123.00 conform, but not if they are
10090 -- user-defined literals.
10092 -------------------------------------------
10093 -- User_Defined_Numeric_Literal_Mismatch --
10094 -------------------------------------------
10096 function User_Defined_Numeric_Literal_Mismatch
return Boolean is
10097 E1_Is_User_Defined
: constant Boolean :=
10098 Nkind
(Given_E1
) not in N_Integer_Literal | N_Real_Literal
;
10099 E2_Is_User_Defined
: constant Boolean :=
10100 Nkind
(Given_E2
) not in N_Integer_Literal | N_Real_Literal
;
10103 pragma Assert
(E1_Is_User_Defined
= E2_Is_User_Defined
);
10105 return E1_Is_User_Defined
and then
10106 not String_Equal
(String_From_Numeric_Literal
(E1
),
10107 String_From_Numeric_Literal
(E2
));
10108 end User_Defined_Numeric_Literal_Mismatch
;
10114 -- Start of processing for Fully_Conformant_Expressions
10119 -- Nonconformant if paren count does not match. Note: if some idiot
10120 -- complains that we don't do this right for more than 3 levels of
10121 -- parentheses, they will be treated with the respect they deserve.
10123 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
10126 -- If same entities are referenced, then they are conformant even if
10127 -- they have different forms (RM 8.3.1(19-20)).
10129 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
10130 if Present
(Entity
(E1
)) then
10131 Result
:= Entity
(E1
) = Entity
(E2
)
10133 -- One may be a discriminant that has been replaced by the
10134 -- corresponding discriminal.
10137 (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
10138 and then Ekind
(Entity
(E1
)) = E_Discriminant
10139 and then Ekind
(Entity
(E2
)) = E_In_Parameter
)
10141 -- The discriminant of a protected type is transformed into
10142 -- a local constant and then into a parameter of a protected
10146 (Ekind
(Entity
(E1
)) = E_Constant
10147 and then Ekind
(Entity
(E2
)) = E_In_Parameter
10148 and then Present
(Discriminal_Link
(Entity
(E1
)))
10149 and then Discriminal_Link
(Entity
(E1
)) =
10150 Discriminal_Link
(Entity
(E2
)))
10152 -- AI12-050: The entities of quantified expressions match if they
10153 -- have the same identifier, even if they may be distinct nodes.
10156 (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
10157 and then Is_Entity_Of_Quantified_Expression
(Entity
(E1
))
10158 and then Is_Entity_Of_Quantified_Expression
(Entity
(E2
)))
10160 -- A call to an instantiation of Unchecked_Conversion is
10161 -- rewritten with the name of the generated function created for
10162 -- the instance, and this must be special-cased.
10165 (Ekind
(Entity
(E1
)) = E_Function
10166 and then Is_Intrinsic_Subprogram
(Entity
(E1
))
10167 and then Is_Generic_Instance
(Entity
(E1
))
10168 and then Entity
(E2
) = Alias
(Entity
(E1
)));
10169 if Report
and not Result
then
10171 Text_Ptr
'Max (Sloc
(Entity
(E1
)), Sloc
(Entity
(E2
)));
10173 ("meaning of& differs because of declaration#", E1
, E2
);
10178 elsif Nkind
(E1
) = N_Expanded_Name
10179 and then Nkind
(E2
) = N_Expanded_Name
10180 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
10181 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
10183 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
10186 -- Identifiers in component associations don't always have
10187 -- entities, but their names must conform.
10189 return Nkind
(E1
) = N_Identifier
10190 and then Nkind
(E2
) = N_Identifier
10191 and then Chars
(E1
) = Chars
(E2
);
10194 elsif Nkind
(E1
) = N_Character_Literal
10195 and then Nkind
(E2
) = N_Expanded_Name
10197 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
10198 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
10200 elsif Nkind
(E2
) = N_Character_Literal
10201 and then Nkind
(E1
) = N_Expanded_Name
10203 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
10204 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
10206 elsif Nkind
(E1
) in N_Op
and then Nkind
(E2
) = N_Function_Call
then
10207 return FCO
(E1
, E2
);
10209 elsif Nkind
(E2
) in N_Op
and then Nkind
(E1
) = N_Function_Call
then
10210 return FCO
(E2
, E1
);
10212 -- Otherwise we must have the same syntactic entity
10214 elsif Nkind
(E1
) /= Nkind
(E2
) then
10217 -- At this point, we specialize by node type
10221 when N_Aggregate
=>
10223 FCL
(Expressions
(E1
), Expressions
(E2
))
10225 FCL
(Component_Associations
(E1
),
10226 Component_Associations
(E2
));
10228 when N_Allocator
=>
10229 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
10231 Nkind
(Expression
(E2
)) = N_Qualified_Expression
10233 return FCE
(Expression
(E1
), Expression
(E2
));
10235 -- Check that the subtype marks and any constraints
10240 Indic1
: constant Node_Id
:= Expression
(E1
);
10241 Indic2
: constant Node_Id
:= Expression
(E2
);
10246 if Nkind
(Indic1
) /= N_Subtype_Indication
then
10248 Nkind
(Indic2
) /= N_Subtype_Indication
10249 and then Entity
(Indic1
) = Entity
(Indic2
);
10251 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
10253 Nkind
(Indic1
) /= N_Subtype_Indication
10254 and then Entity
(Indic1
) = Entity
(Indic2
);
10257 if Entity
(Subtype_Mark
(Indic1
)) /=
10258 Entity
(Subtype_Mark
(Indic2
))
10263 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
10264 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
10265 while Present
(Elt1
) and then Present
(Elt2
) loop
10266 if not FCE
(Elt1
, Elt2
) then
10279 when N_Attribute_Reference
=>
10281 Attribute_Name
(E1
) = Attribute_Name
(E2
)
10282 and then FCL
(Expressions
(E1
), Expressions
(E2
));
10284 when N_Binary_Op
=>
10286 Entity
(E1
) = Entity
(E2
)
10287 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
10288 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
10290 when N_Membership_Test
10294 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
10296 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
10298 when N_Case_Expression
=>
10304 if not FCE
(Expression
(E1
), Expression
(E2
)) then
10308 Alt1
:= First
(Alternatives
(E1
));
10309 Alt2
:= First
(Alternatives
(E2
));
10311 if Present
(Alt1
) /= Present
(Alt2
) then
10313 elsif No
(Alt1
) then
10317 if not FCE
(Expression
(Alt1
), Expression
(Alt2
))
10318 or else not FCL
(Discrete_Choices
(Alt1
),
10319 Discrete_Choices
(Alt2
))
10330 when N_Character_Literal
=>
10332 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
10334 when N_Component_Association
=>
10336 FCL
(Choices
(E1
), Choices
(E2
))
10338 FCE
(Expression
(E1
), Expression
(E2
));
10340 when N_Explicit_Dereference
=>
10342 FCE
(Prefix
(E1
), Prefix
(E2
));
10344 when N_Extension_Aggregate
=>
10346 FCL
(Expressions
(E1
), Expressions
(E2
))
10347 and then Null_Record_Present
(E1
) =
10348 Null_Record_Present
(E2
)
10349 and then FCL
(Component_Associations
(E1
),
10350 Component_Associations
(E2
));
10352 when N_Function_Call
=>
10354 FCE
(Name
(E1
), Name
(E2
))
10356 FCL
(Parameter_Associations
(E1
),
10357 Parameter_Associations
(E2
));
10359 when N_If_Expression
=>
10361 FCL
(Expressions
(E1
), Expressions
(E2
));
10363 when N_Indexed_Component
=>
10365 FCE
(Prefix
(E1
), Prefix
(E2
))
10367 FCL
(Expressions
(E1
), Expressions
(E2
));
10369 when N_Integer_Literal
=>
10370 return Intval
(E1
) = Intval
(E2
)
10371 and then not User_Defined_Numeric_Literal_Mismatch
;
10376 when N_Operator_Symbol
=>
10378 Chars
(E1
) = Chars
(E2
);
10380 when N_Others_Choice
=>
10383 when N_Parameter_Association
=>
10385 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
10386 and then FCE
(Explicit_Actual_Parameter
(E1
),
10387 Explicit_Actual_Parameter
(E2
));
10389 when N_Qualified_Expression
10390 | N_Type_Conversion
10391 | N_Unchecked_Type_Conversion
10394 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
10396 FCE
(Expression
(E1
), Expression
(E2
));
10398 when N_Quantified_Expression
=>
10399 if not FCE
(Condition
(E1
), Condition
(E2
)) then
10403 if Present
(Loop_Parameter_Specification
(E1
))
10404 and then Present
(Loop_Parameter_Specification
(E2
))
10407 L1
: constant Node_Id
:=
10408 Loop_Parameter_Specification
(E1
);
10409 L2
: constant Node_Id
:=
10410 Loop_Parameter_Specification
(E2
);
10414 Reverse_Present
(L1
) = Reverse_Present
(L2
)
10416 FCE
(Defining_Identifier
(L1
),
10417 Defining_Identifier
(L2
))
10419 FCE
(Discrete_Subtype_Definition
(L1
),
10420 Discrete_Subtype_Definition
(L2
));
10423 elsif Present
(Iterator_Specification
(E1
))
10424 and then Present
(Iterator_Specification
(E2
))
10427 I1
: constant Node_Id
:= Iterator_Specification
(E1
);
10428 I2
: constant Node_Id
:= Iterator_Specification
(E2
);
10432 FCE
(Defining_Identifier
(I1
),
10433 Defining_Identifier
(I2
))
10435 Of_Present
(I1
) = Of_Present
(I2
)
10437 Reverse_Present
(I1
) = Reverse_Present
(I2
)
10438 and then FCE
(Name
(I1
), Name
(I2
))
10439 and then FCE
(Subtype_Indication
(I1
),
10440 Subtype_Indication
(I2
));
10443 -- The quantified expressions used different specifications to
10444 -- walk their respective ranges.
10452 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
10454 FCE
(High_Bound
(E1
), High_Bound
(E2
));
10456 when N_Real_Literal
=>
10457 return Realval
(E1
) = Realval
(E2
)
10458 and then not User_Defined_Numeric_Literal_Mismatch
;
10460 when N_Selected_Component
=>
10462 FCE
(Prefix
(E1
), Prefix
(E2
))
10464 FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
10468 FCE
(Prefix
(E1
), Prefix
(E2
))
10470 FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
10472 when N_String_Literal
=>
10474 S1
: constant String_Id
:= Strval
(E1
);
10475 S2
: constant String_Id
:= Strval
(E2
);
10476 L1
: constant Nat
:= String_Length
(S1
);
10477 L2
: constant Nat
:= String_Length
(S2
);
10484 for J
in 1 .. L1
loop
10485 if Get_String_Char
(S1
, J
) /=
10486 Get_String_Char
(S2
, J
)
10498 Entity
(E1
) = Entity
(E2
)
10500 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
10502 -- All other node types cannot appear in this context. Strictly
10503 -- we should raise a fatal internal error. Instead we just ignore
10504 -- the nodes. This means that if anyone makes a mistake in the
10505 -- expander and mucks an expression tree irretrievably, the result
10506 -- will be a failure to detect a (probably very obscure) case
10507 -- of non-conformance, which is better than bombing on some
10508 -- case where two expressions do in fact conform.
10514 end Fully_Conformant_Expressions
;
10516 ----------------------------------------
10517 -- Fully_Conformant_Discrete_Subtypes --
10518 ----------------------------------------
10520 function Fully_Conformant_Discrete_Subtypes
10521 (Given_S1
: Node_Id
;
10522 Given_S2
: Node_Id
) return Boolean
10524 S1
: constant Node_Id
:= Original_Node
(Given_S1
);
10525 S2
: constant Node_Id
:= Original_Node
(Given_S2
);
10527 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean;
10528 -- Special-case for a bound given by a discriminant, which in the body
10529 -- is replaced with the discriminal of the enclosing type.
10531 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean;
10532 -- Check both bounds
10534 -----------------------
10535 -- Conforming_Bounds --
10536 -----------------------
10538 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean is
10540 if Is_Entity_Name
(B1
)
10541 and then Is_Entity_Name
(B2
)
10542 and then Ekind
(Entity
(B1
)) = E_Discriminant
10544 return Chars
(B1
) = Chars
(B2
);
10547 return Fully_Conformant_Expressions
(B1
, B2
);
10549 end Conforming_Bounds
;
10551 -----------------------
10552 -- Conforming_Ranges --
10553 -----------------------
10555 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean is
10558 Conforming_Bounds
(Low_Bound
(R1
), Low_Bound
(R2
))
10560 Conforming_Bounds
(High_Bound
(R1
), High_Bound
(R2
));
10561 end Conforming_Ranges
;
10563 -- Start of processing for Fully_Conformant_Discrete_Subtypes
10566 if Nkind
(S1
) /= Nkind
(S2
) then
10569 elsif Is_Entity_Name
(S1
) then
10570 return Entity
(S1
) = Entity
(S2
);
10572 elsif Nkind
(S1
) = N_Range
then
10573 return Conforming_Ranges
(S1
, S2
);
10575 elsif Nkind
(S1
) = N_Subtype_Indication
then
10577 Entity
(Subtype_Mark
(S1
)) = Entity
(Subtype_Mark
(S2
))
10580 (Range_Expression
(Constraint
(S1
)),
10581 Range_Expression
(Constraint
(S2
)));
10585 end Fully_Conformant_Discrete_Subtypes
;
10587 ---------------------
10588 -- Has_BIP_Formals --
10589 ---------------------
10591 function Has_BIP_Formals
(E
: Entity_Id
) return Boolean is
10592 Formal
: Entity_Id
:= First_Formal_With_Extras
(E
);
10595 while Present
(Formal
) loop
10596 if Is_Build_In_Place_Entity
(Formal
) then
10600 Next_Formal_With_Extras
(Formal
);
10604 end Has_BIP_Formals
;
10606 --------------------------------
10607 -- Has_Reliable_Extra_Formals --
10608 --------------------------------
10610 function Has_Reliable_Extra_Formals
(E
: Entity_Id
) return Boolean is
10611 Alias_E
: Entity_Id
;
10614 -- Extra formals are not added if expansion is not active (and hence if
10615 -- available they are not reliable for extra formals check).
10617 if not Expander_Active
then
10620 -- Currently the unique cases where extra formals are not reliable
10621 -- are associated with predefined dispatching operations; otherwise
10622 -- they are properly added when required.
10624 elsif not Is_Predefined_Dispatching_Operation
(E
) then
10628 Alias_E
:= Ultimate_Alias
(E
);
10630 -- Abstract predefined primitives of Root_Controlled don't have
10631 -- extra formals; this is required to build the runtime.
10633 if Ekind
(Alias_E
) = E_Function
10634 and then Is_Abstract_Subprogram
(Alias_E
)
10635 and then Is_RTE
(Underlying_Type
(Etype
(Alias_E
)),
10636 RE_Root_Controlled
)
10640 -- Predefined stream dispatching operations that are not emitted by
10641 -- the frontend; they have a renaming of the corresponding primitive
10642 -- of their parent type and hence they don't have extra formals.
10646 Typ
: constant Entity_Id
:=
10647 Underlying_Type
(Find_Dispatching_Type
(Alias_E
));
10650 if (Get_TSS_Name
(E
) = TSS_Stream_Input
10651 and then not Stream_Operation_OK
(Typ
, TSS_Stream_Input
))
10653 (Get_TSS_Name
(E
) = TSS_Stream_Output
10654 and then not Stream_Operation_OK
(Typ
, TSS_Stream_Output
))
10656 (Get_TSS_Name
(E
) = TSS_Stream_Read
10657 and then not Stream_Operation_OK
(Typ
, TSS_Stream_Read
))
10659 (Get_TSS_Name
(E
) = TSS_Stream_Write
10660 and then not Stream_Operation_OK
(Typ
, TSS_Stream_Write
))
10668 end Has_Reliable_Extra_Formals
;
10670 --------------------
10671 -- Install_Entity --
10672 --------------------
10674 procedure Install_Entity
(E
: Entity_Id
) is
10675 Prev
: constant Entity_Id
:= Current_Entity
(E
);
10677 Set_Is_Immediately_Visible
(E
);
10678 Set_Current_Entity
(E
);
10679 pragma Assert
(Prev
/= E
);
10680 Set_Homonym
(E
, Prev
);
10681 end Install_Entity
;
10683 ---------------------
10684 -- Install_Formals --
10685 ---------------------
10687 procedure Install_Formals
(Id
: Entity_Id
) is
10690 F
:= First_Formal
(Id
);
10691 while Present
(F
) loop
10692 Install_Entity
(F
);
10695 end Install_Formals
;
10697 -----------------------------
10698 -- Is_Interface_Conformant --
10699 -----------------------------
10701 function Is_Interface_Conformant
10702 (Tagged_Type
: Entity_Id
;
10703 Iface_Prim
: Entity_Id
;
10704 Prim
: Entity_Id
) return Boolean
10706 -- The operation may in fact be an inherited (implicit) operation
10707 -- rather than the original interface primitive, so retrieve the
10708 -- ultimate ancestor.
10710 Iface
: constant Entity_Id
:=
10711 Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
));
10712 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Prim
);
10714 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
;
10715 -- Return the controlling formal of Prim
10717 ------------------------
10718 -- Controlling_Formal --
10719 ------------------------
10721 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
is
10725 E
:= First_Formal
(Prim
);
10726 while Present
(E
) loop
10727 if Is_Controlling_Formal
(E
) then
10735 end Controlling_Formal
;
10739 Iface_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Iface_Prim
);
10740 Prim_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Prim
);
10742 -- Start of processing for Is_Interface_Conformant
10745 pragma Assert
(Is_Subprogram
(Iface_Prim
)
10746 and then Is_Subprogram
(Prim
)
10747 and then Is_Dispatching_Operation
(Iface_Prim
)
10748 and then Is_Dispatching_Operation
(Prim
));
10750 pragma Assert
(Is_Interface
(Iface
)
10751 or else (Present
(Alias
(Iface_Prim
))
10754 (Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
)))));
10756 if Prim
= Iface_Prim
10757 or else not Is_Subprogram
(Prim
)
10758 or else Ekind
(Prim
) /= Ekind
(Iface_Prim
)
10759 or else not Is_Dispatching_Operation
(Prim
)
10760 or else Scope
(Prim
) /= Scope
(Tagged_Type
)
10762 or else Base_Type
(Typ
) /= Base_Type
(Tagged_Type
)
10763 or else not Primitive_Names_Match
(Iface_Prim
, Prim
)
10767 -- The mode of the controlling formals must match
10769 elsif Present
(Iface_Ctrl_F
)
10770 and then Present
(Prim_Ctrl_F
)
10771 and then Ekind
(Iface_Ctrl_F
) /= Ekind
(Prim_Ctrl_F
)
10775 -- Case of a procedure, or a function whose result type matches the
10776 -- result type of the interface primitive, or a function that has no
10777 -- controlling result (I or access I).
10779 elsif Ekind
(Iface_Prim
) = E_Procedure
10780 or else Etype
(Prim
) = Etype
(Iface_Prim
)
10781 or else not Has_Controlling_Result
(Prim
)
10783 return Type_Conformant
10784 (Iface_Prim
, Prim
, Skip_Controlling_Formals
=> True);
10786 -- Case of a function returning an interface, or an access to one. Check
10787 -- that the return types correspond.
10789 elsif Implements_Interface
(Typ
, Iface
) then
10790 if (Ekind
(Etype
(Prim
)) = E_Anonymous_Access_Type
)
10792 (Ekind
(Etype
(Iface_Prim
)) = E_Anonymous_Access_Type
)
10797 Type_Conformant
(Prim
, Ultimate_Alias
(Iface_Prim
),
10798 Skip_Controlling_Formals
=> True);
10804 end Is_Interface_Conformant
;
10806 ---------------------------------
10807 -- Is_Non_Overriding_Operation --
10808 ---------------------------------
10810 function Is_Non_Overriding_Operation
10811 (Prev_E
: Entity_Id
;
10812 New_E
: Entity_Id
) return Boolean
10814 Formal
: Entity_Id
;
10816 G_Typ
: Entity_Id
:= Empty
;
10818 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
10819 -- If F_Type is a derived type associated with a generic actual subtype,
10820 -- then return its Generic_Parent_Type attribute, else return Empty.
10822 function Types_Correspond
10823 (P_Type
: Entity_Id
;
10824 N_Type
: Entity_Id
) return Boolean;
10825 -- Returns true if and only if the types (or designated types in the
10826 -- case of anonymous access types) are the same or N_Type is derived
10827 -- directly or indirectly from P_Type.
10829 -----------------------------
10830 -- Get_Generic_Parent_Type --
10831 -----------------------------
10833 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
10839 if Is_Derived_Type
(F_Typ
)
10840 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
10842 -- The tree must be traversed to determine the parent subtype in
10843 -- the generic unit, which unfortunately isn't always available
10844 -- via semantic attributes. ??? (Note: The use of Original_Node
10845 -- is needed for cases where a full derived type has been
10848 -- If the parent type is a scalar type, the derivation creates
10849 -- an anonymous base type for it, and the source type is its
10852 if Is_Scalar_Type
(F_Typ
)
10853 and then not Comes_From_Source
(F_Typ
)
10857 (Original_Node
(Parent
(First_Subtype
(F_Typ
))));
10859 Defn
:= Type_Definition
(Original_Node
(Parent
(F_Typ
)));
10861 if Nkind
(Defn
) = N_Derived_Type_Definition
then
10862 Indic
:= Subtype_Indication
(Defn
);
10864 if Nkind
(Indic
) = N_Subtype_Indication
then
10865 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
10867 G_Typ
:= Entity
(Indic
);
10870 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
10871 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
10873 return Generic_Parent_Type
(Parent
(G_Typ
));
10879 end Get_Generic_Parent_Type
;
10881 ----------------------
10882 -- Types_Correspond --
10883 ----------------------
10885 function Types_Correspond
10886 (P_Type
: Entity_Id
;
10887 N_Type
: Entity_Id
) return Boolean
10889 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
10890 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
10893 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
10894 Prev_Type
:= Designated_Type
(Prev_Type
);
10897 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
10898 New_Type
:= Designated_Type
(New_Type
);
10901 if Prev_Type
= New_Type
then
10904 elsif not Is_Class_Wide_Type
(New_Type
) then
10905 while Etype
(New_Type
) /= New_Type
loop
10906 New_Type
:= Etype
(New_Type
);
10908 if New_Type
= Prev_Type
then
10914 end Types_Correspond
;
10916 -- Start of processing for Is_Non_Overriding_Operation
10919 -- In the case where both operations are implicit derived subprograms
10920 -- then neither overrides the other. This can only occur in certain
10921 -- obscure cases (e.g., derivation from homographs created in a generic
10924 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
10927 elsif Ekind
(Current_Scope
) = E_Package
10928 and then Is_Generic_Instance
(Current_Scope
)
10929 and then In_Private_Part
(Current_Scope
)
10930 and then Comes_From_Source
(New_E
)
10932 -- We examine the formals and result type of the inherited operation,
10933 -- to determine whether their type is derived from (the instance of)
10934 -- a generic type. The first such formal or result type is the one
10937 Formal
:= First_Formal
(Prev_E
);
10939 while Present
(Formal
) loop
10940 F_Typ
:= Base_Type
(Etype
(Formal
));
10942 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
10943 F_Typ
:= Designated_Type
(F_Typ
);
10946 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
10947 exit when Present
(G_Typ
);
10949 Next_Formal
(Formal
);
10952 -- If the function dispatches on result check the result type
10954 if No
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
10955 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
10962 -- If the generic type is a private type, then the original operation
10963 -- was not overriding in the generic, because there was no primitive
10964 -- operation to override.
10966 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
10967 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
10968 N_Formal_Private_Type_Definition
10972 -- The generic parent type is the ancestor of a formal derived
10973 -- type declaration. We need to check whether it has a primitive
10974 -- operation that should be overridden by New_E in the generic.
10978 P_Formal
: Entity_Id
;
10979 N_Formal
: Entity_Id
;
10982 P_Prim
: Entity_Id
;
10983 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
10986 while Present
(Prim_Elt
) loop
10987 P_Prim
:= Node
(Prim_Elt
);
10989 if Chars
(P_Prim
) = Chars
(New_E
)
10990 and then Ekind
(P_Prim
) = Ekind
(New_E
)
10992 P_Formal
:= First_Formal
(P_Prim
);
10993 N_Formal
:= First_Formal
(New_E
);
10994 while Present
(P_Formal
) and then Present
(N_Formal
) loop
10995 P_Typ
:= Etype
(P_Formal
);
10996 N_Typ
:= Etype
(N_Formal
);
10998 if not Types_Correspond
(P_Typ
, N_Typ
) then
11002 Next_Formal
(P_Formal
);
11003 Next_Formal
(N_Formal
);
11006 -- Found a matching primitive operation belonging to the
11007 -- formal ancestor type, so the new subprogram is
11011 and then No
(N_Formal
)
11012 and then (Ekind
(New_E
) /= E_Function
11015 (Etype
(P_Prim
), Etype
(New_E
)))
11021 Next_Elmt
(Prim_Elt
);
11024 -- If no match found, then the new subprogram does not override
11025 -- in the generic (nor in the instance).
11027 -- If the type in question is not abstract, and the subprogram
11028 -- is, this will be an error if the new operation is in the
11029 -- private part of the instance. Emit a warning now, which will
11030 -- make the subsequent error message easier to understand.
11032 if Present
(F_Typ
) and then not Is_Abstract_Type
(F_Typ
)
11033 and then Is_Abstract_Subprogram
(Prev_E
)
11034 and then In_Private_Part
(Current_Scope
)
11036 Error_Msg_Node_2
:= F_Typ
;
11038 ("private operation& in generic unit does not override "
11039 & "any primitive operation of& (RM 12.3(18))??",
11049 end Is_Non_Overriding_Operation
;
11051 -------------------------------------
11052 -- List_Inherited_Pre_Post_Aspects --
11053 -------------------------------------
11055 procedure List_Inherited_Pre_Post_Aspects
(E
: Entity_Id
) is
11057 if List_Inherited_Aspects
11058 and then Is_Subprogram_Or_Generic_Subprogram
(E
)
11061 Subps
: constant Subprogram_List
:= Inherited_Subprograms
(E
);
11066 for Index
in Subps
'Range loop
11067 Items
:= Contract
(Subps
(Index
));
11069 if Present
(Items
) then
11070 Prag
:= Pre_Post_Conditions
(Items
);
11071 while Present
(Prag
) loop
11072 Error_Msg_Sloc
:= Sloc
(Prag
);
11074 if Class_Present
(Prag
)
11075 and then not Split_PPC
(Prag
)
11077 if Pragma_Name
(Prag
) = Name_Precondition
then
11079 ("info: & inherits `Pre''Class` aspect from "
11083 ("info: & inherits `Post''Class` aspect from "
11088 Prag
:= Next_Pragma
(Prag
);
11094 end List_Inherited_Pre_Post_Aspects
;
11096 ------------------------------
11097 -- Make_Inequality_Operator --
11098 ------------------------------
11100 -- S is the defining identifier of an equality operator. We build a
11101 -- subprogram declaration with the right signature. This operation is
11102 -- intrinsic, because it is always expanded as the negation of the
11103 -- call to the equality function.
11105 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
11106 Loc
: constant Source_Ptr
:= Sloc
(S
);
11109 Op_Name
: Entity_Id
;
11111 FF
: constant Entity_Id
:= First_Formal
(S
);
11112 NF
: constant Entity_Id
:= Next_Formal
(FF
);
11115 -- Check that equality was properly defined, ignore call if not
11122 A
: constant Entity_Id
:=
11123 Make_Defining_Identifier
(Sloc
(FF
),
11124 Chars
=> Chars
(FF
));
11126 B
: constant Entity_Id
:=
11127 Make_Defining_Identifier
(Sloc
(NF
),
11128 Chars
=> Chars
(NF
));
11131 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
11133 Formals
:= New_List
(
11134 Make_Parameter_Specification
(Loc
,
11135 Defining_Identifier
=> A
,
11137 New_Occurrence_Of
(Etype
(First_Formal
(S
)),
11138 Sloc
(Etype
(First_Formal
(S
))))),
11140 Make_Parameter_Specification
(Loc
,
11141 Defining_Identifier
=> B
,
11143 New_Occurrence_Of
(Etype
(Next_Formal
(First_Formal
(S
))),
11144 Sloc
(Etype
(Next_Formal
(First_Formal
(S
)))))));
11147 Make_Subprogram_Declaration
(Loc
,
11149 Make_Function_Specification
(Loc
,
11150 Defining_Unit_Name
=> Op_Name
,
11151 Parameter_Specifications
=> Formals
,
11152 Result_Definition
=>
11153 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
11155 -- Insert inequality right after equality if it is explicit or after
11156 -- the derived type when implicit. These entities are created only
11157 -- for visibility purposes, and eventually replaced in the course
11158 -- of expansion, so they do not need to be attached to the tree and
11159 -- seen by the back-end. Keeping them internal also avoids spurious
11160 -- freezing problems. The declaration is inserted in the tree for
11161 -- analysis, and removed afterwards. If the equality operator comes
11162 -- from an explicit declaration, attach the inequality immediately
11163 -- after. Else the equality is inherited from a derived type
11164 -- declaration, so insert inequality after that declaration.
11166 if No
(Alias
(S
)) then
11167 Insert_After
(Unit_Declaration_Node
(S
), Decl
);
11168 elsif Is_List_Member
(Parent
(S
)) then
11169 Insert_After
(Parent
(S
), Decl
);
11171 Insert_After
(Parent
(Etype
(First_Formal
(S
))), Decl
);
11174 Mark_Rewrite_Insertion
(Decl
);
11175 Set_Is_Intrinsic_Subprogram
(Op_Name
);
11178 Set_Has_Completion
(Op_Name
);
11179 Set_Corresponding_Equality
(Op_Name
, S
);
11180 Set_Is_Abstract_Subprogram
(Op_Name
, Is_Abstract_Subprogram
(S
));
11182 end Make_Inequality_Operator
;
11184 ----------------------
11185 -- May_Need_Actuals --
11186 ----------------------
11188 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
11193 F
:= First_Formal
(Fun
);
11195 while Present
(F
) loop
11196 if No
(Default_Value
(F
)) then
11204 Set_Needs_No_Actuals
(Fun
, B
);
11205 end May_Need_Actuals
;
11207 ---------------------
11208 -- Mode_Conformant --
11209 ---------------------
11211 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
11214 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
11216 end Mode_Conformant
;
11218 ---------------------------
11219 -- New_Overloaded_Entity --
11220 ---------------------------
11222 procedure New_Overloaded_Entity
11224 Derived_Type
: Entity_Id
:= Empty
)
11226 Overridden_Subp
: Entity_Id
:= Empty
;
11227 -- Set if the current scope has an operation that is type-conformant
11228 -- with S, and becomes hidden by S.
11230 Is_Primitive_Subp
: Boolean;
11231 -- Set to True if the new subprogram is primitive
11234 -- Entity that S overrides
11236 procedure Check_For_Primitive_Subprogram
11237 (Is_Primitive
: out Boolean;
11238 Is_Overriding
: Boolean := False);
11239 -- If the subprogram being analyzed is a primitive operation of the type
11240 -- of a formal or result, set the Has_Primitive_Operations flag on the
11241 -- type, and set Is_Primitive to True (otherwise set to False). Set the
11242 -- corresponding flag on the entity itself for later use.
11244 function Has_Matching_Entry_Or_Subprogram
(E
: Entity_Id
) return Boolean;
11245 -- True if a) E is a subprogram whose first formal is a concurrent type
11246 -- defined in the scope of E that has some entry or subprogram whose
11247 -- profile matches E, or b) E is an internally built dispatching
11248 -- subprogram of a protected type and there is a matching subprogram
11249 -- defined in the enclosing scope of the protected type, or c) E is
11250 -- an entry of a synchronized type and a matching procedure has been
11251 -- previously defined in the enclosing scope of the synchronized type.
11253 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
11254 -- Check that E is declared in the private part of the current package,
11255 -- or in the package body, where it may hide a previous declaration.
11256 -- We can't use In_Private_Part by itself because this flag is also
11257 -- set when freezing entities, so we must examine the place of the
11258 -- declaration in the tree, and recognize wrapper packages as well.
11260 function Is_Overriding_Alias
11261 (Old_E
: Entity_Id
;
11262 New_E
: Entity_Id
) return Boolean;
11263 -- Check whether new subprogram and old subprogram are both inherited
11264 -- from subprograms that have distinct dispatch table entries. This can
11265 -- occur with derivations from instances with accidental homonyms. The
11266 -- function is conservative given that the converse is only true within
11267 -- instances that contain accidental overloadings.
11269 procedure Report_Conflict
(S
: Entity_Id
; E
: Entity_Id
);
11270 -- Report conflict between entities S and E
11272 ------------------------------------
11273 -- Check_For_Primitive_Subprogram --
11274 ------------------------------------
11276 procedure Check_For_Primitive_Subprogram
11277 (Is_Primitive
: out Boolean;
11278 Is_Overriding
: Boolean := False)
11280 procedure Add_Or_Replace_Untagged_Primitive
(Typ
: Entity_Id
);
11281 -- Either add the new subprogram to the list of primitives for
11282 -- untagged type Typ, or if it overrides a primitive of Typ, then
11283 -- replace the overridden primitive in Typ's primitives list with
11284 -- the new subprogram.
11286 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
11287 -- Returns true if T is declared in the visible part of the current
11288 -- package scope; otherwise returns false. Assumes that T is declared
11291 procedure Check_Private_Overriding
(T
: Entity_Id
);
11292 -- Checks that if a primitive abstract subprogram of a visible
11293 -- abstract type is declared in a private part, then it must override
11294 -- an abstract subprogram declared in the visible part. Also checks
11295 -- that if a primitive function with a controlling result is declared
11296 -- in a private part, then it must override a function declared in
11297 -- the visible part.
11299 ---------------------------------------
11300 -- Add_Or_Replace_Untagged_Primitive --
11301 ---------------------------------------
11303 procedure Add_Or_Replace_Untagged_Primitive
(Typ
: Entity_Id
) is
11304 Replaced_Overridden_Subp
: Boolean := False;
11307 pragma Assert
(not Is_Tagged_Type
(Typ
));
11309 -- Anonymous access types don't have a primitives list. Normally
11310 -- such types wouldn't make it here, but the case of anonymous
11311 -- access-to-subprogram types can.
11313 if not Is_Anonymous_Access_Type
(Typ
) then
11315 -- If S overrides a subprogram that's a primitive of
11316 -- the formal's type, then replace the overridden
11317 -- subprogram with the new subprogram in the type's
11318 -- list of primitives.
11320 if Is_Overriding
then
11321 pragma Assert
(Present
(Overridden_Subp
)
11322 and then Overridden_Subp
= E
); -- Added for now
11325 Prim_Ops
: constant Elist_Id
:=
11326 Primitive_Operations
(Typ
);
11329 if Present
(Prim_Ops
) then
11330 Elmt
:= First_Elmt
(Prim_Ops
);
11332 while Present
(Elmt
)
11333 and then Node
(Elmt
) /= Overridden_Subp
11338 if Present
(Elmt
) then
11339 Replace_Elmt
(Elmt
, S
);
11340 Replaced_Overridden_Subp
:= True;
11346 -- If the new subprogram did not override an operation
11347 -- of the formal's type, then add it to the primitives
11348 -- list of the type.
11350 if not Replaced_Overridden_Subp
then
11351 Append_Unique_Elmt
(S
, Primitive_Operations
(Typ
));
11354 end Add_Or_Replace_Untagged_Primitive
;
11356 ------------------------------
11357 -- Check_Private_Overriding --
11358 ------------------------------
11360 procedure Check_Private_Overriding
(T
: Entity_Id
) is
11361 function Overrides_Private_Part_Op
return Boolean;
11362 -- This detects the special case where the overriding subprogram
11363 -- is overriding a subprogram that was declared in the same
11364 -- private part. That case is illegal by 3.9.3(10).
11366 function Overrides_Visible_Function
11367 (Partial_View
: Entity_Id
) return Boolean;
11368 -- True if S overrides a function in the visible part. The
11369 -- overridden function could be explicitly or implicitly declared.
11371 -------------------------------
11372 -- Overrides_Private_Part_Op --
11373 -------------------------------
11375 function Overrides_Private_Part_Op
return Boolean is
11376 Over_Decl
: constant Node_Id
:=
11377 Unit_Declaration_Node
11378 (Ultimate_Alias
(Overridden_Operation
(S
)));
11379 Subp_Decl
: constant Node_Id
:= Unit_Declaration_Node
(S
);
11382 pragma Assert
(Is_Overriding
);
11384 (Nkind
(Over_Decl
) = N_Abstract_Subprogram_Declaration
);
11386 (Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
);
11388 return In_Same_List
(Over_Decl
, Subp_Decl
);
11389 end Overrides_Private_Part_Op
;
11391 --------------------------------
11392 -- Overrides_Visible_Function --
11393 --------------------------------
11395 function Overrides_Visible_Function
11396 (Partial_View
: Entity_Id
) return Boolean
11399 if not Is_Overriding
or else not Has_Homonym
(S
) then
11403 if No
(Partial_View
) then
11407 -- Search through all the homonyms H of S in the current
11408 -- package spec, and return True if we find one that matches.
11409 -- Note that Parent (H) will be the declaration of the
11410 -- partial view of T for a match.
11413 H
: Entity_Id
:= S
;
11417 exit when No
(H
) or else Scope
(H
) /= Scope
(S
);
11419 if Nkind
(Parent
(H
)) in
11420 N_Private_Extension_Declaration |
11421 N_Private_Type_Declaration
11422 and then Defining_Identifier
(Parent
(H
)) = Partial_View
11430 end Overrides_Visible_Function
;
11432 -- Start of processing for Check_Private_Overriding
11435 if Is_Package_Or_Generic_Package
(Current_Scope
)
11436 and then In_Private_Part
(Current_Scope
)
11437 and then Visible_Part_Type
(T
)
11438 and then not In_Instance
11440 if Is_Abstract_Type
(T
)
11441 and then Is_Abstract_Subprogram
(S
)
11442 and then (not Is_Overriding
11443 or else not Is_Abstract_Subprogram
(E
)
11444 or else Overrides_Private_Part_Op
)
11447 ("abstract subprograms must be visible (RM 3.9.3(10))!",
11450 elsif Ekind
(S
) = E_Function
then
11452 Partial_View
: constant Entity_Id
:=
11453 Incomplete_Or_Partial_View
(T
);
11456 if not Overrides_Visible_Function
(Partial_View
) then
11458 -- Here, S is "function ... return T;" declared in
11459 -- the private part, not overriding some visible
11460 -- operation. That's illegal in the tagged case
11461 -- (but not if the private type is untagged).
11463 if ((Present
(Partial_View
)
11464 and then Is_Tagged_Type
(Partial_View
))
11465 or else (No
(Partial_View
)
11466 and then Is_Tagged_Type
(T
)))
11467 and then T
= Base_Type
(Etype
(S
))
11470 ("private function with tagged result must"
11471 & " override visible-part function", S
);
11473 ("\move subprogram to the visible part"
11474 & " (RM 3.9.3(10))", S
);
11476 -- Ada 2012 (AI05-0073): Extend this check to the case
11477 -- of a function whose result subtype is defined by an
11478 -- access_definition designating specific tagged type.
11480 elsif Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
11481 and then Is_Tagged_Type
(Designated_Type
(Etype
(S
)))
11483 not Is_Class_Wide_Type
11484 (Designated_Type
(Etype
(S
)))
11485 and then Ada_Version
>= Ada_2012
11488 ("private function with controlling access "
11489 & "result must override visible-part function",
11492 ("\move subprogram to the visible part"
11493 & " (RM 3.9.3(10))", S
);
11499 end Check_Private_Overriding
;
11501 -----------------------
11502 -- Visible_Part_Type --
11503 -----------------------
11505 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
11506 P
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
11509 -- If the entity is a private type, then it must be declared in a
11512 if Is_Private_Type
(T
) then
11515 elsif Is_Type
(T
) and then Has_Private_Declaration
(T
) then
11518 elsif Is_List_Member
(Declaration_Node
(T
))
11519 and then List_Containing
(Declaration_Node
(T
)) =
11520 Visible_Declarations
(Specification
(P
))
11527 end Visible_Part_Type
;
11531 Formal
: Entity_Id
;
11535 -- Start of processing for Check_For_Primitive_Subprogram
11538 Is_Primitive
:= False;
11540 if not Comes_From_Source
(S
) then
11542 -- Add an inherited primitive for an untagged derived type to
11543 -- Derived_Type's list of primitives. Tagged primitives are
11544 -- dealt with in Check_Dispatching_Operation. Do this even when
11545 -- Extensions_Allowed is False to issue better error messages.
11547 if Present
(Derived_Type
)
11548 and then not Is_Tagged_Type
(Derived_Type
)
11550 Append_Unique_Elmt
(S
, Primitive_Operations
(Derived_Type
));
11553 -- If subprogram is at library level, it is not primitive operation
11555 elsif Current_Scope
= Standard_Standard
then
11558 elsif (Is_Package_Or_Generic_Package
(Current_Scope
)
11559 and then not In_Package_Body
(Current_Scope
))
11560 or else Is_Overriding
11562 -- For function, check return type
11564 if Ekind
(S
) = E_Function
then
11565 if Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
then
11566 F_Typ
:= Designated_Type
(Etype
(S
));
11568 F_Typ
:= Etype
(S
);
11571 B_Typ
:= Base_Type
(F_Typ
);
11573 if Scope
(B_Typ
) = Current_Scope
11574 and then not Is_Class_Wide_Type
(B_Typ
)
11575 and then not Is_Generic_Type
(B_Typ
)
11577 Is_Primitive
:= True;
11578 Set_Has_Primitive_Operations
(B_Typ
);
11579 Set_Is_Primitive
(S
);
11581 -- Add a primitive for an untagged type to B_Typ's
11582 -- list of primitives. Tagged primitives are dealt with
11583 -- in Check_Dispatching_Operation. Do this even when
11584 -- Extensions_Allowed is False to issue better error
11587 if not Is_Tagged_Type
(B_Typ
) then
11588 Add_Or_Replace_Untagged_Primitive
(B_Typ
);
11591 Check_Private_Overriding
(B_Typ
);
11592 -- The Ghost policy in effect at the point of declaration
11593 -- or a tagged type and a primitive operation must match
11594 -- (SPARK RM 6.9(16)).
11596 Check_Ghost_Primitive
(S
, B_Typ
);
11600 -- For all subprograms, check formals
11602 Formal
:= First_Formal
(S
);
11603 while Present
(Formal
) loop
11604 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
11605 F_Typ
:= Designated_Type
(Etype
(Formal
));
11607 F_Typ
:= Etype
(Formal
);
11610 B_Typ
:= Base_Type
(F_Typ
);
11612 if Ekind
(B_Typ
) = E_Access_Subtype
then
11613 B_Typ
:= Base_Type
(B_Typ
);
11616 if Scope
(B_Typ
) = Current_Scope
11617 and then not Is_Class_Wide_Type
(B_Typ
)
11618 and then not Is_Generic_Type
(B_Typ
)
11620 Is_Primitive
:= True;
11621 Set_Is_Primitive
(S
);
11622 Set_Has_Primitive_Operations
(B_Typ
);
11624 -- Add a primitive for an untagged type to B_Typ's list
11625 -- of primitives. Tagged primitives are dealt with in
11626 -- Check_Dispatching_Operation. Do this even when
11627 -- Extensions_Allowed is False to issue better error
11630 if not Is_Tagged_Type
(B_Typ
) then
11631 Add_Or_Replace_Untagged_Primitive
(B_Typ
);
11634 Check_Private_Overriding
(B_Typ
);
11636 -- The Ghost policy in effect at the point of declaration
11637 -- of a tagged type and a primitive operation must match
11638 -- (SPARK RM 6.9(16)).
11640 Check_Ghost_Primitive
(S
, B_Typ
);
11643 Next_Formal
(Formal
);
11646 -- Special case: An equality function can be redefined for a type
11647 -- occurring in a declarative part, and won't otherwise be treated as
11648 -- a primitive because it doesn't occur in a package spec and doesn't
11649 -- override an inherited subprogram. It's important that we mark it
11650 -- primitive so it can be returned by Collect_Primitive_Operations
11651 -- and be used in composing the equality operation of later types
11652 -- that have a component of the type.
11654 elsif Chars
(S
) = Name_Op_Eq
11655 and then Etype
(S
) = Standard_Boolean
11657 B_Typ
:= Base_Type
(Etype
(First_Formal
(S
)));
11659 if Scope
(B_Typ
) = Current_Scope
11661 Base_Type
(Etype
(Next_Formal
(First_Formal
(S
)))) = B_Typ
11662 and then not Is_Limited_Type
(B_Typ
)
11664 Is_Primitive
:= True;
11665 Set_Is_Primitive
(S
);
11666 Set_Has_Primitive_Operations
(B_Typ
);
11667 Check_Private_Overriding
(B_Typ
);
11669 -- The Ghost policy in effect at the point of declaration of a
11670 -- tagged type and a primitive operation must match
11671 -- (SPARK RM 6.9(16)).
11673 Check_Ghost_Primitive
(S
, B_Typ
);
11676 end Check_For_Primitive_Subprogram
;
11678 --------------------------------------
11679 -- Has_Matching_Entry_Or_Subprogram --
11680 --------------------------------------
11682 function Has_Matching_Entry_Or_Subprogram
11683 (E
: Entity_Id
) return Boolean
11685 function Check_Conforming_Parameters
11686 (E1_Param
: Node_Id
;
11687 E2_Param
: Node_Id
;
11688 Ctype
: Conformance_Type
) return Boolean;
11689 -- Starting from the given parameters, check that all the parameters
11690 -- of two entries or subprograms are conformant. Used to skip
11691 -- the check on the controlling argument.
11693 function Matching_Entry_Or_Subprogram
11694 (Conc_Typ
: Entity_Id
;
11695 Subp
: Entity_Id
) return Entity_Id
;
11696 -- Return the first entry or subprogram of the given concurrent type
11697 -- whose name matches the name of Subp and has a profile conformant
11698 -- with Subp; return Empty if not found.
11700 function Matching_Dispatching_Subprogram
11701 (Conc_Typ
: Entity_Id
;
11702 Ent
: Entity_Id
) return Entity_Id
;
11703 -- Return the first dispatching primitive of Conc_Type defined in the
11704 -- enclosing scope of Conc_Type (i.e. before the full definition of
11705 -- this concurrent type) whose name matches the entry Ent and has a
11706 -- profile conformant with the profile of the corresponding (not yet
11707 -- built) dispatching primitive of Ent; return Empty if not found.
11709 function Matching_Original_Protected_Subprogram
11710 (Prot_Typ
: Entity_Id
;
11711 Subp
: Entity_Id
) return Entity_Id
;
11712 -- Return the first subprogram defined in the enclosing scope of
11713 -- Prot_Typ (before the full definition of this protected type)
11714 -- whose name matches the original name of Subp and has a profile
11715 -- conformant with the profile of Subp; return Empty if not found.
11717 function Normalized_First_Parameter_Type
11718 (E
: Entity_Id
) return Entity_Id
;
11719 -- Return the type of the first parameter unless that type
11720 -- is an anonymous access type, in which case return the
11721 -- designated type. Used to treat anonymous-access-to-synchronized
11722 -- the same as synchronized for purposes of checking for
11723 -- prefixed view profile conflicts.
11725 ---------------------------------
11726 -- Check_Conforming_Parameters --
11727 ---------------------------------
11729 function Check_Conforming_Parameters
11730 (E1_Param
: Node_Id
;
11731 E2_Param
: Node_Id
;
11732 Ctype
: Conformance_Type
) return Boolean
11734 Param_E1
: Node_Id
:= E1_Param
;
11735 Param_E2
: Node_Id
:= E2_Param
;
11738 while Present
(Param_E1
) and then Present
(Param_E2
) loop
11739 if Ctype
>= Mode_Conformant
and then
11740 Ekind
(Defining_Identifier
(Param_E1
)) /=
11741 Ekind
(Defining_Identifier
(Param_E2
))
11746 (Find_Parameter_Type
(Param_E1
),
11747 Find_Parameter_Type
(Param_E2
),
11757 -- The candidate is not valid if one of the two lists contains
11758 -- more parameters than the other
11760 return No
(Param_E1
) and then No
(Param_E2
);
11761 end Check_Conforming_Parameters
;
11763 ----------------------------------
11764 -- Matching_Entry_Or_Subprogram --
11765 ----------------------------------
11767 function Matching_Entry_Or_Subprogram
11768 (Conc_Typ
: Entity_Id
;
11769 Subp
: Entity_Id
) return Entity_Id
11774 E
:= First_Entity
(Conc_Typ
);
11775 while Present
(E
) loop
11776 if Chars
(Subp
) = Chars
(E
)
11777 and then (Ekind
(E
) = E_Entry
or else Is_Subprogram
(E
))
11779 Check_Conforming_Parameters
11780 (First
(Parameter_Specifications
(Parent
(E
))),
11781 Next
(First
(Parameter_Specifications
(Parent
(Subp
)))),
11791 end Matching_Entry_Or_Subprogram
;
11793 -------------------------------------
11794 -- Matching_Dispatching_Subprogram --
11795 -------------------------------------
11797 function Matching_Dispatching_Subprogram
11798 (Conc_Typ
: Entity_Id
;
11799 Ent
: Entity_Id
) return Entity_Id
11804 -- Search for entities in the enclosing scope of this synchronized
11807 pragma Assert
(Is_Concurrent_Type
(Conc_Typ
));
11808 Push_Scope
(Scope
(Conc_Typ
));
11809 E
:= Current_Entity_In_Scope
(Ent
);
11812 while Present
(E
) loop
11813 if Scope
(E
) = Scope
(Conc_Typ
)
11814 and then Comes_From_Source
(E
)
11815 and then Ekind
(E
) = E_Procedure
11816 and then Present
(First_Entity
(E
))
11817 and then Is_Controlling_Formal
(First_Entity
(E
))
11818 and then Etype
(First_Entity
(E
)) = Conc_Typ
11820 Check_Conforming_Parameters
11821 (First
(Parameter_Specifications
(Parent
(Ent
))),
11822 Next
(First
(Parameter_Specifications
(Parent
(E
)))),
11823 Subtype_Conformant
)
11832 end Matching_Dispatching_Subprogram
;
11834 --------------------------------------------
11835 -- Matching_Original_Protected_Subprogram --
11836 --------------------------------------------
11838 function Matching_Original_Protected_Subprogram
11839 (Prot_Typ
: Entity_Id
;
11840 Subp
: Entity_Id
) return Entity_Id
11842 ICF
: constant Boolean :=
11843 Is_Controlling_Formal
(First_Entity
(Subp
));
11847 -- Temporarily decorate the first parameter of Subp as controlling
11848 -- formal, required to invoke Subtype_Conformant.
11850 Set_Is_Controlling_Formal
(First_Entity
(Subp
));
11853 Current_Entity_In_Scope
(Original_Protected_Subprogram
(Subp
));
11855 while Present
(E
) loop
11856 if Scope
(E
) = Scope
(Prot_Typ
)
11857 and then Comes_From_Source
(E
)
11858 and then Ekind
(Subp
) = Ekind
(E
)
11859 and then Present
(First_Entity
(E
))
11860 and then Is_Controlling_Formal
(First_Entity
(E
))
11861 and then Etype
(First_Entity
(E
)) = Prot_Typ
11862 and then Subtype_Conformant
(Subp
, E
,
11863 Skip_Controlling_Formals
=> True)
11865 Set_Is_Controlling_Formal
(First_Entity
(Subp
), ICF
);
11872 Set_Is_Controlling_Formal
(First_Entity
(Subp
), ICF
);
11875 end Matching_Original_Protected_Subprogram
;
11877 -------------------------------------
11878 -- Normalized_First_Parameter_Type --
11879 -------------------------------------
11881 function Normalized_First_Parameter_Type
11882 (E
: Entity_Id
) return Entity_Id
11884 Result
: Entity_Id
:= Etype
(First_Entity
(E
));
11886 if Ekind
(Result
) = E_Anonymous_Access_Type
then
11887 Result
:= Designated_Type
(Result
);
11890 end Normalized_First_Parameter_Type
;
11892 -- Start of processing for Has_Matching_Entry_Or_Subprogram
11895 -- Case 1: E is a subprogram whose first formal is a concurrent type
11896 -- defined in the scope of E that has an entry or subprogram whose
11897 -- profile matches E.
11899 if Comes_From_Source
(E
)
11900 and then Is_Subprogram
(E
)
11901 and then Present
(First_Entity
(E
))
11902 and then Is_Concurrent_Record_Type
11903 (Normalized_First_Parameter_Type
(E
))
11906 Scope
(Corresponding_Concurrent_Type
11907 (Normalized_First_Parameter_Type
(E
)))
11910 (Matching_Entry_Or_Subprogram
11911 (Corresponding_Concurrent_Type
11912 (Normalized_First_Parameter_Type
(E
)),
11915 Report_Conflict
(E
,
11916 Matching_Entry_Or_Subprogram
11917 (Corresponding_Concurrent_Type
11918 (Normalized_First_Parameter_Type
(E
)),
11923 -- Case 2: E is an internally built dispatching subprogram of a
11924 -- protected type and there is a subprogram defined in the enclosing
11925 -- scope of the protected type that has the original name of E and
11926 -- its profile is conformant with the profile of E. We check the
11927 -- name of the original protected subprogram associated with E since
11928 -- the expander builds dispatching primitives of protected functions
11929 -- and procedures with other names (see Exp_Ch9.Build_Selected_Name).
11931 elsif not Comes_From_Source
(E
)
11932 and then Is_Subprogram
(E
)
11933 and then Present
(First_Entity
(E
))
11934 and then Is_Concurrent_Record_Type
(Etype
(First_Entity
(E
)))
11935 and then Present
(Original_Protected_Subprogram
(E
))
11938 (Matching_Original_Protected_Subprogram
11939 (Corresponding_Concurrent_Type
(Etype
(First_Entity
(E
))),
11942 Report_Conflict
(E
,
11943 Matching_Original_Protected_Subprogram
11944 (Corresponding_Concurrent_Type
(Etype
(First_Entity
(E
))),
11948 -- Case 3: E is an entry of a synchronized type and a matching
11949 -- procedure has been previously defined in the enclosing scope
11950 -- of the synchronized type.
11952 elsif Comes_From_Source
(E
)
11953 and then Ekind
(E
) = E_Entry
11955 Present
(Matching_Dispatching_Subprogram
(Current_Scope
, E
))
11957 Report_Conflict
(E
,
11958 Matching_Dispatching_Subprogram
(Current_Scope
, E
));
11963 end Has_Matching_Entry_Or_Subprogram
;
11965 ----------------------------
11966 -- Is_Private_Declaration --
11967 ----------------------------
11969 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
11970 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
11971 Priv_Decls
: List_Id
;
11974 if Is_Package_Or_Generic_Package
(Current_Scope
)
11975 and then In_Private_Part
(Current_Scope
)
11978 Private_Declarations
(Package_Specification
(Current_Scope
));
11980 return In_Package_Body
(Current_Scope
)
11982 (Is_List_Member
(Decl
)
11983 and then List_Containing
(Decl
) = Priv_Decls
)
11984 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
11986 Is_Compilation_Unit
11987 (Defining_Entity
(Parent
(Decl
)))
11988 and then List_Containing
(Parent
(Parent
(Decl
))) =
11993 end Is_Private_Declaration
;
11995 --------------------------
11996 -- Is_Overriding_Alias --
11997 --------------------------
11999 function Is_Overriding_Alias
12000 (Old_E
: Entity_Id
;
12001 New_E
: Entity_Id
) return Boolean
12003 AO
: constant Entity_Id
:= Alias
(Old_E
);
12004 AN
: constant Entity_Id
:= Alias
(New_E
);
12007 return Scope
(AO
) /= Scope
(AN
)
12008 or else No
(DTC_Entity
(AO
))
12009 or else No
(DTC_Entity
(AN
))
12010 or else DT_Position
(AO
) = DT_Position
(AN
);
12011 end Is_Overriding_Alias
;
12013 ---------------------
12014 -- Report_Conflict --
12015 ---------------------
12017 procedure Report_Conflict
(S
: Entity_Id
; E
: Entity_Id
) is
12019 Error_Msg_Sloc
:= Sloc
(E
);
12021 -- Generate message, with useful additional warning if in generic
12023 if Is_Generic_Unit
(E
) then
12024 Error_Msg_N
("previous generic unit cannot be overloaded", S
);
12025 Error_Msg_N
("\& conflicts with declaration#", S
);
12027 Error_Msg_N
("& conflicts with declaration#", S
);
12029 end Report_Conflict
;
12031 -- Start of processing for New_Overloaded_Entity
12034 -- We need to look for an entity that S may override. This must be a
12035 -- homonym in the current scope, so we look for the first homonym of
12036 -- S in the current scope as the starting point for the search.
12038 E
:= Current_Entity_In_Scope
(S
);
12040 -- Ada 2005 (AI-251): Derivation of abstract interface primitives.
12041 -- They are directly added to the list of primitive operations of
12042 -- Derived_Type, unless this is a rederivation in the private part
12043 -- of an operation that was already derived in the visible part of
12044 -- the current package.
12046 if Ada_Version
>= Ada_2005
12047 and then Present
(Derived_Type
)
12048 and then Present
(Alias
(S
))
12049 and then Is_Dispatching_Operation
(Alias
(S
))
12050 and then Present
(Find_Dispatching_Type
(Alias
(S
)))
12051 and then Is_Interface
(Find_Dispatching_Type
(Alias
(S
)))
12053 -- For private types, when the full-view is processed we propagate to
12054 -- the full view the non-overridden entities whose attribute "alias"
12055 -- references an interface primitive. These entities were added by
12056 -- Derive_Subprograms to ensure that interface primitives are
12059 -- Inside_Freeze_Actions is non zero when S corresponds with an
12060 -- internal entity that links an interface primitive with its
12061 -- covering primitive through attribute Interface_Alias (see
12062 -- Add_Internal_Interface_Entities).
12064 if Inside_Freezing_Actions
= 0
12065 and then Is_Package_Or_Generic_Package
(Current_Scope
)
12066 and then In_Private_Part
(Current_Scope
)
12067 and then Parent_Kind
(E
) = N_Private_Extension_Declaration
12068 and then Nkind
(Parent
(S
)) = N_Full_Type_Declaration
12069 and then Full_View
(Defining_Identifier
(Parent
(E
)))
12070 = Defining_Identifier
(Parent
(S
))
12071 and then Alias
(E
) = Alias
(S
)
12073 Check_Operation_From_Private_View
(S
, E
);
12074 Set_Is_Dispatching_Operation
(S
);
12079 Enter_Overloaded_Entity
(S
);
12080 Check_Dispatching_Operation
(S
, Empty
);
12081 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
12087 -- For synchronized types check conflicts of this entity with previously
12088 -- defined entities.
12090 if Ada_Version
>= Ada_2005
12091 and then Has_Matching_Entry_Or_Subprogram
(S
)
12096 -- If there is no homonym then this is definitely not overriding
12099 Enter_Overloaded_Entity
(S
);
12100 Check_Dispatching_Operation
(S
, Empty
);
12101 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
12103 -- If subprogram has an explicit declaration, check whether it has an
12104 -- overriding indicator.
12106 if Comes_From_Source
(S
) then
12107 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
12109 -- (Ada 2012: AI05-0125-1): If S is a dispatching operation then
12110 -- it may have overridden some hidden inherited primitive. Update
12111 -- Overridden_Subp to avoid spurious errors when checking the
12112 -- overriding indicator.
12114 if Ada_Version
>= Ada_2012
12115 and then No
(Overridden_Subp
)
12116 and then Is_Dispatching_Operation
(S
)
12117 and then Present
(Overridden_Operation
(S
))
12119 Overridden_Subp
:= Overridden_Operation
(S
);
12122 Check_Overriding_Indicator
12123 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
12125 -- The Ghost policy in effect at the point of declaration of a
12126 -- parent subprogram and an overriding subprogram must match
12127 -- (SPARK RM 6.9(17)).
12129 Check_Ghost_Overriding
(S
, Overridden_Subp
);
12132 -- If there is a homonym that is not overloadable, then we have an
12133 -- error, except for the special cases checked explicitly below.
12135 elsif not Is_Overloadable
(E
) then
12137 -- Check for spurious conflict produced by a subprogram that has the
12138 -- same name as that of the enclosing generic package. The conflict
12139 -- occurs within an instance, between the subprogram and the renaming
12140 -- declaration for the package. After the subprogram, the package
12141 -- renaming declaration becomes hidden.
12143 if Ekind
(E
) = E_Package
12144 and then Present
(Renamed_Entity
(E
))
12145 and then Renamed_Entity
(E
) = Current_Scope
12146 and then Nkind
(Parent
(Renamed_Entity
(E
))) =
12147 N_Package_Specification
12148 and then Present
(Generic_Parent
(Parent
(Renamed_Entity
(E
))))
12151 Set_Is_Immediately_Visible
(E
, False);
12152 Enter_Overloaded_Entity
(S
);
12153 Set_Homonym
(S
, Homonym
(E
));
12154 Check_Dispatching_Operation
(S
, Empty
);
12155 Check_Overriding_Indicator
(S
, Empty
, Is_Primitive
=> False);
12157 -- If the subprogram is implicit it is hidden by the previous
12158 -- declaration. However if it is dispatching, it must appear in the
12159 -- dispatch table anyway, because it can be dispatched to even if it
12160 -- cannot be called directly.
12162 elsif Present
(Alias
(S
)) and then not Comes_From_Source
(S
) then
12163 Set_Scope
(S
, Current_Scope
);
12165 if Is_Dispatching_Operation
(Alias
(S
)) then
12166 Check_Dispatching_Operation
(S
, Empty
);
12172 Report_Conflict
(S
, E
);
12176 -- E exists and is overloadable
12179 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
12181 -- Loop through E and its homonyms to determine if any of them is
12182 -- the candidate for overriding by S.
12184 while Present
(E
) loop
12186 -- Definitely not interesting if not in the current scope
12188 if Scope
(E
) /= Current_Scope
then
12191 -- A function can overload the name of an abstract state. The
12192 -- state can be viewed as a function with a profile that cannot
12193 -- be matched by anything.
12195 elsif Ekind
(S
) = E_Function
12196 and then Ekind
(E
) = E_Abstract_State
12198 Enter_Overloaded_Entity
(S
);
12201 -- Ada 2012 (AI05-0165): For internally generated bodies of null
12202 -- procedures locate the internally generated spec. We enforce
12203 -- mode conformance since a tagged type may inherit from
12204 -- interfaces several null primitives which differ only in
12205 -- the mode of the formals.
12207 elsif not Comes_From_Source
(S
)
12208 and then Is_Null_Procedure
(S
)
12209 and then not Mode_Conformant
(E
, S
)
12213 -- Check if we have type conformance
12215 elsif Type_Conformant
(E
, S
) then
12217 -- If the old and new entities have the same profile and one
12218 -- is not the body of the other, then this is an error, unless
12219 -- one of them is implicitly declared.
12221 -- There are some cases when both can be implicit, for example
12222 -- when both a literal and a function that overrides it are
12223 -- inherited in a derivation, or when an inherited operation
12224 -- of a tagged full type overrides the inherited operation of
12225 -- a private extension. Ada 83 had a special rule for the
12226 -- literal case. In Ada 95, the later implicit operation hides
12227 -- the former, and the literal is always the former. In the
12228 -- odd case where both are derived operations declared at the
12229 -- same point, both operations should be declared, and in that
12230 -- case we bypass the following test and proceed to the next
12231 -- part. This can only occur for certain obscure cases in
12232 -- instances, when an operation on a type derived from a formal
12233 -- private type does not override a homograph inherited from
12234 -- the actual. In subsequent derivations of such a type, the
12235 -- DT positions of these operations remain distinct, if they
12238 if Present
(Alias
(S
))
12239 and then (No
(Alias
(E
))
12240 or else Comes_From_Source
(E
)
12241 or else Is_Abstract_Subprogram
(S
)
12243 (Is_Dispatching_Operation
(E
)
12244 and then Is_Overriding_Alias
(E
, S
)))
12245 and then Ekind
(E
) /= E_Enumeration_Literal
12247 -- When an derived operation is overloaded it may be due to
12248 -- the fact that the full view of a private extension
12249 -- re-inherits. It has to be dealt with.
12251 if Is_Package_Or_Generic_Package
(Current_Scope
)
12252 and then In_Private_Part
(Current_Scope
)
12254 Check_Operation_From_Private_View
(S
, E
);
12257 -- In any case the implicit operation remains hidden by the
12258 -- existing declaration, which is overriding. Indicate that
12259 -- E overrides the operation from which S is inherited.
12261 if Present
(Alias
(S
)) then
12262 Set_Overridden_Operation
(E
, Alias
(S
));
12263 Inherit_Subprogram_Contract
(E
, Alias
(S
));
12264 Set_Is_Ada_2022_Only
(E
,
12265 Is_Ada_2022_Only
(Alias
(S
)));
12268 Set_Overridden_Operation
(E
, S
);
12269 Inherit_Subprogram_Contract
(E
, S
);
12270 Set_Is_Ada_2022_Only
(E
, Is_Ada_2022_Only
(S
));
12273 -- When a dispatching operation overrides an inherited
12274 -- subprogram, it shall be subtype conformant with the
12275 -- inherited subprogram (RM 3.9.2 (10.2)).
12277 if Comes_From_Source
(E
)
12278 and then Is_Dispatching_Operation
(E
)
12279 and then Find_Dispatching_Type
(S
)
12280 = Find_Dispatching_Type
(E
)
12282 Check_Subtype_Conformant
(E
, S
);
12285 if Comes_From_Source
(E
) then
12286 Check_Overriding_Indicator
(E
, S
, Is_Primitive
=> False);
12288 -- The Ghost policy in effect at the point of declaration
12289 -- of a parent subprogram and an overriding subprogram
12290 -- must match (SPARK RM 6.9(17)).
12292 Check_Ghost_Overriding
(E
, S
);
12297 -- Within an instance, the renaming declarations for actual
12298 -- subprograms may become ambiguous, but they do not hide each
12301 elsif Ekind
(E
) /= E_Entry
12302 and then not Comes_From_Source
(E
)
12303 and then not Is_Generic_Instance
(E
)
12304 and then (Present
(Alias
(E
))
12305 or else Is_Intrinsic_Subprogram
(E
))
12306 and then (not In_Instance
12307 or else No
(Parent
(E
))
12308 or else Nkind
(Unit_Declaration_Node
(E
)) /=
12309 N_Subprogram_Renaming_Declaration
)
12311 -- A subprogram child unit is not allowed to override an
12312 -- inherited subprogram (10.1.1(20)).
12314 if Is_Child_Unit
(S
) then
12316 ("child unit overrides inherited subprogram in parent",
12321 if Is_Non_Overriding_Operation
(E
, S
) then
12322 Enter_Overloaded_Entity
(S
);
12324 if No
(Derived_Type
)
12325 or else Is_Tagged_Type
(Derived_Type
)
12327 Check_Dispatching_Operation
(S
, Empty
);
12333 -- E is a derived operation or an internal operator which
12334 -- is being overridden. Remove E from further visibility.
12335 -- Furthermore, if E is a dispatching operation, it must be
12336 -- replaced in the list of primitive operations of its type
12337 -- (see Override_Dispatching_Operation).
12339 Overridden_Subp
:= E
;
12341 -- It is possible for E to be in the current scope and
12342 -- yet not in the entity chain. This can only occur in a
12343 -- generic context where E is an implicit concatenation
12344 -- in the formal part, because in a generic body the
12345 -- entity chain starts with the formals.
12347 -- In GNATprove mode, a wrapper for an operation with
12348 -- axiomatization may be a homonym of another declaration
12349 -- for an actual subprogram (needs refinement ???).
12351 if No
(Prev_Entity
(E
)) then
12353 and then GNATprove_Mode
12355 Nkind
(Original_Node
(Unit_Declaration_Node
(S
))) =
12356 N_Subprogram_Renaming_Declaration
12360 pragma Assert
(Chars
(E
) = Name_Op_Concat
);
12365 -- E must be removed both from the entity_list of the
12366 -- current scope, and from the visibility chain.
12368 if Debug_Flag_E
then
12369 Write_Str
("Override implicit operation ");
12370 Write_Int
(Int
(E
));
12374 -- If E is a predefined concatenation, it stands for four
12375 -- different operations. As a result, a single explicit
12376 -- declaration does not hide it. In a possible ambiguous
12377 -- situation, Disambiguate chooses the user-defined op,
12378 -- so it is correct to retain the previous internal one.
12380 if Chars
(E
) /= Name_Op_Concat
12381 or else Ekind
(E
) /= E_Operator
12383 -- For nondispatching derived operations that are
12384 -- overridden by a subprogram declared in the private
12385 -- part of a package, we retain the derived subprogram
12386 -- but mark it as not immediately visible. If the
12387 -- derived operation was declared in the visible part
12388 -- then this ensures that it will still be visible
12389 -- outside the package with the proper signature
12390 -- (calls from outside must also be directed to this
12391 -- version rather than the overriding one, unlike the
12392 -- dispatching case). Calls from inside the package
12393 -- will still resolve to the overriding subprogram
12394 -- since the derived one is marked as not visible
12395 -- within the package.
12397 -- If the private operation is dispatching, we achieve
12398 -- the overriding by keeping the implicit operation
12399 -- but setting its alias to be the overriding one. In
12400 -- this fashion the proper body is executed in all
12401 -- cases, but the original signature is used outside
12404 -- If the overriding is not in the private part, we
12405 -- remove the implicit operation altogether.
12407 if Is_Private_Declaration
(S
) then
12408 if not Is_Dispatching_Operation
(E
) then
12409 Set_Is_Immediately_Visible
(E
, False);
12411 -- Work done in Override_Dispatching_Operation, so
12412 -- nothing else needs to be done here.
12414 -- ??? Special case to keep supporting the hiding
12415 -- of the predefined "=" operator for a nonlimited
12416 -- tagged type by a user-defined "=" operator for
12417 -- its class-wide type when the type is private.
12419 if Chars
(E
) = Name_Op_Eq
then
12421 Typ
: constant Entity_Id
12422 := Etype
(First_Entity
(E
));
12423 H
: Entity_Id
:= Homonym
(E
);
12427 and then Scope
(H
) = Scope
(E
)
12429 if Is_User_Defined_Equality
(H
)
12430 and then Is_Immediately_Visible
(H
)
12431 and then Etype
(First_Entity
(H
))
12432 = Class_Wide_Type
(Typ
)
12434 Remove_Entity_And_Homonym
(E
);
12445 Remove_Entity_And_Homonym
(E
);
12449 Enter_Overloaded_Entity
(S
);
12451 -- For entities generated by Derive_Subprograms the
12452 -- overridden operation is the inherited primitive
12453 -- (which is available through the attribute alias).
12455 if not (Comes_From_Source
(E
))
12456 and then Is_Dispatching_Operation
(E
)
12457 and then Find_Dispatching_Type
(E
) =
12458 Find_Dispatching_Type
(S
)
12459 and then Present
(Alias
(E
))
12460 and then Comes_From_Source
(Alias
(E
))
12462 Set_Overridden_Operation
(S
, Alias
(E
));
12463 Inherit_Subprogram_Contract
(S
, Alias
(E
));
12464 Set_Is_Ada_2022_Only
(S
,
12465 Is_Ada_2022_Only
(Alias
(E
)));
12467 -- Normal case of setting entity as overridden
12469 -- Note: Static_Initialization and Overridden_Operation
12470 -- attributes use the same field in subprogram entities.
12471 -- Static_Initialization is only defined for internal
12472 -- initialization procedures, where Overridden_Operation
12473 -- is irrelevant. Therefore the setting of this attribute
12474 -- must check whether the target is an init_proc.
12476 elsif not Is_Init_Proc
(S
) then
12478 -- LSP wrappers must override the ultimate alias of their
12479 -- wrapped dispatching primitive E; required to traverse
12480 -- the chain of ancestor primitives (c.f. Map_Primitives)
12481 -- They don't inherit contracts.
12484 and then Present
(LSP_Subprogram
(S
))
12486 Set_Overridden_Operation
(S
, Ultimate_Alias
(E
));
12488 Set_Overridden_Operation
(S
, E
);
12489 Inherit_Subprogram_Contract
(S
, E
);
12492 Set_Is_Ada_2022_Only
(S
, Is_Ada_2022_Only
(E
));
12495 Check_Overriding_Indicator
(S
, E
, Is_Primitive
=> True);
12497 -- The Ghost policy in effect at the point of declaration
12498 -- of a parent subprogram and an overriding subprogram
12499 -- must match (SPARK RM 6.9(17)).
12501 Check_Ghost_Overriding
(S
, E
);
12503 -- If S is a user-defined subprogram or a null procedure
12504 -- expanded to override an inherited null procedure, or a
12505 -- predefined dispatching primitive then indicate that E
12506 -- overrides the operation from which S is inherited.
12508 if Comes_From_Source
(S
)
12510 (Present
(Parent
(S
))
12511 and then Nkind
(Parent
(S
)) = N_Procedure_Specification
12512 and then Null_Present
(Parent
(S
)))
12514 (Present
(Alias
(E
))
12516 Is_Predefined_Dispatching_Operation
(Alias
(E
)))
12518 if Present
(Alias
(E
)) then
12520 -- LSP wrappers must override the ultimate alias of
12521 -- their wrapped dispatching primitive E; required to
12522 -- traverse the chain of ancestor primitives (see
12523 -- Map_Primitives). They don't inherit contracts.
12526 and then Present
(LSP_Subprogram
(S
))
12528 Set_Overridden_Operation
(S
, Ultimate_Alias
(E
));
12530 Set_Overridden_Operation
(S
, Alias
(E
));
12531 Inherit_Subprogram_Contract
(S
, Alias
(E
));
12534 Set_Is_Ada_2022_Only
(S
, Is_Ada_2022_Only
(Alias
(E
)));
12538 if Is_Dispatching_Operation
(E
) then
12540 -- An overriding dispatching subprogram inherits the
12541 -- convention of the overridden subprogram (AI95-117).
12543 Set_Convention
(S
, Convention
(E
));
12544 Check_Dispatching_Operation
(S
, E
);
12547 Check_Dispatching_Operation
(S
, Empty
);
12550 Check_For_Primitive_Subprogram
12551 (Is_Primitive_Subp
, Is_Overriding
=> True);
12552 goto Check_Inequality
;
12554 -- Apparent redeclarations in instances can occur when two
12555 -- formal types get the same actual type. The subprograms in
12556 -- in the instance are legal, even if not callable from the
12557 -- outside. Calls from within are disambiguated elsewhere.
12558 -- For dispatching operations in the visible part, the usual
12559 -- rules apply, and operations with the same profile are not
12560 -- legal (B830001).
12562 elsif (In_Instance_Visible_Part
12563 and then not Is_Dispatching_Operation
(E
))
12564 or else In_Instance_Not_Visible
12568 -- Here we have a real error (identical profile)
12571 Error_Msg_Sloc
:= Sloc
(E
);
12573 -- Avoid cascaded errors if the entity appears in
12574 -- subsequent calls.
12576 Set_Scope
(S
, Current_Scope
);
12578 -- Generate error, with extra useful warning for the case
12579 -- of a generic instance with no completion.
12581 if Is_Generic_Instance
(S
)
12582 and then not Has_Completion
(E
)
12585 ("instantiation cannot provide body for&", S
);
12586 Error_Msg_N
("\& conflicts with declaration#", S
);
12588 Error_Msg_N
("& conflicts with declaration#", S
);
12595 -- If one subprogram has an access parameter and the other
12596 -- a parameter of an access type, calls to either might be
12597 -- ambiguous. Verify that parameters match except for the
12598 -- access parameter.
12600 if May_Hide_Profile
then
12606 F1
:= First_Formal
(S
);
12607 F2
:= First_Formal
(E
);
12608 while Present
(F1
) and then Present
(F2
) loop
12609 if Is_Access_Type
(Etype
(F1
)) then
12610 if not Is_Access_Type
(Etype
(F2
))
12611 or else not Conforming_Types
12612 (Designated_Type
(Etype
(F1
)),
12613 Designated_Type
(Etype
(F2
)),
12616 May_Hide_Profile
:= False;
12620 not Conforming_Types
12621 (Etype
(F1
), Etype
(F2
), Type_Conformant
)
12623 May_Hide_Profile
:= False;
12630 if May_Hide_Profile
12634 Error_Msg_NE
("calls to& may be ambiguous??", S
, S
);
12643 -- On exit, we know that S is a new entity
12645 Enter_Overloaded_Entity
(S
);
12646 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
12647 Check_Overriding_Indicator
12648 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
12650 -- The Ghost policy in effect at the point of declaration of a parent
12651 -- subprogram and an overriding subprogram must match
12652 -- (SPARK RM 6.9(17)).
12654 Check_Ghost_Overriding
(S
, Overridden_Subp
);
12656 -- If S is a derived operation for an untagged type then by
12657 -- definition it's not a dispatching operation (even if the parent
12658 -- operation was dispatching), so Check_Dispatching_Operation is not
12659 -- called in that case.
12661 if No
(Derived_Type
)
12662 or else Is_Tagged_Type
(Derived_Type
)
12664 Check_Dispatching_Operation
(S
, Empty
);
12668 -- If this is a user-defined equality operator that is not a derived
12669 -- subprogram, create the corresponding inequality. If the operation is
12670 -- dispatching, the expansion is done elsewhere, and we do not create
12671 -- an explicit inequality operation.
12673 <<Check_Inequality
>>
12674 if Chars
(S
) = Name_Op_Eq
12675 and then Etype
(S
) = Standard_Boolean
12676 and then Present
(Parent
(S
))
12677 and then not Is_Dispatching_Operation
(S
)
12679 Make_Inequality_Operator
(S
);
12680 Check_Untagged_Equality
(S
);
12682 end New_Overloaded_Entity
;
12684 ----------------------------------
12685 -- Preanalyze_Formal_Expression --
12686 ----------------------------------
12688 procedure Preanalyze_Formal_Expression
(N
: Node_Id
; T
: Entity_Id
) is
12689 Save_In_Spec_Expression
: constant Boolean := In_Spec_Expression
;
12691 In_Spec_Expression
:= True;
12692 Preanalyze_With_Freezing_And_Resolve
(N
, T
);
12693 In_Spec_Expression
:= Save_In_Spec_Expression
;
12694 end Preanalyze_Formal_Expression
;
12696 ---------------------
12697 -- Process_Formals --
12698 ---------------------
12700 procedure Process_Formals
12702 Related_Nod
: Node_Id
)
12704 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean;
12705 -- Determine whether an access type designates a type coming from a
12708 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean;
12709 -- Check whether the default has a class-wide type. After analysis the
12710 -- default has the type of the formal, so we must also check explicitly
12711 -- for an access attribute.
12713 ----------------------------------
12714 -- Designates_From_Limited_With --
12715 ----------------------------------
12717 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean is
12718 Desig
: Entity_Id
:= Typ
;
12721 if Is_Access_Type
(Desig
) then
12722 Desig
:= Directly_Designated_Type
(Desig
);
12725 if Is_Class_Wide_Type
(Desig
) then
12726 Desig
:= Root_Type
(Desig
);
12730 Ekind
(Desig
) = E_Incomplete_Type
12731 and then From_Limited_With
(Desig
);
12732 end Designates_From_Limited_With
;
12734 ---------------------------
12735 -- Is_Class_Wide_Default --
12736 ---------------------------
12738 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean is
12740 return Is_Class_Wide_Type
(Designated_Type
(Etype
(D
)))
12741 or else (Nkind
(D
) = N_Attribute_Reference
12742 and then Attribute_Name
(D
) = Name_Access
12743 and then Is_Class_Wide_Type
(Etype
(Prefix
(D
))));
12744 end Is_Class_Wide_Default
;
12748 Context
: constant Node_Id
:= Parent
(Parent
(T
));
12750 Formal
: Entity_Id
;
12751 Formal_Type
: Entity_Id
;
12752 Param_Spec
: Node_Id
;
12755 Num_Out_Params
: Nat
:= 0;
12756 First_Out_Param
: Entity_Id
:= Empty
;
12757 -- Used for setting Is_Only_Out_Parameter
12759 -- Start of processing for Process_Formals
12762 -- In order to prevent premature use of the formals in the same formal
12763 -- part, the Ekind is left undefined until all default expressions are
12764 -- analyzed. The Ekind is established in a separate loop at the end.
12766 Param_Spec
:= First
(T
);
12767 while Present
(Param_Spec
) loop
12768 Formal
:= Defining_Identifier
(Param_Spec
);
12769 Set_Never_Set_In_Source
(Formal
, True);
12770 Enter_Name
(Formal
);
12772 -- Case of ordinary parameters
12774 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
12775 Find_Type
(Parameter_Type
(Param_Spec
));
12776 Ptype
:= Parameter_Type
(Param_Spec
);
12778 if Ptype
= Error
then
12782 -- Protect against malformed parameter types
12784 if Nkind
(Ptype
) not in N_Has_Entity
then
12785 Formal_Type
:= Any_Type
;
12787 Formal_Type
:= Entity
(Ptype
);
12790 if Is_Incomplete_Type
(Formal_Type
)
12792 (Is_Class_Wide_Type
(Formal_Type
)
12793 and then Is_Incomplete_Type
(Root_Type
(Formal_Type
)))
12795 -- Ada 2005 (AI-326): Tagged incomplete types allowed in
12796 -- primitive operations, as long as their completion is
12797 -- in the same declarative part. If in the private part
12798 -- this means that the type cannot be a Taft-amendment type.
12799 -- Check is done on package exit. For access to subprograms,
12800 -- the use is legal for Taft-amendment types.
12802 -- Ada 2012: tagged incomplete types are allowed as generic
12803 -- formal types. They do not introduce dependencies and the
12804 -- corresponding generic subprogram does not have a delayed
12805 -- freeze, because it does not need a freeze node. However,
12806 -- it is still the case that untagged incomplete types cannot
12807 -- be Taft-amendment types and must be completed in private
12808 -- part, so the subprogram must appear in the list of private
12809 -- dependents of the type.
12811 if Is_Tagged_Type
(Formal_Type
)
12812 or else (Ada_Version
>= Ada_2012
12813 and then not From_Limited_With
(Formal_Type
)
12814 and then not Is_Generic_Type
(Formal_Type
))
12816 if Ekind
(Scope
(Current_Scope
)) = E_Package
12817 and then not Is_Generic_Type
(Formal_Type
)
12818 and then not Is_Class_Wide_Type
(Formal_Type
)
12820 if Nkind
(Parent
(T
)) not in
12821 N_Access_Function_Definition |
12822 N_Access_Procedure_Definition
12824 Append_Elmt
(Current_Scope
,
12825 Private_Dependents
(Base_Type
(Formal_Type
)));
12827 -- Freezing is delayed to ensure that Register_Prim
12828 -- will get called for this operation, which is needed
12829 -- in cases where static dispatch tables aren't built.
12830 -- (Note that the same is done for controlling access
12831 -- parameter cases in function Access_Definition.)
12833 if not Is_Thunk
(Current_Scope
) then
12834 Set_Has_Delayed_Freeze
(Current_Scope
);
12839 elsif Nkind
(Parent
(T
)) not in N_Access_Function_Definition
12840 | N_Access_Procedure_Definition
12842 -- AI05-0151: Tagged incomplete types are allowed in all
12843 -- formal parts. Untagged incomplete types are not allowed
12844 -- in bodies. Limited views of either kind are not allowed
12845 -- if there is no place at which the non-limited view can
12846 -- become available.
12848 -- Incomplete formal untagged types are not allowed in
12849 -- subprogram bodies (but are legal in their declarations).
12850 -- This excludes bodies created for null procedures, which
12851 -- are basic declarations.
12853 if Is_Generic_Type
(Formal_Type
)
12854 and then not Is_Tagged_Type
(Formal_Type
)
12855 and then Nkind
(Parent
(Related_Nod
)) = N_Subprogram_Body
12858 ("invalid use of formal incomplete type", Param_Spec
);
12860 elsif Ada_Version
>= Ada_2012
then
12861 if Is_Tagged_Type
(Formal_Type
)
12862 and then (not From_Limited_With
(Formal_Type
)
12863 or else not In_Package_Body
)
12867 elsif Nkind
(Context
) in N_Accept_Statement
12868 | N_Accept_Alternative
12870 or else (Nkind
(Context
) = N_Subprogram_Body
12871 and then Comes_From_Source
(Context
))
12874 ("invalid use of untagged incomplete type &",
12875 Ptype
, Formal_Type
);
12880 ("invalid use of incomplete type&",
12881 Param_Spec
, Formal_Type
);
12883 -- Further checks on the legality of incomplete types
12884 -- in formal parts are delayed until the freeze point
12885 -- of the enclosing subprogram or access to subprogram.
12889 elsif Ekind
(Formal_Type
) = E_Void
then
12891 ("premature use of&",
12892 Parameter_Type
(Param_Spec
), Formal_Type
);
12895 -- Ada 2012 (AI-142): Handle aliased parameters
12897 if Ada_Version
>= Ada_2012
12898 and then Aliased_Present
(Param_Spec
)
12900 Set_Is_Aliased
(Formal
);
12902 -- AI12-001: All aliased objects are considered to be specified
12903 -- as independently addressable (RM C.6(8.1/4)).
12905 Set_Is_Independent
(Formal
);
12908 -- Ada 2005 (AI-231): Create and decorate an internal subtype
12909 -- declaration corresponding to the null-excluding type of the
12910 -- formal in the enclosing scope. Finally, replace the parameter
12911 -- type of the formal with the internal subtype.
12913 if Ada_Version
>= Ada_2005
12914 and then Null_Exclusion_Present
(Param_Spec
)
12916 if not Is_Access_Type
(Formal_Type
) then
12918 ("`NOT NULL` allowed only for an access type", Param_Spec
);
12921 if Can_Never_Be_Null
(Formal_Type
)
12922 and then Comes_From_Source
(Related_Nod
)
12925 ("`NOT NULL` not allowed (& already excludes null)",
12926 Param_Spec
, Formal_Type
);
12930 Create_Null_Excluding_Itype
12932 Related_Nod
=> Related_Nod
,
12933 Scope_Id
=> Scope
(Current_Scope
));
12935 -- If the designated type of the itype is an itype that is
12936 -- not frozen yet, we set the Has_Delayed_Freeze attribute
12937 -- on the access subtype, to prevent order-of-elaboration
12938 -- issues in the backend.
12941 -- type T is access procedure;
12942 -- procedure Op (O : not null T);
12944 if Is_Itype
(Directly_Designated_Type
(Formal_Type
))
12946 not Is_Frozen
(Directly_Designated_Type
(Formal_Type
))
12948 Set_Has_Delayed_Freeze
(Formal_Type
);
12953 -- An access formal type
12957 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
12959 -- No need to continue if we already notified errors
12961 if No
(Formal_Type
) then
12965 -- Ada 2005 (AI-254)
12968 AD
: constant Node_Id
:=
12969 Access_To_Subprogram_Definition
12970 (Parameter_Type
(Param_Spec
));
12972 if Present
(AD
) and then Protected_Present
(AD
) then
12974 Replace_Anonymous_Access_To_Protected_Subprogram
12980 Set_Etype
(Formal
, Formal_Type
);
12982 -- Deal with default expression if present
12984 Default
:= Expression
(Param_Spec
);
12986 if Present
(Default
) then
12987 if Out_Present
(Param_Spec
) then
12989 ("default initialization only allowed for IN parameters",
12993 -- Do the special preanalysis of the expression (see section on
12994 -- "Handling of Default Expressions" in the spec of package Sem).
12996 Preanalyze_Formal_Expression
(Default
, Formal_Type
);
12998 -- An access to constant cannot be the default for
12999 -- an access parameter that is an access to variable.
13001 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
13002 and then not Is_Access_Constant
(Formal_Type
)
13003 and then Is_Access_Type
(Etype
(Default
))
13004 and then Is_Access_Constant
(Etype
(Default
))
13007 ("formal that is access to variable cannot be initialized "
13008 & "with an access-to-constant expression", Default
);
13011 -- Check that the designated type of an access parameter's default
13012 -- is not a class-wide type unless the parameter's designated type
13013 -- is also class-wide.
13015 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
13016 and then not Designates_From_Limited_With
(Formal_Type
)
13017 and then Is_Class_Wide_Default
(Default
)
13018 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
13021 ("access to class-wide expression not allowed here", Default
);
13024 -- Check incorrect use of dynamically tagged expressions
13026 if Is_Tagged_Type
(Formal_Type
) then
13027 Check_Dynamically_Tagged_Expression
13029 Typ
=> Formal_Type
,
13030 Related_Nod
=> Default
);
13034 -- Ada 2005 (AI-231): Static checks
13036 if Ada_Version
>= Ada_2005
13037 and then Is_Access_Type
(Etype
(Formal
))
13038 and then Can_Never_Be_Null
(Etype
(Formal
))
13040 Null_Exclusion_Static_Checks
(Param_Spec
);
13043 -- The following checks are relevant only when SPARK_Mode is on as
13044 -- these are not standard Ada legality rules.
13046 if SPARK_Mode
= On
then
13047 if Ekind
(Scope
(Formal
)) in E_Function | E_Generic_Function
then
13049 -- A function cannot have a parameter of mode IN OUT or OUT
13052 if Ekind
(Formal
) in E_In_Out_Parameter | E_Out_Parameter
then
13054 ("function cannot have parameter of mode `OUT` or "
13055 & "`IN OUT`", Formal
);
13058 -- A procedure cannot have an effectively volatile formal
13059 -- parameter of mode IN because it behaves as a constant
13060 -- (SPARK RM 7.1.3(4)).
13062 elsif Ekind
(Scope
(Formal
)) = E_Procedure
13063 and then Ekind
(Formal
) = E_In_Parameter
13064 and then Is_Effectively_Volatile
(Formal
)
13067 ("formal parameter of mode `IN` cannot be volatile", Formal
);
13071 -- Deal with aspects on formal parameters. Only Unreferenced is
13072 -- supported for the time being.
13074 if Has_Aspects
(Param_Spec
) then
13076 Aspect
: Node_Id
:= First
(Aspect_Specifications
(Param_Spec
));
13078 while Present
(Aspect
) loop
13079 if Chars
(Identifier
(Aspect
)) = Name_Unreferenced
then
13080 Set_Has_Pragma_Unreferenced
(Formal
);
13083 ("unsupported aspect& on parameter",
13084 Aspect
, Identifier
(Aspect
));
13096 -- If this is the formal part of a function specification, analyze the
13097 -- subtype mark in the context where the formals are visible but not
13098 -- yet usable, and may hide outer homographs.
13100 if Nkind
(Related_Nod
) = N_Function_Specification
then
13101 Analyze_Return_Type
(Related_Nod
);
13104 -- Now set the kind (mode) of each formal
13106 Param_Spec
:= First
(T
);
13107 while Present
(Param_Spec
) loop
13108 Formal
:= Defining_Identifier
(Param_Spec
);
13109 Set_Formal_Mode
(Formal
);
13111 if Ekind
(Formal
) = E_In_Parameter
then
13112 Default
:= Expression
(Param_Spec
);
13114 if Present
(Default
) then
13115 Set_Default_Value
(Formal
, Default
);
13117 if Is_Scalar_Type
(Etype
(Default
)) then
13118 if Nkind
(Parameter_Type
(Param_Spec
)) /=
13119 N_Access_Definition
13121 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
13125 (Related_Nod
, Parameter_Type
(Param_Spec
));
13128 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
13132 elsif Ekind
(Formal
) = E_Out_Parameter
then
13133 Num_Out_Params
:= Num_Out_Params
+ 1;
13135 if Num_Out_Params
= 1 then
13136 First_Out_Param
:= Formal
;
13139 elsif Ekind
(Formal
) = E_In_Out_Parameter
then
13140 Num_Out_Params
:= Num_Out_Params
+ 1;
13143 -- Skip remaining processing if formal type was in error
13145 if Etype
(Formal
) = Any_Type
or else Error_Posted
(Formal
) then
13146 goto Next_Parameter
;
13149 -- Force call by reference if aliased
13152 Conv
: constant Convention_Id
:= Convention
(Etype
(Formal
));
13154 if Is_Aliased
(Formal
) then
13155 Set_Mechanism
(Formal
, By_Reference
);
13157 -- Warn if user asked this to be passed by copy
13159 if Conv
= Convention_Ada_Pass_By_Copy
then
13161 ("cannot pass aliased parameter & by copy??", Formal
);
13164 -- Force mechanism if type has Convention Ada_Pass_By_Ref/Copy
13166 elsif Conv
= Convention_Ada_Pass_By_Copy
then
13167 Set_Mechanism
(Formal
, By_Copy
);
13169 elsif Conv
= Convention_Ada_Pass_By_Reference
then
13170 Set_Mechanism
(Formal
, By_Reference
);
13178 if Present
(First_Out_Param
) and then Num_Out_Params
= 1 then
13179 Set_Is_Only_Out_Parameter
(First_Out_Param
);
13181 end Process_Formals
;
13183 ----------------------------
13184 -- Reference_Body_Formals --
13185 ----------------------------
13187 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
) is
13192 if Error_Posted
(Spec
) then
13196 -- Iterate over both lists. They may be of different lengths if the two
13197 -- specs are not conformant.
13199 Fs
:= First_Formal
(Spec
);
13200 Fb
:= First_Formal
(Bod
);
13201 while Present
(Fs
) and then Present
(Fb
) loop
13202 Generate_Reference
(Fs
, Fb
, 'b');
13204 if Style_Check
then
13205 Style
.Check_Identifier
(Fb
, Fs
);
13208 Set_Spec_Entity
(Fb
, Fs
);
13209 Set_Referenced
(Fs
, False);
13213 end Reference_Body_Formals
;
13215 -------------------------
13216 -- Set_Actual_Subtypes --
13217 -------------------------
13219 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
13221 Formal
: Entity_Id
;
13223 First_Stmt
: Node_Id
:= Empty
;
13224 AS_Needed
: Boolean;
13227 -- If this is an empty initialization procedure, no need to create
13228 -- actual subtypes (small optimization).
13230 if Ekind
(Subp
) = E_Procedure
and then Is_Null_Init_Proc
(Subp
) then
13233 -- Within a predicate function we do not want to generate local
13234 -- subtypes that may generate nested predicate functions.
13236 elsif Is_Subprogram
(Subp
) and then Is_Predicate_Function
(Subp
) then
13240 -- The subtype declarations may freeze the formals. The body generated
13241 -- for an expression function is not a freeze point, so do not emit
13242 -- these declarations (small loss of efficiency in rare cases).
13244 if Nkind
(N
) = N_Subprogram_Body
13245 and then Was_Expression_Function
(N
)
13250 Formal
:= First_Formal
(Subp
);
13251 while Present
(Formal
) loop
13252 T
:= Etype
(Formal
);
13254 -- We never need an actual subtype for a constrained formal
13256 if Is_Constrained
(T
) then
13257 AS_Needed
:= False;
13259 -- If we have unknown discriminants, then we do not need an actual
13260 -- subtype, or more accurately we cannot figure it out. Note that
13261 -- all class-wide types have unknown discriminants.
13263 elsif Has_Unknown_Discriminants
(T
) then
13264 AS_Needed
:= False;
13266 -- At this stage we have an unconstrained type that may need an
13267 -- actual subtype. For sure the actual subtype is needed if we have
13268 -- an unconstrained array type. However, in an instance, the type
13269 -- may appear as a subtype of the full view, while the actual is
13270 -- in fact private (in which case no actual subtype is needed) so
13271 -- check the kind of the base type.
13273 elsif Is_Array_Type
(Base_Type
(T
)) then
13276 -- The only other case needing an actual subtype is an unconstrained
13277 -- record type which is an IN parameter (we cannot generate actual
13278 -- subtypes for the OUT or IN OUT case, since an assignment can
13279 -- change the discriminant values. However we exclude the case of
13280 -- initialization procedures, since discriminants are handled very
13281 -- specially in this context, see the section entitled "Handling of
13282 -- Discriminants" in Einfo.
13284 -- We also exclude the case of Discrim_SO_Functions (functions used
13285 -- in front-end layout mode for size/offset values), since in such
13286 -- functions only discriminants are referenced, and not only are such
13287 -- subtypes not needed, but they cannot always be generated, because
13288 -- of order of elaboration issues.
13290 elsif Is_Record_Type
(T
)
13291 and then Ekind
(Formal
) = E_In_Parameter
13292 and then Chars
(Formal
) /= Name_uInit
13293 and then not Is_Unchecked_Union
(T
)
13294 and then not Is_Discrim_SO_Function
(Subp
)
13298 -- All other cases do not need an actual subtype
13301 AS_Needed
:= False;
13304 -- Generate actual subtypes for unconstrained arrays and
13305 -- unconstrained discriminated records.
13308 if Nkind
(N
) = N_Accept_Statement
then
13310 -- If expansion is active, the formal is replaced by a local
13311 -- variable that renames the corresponding entry of the
13312 -- parameter block, and it is this local variable that may
13313 -- require an actual subtype.
13315 if Expander_Active
then
13316 Decl
:= Build_Actual_Subtype
(T
, Renamed_Object
(Formal
));
13318 Decl
:= Build_Actual_Subtype
(T
, Formal
);
13321 if Present
(Handled_Statement_Sequence
(N
)) then
13323 First
(Statements
(Handled_Statement_Sequence
(N
)));
13324 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
13325 Mark_Rewrite_Insertion
(Decl
);
13327 -- If the accept statement has no body, there will be no
13328 -- reference to the actuals, so no need to compute actual
13335 Decl
:= Build_Actual_Subtype
(T
, Formal
);
13336 Prepend
(Decl
, Declarations
(N
));
13337 Mark_Rewrite_Insertion
(Decl
);
13340 -- The declaration uses the bounds of an existing object, and
13341 -- therefore needs no constraint checks.
13343 Analyze
(Decl
, Suppress
=> All_Checks
);
13344 Set_Is_Actual_Subtype
(Defining_Identifier
(Decl
));
13346 -- We need to freeze manually the generated type when it is
13347 -- inserted anywhere else than in a declarative part.
13349 if Present
(First_Stmt
) then
13350 Insert_List_Before_And_Analyze
(First_Stmt
,
13351 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
13353 -- Ditto if the type has a dynamic predicate, because the
13354 -- generated function will mention the actual subtype. The
13355 -- predicate may come from an explicit aspect of be inherited.
13357 elsif Has_Predicates
(T
) then
13358 Insert_List_After_And_Analyze
(Decl
,
13359 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
13362 if Nkind
(N
) = N_Accept_Statement
13363 and then Expander_Active
13365 Set_Actual_Subtype
(Renamed_Object
(Formal
),
13366 Defining_Identifier
(Decl
));
13368 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
13372 Next_Formal
(Formal
);
13374 end Set_Actual_Subtypes
;
13376 ---------------------
13377 -- Set_Formal_Mode --
13378 ---------------------
13380 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
13381 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
13382 Id
: constant Entity_Id
:= Scope
(Formal_Id
);
13385 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
13386 -- since we ensure that corresponding actuals are always valid at the
13387 -- point of the call.
13389 if Out_Present
(Spec
) then
13391 or else Is_Subprogram_Or_Generic_Subprogram
(Id
)
13393 Set_Has_Out_Or_In_Out_Parameter
(Id
, True);
13396 if Ekind
(Id
) in E_Function | E_Generic_Function
then
13398 -- [IN] OUT parameters allowed for functions in Ada 2012
13400 if Ada_Version
>= Ada_2012
then
13402 -- Even in Ada 2012 operators can only have IN parameters
13404 if Is_Operator_Symbol_Name
(Chars
(Scope
(Formal_Id
))) then
13405 Error_Msg_N
("operators can only have IN parameters", Spec
);
13408 if In_Present
(Spec
) then
13409 Mutate_Ekind
(Formal_Id
, E_In_Out_Parameter
);
13411 Mutate_Ekind
(Formal_Id
, E_Out_Parameter
);
13414 -- But not in earlier versions of Ada
13417 Error_Msg_N
("functions can only have IN parameters", Spec
);
13418 Mutate_Ekind
(Formal_Id
, E_In_Parameter
);
13421 elsif In_Present
(Spec
) then
13422 Mutate_Ekind
(Formal_Id
, E_In_Out_Parameter
);
13425 Mutate_Ekind
(Formal_Id
, E_Out_Parameter
);
13426 Set_Is_True_Constant
(Formal_Id
, False);
13427 Set_Current_Value
(Formal_Id
, Empty
);
13431 Mutate_Ekind
(Formal_Id
, E_In_Parameter
);
13434 Set_Is_Not_Self_Hidden
(Formal_Id
);
13436 -- Set Is_Known_Non_Null for access parameters since the language
13437 -- guarantees that access parameters are always non-null. We also set
13438 -- Can_Never_Be_Null, since there is no way to change the value.
13440 if Nkind
(Parameter_Type
(Spec
)) = N_Access_Definition
then
13442 -- Ada 2005 (AI-231): In Ada 95, access parameters are always non-
13443 -- null; In Ada 2005, only if then null_exclusion is explicit.
13445 if Ada_Version
< Ada_2005
13446 or else Can_Never_Be_Null
(Etype
(Formal_Id
))
13448 Set_Is_Known_Non_Null
(Formal_Id
);
13449 Set_Can_Never_Be_Null
(Formal_Id
);
13452 -- Ada 2005 (AI-231): Null-exclusion access subtype
13454 elsif Is_Access_Type
(Etype
(Formal_Id
))
13455 and then Can_Never_Be_Null
(Etype
(Formal_Id
))
13457 Set_Is_Known_Non_Null
(Formal_Id
);
13459 -- We can also set Can_Never_Be_Null (thus preventing some junk
13460 -- access checks) for the case of an IN parameter, which cannot
13461 -- be changed, or for an IN OUT parameter, which can be changed but
13462 -- not to a null value. But for an OUT parameter, the initial value
13463 -- passed in can be null, so we can't set this flag in that case.
13465 if Ekind
(Formal_Id
) /= E_Out_Parameter
then
13466 Set_Can_Never_Be_Null
(Formal_Id
);
13470 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
13471 Set_Formal_Validity
(Formal_Id
);
13472 end Set_Formal_Mode
;
13474 -------------------------
13475 -- Set_Formal_Validity --
13476 -------------------------
13478 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
13480 -- If no validity checking, then we cannot assume anything about the
13481 -- validity of parameters, since we do not know there is any checking
13482 -- of the validity on the call side.
13484 if not Validity_Checks_On
then
13487 -- If validity checking for parameters is enabled, this means we are
13488 -- not supposed to make any assumptions about argument values.
13490 elsif Validity_Check_Parameters
then
13493 -- If we are checking in parameters, we will assume that the caller is
13494 -- also checking parameters, so we can assume the parameter is valid.
13496 elsif Ekind
(Formal_Id
) = E_In_Parameter
13497 and then Validity_Check_In_Params
13499 Set_Is_Known_Valid
(Formal_Id
, True);
13501 -- Similar treatment for IN OUT parameters
13503 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
13504 and then Validity_Check_In_Out_Params
13506 Set_Is_Known_Valid
(Formal_Id
, True);
13508 end Set_Formal_Validity
;
13510 ------------------------
13511 -- Subtype_Conformant --
13512 ------------------------
13514 function Subtype_Conformant
13515 (New_Id
: Entity_Id
;
13516 Old_Id
: Entity_Id
;
13517 Skip_Controlling_Formals
: Boolean := False) return Boolean
13521 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
,
13522 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
13524 end Subtype_Conformant
;
13526 ---------------------
13527 -- Type_Conformant --
13528 ---------------------
13530 function Type_Conformant
13531 (New_Id
: Entity_Id
;
13532 Old_Id
: Entity_Id
;
13533 Skip_Controlling_Formals
: Boolean := False) return Boolean
13537 May_Hide_Profile
:= False;
13539 (New_Id
, Old_Id
, Type_Conformant
, False, Result
,
13540 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
13542 end Type_Conformant
;
13544 -------------------------------
13545 -- Valid_Operator_Definition --
13546 -------------------------------
13548 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
13551 Id
: constant Name_Id
:= Chars
(Designator
);
13555 F
:= First_Formal
(Designator
);
13556 while Present
(F
) loop
13559 if Present
(Default_Value
(F
)) then
13561 ("default values not allowed for operator parameters",
13564 -- For function instantiations that are operators, we must check
13565 -- separately that the corresponding generic only has in-parameters.
13566 -- For subprogram declarations this is done in Set_Formal_Mode. Such
13567 -- an error could not arise in earlier versions of the language.
13569 elsif Ekind
(F
) /= E_In_Parameter
then
13570 Error_Msg_N
("operators can only have IN parameters", F
);
13576 -- Verify that user-defined operators have proper number of arguments
13577 -- First case of operators which can only be unary
13579 if Id
in Name_Op_Not | Name_Op_Abs
then
13582 -- Case of operators which can be unary or binary
13584 elsif Id
in Name_Op_Add | Name_Op_Subtract
then
13585 N_OK
:= (N
in 1 .. 2);
13587 -- All other operators can only be binary
13595 ("incorrect number of arguments for operator", Designator
);
13599 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
13600 and then not Is_Intrinsic_Subprogram
(Designator
)
13603 ("explicit definition of inequality not allowed", Designator
);
13605 end Valid_Operator_Definition
;