1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Contracts
; use Contracts
;
30 with Debug
; use Debug
;
31 with Einfo
; use Einfo
;
32 with Elists
; use Elists
;
33 with Errout
; use Errout
;
34 with Expander
; use Expander
;
35 with Exp_Ch6
; use Exp_Ch6
;
36 with Exp_Ch7
; use Exp_Ch7
;
37 with Exp_Ch9
; use Exp_Ch9
;
38 with Exp_Dbug
; use Exp_Dbug
;
39 with Exp_Disp
; use Exp_Disp
;
40 with Exp_Tss
; use Exp_Tss
;
41 with Exp_Util
; use Exp_Util
;
42 with Fname
; use Fname
;
43 with Freeze
; use Freeze
;
44 with Ghost
; use Ghost
;
45 with Inline
; use Inline
;
46 with Itypes
; use Itypes
;
47 with Lib
.Xref
; use Lib
.Xref
;
48 with Layout
; use Layout
;
49 with Namet
; use Namet
;
51 with Nlists
; use Nlists
;
52 with Nmake
; use Nmake
;
54 with Output
; use Output
;
55 with Restrict
; use Restrict
;
56 with Rident
; use Rident
;
57 with Rtsfind
; use Rtsfind
;
59 with Sem_Aux
; use Sem_Aux
;
60 with Sem_Cat
; use Sem_Cat
;
61 with Sem_Ch3
; use Sem_Ch3
;
62 with Sem_Ch4
; use Sem_Ch4
;
63 with Sem_Ch5
; use Sem_Ch5
;
64 with Sem_Ch8
; use Sem_Ch8
;
65 with Sem_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
.CN
; use Sinfo
.CN
;
83 with Snames
; use Snames
;
84 with Stringt
; use Stringt
;
86 with Stylesw
; use Stylesw
;
87 with Tbuild
; use Tbuild
;
88 with Uintp
; use Uintp
;
89 with Urealp
; use Urealp
;
90 with Validsw
; use Validsw
;
92 package body Sem_Ch6
is
94 May_Hide_Profile
: Boolean := False;
95 -- This flag is used to indicate that two formals in two subprograms being
96 -- checked for conformance differ only in that one is an access parameter
97 -- while the other is of a general access type with the same designated
98 -- type. In this case, if the rest of the signatures match, a call to
99 -- either subprogram may be ambiguous, which is worth a warning. The flag
100 -- is set in Compatible_Types, and the warning emitted in
101 -- New_Overloaded_Entity.
103 -----------------------
104 -- Local Subprograms --
105 -----------------------
107 procedure Analyze_Function_Return
(N
: Node_Id
);
108 -- Subsidiary to Analyze_Return_Statement. Called when the return statement
109 -- applies to a [generic] function.
111 procedure Analyze_Generic_Subprogram_Body
(N
: Node_Id
; Gen_Id
: Entity_Id
);
112 -- Analyze a generic subprogram body. N is the body to be analyzed, and
113 -- Gen_Id is the defining entity Id for the corresponding spec.
115 procedure Analyze_Null_Procedure
117 Is_Completion
: out Boolean);
118 -- A null procedure can be a declaration or (Ada 2012) a completion
120 procedure Analyze_Return_Statement
(N
: Node_Id
);
121 -- Common processing for simple and extended return statements
123 procedure Analyze_Return_Type
(N
: Node_Id
);
124 -- Subsidiary to Process_Formals: analyze subtype mark in function
125 -- specification in a context where the formals are visible and hide
128 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
);
129 -- Does all the real work of Analyze_Subprogram_Body. This is split out so
130 -- that we can use RETURN but not skip the debug output at the end.
132 function Can_Override_Operator
(Subp
: Entity_Id
) return Boolean;
133 -- Returns true if Subp can override a predefined operator.
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_Limited_Return
160 -- Check the appropriate (Ada 95 or Ada 2005) rules for returning limited
161 -- types. Used only for simple return statements. Expr is the expression
164 procedure Check_Subprogram_Order
(N
: Node_Id
);
165 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
166 -- the alpha ordering rule for N if this ordering requirement applicable.
168 procedure Check_Returns
172 Proc
: Entity_Id
:= Empty
);
173 -- Called to check for missing return statements in a function body, or for
174 -- returns present in a procedure body which has No_Return set. HSS is the
175 -- handled statement sequence for the subprogram body. This procedure
176 -- checks all flow paths to make sure they either have return (Mode = 'F',
177 -- used for functions) or do not have a return (Mode = 'P', used for
178 -- No_Return procedures). The flag Err is set if there are any control
179 -- paths not explicitly terminated by a return in the function case, and is
180 -- True otherwise. Proc is the entity for the procedure case and is used
181 -- in posting the warning message.
183 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
);
184 -- In Ada 2012, a primitive equality operator on an untagged record type
185 -- must appear before the type is frozen, and have the same visibility as
186 -- that of the type. This procedure checks that this rule is met, and
187 -- otherwise emits an error on the subprogram declaration and a warning
188 -- on the earlier freeze point if it is easy to locate. In Ada 2012 mode,
189 -- this routine outputs errors (or warnings if -gnatd.E is set). In earlier
190 -- versions of Ada, warnings are output if Warn_On_Ada_2012_Incompatibility
191 -- is set, otherwise the call has no effect.
193 procedure Enter_Overloaded_Entity
(S
: Entity_Id
);
194 -- This procedure makes S, a new overloaded entity, into the first visible
195 -- entity with that name.
197 function Is_Non_Overriding_Operation
199 New_E
: Entity_Id
) return Boolean;
200 -- Enforce the rule given in 12.3(18): a private operation in an instance
201 -- overrides an inherited operation only if the corresponding operation
202 -- was overriding in the generic. This needs to be checked for primitive
203 -- operations of types derived (in the generic unit) from formal private
204 -- or formal derived types.
206 procedure Make_Inequality_Operator
(S
: Entity_Id
);
207 -- Create the declaration for an inequality operator that is implicitly
208 -- created by a user-defined equality operator that yields a boolean.
210 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
);
211 -- Formal_Id is an formal parameter entity. This procedure deals with
212 -- setting the proper validity status for this entity, which depends on
213 -- the kind of parameter and the validity checking mode.
215 ---------------------------------------------
216 -- Analyze_Abstract_Subprogram_Declaration --
217 ---------------------------------------------
219 procedure Analyze_Abstract_Subprogram_Declaration
(N
: Node_Id
) is
220 Scop
: constant Entity_Id
:= Current_Scope
;
221 Subp_Id
: constant Entity_Id
:=
222 Analyze_Subprogram_Specification
(Specification
(N
));
225 Check_SPARK_05_Restriction
("abstract subprogram is not allowed", N
);
227 Generate_Definition
(Subp_Id
);
229 Set_Is_Abstract_Subprogram
(Subp_Id
);
230 New_Overloaded_Entity
(Subp_Id
);
231 Check_Delayed_Subprogram
(Subp_Id
);
233 Set_Categorization_From_Scope
(Subp_Id
, Scop
);
235 -- An abstract subprogram declared within a Ghost region is rendered
236 -- Ghost (SPARK RM 6.9(2)).
238 if Ghost_Mode
> None
then
239 Set_Is_Ghost_Entity
(Subp_Id
);
242 if Ekind
(Scope
(Subp_Id
)) = E_Protected_Type
then
243 Error_Msg_N
("abstract subprogram not allowed in protected type", N
);
245 -- Issue a warning if the abstract subprogram is neither a dispatching
246 -- operation nor an operation that overrides an inherited subprogram or
247 -- predefined operator, since this most likely indicates a mistake.
249 elsif Warn_On_Redundant_Constructs
250 and then not Is_Dispatching_Operation
(Subp_Id
)
251 and then not Present
(Overridden_Operation
(Subp_Id
))
252 and then (not Is_Operator_Symbol_Name
(Chars
(Subp_Id
))
253 or else Scop
/= Scope
(Etype
(First_Formal
(Subp_Id
))))
256 ("abstract subprogram is not dispatching or overriding?r?", N
);
259 Generate_Reference_To_Formals
(Subp_Id
);
260 Check_Eliminated
(Subp_Id
);
262 if Has_Aspects
(N
) then
263 Analyze_Aspect_Specifications
(N
, Subp_Id
);
265 end Analyze_Abstract_Subprogram_Declaration
;
267 ---------------------------------
268 -- Analyze_Expression_Function --
269 ---------------------------------
271 procedure Analyze_Expression_Function
(N
: Node_Id
) is
272 Expr
: constant Node_Id
:= Expression
(N
);
273 Loc
: constant Source_Ptr
:= Sloc
(N
);
274 LocX
: constant Source_Ptr
:= Sloc
(Expr
);
275 Spec
: constant Node_Id
:= Specification
(N
);
280 -- If the expression is a completion, Prev is the entity whose
281 -- declaration is completed. Def_Id is needed to analyze the spec.
289 -- This is one of the occasions on which we transform the tree during
290 -- semantic analysis. If this is a completion, transform the expression
291 -- function into an equivalent subprogram body, and analyze it.
293 -- Expression functions are inlined unconditionally. The back-end will
294 -- determine whether this is possible.
296 Inline_Processing_Required
:= True;
298 -- Create a specification for the generated body. This must be done
299 -- prior to the analysis of the initial declaration.
301 New_Spec
:= Copy_Subprogram_Spec
(Spec
);
302 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
304 -- If there are previous overloadable entities with the same name,
305 -- check whether any of them is completed by the expression function.
306 -- In a generic context a formal subprogram has no completion.
309 and then Is_Overloadable
(Prev
)
310 and then not Is_Formal_Subprogram
(Prev
)
312 Def_Id
:= Analyze_Subprogram_Specification
(Spec
);
313 Prev
:= Find_Corresponding_Spec
(N
);
315 -- The previous entity may be an expression function as well, in
316 -- which case the redeclaration is illegal.
319 and then Nkind
(Original_Node
(Unit_Declaration_Node
(Prev
))) =
320 N_Expression_Function
322 Error_Msg_Sloc
:= Sloc
(Prev
);
323 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
328 Ret
:= Make_Simple_Return_Statement
(LocX
, Expression
(N
));
331 Make_Subprogram_Body
(Loc
,
332 Specification
=> New_Spec
,
333 Declarations
=> Empty_List
,
334 Handled_Statement_Sequence
=>
335 Make_Handled_Sequence_Of_Statements
(LocX
,
336 Statements
=> New_List
(Ret
)));
337 Set_Was_Expression_Function
(New_Body
);
339 -- If the expression completes a generic subprogram, we must create a
340 -- separate node for the body, because at instantiation the original
341 -- node of the generic copy must be a generic subprogram body, and
342 -- cannot be a expression function. Otherwise we just rewrite the
343 -- expression with the non-generic body.
345 if Present
(Prev
) and then Ekind
(Prev
) = E_Generic_Function
then
346 Insert_After
(N
, New_Body
);
348 -- Propagate any aspects or pragmas that apply to the expression
349 -- function to the proper body when the expression function acts
352 if Has_Aspects
(N
) then
353 Move_Aspects
(N
, To
=> New_Body
);
356 Relocate_Pragmas_To_Body
(New_Body
);
358 Rewrite
(N
, Make_Null_Statement
(Loc
));
359 Set_Has_Completion
(Prev
, False);
362 Set_Is_Inlined
(Prev
);
364 -- If the expression function is a completion, the previous declaration
365 -- must come from source. We know already that it appears in the current
366 -- scope. The entity itself may be internally created if within a body
370 and then Comes_From_Source
(Parent
(Prev
))
371 and then not Is_Formal_Subprogram
(Prev
)
373 Set_Has_Completion
(Prev
, False);
374 Set_Is_Inlined
(Prev
);
376 -- An expression function that is a completion freezes the
377 -- expression. This means freezing the return type, and if it is
378 -- an access type, freezing its designated type as well.
380 -- Note that we cannot defer this freezing to the analysis of the
381 -- expression itself, because a freeze node might appear in a nested
382 -- scope, leading to an elaboration order issue in gigi.
384 Freeze_Before
(N
, Etype
(Prev
));
386 if Is_Access_Type
(Etype
(Prev
)) then
387 Freeze_Before
(N
, Designated_Type
(Etype
(Prev
)));
390 -- For navigation purposes, indicate that the function is a body
392 Generate_Reference
(Prev
, Defining_Entity
(N
), 'b', Force
=> True);
393 Rewrite
(N
, New_Body
);
395 -- Correct the parent pointer of the aspect specification list to
396 -- reference the rewritten node.
398 if Has_Aspects
(N
) then
399 Set_Parent
(Aspect_Specifications
(N
), N
);
402 -- Propagate any pragmas that apply to the expression function to the
403 -- proper body when the expression function acts as a completion.
404 -- Aspects are automatically transfered because of node rewriting.
406 Relocate_Pragmas_To_Body
(N
);
409 -- Prev is the previous entity with the same name, but it is can
410 -- be an unrelated spec that is not completed by the expression
411 -- function. In that case the relevant entity is the one in the body.
412 -- Not clear that the backend can inline it in this case ???
414 if Has_Completion
(Prev
) then
416 -- The formals of the expression function are body formals,
417 -- and do not appear in the ali file, which will only contain
418 -- references to the formals of the original subprogram spec.
425 F1
:= First_Formal
(Def_Id
);
426 F2
:= First_Formal
(Prev
);
428 while Present
(F1
) loop
429 Set_Spec_Entity
(F1
, F2
);
436 Set_Is_Inlined
(Defining_Entity
(New_Body
));
439 -- If this is not a completion, create both a declaration and a body, so
440 -- that the expression can be inlined whenever possible.
443 -- An expression function that is not a completion is not a
444 -- subprogram declaration, and thus cannot appear in a protected
447 if Nkind
(Parent
(N
)) = N_Protected_Definition
then
449 ("an expression function is not a legal protected operation", N
);
452 Rewrite
(N
, Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
));
454 -- Correct the parent pointer of the aspect specification list to
455 -- reference the rewritten node.
457 if Has_Aspects
(N
) then
458 Set_Parent
(Aspect_Specifications
(N
), N
);
462 Def_Id
:= Defining_Entity
(N
);
464 -- If aspect SPARK_Mode was specified on the body, it needs to be
465 -- repeated both on the generated spec and the body.
467 Asp
:= Find_Aspect
(Defining_Unit_Name
(Spec
), Aspect_SPARK_Mode
);
469 if Present
(Asp
) then
470 Asp
:= New_Copy_Tree
(Asp
);
471 Set_Analyzed
(Asp
, False);
472 Set_Aspect_Specifications
(New_Body
, New_List
(Asp
));
475 -- Within a generic pre-analyze the original expression for name
476 -- capture. The body is also generated but plays no role in
477 -- this because it is not part of the original source.
479 if Inside_A_Generic
then
480 Set_Has_Completion
(Def_Id
);
482 Install_Formals
(Def_Id
);
483 Preanalyze_Spec_Expression
(Expr
, Etype
(Def_Id
));
487 Set_Is_Inlined
(Defining_Entity
(N
));
489 -- Establish the linkages between the spec and the body. These are
490 -- used when the expression function acts as the prefix of attribute
491 -- 'Access in order to freeze the original expression which has been
492 -- moved to the generated body.
494 Set_Corresponding_Body
(N
, Defining_Entity
(New_Body
));
495 Set_Corresponding_Spec
(New_Body
, Defining_Entity
(N
));
497 -- To prevent premature freeze action, insert the new body at the end
498 -- of the current declarations, or at the end of the package spec.
499 -- However, resolve usage names now, to prevent spurious visibility
500 -- on later entities. Note that the function can now be called in
501 -- the current declarative part, which will appear to be prior to
502 -- the presence of the body in the code. There are nevertheless no
503 -- order of elaboration issues because all name resolution has taken
504 -- place at the point of declaration.
507 Decls
: List_Id
:= List_Containing
(N
);
508 Expr
: constant Node_Id
:= Expression
(Ret
);
509 Par
: constant Node_Id
:= Parent
(Decls
);
510 Typ
: constant Entity_Id
:= Etype
(Def_Id
);
513 -- If this is a wrapper created for in an instance for a formal
514 -- subprogram, insert body after declaration, to be analyzed when
515 -- the enclosing instance is analyzed.
518 and then Is_Generic_Actual_Subprogram
(Defining_Entity
(N
))
520 Insert_After
(N
, New_Body
);
523 if Nkind
(Par
) = N_Package_Specification
524 and then Decls
= Visible_Declarations
(Par
)
525 and then Present
(Private_Declarations
(Par
))
526 and then not Is_Empty_List
(Private_Declarations
(Par
))
528 Decls
:= Private_Declarations
(Par
);
531 Insert_After
(Last
(Decls
), New_Body
);
533 -- Preanalyze the expression for name capture, except in an
534 -- instance, where this has been done during generic analysis,
535 -- and will be redone when analyzing the body.
537 Set_Parent
(Expr
, Ret
);
539 Install_Formals
(Def_Id
);
541 if not In_Instance
then
542 Preanalyze_Spec_Expression
(Expr
, Typ
);
543 Check_Limited_Return
(Original_Node
(N
), Expr
, Typ
);
551 -- If the return expression is a static constant, we suppress warning
552 -- messages on unused formals, which in most cases will be noise.
554 Set_Is_Trivial_Subprogram
555 (Defining_Entity
(New_Body
), Is_OK_Static_Expression
(Expr
));
556 end Analyze_Expression_Function
;
558 ----------------------------------------
559 -- Analyze_Extended_Return_Statement --
560 ----------------------------------------
562 procedure Analyze_Extended_Return_Statement
(N
: Node_Id
) is
564 Check_Compiler_Unit
("extended return statement", N
);
565 Analyze_Return_Statement
(N
);
566 end Analyze_Extended_Return_Statement
;
568 ----------------------------
569 -- Analyze_Function_Call --
570 ----------------------------
572 procedure Analyze_Function_Call
(N
: Node_Id
) is
573 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
574 Func_Nam
: constant Node_Id
:= Name
(N
);
580 -- A call of the form A.B (X) may be an Ada 2005 call, which is
581 -- rewritten as B (A, X). If the rewriting is successful, the call
582 -- has been analyzed and we just return.
584 if Nkind
(Func_Nam
) = N_Selected_Component
585 and then Name
(N
) /= Func_Nam
586 and then Is_Rewrite_Substitution
(N
)
587 and then Present
(Etype
(N
))
592 -- If error analyzing name, then set Any_Type as result type and return
594 if Etype
(Func_Nam
) = Any_Type
then
595 Set_Etype
(N
, Any_Type
);
599 -- Otherwise analyze the parameters
601 if Present
(Actuals
) then
602 Actual
:= First
(Actuals
);
603 while Present
(Actual
) loop
605 Check_Parameterless_Call
(Actual
);
611 end Analyze_Function_Call
;
613 -----------------------------
614 -- Analyze_Function_Return --
615 -----------------------------
617 procedure Analyze_Function_Return
(N
: Node_Id
) is
618 Loc
: constant Source_Ptr
:= Sloc
(N
);
619 Stm_Entity
: constant Entity_Id
:= Return_Statement_Entity
(N
);
620 Scope_Id
: constant Entity_Id
:= Return_Applies_To
(Stm_Entity
);
622 R_Type
: constant Entity_Id
:= Etype
(Scope_Id
);
623 -- Function result subtype
625 procedure Check_Aggregate_Accessibility
(Aggr
: Node_Id
);
626 -- Apply legality rule of 6.5 (8.2) to the access discriminants of an
627 -- aggregate in a return statement.
629 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
);
630 -- Check that the return_subtype_indication properly matches the result
631 -- subtype of the function, as required by RM-6.5(5.1/2-5.3/2).
633 -----------------------------------
634 -- Check_Aggregate_Accessibility --
635 -----------------------------------
637 procedure Check_Aggregate_Accessibility
(Aggr
: Node_Id
) is
638 Typ
: constant Entity_Id
:= Etype
(Aggr
);
645 if Is_Record_Type
(Typ
) and then Has_Discriminants
(Typ
) then
646 Discr
:= First_Discriminant
(Typ
);
647 Assoc
:= First
(Component_Associations
(Aggr
));
648 while Present
(Discr
) loop
649 if Ekind
(Etype
(Discr
)) = E_Anonymous_Access_Type
then
650 Expr
:= Expression
(Assoc
);
651 if Nkind
(Expr
) = N_Attribute_Reference
652 and then Attribute_Name
(Expr
) /= Name_Unrestricted_Access
654 Obj
:= Prefix
(Expr
);
655 while Nkind_In
(Obj
, N_Indexed_Component
,
656 N_Selected_Component
)
661 -- No check needed for an aliased formal.
662 -- A run-time check may still be needed ???
664 if Is_Entity_Name
(Obj
)
665 and then Is_Formal
(Entity
(Obj
))
666 and then Is_Aliased
(Entity
(Obj
))
670 elsif Object_Access_Level
(Obj
) >
671 Scope_Depth
(Scope
(Scope_Id
))
674 ("access discriminant in return aggregate would be "
675 & "a dangling reference", Obj
);
680 Next_Discriminant
(Discr
);
683 end Check_Aggregate_Accessibility
;
685 -------------------------------------
686 -- Check_Return_Subtype_Indication --
687 -------------------------------------
689 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
) is
690 Return_Obj
: constant Node_Id
:= Defining_Identifier
(Obj_Decl
);
692 R_Stm_Type
: constant Entity_Id
:= Etype
(Return_Obj
);
693 -- Subtype given in the extended return statement (must match R_Type)
695 Subtype_Ind
: constant Node_Id
:=
696 Object_Definition
(Original_Node
(Obj_Decl
));
698 R_Type_Is_Anon_Access
: constant Boolean :=
700 E_Anonymous_Access_Subprogram_Type
,
701 E_Anonymous_Access_Protected_Subprogram_Type
,
702 E_Anonymous_Access_Type
);
703 -- True if return type of the function is an anonymous access type
704 -- Can't we make Is_Anonymous_Access_Type in einfo ???
706 R_Stm_Type_Is_Anon_Access
: constant Boolean :=
707 Ekind_In
(R_Stm_Type
,
708 E_Anonymous_Access_Subprogram_Type
,
709 E_Anonymous_Access_Protected_Subprogram_Type
,
710 E_Anonymous_Access_Type
);
711 -- True if type of the return object is an anonymous access type
713 procedure Error_No_Match
(N
: Node_Id
);
714 -- Output error messages for case where types do not statically
715 -- match. N is the location for the messages.
721 procedure Error_No_Match
(N
: Node_Id
) is
724 ("subtype must statically match function result subtype", N
);
726 if not Predicates_Match
(R_Stm_Type
, R_Type
) then
727 Error_Msg_Node_2
:= R_Type
;
729 ("\predicate of& does not match predicate of&",
734 -- Start of processing for Check_Return_Subtype_Indication
737 -- First, avoid cascaded errors
739 if Error_Posted
(Obj_Decl
) or else Error_Posted
(Subtype_Ind
) then
743 -- "return access T" case; check that the return statement also has
744 -- "access T", and that the subtypes statically match:
745 -- if this is an access to subprogram the signatures must match.
747 if R_Type_Is_Anon_Access
then
748 if R_Stm_Type_Is_Anon_Access
then
750 Ekind
(Designated_Type
(R_Stm_Type
)) /= E_Subprogram_Type
752 if Base_Type
(Designated_Type
(R_Stm_Type
)) /=
753 Base_Type
(Designated_Type
(R_Type
))
754 or else not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
)
756 Error_No_Match
(Subtype_Mark
(Subtype_Ind
));
760 -- For two anonymous access to subprogram types, the
761 -- types themselves must be type conformant.
763 if not Conforming_Types
764 (R_Stm_Type
, R_Type
, Fully_Conformant
)
766 Error_No_Match
(Subtype_Ind
);
771 Error_Msg_N
("must use anonymous access type", Subtype_Ind
);
774 -- If the return object is of an anonymous access type, then report
775 -- an error if the function's result type is not also anonymous.
777 elsif R_Stm_Type_Is_Anon_Access
778 and then not R_Type_Is_Anon_Access
780 Error_Msg_N
("anonymous access not allowed for function with "
781 & "named access result", Subtype_Ind
);
783 -- Subtype indication case: check that the return object's type is
784 -- covered by the result type, and that the subtypes statically match
785 -- when the result subtype is constrained. Also handle record types
786 -- with unknown discriminants for which we have built the underlying
787 -- record view. Coverage is needed to allow specific-type return
788 -- objects when the result type is class-wide (see AI05-32).
790 elsif Covers
(Base_Type
(R_Type
), Base_Type
(R_Stm_Type
))
791 or else (Is_Underlying_Record_View
(Base_Type
(R_Stm_Type
))
795 Underlying_Record_View
(Base_Type
(R_Stm_Type
))))
797 -- A null exclusion may be present on the return type, on the
798 -- function specification, on the object declaration or on the
801 if Is_Access_Type
(R_Type
)
803 (Can_Never_Be_Null
(R_Type
)
804 or else Null_Exclusion_Present
(Parent
(Scope_Id
))) /=
805 Can_Never_Be_Null
(R_Stm_Type
)
807 Error_No_Match
(Subtype_Ind
);
810 -- AI05-103: for elementary types, subtypes must statically match
812 if Is_Constrained
(R_Type
)
813 or else Is_Access_Type
(R_Type
)
815 if not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
) then
816 Error_No_Match
(Subtype_Ind
);
820 -- All remaining cases are illegal
822 -- Note: previous versions of this subprogram allowed the return
823 -- value to be the ancestor of the return type if the return type
824 -- was a null extension. This was plainly incorrect.
828 ("wrong type for return_subtype_indication", Subtype_Ind
);
830 end Check_Return_Subtype_Indication
;
832 ---------------------
833 -- Local Variables --
834 ---------------------
839 -- Start of processing for Analyze_Function_Return
842 Set_Return_Present
(Scope_Id
);
844 if Nkind
(N
) = N_Simple_Return_Statement
then
845 Expr
:= Expression
(N
);
847 -- Guard against a malformed expression. The parser may have tried to
848 -- recover but the node is not analyzable.
850 if Nkind
(Expr
) = N_Error
then
851 Set_Etype
(Expr
, Any_Type
);
852 Expander_Mode_Save_And_Set
(False);
856 -- The resolution of a controlled [extension] aggregate associated
857 -- with a return statement creates a temporary which needs to be
858 -- finalized on function exit. Wrap the return statement inside a
859 -- block so that the finalization machinery can detect this case.
860 -- This early expansion is done only when the return statement is
861 -- not part of a handled sequence of statements.
863 if Nkind_In
(Expr
, N_Aggregate
,
864 N_Extension_Aggregate
)
865 and then Needs_Finalization
(R_Type
)
866 and then Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
869 Make_Block_Statement
(Loc
,
870 Handled_Statement_Sequence
=>
871 Make_Handled_Sequence_Of_Statements
(Loc
,
872 Statements
=> New_List
(Relocate_Node
(N
)))));
880 -- Ada 2005 (AI-251): If the type of the returned object is
881 -- an access to an interface type then we add an implicit type
882 -- conversion to force the displacement of the "this" pointer to
883 -- reference the secondary dispatch table. We cannot delay the
884 -- generation of this implicit conversion until the expansion
885 -- because in this case the type resolution changes the decoration
886 -- of the expression node to match R_Type; by contrast, if the
887 -- returned object is a class-wide interface type then it is too
888 -- early to generate here the implicit conversion since the return
889 -- statement may be rewritten by the expander into an extended
890 -- return statement whose expansion takes care of adding the
891 -- implicit type conversion to displace the pointer to the object.
894 and then Serious_Errors_Detected
= 0
895 and then Is_Access_Type
(R_Type
)
896 and then Nkind
(Expr
) /= N_Null
897 and then Is_Interface
(Designated_Type
(R_Type
))
898 and then Is_Progenitor
(Designated_Type
(R_Type
),
899 Designated_Type
(Etype
(Expr
)))
901 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
905 Resolve
(Expr
, R_Type
);
906 Check_Limited_Return
(N
, Expr
, R_Type
);
908 if Present
(Expr
) and then Nkind
(Expr
) = N_Aggregate
then
909 Check_Aggregate_Accessibility
(Expr
);
913 -- RETURN only allowed in SPARK as the last statement in function
915 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
917 (Nkind
(Parent
(Parent
(N
))) /= N_Subprogram_Body
918 or else Present
(Next
(N
)))
920 Check_SPARK_05_Restriction
921 ("RETURN should be the last statement in function", N
);
925 Check_SPARK_05_Restriction
("extended RETURN is not allowed", N
);
926 Obj_Decl
:= Last
(Return_Object_Declarations
(N
));
928 -- Analyze parts specific to extended_return_statement:
931 Has_Aliased
: constant Boolean := Aliased_Present
(Obj_Decl
);
932 HSS
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
935 Expr
:= Expression
(Obj_Decl
);
937 -- Note: The check for OK_For_Limited_Init will happen in
938 -- Analyze_Object_Declaration; we treat it as a normal
939 -- object declaration.
941 Set_Is_Return_Object
(Defining_Identifier
(Obj_Decl
));
944 Check_Return_Subtype_Indication
(Obj_Decl
);
946 if Present
(HSS
) then
949 if Present
(Exception_Handlers
(HSS
)) then
951 -- ???Has_Nested_Block_With_Handler needs to be set.
952 -- Probably by creating an actual N_Block_Statement.
953 -- Probably in Expand.
959 -- Mark the return object as referenced, since the return is an
960 -- implicit reference of the object.
962 Set_Referenced
(Defining_Identifier
(Obj_Decl
));
964 Check_References
(Stm_Entity
);
966 -- Check RM 6.5 (5.9/3)
969 if Ada_Version
< Ada_2012
then
971 -- Shouldn't this test Warn_On_Ada_2012_Compatibility ???
972 -- Can it really happen (extended return???)
975 ("aliased only allowed for limited return objects "
976 & "in Ada 2012??", N
);
978 elsif not Is_Limited_View
(R_Type
) then
980 ("aliased only allowed for limited return objects", N
);
986 -- Case of Expr present
990 -- Defend against previous errors
992 and then Nkind
(Expr
) /= N_Empty
993 and then Present
(Etype
(Expr
))
995 -- Apply constraint check. Note that this is done before the implicit
996 -- conversion of the expression done for anonymous access types to
997 -- ensure correct generation of the null-excluding check associated
998 -- with null-excluding expressions found in return statements.
1000 Apply_Constraint_Check
(Expr
, R_Type
);
1002 -- Ada 2005 (AI-318-02): When the result type is an anonymous access
1003 -- type, apply an implicit conversion of the expression to that type
1004 -- to force appropriate static and run-time accessibility checks.
1006 if Ada_Version
>= Ada_2005
1007 and then Ekind
(R_Type
) = E_Anonymous_Access_Type
1009 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
1010 Analyze_And_Resolve
(Expr
, R_Type
);
1012 -- If this is a local anonymous access to subprogram, the
1013 -- accessibility check can be applied statically. The return is
1014 -- illegal if the access type of the return expression is declared
1015 -- inside of the subprogram (except if it is the subtype indication
1016 -- of an extended return statement).
1018 elsif Ekind
(R_Type
) = E_Anonymous_Access_Subprogram_Type
then
1019 if not Comes_From_Source
(Current_Scope
)
1020 or else Ekind
(Current_Scope
) = E_Return_Statement
1025 Scope_Depth
(Scope
(Etype
(Expr
))) >= Scope_Depth
(Scope_Id
)
1027 Error_Msg_N
("cannot return local access to subprogram", N
);
1030 -- The expression cannot be of a formal incomplete type
1032 elsif Ekind
(Etype
(Expr
)) = E_Incomplete_Type
1033 and then Is_Generic_Type
(Etype
(Expr
))
1036 ("cannot return expression of a formal incomplete type", N
);
1039 -- If the result type is class-wide, then check that the return
1040 -- expression's type is not declared at a deeper level than the
1041 -- function (RM05-6.5(5.6/2)).
1043 if Ada_Version
>= Ada_2005
1044 and then Is_Class_Wide_Type
(R_Type
)
1046 if Type_Access_Level
(Etype
(Expr
)) >
1047 Subprogram_Access_Level
(Scope_Id
)
1050 ("level of return expression type is deeper than "
1051 & "class-wide function!", Expr
);
1055 -- Check incorrect use of dynamically tagged expression
1057 if Is_Tagged_Type
(R_Type
) then
1058 Check_Dynamically_Tagged_Expression
1064 -- ??? A real run-time accessibility check is needed in cases
1065 -- involving dereferences of access parameters. For now we just
1066 -- check the static cases.
1068 if (Ada_Version
< Ada_2005
or else Debug_Flag_Dot_L
)
1069 and then Is_Limited_View
(Etype
(Scope_Id
))
1070 and then Object_Access_Level
(Expr
) >
1071 Subprogram_Access_Level
(Scope_Id
)
1073 -- Suppress the message in a generic, where the rewriting
1076 if Inside_A_Generic
then
1081 Make_Raise_Program_Error
(Loc
,
1082 Reason
=> PE_Accessibility_Check_Failed
));
1085 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1086 Error_Msg_N
("cannot return a local value by reference<<", N
);
1087 Error_Msg_NE
("\& [<<", N
, Standard_Program_Error
);
1091 if Known_Null
(Expr
)
1092 and then Nkind
(Parent
(Scope_Id
)) = N_Function_Specification
1093 and then Null_Exclusion_Present
(Parent
(Scope_Id
))
1095 Apply_Compile_Time_Constraint_Error
1097 Msg
=> "(Ada 2005) null not allowed for "
1098 & "null-excluding return??",
1099 Reason
=> CE_Null_Not_Allowed
);
1102 -- RM 6.5 (5.4/3): accessibility checks also apply if the return object
1103 -- has no initializing expression.
1105 elsif Ada_Version
> Ada_2005
and then Is_Class_Wide_Type
(R_Type
) then
1106 if Type_Access_Level
(Etype
(Defining_Identifier
(Obj_Decl
))) >
1107 Subprogram_Access_Level
(Scope_Id
)
1110 ("level of return expression type is deeper than "
1111 & "class-wide function!", Obj_Decl
);
1114 end Analyze_Function_Return
;
1116 -------------------------------------
1117 -- Analyze_Generic_Subprogram_Body --
1118 -------------------------------------
1120 procedure Analyze_Generic_Subprogram_Body
1124 Gen_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Gen_Id
);
1125 Kind
: constant Entity_Kind
:= Ekind
(Gen_Id
);
1126 Body_Id
: Entity_Id
;
1131 -- Copy body and disable expansion while analyzing the generic For a
1132 -- stub, do not copy the stub (which would load the proper body), this
1133 -- will be done when the proper body is analyzed.
1135 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1136 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
1139 -- Once the contents of the generic copy and the template are
1140 -- swapped, do the same for their respective aspect specifications.
1142 Exchange_Aspects
(N
, New_N
);
1144 -- Collect all contract-related source pragmas found within the
1145 -- template and attach them to the contract of the subprogram body.
1146 -- This contract is used in the capture of global references within
1149 Create_Generic_Contract
(N
);
1154 Spec
:= Specification
(N
);
1156 -- Within the body of the generic, the subprogram is callable, and
1157 -- behaves like the corresponding non-generic unit.
1159 Body_Id
:= Defining_Entity
(Spec
);
1161 if Kind
= E_Generic_Procedure
1162 and then Nkind
(Spec
) /= N_Procedure_Specification
1164 Error_Msg_N
("invalid body for generic procedure ", Body_Id
);
1167 elsif Kind
= E_Generic_Function
1168 and then Nkind
(Spec
) /= N_Function_Specification
1170 Error_Msg_N
("invalid body for generic function ", Body_Id
);
1174 Set_Corresponding_Body
(Gen_Decl
, Body_Id
);
1176 if Has_Completion
(Gen_Id
)
1177 and then Nkind
(Parent
(N
)) /= N_Subunit
1179 Error_Msg_N
("duplicate generic body", N
);
1182 Set_Has_Completion
(Gen_Id
);
1185 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1186 Set_Ekind
(Defining_Entity
(Specification
(N
)), Kind
);
1188 Set_Corresponding_Spec
(N
, Gen_Id
);
1191 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1192 Set_Cunit_Entity
(Current_Sem_Unit
, Defining_Entity
(N
));
1195 -- Make generic parameters immediately visible in the body. They are
1196 -- needed to process the formals declarations. Then make the formals
1197 -- visible in a separate step.
1199 Push_Scope
(Gen_Id
);
1203 First_Ent
: Entity_Id
;
1206 First_Ent
:= First_Entity
(Gen_Id
);
1209 while Present
(E
) and then not Is_Formal
(E
) loop
1214 Set_Use
(Generic_Formal_Declarations
(Gen_Decl
));
1216 -- Now generic formals are visible, and the specification can be
1217 -- analyzed, for subsequent conformance check.
1219 Body_Id
:= Analyze_Subprogram_Specification
(Spec
);
1221 -- Make formal parameters visible
1225 -- E is the first formal parameter, we loop through the formals
1226 -- installing them so that they will be visible.
1228 Set_First_Entity
(Gen_Id
, E
);
1229 while Present
(E
) loop
1235 -- Visible generic entity is callable within its own body
1237 Set_Ekind
(Gen_Id
, Ekind
(Body_Id
));
1238 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
1239 Set_Convention
(Body_Id
, Convention
(Gen_Id
));
1240 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Gen_Id
));
1241 Set_Scope
(Body_Id
, Scope
(Gen_Id
));
1243 -- Inherit the "ghostness" of the generic spec. Note that this
1244 -- property is not directly inherited as the body may be subject
1245 -- to a different Ghost assertion policy.
1247 if Ghost_Mode
> None
or else Is_Ghost_Entity
(Gen_Id
) then
1248 Set_Is_Ghost_Entity
(Body_Id
);
1250 -- The Ghost policy in effect at the point of declaration and at
1251 -- the point of completion must match (SPARK RM 6.9(14)).
1253 Check_Ghost_Completion
(Gen_Id
, Body_Id
);
1256 Check_Fully_Conformant
(Body_Id
, Gen_Id
, Body_Id
);
1258 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1260 -- No body to analyze, so restore state of generic unit
1262 Set_Ekind
(Gen_Id
, Kind
);
1263 Set_Ekind
(Body_Id
, Kind
);
1265 if Present
(First_Ent
) then
1266 Set_First_Entity
(Gen_Id
, First_Ent
);
1273 -- If this is a compilation unit, it must be made visible explicitly,
1274 -- because the compilation of the declaration, unlike other library
1275 -- unit declarations, does not. If it is not a unit, the following
1276 -- is redundant but harmless.
1278 Set_Is_Immediately_Visible
(Gen_Id
);
1279 Reference_Body_Formals
(Gen_Id
, Body_Id
);
1281 if Is_Child_Unit
(Gen_Id
) then
1282 Generate_Reference
(Gen_Id
, Scope
(Gen_Id
), 'k', False);
1285 Set_Actual_Subtypes
(N
, Current_Scope
);
1287 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
1288 Set_SPARK_Pragma_Inherited
(Body_Id
);
1290 -- Analyze any aspect specifications that appear on the generic
1293 if Has_Aspects
(N
) then
1294 Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
);
1297 Analyze_Declarations
(Declarations
(N
));
1300 -- Process the contract of the subprogram body after all declarations
1301 -- have been analyzed. This ensures that any contract-related pragmas
1302 -- are available through the N_Contract node of the body.
1304 Analyze_Entry_Or_Subprogram_Body_Contract
(Body_Id
);
1306 Analyze
(Handled_Statement_Sequence
(N
));
1307 Save_Global_References
(Original_Node
(N
));
1309 -- Prior to exiting the scope, include generic formals again (if any
1310 -- are present) in the set of local entities.
1312 if Present
(First_Ent
) then
1313 Set_First_Entity
(Gen_Id
, First_Ent
);
1316 Check_References
(Gen_Id
);
1319 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Current_Scope
);
1321 Check_Subprogram_Order
(N
);
1323 -- Outside of its body, unit is generic again
1325 Set_Ekind
(Gen_Id
, Kind
);
1326 Generate_Reference
(Gen_Id
, Body_Id
, 'b', Set_Ref
=> False);
1329 Style
.Check_Identifier
(Body_Id
, Gen_Id
);
1333 end Analyze_Generic_Subprogram_Body
;
1335 ----------------------------
1336 -- Analyze_Null_Procedure --
1337 ----------------------------
1339 procedure Analyze_Null_Procedure
1341 Is_Completion
: out Boolean)
1343 Loc
: constant Source_Ptr
:= Sloc
(N
);
1344 Spec
: constant Node_Id
:= Specification
(N
);
1345 Designator
: Entity_Id
;
1347 Null_Body
: Node_Id
:= Empty
;
1351 -- Capture the profile of the null procedure before analysis, for
1352 -- expansion at the freeze point and at each point of call. The body is
1353 -- used if the procedure has preconditions, or if it is a completion. In
1354 -- the first case the body is analyzed at the freeze point, in the other
1355 -- it replaces the null procedure declaration.
1358 Make_Subprogram_Body
(Loc
,
1359 Specification
=> New_Copy_Tree
(Spec
),
1360 Declarations
=> New_List
,
1361 Handled_Statement_Sequence
=>
1362 Make_Handled_Sequence_Of_Statements
(Loc
,
1363 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
1365 -- Create new entities for body and formals
1367 Set_Defining_Unit_Name
(Specification
(Null_Body
),
1368 Make_Defining_Identifier
1369 (Sloc
(Defining_Entity
(N
)),
1370 Chars
(Defining_Entity
(N
))));
1372 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1373 while Present
(Form
) loop
1374 Set_Defining_Identifier
(Form
,
1375 Make_Defining_Identifier
1376 (Sloc
(Defining_Identifier
(Form
)),
1377 Chars
(Defining_Identifier
(Form
))));
1381 -- Determine whether the null procedure may be a completion of a generic
1382 -- suprogram, in which case we use the new null body as the completion
1383 -- and set minimal semantic information on the original declaration,
1384 -- which is rewritten as a null statement.
1386 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
1388 if Present
(Prev
) and then Is_Generic_Subprogram
(Prev
) then
1389 Insert_Before
(N
, Null_Body
);
1390 Set_Ekind
(Defining_Entity
(N
), Ekind
(Prev
));
1392 Rewrite
(N
, Make_Null_Statement
(Loc
));
1393 Analyze_Generic_Subprogram_Body
(Null_Body
, Prev
);
1394 Is_Completion
:= True;
1398 -- Resolve the types of the formals now, because the freeze point
1399 -- may appear in a different context, e.g. an instantiation.
1401 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1402 while Present
(Form
) loop
1403 if Nkind
(Parameter_Type
(Form
)) /= N_Access_Definition
then
1404 Find_Type
(Parameter_Type
(Form
));
1407 No
(Access_To_Subprogram_Definition
(Parameter_Type
(Form
)))
1409 Find_Type
(Subtype_Mark
(Parameter_Type
(Form
)));
1412 -- The case of a null procedure with a formal that is an
1413 -- access_to_subprogram type, and that is used as an actual
1414 -- in an instantiation is left to the enthusiastic reader.
1423 -- If there are previous overloadable entities with the same name,
1424 -- check whether any of them is completed by the null procedure.
1426 if Present
(Prev
) and then Is_Overloadable
(Prev
) then
1427 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1428 Prev
:= Find_Corresponding_Spec
(N
);
1431 if No
(Prev
) or else not Comes_From_Source
(Prev
) then
1432 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1433 Set_Has_Completion
(Designator
);
1435 -- Signal to caller that this is a procedure declaration
1437 Is_Completion
:= False;
1439 -- Null procedures are always inlined, but generic formal subprograms
1440 -- which appear as such in the internal instance of formal packages,
1441 -- need no completion and are not marked Inline.
1444 and then Nkind
(N
) /= N_Formal_Concrete_Subprogram_Declaration
1446 Set_Corresponding_Body
(N
, Defining_Entity
(Null_Body
));
1447 Set_Body_To_Inline
(N
, Null_Body
);
1448 Set_Is_Inlined
(Designator
);
1452 -- The null procedure is a completion. We unconditionally rewrite
1453 -- this as a null body (even if expansion is not active), because
1454 -- there are various error checks that are applied on this body
1455 -- when it is analyzed (e.g. correct aspect placement).
1457 if Has_Completion
(Prev
) then
1458 Error_Msg_Sloc
:= Sloc
(Prev
);
1459 Error_Msg_NE
("duplicate body for & declared#", N
, Prev
);
1462 Is_Completion
:= True;
1463 Rewrite
(N
, Null_Body
);
1466 end Analyze_Null_Procedure
;
1468 -----------------------------
1469 -- Analyze_Operator_Symbol --
1470 -----------------------------
1472 -- An operator symbol such as "+" or "and" may appear in context where the
1473 -- literal denotes an entity name, such as "+"(x, y) or in context when it
1474 -- is just a string, as in (conjunction = "or"). In these cases the parser
1475 -- generates this node, and the semantics does the disambiguation. Other
1476 -- such case are actuals in an instantiation, the generic unit in an
1477 -- instantiation, and pragma arguments.
1479 procedure Analyze_Operator_Symbol
(N
: Node_Id
) is
1480 Par
: constant Node_Id
:= Parent
(N
);
1483 if (Nkind
(Par
) = N_Function_Call
and then N
= Name
(Par
))
1484 or else Nkind
(Par
) = N_Function_Instantiation
1485 or else (Nkind
(Par
) = N_Indexed_Component
and then N
= Prefix
(Par
))
1486 or else (Nkind
(Par
) = N_Pragma_Argument_Association
1487 and then not Is_Pragma_String_Literal
(Par
))
1488 or else Nkind
(Par
) = N_Subprogram_Renaming_Declaration
1489 or else (Nkind
(Par
) = N_Attribute_Reference
1490 and then Attribute_Name
(Par
) /= Name_Value
)
1492 Find_Direct_Name
(N
);
1495 Change_Operator_Symbol_To_String_Literal
(N
);
1498 end Analyze_Operator_Symbol
;
1500 -----------------------------------
1501 -- Analyze_Parameter_Association --
1502 -----------------------------------
1504 procedure Analyze_Parameter_Association
(N
: Node_Id
) is
1506 Analyze
(Explicit_Actual_Parameter
(N
));
1507 end Analyze_Parameter_Association
;
1509 ----------------------------
1510 -- Analyze_Procedure_Call --
1511 ----------------------------
1513 procedure Analyze_Procedure_Call
(N
: Node_Id
) is
1514 procedure Analyze_Call_And_Resolve
;
1515 -- Do Analyze and Resolve calls for procedure call
1516 -- At end, check illegal order dependence.
1518 ------------------------------
1519 -- Analyze_Call_And_Resolve --
1520 ------------------------------
1522 procedure Analyze_Call_And_Resolve
is
1524 if Nkind
(N
) = N_Procedure_Call_Statement
then
1526 Resolve
(N
, Standard_Void_Type
);
1530 end Analyze_Call_And_Resolve
;
1534 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
1535 Loc
: constant Source_Ptr
:= Sloc
(N
);
1536 P
: constant Node_Id
:= Name
(N
);
1540 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
1542 -- Start of processing for Analyze_Procedure_Call
1545 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
1546 -- a procedure call or an entry call. The prefix may denote an access
1547 -- to subprogram type, in which case an implicit dereference applies.
1548 -- If the prefix is an indexed component (without implicit dereference)
1549 -- then the construct denotes a call to a member of an entire family.
1550 -- If the prefix is a simple name, it may still denote a call to a
1551 -- parameterless member of an entry family. Resolution of these various
1552 -- interpretations is delicate.
1554 -- Do not analyze machine code statements to avoid rejecting them in
1557 if CodePeer_Mode
and then Nkind
(P
) = N_Qualified_Expression
then
1558 Set_Etype
(P
, Standard_Void_Type
);
1563 -- If this is a call of the form Obj.Op, the call may have been analyzed
1564 -- and possibly rewritten into a block, in which case we are done.
1566 if Analyzed
(N
) then
1570 -- If there is an error analyzing the name (which may have been
1571 -- rewritten if the original call was in prefix notation) then error
1572 -- has been emitted already, mark node and return.
1574 if Error_Posted
(N
) or else Etype
(Name
(N
)) = Any_Type
then
1575 Set_Etype
(N
, Any_Type
);
1579 -- A procedure call is Ghost when its name denotes a Ghost procedure.
1580 -- Set the mode now to ensure that any nodes generated during analysis
1581 -- and expansion are properly marked as Ghost.
1585 -- Otherwise analyze the parameters
1587 if Present
(Actuals
) then
1588 Actual
:= First
(Actuals
);
1590 while Present
(Actual
) loop
1592 Check_Parameterless_Call
(Actual
);
1597 -- Special processing for Elab_Spec, Elab_Body and Elab_Subp_Body calls
1599 if Nkind
(P
) = N_Attribute_Reference
1600 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Spec
,
1602 Name_Elab_Subp_Body
)
1604 if Present
(Actuals
) then
1606 ("no parameters allowed for this call", First
(Actuals
));
1610 Set_Etype
(N
, Standard_Void_Type
);
1613 elsif Is_Entity_Name
(P
)
1614 and then Is_Record_Type
(Etype
(Entity
(P
)))
1615 and then Remote_AST_I_Dereference
(P
)
1617 Ghost_Mode
:= Save_Ghost_Mode
;
1620 elsif Is_Entity_Name
(P
)
1621 and then Ekind
(Entity
(P
)) /= E_Entry_Family
1623 if Is_Access_Type
(Etype
(P
))
1624 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1625 and then No
(Actuals
)
1626 and then Comes_From_Source
(N
)
1628 Error_Msg_N
("missing explicit dereference in call", N
);
1631 Analyze_Call_And_Resolve
;
1633 -- If the prefix is the simple name of an entry family, this is a
1634 -- parameterless call from within the task body itself.
1636 elsif Is_Entity_Name
(P
)
1637 and then Nkind
(P
) = N_Identifier
1638 and then Ekind
(Entity
(P
)) = E_Entry_Family
1639 and then Present
(Actuals
)
1640 and then No
(Next
(First
(Actuals
)))
1642 -- Can be call to parameterless entry family. What appears to be the
1643 -- sole argument is in fact the entry index. Rewrite prefix of node
1644 -- accordingly. Source representation is unchanged by this
1648 Make_Indexed_Component
(Loc
,
1650 Make_Selected_Component
(Loc
,
1651 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(P
)), Loc
),
1652 Selector_Name
=> New_Occurrence_Of
(Entity
(P
), Loc
)),
1653 Expressions
=> Actuals
);
1654 Set_Name
(N
, New_N
);
1655 Set_Etype
(New_N
, Standard_Void_Type
);
1656 Set_Parameter_Associations
(N
, No_List
);
1657 Analyze_Call_And_Resolve
;
1659 elsif Nkind
(P
) = N_Explicit_Dereference
then
1660 if Ekind
(Etype
(P
)) = E_Subprogram_Type
then
1661 Analyze_Call_And_Resolve
;
1663 Error_Msg_N
("expect access to procedure in call", P
);
1666 -- The name can be a selected component or an indexed component that
1667 -- yields an access to subprogram. Such a prefix is legal if the call
1668 -- has parameter associations.
1670 elsif Is_Access_Type
(Etype
(P
))
1671 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1673 if Present
(Actuals
) then
1674 Analyze_Call_And_Resolve
;
1676 Error_Msg_N
("missing explicit dereference in call ", N
);
1679 -- If not an access to subprogram, then the prefix must resolve to the
1680 -- name of an entry, entry family, or protected operation.
1682 -- For the case of a simple entry call, P is a selected component where
1683 -- the prefix is the task and the selector name is the entry. A call to
1684 -- a protected procedure will have the same syntax. If the protected
1685 -- object contains overloaded operations, the entity may appear as a
1686 -- function, the context will select the operation whose type is Void.
1688 elsif Nkind
(P
) = N_Selected_Component
1689 and then Ekind_In
(Entity
(Selector_Name
(P
)), E_Entry
,
1693 Analyze_Call_And_Resolve
;
1695 elsif Nkind
(P
) = N_Selected_Component
1696 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
1697 and then Present
(Actuals
)
1698 and then No
(Next
(First
(Actuals
)))
1700 -- Can be call to parameterless entry family. What appears to be the
1701 -- sole argument is in fact the entry index. Rewrite prefix of node
1702 -- accordingly. Source representation is unchanged by this
1706 Make_Indexed_Component
(Loc
,
1707 Prefix
=> New_Copy
(P
),
1708 Expressions
=> Actuals
);
1709 Set_Name
(N
, New_N
);
1710 Set_Etype
(New_N
, Standard_Void_Type
);
1711 Set_Parameter_Associations
(N
, No_List
);
1712 Analyze_Call_And_Resolve
;
1714 -- For the case of a reference to an element of an entry family, P is
1715 -- an indexed component whose prefix is a selected component (task and
1716 -- entry family), and whose index is the entry family index.
1718 elsif Nkind
(P
) = N_Indexed_Component
1719 and then Nkind
(Prefix
(P
)) = N_Selected_Component
1720 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) = E_Entry_Family
1722 Analyze_Call_And_Resolve
;
1724 -- If the prefix is the name of an entry family, it is a call from
1725 -- within the task body itself.
1727 elsif Nkind
(P
) = N_Indexed_Component
1728 and then Nkind
(Prefix
(P
)) = N_Identifier
1729 and then Ekind
(Entity
(Prefix
(P
))) = E_Entry_Family
1732 Make_Selected_Component
(Loc
,
1733 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(Prefix
(P
))), Loc
),
1734 Selector_Name
=> New_Occurrence_Of
(Entity
(Prefix
(P
)), Loc
));
1735 Rewrite
(Prefix
(P
), New_N
);
1737 Analyze_Call_And_Resolve
;
1739 -- In Ada 2012. a qualified expression is a name, but it cannot be a
1740 -- procedure name, so the construct can only be a qualified expression.
1742 elsif Nkind
(P
) = N_Qualified_Expression
1743 and then Ada_Version
>= Ada_2012
1745 Rewrite
(N
, Make_Code_Statement
(Loc
, Expression
=> P
));
1748 -- Anything else is an error
1751 Error_Msg_N
("invalid procedure or entry call", N
);
1754 Ghost_Mode
:= Save_Ghost_Mode
;
1755 end Analyze_Procedure_Call
;
1757 ------------------------------
1758 -- Analyze_Return_Statement --
1759 ------------------------------
1761 procedure Analyze_Return_Statement
(N
: Node_Id
) is
1763 pragma Assert
(Nkind_In
(N
, N_Simple_Return_Statement
,
1764 N_Extended_Return_Statement
));
1766 Returns_Object
: constant Boolean :=
1767 Nkind
(N
) = N_Extended_Return_Statement
1769 (Nkind
(N
) = N_Simple_Return_Statement
1770 and then Present
(Expression
(N
)));
1771 -- True if we're returning something; that is, "return <expression>;"
1772 -- or "return Result : T [:= ...]". False for "return;". Used for error
1773 -- checking: If Returns_Object is True, N should apply to a function
1774 -- body; otherwise N should apply to a procedure body, entry body,
1775 -- accept statement, or extended return statement.
1777 function Find_What_It_Applies_To
return Entity_Id
;
1778 -- Find the entity representing the innermost enclosing body, accept
1779 -- statement, or extended return statement. If the result is a callable
1780 -- construct or extended return statement, then this will be the value
1781 -- of the Return_Applies_To attribute. Otherwise, the program is
1782 -- illegal. See RM-6.5(4/2).
1784 -----------------------------
1785 -- Find_What_It_Applies_To --
1786 -----------------------------
1788 function Find_What_It_Applies_To
return Entity_Id
is
1789 Result
: Entity_Id
:= Empty
;
1792 -- Loop outward through the Scope_Stack, skipping blocks, loops,
1793 -- and postconditions.
1795 for J
in reverse 0 .. Scope_Stack
.Last
loop
1796 Result
:= Scope_Stack
.Table
(J
).Entity
;
1797 exit when not Ekind_In
(Result
, E_Block
, E_Loop
)
1798 and then Chars
(Result
) /= Name_uPostconditions
;
1801 pragma Assert
(Present
(Result
));
1803 end Find_What_It_Applies_To
;
1805 -- Local declarations
1807 Scope_Id
: constant Entity_Id
:= Find_What_It_Applies_To
;
1808 Kind
: constant Entity_Kind
:= Ekind
(Scope_Id
);
1809 Loc
: constant Source_Ptr
:= Sloc
(N
);
1810 Stm_Entity
: constant Entity_Id
:=
1812 (E_Return_Statement
, Current_Scope
, Loc
, 'R');
1814 -- Start of processing for Analyze_Return_Statement
1817 Set_Return_Statement_Entity
(N
, Stm_Entity
);
1819 Set_Etype
(Stm_Entity
, Standard_Void_Type
);
1820 Set_Return_Applies_To
(Stm_Entity
, Scope_Id
);
1822 -- Place Return entity on scope stack, to simplify enforcement of 6.5
1823 -- (4/2): an inner return statement will apply to this extended return.
1825 if Nkind
(N
) = N_Extended_Return_Statement
then
1826 Push_Scope
(Stm_Entity
);
1829 -- Check that pragma No_Return is obeyed. Don't complain about the
1830 -- implicitly-generated return that is placed at the end.
1832 if No_Return
(Scope_Id
) and then Comes_From_Source
(N
) then
1833 Error_Msg_N
("RETURN statement not allowed (No_Return)", N
);
1836 -- Warn on any unassigned OUT parameters if in procedure
1838 if Ekind
(Scope_Id
) = E_Procedure
then
1839 Warn_On_Unassigned_Out_Parameter
(N
, Scope_Id
);
1842 -- Check that functions return objects, and other things do not
1844 if Kind
= E_Function
or else Kind
= E_Generic_Function
then
1845 if not Returns_Object
then
1846 Error_Msg_N
("missing expression in return from function", N
);
1849 elsif Kind
= E_Procedure
or else Kind
= E_Generic_Procedure
then
1850 if Returns_Object
then
1851 Error_Msg_N
("procedure cannot return value (use function)", N
);
1854 elsif Kind
= E_Entry
or else Kind
= E_Entry_Family
then
1855 if Returns_Object
then
1856 if Is_Protected_Type
(Scope
(Scope_Id
)) then
1857 Error_Msg_N
("entry body cannot return value", N
);
1859 Error_Msg_N
("accept statement cannot return value", N
);
1863 elsif Kind
= E_Return_Statement
then
1865 -- We are nested within another return statement, which must be an
1866 -- extended_return_statement.
1868 if Returns_Object
then
1869 if Nkind
(N
) = N_Extended_Return_Statement
then
1871 ("extended return statement cannot be nested (use `RETURN;`)",
1874 -- Case of a simple return statement with a value inside extended
1875 -- return statement.
1879 ("return nested in extended return statement cannot return "
1880 & "value (use `RETURN;`)", N
);
1885 Error_Msg_N
("illegal context for return statement", N
);
1888 if Ekind_In
(Kind
, E_Function
, E_Generic_Function
) then
1889 Analyze_Function_Return
(N
);
1891 elsif Ekind_In
(Kind
, E_Procedure
, E_Generic_Procedure
) then
1892 Set_Return_Present
(Scope_Id
);
1895 if Nkind
(N
) = N_Extended_Return_Statement
then
1899 Kill_Current_Values
(Last_Assignment_Only
=> True);
1900 Check_Unreachable_Code
(N
);
1902 Analyze_Dimension
(N
);
1903 end Analyze_Return_Statement
;
1905 -------------------------------------
1906 -- Analyze_Simple_Return_Statement --
1907 -------------------------------------
1909 procedure Analyze_Simple_Return_Statement
(N
: Node_Id
) is
1911 if Present
(Expression
(N
)) then
1912 Mark_Coextensions
(N
, Expression
(N
));
1915 Analyze_Return_Statement
(N
);
1916 end Analyze_Simple_Return_Statement
;
1918 -------------------------
1919 -- Analyze_Return_Type --
1920 -------------------------
1922 procedure Analyze_Return_Type
(N
: Node_Id
) is
1923 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
1924 Typ
: Entity_Id
:= Empty
;
1927 -- Normal case where result definition does not indicate an error
1929 if Result_Definition
(N
) /= Error
then
1930 if Nkind
(Result_Definition
(N
)) = N_Access_Definition
then
1931 Check_SPARK_05_Restriction
1932 ("access result is not allowed", Result_Definition
(N
));
1934 -- Ada 2005 (AI-254): Handle anonymous access to subprograms
1937 AD
: constant Node_Id
:=
1938 Access_To_Subprogram_Definition
(Result_Definition
(N
));
1940 if Present
(AD
) and then Protected_Present
(AD
) then
1941 Typ
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
1943 Typ
:= Access_Definition
(N
, Result_Definition
(N
));
1947 Set_Parent
(Typ
, Result_Definition
(N
));
1948 Set_Is_Local_Anonymous_Access
(Typ
);
1949 Set_Etype
(Designator
, Typ
);
1951 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1953 Null_Exclusion_Static_Checks
(N
);
1955 -- Subtype_Mark case
1958 Find_Type
(Result_Definition
(N
));
1959 Typ
:= Entity
(Result_Definition
(N
));
1960 Set_Etype
(Designator
, Typ
);
1962 -- Unconstrained array as result is not allowed in SPARK
1964 if Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
1965 Check_SPARK_05_Restriction
1966 ("returning an unconstrained array is not allowed",
1967 Result_Definition
(N
));
1970 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1972 Null_Exclusion_Static_Checks
(N
);
1974 -- If a null exclusion is imposed on the result type, then create
1975 -- a null-excluding itype (an access subtype) and use it as the
1976 -- function's Etype. Note that the null exclusion checks are done
1977 -- right before this, because they don't get applied to types that
1978 -- do not come from source.
1980 if Is_Access_Type
(Typ
) and then Null_Exclusion_Present
(N
) then
1981 Set_Etype
(Designator
,
1982 Create_Null_Excluding_Itype
1985 Scope_Id
=> Scope
(Current_Scope
)));
1987 -- The new subtype must be elaborated before use because
1988 -- it is visible outside of the function. However its base
1989 -- type may not be frozen yet, so the reference that will
1990 -- force elaboration must be attached to the freezing of
1993 -- If the return specification appears on a proper body,
1994 -- the subtype will have been created already on the spec.
1996 if Is_Frozen
(Typ
) then
1997 if Nkind
(Parent
(N
)) = N_Subprogram_Body
1998 and then Nkind
(Parent
(Parent
(N
))) = N_Subunit
2002 Build_Itype_Reference
(Etype
(Designator
), Parent
(N
));
2006 Ensure_Freeze_Node
(Typ
);
2009 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(N
));
2011 Set_Itype
(IR
, Etype
(Designator
));
2012 Append_Freeze_Actions
(Typ
, New_List
(IR
));
2017 Set_Etype
(Designator
, Typ
);
2020 if Ekind
(Typ
) = E_Incomplete_Type
2021 or else (Is_Class_Wide_Type
(Typ
)
2022 and then Ekind
(Root_Type
(Typ
)) = E_Incomplete_Type
)
2024 -- AI05-0151: Tagged incomplete types are allowed in all formal
2025 -- parts. Untagged incomplete types are not allowed in bodies.
2026 -- As a consequence, limited views cannot appear in a basic
2027 -- declaration that is itself within a body, because there is
2028 -- no point at which the non-limited view will become visible.
2030 if Ada_Version
>= Ada_2012
then
2031 if From_Limited_With
(Typ
) and then In_Package_Body
then
2033 ("invalid use of incomplete type&",
2034 Result_Definition
(N
), Typ
);
2036 -- The return type of a subprogram body cannot be of a
2037 -- formal incomplete type.
2039 elsif Is_Generic_Type
(Typ
)
2040 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
2043 ("return type cannot be a formal incomplete type",
2044 Result_Definition
(N
));
2046 elsif Is_Class_Wide_Type
(Typ
)
2047 and then Is_Generic_Type
(Root_Type
(Typ
))
2048 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
2051 ("return type cannot be a formal incomplete type",
2052 Result_Definition
(N
));
2054 elsif Is_Tagged_Type
(Typ
) then
2057 -- Use is legal in a thunk generated for an operation
2058 -- inherited from a progenitor.
2060 elsif Is_Thunk
(Designator
)
2061 and then Present
(Non_Limited_View
(Typ
))
2065 elsif Nkind
(Parent
(N
)) = N_Subprogram_Body
2066 or else Nkind_In
(Parent
(Parent
(N
)), N_Accept_Statement
,
2070 ("invalid use of untagged incomplete type&",
2074 -- The type must be completed in the current package. This
2075 -- is checked at the end of the package declaration when
2076 -- Taft-amendment types are identified. If the return type
2077 -- is class-wide, there is no required check, the type can
2078 -- be a bona fide TAT.
2080 if Ekind
(Scope
(Current_Scope
)) = E_Package
2081 and then In_Private_Part
(Scope
(Current_Scope
))
2082 and then not Is_Class_Wide_Type
(Typ
)
2084 Append_Elmt
(Designator
, Private_Dependents
(Typ
));
2089 ("invalid use of incomplete type&", Designator
, Typ
);
2094 -- Case where result definition does indicate an error
2097 Set_Etype
(Designator
, Any_Type
);
2099 end Analyze_Return_Type
;
2101 -----------------------------
2102 -- Analyze_Subprogram_Body --
2103 -----------------------------
2105 procedure Analyze_Subprogram_Body
(N
: Node_Id
) is
2106 Loc
: constant Source_Ptr
:= Sloc
(N
);
2107 Body_Spec
: constant Node_Id
:= Specification
(N
);
2108 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Spec
);
2111 if Debug_Flag_C
then
2112 Write_Str
("==> subprogram body ");
2113 Write_Name
(Chars
(Body_Id
));
2114 Write_Str
(" from ");
2115 Write_Location
(Loc
);
2120 Trace_Scope
(N
, Body_Id
, " Analyze subprogram: ");
2122 -- The real work is split out into the helper, so it can do "return;"
2123 -- without skipping the debug output:
2125 Analyze_Subprogram_Body_Helper
(N
);
2127 if Debug_Flag_C
then
2129 Write_Str
("<== subprogram body ");
2130 Write_Name
(Chars
(Body_Id
));
2131 Write_Str
(" from ");
2132 Write_Location
(Loc
);
2135 end Analyze_Subprogram_Body
;
2137 ------------------------------------
2138 -- Analyze_Subprogram_Body_Helper --
2139 ------------------------------------
2141 -- This procedure is called for regular subprogram bodies, generic bodies,
2142 -- and for subprogram stubs of both kinds. In the case of stubs, only the
2143 -- specification matters, and is used to create a proper declaration for
2144 -- the subprogram, or to perform conformance checks.
2146 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
) is
2147 Loc
: constant Source_Ptr
:= Sloc
(N
);
2148 Body_Spec
: Node_Id
:= Specification
(N
);
2149 Body_Id
: Entity_Id
:= Defining_Entity
(Body_Spec
);
2150 Prev_Id
: constant Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
2151 Conformant
: Boolean;
2153 Prot_Typ
: Entity_Id
:= Empty
;
2154 Spec_Id
: Entity_Id
;
2155 Spec_Decl
: Node_Id
:= Empty
;
2157 Last_Real_Spec_Entity
: Entity_Id
:= Empty
;
2158 -- When we analyze a separate spec, the entity chain ends up containing
2159 -- the formals, as well as any itypes generated during analysis of the
2160 -- default expressions for parameters, or the arguments of associated
2161 -- precondition/postcondition pragmas (which are analyzed in the context
2162 -- of the spec since they have visibility on formals).
2164 -- These entities belong with the spec and not the body. However we do
2165 -- the analysis of the body in the context of the spec (again to obtain
2166 -- visibility to the formals), and all the entities generated during
2167 -- this analysis end up also chained to the entity chain of the spec.
2168 -- But they really belong to the body, and there is circuitry to move
2169 -- them from the spec to the body.
2171 -- However, when we do this move, we don't want to move the real spec
2172 -- entities (first para above) to the body. The Last_Real_Spec_Entity
2173 -- variable points to the last real spec entity, so we only move those
2174 -- chained beyond that point. It is initialized to Empty to deal with
2175 -- the case where there is no separate spec.
2177 function Body_Has_Contract
return Boolean;
2178 -- Check whether unanalyzed body has an aspect or pragma that may
2179 -- generate a SPARK contract.
2181 function Body_Has_SPARK_Mode_On
return Boolean;
2182 -- Check whether SPARK_Mode On applies to the subprogram body, either
2183 -- because it is specified directly on the body, or because it is
2184 -- inherited from the enclosing subprogram or package.
2186 procedure Build_Subprogram_Declaration
;
2187 -- Create a matching subprogram declaration for subprogram body N
2189 procedure Check_Anonymous_Return
;
2190 -- Ada 2005: if a function returns an access type that denotes a task,
2191 -- or a type that contains tasks, we must create a master entity for
2192 -- the anonymous type, which typically will be used in an allocator
2193 -- in the body of the function.
2195 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
);
2196 -- Look ahead to recognize a pragma that may appear after the body.
2197 -- If there is a previous spec, check that it appears in the same
2198 -- declarative part. If the pragma is Inline_Always, perform inlining
2199 -- unconditionally, otherwise only if Front_End_Inlining is requested.
2200 -- If the body acts as a spec, and inlining is required, we create a
2201 -- subprogram declaration for it, in order to attach the body to inline.
2202 -- If pragma does not appear after the body, check whether there is
2203 -- an inline pragma before any local declarations.
2205 procedure Check_Missing_Return
;
2206 -- Checks for a function with a no return statements, and also performs
2207 -- the warning checks implemented by Check_Returns. In formal mode, also
2208 -- verify that a function ends with a RETURN and that a procedure does
2209 -- not contain any RETURN.
2211 function Disambiguate_Spec
return Entity_Id
;
2212 -- When a primitive is declared between the private view and the full
2213 -- view of a concurrent type which implements an interface, a special
2214 -- mechanism is used to find the corresponding spec of the primitive
2217 procedure Exchange_Limited_Views
(Subp_Id
: Entity_Id
);
2218 -- Ada 2012 (AI05-0151): Detect whether the profile of Subp_Id contains
2219 -- incomplete types coming from a limited context and swap their limited
2220 -- views with the non-limited ones.
2222 function Is_Private_Concurrent_Primitive
2223 (Subp_Id
: Entity_Id
) return Boolean;
2224 -- Determine whether subprogram Subp_Id is a primitive of a concurrent
2225 -- type that implements an interface and has a private view.
2227 procedure Set_Trivial_Subprogram
(N
: Node_Id
);
2228 -- Sets the Is_Trivial_Subprogram flag in both spec and body of the
2229 -- subprogram whose body is being analyzed. N is the statement node
2230 -- causing the flag to be set, if the following statement is a return
2231 -- of an entity, we mark the entity as set in source to suppress any
2232 -- warning on the stylized use of function stubs with a dummy return.
2234 procedure Verify_Overriding_Indicator
;
2235 -- If there was a previous spec, the entity has been entered in the
2236 -- current scope previously. If the body itself carries an overriding
2237 -- indicator, check that it is consistent with the known status of the
2240 -----------------------
2241 -- Body_Has_Contract --
2242 -----------------------
2244 function Body_Has_Contract
return Boolean is
2245 Decls
: constant List_Id
:= Declarations
(N
);
2249 -- Check for aspects that may generate a contract
2251 if Present
(Aspect_Specifications
(N
)) then
2252 Item
:= First
(Aspect_Specifications
(N
));
2253 while Present
(Item
) loop
2254 if Is_Subprogram_Contract_Annotation
(Item
) then
2262 -- Check for pragmas that may generate a contract
2264 if Present
(Decls
) then
2265 Item
:= First
(Decls
);
2266 while Present
(Item
) loop
2267 if Nkind
(Item
) = N_Pragma
2268 and then Is_Subprogram_Contract_Annotation
(Item
)
2278 end Body_Has_Contract
;
2280 ----------------------------
2281 -- Body_Has_SPARK_Mode_On --
2282 ----------------------------
2284 function Body_Has_SPARK_Mode_On
return Boolean is
2285 Decls
: constant List_Id
:= Declarations
(N
);
2289 -- Check for SPARK_Mode aspect
2291 if Present
(Aspect_Specifications
(N
)) then
2292 Item
:= First
(Aspect_Specifications
(N
));
2293 while Present
(Item
) loop
2294 if Get_Aspect_Id
(Item
) = Aspect_SPARK_Mode
then
2295 return Get_SPARK_Mode_From_Annotation
(Item
) = On
;
2302 -- Check for SPARK_Mode pragma
2304 if Present
(Decls
) then
2305 Item
:= First
(Decls
);
2306 while Present
(Item
) loop
2308 -- Pragmas that apply to a subprogram body are usually grouped
2309 -- together. Look for a potential pragma SPARK_Mode among them.
2311 if Nkind
(Item
) = N_Pragma
then
2312 if Get_Pragma_Id
(Item
) = Pragma_SPARK_Mode
then
2313 return Get_SPARK_Mode_From_Annotation
(Item
) = On
;
2316 -- Otherwise the first non-pragma declarative item terminates
2317 -- the region where pragma SPARK_Mode may appear.
2327 -- Otherwise, the applicable SPARK_Mode is inherited from the
2328 -- enclosing subprogram or package.
2330 return SPARK_Mode
= On
;
2331 end Body_Has_SPARK_Mode_On
;
2333 ----------------------------------
2334 -- Build_Subprogram_Declaration --
2335 ----------------------------------
2337 procedure Build_Subprogram_Declaration
is
2338 procedure Move_Pragmas
(From
: Node_Id
; To
: Node_Id
);
2339 -- Relocate certain categorization pragmas from the declarative list
2340 -- of subprogram body From and insert them after node To. The pragmas
2344 -- Volatile_Function
2350 procedure Move_Pragmas
(From
: Node_Id
; To
: Node_Id
) is
2352 Next_Decl
: Node_Id
;
2355 pragma Assert
(Nkind
(From
) = N_Subprogram_Body
);
2357 -- The destination node must be part of a list, as the pragmas are
2358 -- inserted after it.
2360 pragma Assert
(Is_List_Member
(To
));
2362 -- Inspect the declarations of the subprogram body looking for
2363 -- specific pragmas.
2365 Decl
:= First
(Declarations
(N
));
2366 while Present
(Decl
) loop
2367 Next_Decl
:= Next
(Decl
);
2369 if Nkind
(Decl
) = N_Pragma
2370 and then Nam_In
(Pragma_Name
(Decl
), Name_Ghost
,
2372 Name_Volatile_Function
)
2375 Insert_After
(To
, Decl
);
2385 Subp_Decl
: Node_Id
;
2387 -- Start of processing for Build_Subprogram_Declaration
2390 -- Create a matching subprogram spec using the profile of the body.
2391 -- The structure of the tree is identical, but has new entities for
2392 -- the defining unit name and formal parameters.
2395 Make_Subprogram_Declaration
(Loc
,
2396 Specification
=> Copy_Subprogram_Spec
(Body_Spec
));
2397 Set_Comes_From_Source
(Subp_Decl
, True);
2399 -- Relocate the aspects and relevant pragmas from the subprogram body
2400 -- to the generated spec because it acts as the initial declaration.
2402 Insert_Before
(N
, Subp_Decl
);
2403 Move_Aspects
(N
, To
=> Subp_Decl
);
2404 Move_Pragmas
(N
, To
=> Subp_Decl
);
2406 Analyze
(Subp_Decl
);
2408 -- Analyze any relocated source pragmas or pragmas created for aspect
2411 Decl
:= Next
(Subp_Decl
);
2412 while Present
(Decl
) loop
2414 -- Stop the search for pragmas once the body has been reached as
2415 -- this terminates the region where pragmas may appear.
2420 elsif Nkind
(Decl
) = N_Pragma
then
2427 Spec_Id
:= Defining_Entity
(Subp_Decl
);
2428 Set_Corresponding_Spec
(N
, Spec_Id
);
2430 -- Mark the generated spec as a source construct to ensure that all
2431 -- calls to it are properly registered in ALI files for GNATprove.
2433 Set_Comes_From_Source
(Spec_Id
, True);
2435 -- Ensure that the specs of the subprogram declaration and its body
2436 -- are identical, otherwise they will appear non-conformant due to
2437 -- rewritings in the default values of formal parameters.
2439 Body_Spec
:= Copy_Subprogram_Spec
(Body_Spec
);
2440 Set_Specification
(N
, Body_Spec
);
2441 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
2443 -- Ensure that the generated corresponding spec and original body
2444 -- share the same Ghost and SPARK_Mode attributes.
2446 Set_Is_Checked_Ghost_Entity
2447 (Body_Id
, Is_Checked_Ghost_Entity
(Spec_Id
));
2448 Set_Is_Ignored_Ghost_Entity
2449 (Body_Id
, Is_Ignored_Ghost_Entity
(Spec_Id
));
2451 Set_SPARK_Pragma
(Body_Id
, SPARK_Pragma
(Spec_Id
));
2452 Set_SPARK_Pragma_Inherited
2453 (Body_Id
, SPARK_Pragma_Inherited
(Spec_Id
));
2454 end Build_Subprogram_Declaration
;
2456 ----------------------------
2457 -- Check_Anonymous_Return --
2458 ----------------------------
2460 procedure Check_Anonymous_Return
is
2466 if Present
(Spec_Id
) then
2472 if Ekind
(Scop
) = E_Function
2473 and then Ekind
(Etype
(Scop
)) = E_Anonymous_Access_Type
2474 and then not Is_Thunk
(Scop
)
2476 -- Skip internally built functions which handle the case of
2477 -- a null access (see Expand_Interface_Conversion)
2479 and then not (Is_Interface
(Designated_Type
(Etype
(Scop
)))
2480 and then not Comes_From_Source
(Parent
(Scop
)))
2482 and then (Has_Task
(Designated_Type
(Etype
(Scop
)))
2484 (Is_Class_Wide_Type
(Designated_Type
(Etype
(Scop
)))
2486 Is_Limited_Record
(Designated_Type
(Etype
(Scop
)))))
2487 and then Expander_Active
2489 -- Avoid cases with no tasking support
2491 and then RTE_Available
(RE_Current_Master
)
2492 and then not Restriction_Active
(No_Task_Hierarchy
)
2495 Make_Object_Declaration
(Loc
,
2496 Defining_Identifier
=>
2497 Make_Defining_Identifier
(Loc
, Name_uMaster
),
2498 Constant_Present
=> True,
2499 Object_Definition
=>
2500 New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
2502 Make_Explicit_Dereference
(Loc
,
2503 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
2505 if Present
(Declarations
(N
)) then
2506 Prepend
(Decl
, Declarations
(N
));
2508 Set_Declarations
(N
, New_List
(Decl
));
2511 Set_Master_Id
(Etype
(Scop
), Defining_Identifier
(Decl
));
2512 Set_Has_Master_Entity
(Scop
);
2514 -- Now mark the containing scope as a task master
2517 while Nkind
(Par
) /= N_Compilation_Unit
loop
2518 Par
:= Parent
(Par
);
2519 pragma Assert
(Present
(Par
));
2521 -- If we fall off the top, we are at the outer level, and
2522 -- the environment task is our effective master, so nothing
2526 (Par
, N_Task_Body
, N_Block_Statement
, N_Subprogram_Body
)
2528 Set_Is_Task_Master
(Par
, True);
2533 end Check_Anonymous_Return
;
2535 -------------------------
2536 -- Check_Inline_Pragma --
2537 -------------------------
2539 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
) is
2543 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean;
2544 -- True when N is a pragma Inline or Inline_Always that applies
2545 -- to this subprogram.
2547 -----------------------
2548 -- Is_Inline_Pragma --
2549 -----------------------
2551 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean is
2553 if Nkind
(N
) = N_Pragma
2555 (Pragma_Name
(N
) = Name_Inline_Always
2556 or else (Pragma_Name
(N
) = Name_Inline
2558 (Front_End_Inlining
or else Optimization_Level
> 0)))
2559 and then Present
(Pragma_Argument_Associations
(N
))
2562 Pragma_Arg
: Node_Id
:=
2563 Expression
(First
(Pragma_Argument_Associations
(N
)));
2565 if Nkind
(Pragma_Arg
) = N_Selected_Component
then
2566 Pragma_Arg
:= Selector_Name
(Pragma_Arg
);
2569 return Chars
(Pragma_Arg
) = Chars
(Body_Id
);
2575 end Is_Inline_Pragma
;
2577 -- Start of processing for Check_Inline_Pragma
2580 if not Expander_Active
then
2584 if Is_List_Member
(N
)
2585 and then Present
(Next
(N
))
2586 and then Is_Inline_Pragma
(Next
(N
))
2590 elsif Nkind
(N
) /= N_Subprogram_Body_Stub
2591 and then Present
(Declarations
(N
))
2592 and then Is_Inline_Pragma
(First
(Declarations
(N
)))
2594 Prag
:= First
(Declarations
(N
));
2600 if Present
(Prag
) then
2601 if Present
(Spec_Id
) then
2602 if Is_List_Member
(N
)
2603 and then Is_List_Member
(Unit_Declaration_Node
(Spec_Id
))
2604 and then In_Same_List
(N
, Unit_Declaration_Node
(Spec_Id
))
2610 -- Create a subprogram declaration, to make treatment uniform.
2611 -- Make the sloc of the subprogram name that of the entity in
2612 -- the body, so that style checks find identical strings.
2615 Subp
: constant Entity_Id
:=
2616 Make_Defining_Identifier
2617 (Sloc
(Body_Id
), Chars
(Body_Id
));
2618 Decl
: constant Node_Id
:=
2619 Make_Subprogram_Declaration
(Loc
,
2621 New_Copy_Tree
(Specification
(N
)));
2624 Set_Defining_Unit_Name
(Specification
(Decl
), Subp
);
2626 -- To ensure proper coverage when body is inlined, indicate
2627 -- whether the subprogram comes from source.
2629 Set_Comes_From_Source
(Subp
, Comes_From_Source
(N
));
2631 if Present
(First_Formal
(Body_Id
)) then
2632 Plist
:= Copy_Parameter_List
(Body_Id
);
2633 Set_Parameter_Specifications
2634 (Specification
(Decl
), Plist
);
2637 Insert_Before
(N
, Decl
);
2640 Set_Has_Pragma_Inline
(Subp
);
2642 if Pragma_Name
(Prag
) = Name_Inline_Always
then
2643 Set_Is_Inlined
(Subp
);
2644 Set_Has_Pragma_Inline_Always
(Subp
);
2647 -- Prior to copying the subprogram body to create a template
2648 -- for it for subsequent inlining, remove the pragma from
2649 -- the current body so that the copy that will produce the
2650 -- new body will start from a completely unanalyzed tree.
2652 if Nkind
(Parent
(Prag
)) = N_Subprogram_Body
then
2653 Rewrite
(Prag
, Make_Null_Statement
(Sloc
(Prag
)));
2660 end Check_Inline_Pragma
;
2662 --------------------------
2663 -- Check_Missing_Return --
2664 --------------------------
2666 procedure Check_Missing_Return
is
2668 Missing_Ret
: Boolean;
2671 if Nkind
(Body_Spec
) = N_Function_Specification
then
2672 if Present
(Spec_Id
) then
2678 if Return_Present
(Id
) then
2679 Check_Returns
(HSS
, 'F', Missing_Ret
);
2682 Set_Has_Missing_Return
(Id
);
2685 -- Within a premature instantiation of a package with no body, we
2686 -- build completions of the functions therein, with a Raise
2687 -- statement. No point in complaining about a missing return in
2690 elsif Ekind
(Id
) = E_Function
2691 and then In_Instance
2692 and then Present
(Statements
(HSS
))
2693 and then Nkind
(First
(Statements
(HSS
))) = N_Raise_Program_Error
2697 elsif Is_Generic_Subprogram
(Id
)
2698 or else not Is_Machine_Code_Subprogram
(Id
)
2700 Error_Msg_N
("missing RETURN statement in function body", N
);
2703 -- If procedure with No_Return, check returns
2705 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
2706 and then Present
(Spec_Id
)
2707 and then No_Return
(Spec_Id
)
2709 Check_Returns
(HSS
, 'P', Missing_Ret
, Spec_Id
);
2712 -- Special checks in SPARK mode
2714 if Nkind
(Body_Spec
) = N_Function_Specification
then
2716 -- In SPARK mode, last statement of a function should be a return
2719 Stat
: constant Node_Id
:= Last_Source_Statement
(HSS
);
2722 and then not Nkind_In
(Stat
, N_Simple_Return_Statement
,
2723 N_Extended_Return_Statement
)
2725 Check_SPARK_05_Restriction
2726 ("last statement in function should be RETURN", Stat
);
2730 -- In SPARK mode, verify that a procedure has no return
2732 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
then
2733 if Present
(Spec_Id
) then
2739 -- Would be nice to point to return statement here, can we
2740 -- borrow the Check_Returns procedure here ???
2742 if Return_Present
(Id
) then
2743 Check_SPARK_05_Restriction
2744 ("procedure should not have RETURN", N
);
2747 end Check_Missing_Return
;
2749 -----------------------
2750 -- Disambiguate_Spec --
2751 -----------------------
2753 function Disambiguate_Spec
return Entity_Id
is
2754 Priv_Spec
: Entity_Id
;
2757 procedure Replace_Types
(To_Corresponding
: Boolean);
2758 -- Depending on the flag, replace the type of formal parameters of
2759 -- Body_Id if it is a concurrent type implementing interfaces with
2760 -- the corresponding record type or the other way around.
2762 procedure Replace_Types
(To_Corresponding
: Boolean) is
2764 Formal_Typ
: Entity_Id
;
2767 Formal
:= First_Formal
(Body_Id
);
2768 while Present
(Formal
) loop
2769 Formal_Typ
:= Etype
(Formal
);
2771 if Is_Class_Wide_Type
(Formal_Typ
) then
2772 Formal_Typ
:= Root_Type
(Formal_Typ
);
2775 -- From concurrent type to corresponding record
2777 if To_Corresponding
then
2778 if Is_Concurrent_Type
(Formal_Typ
)
2779 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
2782 (Corresponding_Record_Type
(Formal_Typ
)))
2785 Corresponding_Record_Type
(Formal_Typ
));
2788 -- From corresponding record to concurrent type
2791 if Is_Concurrent_Record_Type
(Formal_Typ
)
2792 and then Present
(Interfaces
(Formal_Typ
))
2795 Corresponding_Concurrent_Type
(Formal_Typ
));
2799 Next_Formal
(Formal
);
2803 -- Start of processing for Disambiguate_Spec
2806 -- Try to retrieve the specification of the body as is. All error
2807 -- messages are suppressed because the body may not have a spec in
2808 -- its current state.
2810 Spec_N
:= Find_Corresponding_Spec
(N
, False);
2812 -- It is possible that this is the body of a primitive declared
2813 -- between a private and a full view of a concurrent type. The
2814 -- controlling parameter of the spec carries the concurrent type,
2815 -- not the corresponding record type as transformed by Analyze_
2816 -- Subprogram_Specification. In such cases, we undo the change
2817 -- made by the analysis of the specification and try to find the
2820 -- Note that wrappers already have their corresponding specs and
2821 -- bodies set during their creation, so if the candidate spec is
2822 -- a wrapper, then we definitely need to swap all types to their
2823 -- original concurrent status.
2826 or else Is_Primitive_Wrapper
(Spec_N
)
2828 -- Restore all references of corresponding record types to the
2829 -- original concurrent types.
2831 Replace_Types
(To_Corresponding
=> False);
2832 Priv_Spec
:= Find_Corresponding_Spec
(N
, False);
2834 -- The current body truly belongs to a primitive declared between
2835 -- a private and a full view. We leave the modified body as is,
2836 -- and return the true spec.
2838 if Present
(Priv_Spec
)
2839 and then Is_Private_Primitive
(Priv_Spec
)
2844 -- In case that this is some sort of error, restore the original
2845 -- state of the body.
2847 Replace_Types
(To_Corresponding
=> True);
2851 end Disambiguate_Spec
;
2853 ----------------------------
2854 -- Exchange_Limited_Views --
2855 ----------------------------
2857 procedure Exchange_Limited_Views
(Subp_Id
: Entity_Id
) is
2858 procedure Detect_And_Exchange
(Id
: Entity_Id
);
2859 -- Determine whether Id's type denotes an incomplete type associated
2860 -- with a limited with clause and exchange the limited view with the
2861 -- non-limited one when available. Note that the non-limited view
2862 -- may exist because of a with_clause in another unit in the context,
2863 -- but cannot be used because the current view of the enclosing unit
2864 -- is still a limited view.
2866 -------------------------
2867 -- Detect_And_Exchange --
2868 -------------------------
2870 procedure Detect_And_Exchange
(Id
: Entity_Id
) is
2871 Typ
: constant Entity_Id
:= Etype
(Id
);
2873 if From_Limited_With
(Typ
)
2874 and then Has_Non_Limited_View
(Typ
)
2875 and then not From_Limited_With
(Scope
(Typ
))
2877 Set_Etype
(Id
, Non_Limited_View
(Typ
));
2879 end Detect_And_Exchange
;
2885 -- Start of processing for Exchange_Limited_Views
2888 if No
(Subp_Id
) then
2891 -- Do not process subprogram bodies as they already use the non-
2892 -- limited view of types.
2894 elsif not Ekind_In
(Subp_Id
, E_Function
, E_Procedure
) then
2898 -- Examine all formals and swap views when applicable
2900 Formal
:= First_Formal
(Subp_Id
);
2901 while Present
(Formal
) loop
2902 Detect_And_Exchange
(Formal
);
2904 Next_Formal
(Formal
);
2907 -- Process the return type of a function
2909 if Ekind
(Subp_Id
) = E_Function
then
2910 Detect_And_Exchange
(Subp_Id
);
2912 end Exchange_Limited_Views
;
2914 -------------------------------------
2915 -- Is_Private_Concurrent_Primitive --
2916 -------------------------------------
2918 function Is_Private_Concurrent_Primitive
2919 (Subp_Id
: Entity_Id
) return Boolean
2921 Formal_Typ
: Entity_Id
;
2924 if Present
(First_Formal
(Subp_Id
)) then
2925 Formal_Typ
:= Etype
(First_Formal
(Subp_Id
));
2927 if Is_Concurrent_Record_Type
(Formal_Typ
) then
2928 if Is_Class_Wide_Type
(Formal_Typ
) then
2929 Formal_Typ
:= Root_Type
(Formal_Typ
);
2932 Formal_Typ
:= Corresponding_Concurrent_Type
(Formal_Typ
);
2935 -- The type of the first formal is a concurrent tagged type with
2939 Is_Concurrent_Type
(Formal_Typ
)
2940 and then Is_Tagged_Type
(Formal_Typ
)
2941 and then Has_Private_Declaration
(Formal_Typ
);
2945 end Is_Private_Concurrent_Primitive
;
2947 ----------------------------
2948 -- Set_Trivial_Subprogram --
2949 ----------------------------
2951 procedure Set_Trivial_Subprogram
(N
: Node_Id
) is
2952 Nxt
: constant Node_Id
:= Next
(N
);
2955 Set_Is_Trivial_Subprogram
(Body_Id
);
2957 if Present
(Spec_Id
) then
2958 Set_Is_Trivial_Subprogram
(Spec_Id
);
2962 and then Nkind
(Nxt
) = N_Simple_Return_Statement
2963 and then No
(Next
(Nxt
))
2964 and then Present
(Expression
(Nxt
))
2965 and then Is_Entity_Name
(Expression
(Nxt
))
2967 Set_Never_Set_In_Source
(Entity
(Expression
(Nxt
)), False);
2969 end Set_Trivial_Subprogram
;
2971 ---------------------------------
2972 -- Verify_Overriding_Indicator --
2973 ---------------------------------
2975 procedure Verify_Overriding_Indicator
is
2977 if Must_Override
(Body_Spec
) then
2978 if Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
2979 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
2983 elsif not Present
(Overridden_Operation
(Spec_Id
)) then
2985 ("subprogram& is not overriding", Body_Spec
, Spec_Id
);
2987 -- Overriding indicators aren't allowed for protected subprogram
2988 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
2989 -- this to a warning if -gnatd.E is enabled.
2991 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
2992 Error_Msg_Warn
:= Error_To_Warning
;
2994 ("<<overriding indicator not allowed for protected "
2995 & "subprogram body", Body_Spec
);
2998 elsif Must_Not_Override
(Body_Spec
) then
2999 if Present
(Overridden_Operation
(Spec_Id
)) then
3001 ("subprogram& overrides inherited operation",
3002 Body_Spec
, Spec_Id
);
3004 elsif Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
3005 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
3008 ("subprogram& overrides predefined operator ",
3009 Body_Spec
, Spec_Id
);
3011 -- Overriding indicators aren't allowed for protected subprogram
3012 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
3013 -- this to a warning if -gnatd.E is enabled.
3015 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
3016 Error_Msg_Warn
:= Error_To_Warning
;
3019 ("<<overriding indicator not allowed "
3020 & "for protected subprogram body", Body_Spec
);
3022 -- If this is not a primitive operation, then the overriding
3023 -- indicator is altogether illegal.
3025 elsif not Is_Primitive
(Spec_Id
) then
3027 ("overriding indicator only allowed "
3028 & "if subprogram is primitive", Body_Spec
);
3031 -- If checking the style rule and the operation overrides, then
3032 -- issue a warning about a missing overriding_indicator. Protected
3033 -- subprogram bodies are excluded from this style checking, since
3034 -- they aren't primitives (even though their declarations can
3035 -- override) and aren't allowed to have an overriding_indicator.
3038 and then Present
(Overridden_Operation
(Spec_Id
))
3039 and then Ekind
(Scope
(Spec_Id
)) /= E_Protected_Type
3041 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
3042 Style
.Missing_Overriding
(N
, Body_Id
);
3045 and then Can_Override_Operator
(Spec_Id
)
3046 and then not Is_Predefined_File_Name
3047 (Unit_File_Name
(Get_Source_Unit
(Spec_Id
)))
3049 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
3050 Style
.Missing_Overriding
(N
, Body_Id
);
3052 end Verify_Overriding_Indicator
;
3056 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
3057 Cloned_Body_For_C
: Node_Id
:= Empty
;
3059 -- Start of processing for Analyze_Subprogram_Body_Helper
3062 -- A [generic] subprogram body "freezes" the contract of the nearest
3063 -- enclosing package body and all other contracts encountered in the
3064 -- same declarative part up to and excluding the subprogram body:
3066 -- package body Nearest_Enclosing_Package
3067 -- with Refined_State => (State => Constit)
3071 -- procedure Freezes_Enclosing_Package_Body
3072 -- with Refined_Depends => (Input => Constit) ...
3074 -- This ensures that any annotations referenced by the contract of the
3075 -- [generic] subprogram body are available. This form of "freezing" is
3076 -- decoupled from the usual Freeze_xxx mechanism because it must also
3077 -- work in the context of generics where normal freezing is disabled.
3079 -- Only bodies coming from source should cause this type of "freezing".
3080 -- Expression functions that act as bodies and complete an initial
3081 -- declaration must be included in this category, hence the use of
3084 if Comes_From_Source
(Original_Node
(N
)) then
3085 Analyze_Previous_Contracts
(N
);
3088 -- Generic subprograms are handled separately. They always have a
3089 -- generic specification. Determine whether current scope has a
3090 -- previous declaration.
3092 -- If the subprogram body is defined within an instance of the same
3093 -- name, the instance appears as a package renaming, and will be hidden
3094 -- within the subprogram.
3096 if Present
(Prev_Id
)
3097 and then not Is_Overloadable
(Prev_Id
)
3098 and then (Nkind
(Parent
(Prev_Id
)) /= N_Package_Renaming_Declaration
3099 or else Comes_From_Source
(Prev_Id
))
3101 if Is_Generic_Subprogram
(Prev_Id
) then
3104 -- A subprogram body is Ghost when it is stand alone and subject
3105 -- to pragma Ghost or when the corresponding spec is Ghost. Set
3106 -- the mode now to ensure that any nodes generated during analysis
3107 -- and expansion are properly marked as Ghost.
3109 Set_Ghost_Mode
(N
, Spec_Id
);
3110 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3111 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3113 Analyze_Generic_Subprogram_Body
(N
, Spec_Id
);
3115 if Nkind
(N
) = N_Subprogram_Body
then
3116 HSS
:= Handled_Statement_Sequence
(N
);
3117 Check_Missing_Return
;
3120 Ghost_Mode
:= Save_Ghost_Mode
;
3124 -- Previous entity conflicts with subprogram name. Attempting to
3125 -- enter name will post error.
3127 Enter_Name
(Body_Id
);
3128 Ghost_Mode
:= Save_Ghost_Mode
;
3132 -- Non-generic case, find the subprogram declaration, if one was seen,
3133 -- or enter new overloaded entity in the current scope. If the
3134 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
3135 -- part of the context of one of its subunits. No need to redo the
3138 elsif Prev_Id
= Body_Id
and then Has_Completion
(Body_Id
) then
3139 Ghost_Mode
:= Save_Ghost_Mode
;
3143 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
3145 if Nkind
(N
) = N_Subprogram_Body_Stub
3146 or else No
(Corresponding_Spec
(N
))
3148 if Is_Private_Concurrent_Primitive
(Body_Id
) then
3149 Spec_Id
:= Disambiguate_Spec
;
3151 -- A subprogram body is Ghost when it is stand alone and
3152 -- subject to pragma Ghost or when the corresponding spec is
3153 -- Ghost. Set the mode now to ensure that any nodes generated
3154 -- during analysis and expansion are properly marked as Ghost.
3156 Set_Ghost_Mode
(N
, Spec_Id
);
3159 Spec_Id
:= Find_Corresponding_Spec
(N
);
3161 -- A subprogram body is Ghost when it is stand alone and
3162 -- subject to pragma Ghost or when the corresponding spec is
3163 -- Ghost. Set the mode now to ensure that any nodes generated
3164 -- during analysis and expansion are properly marked as Ghost.
3166 Set_Ghost_Mode
(N
, Spec_Id
);
3168 -- In GNATprove mode, if the body has no previous spec, create
3169 -- one so that the inlining machinery can operate properly.
3170 -- Transfer aspects, if any, to the new spec, so that they
3171 -- are legal and can be processed ahead of the body.
3172 -- We make two copies of the given spec, one for the new
3173 -- declaration, and one for the body.
3175 if No
(Spec_Id
) and then GNATprove_Mode
3177 -- Inlining does not apply during pre-analysis of code
3179 and then Full_Analysis
3181 -- Inlining only applies to full bodies, not stubs
3183 and then Nkind
(N
) /= N_Subprogram_Body_Stub
3185 -- Inlining only applies to bodies in the source code, not to
3186 -- those generated by the compiler. In particular, expression
3187 -- functions, whose body is generated by the compiler, are
3188 -- treated specially by GNATprove.
3190 and then Comes_From_Source
(Body_Id
)
3192 -- This cannot be done for a compilation unit, which is not
3193 -- in a context where we can insert a new spec.
3195 and then Is_List_Member
(N
)
3197 -- Inlining only applies to subprograms without contracts,
3198 -- as a contract is a sign that GNATprove should perform a
3199 -- modular analysis of the subprogram instead of a contextual
3200 -- analysis at each call site. The same test is performed in
3201 -- Inline.Can_Be_Inlined_In_GNATprove_Mode. It is repeated
3202 -- here in another form (because the contract has not
3203 -- been attached to the body) to avoid frontend errors in
3204 -- case pragmas are used instead of aspects, because the
3205 -- corresponding pragmas in the body would not be transferred
3206 -- to the spec, leading to legality errors.
3208 and then not Body_Has_Contract
3209 and then not Inside_A_Generic
3211 Build_Subprogram_Declaration
;
3213 -- If this is a function that returns a constrained array, and
3214 -- we are generating SPARK_For_C, create subprogram declaration
3215 -- to simplify subsequent C generation.
3218 and then Modify_Tree_For_C
3219 and then Nkind
(Body_Spec
) = N_Function_Specification
3220 and then Is_Array_Type
(Etype
(Body_Id
))
3221 and then Is_Constrained
(Etype
(Body_Id
))
3223 Build_Subprogram_Declaration
;
3227 -- If this is a duplicate body, no point in analyzing it
3229 if Error_Posted
(N
) then
3230 Ghost_Mode
:= Save_Ghost_Mode
;
3234 -- A subprogram body should cause freezing of its own declaration,
3235 -- but if there was no previous explicit declaration, then the
3236 -- subprogram will get frozen too late (there may be code within
3237 -- the body that depends on the subprogram having been frozen,
3238 -- such as uses of extra formals), so we force it to be frozen
3239 -- here. Same holds if the body and spec are compilation units.
3240 -- Finally, if the return type is an anonymous access to protected
3241 -- subprogram, it must be frozen before the body because its
3242 -- expansion has generated an equivalent type that is used when
3243 -- elaborating the body.
3245 -- An exception in the case of Ada 2012, AI05-177: The bodies
3246 -- created for expression functions do not freeze.
3249 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3251 Freeze_Before
(N
, Body_Id
);
3253 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3254 Freeze_Before
(N
, Spec_Id
);
3256 elsif Is_Access_Subprogram_Type
(Etype
(Body_Id
)) then
3257 Freeze_Before
(N
, Etype
(Body_Id
));
3261 Spec_Id
:= Corresponding_Spec
(N
);
3263 -- A subprogram body is Ghost when it is stand alone and subject
3264 -- to pragma Ghost or when the corresponding spec is Ghost. Set
3265 -- the mode now to ensure that any nodes generated during analysis
3266 -- and expansion are properly marked as Ghost.
3268 Set_Ghost_Mode
(N
, Spec_Id
);
3272 -- Previously we scanned the body to look for nested subprograms, and
3273 -- rejected an inline directive if nested subprograms were present,
3274 -- because the back-end would generate conflicting symbols for the
3275 -- nested bodies. This is now unnecessary.
3277 -- Look ahead to recognize a pragma Inline that appears after the body
3279 Check_Inline_Pragma
(Spec_Id
);
3281 -- Deal with special case of a fully private operation in the body of
3282 -- the protected type. We must create a declaration for the subprogram,
3283 -- in order to attach the protected subprogram that will be used in
3284 -- internal calls. We exclude compiler generated bodies from the
3285 -- expander since the issue does not arise for those cases.
3288 and then Comes_From_Source
(N
)
3289 and then Is_Protected_Type
(Current_Scope
)
3291 Spec_Id
:= Build_Private_Protected_Declaration
(N
);
3294 -- If a separate spec is present, then deal with freezing issues
3296 if Present
(Spec_Id
) then
3297 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
3298 Verify_Overriding_Indicator
;
3300 -- In general, the spec will be frozen when we start analyzing the
3301 -- body. However, for internally generated operations, such as
3302 -- wrapper functions for inherited operations with controlling
3303 -- results, the spec may not have been frozen by the time we expand
3304 -- the freeze actions that include the bodies. In particular, extra
3305 -- formals for accessibility or for return-in-place may need to be
3306 -- generated. Freeze nodes, if any, are inserted before the current
3307 -- body. These freeze actions are also needed in ASIS mode and in
3308 -- Compile_Only mode to enable the proper back-end type annotations.
3309 -- They are necessary in any case to insure order of elaboration
3312 if not Is_Frozen
(Spec_Id
)
3313 and then (Expander_Active
3315 or else (Operating_Mode
= Check_Semantics
3316 and then Serious_Errors_Detected
= 0))
3318 Set_Has_Delayed_Freeze
(Spec_Id
);
3319 Freeze_Before
(N
, Spec_Id
);
3323 -- Place subprogram on scope stack, and make formals visible. If there
3324 -- is a spec, the visible entity remains that of the spec.
3326 if Present
(Spec_Id
) then
3327 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
3329 if Is_Child_Unit
(Spec_Id
) then
3330 Generate_Reference
(Spec_Id
, Scope
(Spec_Id
), 'k', False);
3334 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
3337 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3338 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3340 if Is_Abstract_Subprogram
(Spec_Id
) then
3341 Error_Msg_N
("an abstract subprogram cannot have a body", N
);
3342 Ghost_Mode
:= Save_Ghost_Mode
;
3346 Set_Convention
(Body_Id
, Convention
(Spec_Id
));
3347 Set_Has_Completion
(Spec_Id
);
3349 -- Inherit the "ghostness" of the subprogram spec. Note that this
3350 -- property is not directly inherited as the body may be subject
3351 -- to a different Ghost assertion policy.
3353 if Ghost_Mode
> None
or else Is_Ghost_Entity
(Spec_Id
) then
3354 Set_Is_Ghost_Entity
(Body_Id
);
3356 -- The Ghost policy in effect at the point of declaration and
3357 -- at the point of completion must match (SPARK RM 6.9(14)).
3359 Check_Ghost_Completion
(Spec_Id
, Body_Id
);
3362 if Is_Protected_Type
(Scope
(Spec_Id
)) then
3363 Prot_Typ
:= Scope
(Spec_Id
);
3366 -- If this is a body generated for a renaming, do not check for
3367 -- full conformance. The check is redundant, because the spec of
3368 -- the body is a copy of the spec in the renaming declaration,
3369 -- and the test can lead to spurious errors on nested defaults.
3371 if Present
(Spec_Decl
)
3372 and then not Comes_From_Source
(N
)
3374 (Nkind
(Original_Node
(Spec_Decl
)) =
3375 N_Subprogram_Renaming_Declaration
3376 or else (Present
(Corresponding_Body
(Spec_Decl
))
3378 Nkind
(Unit_Declaration_Node
3379 (Corresponding_Body
(Spec_Decl
))) =
3380 N_Subprogram_Renaming_Declaration
))
3384 -- Conversely, the spec may have been generated for specless body
3385 -- with an inline pragma. The entity comes from source, which is
3386 -- both semantically correct and necessary for proper inlining.
3387 -- The subprogram declaration itself is not in the source.
3389 elsif Comes_From_Source
(N
)
3390 and then Present
(Spec_Decl
)
3391 and then not Comes_From_Source
(Spec_Decl
)
3392 and then Has_Pragma_Inline
(Spec_Id
)
3399 Fully_Conformant
, True, Conformant
, Body_Id
);
3402 -- If the body is not fully conformant, we have to decide if we
3403 -- should analyze it or not. If it has a really messed up profile
3404 -- then we probably should not analyze it, since we will get too
3405 -- many bogus messages.
3407 -- Our decision is to go ahead in the non-fully conformant case
3408 -- only if it is at least mode conformant with the spec. Note
3409 -- that the call to Check_Fully_Conformant has issued the proper
3410 -- error messages to complain about the lack of conformance.
3413 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
3415 Ghost_Mode
:= Save_Ghost_Mode
;
3420 if Spec_Id
/= Body_Id
then
3421 Reference_Body_Formals
(Spec_Id
, Body_Id
);
3424 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
3426 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3427 Set_Corresponding_Spec_Of_Stub
(N
, Spec_Id
);
3432 Set_Corresponding_Spec
(N
, Spec_Id
);
3434 -- Ada 2005 (AI-345): If the operation is a primitive operation
3435 -- of a concurrent type, the type of the first parameter has been
3436 -- replaced with the corresponding record, which is the proper
3437 -- run-time structure to use. However, within the body there may
3438 -- be uses of the formals that depend on primitive operations
3439 -- of the type (in particular calls in prefixed form) for which
3440 -- we need the original concurrent type. The operation may have
3441 -- several controlling formals, so the replacement must be done
3444 if Comes_From_Source
(Spec_Id
)
3445 and then Present
(First_Entity
(Spec_Id
))
3446 and then Ekind
(Etype
(First_Entity
(Spec_Id
))) = E_Record_Type
3447 and then Is_Tagged_Type
(Etype
(First_Entity
(Spec_Id
)))
3448 and then Present
(Interfaces
(Etype
(First_Entity
(Spec_Id
))))
3449 and then Present
(Corresponding_Concurrent_Type
3450 (Etype
(First_Entity
(Spec_Id
))))
3453 Typ
: constant Entity_Id
:= Etype
(First_Entity
(Spec_Id
));
3457 Form
:= First_Formal
(Spec_Id
);
3458 while Present
(Form
) loop
3459 if Etype
(Form
) = Typ
then
3460 Set_Etype
(Form
, Corresponding_Concurrent_Type
(Typ
));
3468 -- Make the formals visible, and place subprogram on scope stack.
3469 -- This is also the point at which we set Last_Real_Spec_Entity
3470 -- to mark the entities which will not be moved to the body.
3472 Install_Formals
(Spec_Id
);
3473 Last_Real_Spec_Entity
:= Last_Entity
(Spec_Id
);
3475 -- Within an instance, add local renaming declarations so that
3476 -- gdb can retrieve the values of actuals more easily. This is
3477 -- only relevant if generating code (and indeed we definitely
3478 -- do not want these definitions -gnatc mode, because that would
3481 if Is_Generic_Instance
(Spec_Id
)
3482 and then Is_Wrapper_Package
(Current_Scope
)
3483 and then Expander_Active
3485 Build_Subprogram_Instance_Renamings
(N
, Current_Scope
);
3488 Push_Scope
(Spec_Id
);
3490 -- Make sure that the subprogram is immediately visible. For
3491 -- child units that have no separate spec this is indispensable.
3492 -- Otherwise it is safe albeit redundant.
3494 Set_Is_Immediately_Visible
(Spec_Id
);
3497 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
3498 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Spec_Id
));
3499 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
3501 -- Case of subprogram body with no previous spec
3504 -- Check for style warning required
3508 -- Only apply check for source level subprograms for which checks
3509 -- have not been suppressed.
3511 and then Comes_From_Source
(Body_Id
)
3512 and then not Suppress_Style_Checks
(Body_Id
)
3514 -- No warnings within an instance
3516 and then not In_Instance
3518 -- No warnings for expression functions
3520 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3522 Style
.Body_With_No_Spec
(N
);
3525 New_Overloaded_Entity
(Body_Id
);
3527 -- A subprogram body declared within a Ghost region is automatically
3528 -- Ghost (SPARK RM 6.9(2)).
3530 if Ghost_Mode
> None
then
3531 Set_Is_Ghost_Entity
(Body_Id
);
3534 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
3535 Set_Acts_As_Spec
(N
);
3536 Generate_Definition
(Body_Id
);
3538 (Body_Id
, Body_Id
, 'b', Set_Ref
=> False, Force
=> True);
3539 Install_Formals
(Body_Id
);
3541 Push_Scope
(Body_Id
);
3544 -- For stubs and bodies with no previous spec, generate references to
3547 Generate_Reference_To_Formals
(Body_Id
);
3550 -- Entry barrier functions are generated outside the protected type and
3551 -- should not carry the SPARK_Mode of the enclosing context.
3553 if Nkind
(N
) = N_Subprogram_Body
3554 and then Is_Entry_Barrier_Function
(N
)
3558 -- The body is generated as part of expression function expansion. When
3559 -- the expression function appears in the visible declarations of a
3560 -- package, the body is added to the private declarations. Since both
3561 -- declarative lists may be subject to a different SPARK_Mode, inherit
3562 -- the mode of the spec.
3564 -- package P with SPARK_Mode is
3565 -- function Expr_Func ... is (...); -- original
3566 -- [function Expr_Func ...;] -- generated spec
3569 -- pragma SPARK_Mode (Off);
3570 -- [function Expr_Func ... is return ...;] -- generated body
3571 -- end P; -- mode is ON
3573 elsif not Comes_From_Source
(N
)
3574 and then Present
(Prev_Id
)
3575 and then Is_Expression_Function
(Prev_Id
)
3577 Set_SPARK_Pragma
(Body_Id
, SPARK_Pragma
(Prev_Id
));
3578 Set_SPARK_Pragma_Inherited
3579 (Body_Id
, SPARK_Pragma_Inherited
(Prev_Id
));
3581 -- Set the SPARK_Mode from the current context (may be overwritten later
3582 -- with explicit pragma). Exclude the case where the SPARK_Mode appears
3583 -- initially on a stand-alone subprogram body, but is then relocated to
3584 -- a generated corresponding spec. In this scenario the mode is shared
3585 -- between the spec and body.
3587 elsif No
(SPARK_Pragma
(Body_Id
)) then
3588 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
3589 Set_SPARK_Pragma_Inherited
(Body_Id
);
3592 -- If the return type is an anonymous access type whose designated type
3593 -- is the limited view of a class-wide type and the non-limited view is
3594 -- available, update the return type accordingly.
3596 if Ada_Version
>= Ada_2005
and then Comes_From_Source
(N
) then
3602 Rtyp
:= Etype
(Current_Scope
);
3604 if Ekind
(Rtyp
) = E_Anonymous_Access_Type
then
3605 Etyp
:= Directly_Designated_Type
(Rtyp
);
3607 if Is_Class_Wide_Type
(Etyp
)
3608 and then From_Limited_With
(Etyp
)
3610 Set_Directly_Designated_Type
3611 (Etype
(Current_Scope
), Available_View
(Etyp
));
3617 -- If this is the proper body of a stub, we must verify that the stub
3618 -- conforms to the body, and to the previous spec if one was present.
3619 -- We know already that the body conforms to that spec. This test is
3620 -- only required for subprograms that come from source.
3622 if Nkind
(Parent
(N
)) = N_Subunit
3623 and then Comes_From_Source
(N
)
3624 and then not Error_Posted
(Body_Id
)
3625 and then Nkind
(Corresponding_Stub
(Parent
(N
))) =
3626 N_Subprogram_Body_Stub
3629 Old_Id
: constant Entity_Id
:=
3631 (Specification
(Corresponding_Stub
(Parent
(N
))));
3633 Conformant
: Boolean := False;
3636 if No
(Spec_Id
) then
3637 Check_Fully_Conformant
(Body_Id
, Old_Id
);
3641 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
3643 if not Conformant
then
3645 -- The stub was taken to be a new declaration. Indicate that
3648 Set_Has_Completion
(Old_Id
, False);
3654 Set_Has_Completion
(Body_Id
);
3655 Check_Eliminated
(Body_Id
);
3657 -- Analyze any aspect specifications that appear on the subprogram body
3658 -- stub. Stop the analysis now as the stub does not have a declarative
3659 -- or a statement part, and it cannot be inlined.
3661 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3662 if Has_Aspects
(N
) then
3663 Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
);
3666 Ghost_Mode
:= Save_Ghost_Mode
;
3670 -- If we are generating C and this is a function returning a constrained
3671 -- array type for which we must create a procedure with an extra out
3672 -- parameter then clone the body before it is analyzed. Needed to ensure
3673 -- that the body of the built procedure does not have any reference to
3674 -- the body of the function.
3677 and then Modify_Tree_For_C
3678 and then Present
(Spec_Id
)
3679 and then Ekind
(Spec_Id
) = E_Function
3680 and then Rewritten_For_C
(Spec_Id
)
3682 Cloned_Body_For_C
:= Copy_Separate_Tree
(N
);
3685 -- Handle frontend inlining
3687 -- Note: Normally we don't do any inlining if expansion is off, since
3688 -- we won't generate code in any case. An exception arises in GNATprove
3689 -- mode where we want to expand some calls in place, even with expansion
3690 -- disabled, since the inlining eases formal verification.
3692 if not GNATprove_Mode
3693 and then Expander_Active
3694 and then Serious_Errors_Detected
= 0
3695 and then Present
(Spec_Id
)
3696 and then Has_Pragma_Inline
(Spec_Id
)
3698 -- Legacy implementation (relying on frontend inlining)
3700 if not Back_End_Inlining
then
3701 if (Has_Pragma_Inline_Always
(Spec_Id
)
3702 and then not Opt
.Disable_FE_Inline_Always
)
3704 (Has_Pragma_Inline
(Spec_Id
) and then Front_End_Inlining
3705 and then not Opt
.Disable_FE_Inline
)
3707 Build_Body_To_Inline
(N
, Spec_Id
);
3710 -- New implementation (relying on backend inlining)
3713 if Has_Pragma_Inline_Always
(Spec_Id
)
3714 or else Optimization_Level
> 0
3716 -- Handle function returning an unconstrained type
3718 if Comes_From_Source
(Body_Id
)
3719 and then Ekind
(Spec_Id
) = E_Function
3720 and then Returns_Unconstrained_Type
(Spec_Id
)
3722 -- If function builds in place, i.e. returns a limited type,
3723 -- inlining cannot be done.
3725 and then not Is_Limited_Type
(Etype
(Spec_Id
))
3727 Check_And_Split_Unconstrained_Function
(N
, Spec_Id
, Body_Id
);
3731 Subp_Body
: constant Node_Id
:=
3732 Unit_Declaration_Node
(Body_Id
);
3733 Subp_Decl
: constant List_Id
:= Declarations
(Subp_Body
);
3736 -- Do not pass inlining to the backend if the subprogram
3737 -- has declarations or statements which cannot be inlined
3738 -- by the backend. This check is done here to emit an
3739 -- error instead of the generic warning message reported
3740 -- by the GCC backend (ie. "function might not be
3743 if Present
(Subp_Decl
)
3744 and then Has_Excluded_Declaration
(Spec_Id
, Subp_Decl
)
3748 elsif Has_Excluded_Statement
3751 (Handled_Statement_Sequence
(Subp_Body
)))
3755 -- If the backend inlining is available then at this
3756 -- stage we only have to mark the subprogram as inlined.
3757 -- The expander will take care of registering it in the
3758 -- table of subprograms inlined by the backend a part of
3759 -- processing calls to it (cf. Expand_Call)
3762 Set_Is_Inlined
(Spec_Id
);
3769 -- In GNATprove mode, inline only when there is a separate subprogram
3770 -- declaration for now, as inlining of subprogram bodies acting as
3771 -- declarations, or subprogram stubs, are not supported by frontend
3772 -- inlining. This inlining should occur after analysis of the body, so
3773 -- that it is known whether the value of SPARK_Mode, which can be
3774 -- defined by a pragma inside the body, is applicable to the body.
3776 elsif GNATprove_Mode
3777 and then Full_Analysis
3778 and then not Inside_A_Generic
3779 and then Present
(Spec_Id
)
3781 Nkind
(Unit_Declaration_Node
(Spec_Id
)) = N_Subprogram_Declaration
3782 and then Body_Has_SPARK_Mode_On
3783 and then Can_Be_Inlined_In_GNATprove_Mode
(Spec_Id
, Body_Id
)
3784 and then not Body_Has_Contract
3786 Build_Body_To_Inline
(N
, Spec_Id
);
3789 -- When generating code, inherited pre/postconditions are handled when
3790 -- expanding the corresponding contract.
3792 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
3793 -- of the specification we have to install the private withed units.
3794 -- This holds for child units as well.
3796 if Is_Compilation_Unit
(Body_Id
)
3797 or else Nkind
(Parent
(N
)) = N_Compilation_Unit
3799 Install_Private_With_Clauses
(Body_Id
);
3802 Check_Anonymous_Return
;
3804 -- Set the Protected_Formal field of each extra formal of the protected
3805 -- subprogram to reference the corresponding extra formal of the
3806 -- subprogram that implements it. For regular formals this occurs when
3807 -- the protected subprogram's declaration is expanded, but the extra
3808 -- formals don't get created until the subprogram is frozen. We need to
3809 -- do this before analyzing the protected subprogram's body so that any
3810 -- references to the original subprogram's extra formals will be changed
3811 -- refer to the implementing subprogram's formals (see Expand_Formal).
3813 if Present
(Spec_Id
)
3814 and then Is_Protected_Type
(Scope
(Spec_Id
))
3815 and then Present
(Protected_Body_Subprogram
(Spec_Id
))
3818 Impl_Subp
: constant Entity_Id
:=
3819 Protected_Body_Subprogram
(Spec_Id
);
3820 Prot_Ext_Formal
: Entity_Id
:= Extra_Formals
(Spec_Id
);
3821 Impl_Ext_Formal
: Entity_Id
:= Extra_Formals
(Impl_Subp
);
3823 while Present
(Prot_Ext_Formal
) loop
3824 pragma Assert
(Present
(Impl_Ext_Formal
));
3825 Set_Protected_Formal
(Prot_Ext_Formal
, Impl_Ext_Formal
);
3826 Next_Formal_With_Extras
(Prot_Ext_Formal
);
3827 Next_Formal_With_Extras
(Impl_Ext_Formal
);
3832 -- Now we can go on to analyze the body
3834 HSS
:= Handled_Statement_Sequence
(N
);
3835 Set_Actual_Subtypes
(N
, Current_Scope
);
3837 -- Add a declaration for the Protection object, renaming declarations
3838 -- for discriminals and privals and finally a declaration for the entry
3839 -- family index (if applicable). This form of early expansion is done
3840 -- when the Expander is active because Install_Private_Data_Declarations
3841 -- references entities which were created during regular expansion. The
3842 -- subprogram entity must come from source, and not be an internally
3843 -- generated subprogram.
3846 and then Present
(Prot_Typ
)
3847 and then Present
(Spec_Id
)
3848 and then Comes_From_Source
(Spec_Id
)
3849 and then not Is_Eliminated
(Spec_Id
)
3851 Install_Private_Data_Declarations
3852 (Sloc
(N
), Spec_Id
, Prot_Typ
, N
, Declarations
(N
));
3855 -- Ada 2012 (AI05-0151): Incomplete types coming from a limited context
3856 -- may now appear in parameter and result profiles. Since the analysis
3857 -- of a subprogram body may use the parameter and result profile of the
3858 -- spec, swap any limited views with their non-limited counterpart.
3860 if Ada_Version
>= Ada_2012
then
3861 Exchange_Limited_Views
(Spec_Id
);
3864 -- Analyze any aspect specifications that appear on the subprogram body
3866 if Has_Aspects
(N
) then
3867 Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
);
3870 Analyze_Declarations
(Declarations
(N
));
3872 -- Verify that the SPARK_Mode of the body agrees with that of its spec
3874 if Present
(Spec_Id
) and then Present
(SPARK_Pragma
(Body_Id
)) then
3875 if Present
(SPARK_Pragma
(Spec_Id
)) then
3876 if Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Spec_Id
)) = Off
3878 Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Body_Id
)) = On
3880 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
3881 Error_Msg_N
("incorrect application of SPARK_Mode#", N
);
3882 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Spec_Id
));
3884 ("\value Off was set for SPARK_Mode on & #", N
, Spec_Id
);
3887 elsif Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Body_Stub
then
3891 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
3892 Error_Msg_N
("incorrect application of SPARK_Mode #", N
);
3893 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
3895 ("\no value was set for SPARK_Mode on & #", N
, Spec_Id
);
3899 -- A subprogram body "freezes" its own contract. Analyze the contract
3900 -- after the declarations of the body have been processed as pragmas
3901 -- are now chained on the contract of the subprogram body.
3903 Analyze_Entry_Or_Subprogram_Body_Contract
(Body_Id
);
3905 -- Check completion, and analyze the statements
3908 Inspect_Deferred_Constant_Completion
(Declarations
(N
));
3911 -- Deal with end of scope processing for the body
3913 Process_End_Label
(HSS
, 't', Current_Scope
);
3915 Check_Subprogram_Order
(N
);
3916 Set_Analyzed
(Body_Id
);
3918 -- If we have a separate spec, then the analysis of the declarations
3919 -- caused the entities in the body to be chained to the spec id, but
3920 -- we want them chained to the body id. Only the formal parameters
3921 -- end up chained to the spec id in this case.
3923 if Present
(Spec_Id
) then
3925 -- We must conform to the categorization of our spec
3927 Validate_Categorization_Dependency
(N
, Spec_Id
);
3929 -- And if this is a child unit, the parent units must conform
3931 if Is_Child_Unit
(Spec_Id
) then
3932 Validate_Categorization_Dependency
3933 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
3936 -- Here is where we move entities from the spec to the body
3938 -- Case where there are entities that stay with the spec
3940 if Present
(Last_Real_Spec_Entity
) then
3942 -- No body entities (happens when the only real spec entities come
3943 -- from precondition and postcondition pragmas).
3945 if No
(Last_Entity
(Body_Id
)) then
3946 Set_First_Entity
(Body_Id
, Next_Entity
(Last_Real_Spec_Entity
));
3948 -- Body entities present (formals), so chain stuff past them
3952 (Last_Entity
(Body_Id
), Next_Entity
(Last_Real_Spec_Entity
));
3955 Set_Next_Entity
(Last_Real_Spec_Entity
, Empty
);
3956 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
3957 Set_Last_Entity
(Spec_Id
, Last_Real_Spec_Entity
);
3959 -- Case where there are no spec entities, in this case there can be
3960 -- no body entities either, so just move everything.
3962 -- If the body is generated for an expression function, it may have
3963 -- been preanalyzed already, if 'access was applied to it.
3966 if Nkind
(Original_Node
(Unit_Declaration_Node
(Spec_Id
))) /=
3967 N_Expression_Function
3969 pragma Assert
(No
(Last_Entity
(Body_Id
)));
3973 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
3974 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
3975 Set_First_Entity
(Spec_Id
, Empty
);
3976 Set_Last_Entity
(Spec_Id
, Empty
);
3980 Check_Missing_Return
;
3982 -- Now we are going to check for variables that are never modified in
3983 -- the body of the procedure. But first we deal with a special case
3984 -- where we want to modify this check. If the body of the subprogram
3985 -- starts with a raise statement or its equivalent, or if the body
3986 -- consists entirely of a null statement, then it is pretty obvious that
3987 -- it is OK to not reference the parameters. For example, this might be
3988 -- the following common idiom for a stubbed function: statement of the
3989 -- procedure raises an exception. In particular this deals with the
3990 -- common idiom of a stubbed function, which appears something like:
3992 -- function F (A : Integer) return Some_Type;
3995 -- raise Program_Error;
3999 -- Here the purpose of X is simply to satisfy the annoying requirement
4000 -- in Ada that there be at least one return, and we certainly do not
4001 -- want to go posting warnings on X that it is not initialized. On
4002 -- the other hand, if X is entirely unreferenced that should still
4005 -- What we do is to detect these cases, and if we find them, flag the
4006 -- subprogram as being Is_Trivial_Subprogram and then use that flag to
4007 -- suppress unwanted warnings. For the case of the function stub above
4008 -- we have a special test to set X as apparently assigned to suppress
4015 -- Skip initial labels (for one thing this occurs when we are in
4016 -- front end ZCX mode, but in any case it is irrelevant), and also
4017 -- initial Push_xxx_Error_Label nodes, which are also irrelevant.
4019 Stm
:= First
(Statements
(HSS
));
4020 while Nkind
(Stm
) = N_Label
4021 or else Nkind
(Stm
) in N_Push_xxx_Label
4026 -- Do the test on the original statement before expansion
4029 Ostm
: constant Node_Id
:= Original_Node
(Stm
);
4032 -- If explicit raise statement, turn on flag
4034 if Nkind
(Ostm
) = N_Raise_Statement
then
4035 Set_Trivial_Subprogram
(Stm
);
4037 -- If null statement, and no following statements, turn on flag
4039 elsif Nkind
(Stm
) = N_Null_Statement
4040 and then Comes_From_Source
(Stm
)
4041 and then No
(Next
(Stm
))
4043 Set_Trivial_Subprogram
(Stm
);
4045 -- Check for explicit call cases which likely raise an exception
4047 elsif Nkind
(Ostm
) = N_Procedure_Call_Statement
then
4048 if Is_Entity_Name
(Name
(Ostm
)) then
4050 Ent
: constant Entity_Id
:= Entity
(Name
(Ostm
));
4053 -- If the procedure is marked No_Return, then likely it
4054 -- raises an exception, but in any case it is not coming
4055 -- back here, so turn on the flag.
4058 and then Ekind
(Ent
) = E_Procedure
4059 and then No_Return
(Ent
)
4061 Set_Trivial_Subprogram
(Stm
);
4069 -- Check for variables that are never modified
4075 -- If there is a separate spec, then transfer Never_Set_In_Source
4076 -- flags from out parameters to the corresponding entities in the
4077 -- body. The reason we do that is we want to post error flags on
4078 -- the body entities, not the spec entities.
4080 if Present
(Spec_Id
) then
4081 E1
:= First_Entity
(Spec_Id
);
4082 while Present
(E1
) loop
4083 if Ekind
(E1
) = E_Out_Parameter
then
4084 E2
:= First_Entity
(Body_Id
);
4085 while Present
(E2
) loop
4086 exit when Chars
(E1
) = Chars
(E2
);
4090 if Present
(E2
) then
4091 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
4099 -- Check references in body
4101 Check_References
(Body_Id
);
4104 -- Check for nested subprogram, and mark outer level subprogram if so
4110 if Present
(Spec_Id
) then
4117 Ent
:= Enclosing_Subprogram
(Ent
);
4118 exit when No
(Ent
) or else Is_Subprogram
(Ent
);
4121 if Present
(Ent
) then
4122 Set_Has_Nested_Subprogram
(Ent
);
4126 -- When generating C code, transform a function that returns a
4127 -- constrained array type into a procedure with an out parameter
4128 -- that carries the return value.
4130 if Present
(Cloned_Body_For_C
) then
4132 Build_Procedure_Body_Form
(Spec_Id
, Cloned_Body_For_C
));
4136 Ghost_Mode
:= Save_Ghost_Mode
;
4137 end Analyze_Subprogram_Body_Helper
;
4139 ------------------------------------
4140 -- Analyze_Subprogram_Declaration --
4141 ------------------------------------
4143 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
4144 Scop
: constant Entity_Id
:= Current_Scope
;
4145 Designator
: Entity_Id
;
4147 Is_Completion
: Boolean;
4148 -- Indicates whether a null procedure declaration is a completion
4151 -- Null procedures are not allowed in SPARK
4153 if Nkind
(Specification
(N
)) = N_Procedure_Specification
4154 and then Null_Present
(Specification
(N
))
4156 Check_SPARK_05_Restriction
("null procedure is not allowed", N
);
4158 -- Null procedures are allowed in protected types, following the
4159 -- recent AI12-0147.
4161 if Is_Protected_Type
(Current_Scope
)
4162 and then Ada_Version
< Ada_2012
4164 Error_Msg_N
("protected operation cannot be a null procedure", N
);
4167 Analyze_Null_Procedure
(N
, Is_Completion
);
4169 -- The null procedure acts as a body, nothing further is needed
4171 if Is_Completion
then
4176 Designator
:= Analyze_Subprogram_Specification
(Specification
(N
));
4178 -- A reference may already have been generated for the unit name, in
4179 -- which case the following call is redundant. However it is needed for
4180 -- declarations that are the rewriting of an expression function.
4182 Generate_Definition
(Designator
);
4184 -- Set the SPARK mode from the current context (may be overwritten later
4185 -- with explicit pragma). This is not done for entry barrier functions
4186 -- because they are generated outside the protected type and should not
4187 -- carry the mode of the enclosing context.
4189 if Nkind
(N
) = N_Subprogram_Declaration
4190 and then Is_Entry_Barrier_Function
(N
)
4194 Set_SPARK_Pragma
(Designator
, SPARK_Mode_Pragma
);
4195 Set_SPARK_Pragma_Inherited
(Designator
);
4198 -- A subprogram declared within a Ghost region is automatically Ghost
4199 -- (SPARK RM 6.9(2)).
4201 if Ghost_Mode
> None
then
4202 Set_Is_Ghost_Entity
(Designator
);
4205 if Debug_Flag_C
then
4206 Write_Str
("==> subprogram spec ");
4207 Write_Name
(Chars
(Designator
));
4208 Write_Str
(" from ");
4209 Write_Location
(Sloc
(N
));
4214 Validate_RCI_Subprogram_Declaration
(N
);
4215 New_Overloaded_Entity
(Designator
);
4216 Check_Delayed_Subprogram
(Designator
);
4218 -- If the type of the first formal of the current subprogram is a non-
4219 -- generic tagged private type, mark the subprogram as being a private
4220 -- primitive. Ditto if this is a function with controlling result, and
4221 -- the return type is currently private. In both cases, the type of the
4222 -- controlling argument or result must be in the current scope for the
4223 -- operation to be primitive.
4225 if Has_Controlling_Result
(Designator
)
4226 and then Is_Private_Type
(Etype
(Designator
))
4227 and then Scope
(Etype
(Designator
)) = Current_Scope
4228 and then not Is_Generic_Actual_Type
(Etype
(Designator
))
4230 Set_Is_Private_Primitive
(Designator
);
4232 elsif Present
(First_Formal
(Designator
)) then
4234 Formal_Typ
: constant Entity_Id
:=
4235 Etype
(First_Formal
(Designator
));
4237 Set_Is_Private_Primitive
(Designator
,
4238 Is_Tagged_Type
(Formal_Typ
)
4239 and then Scope
(Formal_Typ
) = Current_Scope
4240 and then Is_Private_Type
(Formal_Typ
)
4241 and then not Is_Generic_Actual_Type
(Formal_Typ
));
4245 -- Ada 2005 (AI-251): Abstract interface primitives must be abstract
4248 if Ada_Version
>= Ada_2005
4249 and then Comes_From_Source
(N
)
4250 and then Is_Dispatching_Operation
(Designator
)
4257 if Has_Controlling_Result
(Designator
) then
4258 Etyp
:= Etype
(Designator
);
4261 E
:= First_Entity
(Designator
);
4263 and then Is_Formal
(E
)
4264 and then not Is_Controlling_Formal
(E
)
4272 if Is_Access_Type
(Etyp
) then
4273 Etyp
:= Directly_Designated_Type
(Etyp
);
4276 if Is_Interface
(Etyp
)
4277 and then not Is_Abstract_Subprogram
(Designator
)
4278 and then not (Ekind
(Designator
) = E_Procedure
4279 and then Null_Present
(Specification
(N
)))
4281 Error_Msg_Name_1
:= Chars
(Defining_Entity
(N
));
4283 -- Specialize error message based on procedures vs. functions,
4284 -- since functions can't be null subprograms.
4286 if Ekind
(Designator
) = E_Procedure
then
4288 ("interface procedure % must be abstract or null", N
);
4291 ("interface function % must be abstract", N
);
4297 -- What is the following code for, it used to be
4299 -- ??? Set_Suppress_Elaboration_Checks
4300 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
4302 -- The following seems equivalent, but a bit dubious
4304 if Elaboration_Checks_Suppressed
(Designator
) then
4305 Set_Kill_Elaboration_Checks
(Designator
);
4308 if Scop
/= Standard_Standard
and then not Is_Child_Unit
(Designator
) then
4309 Set_Categorization_From_Scope
(Designator
, Scop
);
4312 -- For a compilation unit, check for library-unit pragmas
4314 Push_Scope
(Designator
);
4315 Set_Categorization_From_Pragmas
(N
);
4316 Validate_Categorization_Dependency
(N
, Designator
);
4320 -- For a compilation unit, set body required. This flag will only be
4321 -- reset if a valid Import or Interface pragma is processed later on.
4323 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
4324 Set_Body_Required
(Parent
(N
), True);
4326 if Ada_Version
>= Ada_2005
4327 and then Nkind
(Specification
(N
)) = N_Procedure_Specification
4328 and then Null_Present
(Specification
(N
))
4331 ("null procedure cannot be declared at library level", N
);
4335 Generate_Reference_To_Formals
(Designator
);
4336 Check_Eliminated
(Designator
);
4338 if Debug_Flag_C
then
4340 Write_Str
("<== subprogram spec ");
4341 Write_Name
(Chars
(Designator
));
4342 Write_Str
(" from ");
4343 Write_Location
(Sloc
(N
));
4347 if Is_Protected_Type
(Current_Scope
) then
4349 -- Indicate that this is a protected operation, because it may be
4350 -- used in subsequent declarations within the protected type.
4352 Set_Convention
(Designator
, Convention_Protected
);
4355 List_Inherited_Pre_Post_Aspects
(Designator
);
4357 if Has_Aspects
(N
) then
4358 Analyze_Aspect_Specifications
(N
, Designator
);
4360 end Analyze_Subprogram_Declaration
;
4362 --------------------------------------
4363 -- Analyze_Subprogram_Specification --
4364 --------------------------------------
4366 -- Reminder: N here really is a subprogram specification (not a subprogram
4367 -- declaration). This procedure is called to analyze the specification in
4368 -- both subprogram bodies and subprogram declarations (specs).
4370 function Analyze_Subprogram_Specification
(N
: Node_Id
) return Entity_Id
is
4371 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
4372 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
4374 -- Start of processing for Analyze_Subprogram_Specification
4377 -- User-defined operator is not allowed in SPARK, except as a renaming
4379 if Nkind
(Defining_Unit_Name
(N
)) = N_Defining_Operator_Symbol
4380 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
4382 Check_SPARK_05_Restriction
4383 ("user-defined operator is not allowed", N
);
4386 -- Proceed with analysis. Do not emit a cross-reference entry if the
4387 -- specification comes from an expression function, because it may be
4388 -- the completion of a previous declaration. It is not, the cross-
4389 -- reference entry will be emitted for the new subprogram declaration.
4391 if Nkind
(Parent
(N
)) /= N_Expression_Function
then
4392 Generate_Definition
(Designator
);
4395 if Nkind
(N
) = N_Function_Specification
then
4396 Set_Ekind
(Designator
, E_Function
);
4397 Set_Mechanism
(Designator
, Default_Mechanism
);
4399 Set_Ekind
(Designator
, E_Procedure
);
4400 Set_Etype
(Designator
, Standard_Void_Type
);
4403 -- Flag Is_Inlined_Always is True by default, and reversed to False for
4404 -- those subprograms which could be inlined in GNATprove mode (because
4405 -- Body_To_Inline is non-Empty) but should not be inlined.
4407 if GNATprove_Mode
then
4408 Set_Is_Inlined_Always
(Designator
);
4411 -- Introduce new scope for analysis of the formals and the return type
4413 Set_Scope
(Designator
, Current_Scope
);
4415 if Present
(Formals
) then
4416 Push_Scope
(Designator
);
4417 Process_Formals
(Formals
, N
);
4419 -- Check dimensions in N for formals with default expression
4421 Analyze_Dimension_Formals
(N
, Formals
);
4423 -- Ada 2005 (AI-345): If this is an overriding operation of an
4424 -- inherited interface operation, and the controlling type is
4425 -- a synchronized type, replace the type with its corresponding
4426 -- record, to match the proper signature of an overriding operation.
4427 -- Same processing for an access parameter whose designated type is
4428 -- derived from a synchronized interface.
4430 if Ada_Version
>= Ada_2005
then
4433 Formal_Typ
: Entity_Id
;
4434 Rec_Typ
: Entity_Id
;
4435 Desig_Typ
: Entity_Id
;
4438 Formal
:= First_Formal
(Designator
);
4439 while Present
(Formal
) loop
4440 Formal_Typ
:= Etype
(Formal
);
4442 if Is_Concurrent_Type
(Formal_Typ
)
4443 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
4445 Rec_Typ
:= Corresponding_Record_Type
(Formal_Typ
);
4447 if Present
(Interfaces
(Rec_Typ
)) then
4448 Set_Etype
(Formal
, Rec_Typ
);
4451 elsif Ekind
(Formal_Typ
) = E_Anonymous_Access_Type
then
4452 Desig_Typ
:= Designated_Type
(Formal_Typ
);
4454 if Is_Concurrent_Type
(Desig_Typ
)
4455 and then Present
(Corresponding_Record_Type
(Desig_Typ
))
4457 Rec_Typ
:= Corresponding_Record_Type
(Desig_Typ
);
4459 if Present
(Interfaces
(Rec_Typ
)) then
4460 Set_Directly_Designated_Type
(Formal_Typ
, Rec_Typ
);
4465 Next_Formal
(Formal
);
4472 -- The subprogram scope is pushed and popped around the processing of
4473 -- the return type for consistency with call above to Process_Formals
4474 -- (which itself can call Analyze_Return_Type), and to ensure that any
4475 -- itype created for the return type will be associated with the proper
4478 elsif Nkind
(N
) = N_Function_Specification
then
4479 Push_Scope
(Designator
);
4480 Analyze_Return_Type
(N
);
4486 if Nkind
(N
) = N_Function_Specification
then
4488 -- Deal with operator symbol case
4490 if Nkind
(Designator
) = N_Defining_Operator_Symbol
then
4491 Valid_Operator_Definition
(Designator
);
4494 May_Need_Actuals
(Designator
);
4496 -- Ada 2005 (AI-251): If the return type is abstract, verify that
4497 -- the subprogram is abstract also. This does not apply to renaming
4498 -- declarations, where abstractness is inherited, and to subprogram
4499 -- bodies generated for stream operations, which become renamings as
4502 -- In case of primitives associated with abstract interface types
4503 -- the check is applied later (see Analyze_Subprogram_Declaration).
4505 if not Nkind_In
(Original_Node
(Parent
(N
)),
4506 N_Abstract_Subprogram_Declaration
,
4507 N_Formal_Abstract_Subprogram_Declaration
,
4508 N_Subprogram_Renaming_Declaration
)
4510 if Is_Abstract_Type
(Etype
(Designator
))
4511 and then not Is_Interface
(Etype
(Designator
))
4514 ("function that returns abstract type must be abstract", N
);
4516 -- Ada 2012 (AI-0073): Extend this test to subprograms with an
4517 -- access result whose designated type is abstract.
4519 elsif Ada_Version
>= Ada_2012
4520 and then Nkind
(Result_Definition
(N
)) = N_Access_Definition
4522 not Is_Class_Wide_Type
(Designated_Type
(Etype
(Designator
)))
4523 and then Is_Abstract_Type
(Designated_Type
(Etype
(Designator
)))
4526 ("function whose access result designates abstract type "
4527 & "must be abstract", N
);
4533 end Analyze_Subprogram_Specification
;
4535 -----------------------
4536 -- Check_Conformance --
4537 -----------------------
4539 procedure Check_Conformance
4540 (New_Id
: Entity_Id
;
4542 Ctype
: Conformance_Type
;
4544 Conforms
: out Boolean;
4545 Err_Loc
: Node_Id
:= Empty
;
4546 Get_Inst
: Boolean := False;
4547 Skip_Controlling_Formals
: Boolean := False)
4549 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
4550 -- Sets Conforms to False. If Errmsg is False, then that's all it does.
4551 -- If Errmsg is True, then processing continues to post an error message
4552 -- for conformance error on given node. Two messages are output. The
4553 -- first message points to the previous declaration with a general "no
4554 -- conformance" message. The second is the detailed reason, supplied as
4555 -- Msg. The parameter N provide information for a possible & insertion
4556 -- in the message, and also provides the location for posting the
4557 -- message in the absence of a specified Err_Loc location.
4559 -----------------------
4560 -- Conformance_Error --
4561 -----------------------
4563 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
4570 if No
(Err_Loc
) then
4576 Error_Msg_Sloc
:= Sloc
(Old_Id
);
4579 when Type_Conformant
=>
4580 Error_Msg_N
-- CODEFIX
4581 ("not type conformant with declaration#!", Enode
);
4583 when Mode_Conformant
=>
4584 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4586 ("not mode conformant with operation inherited#!",
4590 ("not mode conformant with declaration#!", Enode
);
4593 when Subtype_Conformant
=>
4594 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4596 ("not subtype conformant with operation inherited#!",
4600 ("not subtype conformant with declaration#!", Enode
);
4603 when Fully_Conformant
=>
4604 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4605 Error_Msg_N
-- CODEFIX
4606 ("not fully conformant with operation inherited#!",
4609 Error_Msg_N
-- CODEFIX
4610 ("not fully conformant with declaration#!", Enode
);
4614 Error_Msg_NE
(Msg
, Enode
, N
);
4616 end Conformance_Error
;
4620 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
4621 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
4622 Old_Formal
: Entity_Id
;
4623 New_Formal
: Entity_Id
;
4624 Access_Types_Match
: Boolean;
4625 Old_Formal_Base
: Entity_Id
;
4626 New_Formal_Base
: Entity_Id
;
4628 -- Start of processing for Check_Conformance
4633 -- We need a special case for operators, since they don't appear
4636 if Ctype
= Type_Conformant
then
4637 if Ekind
(New_Id
) = E_Operator
4638 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
4644 -- If both are functions/operators, check return types conform
4646 if Old_Type
/= Standard_Void_Type
4648 New_Type
/= Standard_Void_Type
4650 -- If we are checking interface conformance we omit controlling
4651 -- arguments and result, because we are only checking the conformance
4652 -- of the remaining parameters.
4654 if Has_Controlling_Result
(Old_Id
)
4655 and then Has_Controlling_Result
(New_Id
)
4656 and then Skip_Controlling_Formals
4660 elsif not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
4661 if Ctype
>= Subtype_Conformant
4662 and then not Predicates_Match
(Old_Type
, New_Type
)
4665 ("\predicate of return type does not match!", New_Id
);
4668 ("\return type does not match!", New_Id
);
4674 -- Ada 2005 (AI-231): In case of anonymous access types check the
4675 -- null-exclusion and access-to-constant attributes match.
4677 if Ada_Version
>= Ada_2005
4678 and then Ekind
(Etype
(Old_Type
)) = E_Anonymous_Access_Type
4680 (Can_Never_Be_Null
(Old_Type
) /= Can_Never_Be_Null
(New_Type
)
4681 or else Is_Access_Constant
(Etype
(Old_Type
)) /=
4682 Is_Access_Constant
(Etype
(New_Type
)))
4684 Conformance_Error
("\return type does not match!", New_Id
);
4688 -- If either is a function/operator and the other isn't, error
4690 elsif Old_Type
/= Standard_Void_Type
4691 or else New_Type
/= Standard_Void_Type
4693 Conformance_Error
("\functions can only match functions!", New_Id
);
4697 -- In subtype conformant case, conventions must match (RM 6.3.1(16)).
4698 -- If this is a renaming as body, refine error message to indicate that
4699 -- the conflict is with the original declaration. If the entity is not
4700 -- frozen, the conventions don't have to match, the one of the renamed
4701 -- entity is inherited.
4703 if Ctype
>= Subtype_Conformant
then
4704 if Convention
(Old_Id
) /= Convention
(New_Id
) then
4705 if not Is_Frozen
(New_Id
) then
4708 elsif Present
(Err_Loc
)
4709 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
4710 and then Present
(Corresponding_Spec
(Err_Loc
))
4712 Error_Msg_Name_1
:= Chars
(New_Id
);
4714 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
4715 Conformance_Error
("\prior declaration for% has convention %!");
4718 Conformance_Error
("\calling conventions do not match!");
4723 elsif Is_Formal_Subprogram
(Old_Id
)
4724 or else Is_Formal_Subprogram
(New_Id
)
4726 Conformance_Error
("\formal subprograms not allowed!");
4731 -- Deal with parameters
4733 -- Note: we use the entity information, rather than going directly
4734 -- to the specification in the tree. This is not only simpler, but
4735 -- absolutely necessary for some cases of conformance tests between
4736 -- operators, where the declaration tree simply does not exist.
4738 Old_Formal
:= First_Formal
(Old_Id
);
4739 New_Formal
:= First_Formal
(New_Id
);
4740 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
4741 if Is_Controlling_Formal
(Old_Formal
)
4742 and then Is_Controlling_Formal
(New_Formal
)
4743 and then Skip_Controlling_Formals
4745 -- The controlling formals will have different types when
4746 -- comparing an interface operation with its match, but both
4747 -- or neither must be access parameters.
4749 if Is_Access_Type
(Etype
(Old_Formal
))
4751 Is_Access_Type
(Etype
(New_Formal
))
4753 goto Skip_Controlling_Formal
;
4756 ("\access parameter does not match!", New_Formal
);
4760 -- Ada 2012: Mode conformance also requires that formal parameters
4761 -- be both aliased, or neither.
4763 if Ctype
>= Mode_Conformant
and then Ada_Version
>= Ada_2012
then
4764 if Is_Aliased
(Old_Formal
) /= Is_Aliased
(New_Formal
) then
4766 ("\aliased parameter mismatch!", New_Formal
);
4770 if Ctype
= Fully_Conformant
then
4772 -- Names must match. Error message is more accurate if we do
4773 -- this before checking that the types of the formals match.
4775 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
4776 Conformance_Error
("\name& does not match!", New_Formal
);
4778 -- Set error posted flag on new formal as well to stop
4779 -- junk cascaded messages in some cases.
4781 Set_Error_Posted
(New_Formal
);
4785 -- Null exclusion must match
4787 if Null_Exclusion_Present
(Parent
(Old_Formal
))
4789 Null_Exclusion_Present
(Parent
(New_Formal
))
4791 -- Only give error if both come from source. This should be
4792 -- investigated some time, since it should not be needed ???
4794 if Comes_From_Source
(Old_Formal
)
4796 Comes_From_Source
(New_Formal
)
4799 ("\null exclusion for& does not match", New_Formal
);
4801 -- Mark error posted on the new formal to avoid duplicated
4802 -- complaint about types not matching.
4804 Set_Error_Posted
(New_Formal
);
4809 -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This
4810 -- case occurs whenever a subprogram is being renamed and one of its
4811 -- parameters imposes a null exclusion. For example:
4813 -- type T is null record;
4814 -- type Acc_T is access T;
4815 -- subtype Acc_T_Sub is Acc_T;
4817 -- procedure P (Obj : not null Acc_T_Sub); -- itype
4818 -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype
4821 Old_Formal_Base
:= Etype
(Old_Formal
);
4822 New_Formal_Base
:= Etype
(New_Formal
);
4825 Old_Formal_Base
:= Get_Instance_Of
(Old_Formal_Base
);
4826 New_Formal_Base
:= Get_Instance_Of
(New_Formal_Base
);
4829 Access_Types_Match
:= Ada_Version
>= Ada_2005
4831 -- Ensure that this rule is only applied when New_Id is a
4832 -- renaming of Old_Id.
4834 and then Nkind
(Parent
(Parent
(New_Id
))) =
4835 N_Subprogram_Renaming_Declaration
4836 and then Nkind
(Name
(Parent
(Parent
(New_Id
)))) in N_Has_Entity
4837 and then Present
(Entity
(Name
(Parent
(Parent
(New_Id
)))))
4838 and then Entity
(Name
(Parent
(Parent
(New_Id
)))) = Old_Id
4840 -- Now handle the allowed access-type case
4842 and then Is_Access_Type
(Old_Formal_Base
)
4843 and then Is_Access_Type
(New_Formal_Base
)
4845 -- The type kinds must match. The only exception occurs with
4846 -- multiple generics of the form:
4849 -- type F is private; type A is private;
4850 -- type F_Ptr is access F; type A_Ptr is access A;
4851 -- with proc F_P (X : F_Ptr); with proc A_P (X : A_Ptr);
4852 -- package F_Pack is ... package A_Pack is
4853 -- package F_Inst is
4854 -- new F_Pack (A, A_Ptr, A_P);
4856 -- When checking for conformance between the parameters of A_P
4857 -- and F_P, the type kinds of F_Ptr and A_Ptr will not match
4858 -- because the compiler has transformed A_Ptr into a subtype of
4859 -- F_Ptr. We catch this case in the code below.
4861 and then (Ekind
(Old_Formal_Base
) = Ekind
(New_Formal_Base
)
4863 (Is_Generic_Type
(Old_Formal_Base
)
4864 and then Is_Generic_Type
(New_Formal_Base
)
4865 and then Is_Internal
(New_Formal_Base
)
4866 and then Etype
(Etype
(New_Formal_Base
)) =
4868 and then Directly_Designated_Type
(Old_Formal_Base
) =
4869 Directly_Designated_Type
(New_Formal_Base
)
4870 and then ((Is_Itype
(Old_Formal_Base
)
4871 and then Can_Never_Be_Null
(Old_Formal_Base
))
4873 (Is_Itype
(New_Formal_Base
)
4874 and then Can_Never_Be_Null
(New_Formal_Base
)));
4876 -- Types must always match. In the visible part of an instance,
4877 -- usual overloading rules for dispatching operations apply, and
4878 -- we check base types (not the actual subtypes).
4880 if In_Instance_Visible_Part
4881 and then Is_Dispatching_Operation
(New_Id
)
4883 if not Conforming_Types
4884 (T1
=> Base_Type
(Etype
(Old_Formal
)),
4885 T2
=> Base_Type
(Etype
(New_Formal
)),
4887 Get_Inst
=> Get_Inst
)
4888 and then not Access_Types_Match
4890 Conformance_Error
("\type of & does not match!", New_Formal
);
4894 elsif not Conforming_Types
4895 (T1
=> Old_Formal_Base
,
4896 T2
=> New_Formal_Base
,
4898 Get_Inst
=> Get_Inst
)
4899 and then not Access_Types_Match
4901 -- Don't give error message if old type is Any_Type. This test
4902 -- avoids some cascaded errors, e.g. in case of a bad spec.
4904 if Errmsg
and then Old_Formal_Base
= Any_Type
then
4907 if Ctype
>= Subtype_Conformant
4909 not Predicates_Match
(Old_Formal_Base
, New_Formal_Base
)
4912 ("\predicate of & does not match!", New_Formal
);
4915 ("\type of & does not match!", New_Formal
);
4922 -- For mode conformance, mode must match
4924 if Ctype
>= Mode_Conformant
then
4925 if Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
) then
4926 if not Ekind_In
(New_Id
, E_Function
, E_Procedure
)
4927 or else not Is_Primitive_Wrapper
(New_Id
)
4929 Conformance_Error
("\mode of & does not match!", New_Formal
);
4933 T
: constant Entity_Id
:= Find_Dispatching_Type
(New_Id
);
4935 if Is_Protected_Type
(Corresponding_Concurrent_Type
(T
))
4937 Error_Msg_PT
(New_Id
, Ultimate_Alias
(Old_Id
));
4940 ("\mode of & does not match!", New_Formal
);
4947 -- Part of mode conformance for access types is having the same
4948 -- constant modifier.
4950 elsif Access_Types_Match
4951 and then Is_Access_Constant
(Old_Formal_Base
) /=
4952 Is_Access_Constant
(New_Formal_Base
)
4955 ("\constant modifier does not match!", New_Formal
);
4960 if Ctype
>= Subtype_Conformant
then
4962 -- Ada 2005 (AI-231): In case of anonymous access types check
4963 -- the null-exclusion and access-to-constant attributes must
4964 -- match. For null exclusion, we test the types rather than the
4965 -- formals themselves, since the attribute is only set reliably
4966 -- on the formals in the Ada 95 case, and we exclude the case
4967 -- where Old_Formal is marked as controlling, to avoid errors
4968 -- when matching completing bodies with dispatching declarations
4969 -- (access formals in the bodies aren't marked Can_Never_Be_Null).
4971 if Ada_Version
>= Ada_2005
4972 and then Ekind
(Etype
(Old_Formal
)) = E_Anonymous_Access_Type
4973 and then Ekind
(Etype
(New_Formal
)) = E_Anonymous_Access_Type
4975 ((Can_Never_Be_Null
(Etype
(Old_Formal
)) /=
4976 Can_Never_Be_Null
(Etype
(New_Formal
))
4978 not Is_Controlling_Formal
(Old_Formal
))
4980 Is_Access_Constant
(Etype
(Old_Formal
)) /=
4981 Is_Access_Constant
(Etype
(New_Formal
)))
4983 -- Do not complain if error already posted on New_Formal. This
4984 -- avoids some redundant error messages.
4986 and then not Error_Posted
(New_Formal
)
4988 -- It is allowed to omit the null-exclusion in case of stream
4989 -- attribute subprograms. We recognize stream subprograms
4990 -- through their TSS-generated suffix.
4993 TSS_Name
: constant TSS_Name_Type
:= Get_TSS_Name
(New_Id
);
4996 if TSS_Name
/= TSS_Stream_Read
4997 and then TSS_Name
/= TSS_Stream_Write
4998 and then TSS_Name
/= TSS_Stream_Input
4999 and then TSS_Name
/= TSS_Stream_Output
5001 -- Here we have a definite conformance error. It is worth
5002 -- special casing the error message for the case of a
5003 -- controlling formal (which excludes null).
5005 if Is_Controlling_Formal
(New_Formal
) then
5006 Error_Msg_Node_2
:= Scope
(New_Formal
);
5008 ("\controlling formal & of & excludes null, "
5009 & "declaration must exclude null as well",
5012 -- Normal case (couldn't we give more detail here???)
5016 ("\type of & does not match!", New_Formal
);
5025 -- Full conformance checks
5027 if Ctype
= Fully_Conformant
then
5029 -- We have checked already that names match
5031 if Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
5033 -- Check default expressions for in parameters
5036 NewD
: constant Boolean :=
5037 Present
(Default_Value
(New_Formal
));
5038 OldD
: constant Boolean :=
5039 Present
(Default_Value
(Old_Formal
));
5041 if NewD
or OldD
then
5043 -- The old default value has been analyzed because the
5044 -- current full declaration will have frozen everything
5045 -- before. The new default value has not been analyzed,
5046 -- so analyze it now before we check for conformance.
5049 Push_Scope
(New_Id
);
5050 Preanalyze_Spec_Expression
5051 (Default_Value
(New_Formal
), Etype
(New_Formal
));
5055 if not (NewD
and OldD
)
5056 or else not Fully_Conformant_Expressions
5057 (Default_Value
(Old_Formal
),
5058 Default_Value
(New_Formal
))
5061 ("\default expression for & does not match!",
5070 -- A couple of special checks for Ada 83 mode. These checks are
5071 -- skipped if either entity is an operator in package Standard,
5072 -- or if either old or new instance is not from the source program.
5074 if Ada_Version
= Ada_83
5075 and then Sloc
(Old_Id
) > Standard_Location
5076 and then Sloc
(New_Id
) > Standard_Location
5077 and then Comes_From_Source
(Old_Id
)
5078 and then Comes_From_Source
(New_Id
)
5081 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
5082 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
5085 -- Explicit IN must be present or absent in both cases. This
5086 -- test is required only in the full conformance case.
5088 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
5089 and then Ctype
= Fully_Conformant
5092 ("\(Ada 83) IN must appear in both declarations",
5097 -- Grouping (use of comma in param lists) must be the same
5098 -- This is where we catch a misconformance like:
5101 -- A : Integer; B : Integer
5103 -- which are represented identically in the tree except
5104 -- for the setting of the flags More_Ids and Prev_Ids.
5106 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
5107 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
5110 ("\grouping of & does not match!", New_Formal
);
5116 -- This label is required when skipping controlling formals
5118 <<Skip_Controlling_Formal
>>
5120 Next_Formal
(Old_Formal
);
5121 Next_Formal
(New_Formal
);
5124 if Present
(Old_Formal
) then
5125 Conformance_Error
("\too few parameters!");
5128 elsif Present
(New_Formal
) then
5129 Conformance_Error
("\too many parameters!", New_Formal
);
5132 end Check_Conformance
;
5134 -----------------------
5135 -- Check_Conventions --
5136 -----------------------
5138 procedure Check_Conventions
(Typ
: Entity_Id
) is
5139 Ifaces_List
: Elist_Id
;
5141 procedure Check_Convention
(Op
: Entity_Id
);
5142 -- Verify that the convention of inherited dispatching operation Op is
5143 -- consistent among all subprograms it overrides. In order to minimize
5144 -- the search, Search_From is utilized to designate a specific point in
5145 -- the list rather than iterating over the whole list once more.
5147 ----------------------
5148 -- Check_Convention --
5149 ----------------------
5151 procedure Check_Convention
(Op
: Entity_Id
) is
5152 Op_Conv
: constant Convention_Id
:= Convention
(Op
);
5153 Iface_Conv
: Convention_Id
;
5154 Iface_Elmt
: Elmt_Id
;
5155 Iface_Prim_Elmt
: Elmt_Id
;
5156 Iface_Prim
: Entity_Id
;
5159 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
5160 while Present
(Iface_Elmt
) loop
5162 First_Elmt
(Primitive_Operations
(Node
(Iface_Elmt
)));
5163 while Present
(Iface_Prim_Elmt
) loop
5164 Iface_Prim
:= Node
(Iface_Prim_Elmt
);
5165 Iface_Conv
:= Convention
(Iface_Prim
);
5167 if Is_Interface_Conformant
(Typ
, Iface_Prim
, Op
)
5168 and then Iface_Conv
/= Op_Conv
5171 ("inconsistent conventions in primitive operations", Typ
);
5173 Error_Msg_Name_1
:= Chars
(Op
);
5174 Error_Msg_Name_2
:= Get_Convention_Name
(Op_Conv
);
5175 Error_Msg_Sloc
:= Sloc
(Op
);
5177 if Comes_From_Source
(Op
) or else No
(Alias
(Op
)) then
5178 if not Present
(Overridden_Operation
(Op
)) then
5179 Error_Msg_N
("\\primitive % defined #", Typ
);
5182 ("\\overriding operation % with "
5183 & "convention % defined #", Typ
);
5186 else pragma Assert
(Present
(Alias
(Op
)));
5187 Error_Msg_Sloc
:= Sloc
(Alias
(Op
));
5188 Error_Msg_N
("\\inherited operation % with "
5189 & "convention % defined #", Typ
);
5192 Error_Msg_Name_1
:= Chars
(Op
);
5193 Error_Msg_Name_2
:= Get_Convention_Name
(Iface_Conv
);
5194 Error_Msg_Sloc
:= Sloc
(Iface_Prim
);
5195 Error_Msg_N
("\\overridden operation % with "
5196 & "convention % defined #", Typ
);
5198 -- Avoid cascading errors
5203 Next_Elmt
(Iface_Prim_Elmt
);
5206 Next_Elmt
(Iface_Elmt
);
5208 end Check_Convention
;
5212 Prim_Op
: Entity_Id
;
5213 Prim_Op_Elmt
: Elmt_Id
;
5215 -- Start of processing for Check_Conventions
5218 if not Has_Interfaces
(Typ
) then
5222 Collect_Interfaces
(Typ
, Ifaces_List
);
5224 -- The algorithm checks every overriding dispatching operation against
5225 -- all the corresponding overridden dispatching operations, detecting
5226 -- differences in conventions.
5228 Prim_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5229 while Present
(Prim_Op_Elmt
) loop
5230 Prim_Op
:= Node
(Prim_Op_Elmt
);
5232 -- A small optimization: skip the predefined dispatching operations
5233 -- since they always have the same convention.
5235 if not Is_Predefined_Dispatching_Operation
(Prim_Op
) then
5236 Check_Convention
(Prim_Op
);
5239 Next_Elmt
(Prim_Op_Elmt
);
5241 end Check_Conventions
;
5243 ------------------------------
5244 -- Check_Delayed_Subprogram --
5245 ------------------------------
5247 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
5250 procedure Possible_Freeze
(T
: Entity_Id
);
5251 -- T is the type of either a formal parameter or of the return type.
5252 -- If T is not yet frozen and needs a delayed freeze, then the
5253 -- subprogram itself must be delayed. If T is the limited view of an
5254 -- incomplete type (or of a CW type thereof) the subprogram must be
5255 -- frozen as well, because T may depend on local types that have not
5258 ---------------------
5259 -- Possible_Freeze --
5260 ---------------------
5262 procedure Possible_Freeze
(T
: Entity_Id
) is
5264 if Has_Delayed_Freeze
(T
) and then not Is_Frozen
(T
) then
5265 Set_Has_Delayed_Freeze
(Designator
);
5267 elsif Is_Access_Type
(T
)
5268 and then Has_Delayed_Freeze
(Designated_Type
(T
))
5269 and then not Is_Frozen
(Designated_Type
(T
))
5271 Set_Has_Delayed_Freeze
(Designator
);
5273 elsif (Ekind
(T
) = E_Incomplete_Type
5274 or else Ekind
(T
) = E_Class_Wide_Type
)
5275 and then From_Limited_With
(T
)
5277 Set_Has_Delayed_Freeze
(Designator
);
5279 -- AI05-0151: In Ada 2012, Incomplete types can appear in the profile
5280 -- of a subprogram or entry declaration.
5282 elsif Ekind
(T
) = E_Incomplete_Type
5283 and then Ada_Version
>= Ada_2012
5285 Set_Has_Delayed_Freeze
(Designator
);
5288 end Possible_Freeze
;
5290 -- Start of processing for Check_Delayed_Subprogram
5293 -- All subprograms, including abstract subprograms, may need a freeze
5294 -- node if some formal type or the return type needs one.
5296 Possible_Freeze
(Etype
(Designator
));
5297 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
5299 -- Need delayed freeze if any of the formal types themselves need
5300 -- a delayed freeze and are not yet frozen.
5302 F
:= First_Formal
(Designator
);
5303 while Present
(F
) loop
5304 Possible_Freeze
(Etype
(F
));
5305 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
5309 -- Mark functions that return by reference. Note that it cannot be
5310 -- done for delayed_freeze subprograms because the underlying
5311 -- returned type may not be known yet (for private types)
5313 if not Has_Delayed_Freeze
(Designator
) and then Expander_Active
then
5315 Typ
: constant Entity_Id
:= Etype
(Designator
);
5316 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
5318 if Is_Limited_View
(Typ
) then
5319 Set_Returns_By_Ref
(Designator
);
5320 elsif Present
(Utyp
) and then CW_Or_Has_Controlled_Part
(Utyp
) then
5321 Set_Returns_By_Ref
(Designator
);
5325 end Check_Delayed_Subprogram
;
5327 ------------------------------------
5328 -- Check_Discriminant_Conformance --
5329 ------------------------------------
5331 procedure Check_Discriminant_Conformance
5336 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
5337 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
5338 New_Discr_Id
: Entity_Id
;
5339 New_Discr_Type
: Entity_Id
;
5341 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
5342 -- Post error message for conformance error on given node. Two messages
5343 -- are output. The first points to the previous declaration with a
5344 -- general "no conformance" message. The second is the detailed reason,
5345 -- supplied as Msg. The parameter N provide information for a possible
5346 -- & insertion in the message.
5348 -----------------------
5349 -- Conformance_Error --
5350 -----------------------
5352 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
5354 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
5355 Error_Msg_N
-- CODEFIX
5356 ("not fully conformant with declaration#!", N
);
5357 Error_Msg_NE
(Msg
, N
, N
);
5358 end Conformance_Error
;
5360 -- Start of processing for Check_Discriminant_Conformance
5363 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
5364 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
5366 -- The subtype mark of the discriminant on the full type has not
5367 -- been analyzed so we do it here. For an access discriminant a new
5370 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
5372 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
5375 Analyze
(Discriminant_Type
(New_Discr
));
5376 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
5378 -- Ada 2005: if the discriminant definition carries a null
5379 -- exclusion, create an itype to check properly for consistency
5380 -- with partial declaration.
5382 if Is_Access_Type
(New_Discr_Type
)
5383 and then Null_Exclusion_Present
(New_Discr
)
5386 Create_Null_Excluding_Itype
5387 (T
=> New_Discr_Type
,
5388 Related_Nod
=> New_Discr
,
5389 Scope_Id
=> Current_Scope
);
5393 if not Conforming_Types
5394 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
5396 Conformance_Error
("type of & does not match!", New_Discr_Id
);
5399 -- Treat the new discriminant as an occurrence of the old one,
5400 -- for navigation purposes, and fill in some semantic
5401 -- information, for completeness.
5403 Generate_Reference
(Old_Discr
, New_Discr_Id
, 'r');
5404 Set_Etype
(New_Discr_Id
, Etype
(Old_Discr
));
5405 Set_Scope
(New_Discr_Id
, Scope
(Old_Discr
));
5410 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
5411 Conformance_Error
("name & does not match!", New_Discr_Id
);
5415 -- Default expressions must match
5418 NewD
: constant Boolean :=
5419 Present
(Expression
(New_Discr
));
5420 OldD
: constant Boolean :=
5421 Present
(Expression
(Parent
(Old_Discr
)));
5424 if NewD
or OldD
then
5426 -- The old default value has been analyzed and expanded,
5427 -- because the current full declaration will have frozen
5428 -- everything before. The new default values have not been
5429 -- expanded, so expand now to check conformance.
5432 Preanalyze_Spec_Expression
5433 (Expression
(New_Discr
), New_Discr_Type
);
5436 if not (NewD
and OldD
)
5437 or else not Fully_Conformant_Expressions
5438 (Expression
(Parent
(Old_Discr
)),
5439 Expression
(New_Discr
))
5443 ("default expression for & does not match!",
5450 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
5452 if Ada_Version
= Ada_83
then
5454 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
5457 -- Grouping (use of comma in param lists) must be the same
5458 -- This is where we catch a misconformance like:
5461 -- A : Integer; B : Integer
5463 -- which are represented identically in the tree except
5464 -- for the setting of the flags More_Ids and Prev_Ids.
5466 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
5467 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
5470 ("grouping of & does not match!", New_Discr_Id
);
5476 Next_Discriminant
(Old_Discr
);
5480 if Present
(Old_Discr
) then
5481 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
5484 elsif Present
(New_Discr
) then
5486 ("too many discriminants!", Defining_Identifier
(New_Discr
));
5489 end Check_Discriminant_Conformance
;
5491 ----------------------------
5492 -- Check_Fully_Conformant --
5493 ----------------------------
5495 procedure Check_Fully_Conformant
5496 (New_Id
: Entity_Id
;
5498 Err_Loc
: Node_Id
:= Empty
)
5501 pragma Warnings
(Off
, Result
);
5504 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
5505 end Check_Fully_Conformant
;
5507 --------------------------
5508 -- Check_Limited_Return --
5509 --------------------------
5511 procedure Check_Limited_Return
5517 -- Ada 2005 (AI-318-02): Return-by-reference types have been removed and
5518 -- replaced by anonymous access results. This is an incompatibility with
5519 -- Ada 95. Not clear whether this should be enforced yet or perhaps
5520 -- controllable with special switch. ???
5522 -- A limited interface that is not immutably limited is OK
5524 if Is_Limited_Interface
(R_Type
)
5526 not (Is_Task_Interface
(R_Type
)
5527 or else Is_Protected_Interface
(R_Type
)
5528 or else Is_Synchronized_Interface
(R_Type
))
5532 elsif Is_Limited_Type
(R_Type
)
5533 and then not Is_Interface
(R_Type
)
5534 and then Comes_From_Source
(N
)
5535 and then not In_Instance_Body
5536 and then not OK_For_Limited_Init_In_05
(R_Type
, Expr
)
5538 -- Error in Ada 2005
5540 if Ada_Version
>= Ada_2005
5541 and then not Debug_Flag_Dot_L
5542 and then not GNAT_Mode
5545 ("(Ada 2005) cannot copy object of a limited type "
5546 & "(RM-2005 6.5(5.5/2))", Expr
);
5548 if Is_Limited_View
(R_Type
) then
5550 ("\return by reference not permitted in Ada 2005", Expr
);
5553 -- Warn in Ada 95 mode, to give folks a heads up about this
5556 -- In GNAT mode, this is just a warning, to allow it to be evilly
5557 -- turned off. Otherwise it is a real error.
5559 -- In a generic context, simplify the warning because it makes no
5560 -- sense to discuss pass-by-reference or copy.
5562 elsif Warn_On_Ada_2005_Compatibility
or GNAT_Mode
then
5563 if Inside_A_Generic
then
5565 ("return of limited object not permitted in Ada 2005 "
5566 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
5568 elsif Is_Limited_View
(R_Type
) then
5570 ("return by reference not permitted in Ada 2005 "
5571 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
5574 ("cannot copy object of a limited type in Ada 2005 "
5575 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
5578 -- Ada 95 mode, compatibility warnings disabled
5581 return; -- skip continuation messages below
5584 if not Inside_A_Generic
then
5586 ("\consider switching to return of access type", Expr
);
5587 Explain_Limited_Type
(R_Type
, Expr
);
5590 end Check_Limited_Return
;
5592 ---------------------------
5593 -- Check_Mode_Conformant --
5594 ---------------------------
5596 procedure Check_Mode_Conformant
5597 (New_Id
: Entity_Id
;
5599 Err_Loc
: Node_Id
:= Empty
;
5600 Get_Inst
: Boolean := False)
5603 pragma Warnings
(Off
, Result
);
5606 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
5607 end Check_Mode_Conformant
;
5609 --------------------------------
5610 -- Check_Overriding_Indicator --
5611 --------------------------------
5613 procedure Check_Overriding_Indicator
5615 Overridden_Subp
: Entity_Id
;
5616 Is_Primitive
: Boolean)
5622 -- No overriding indicator for literals
5624 if Ekind
(Subp
) = E_Enumeration_Literal
then
5627 elsif Ekind
(Subp
) = E_Entry
then
5628 Decl
:= Parent
(Subp
);
5630 -- No point in analyzing a malformed operator
5632 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
5633 and then Error_Posted
(Subp
)
5638 Decl
:= Unit_Declaration_Node
(Subp
);
5641 if Nkind_In
(Decl
, N_Subprogram_Body
,
5642 N_Subprogram_Body_Stub
,
5643 N_Subprogram_Declaration
,
5644 N_Abstract_Subprogram_Declaration
,
5645 N_Subprogram_Renaming_Declaration
)
5647 Spec
:= Specification
(Decl
);
5649 elsif Nkind
(Decl
) = N_Entry_Declaration
then
5656 -- The overriding operation is type conformant with the overridden one,
5657 -- but the names of the formals are not required to match. If the names
5658 -- appear permuted in the overriding operation, this is a possible
5659 -- source of confusion that is worth diagnosing. Controlling formals
5660 -- often carry names that reflect the type, and it is not worthwhile
5661 -- requiring that their names match.
5663 if Present
(Overridden_Subp
)
5664 and then Nkind
(Subp
) /= N_Defining_Operator_Symbol
5671 Form1
:= First_Formal
(Subp
);
5672 Form2
:= First_Formal
(Overridden_Subp
);
5674 -- If the overriding operation is a synchronized operation, skip
5675 -- the first parameter of the overridden operation, which is
5676 -- implicit in the new one. If the operation is declared in the
5677 -- body it is not primitive and all formals must match.
5679 if Is_Concurrent_Type
(Scope
(Subp
))
5680 and then Is_Tagged_Type
(Scope
(Subp
))
5681 and then not Has_Completion
(Scope
(Subp
))
5683 Form2
:= Next_Formal
(Form2
);
5686 if Present
(Form1
) then
5687 Form1
:= Next_Formal
(Form1
);
5688 Form2
:= Next_Formal
(Form2
);
5691 while Present
(Form1
) loop
5692 if not Is_Controlling_Formal
(Form1
)
5693 and then Present
(Next_Formal
(Form2
))
5694 and then Chars
(Form1
) = Chars
(Next_Formal
(Form2
))
5696 Error_Msg_Node_2
:= Alias
(Overridden_Subp
);
5697 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
5699 ("& does not match corresponding formal of&#",
5704 Next_Formal
(Form1
);
5705 Next_Formal
(Form2
);
5710 -- If there is an overridden subprogram, then check that there is no
5711 -- "not overriding" indicator, and mark the subprogram as overriding.
5712 -- This is not done if the overridden subprogram is marked as hidden,
5713 -- which can occur for the case of inherited controlled operations
5714 -- (see Derive_Subprogram), unless the inherited subprogram's parent
5715 -- subprogram is not itself hidden. (Note: This condition could probably
5716 -- be simplified, leaving out the testing for the specific controlled
5717 -- cases, but it seems safer and clearer this way, and echoes similar
5718 -- special-case tests of this kind in other places.)
5720 if Present
(Overridden_Subp
)
5721 and then (not Is_Hidden
(Overridden_Subp
)
5723 (Nam_In
(Chars
(Overridden_Subp
), Name_Initialize
,
5726 and then Present
(Alias
(Overridden_Subp
))
5727 and then not Is_Hidden
(Alias
(Overridden_Subp
))))
5729 if Must_Not_Override
(Spec
) then
5730 Error_Msg_Sloc
:= Sloc
(Overridden_Subp
);
5732 if Ekind
(Subp
) = E_Entry
then
5734 ("entry & overrides inherited operation #", Spec
, Subp
);
5737 ("subprogram & overrides inherited operation #", Spec
, Subp
);
5740 -- Special-case to fix a GNAT oddity: Limited_Controlled is declared
5741 -- as an extension of Root_Controlled, and thus has a useless Adjust
5742 -- operation. This operation should not be inherited by other limited
5743 -- controlled types. An explicit Adjust for them is not overriding.
5745 elsif Must_Override
(Spec
)
5746 and then Chars
(Overridden_Subp
) = Name_Adjust
5747 and then Is_Limited_Type
(Etype
(First_Formal
(Subp
)))
5748 and then Present
(Alias
(Overridden_Subp
))
5750 Is_Predefined_File_Name
5751 (Unit_File_Name
(Get_Source_Unit
(Alias
(Overridden_Subp
))))
5753 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
5755 elsif Is_Subprogram
(Subp
) then
5756 if Is_Init_Proc
(Subp
) then
5759 elsif No
(Overridden_Operation
(Subp
)) then
5761 -- For entities generated by Derive_Subprograms the overridden
5762 -- operation is the inherited primitive (which is available
5763 -- through the attribute alias)
5765 if (Is_Dispatching_Operation
(Subp
)
5766 or else Is_Dispatching_Operation
(Overridden_Subp
))
5767 and then not Comes_From_Source
(Overridden_Subp
)
5768 and then Find_Dispatching_Type
(Overridden_Subp
) =
5769 Find_Dispatching_Type
(Subp
)
5770 and then Present
(Alias
(Overridden_Subp
))
5771 and then Comes_From_Source
(Alias
(Overridden_Subp
))
5773 Set_Overridden_Operation
(Subp
, Alias
(Overridden_Subp
));
5774 Inherit_Subprogram_Contract
(Subp
, Alias
(Overridden_Subp
));
5777 Set_Overridden_Operation
(Subp
, Overridden_Subp
);
5778 Inherit_Subprogram_Contract
(Subp
, Overridden_Subp
);
5783 -- If primitive flag is set or this is a protected operation, then
5784 -- the operation is overriding at the point of its declaration, so
5785 -- warn if necessary. Otherwise it may have been declared before the
5786 -- operation it overrides and no check is required.
5789 and then not Must_Override
(Spec
)
5790 and then (Is_Primitive
5791 or else Ekind
(Scope
(Subp
)) = E_Protected_Type
)
5793 Style
.Missing_Overriding
(Decl
, Subp
);
5796 -- If Subp is an operator, it may override a predefined operation, if
5797 -- it is defined in the same scope as the type to which it applies.
5798 -- In that case Overridden_Subp is empty because of our implicit
5799 -- representation for predefined operators. We have to check whether the
5800 -- signature of Subp matches that of a predefined operator. Note that
5801 -- first argument provides the name of the operator, and the second
5802 -- argument the signature that may match that of a standard operation.
5803 -- If the indicator is overriding, then the operator must match a
5804 -- predefined signature, because we know already that there is no
5805 -- explicit overridden operation.
5807 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
then
5808 if Must_Not_Override
(Spec
) then
5810 -- If this is not a primitive or a protected subprogram, then
5811 -- "not overriding" is illegal.
5814 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
5816 Error_Msg_N
("overriding indicator only allowed "
5817 & "if subprogram is primitive", Subp
);
5819 elsif Can_Override_Operator
(Subp
) then
5821 ("subprogram& overrides predefined operator ", Spec
, Subp
);
5824 elsif Must_Override
(Spec
) then
5825 if No
(Overridden_Operation
(Subp
))
5826 and then not Can_Override_Operator
(Subp
)
5828 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
5831 elsif not Error_Posted
(Subp
)
5832 and then Style_Check
5833 and then Can_Override_Operator
(Subp
)
5835 not Is_Predefined_File_Name
5836 (Unit_File_Name
(Get_Source_Unit
(Subp
)))
5838 -- If style checks are enabled, indicate that the indicator is
5839 -- missing. However, at the point of declaration, the type of
5840 -- which this is a primitive operation may be private, in which
5841 -- case the indicator would be premature.
5843 if Has_Private_Declaration
(Etype
(Subp
))
5844 or else Has_Private_Declaration
(Etype
(First_Formal
(Subp
)))
5848 Style
.Missing_Overriding
(Decl
, Subp
);
5852 elsif Must_Override
(Spec
) then
5853 if Ekind
(Subp
) = E_Entry
then
5854 Error_Msg_NE
("entry & is not overriding", Spec
, Subp
);
5856 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
5859 -- If the operation is marked "not overriding" and it's not primitive
5860 -- then an error is issued, unless this is an operation of a task or
5861 -- protected type (RM05-8.3.1(3/2-4/2)). Error cases where "overriding"
5862 -- has been specified have already been checked above.
5864 elsif Must_Not_Override
(Spec
)
5865 and then not Is_Primitive
5866 and then Ekind
(Subp
) /= E_Entry
5867 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
5870 ("overriding indicator only allowed if subprogram is primitive",
5874 end Check_Overriding_Indicator
;
5880 -- Note: this procedure needs to know far too much about how the expander
5881 -- messes with exceptions. The use of the flag Exception_Junk and the
5882 -- incorporation of knowledge of Exp_Ch11.Expand_Local_Exception_Handlers
5883 -- works, but is not very clean. It would be better if the expansion
5884 -- routines would leave Original_Node working nicely, and we could use
5885 -- Original_Node here to ignore all the peculiar expander messing ???
5887 procedure Check_Returns
5891 Proc
: Entity_Id
:= Empty
)
5895 procedure Check_Statement_Sequence
(L
: List_Id
);
5896 -- Internal recursive procedure to check a list of statements for proper
5897 -- termination by a return statement (or a transfer of control or a
5898 -- compound statement that is itself internally properly terminated).
5900 ------------------------------
5901 -- Check_Statement_Sequence --
5902 ------------------------------
5904 procedure Check_Statement_Sequence
(L
: List_Id
) is
5909 function Assert_False
return Boolean;
5910 -- Returns True if Last_Stm is a pragma Assert (False) that has been
5911 -- rewritten as a null statement when assertions are off. The assert
5912 -- is not active, but it is still enough to kill the warning.
5918 function Assert_False
return Boolean is
5919 Orig
: constant Node_Id
:= Original_Node
(Last_Stm
);
5922 if Nkind
(Orig
) = N_Pragma
5923 and then Pragma_Name
(Orig
) = Name_Assert
5924 and then not Error_Posted
(Orig
)
5927 Arg
: constant Node_Id
:=
5928 First
(Pragma_Argument_Associations
(Orig
));
5929 Exp
: constant Node_Id
:= Expression
(Arg
);
5931 return Nkind
(Exp
) = N_Identifier
5932 and then Chars
(Exp
) = Name_False
;
5942 Raise_Exception_Call
: Boolean;
5943 -- Set True if statement sequence terminated by Raise_Exception call
5944 -- or a Reraise_Occurrence call.
5946 -- Start of processing for Check_Statement_Sequence
5949 Raise_Exception_Call
:= False;
5951 -- Get last real statement
5953 Last_Stm
:= Last
(L
);
5955 -- Deal with digging out exception handler statement sequences that
5956 -- have been transformed by the local raise to goto optimization.
5957 -- See Exp_Ch11.Expand_Local_Exception_Handlers for details. If this
5958 -- optimization has occurred, we are looking at something like:
5961 -- original stmts in block
5965 -- goto L1; | omitted if No_Exception_Propagation
5970 -- goto L3; -- skip handler when exception not raised
5972 -- <<L1>> -- target label for local exception
5986 -- and what we have to do is to dig out the estmts1 and estmts2
5987 -- sequences (which were the original sequences of statements in
5988 -- the exception handlers) and check them.
5990 if Nkind
(Last_Stm
) = N_Label
and then Exception_Junk
(Last_Stm
) then
5995 exit when Nkind
(Stm
) /= N_Block_Statement
;
5996 exit when not Exception_Junk
(Stm
);
5999 exit when Nkind
(Stm
) /= N_Label
;
6000 exit when not Exception_Junk
(Stm
);
6001 Check_Statement_Sequence
6002 (Statements
(Handled_Statement_Sequence
(Next
(Stm
))));
6007 exit when Nkind
(Stm
) /= N_Goto_Statement
;
6008 exit when not Exception_Junk
(Stm
);
6012 -- Don't count pragmas
6014 while Nkind
(Last_Stm
) = N_Pragma
6016 -- Don't count call to SS_Release (can happen after Raise_Exception)
6019 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
6021 Nkind
(Name
(Last_Stm
)) = N_Identifier
6023 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
6025 -- Don't count exception junk
6028 (Nkind_In
(Last_Stm
, N_Goto_Statement
,
6030 N_Object_Declaration
)
6031 and then Exception_Junk
(Last_Stm
))
6032 or else Nkind
(Last_Stm
) in N_Push_xxx_Label
6033 or else Nkind
(Last_Stm
) in N_Pop_xxx_Label
6035 -- Inserted code, such as finalization calls, is irrelevant: we only
6036 -- need to check original source.
6038 or else Is_Rewrite_Insertion
(Last_Stm
)
6043 -- Here we have the "real" last statement
6045 Kind
:= Nkind
(Last_Stm
);
6047 -- Transfer of control, OK. Note that in the No_Return procedure
6048 -- case, we already diagnosed any explicit return statements, so
6049 -- we can treat them as OK in this context.
6051 if Is_Transfer
(Last_Stm
) then
6054 -- Check cases of explicit non-indirect procedure calls
6056 elsif Kind
= N_Procedure_Call_Statement
6057 and then Is_Entity_Name
(Name
(Last_Stm
))
6059 -- Check call to Raise_Exception procedure which is treated
6060 -- specially, as is a call to Reraise_Occurrence.
6062 -- We suppress the warning in these cases since it is likely that
6063 -- the programmer really does not expect to deal with the case
6064 -- of Null_Occurrence, and thus would find a warning about a
6065 -- missing return curious, and raising Program_Error does not
6066 -- seem such a bad behavior if this does occur.
6068 -- Note that in the Ada 2005 case for Raise_Exception, the actual
6069 -- behavior will be to raise Constraint_Error (see AI-329).
6071 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
6073 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
6075 Raise_Exception_Call
:= True;
6077 -- For Raise_Exception call, test first argument, if it is
6078 -- an attribute reference for a 'Identity call, then we know
6079 -- that the call cannot possibly return.
6082 Arg
: constant Node_Id
:=
6083 Original_Node
(First_Actual
(Last_Stm
));
6085 if Nkind
(Arg
) = N_Attribute_Reference
6086 and then Attribute_Name
(Arg
) = Name_Identity
6093 -- If statement, need to look inside if there is an else and check
6094 -- each constituent statement sequence for proper termination.
6096 elsif Kind
= N_If_Statement
6097 and then Present
(Else_Statements
(Last_Stm
))
6099 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
6100 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
6102 if Present
(Elsif_Parts
(Last_Stm
)) then
6104 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
6107 while Present
(Elsif_Part
) loop
6108 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
6116 -- Case statement, check each case for proper termination
6118 elsif Kind
= N_Case_Statement
then
6122 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
6123 while Present
(Case_Alt
) loop
6124 Check_Statement_Sequence
(Statements
(Case_Alt
));
6125 Next_Non_Pragma
(Case_Alt
);
6131 -- Block statement, check its handled sequence of statements
6133 elsif Kind
= N_Block_Statement
then
6139 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
6148 -- Loop statement. If there is an iteration scheme, we can definitely
6149 -- fall out of the loop. Similarly if there is an exit statement, we
6150 -- can fall out. In either case we need a following return.
6152 elsif Kind
= N_Loop_Statement
then
6153 if Present
(Iteration_Scheme
(Last_Stm
))
6154 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
6158 -- A loop with no exit statement or iteration scheme is either
6159 -- an infinite loop, or it has some other exit (raise/return).
6160 -- In either case, no warning is required.
6166 -- Timed entry call, check entry call and delay alternatives
6168 -- Note: in expanded code, the timed entry call has been converted
6169 -- to a set of expanded statements on which the check will work
6170 -- correctly in any case.
6172 elsif Kind
= N_Timed_Entry_Call
then
6174 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
6175 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
6178 -- If statement sequence of entry call alternative is missing,
6179 -- then we can definitely fall through, and we post the error
6180 -- message on the entry call alternative itself.
6182 if No
(Statements
(ECA
)) then
6185 -- If statement sequence of delay alternative is missing, then
6186 -- we can definitely fall through, and we post the error
6187 -- message on the delay alternative itself.
6189 -- Note: if both ECA and DCA are missing the return, then we
6190 -- post only one message, should be enough to fix the bugs.
6191 -- If not we will get a message next time on the DCA when the
6194 elsif No
(Statements
(DCA
)) then
6197 -- Else check both statement sequences
6200 Check_Statement_Sequence
(Statements
(ECA
));
6201 Check_Statement_Sequence
(Statements
(DCA
));
6206 -- Conditional entry call, check entry call and else part
6208 -- Note: in expanded code, the conditional entry call has been
6209 -- converted to a set of expanded statements on which the check
6210 -- will work correctly in any case.
6212 elsif Kind
= N_Conditional_Entry_Call
then
6214 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
6217 -- If statement sequence of entry call alternative is missing,
6218 -- then we can definitely fall through, and we post the error
6219 -- message on the entry call alternative itself.
6221 if No
(Statements
(ECA
)) then
6224 -- Else check statement sequence and else part
6227 Check_Statement_Sequence
(Statements
(ECA
));
6228 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
6234 -- If we fall through, issue appropriate message
6238 -- Kill warning if last statement is a raise exception call,
6239 -- or a pragma Assert (False). Note that with assertions enabled,
6240 -- such a pragma has been converted into a raise exception call
6241 -- already, so the Assert_False is for the assertions off case.
6243 if not Raise_Exception_Call
and then not Assert_False
then
6245 -- In GNATprove mode, it is an error to have a missing return
6247 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6249 -- Issue error message or warning
6252 ("RETURN statement missing following this statement<<!",
6255 ("\Program_Error ]<<!", Last_Stm
);
6258 -- Note: we set Err even though we have not issued a warning
6259 -- because we still have a case of a missing return. This is
6260 -- an extremely marginal case, probably will never be noticed
6261 -- but we might as well get it right.
6265 -- Otherwise we have the case of a procedure marked No_Return
6268 if not Raise_Exception_Call
then
6269 if GNATprove_Mode
then
6271 ("implied return after this statement "
6272 & "would have raised Program_Error", Last_Stm
);
6275 ("implied return after this statement "
6276 & "will raise Program_Error??", Last_Stm
);
6279 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6281 ("\procedure & is marked as No_Return<<!", Last_Stm
, Proc
);
6285 RE
: constant Node_Id
:=
6286 Make_Raise_Program_Error
(Sloc
(Last_Stm
),
6287 Reason
=> PE_Implicit_Return
);
6289 Insert_After
(Last_Stm
, RE
);
6293 end Check_Statement_Sequence
;
6295 -- Start of processing for Check_Returns
6299 Check_Statement_Sequence
(Statements
(HSS
));
6301 if Present
(Exception_Handlers
(HSS
)) then
6302 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
6303 while Present
(Handler
) loop
6304 Check_Statement_Sequence
(Statements
(Handler
));
6305 Next_Non_Pragma
(Handler
);
6310 ----------------------------
6311 -- Check_Subprogram_Order --
6312 ----------------------------
6314 procedure Check_Subprogram_Order
(N
: Node_Id
) is
6316 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
6317 -- This is used to check if S1 > S2 in the sense required by this test,
6318 -- for example nameab < namec, but name2 < name10.
6320 -----------------------------
6321 -- Subprogram_Name_Greater --
6322 -----------------------------
6324 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
6329 -- Deal with special case where names are identical except for a
6330 -- numerical suffix. These are handled specially, taking the numeric
6331 -- ordering from the suffix into account.
6334 while S1
(L1
) in '0' .. '9' loop
6339 while S2
(L2
) in '0' .. '9' loop
6343 -- If non-numeric parts non-equal, do straight compare
6345 if S1
(S1
'First .. L1
) /= S2
(S2
'First .. L2
) then
6348 -- If non-numeric parts equal, compare suffixed numeric parts. Note
6349 -- that a missing suffix is treated as numeric zero in this test.
6353 while L1
< S1
'Last loop
6355 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
6359 while L2
< S2
'Last loop
6361 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
6366 end Subprogram_Name_Greater
;
6368 -- Start of processing for Check_Subprogram_Order
6371 -- Check body in alpha order if this is option
6374 and then Style_Check_Order_Subprograms
6375 and then Nkind
(N
) = N_Subprogram_Body
6376 and then Comes_From_Source
(N
)
6377 and then In_Extended_Main_Source_Unit
(N
)
6381 renames Scope_Stack
.Table
6382 (Scope_Stack
.Last
).Last_Subprogram_Name
;
6384 Body_Id
: constant Entity_Id
:=
6385 Defining_Entity
(Specification
(N
));
6388 Get_Decoded_Name_String
(Chars
(Body_Id
));
6391 if Subprogram_Name_Greater
6392 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
6394 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
6400 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
6403 end Check_Subprogram_Order;
6405 ------------------------------
6406 -- Check_Subtype_Conformant --
6407 ------------------------------
6409 procedure Check_Subtype_Conformant
6410 (New_Id : Entity_Id;
6412 Err_Loc : Node_Id := Empty;
6413 Skip_Controlling_Formals : Boolean := False;
6414 Get_Inst : Boolean := False)
6417 pragma Warnings (Off, Result);
6420 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc,
6421 Skip_Controlling_Formals => Skip_Controlling_Formals,
6422 Get_Inst => Get_Inst);
6423 end Check_Subtype_Conformant;
6425 ---------------------------
6426 -- Check_Type_Conformant --
6427 ---------------------------
6429 procedure Check_Type_Conformant
6430 (New_Id : Entity_Id;
6432 Err_Loc : Node_Id := Empty)
6435 pragma Warnings (Off, Result);
6438 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
6439 end Check_Type_Conformant;
6441 ---------------------------
6442 -- Can_Override_Operator --
6443 ---------------------------
6445 function Can_Override_Operator (Subp : Entity_Id) return Boolean is
6449 if Nkind (Subp) /= N_Defining_Operator_Symbol then
6453 Typ := Base_Type (Etype (First_Formal (Subp)));
6455 -- Check explicitly that the operation is a primitive of the type
6457 return Operator_Matches_Spec (Subp, Subp)
6458 and then not Is_Generic_Type (Typ)
6459 and then Scope (Subp) = Scope (Typ)
6460 and then not Is_Class_Wide_Type (Typ);
6462 end Can_Override_Operator;
6464 ----------------------
6465 -- Conforming_Types --
6466 ----------------------
6468 function Conforming_Types
6471 Ctype : Conformance_Type;
6472 Get_Inst : Boolean := False) return Boolean
6474 Type_1 : Entity_Id := T1;
6475 Type_2 : Entity_Id := T2;
6476 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
6478 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
6479 -- If neither T1 nor T2 are generic actual types, or if they are in
6480 -- different scopes (e.g. parent and child instances), then verify that
6481 -- the base types are equal. Otherwise T1 and T2 must be on the same
6482 -- subtype chain. The whole purpose of this procedure is to prevent
6483 -- spurious ambiguities in an instantiation that may arise if two
6484 -- distinct generic types are instantiated with the same actual.
6486 function Find_Designated_Type (T : Entity_Id) return Entity_Id;
6487 -- An access parameter can designate an incomplete type. If the
6488 -- incomplete type is the limited view of a type from a limited_
6489 -- with_clause, check whether the non-limited view is available. If
6490 -- it is a (non-limited) incomplete type, get the full view.
6492 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean;
6493 -- Returns True if and only if either T1 denotes a limited view of T2
6494 -- or T2 denotes a limited view of T1. This can arise when the limited
6495 -- with view of a type is used in a subprogram declaration and the
6496 -- subprogram body is in the scope of a regular with clause for the
6497 -- same unit. In such a case, the two type entities can be considered
6498 -- identical for purposes of conformance checking.
6500 ----------------------
6501 -- Base_Types_Match --
6502 ----------------------
6504 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
6505 BT1 : constant Entity_Id := Base_Type (T1);
6506 BT2 : constant Entity_Id := Base_Type (T2);
6512 elsif BT1 = BT2 then
6514 -- The following is too permissive. A more precise test should
6515 -- check that the generic actual is an ancestor subtype of the
6518 -- See code in Find_Corresponding_Spec that applies an additional
6519 -- filter to handle accidental amiguities in instances.
6521 return not Is_Generic_Actual_Type (T1)
6522 or else not Is_Generic_Actual_Type (T2)
6523 or else Scope (T1) /= Scope (T2);
6525 -- If T2 is a generic actual type it is declared as the subtype of
6526 -- the actual. If that actual is itself a subtype we need to use its
6527 -- own base type to check for compatibility.
6529 elsif Ekind (BT2) = Ekind (T2) and then BT1 = Base_Type (BT2) then
6532 elsif Ekind (BT1) = Ekind (T1) and then BT2 = Base_Type (BT1) then
6538 end Base_Types_Match;
6540 --------------------------
6541 -- Find_Designated_Type --
6542 --------------------------
6544 function Find_Designated_Type (T : Entity_Id) return Entity_Id is
6548 Desig := Directly_Designated_Type (T);
6550 if Ekind (Desig) = E_Incomplete_Type then
6552 -- If regular incomplete type, get full view if available
6554 if Present (Full_View (Desig)) then
6555 Desig := Full_View (Desig);
6557 -- If limited view of a type, get non-limited view if available,
6558 -- and check again for a regular incomplete type.
6560 elsif Present (Non_Limited_View (Desig)) then
6561 Desig := Get_Full_View (Non_Limited_View (Desig));
6566 end Find_Designated_Type;
6568 -------------------------------
6569 -- Matches_Limited_With_View --
6570 -------------------------------
6572 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean is
6574 -- In some cases a type imported through a limited_with clause, and
6575 -- its nonlimited view are both visible, for example in an anonymous
6576 -- access-to-class-wide type in a formal, or when building the body
6577 -- for a subprogram renaming after the subprogram has been frozen.
6578 -- In these cases Both entities designate the same type. In addition,
6579 -- if one of them is an actual in an instance, it may be a subtype of
6580 -- the non-limited view of the other.
6582 if From_Limited_With (T1)
6583 and then (T2 = Available_View (T1)
6584 or else Is_Subtype_Of (T2, Available_View (T1)))
6588 elsif From_Limited_With (T2)
6589 and then (T1 = Available_View (T2)
6590 or else Is_Subtype_Of (T1, Available_View (T2)))
6594 elsif From_Limited_With (T1)
6595 and then From_Limited_With (T2)
6596 and then Available_View (T1) = Available_View (T2)
6603 end Matches_Limited_With_View;
6605 -- Start of processing for Conforming_Types
6608 -- The context is an instance association for a formal access-to-
6609 -- subprogram type; the formal parameter types require mapping because
6610 -- they may denote other formal parameters of the generic unit.
6613 Type_1 := Get_Instance_Of (T1);
6614 Type_2 := Get_Instance_Of (T2);
6617 -- If one of the types is a view of the other introduced by a limited
6618 -- with clause, treat these as conforming for all purposes.
6620 if Matches_Limited_With_View (T1, T2) then
6623 elsif Base_Types_Match (Type_1, Type_2) then
6624 return Ctype <= Mode_Conformant
6625 or else Subtypes_Statically_Match (Type_1, Type_2);
6627 elsif Is_Incomplete_Or_Private_Type (Type_1)
6628 and then Present (Full_View (Type_1))
6629 and then Base_Types_Match (Full_View (Type_1), Type_2)
6631 return Ctype <= Mode_Conformant
6632 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
6634 elsif Ekind (Type_2) = E_Incomplete_Type
6635 and then Present (Full_View (Type_2))
6636 and then Base_Types_Match (Type_1, Full_View (Type_2))
6638 return Ctype <= Mode_Conformant
6639 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
6641 elsif Is_Private_Type (Type_2)
6642 and then In_Instance
6643 and then Present (Full_View (Type_2))
6644 and then Base_Types_Match (Type_1, Full_View (Type_2))
6646 return Ctype <= Mode_Conformant
6647 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
6649 -- In Ada 2012, incomplete types (including limited views) can appear
6650 -- as actuals in instantiations.
6652 elsif Is_Incomplete_Type (Type_1)
6653 and then Is_Incomplete_Type (Type_2)
6654 and then (Used_As_Generic_Actual (Type_1)
6655 or else Used_As_Generic_Actual (Type_2))
6660 -- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be
6661 -- treated recursively because they carry a signature. As far as
6662 -- conformance is concerned, convention plays no role, and either
6663 -- or both could be access to protected subprograms.
6665 Are_Anonymous_Access_To_Subprogram_Types :=
6666 Ekind_In (Type_1, E_Anonymous_Access_Subprogram_Type,
6667 E_Anonymous_Access_Protected_Subprogram_Type)
6669 Ekind_In (Type_2, E_Anonymous_Access_Subprogram_Type,
6670 E_Anonymous_Access_Protected_Subprogram_Type);
6672 -- Test anonymous access type case. For this case, static subtype
6673 -- matching is required for mode conformance (RM 6.3.1(15)). We check
6674 -- the base types because we may have built internal subtype entities
6675 -- to handle null-excluding types (see Process_Formals).
6677 if (Ekind (Base_Type (Type_1)) = E_Anonymous_Access_Type
6679 Ekind (Base_Type (Type_2)) = E_Anonymous_Access_Type)
6681 -- Ada 2005 (AI-254)
6683 or else Are_Anonymous_Access_To_Subprogram_Types
6686 Desig_1 : Entity_Id;
6687 Desig_2 : Entity_Id;
6690 -- In Ada 2005, access constant indicators must match for
6691 -- subtype conformance.
6693 if Ada_Version >= Ada_2005
6694 and then Ctype >= Subtype_Conformant
6696 Is_Access_Constant (Type_1) /= Is_Access_Constant (Type_2)
6701 Desig_1 := Find_Designated_Type (Type_1);
6702 Desig_2 := Find_Designated_Type (Type_2);
6704 -- If the context is an instance association for a formal
6705 -- access-to-subprogram type; formal access parameter designated
6706 -- types require mapping because they may denote other formal
6707 -- parameters of the generic unit.
6710 Desig_1 := Get_Instance_Of (Desig_1);
6711 Desig_2 := Get_Instance_Of (Desig_2);
6714 -- It is possible for a Class_Wide_Type to be introduced for an
6715 -- incomplete type, in which case there is a separate class_ wide
6716 -- type for the full view. The types conform if their Etypes
6717 -- conform, i.e. one may be the full view of the other. This can
6718 -- only happen in the context of an access parameter, other uses
6719 -- of an incomplete Class_Wide_Type are illegal.
6721 if Is_Class_Wide_Type (Desig_1)
6723 Is_Class_Wide_Type (Desig_2)
6727 (Etype (Base_Type (Desig_1)),
6728 Etype (Base_Type (Desig_2)), Ctype);
6730 elsif Are_Anonymous_Access_To_Subprogram_Types then
6731 if Ada_Version < Ada_2005 then
6732 return Ctype = Type_Conformant
6734 Subtypes_Statically_Match (Desig_1, Desig_2);
6736 -- We must check the conformance of the signatures themselves
6740 Conformant : Boolean;
6743 (Desig_1, Desig_2, Ctype, False, Conformant);
6748 -- A limited view of an actual matches the corresponding
6749 -- incomplete formal.
6751 elsif Ekind (Desig_2) = E_Incomplete_Subtype
6752 and then From_Limited_With (Desig_2)
6753 and then Used_As_Generic_Actual (Etype (Desig_2))
6758 return Base_Type (Desig_1) = Base_Type (Desig_2)
6759 and then (Ctype = Type_Conformant
6761 Subtypes_Statically_Match (Desig_1, Desig_2));
6765 -- Otherwise definitely no match
6768 if ((Ekind (Type_1) = E_Anonymous_Access_Type
6769 and then Is_Access_Type (Type_2))
6770 or else (Ekind (Type_2) = E_Anonymous_Access_Type
6771 and then Is_Access_Type (Type_1)))
6774 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
6776 May_Hide_Profile := True;
6781 end Conforming_Types;
6783 --------------------------
6784 -- Create_Extra_Formals --
6785 --------------------------
6787 procedure Create_Extra_Formals (E : Entity_Id) is
6789 First_Extra : Entity_Id := Empty;
6790 Last_Extra : Entity_Id;
6791 Formal_Type : Entity_Id;
6792 P_Formal : Entity_Id := Empty;
6794 function Add_Extra_Formal
6795 (Assoc_Entity : Entity_Id;
6798 Suffix : String) return Entity_Id;
6799 -- Add an extra formal to the current list of formals and extra formals.
6800 -- The extra formal is added to the end of the list of extra formals,
6801 -- and also returned as the result. These formals are always of mode IN.
6802 -- The new formal has the type Typ, is declared in Scope, and its name
6803 -- is given by a concatenation of the name of Assoc_Entity and Suffix.
6804 -- The following suffixes are currently used. They should not be changed
6805 -- without coordinating with CodePeer, which makes use of these to
6806 -- provide better messages.
6808 -- O denotes the Constrained bit.
6809 -- L denotes the accessibility level.
6810 -- BIP_xxx denotes an extra formal for a build-in-place function. See
6811 -- the full list in exp_ch6.BIP_Formal_Kind.
6813 ----------------------
6814 -- Add_Extra_Formal --
6815 ----------------------
6817 function Add_Extra_Formal
6818 (Assoc_Entity : Entity_Id;
6821 Suffix : String) return Entity_Id
6823 EF : constant Entity_Id :=
6824 Make_Defining_Identifier (Sloc (Assoc_Entity),
6825 Chars => New_External_Name (Chars (Assoc_Entity),
6829 -- A little optimization. Never generate an extra formal for the
6830 -- _init operand of an initialization procedure, since it could
6833 if Chars (Formal) = Name_uInit then
6837 Set_Ekind (EF, E_In_Parameter);
6838 Set_Actual_Subtype (EF, Typ);
6839 Set_Etype (EF, Typ);
6840 Set_Scope (EF, Scope);
6841 Set_Mechanism (EF, Default_Mechanism);
6842 Set_Formal_Validity (EF);
6844 if No (First_Extra) then
6846 Set_Extra_Formals (Scope, First_Extra);
6849 if Present (Last_Extra) then
6850 Set_Extra_Formal (Last_Extra, EF);
6856 end Add_Extra_Formal;
6858 -- Start of processing for Create_Extra_Formals
6861 -- We never generate extra formals if expansion is not active because we
6862 -- don't need them unless we are generating code.
6864 if not Expander_Active then
6868 -- No need to generate extra formals in interface thunks whose target
6869 -- primitive has no extra formals.
6871 if Is_Thunk (E) and then No (Extra_Formals (Thunk_Entity (E))) then
6875 -- If this is a derived subprogram then the subtypes of the parent
6876 -- subprogram's formal parameters will be used to determine the need
6877 -- for extra formals.
6879 if Is_Overloadable (E) and then Present (Alias (E)) then
6880 P_Formal := First_Formal (Alias (E));
6883 Last_Extra := Empty;
6884 Formal := First_Formal (E);
6885 while Present (Formal) loop
6886 Last_Extra := Formal;
6887 Next_Formal (Formal);
6890 -- If Extra_Formals were already created, don't do it again. This
6891 -- situation may arise for subprogram types created as part of
6892 -- dispatching calls (see Expand_Dispatching_Call)
6894 if Present (Last_Extra) and then Present (Extra_Formal (Last_Extra)) then
6898 -- If the subprogram is a predefined dispatching subprogram then don't
6899 -- generate any extra constrained or accessibility level formals. In
6900 -- general we suppress these for internal subprograms (by not calling
6901 -- Freeze_Subprogram and Create_Extra_Formals at all), but internally
6902 -- generated stream attributes do get passed through because extra
6903 -- build-in-place formals are needed in some cases (limited 'Input
).
6905 if Is_Predefined_Internal_Operation
(E
) then
6906 goto Test_For_Func_Result_Extras
;
6909 Formal
:= First_Formal
(E
);
6910 while Present
(Formal
) loop
6912 -- Create extra formal for supporting the attribute 'Constrained.
6913 -- The case of a private type view without discriminants also
6914 -- requires the extra formal if the underlying type has defaulted
6917 if Ekind
(Formal
) /= E_In_Parameter
then
6918 if Present
(P_Formal
) then
6919 Formal_Type
:= Etype
(P_Formal
);
6921 Formal_Type
:= Etype
(Formal
);
6924 -- Do not produce extra formals for Unchecked_Union parameters.
6925 -- Jump directly to the end of the loop.
6927 if Is_Unchecked_Union
(Base_Type
(Formal_Type
)) then
6928 goto Skip_Extra_Formal_Generation
;
6931 if not Has_Discriminants
(Formal_Type
)
6932 and then Ekind
(Formal_Type
) in Private_Kind
6933 and then Present
(Underlying_Type
(Formal_Type
))
6935 Formal_Type
:= Underlying_Type
(Formal_Type
);
6938 -- Suppress the extra formal if formal's subtype is constrained or
6939 -- indefinite, or we're compiling for Ada 2012 and the underlying
6940 -- type is tagged and limited. In Ada 2012, a limited tagged type
6941 -- can have defaulted discriminants, but 'Constrained is required
6942 -- to return True, so the formal is never needed (see AI05-0214).
6943 -- Note that this ensures consistency of calling sequences for
6944 -- dispatching operations when some types in a class have defaults
6945 -- on discriminants and others do not (and requiring the extra
6946 -- formal would introduce distributed overhead).
6948 -- If the type does not have a completion yet, treat as prior to
6949 -- Ada 2012 for consistency.
6951 if Has_Discriminants
(Formal_Type
)
6952 and then not Is_Constrained
(Formal_Type
)
6953 and then Is_Definite_Subtype
(Formal_Type
)
6954 and then (Ada_Version
< Ada_2012
6955 or else No
(Underlying_Type
(Formal_Type
))
6957 (Is_Limited_Type
(Formal_Type
)
6960 (Underlying_Type
(Formal_Type
)))))
6962 Set_Extra_Constrained
6963 (Formal
, Add_Extra_Formal
(Formal
, Standard_Boolean
, E
, "O"));
6967 -- Create extra formal for supporting accessibility checking. This
6968 -- is done for both anonymous access formals and formals of named
6969 -- access types that are marked as controlling formals. The latter
6970 -- case can occur when Expand_Dispatching_Call creates a subprogram
6971 -- type and substitutes the types of access-to-class-wide actuals
6972 -- for the anonymous access-to-specific-type of controlling formals.
6973 -- Base_Type is applied because in cases where there is a null
6974 -- exclusion the formal may have an access subtype.
6976 -- This is suppressed if we specifically suppress accessibility
6977 -- checks at the package level for either the subprogram, or the
6978 -- package in which it resides. However, we do not suppress it
6979 -- simply if the scope has accessibility checks suppressed, since
6980 -- this could cause trouble when clients are compiled with a
6981 -- different suppression setting. The explicit checks at the
6982 -- package level are safe from this point of view.
6984 if (Ekind
(Base_Type
(Etype
(Formal
))) = E_Anonymous_Access_Type
6985 or else (Is_Controlling_Formal
(Formal
)
6986 and then Is_Access_Type
(Base_Type
(Etype
(Formal
)))))
6988 (Explicit_Suppress
(E
, Accessibility_Check
)
6990 Explicit_Suppress
(Scope
(E
), Accessibility_Check
))
6993 or else Present
(Extra_Accessibility
(P_Formal
)))
6995 Set_Extra_Accessibility
6996 (Formal
, Add_Extra_Formal
(Formal
, Standard_Natural
, E
, "L"));
6999 -- This label is required when skipping extra formal generation for
7000 -- Unchecked_Union parameters.
7002 <<Skip_Extra_Formal_Generation
>>
7004 if Present
(P_Formal
) then
7005 Next_Formal
(P_Formal
);
7008 Next_Formal
(Formal
);
7011 <<Test_For_Func_Result_Extras
>>
7013 -- Ada 2012 (AI05-234): "the accessibility level of the result of a
7014 -- function call is ... determined by the point of call ...".
7016 if Needs_Result_Accessibility_Level
(E
) then
7017 Set_Extra_Accessibility_Of_Result
7018 (E
, Add_Extra_Formal
(E
, Standard_Natural
, E
, "L"));
7021 -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add
7022 -- appropriate extra formals. See type Exp_Ch6.BIP_Formal_Kind.
7024 if Ada_Version
>= Ada_2005
and then Is_Build_In_Place_Function
(E
) then
7026 Result_Subt
: constant Entity_Id
:= Etype
(E
);
7027 Full_Subt
: constant Entity_Id
:= Available_View
(Result_Subt
);
7028 Formal_Typ
: Entity_Id
;
7030 Discard
: Entity_Id
;
7031 pragma Warnings
(Off
, Discard
);
7034 -- In the case of functions with unconstrained result subtypes,
7035 -- add a 4-state formal indicating whether the return object is
7036 -- allocated by the caller (1), or should be allocated by the
7037 -- callee on the secondary stack (2), in the global heap (3), or
7038 -- in a user-defined storage pool (4). For the moment we just use
7039 -- Natural for the type of this formal. Note that this formal
7040 -- isn't usually needed in the case where the result subtype is
7041 -- constrained, but it is needed when the function has a tagged
7042 -- result, because generally such functions can be called in a
7043 -- dispatching context and such calls must be handled like calls
7044 -- to a class-wide function.
7046 if Needs_BIP_Alloc_Form
(E
) then
7049 (E
, Standard_Natural
,
7050 E
, BIP_Formal_Suffix
(BIP_Alloc_Form
));
7052 -- Add BIP_Storage_Pool, in case BIP_Alloc_Form indicates to
7053 -- use a user-defined pool. This formal is not added on
7054 -- ZFP as those targets do not support pools.
7056 if RTE_Available
(RE_Root_Storage_Pool_Ptr
) then
7059 (E
, RTE
(RE_Root_Storage_Pool_Ptr
),
7060 E
, BIP_Formal_Suffix
(BIP_Storage_Pool
));
7064 -- In the case of functions whose result type needs finalization,
7065 -- add an extra formal which represents the finalization master.
7067 if Needs_BIP_Finalization_Master
(E
) then
7070 (E
, RTE
(RE_Finalization_Master_Ptr
),
7071 E
, BIP_Formal_Suffix
(BIP_Finalization_Master
));
7074 -- When the result type contains tasks, add two extra formals: the
7075 -- master of the tasks to be created, and the caller's activation
7078 if Has_Task
(Full_Subt
) then
7081 (E
, RTE
(RE_Master_Id
),
7082 E
, BIP_Formal_Suffix
(BIP_Task_Master
));
7085 (E
, RTE
(RE_Activation_Chain_Access
),
7086 E
, BIP_Formal_Suffix
(BIP_Activation_Chain
));
7089 -- All build-in-place functions get an extra formal that will be
7090 -- passed the address of the return object within the caller.
7093 Create_Itype
(E_Anonymous_Access_Type
, E
, Scope_Id
=> Scope
(E
));
7095 Set_Directly_Designated_Type
(Formal_Typ
, Result_Subt
);
7096 Set_Etype
(Formal_Typ
, Formal_Typ
);
7097 Set_Depends_On_Private
7098 (Formal_Typ
, Has_Private_Component
(Formal_Typ
));
7099 Set_Is_Public
(Formal_Typ
, Is_Public
(Scope
(Formal_Typ
)));
7100 Set_Is_Access_Constant
(Formal_Typ
, False);
7102 -- Ada 2005 (AI-50217): Propagate the attribute that indicates
7103 -- the designated type comes from the limited view (for back-end
7106 Set_From_Limited_With
7107 (Formal_Typ
, From_Limited_With
(Result_Subt
));
7109 Layout_Type
(Formal_Typ
);
7113 (E
, Formal_Typ
, E
, BIP_Formal_Suffix
(BIP_Object_Access
));
7116 end Create_Extra_Formals
;
7118 -----------------------------
7119 -- Enter_Overloaded_Entity --
7120 -----------------------------
7122 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
7123 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
7124 C_E
: Entity_Id
:= Current_Entity
(S
);
7128 Set_Has_Homonym
(E
);
7129 Set_Has_Homonym
(S
);
7132 Set_Is_Immediately_Visible
(S
);
7133 Set_Scope
(S
, Current_Scope
);
7135 -- Chain new entity if front of homonym in current scope, so that
7136 -- homonyms are contiguous.
7138 if Present
(E
) and then E
/= C_E
then
7139 while Homonym
(C_E
) /= E
loop
7140 C_E
:= Homonym
(C_E
);
7143 Set_Homonym
(C_E
, S
);
7147 Set_Current_Entity
(S
);
7152 if Is_Inherited_Operation
(S
) then
7153 Append_Inherited_Subprogram
(S
);
7155 Append_Entity
(S
, Current_Scope
);
7158 Set_Public_Status
(S
);
7160 if Debug_Flag_E
then
7161 Write_Str
("New overloaded entity chain: ");
7162 Write_Name
(Chars
(S
));
7165 while Present
(E
) loop
7166 Write_Str
(" "); Write_Int
(Int
(E
));
7173 -- Generate warning for hiding
7176 and then Comes_From_Source
(S
)
7177 and then In_Extended_Main_Source_Unit
(S
)
7184 -- Warn unless genuine overloading. Do not emit warning on
7185 -- hiding predefined operators in Standard (these are either an
7186 -- (artifact of our implicit declarations, or simple noise) but
7187 -- keep warning on a operator defined on a local subtype, because
7188 -- of the real danger that different operators may be applied in
7189 -- various parts of the program.
7191 -- Note that if E and S have the same scope, there is never any
7192 -- hiding. Either the two conflict, and the program is illegal,
7193 -- or S is overriding an implicit inherited subprogram.
7195 if Scope
(E
) /= Scope
(S
)
7196 and then (not Is_Overloadable
(E
)
7197 or else Subtype_Conformant
(E
, S
))
7198 and then (Is_Immediately_Visible
(E
)
7200 Is_Potentially_Use_Visible
(S
))
7202 if Scope
(E
) /= Standard_Standard
then
7203 Error_Msg_Sloc
:= Sloc
(E
);
7204 Error_Msg_N
("declaration of & hides one #?h?", S
);
7206 elsif Nkind
(S
) = N_Defining_Operator_Symbol
7208 Scope
(Base_Type
(Etype
(First_Formal
(S
)))) /= Scope
(S
)
7211 ("declaration of & hides predefined operator?h?", S
);
7216 end Enter_Overloaded_Entity
;
7218 -----------------------------
7219 -- Check_Untagged_Equality --
7220 -----------------------------
7222 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
) is
7223 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Eq_Op
));
7224 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Eq_Op
);
7228 -- This check applies only if we have a subprogram declaration with an
7229 -- untagged record type.
7231 if Nkind
(Decl
) /= N_Subprogram_Declaration
7232 or else not Is_Record_Type
(Typ
)
7233 or else Is_Tagged_Type
(Typ
)
7238 -- In Ada 2012 case, we will output errors or warnings depending on
7239 -- the setting of debug flag -gnatd.E.
7241 if Ada_Version
>= Ada_2012
then
7242 Error_Msg_Warn
:= Debug_Flag_Dot_EE
;
7244 -- In earlier versions of Ada, nothing to do unless we are warning on
7245 -- Ada 2012 incompatibilities (Warn_On_Ada_2012_Incompatibility set).
7248 if not Warn_On_Ada_2012_Compatibility
then
7253 -- Cases where the type has already been frozen
7255 if Is_Frozen
(Typ
) then
7257 -- If the type is not declared in a package, or if we are in the body
7258 -- of the package or in some other scope, the new operation is not
7259 -- primitive, and therefore legal, though suspicious. Should we
7260 -- generate a warning in this case ???
7262 if Ekind
(Scope
(Typ
)) /= E_Package
7263 or else Scope
(Typ
) /= Current_Scope
7267 -- If the type is a generic actual (sub)type, the operation is not
7268 -- primitive either because the base type is declared elsewhere.
7270 elsif Is_Generic_Actual_Type
(Typ
) then
7273 -- Here we have a definite error of declaration after freezing
7276 if Ada_Version
>= Ada_2012
then
7278 ("equality operator must be declared before type & is "
7279 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)<<", Eq_Op
, Typ
);
7281 -- In Ada 2012 mode with error turned to warning, output one
7282 -- more warning to warn that the equality operation may not
7283 -- compose. This is the consequence of ignoring the error.
7285 if Error_Msg_Warn
then
7286 Error_Msg_N
("\equality operation may not compose??", Eq_Op
);
7291 ("equality operator must be declared before type& is "
7292 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)?y?", Eq_Op
, Typ
);
7295 -- If we are in the package body, we could just move the
7296 -- declaration to the package spec, so add a message saying that.
7298 if In_Package_Body
(Scope
(Typ
)) then
7299 if Ada_Version
>= Ada_2012
then
7301 ("\move declaration to package spec<<", Eq_Op
);
7304 ("\move declaration to package spec (Ada 2012)?y?", Eq_Op
);
7307 -- Otherwise try to find the freezing point
7310 Obj_Decl
:= Next
(Parent
(Typ
));
7311 while Present
(Obj_Decl
) and then Obj_Decl
/= Decl
loop
7312 if Nkind
(Obj_Decl
) = N_Object_Declaration
7313 and then Etype
(Defining_Identifier
(Obj_Decl
)) = Typ
7315 -- Freezing point, output warnings
7317 if Ada_Version
>= Ada_2012
then
7319 ("type& is frozen by declaration??", Obj_Decl
, Typ
);
7321 ("\an equality operator cannot be declared after "
7326 ("type& is frozen by declaration (Ada 2012)?y?",
7329 ("\an equality operator cannot be declared after "
7330 & "this point (Ada 2012)?y?",
7342 -- Here if type is not frozen yet. It is illegal to have a primitive
7343 -- equality declared in the private part if the type is visible.
7345 elsif not In_Same_List
(Parent
(Typ
), Decl
)
7346 and then not Is_Limited_Type
(Typ
)
7348 -- Shouldn't we give an RM reference here???
7350 if Ada_Version
>= Ada_2012
then
7352 ("equality operator appears too late<<", Eq_Op
);
7355 ("equality operator appears too late (Ada 2012)?y?", Eq_Op
);
7358 -- No error detected
7363 end Check_Untagged_Equality
;
7365 -----------------------------
7366 -- Find_Corresponding_Spec --
7367 -----------------------------
7369 function Find_Corresponding_Spec
7371 Post_Error
: Boolean := True) return Entity_Id
7373 Spec
: constant Node_Id
:= Specification
(N
);
7374 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
7378 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean;
7379 -- Even if fully conformant, a body may depend on a generic actual when
7380 -- the spec does not, or vice versa, in which case they were distinct
7381 -- entities in the generic.
7383 -------------------------------
7384 -- Different_Generic_Profile --
7385 -------------------------------
7387 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean is
7390 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean;
7391 -- Check that the types of corresponding formals have the same
7392 -- generic actual if any. We have to account for subtypes of a
7393 -- generic formal, declared between a spec and a body, which may
7394 -- appear distinct in an instance but matched in the generic, and
7395 -- the subtype may be used either in the spec or the body of the
7396 -- subprogram being checked.
7398 -------------------------
7399 -- Same_Generic_Actual --
7400 -------------------------
7402 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean is
7404 function Is_Declared_Subtype
(S1
, S2
: Entity_Id
) return Boolean;
7405 -- Predicate to check whether S1 is a subtype of S2 in the source
7408 -------------------------
7409 -- Is_Declared_Subtype --
7410 -------------------------
7412 function Is_Declared_Subtype
(S1
, S2
: Entity_Id
) return Boolean is
7414 return Comes_From_Source
(Parent
(S1
))
7415 and then Nkind
(Parent
(S1
)) = N_Subtype_Declaration
7416 and then Is_Entity_Name
(Subtype_Indication
(Parent
(S1
)))
7417 and then Entity
(Subtype_Indication
(Parent
(S1
))) = S2
;
7418 end Is_Declared_Subtype
;
7420 -- Start of processing for Same_Generic_Actual
7423 return Is_Generic_Actual_Type
(T1
) = Is_Generic_Actual_Type
(T2
)
7424 or else Is_Declared_Subtype
(T1
, T2
)
7425 or else Is_Declared_Subtype
(T2
, T1
);
7426 end Same_Generic_Actual
;
7428 -- Start of processing for Different_Generic_Profile
7431 if not In_Instance
then
7434 elsif Ekind
(E
) = E_Function
7435 and then not Same_Generic_Actual
(Etype
(E
), Etype
(Designator
))
7440 F1
:= First_Formal
(Designator
);
7441 F2
:= First_Formal
(E
);
7442 while Present
(F1
) loop
7443 if not Same_Generic_Actual
(Etype
(F1
), Etype
(F2
)) then
7452 end Different_Generic_Profile
;
7454 -- Start of processing for Find_Corresponding_Spec
7457 E
:= Current_Entity
(Designator
);
7458 while Present
(E
) loop
7460 -- We are looking for a matching spec. It must have the same scope,
7461 -- and the same name, and either be type conformant, or be the case
7462 -- of a library procedure spec and its body (which belong to one
7463 -- another regardless of whether they are type conformant or not).
7465 if Scope
(E
) = Current_Scope
then
7466 if Current_Scope
= Standard_Standard
7467 or else (Ekind
(E
) = Ekind
(Designator
)
7468 and then Type_Conformant
(E
, Designator
))
7470 -- Within an instantiation, we know that spec and body are
7471 -- subtype conformant, because they were subtype conformant in
7472 -- the generic. We choose the subtype-conformant entity here as
7473 -- well, to resolve spurious ambiguities in the instance that
7474 -- were not present in the generic (i.e. when two different
7475 -- types are given the same actual). If we are looking for a
7476 -- spec to match a body, full conformance is expected.
7480 -- Inherit the convention and "ghostness" of the matching
7481 -- spec to ensure proper full and subtype conformance.
7483 Set_Convention
(Designator
, Convention
(E
));
7485 if Is_Ghost_Entity
(E
) then
7486 Set_Is_Ghost_Entity
(Designator
);
7489 -- Skip past subprogram bodies and subprogram renamings that
7490 -- may appear to have a matching spec, but that aren't fully
7491 -- conformant with it. That can occur in cases where an
7492 -- actual type causes unrelated homographs in the instance.
7494 if Nkind_In
(N
, N_Subprogram_Body
,
7495 N_Subprogram_Renaming_Declaration
)
7496 and then Present
(Homonym
(E
))
7497 and then not Fully_Conformant
(Designator
, E
)
7501 elsif not Subtype_Conformant
(Designator
, E
) then
7504 elsif Different_Generic_Profile
(E
) then
7509 -- Ada 2012 (AI05-0165): For internally generated bodies of
7510 -- null procedures locate the internally generated spec. We
7511 -- enforce mode conformance since a tagged type may inherit
7512 -- from interfaces several null primitives which differ only
7513 -- in the mode of the formals.
7515 if not (Comes_From_Source
(E
))
7516 and then Is_Null_Procedure
(E
)
7517 and then not Mode_Conformant
(Designator
, E
)
7521 -- For null procedures coming from source that are completions,
7522 -- analysis of the generated body will establish the link.
7524 elsif Comes_From_Source
(E
)
7525 and then Nkind
(Spec
) = N_Procedure_Specification
7526 and then Null_Present
(Spec
)
7530 -- Expression functions can be completions, but cannot be
7531 -- completed by an explicit body.
7533 elsif Comes_From_Source
(E
)
7534 and then Comes_From_Source
(N
)
7535 and then Nkind
(N
) = N_Subprogram_Body
7536 and then Nkind
(Original_Node
(Unit_Declaration_Node
(E
))) =
7537 N_Expression_Function
7539 Error_Msg_Sloc
:= Sloc
(E
);
7540 Error_Msg_N
("body conflicts with expression function#", N
);
7543 elsif not Has_Completion
(E
) then
7544 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
7545 Set_Corresponding_Spec
(N
, E
);
7548 Set_Has_Completion
(E
);
7551 elsif Nkind
(Parent
(N
)) = N_Subunit
then
7553 -- If this is the proper body of a subunit, the completion
7554 -- flag is set when analyzing the stub.
7558 -- If E is an internal function with a controlling result that
7559 -- was created for an operation inherited by a null extension,
7560 -- it may be overridden by a body without a previous spec (one
7561 -- more reason why these should be shunned). In that case we
7562 -- remove the generated body if present, because the current
7563 -- one is the explicit overriding.
7565 elsif Ekind
(E
) = E_Function
7566 and then Ada_Version
>= Ada_2005
7567 and then not Comes_From_Source
(E
)
7568 and then Has_Controlling_Result
(E
)
7569 and then Is_Null_Extension
(Etype
(E
))
7570 and then Comes_From_Source
(Spec
)
7572 Set_Has_Completion
(E
, False);
7575 and then Nkind
(Parent
(E
)) = N_Function_Specification
7578 (Unit_Declaration_Node
7579 (Corresponding_Body
(Unit_Declaration_Node
(E
))));
7583 -- If expansion is disabled, or if the wrapper function has
7584 -- not been generated yet, this a late body overriding an
7585 -- inherited operation, or it is an overriding by some other
7586 -- declaration before the controlling result is frozen. In
7587 -- either case this is a declaration of a new entity.
7593 -- If the body already exists, then this is an error unless
7594 -- the previous declaration is the implicit declaration of a
7595 -- derived subprogram. It is also legal for an instance to
7596 -- contain type conformant overloadable declarations (but the
7597 -- generic declaration may not), per 8.3(26/2).
7599 elsif No
(Alias
(E
))
7600 and then not Is_Intrinsic_Subprogram
(E
)
7601 and then not In_Instance
7604 Error_Msg_Sloc
:= Sloc
(E
);
7606 if Is_Imported
(E
) then
7608 ("body not allowed for imported subprogram & declared#",
7611 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
7615 -- Child units cannot be overloaded, so a conformance mismatch
7616 -- between body and a previous spec is an error.
7618 elsif Is_Child_Unit
(E
)
7620 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
7622 Nkind
(Parent
(Unit_Declaration_Node
(Designator
))) =
7627 ("body of child unit does not match previous declaration", N
);
7635 -- On exit, we know that no previous declaration of subprogram exists
7638 end Find_Corresponding_Spec
;
7640 ----------------------
7641 -- Fully_Conformant --
7642 ----------------------
7644 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
7647 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
7649 end Fully_Conformant
;
7651 ----------------------------------
7652 -- Fully_Conformant_Expressions --
7653 ----------------------------------
7655 function Fully_Conformant_Expressions
7656 (Given_E1
: Node_Id
;
7657 Given_E2
: Node_Id
) return Boolean
7659 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
7660 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
7661 -- We always test conformance on original nodes, since it is possible
7662 -- for analysis and/or expansion to make things look as though they
7663 -- conform when they do not, e.g. by converting 1+2 into 3.
7665 function FCE
(Given_E1
, Given_E2
: Node_Id
) return Boolean
7666 renames Fully_Conformant_Expressions
;
7668 function FCL
(L1
, L2
: List_Id
) return Boolean;
7669 -- Compare elements of two lists for conformance. Elements have to be
7670 -- conformant, and actuals inserted as default parameters do not match
7671 -- explicit actuals with the same value.
7673 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean;
7674 -- Compare an operator node with a function call
7680 function FCL
(L1
, L2
: List_Id
) return Boolean is
7684 if L1
= No_List
then
7690 if L2
= No_List
then
7696 -- Compare two lists, skipping rewrite insertions (we want to compare
7697 -- the original trees, not the expanded versions).
7700 if Is_Rewrite_Insertion
(N1
) then
7702 elsif Is_Rewrite_Insertion
(N2
) then
7708 elsif not FCE
(N1
, N2
) then
7721 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean is
7722 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
7727 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
7732 Act
:= First
(Actuals
);
7734 if Nkind
(Op_Node
) in N_Binary_Op
then
7735 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
7742 return Present
(Act
)
7743 and then FCE
(Right_Opnd
(Op_Node
), Act
)
7744 and then No
(Next
(Act
));
7748 -- Start of processing for Fully_Conformant_Expressions
7751 -- Non-conformant if paren count does not match. Note: if some idiot
7752 -- complains that we don't do this right for more than 3 levels of
7753 -- parentheses, they will be treated with the respect they deserve.
7755 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
7758 -- If same entities are referenced, then they are conformant even if
7759 -- they have different forms (RM 8.3.1(19-20)).
7761 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
7762 if Present
(Entity
(E1
)) then
7763 return Entity
(E1
) = Entity
(E2
)
7764 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
7765 and then Ekind
(Entity
(E1
)) = E_Discriminant
7766 and then Ekind
(Entity
(E2
)) = E_In_Parameter
);
7768 elsif Nkind
(E1
) = N_Expanded_Name
7769 and then Nkind
(E2
) = N_Expanded_Name
7770 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
7771 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
7773 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
7776 -- Identifiers in component associations don't always have
7777 -- entities, but their names must conform.
7779 return Nkind
(E1
) = N_Identifier
7780 and then Nkind
(E2
) = N_Identifier
7781 and then Chars
(E1
) = Chars
(E2
);
7784 elsif Nkind
(E1
) = N_Character_Literal
7785 and then Nkind
(E2
) = N_Expanded_Name
7787 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
7788 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
7790 elsif Nkind
(E2
) = N_Character_Literal
7791 and then Nkind
(E1
) = N_Expanded_Name
7793 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
7794 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
7796 elsif Nkind
(E1
) in N_Op
and then Nkind
(E2
) = N_Function_Call
then
7797 return FCO
(E1
, E2
);
7799 elsif Nkind
(E2
) in N_Op
and then Nkind
(E1
) = N_Function_Call
then
7800 return FCO
(E2
, E1
);
7802 -- Otherwise we must have the same syntactic entity
7804 elsif Nkind
(E1
) /= Nkind
(E2
) then
7807 -- At this point, we specialize by node type
7814 FCL
(Expressions
(E1
), Expressions
(E2
))
7816 FCL
(Component_Associations
(E1
),
7817 Component_Associations
(E2
));
7820 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
7822 Nkind
(Expression
(E2
)) = N_Qualified_Expression
7824 return FCE
(Expression
(E1
), Expression
(E2
));
7826 -- Check that the subtype marks and any constraints
7831 Indic1
: constant Node_Id
:= Expression
(E1
);
7832 Indic2
: constant Node_Id
:= Expression
(E2
);
7837 if Nkind
(Indic1
) /= N_Subtype_Indication
then
7839 Nkind
(Indic2
) /= N_Subtype_Indication
7840 and then Entity
(Indic1
) = Entity
(Indic2
);
7842 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
7844 Nkind
(Indic1
) /= N_Subtype_Indication
7845 and then Entity
(Indic1
) = Entity
(Indic2
);
7848 if Entity
(Subtype_Mark
(Indic1
)) /=
7849 Entity
(Subtype_Mark
(Indic2
))
7854 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
7855 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
7856 while Present
(Elt1
) and then Present
(Elt2
) loop
7857 if not FCE
(Elt1
, Elt2
) then
7870 when N_Attribute_Reference
=>
7872 Attribute_Name
(E1
) = Attribute_Name
(E2
)
7873 and then FCL
(Expressions
(E1
), Expressions
(E2
));
7877 Entity
(E1
) = Entity
(E2
)
7878 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
7879 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
7881 when N_Short_Circuit | N_Membership_Test
=>
7883 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
7885 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
7887 when N_Case_Expression
=>
7893 if not FCE
(Expression
(E1
), Expression
(E2
)) then
7897 Alt1
:= First
(Alternatives
(E1
));
7898 Alt2
:= First
(Alternatives
(E2
));
7900 if Present
(Alt1
) /= Present
(Alt2
) then
7902 elsif No
(Alt1
) then
7906 if not FCE
(Expression
(Alt1
), Expression
(Alt2
))
7907 or else not FCL
(Discrete_Choices
(Alt1
),
7908 Discrete_Choices
(Alt2
))
7919 when N_Character_Literal
=>
7921 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
7923 when N_Component_Association
=>
7925 FCL
(Choices
(E1
), Choices
(E2
))
7927 FCE
(Expression
(E1
), Expression
(E2
));
7929 when N_Explicit_Dereference
=>
7931 FCE
(Prefix
(E1
), Prefix
(E2
));
7933 when N_Extension_Aggregate
=>
7935 FCL
(Expressions
(E1
), Expressions
(E2
))
7936 and then Null_Record_Present
(E1
) =
7937 Null_Record_Present
(E2
)
7938 and then FCL
(Component_Associations
(E1
),
7939 Component_Associations
(E2
));
7941 when N_Function_Call
=>
7943 FCE
(Name
(E1
), Name
(E2
))
7945 FCL
(Parameter_Associations
(E1
),
7946 Parameter_Associations
(E2
));
7948 when N_If_Expression
=>
7950 FCL
(Expressions
(E1
), Expressions
(E2
));
7952 when N_Indexed_Component
=>
7954 FCE
(Prefix
(E1
), Prefix
(E2
))
7956 FCL
(Expressions
(E1
), Expressions
(E2
));
7958 when N_Integer_Literal
=>
7959 return (Intval
(E1
) = Intval
(E2
));
7964 when N_Operator_Symbol
=>
7966 Chars
(E1
) = Chars
(E2
);
7968 when N_Others_Choice
=>
7971 when N_Parameter_Association
=>
7973 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
7974 and then FCE
(Explicit_Actual_Parameter
(E1
),
7975 Explicit_Actual_Parameter
(E2
));
7977 when N_Qualified_Expression
=>
7979 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
7981 FCE
(Expression
(E1
), Expression
(E2
));
7983 when N_Quantified_Expression
=>
7984 if not FCE
(Condition
(E1
), Condition
(E2
)) then
7988 if Present
(Loop_Parameter_Specification
(E1
))
7989 and then Present
(Loop_Parameter_Specification
(E2
))
7992 L1
: constant Node_Id
:=
7993 Loop_Parameter_Specification
(E1
);
7994 L2
: constant Node_Id
:=
7995 Loop_Parameter_Specification
(E2
);
7999 Reverse_Present
(L1
) = Reverse_Present
(L2
)
8001 FCE
(Defining_Identifier
(L1
),
8002 Defining_Identifier
(L2
))
8004 FCE
(Discrete_Subtype_Definition
(L1
),
8005 Discrete_Subtype_Definition
(L2
));
8008 elsif Present
(Iterator_Specification
(E1
))
8009 and then Present
(Iterator_Specification
(E2
))
8012 I1
: constant Node_Id
:= Iterator_Specification
(E1
);
8013 I2
: constant Node_Id
:= Iterator_Specification
(E2
);
8017 FCE
(Defining_Identifier
(I1
),
8018 Defining_Identifier
(I2
))
8020 Of_Present
(I1
) = Of_Present
(I2
)
8022 Reverse_Present
(I1
) = Reverse_Present
(I2
)
8023 and then FCE
(Name
(I1
), Name
(I2
))
8024 and then FCE
(Subtype_Indication
(I1
),
8025 Subtype_Indication
(I2
));
8028 -- The quantified expressions used different specifications to
8029 -- walk their respective ranges.
8037 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
8039 FCE
(High_Bound
(E1
), High_Bound
(E2
));
8041 when N_Real_Literal
=>
8042 return (Realval
(E1
) = Realval
(E2
));
8044 when N_Selected_Component
=>
8046 FCE
(Prefix
(E1
), Prefix
(E2
))
8048 FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
8052 FCE
(Prefix
(E1
), Prefix
(E2
))
8054 FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
8056 when N_String_Literal
=>
8058 S1
: constant String_Id
:= Strval
(E1
);
8059 S2
: constant String_Id
:= Strval
(E2
);
8060 L1
: constant Nat
:= String_Length
(S1
);
8061 L2
: constant Nat
:= String_Length
(S2
);
8068 for J
in 1 .. L1
loop
8069 if Get_String_Char
(S1
, J
) /=
8070 Get_String_Char
(S2
, J
)
8080 when N_Type_Conversion
=>
8082 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
8084 FCE
(Expression
(E1
), Expression
(E2
));
8088 Entity
(E1
) = Entity
(E2
)
8090 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
8092 when N_Unchecked_Type_Conversion
=>
8094 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
8096 FCE
(Expression
(E1
), Expression
(E2
));
8098 -- All other node types cannot appear in this context. Strictly
8099 -- we should raise a fatal internal error. Instead we just ignore
8100 -- the nodes. This means that if anyone makes a mistake in the
8101 -- expander and mucks an expression tree irretrievably, the result
8102 -- will be a failure to detect a (probably very obscure) case
8103 -- of non-conformance, which is better than bombing on some
8104 -- case where two expressions do in fact conform.
8111 end Fully_Conformant_Expressions
;
8113 ----------------------------------------
8114 -- Fully_Conformant_Discrete_Subtypes --
8115 ----------------------------------------
8117 function Fully_Conformant_Discrete_Subtypes
8118 (Given_S1
: Node_Id
;
8119 Given_S2
: Node_Id
) return Boolean
8121 S1
: constant Node_Id
:= Original_Node
(Given_S1
);
8122 S2
: constant Node_Id
:= Original_Node
(Given_S2
);
8124 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean;
8125 -- Special-case for a bound given by a discriminant, which in the body
8126 -- is replaced with the discriminal of the enclosing type.
8128 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean;
8129 -- Check both bounds
8131 -----------------------
8132 -- Conforming_Bounds --
8133 -----------------------
8135 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean is
8137 if Is_Entity_Name
(B1
)
8138 and then Is_Entity_Name
(B2
)
8139 and then Ekind
(Entity
(B1
)) = E_Discriminant
8141 return Chars
(B1
) = Chars
(B2
);
8144 return Fully_Conformant_Expressions
(B1
, B2
);
8146 end Conforming_Bounds
;
8148 -----------------------
8149 -- Conforming_Ranges --
8150 -----------------------
8152 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean is
8155 Conforming_Bounds
(Low_Bound
(R1
), Low_Bound
(R2
))
8157 Conforming_Bounds
(High_Bound
(R1
), High_Bound
(R2
));
8158 end Conforming_Ranges
;
8160 -- Start of processing for Fully_Conformant_Discrete_Subtypes
8163 if Nkind
(S1
) /= Nkind
(S2
) then
8166 elsif Is_Entity_Name
(S1
) then
8167 return Entity
(S1
) = Entity
(S2
);
8169 elsif Nkind
(S1
) = N_Range
then
8170 return Conforming_Ranges
(S1
, S2
);
8172 elsif Nkind
(S1
) = N_Subtype_Indication
then
8174 Entity
(Subtype_Mark
(S1
)) = Entity
(Subtype_Mark
(S2
))
8177 (Range_Expression
(Constraint
(S1
)),
8178 Range_Expression
(Constraint
(S2
)));
8182 end Fully_Conformant_Discrete_Subtypes
;
8184 --------------------
8185 -- Install_Entity --
8186 --------------------
8188 procedure Install_Entity
(E
: Entity_Id
) is
8189 Prev
: constant Entity_Id
:= Current_Entity
(E
);
8191 Set_Is_Immediately_Visible
(E
);
8192 Set_Current_Entity
(E
);
8193 Set_Homonym
(E
, Prev
);
8196 ---------------------
8197 -- Install_Formals --
8198 ---------------------
8200 procedure Install_Formals
(Id
: Entity_Id
) is
8203 F
:= First_Formal
(Id
);
8204 while Present
(F
) loop
8208 end Install_Formals
;
8210 -----------------------------
8211 -- Is_Interface_Conformant --
8212 -----------------------------
8214 function Is_Interface_Conformant
8215 (Tagged_Type
: Entity_Id
;
8216 Iface_Prim
: Entity_Id
;
8217 Prim
: Entity_Id
) return Boolean
8219 -- The operation may in fact be an inherited (implicit) operation
8220 -- rather than the original interface primitive, so retrieve the
8221 -- ultimate ancestor.
8223 Iface
: constant Entity_Id
:=
8224 Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
));
8225 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Prim
);
8227 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
;
8228 -- Return the controlling formal of Prim
8230 ------------------------
8231 -- Controlling_Formal --
8232 ------------------------
8234 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
is
8238 E
:= First_Entity
(Prim
);
8239 while Present
(E
) loop
8240 if Is_Formal
(E
) and then Is_Controlling_Formal
(E
) then
8248 end Controlling_Formal
;
8252 Iface_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Iface_Prim
);
8253 Prim_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Prim
);
8255 -- Start of processing for Is_Interface_Conformant
8258 pragma Assert
(Is_Subprogram
(Iface_Prim
)
8259 and then Is_Subprogram
(Prim
)
8260 and then Is_Dispatching_Operation
(Iface_Prim
)
8261 and then Is_Dispatching_Operation
(Prim
));
8263 pragma Assert
(Is_Interface
(Iface
)
8264 or else (Present
(Alias
(Iface_Prim
))
8267 (Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
)))));
8269 if Prim
= Iface_Prim
8270 or else not Is_Subprogram
(Prim
)
8271 or else Ekind
(Prim
) /= Ekind
(Iface_Prim
)
8272 or else not Is_Dispatching_Operation
(Prim
)
8273 or else Scope
(Prim
) /= Scope
(Tagged_Type
)
8275 or else Base_Type
(Typ
) /= Base_Type
(Tagged_Type
)
8276 or else not Primitive_Names_Match
(Iface_Prim
, Prim
)
8280 -- The mode of the controlling formals must match
8282 elsif Present
(Iface_Ctrl_F
)
8283 and then Present
(Prim_Ctrl_F
)
8284 and then Ekind
(Iface_Ctrl_F
) /= Ekind
(Prim_Ctrl_F
)
8288 -- Case of a procedure, or a function whose result type matches the
8289 -- result type of the interface primitive, or a function that has no
8290 -- controlling result (I or access I).
8292 elsif Ekind
(Iface_Prim
) = E_Procedure
8293 or else Etype
(Prim
) = Etype
(Iface_Prim
)
8294 or else not Has_Controlling_Result
(Prim
)
8296 return Type_Conformant
8297 (Iface_Prim
, Prim
, Skip_Controlling_Formals
=> True);
8299 -- Case of a function returning an interface, or an access to one. Check
8300 -- that the return types correspond.
8302 elsif Implements_Interface
(Typ
, Iface
) then
8303 if (Ekind
(Etype
(Prim
)) = E_Anonymous_Access_Type
)
8305 (Ekind
(Etype
(Iface_Prim
)) = E_Anonymous_Access_Type
)
8310 Type_Conformant
(Prim
, Ultimate_Alias
(Iface_Prim
),
8311 Skip_Controlling_Formals
=> True);
8317 end Is_Interface_Conformant
;
8319 ---------------------------------
8320 -- Is_Non_Overriding_Operation --
8321 ---------------------------------
8323 function Is_Non_Overriding_Operation
8324 (Prev_E
: Entity_Id
;
8325 New_E
: Entity_Id
) return Boolean
8329 G_Typ
: Entity_Id
:= Empty
;
8331 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
8332 -- If F_Type is a derived type associated with a generic actual subtype,
8333 -- then return its Generic_Parent_Type attribute, else return Empty.
8335 function Types_Correspond
8336 (P_Type
: Entity_Id
;
8337 N_Type
: Entity_Id
) return Boolean;
8338 -- Returns true if and only if the types (or designated types in the
8339 -- case of anonymous access types) are the same or N_Type is derived
8340 -- directly or indirectly from P_Type.
8342 -----------------------------
8343 -- Get_Generic_Parent_Type --
8344 -----------------------------
8346 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
8352 if Is_Derived_Type
(F_Typ
)
8353 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
8355 -- The tree must be traversed to determine the parent subtype in
8356 -- the generic unit, which unfortunately isn't always available
8357 -- via semantic attributes. ??? (Note: The use of Original_Node
8358 -- is needed for cases where a full derived type has been
8361 -- If the parent type is a scalar type, the derivation creates
8362 -- an anonymous base type for it, and the source type is its
8365 if Is_Scalar_Type
(F_Typ
)
8366 and then not Comes_From_Source
(F_Typ
)
8370 (Original_Node
(Parent
(First_Subtype
(F_Typ
))));
8372 Defn
:= Type_Definition
(Original_Node
(Parent
(F_Typ
)));
8374 if Nkind
(Defn
) = N_Derived_Type_Definition
then
8375 Indic
:= Subtype_Indication
(Defn
);
8377 if Nkind
(Indic
) = N_Subtype_Indication
then
8378 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
8380 G_Typ
:= Entity
(Indic
);
8383 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
8384 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
8386 return Generic_Parent_Type
(Parent
(G_Typ
));
8392 end Get_Generic_Parent_Type
;
8394 ----------------------
8395 -- Types_Correspond --
8396 ----------------------
8398 function Types_Correspond
8399 (P_Type
: Entity_Id
;
8400 N_Type
: Entity_Id
) return Boolean
8402 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
8403 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
8406 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
8407 Prev_Type
:= Designated_Type
(Prev_Type
);
8410 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
8411 New_Type
:= Designated_Type
(New_Type
);
8414 if Prev_Type
= New_Type
then
8417 elsif not Is_Class_Wide_Type
(New_Type
) then
8418 while Etype
(New_Type
) /= New_Type
loop
8419 New_Type
:= Etype
(New_Type
);
8421 if New_Type
= Prev_Type
then
8427 end Types_Correspond
;
8429 -- Start of processing for Is_Non_Overriding_Operation
8432 -- In the case where both operations are implicit derived subprograms
8433 -- then neither overrides the other. This can only occur in certain
8434 -- obscure cases (e.g., derivation from homographs created in a generic
8437 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
8440 elsif Ekind
(Current_Scope
) = E_Package
8441 and then Is_Generic_Instance
(Current_Scope
)
8442 and then In_Private_Part
(Current_Scope
)
8443 and then Comes_From_Source
(New_E
)
8445 -- We examine the formals and result type of the inherited operation,
8446 -- to determine whether their type is derived from (the instance of)
8447 -- a generic type. The first such formal or result type is the one
8450 Formal
:= First_Formal
(Prev_E
);
8451 while Present
(Formal
) loop
8452 F_Typ
:= Base_Type
(Etype
(Formal
));
8454 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
8455 F_Typ
:= Designated_Type
(F_Typ
);
8458 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
8459 exit when Present
(G_Typ
);
8461 Next_Formal
(Formal
);
8464 if No
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
8465 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
8472 -- If the generic type is a private type, then the original operation
8473 -- was not overriding in the generic, because there was no primitive
8474 -- operation to override.
8476 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
8477 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
8478 N_Formal_Private_Type_Definition
8482 -- The generic parent type is the ancestor of a formal derived
8483 -- type declaration. We need to check whether it has a primitive
8484 -- operation that should be overridden by New_E in the generic.
8488 P_Formal
: Entity_Id
;
8489 N_Formal
: Entity_Id
;
8493 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
8496 while Present
(Prim_Elt
) loop
8497 P_Prim
:= Node
(Prim_Elt
);
8499 if Chars
(P_Prim
) = Chars
(New_E
)
8500 and then Ekind
(P_Prim
) = Ekind
(New_E
)
8502 P_Formal
:= First_Formal
(P_Prim
);
8503 N_Formal
:= First_Formal
(New_E
);
8504 while Present
(P_Formal
) and then Present
(N_Formal
) loop
8505 P_Typ
:= Etype
(P_Formal
);
8506 N_Typ
:= Etype
(N_Formal
);
8508 if not Types_Correspond
(P_Typ
, N_Typ
) then
8512 Next_Entity
(P_Formal
);
8513 Next_Entity
(N_Formal
);
8516 -- Found a matching primitive operation belonging to the
8517 -- formal ancestor type, so the new subprogram is
8521 and then No
(N_Formal
)
8522 and then (Ekind
(New_E
) /= E_Function
8525 (Etype
(P_Prim
), Etype
(New_E
)))
8531 Next_Elmt
(Prim_Elt
);
8534 -- If no match found, then the new subprogram does not override
8535 -- in the generic (nor in the instance).
8537 -- If the type in question is not abstract, and the subprogram
8538 -- is, this will be an error if the new operation is in the
8539 -- private part of the instance. Emit a warning now, which will
8540 -- make the subsequent error message easier to understand.
8542 if not Is_Abstract_Type
(F_Typ
)
8543 and then Is_Abstract_Subprogram
(Prev_E
)
8544 and then In_Private_Part
(Current_Scope
)
8546 Error_Msg_Node_2
:= F_Typ
;
8548 ("private operation& in generic unit does not override "
8549 & "any primitive operation of& (RM 12.3 (18))??",
8559 end Is_Non_Overriding_Operation
;
8561 -------------------------------------
8562 -- List_Inherited_Pre_Post_Aspects --
8563 -------------------------------------
8565 procedure List_Inherited_Pre_Post_Aspects
(E
: Entity_Id
) is
8567 if Opt
.List_Inherited_Aspects
8568 and then Is_Subprogram_Or_Generic_Subprogram
(E
)
8571 Subps
: constant Subprogram_List
:= Inherited_Subprograms
(E
);
8576 for Index
in Subps
'Range loop
8577 Items
:= Contract
(Subps
(Index
));
8579 if Present
(Items
) then
8580 Prag
:= Pre_Post_Conditions
(Items
);
8581 while Present
(Prag
) loop
8582 Error_Msg_Sloc
:= Sloc
(Prag
);
8584 if Class_Present
(Prag
)
8585 and then not Split_PPC
(Prag
)
8587 if Pragma_Name
(Prag
) = Name_Precondition
then
8589 ("info: & inherits `Pre''Class` aspect from "
8593 ("info: & inherits `Post''Class` aspect from "
8598 Prag
:= Next_Pragma
(Prag
);
8604 end List_Inherited_Pre_Post_Aspects
;
8606 ------------------------------
8607 -- Make_Inequality_Operator --
8608 ------------------------------
8610 -- S is the defining identifier of an equality operator. We build a
8611 -- subprogram declaration with the right signature. This operation is
8612 -- intrinsic, because it is always expanded as the negation of the
8613 -- call to the equality function.
8615 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
8616 Loc
: constant Source_Ptr
:= Sloc
(S
);
8619 Op_Name
: Entity_Id
;
8621 FF
: constant Entity_Id
:= First_Formal
(S
);
8622 NF
: constant Entity_Id
:= Next_Formal
(FF
);
8625 -- Check that equality was properly defined, ignore call if not
8632 A
: constant Entity_Id
:=
8633 Make_Defining_Identifier
(Sloc
(FF
),
8634 Chars
=> Chars
(FF
));
8636 B
: constant Entity_Id
:=
8637 Make_Defining_Identifier
(Sloc
(NF
),
8638 Chars
=> Chars
(NF
));
8641 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
8643 Formals
:= New_List
(
8644 Make_Parameter_Specification
(Loc
,
8645 Defining_Identifier
=> A
,
8647 New_Occurrence_Of
(Etype
(First_Formal
(S
)),
8648 Sloc
(Etype
(First_Formal
(S
))))),
8650 Make_Parameter_Specification
(Loc
,
8651 Defining_Identifier
=> B
,
8653 New_Occurrence_Of
(Etype
(Next_Formal
(First_Formal
(S
))),
8654 Sloc
(Etype
(Next_Formal
(First_Formal
(S
)))))));
8657 Make_Subprogram_Declaration
(Loc
,
8659 Make_Function_Specification
(Loc
,
8660 Defining_Unit_Name
=> Op_Name
,
8661 Parameter_Specifications
=> Formals
,
8662 Result_Definition
=>
8663 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
8665 -- Insert inequality right after equality if it is explicit or after
8666 -- the derived type when implicit. These entities are created only
8667 -- for visibility purposes, and eventually replaced in the course
8668 -- of expansion, so they do not need to be attached to the tree and
8669 -- seen by the back-end. Keeping them internal also avoids spurious
8670 -- freezing problems. The declaration is inserted in the tree for
8671 -- analysis, and removed afterwards. If the equality operator comes
8672 -- from an explicit declaration, attach the inequality immediately
8673 -- after. Else the equality is inherited from a derived type
8674 -- declaration, so insert inequality after that declaration.
8676 if No
(Alias
(S
)) then
8677 Insert_After
(Unit_Declaration_Node
(S
), Decl
);
8678 elsif Is_List_Member
(Parent
(S
)) then
8679 Insert_After
(Parent
(S
), Decl
);
8681 Insert_After
(Parent
(Etype
(First_Formal
(S
))), Decl
);
8684 Mark_Rewrite_Insertion
(Decl
);
8685 Set_Is_Intrinsic_Subprogram
(Op_Name
);
8688 Set_Has_Completion
(Op_Name
);
8689 Set_Corresponding_Equality
(Op_Name
, S
);
8690 Set_Is_Abstract_Subprogram
(Op_Name
, Is_Abstract_Subprogram
(S
));
8692 end Make_Inequality_Operator
;
8694 ----------------------
8695 -- May_Need_Actuals --
8696 ----------------------
8698 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
8703 F
:= First_Formal
(Fun
);
8705 while Present
(F
) loop
8706 if No
(Default_Value
(F
)) then
8714 Set_Needs_No_Actuals
(Fun
, B
);
8715 end May_Need_Actuals
;
8717 ---------------------
8718 -- Mode_Conformant --
8719 ---------------------
8721 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
8724 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
8726 end Mode_Conformant
;
8728 ---------------------------
8729 -- New_Overloaded_Entity --
8730 ---------------------------
8732 procedure New_Overloaded_Entity
8734 Derived_Type
: Entity_Id
:= Empty
)
8736 Overridden_Subp
: Entity_Id
:= Empty
;
8737 -- Set if the current scope has an operation that is type-conformant
8738 -- with S, and becomes hidden by S.
8740 Is_Primitive_Subp
: Boolean;
8741 -- Set to True if the new subprogram is primitive
8744 -- Entity that S overrides
8746 Prev_Vis
: Entity_Id
:= Empty
;
8747 -- Predecessor of E in Homonym chain
8749 procedure Check_For_Primitive_Subprogram
8750 (Is_Primitive
: out Boolean;
8751 Is_Overriding
: Boolean := False);
8752 -- If the subprogram being analyzed is a primitive operation of the type
8753 -- of a formal or result, set the Has_Primitive_Operations flag on the
8754 -- type, and set Is_Primitive to True (otherwise set to False). Set the
8755 -- corresponding flag on the entity itself for later use.
8757 procedure Check_Synchronized_Overriding
8758 (Def_Id
: Entity_Id
;
8759 Overridden_Subp
: out Entity_Id
);
8760 -- First determine if Def_Id is an entry or a subprogram either defined
8761 -- in the scope of a task or protected type, or is a primitive of such
8762 -- a type. Check whether Def_Id overrides a subprogram of an interface
8763 -- implemented by the synchronized type, return the overridden entity
8766 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
8767 -- Check that E is declared in the private part of the current package,
8768 -- or in the package body, where it may hide a previous declaration.
8769 -- We can't use In_Private_Part by itself because this flag is also
8770 -- set when freezing entities, so we must examine the place of the
8771 -- declaration in the tree, and recognize wrapper packages as well.
8773 function Is_Overriding_Alias
8775 New_E
: Entity_Id
) return Boolean;
8776 -- Check whether new subprogram and old subprogram are both inherited
8777 -- from subprograms that have distinct dispatch table entries. This can
8778 -- occur with derivations from instances with accidental homonyms. The
8779 -- function is conservative given that the converse is only true within
8780 -- instances that contain accidental overloadings.
8782 ------------------------------------
8783 -- Check_For_Primitive_Subprogram --
8784 ------------------------------------
8786 procedure Check_For_Primitive_Subprogram
8787 (Is_Primitive
: out Boolean;
8788 Is_Overriding
: Boolean := False)
8794 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
8795 -- Returns true if T is declared in the visible part of the current
8796 -- package scope; otherwise returns false. Assumes that T is declared
8799 procedure Check_Private_Overriding
(T
: Entity_Id
);
8800 -- Checks that if a primitive abstract subprogram of a visible
8801 -- abstract type is declared in a private part, then it must override
8802 -- an abstract subprogram declared in the visible part. Also checks
8803 -- that if a primitive function with a controlling result is declared
8804 -- in a private part, then it must override a function declared in
8805 -- the visible part.
8807 ------------------------------
8808 -- Check_Private_Overriding --
8809 ------------------------------
8811 procedure Check_Private_Overriding
(T
: Entity_Id
) is
8812 function Overrides_Private_Part_Op
return Boolean;
8813 -- This detects the special case where the overriding subprogram
8814 -- is overriding a subprogram that was declared in the same
8815 -- private part. That case is illegal by 3.9.3(10).
8817 function Overrides_Visible_Function
8818 (Partial_View
: Entity_Id
) return Boolean;
8819 -- True if S overrides a function in the visible part. The
8820 -- overridden function could be explicitly or implicitly declared.
8822 -------------------------------
8823 -- Overrides_Private_Part_Op --
8824 -------------------------------
8826 function Overrides_Private_Part_Op
return Boolean is
8827 Over_Decl
: constant Node_Id
:=
8828 Unit_Declaration_Node
(Overridden_Operation
(S
));
8829 Subp_Decl
: constant Node_Id
:= Unit_Declaration_Node
(S
);
8832 pragma Assert
(Is_Overriding
);
8834 (Nkind
(Over_Decl
) = N_Abstract_Subprogram_Declaration
);
8836 (Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
);
8838 return In_Same_List
(Over_Decl
, Subp_Decl
);
8839 end Overrides_Private_Part_Op
;
8841 --------------------------------
8842 -- Overrides_Visible_Function --
8843 --------------------------------
8845 function Overrides_Visible_Function
8846 (Partial_View
: Entity_Id
) return Boolean
8849 if not Is_Overriding
or else not Has_Homonym
(S
) then
8853 if not Present
(Partial_View
) then
8857 -- Search through all the homonyms H of S in the current
8858 -- package spec, and return True if we find one that matches.
8859 -- Note that Parent (H) will be the declaration of the
8860 -- partial view of T for a match.
8867 exit when not Present
(H
) or else Scope
(H
) /= Scope
(S
);
8871 N_Private_Extension_Declaration
,
8872 N_Private_Type_Declaration
)
8873 and then Defining_Identifier
(Parent
(H
)) = Partial_View
8881 end Overrides_Visible_Function
;
8883 -- Start of processing for Check_Private_Overriding
8886 if Is_Package_Or_Generic_Package
(Current_Scope
)
8887 and then In_Private_Part
(Current_Scope
)
8888 and then Visible_Part_Type
(T
)
8889 and then not In_Instance
8891 if Is_Abstract_Type
(T
)
8892 and then Is_Abstract_Subprogram
(S
)
8893 and then (not Is_Overriding
8894 or else not Is_Abstract_Subprogram
(E
)
8895 or else Overrides_Private_Part_Op
)
8898 ("abstract subprograms must be visible (RM 3.9.3(10))!",
8901 elsif Ekind
(S
) = E_Function
then
8903 Partial_View
: constant Entity_Id
:=
8904 Incomplete_Or_Partial_View
(T
);
8907 if not Overrides_Visible_Function
(Partial_View
) then
8909 -- Here, S is "function ... return T;" declared in
8910 -- the private part, not overriding some visible
8911 -- operation. That's illegal in the tagged case
8912 -- (but not if the private type is untagged).
8914 if ((Present
(Partial_View
)
8915 and then Is_Tagged_Type
(Partial_View
))
8916 or else (not Present
(Partial_View
)
8917 and then Is_Tagged_Type
(T
)))
8918 and then T
= Base_Type
(Etype
(S
))
8921 ("private function with tagged result must"
8922 & " override visible-part function", S
);
8924 ("\move subprogram to the visible part"
8925 & " (RM 3.9.3(10))", S
);
8927 -- AI05-0073: extend this test to the case of a
8928 -- function with a controlling access result.
8930 elsif Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
8931 and then Is_Tagged_Type
(Designated_Type
(Etype
(S
)))
8933 not Is_Class_Wide_Type
8934 (Designated_Type
(Etype
(S
)))
8935 and then Ada_Version
>= Ada_2012
8938 ("private function with controlling access "
8939 & "result must override visible-part function",
8942 ("\move subprogram to the visible part"
8943 & " (RM 3.9.3(10))", S
);
8949 end Check_Private_Overriding
;
8951 -----------------------
8952 -- Visible_Part_Type --
8953 -----------------------
8955 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
8956 P
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
8960 -- If the entity is a private type, then it must be declared in a
8963 if Ekind
(T
) in Private_Kind
then
8967 -- Otherwise, we traverse the visible part looking for its
8968 -- corresponding declaration. We cannot use the declaration
8969 -- node directly because in the private part the entity of a
8970 -- private type is the one in the full view, which does not
8971 -- indicate that it is the completion of something visible.
8973 N
:= First
(Visible_Declarations
(Specification
(P
)));
8974 while Present
(N
) loop
8975 if Nkind
(N
) = N_Full_Type_Declaration
8976 and then Present
(Defining_Identifier
(N
))
8977 and then T
= Defining_Identifier
(N
)
8981 elsif Nkind_In
(N
, N_Private_Type_Declaration
,
8982 N_Private_Extension_Declaration
)
8983 and then Present
(Defining_Identifier
(N
))
8984 and then T
= Full_View
(Defining_Identifier
(N
))
8993 end Visible_Part_Type
;
8995 -- Start of processing for Check_For_Primitive_Subprogram
8998 Is_Primitive
:= False;
9000 if not Comes_From_Source
(S
) then
9003 -- If subprogram is at library level, it is not primitive operation
9005 elsif Current_Scope
= Standard_Standard
then
9008 elsif (Is_Package_Or_Generic_Package
(Current_Scope
)
9009 and then not In_Package_Body
(Current_Scope
))
9010 or else Is_Overriding
9012 -- For function, check return type
9014 if Ekind
(S
) = E_Function
then
9015 if Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
then
9016 F_Typ
:= Designated_Type
(Etype
(S
));
9021 B_Typ
:= Base_Type
(F_Typ
);
9023 if Scope
(B_Typ
) = Current_Scope
9024 and then not Is_Class_Wide_Type
(B_Typ
)
9025 and then not Is_Generic_Type
(B_Typ
)
9027 Is_Primitive
:= True;
9028 Set_Has_Primitive_Operations
(B_Typ
);
9029 Set_Is_Primitive
(S
);
9030 Check_Private_Overriding
(B_Typ
);
9032 -- The Ghost policy in effect at the point of declaration of
9033 -- a tagged type and a primitive operation must match
9034 -- (SPARK RM 6.9(16)).
9036 Check_Ghost_Primitive
(S
, B_Typ
);
9040 -- For all subprograms, check formals
9042 Formal
:= First_Formal
(S
);
9043 while Present
(Formal
) loop
9044 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
9045 F_Typ
:= Designated_Type
(Etype
(Formal
));
9047 F_Typ
:= Etype
(Formal
);
9050 B_Typ
:= Base_Type
(F_Typ
);
9052 if Ekind
(B_Typ
) = E_Access_Subtype
then
9053 B_Typ
:= Base_Type
(B_Typ
);
9056 if Scope
(B_Typ
) = Current_Scope
9057 and then not Is_Class_Wide_Type
(B_Typ
)
9058 and then not Is_Generic_Type
(B_Typ
)
9060 Is_Primitive
:= True;
9061 Set_Is_Primitive
(S
);
9062 Set_Has_Primitive_Operations
(B_Typ
);
9063 Check_Private_Overriding
(B_Typ
);
9065 -- The Ghost policy in effect at the point of declaration of
9066 -- a tagged type and a primitive operation must match
9067 -- (SPARK RM 6.9(16)).
9069 Check_Ghost_Primitive
(S
, B_Typ
);
9072 Next_Formal
(Formal
);
9075 -- Special case: An equality function can be redefined for a type
9076 -- occurring in a declarative part, and won't otherwise be treated as
9077 -- a primitive because it doesn't occur in a package spec and doesn't
9078 -- override an inherited subprogram. It's important that we mark it
9079 -- primitive so it can be returned by Collect_Primitive_Operations
9080 -- and be used in composing the equality operation of later types
9081 -- that have a component of the type.
9083 elsif Chars
(S
) = Name_Op_Eq
9084 and then Etype
(S
) = Standard_Boolean
9086 B_Typ
:= Base_Type
(Etype
(First_Formal
(S
)));
9088 if Scope
(B_Typ
) = Current_Scope
9090 Base_Type
(Etype
(Next_Formal
(First_Formal
(S
)))) = B_Typ
9091 and then not Is_Limited_Type
(B_Typ
)
9093 Is_Primitive
:= True;
9094 Set_Is_Primitive
(S
);
9095 Set_Has_Primitive_Operations
(B_Typ
);
9096 Check_Private_Overriding
(B_Typ
);
9098 -- The Ghost policy in effect at the point of declaration of a
9099 -- tagged type and a primitive operation must match
9100 -- (SPARK RM 6.9(16)).
9102 Check_Ghost_Primitive
(S
, B_Typ
);
9105 end Check_For_Primitive_Subprogram
;
9107 -----------------------------------
9108 -- Check_Synchronized_Overriding --
9109 -----------------------------------
9111 procedure Check_Synchronized_Overriding
9112 (Def_Id
: Entity_Id
;
9113 Overridden_Subp
: out Entity_Id
)
9115 Ifaces_List
: Elist_Id
;
9119 function Matches_Prefixed_View_Profile
9120 (Prim_Params
: List_Id
;
9121 Iface_Params
: List_Id
) return Boolean;
9122 -- Determine whether a subprogram's parameter profile Prim_Params
9123 -- matches that of a potentially overridden interface subprogram
9124 -- Iface_Params. Also determine if the type of first parameter of
9125 -- Iface_Params is an implemented interface.
9127 -----------------------------------
9128 -- Matches_Prefixed_View_Profile --
9129 -----------------------------------
9131 function Matches_Prefixed_View_Profile
9132 (Prim_Params
: List_Id
;
9133 Iface_Params
: List_Id
) return Boolean
9135 Iface_Id
: Entity_Id
;
9136 Iface_Param
: Node_Id
;
9137 Iface_Typ
: Entity_Id
;
9138 Prim_Id
: Entity_Id
;
9139 Prim_Param
: Node_Id
;
9140 Prim_Typ
: Entity_Id
;
9142 function Is_Implemented
9143 (Ifaces_List
: Elist_Id
;
9144 Iface
: Entity_Id
) return Boolean;
9145 -- Determine if Iface is implemented by the current task or
9148 --------------------
9149 -- Is_Implemented --
9150 --------------------
9152 function Is_Implemented
9153 (Ifaces_List
: Elist_Id
;
9154 Iface
: Entity_Id
) return Boolean
9156 Iface_Elmt
: Elmt_Id
;
9159 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
9160 while Present
(Iface_Elmt
) loop
9161 if Node
(Iface_Elmt
) = Iface
then
9165 Next_Elmt
(Iface_Elmt
);
9171 -- Start of processing for Matches_Prefixed_View_Profile
9174 Iface_Param
:= First
(Iface_Params
);
9175 Iface_Typ
:= Etype
(Defining_Identifier
(Iface_Param
));
9177 if Is_Access_Type
(Iface_Typ
) then
9178 Iface_Typ
:= Designated_Type
(Iface_Typ
);
9181 Prim_Param
:= First
(Prim_Params
);
9183 -- The first parameter of the potentially overridden subprogram
9184 -- must be an interface implemented by Prim.
9186 if not Is_Interface
(Iface_Typ
)
9187 or else not Is_Implemented
(Ifaces_List
, Iface_Typ
)
9192 -- The checks on the object parameters are done, move onto the
9193 -- rest of the parameters.
9195 if not In_Scope
then
9196 Prim_Param
:= Next
(Prim_Param
);
9199 Iface_Param
:= Next
(Iface_Param
);
9200 while Present
(Iface_Param
) and then Present
(Prim_Param
) loop
9201 Iface_Id
:= Defining_Identifier
(Iface_Param
);
9202 Iface_Typ
:= Find_Parameter_Type
(Iface_Param
);
9204 Prim_Id
:= Defining_Identifier
(Prim_Param
);
9205 Prim_Typ
:= Find_Parameter_Type
(Prim_Param
);
9207 if Ekind
(Iface_Typ
) = E_Anonymous_Access_Type
9208 and then Ekind
(Prim_Typ
) = E_Anonymous_Access_Type
9209 and then Is_Concurrent_Type
(Designated_Type
(Prim_Typ
))
9211 Iface_Typ
:= Designated_Type
(Iface_Typ
);
9212 Prim_Typ
:= Designated_Type
(Prim_Typ
);
9215 -- Case of multiple interface types inside a parameter profile
9217 -- (Obj_Param : in out Iface; ...; Param : Iface)
9219 -- If the interface type is implemented, then the matching type
9220 -- in the primitive should be the implementing record type.
9222 if Ekind
(Iface_Typ
) = E_Record_Type
9223 and then Is_Interface
(Iface_Typ
)
9224 and then Is_Implemented
(Ifaces_List
, Iface_Typ
)
9226 if Prim_Typ
/= Typ
then
9230 -- The two parameters must be both mode and subtype conformant
9232 elsif Ekind
(Iface_Id
) /= Ekind
(Prim_Id
)
9234 Conforming_Types
(Iface_Typ
, Prim_Typ
, Subtype_Conformant
)
9243 -- One of the two lists contains more parameters than the other
9245 if Present
(Iface_Param
) or else Present
(Prim_Param
) then
9250 end Matches_Prefixed_View_Profile
;
9252 -- Start of processing for Check_Synchronized_Overriding
9255 Overridden_Subp
:= Empty
;
9257 -- Def_Id must be an entry or a subprogram. We should skip predefined
9258 -- primitives internally generated by the frontend; however at this
9259 -- stage predefined primitives are still not fully decorated. As a
9260 -- minor optimization we skip here internally generated subprograms.
9262 if (Ekind
(Def_Id
) /= E_Entry
9263 and then Ekind
(Def_Id
) /= E_Function
9264 and then Ekind
(Def_Id
) /= E_Procedure
)
9265 or else not Comes_From_Source
(Def_Id
)
9270 -- Search for the concurrent declaration since it contains the list
9271 -- of all implemented interfaces. In this case, the subprogram is
9272 -- declared within the scope of a protected or a task type.
9274 if Present
(Scope
(Def_Id
))
9275 and then Is_Concurrent_Type
(Scope
(Def_Id
))
9276 and then not Is_Generic_Actual_Type
(Scope
(Def_Id
))
9278 Typ
:= Scope
(Def_Id
);
9281 -- The enclosing scope is not a synchronized type and the subprogram
9284 elsif No
(First_Formal
(Def_Id
)) then
9287 -- The subprogram has formals and hence it may be a primitive of a
9291 Typ
:= Etype
(First_Formal
(Def_Id
));
9293 if Is_Access_Type
(Typ
) then
9294 Typ
:= Directly_Designated_Type
(Typ
);
9297 if Is_Concurrent_Type
(Typ
)
9298 and then not Is_Generic_Actual_Type
(Typ
)
9302 -- This case occurs when the concurrent type is declared within
9303 -- a generic unit. As a result the corresponding record has been
9304 -- built and used as the type of the first formal, we just have
9305 -- to retrieve the corresponding concurrent type.
9307 elsif Is_Concurrent_Record_Type
(Typ
)
9308 and then not Is_Class_Wide_Type
(Typ
)
9309 and then Present
(Corresponding_Concurrent_Type
(Typ
))
9311 Typ
:= Corresponding_Concurrent_Type
(Typ
);
9319 -- There is no overriding to check if is an inherited operation in a
9320 -- type derivation on for a generic actual.
9322 Collect_Interfaces
(Typ
, Ifaces_List
);
9324 if Is_Empty_Elmt_List
(Ifaces_List
) then
9328 -- Determine whether entry or subprogram Def_Id overrides a primitive
9329 -- operation that belongs to one of the interfaces in Ifaces_List.
9332 Candidate
: Entity_Id
:= Empty
;
9333 Hom
: Entity_Id
:= Empty
;
9334 Subp
: Entity_Id
:= Empty
;
9337 -- Traverse the homonym chain, looking for a potentially
9338 -- overridden subprogram that belongs to an implemented
9341 Hom
:= Current_Entity_In_Scope
(Def_Id
);
9342 while Present
(Hom
) loop
9346 or else not Is_Overloadable
(Subp
)
9347 or else not Is_Primitive
(Subp
)
9348 or else not Is_Dispatching_Operation
(Subp
)
9349 or else not Present
(Find_Dispatching_Type
(Subp
))
9350 or else not Is_Interface
(Find_Dispatching_Type
(Subp
))
9354 -- Entries and procedures can override abstract or null
9355 -- interface procedures.
9357 elsif (Ekind
(Def_Id
) = E_Procedure
9358 or else Ekind
(Def_Id
) = E_Entry
)
9359 and then Ekind
(Subp
) = E_Procedure
9360 and then Matches_Prefixed_View_Profile
9361 (Parameter_Specifications
(Parent
(Def_Id
)),
9362 Parameter_Specifications
(Parent
(Subp
)))
9366 -- For an overridden subprogram Subp, check whether the mode
9367 -- of its first parameter is correct depending on the kind
9368 -- of synchronized type.
9371 Formal
: constant Node_Id
:= First_Formal
(Candidate
);
9374 -- In order for an entry or a protected procedure to
9375 -- override, the first parameter of the overridden
9376 -- routine must be of mode "out", "in out" or
9377 -- access-to-variable.
9379 if Ekind_In
(Candidate
, E_Entry
, E_Procedure
)
9380 and then Is_Protected_Type
(Typ
)
9381 and then Ekind
(Formal
) /= E_In_Out_Parameter
9382 and then Ekind
(Formal
) /= E_Out_Parameter
9383 and then Nkind
(Parameter_Type
(Parent
(Formal
))) /=
9388 -- All other cases are OK since a task entry or routine
9389 -- does not have a restriction on the mode of the first
9390 -- parameter of the overridden interface routine.
9393 Overridden_Subp
:= Candidate
;
9398 -- Functions can override abstract interface functions
9400 elsif Ekind
(Def_Id
) = E_Function
9401 and then Ekind
(Subp
) = E_Function
9402 and then Matches_Prefixed_View_Profile
9403 (Parameter_Specifications
(Parent
(Def_Id
)),
9404 Parameter_Specifications
(Parent
(Subp
)))
9405 and then Etype
(Result_Definition
(Parent
(Def_Id
))) =
9406 Etype
(Result_Definition
(Parent
(Subp
)))
9410 -- If an inherited subprogram is implemented by a protected
9411 -- function, then the first parameter of the inherited
9412 -- subprogram shall be of mode in, but not an
9413 -- access-to-variable parameter (RM 9.4(11/9)
9415 if Present
(First_Formal
(Subp
))
9416 and then Ekind
(First_Formal
(Subp
)) = E_In_Parameter
9418 (not Is_Access_Type
(Etype
(First_Formal
(Subp
)))
9420 Is_Access_Constant
(Etype
(First_Formal
(Subp
))))
9422 Overridden_Subp
:= Subp
;
9427 Hom
:= Homonym
(Hom
);
9430 -- After examining all candidates for overriding, we are left with
9431 -- the best match which is a mode incompatible interface routine.
9433 if In_Scope
and then Present
(Candidate
) then
9434 Error_Msg_PT
(Def_Id
, Candidate
);
9437 Overridden_Subp
:= Candidate
;
9440 end Check_Synchronized_Overriding
;
9442 ----------------------------
9443 -- Is_Private_Declaration --
9444 ----------------------------
9446 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
9447 Priv_Decls
: List_Id
;
9448 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
9451 if Is_Package_Or_Generic_Package
(Current_Scope
)
9452 and then In_Private_Part
(Current_Scope
)
9455 Private_Declarations
(Package_Specification
(Current_Scope
));
9457 return In_Package_Body
(Current_Scope
)
9459 (Is_List_Member
(Decl
)
9460 and then List_Containing
(Decl
) = Priv_Decls
)
9461 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
9464 (Defining_Entity
(Parent
(Decl
)))
9465 and then List_Containing
(Parent
(Parent
(Decl
))) =
9470 end Is_Private_Declaration
;
9472 --------------------------
9473 -- Is_Overriding_Alias --
9474 --------------------------
9476 function Is_Overriding_Alias
9478 New_E
: Entity_Id
) return Boolean
9480 AO
: constant Entity_Id
:= Alias
(Old_E
);
9481 AN
: constant Entity_Id
:= Alias
(New_E
);
9483 return Scope
(AO
) /= Scope
(AN
)
9484 or else No
(DTC_Entity
(AO
))
9485 or else No
(DTC_Entity
(AN
))
9486 or else DT_Position
(AO
) = DT_Position
(AN
);
9487 end Is_Overriding_Alias
;
9489 -- Start of processing for New_Overloaded_Entity
9492 -- We need to look for an entity that S may override. This must be a
9493 -- homonym in the current scope, so we look for the first homonym of
9494 -- S in the current scope as the starting point for the search.
9496 E
:= Current_Entity_In_Scope
(S
);
9498 -- Ada 2005 (AI-251): Derivation of abstract interface primitives.
9499 -- They are directly added to the list of primitive operations of
9500 -- Derived_Type, unless this is a rederivation in the private part
9501 -- of an operation that was already derived in the visible part of
9502 -- the current package.
9504 if Ada_Version
>= Ada_2005
9505 and then Present
(Derived_Type
)
9506 and then Present
(Alias
(S
))
9507 and then Is_Dispatching_Operation
(Alias
(S
))
9508 and then Present
(Find_Dispatching_Type
(Alias
(S
)))
9509 and then Is_Interface
(Find_Dispatching_Type
(Alias
(S
)))
9511 -- For private types, when the full-view is processed we propagate to
9512 -- the full view the non-overridden entities whose attribute "alias"
9513 -- references an interface primitive. These entities were added by
9514 -- Derive_Subprograms to ensure that interface primitives are
9517 -- Inside_Freeze_Actions is non zero when S corresponds with an
9518 -- internal entity that links an interface primitive with its
9519 -- covering primitive through attribute Interface_Alias (see
9520 -- Add_Internal_Interface_Entities).
9522 if Inside_Freezing_Actions
= 0
9523 and then Is_Package_Or_Generic_Package
(Current_Scope
)
9524 and then In_Private_Part
(Current_Scope
)
9525 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
9526 and then Nkind
(Parent
(S
)) = N_Full_Type_Declaration
9527 and then Full_View
(Defining_Identifier
(Parent
(E
)))
9528 = Defining_Identifier
(Parent
(S
))
9529 and then Alias
(E
) = Alias
(S
)
9531 Check_Operation_From_Private_View
(S
, E
);
9532 Set_Is_Dispatching_Operation
(S
);
9537 Enter_Overloaded_Entity
(S
);
9538 Check_Dispatching_Operation
(S
, Empty
);
9539 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
9545 -- If there is no homonym then this is definitely not overriding
9548 Enter_Overloaded_Entity
(S
);
9549 Check_Dispatching_Operation
(S
, Empty
);
9550 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
9552 -- If subprogram has an explicit declaration, check whether it has an
9553 -- overriding indicator.
9555 if Comes_From_Source
(S
) then
9556 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
9558 -- (Ada 2012: AI05-0125-1): If S is a dispatching operation then
9559 -- it may have overridden some hidden inherited primitive. Update
9560 -- Overridden_Subp to avoid spurious errors when checking the
9561 -- overriding indicator.
9563 if Ada_Version
>= Ada_2012
9564 and then No
(Overridden_Subp
)
9565 and then Is_Dispatching_Operation
(S
)
9566 and then Present
(Overridden_Operation
(S
))
9568 Overridden_Subp
:= Overridden_Operation
(S
);
9571 Check_Overriding_Indicator
9572 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
9574 -- The Ghost policy in effect at the point of declaration of a
9575 -- parent subprogram and an overriding subprogram must match
9576 -- (SPARK RM 6.9(17)).
9578 Check_Ghost_Overriding
(S
, Overridden_Subp
);
9581 -- If there is a homonym that is not overloadable, then we have an
9582 -- error, except for the special cases checked explicitly below.
9584 elsif not Is_Overloadable
(E
) then
9586 -- Check for spurious conflict produced by a subprogram that has the
9587 -- same name as that of the enclosing generic package. The conflict
9588 -- occurs within an instance, between the subprogram and the renaming
9589 -- declaration for the package. After the subprogram, the package
9590 -- renaming declaration becomes hidden.
9592 if Ekind
(E
) = E_Package
9593 and then Present
(Renamed_Object
(E
))
9594 and then Renamed_Object
(E
) = Current_Scope
9595 and then Nkind
(Parent
(Renamed_Object
(E
))) =
9596 N_Package_Specification
9597 and then Present
(Generic_Parent
(Parent
(Renamed_Object
(E
))))
9600 Set_Is_Immediately_Visible
(E
, False);
9601 Enter_Overloaded_Entity
(S
);
9602 Set_Homonym
(S
, Homonym
(E
));
9603 Check_Dispatching_Operation
(S
, Empty
);
9604 Check_Overriding_Indicator
(S
, Empty
, Is_Primitive
=> False);
9606 -- If the subprogram is implicit it is hidden by the previous
9607 -- declaration. However if it is dispatching, it must appear in the
9608 -- dispatch table anyway, because it can be dispatched to even if it
9609 -- cannot be called directly.
9611 elsif Present
(Alias
(S
)) and then not Comes_From_Source
(S
) then
9612 Set_Scope
(S
, Current_Scope
);
9614 if Is_Dispatching_Operation
(Alias
(S
)) then
9615 Check_Dispatching_Operation
(S
, Empty
);
9621 Error_Msg_Sloc
:= Sloc
(E
);
9623 -- Generate message, with useful additional warning if in generic
9625 if Is_Generic_Unit
(E
) then
9626 Error_Msg_N
("previous generic unit cannot be overloaded", S
);
9627 Error_Msg_N
("\& conflicts with declaration#", S
);
9629 Error_Msg_N
("& conflicts with declaration#", S
);
9635 -- E exists and is overloadable
9638 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
9640 -- Loop through E and its homonyms to determine if any of them is
9641 -- the candidate for overriding by S.
9643 while Present
(E
) loop
9645 -- Definitely not interesting if not in the current scope
9647 if Scope
(E
) /= Current_Scope
then
9650 -- A function can overload the name of an abstract state. The
9651 -- state can be viewed as a function with a profile that cannot
9652 -- be matched by anything.
9654 elsif Ekind
(S
) = E_Function
9655 and then Ekind
(E
) = E_Abstract_State
9657 Enter_Overloaded_Entity
(S
);
9660 -- Ada 2012 (AI05-0165): For internally generated bodies of null
9661 -- procedures locate the internally generated spec. We enforce
9662 -- mode conformance since a tagged type may inherit from
9663 -- interfaces several null primitives which differ only in
9664 -- the mode of the formals.
9666 elsif not Comes_From_Source
(S
)
9667 and then Is_Null_Procedure
(S
)
9668 and then not Mode_Conformant
(E
, S
)
9672 -- Check if we have type conformance
9674 elsif Type_Conformant
(E
, S
) then
9676 -- If the old and new entities have the same profile and one
9677 -- is not the body of the other, then this is an error, unless
9678 -- one of them is implicitly declared.
9680 -- There are some cases when both can be implicit, for example
9681 -- when both a literal and a function that overrides it are
9682 -- inherited in a derivation, or when an inherited operation
9683 -- of a tagged full type overrides the inherited operation of
9684 -- a private extension. Ada 83 had a special rule for the
9685 -- literal case. In Ada 95, the later implicit operation hides
9686 -- the former, and the literal is always the former. In the
9687 -- odd case where both are derived operations declared at the
9688 -- same point, both operations should be declared, and in that
9689 -- case we bypass the following test and proceed to the next
9690 -- part. This can only occur for certain obscure cases in
9691 -- instances, when an operation on a type derived from a formal
9692 -- private type does not override a homograph inherited from
9693 -- the actual. In subsequent derivations of such a type, the
9694 -- DT positions of these operations remain distinct, if they
9697 if Present
(Alias
(S
))
9698 and then (No
(Alias
(E
))
9699 or else Comes_From_Source
(E
)
9700 or else Is_Abstract_Subprogram
(S
)
9702 (Is_Dispatching_Operation
(E
)
9703 and then Is_Overriding_Alias
(E
, S
)))
9704 and then Ekind
(E
) /= E_Enumeration_Literal
9706 -- When an derived operation is overloaded it may be due to
9707 -- the fact that the full view of a private extension
9708 -- re-inherits. It has to be dealt with.
9710 if Is_Package_Or_Generic_Package
(Current_Scope
)
9711 and then In_Private_Part
(Current_Scope
)
9713 Check_Operation_From_Private_View
(S
, E
);
9716 -- In any case the implicit operation remains hidden by the
9717 -- existing declaration, which is overriding. Indicate that
9718 -- E overrides the operation from which S is inherited.
9720 if Present
(Alias
(S
)) then
9721 Set_Overridden_Operation
(E
, Alias
(S
));
9722 Inherit_Subprogram_Contract
(E
, Alias
(S
));
9725 Set_Overridden_Operation
(E
, S
);
9726 Inherit_Subprogram_Contract
(E
, S
);
9729 if Comes_From_Source
(E
) then
9730 Check_Overriding_Indicator
(E
, S
, Is_Primitive
=> False);
9732 -- The Ghost policy in effect at the point of declaration
9733 -- of a parent subprogram and an overriding subprogram
9734 -- must match (SPARK RM 6.9(17)).
9736 Check_Ghost_Overriding
(E
, S
);
9741 -- Within an instance, the renaming declarations for actual
9742 -- subprograms may become ambiguous, but they do not hide each
9745 elsif Ekind
(E
) /= E_Entry
9746 and then not Comes_From_Source
(E
)
9747 and then not Is_Generic_Instance
(E
)
9748 and then (Present
(Alias
(E
))
9749 or else Is_Intrinsic_Subprogram
(E
))
9750 and then (not In_Instance
9751 or else No
(Parent
(E
))
9752 or else Nkind
(Unit_Declaration_Node
(E
)) /=
9753 N_Subprogram_Renaming_Declaration
)
9755 -- A subprogram child unit is not allowed to override an
9756 -- inherited subprogram (10.1.1(20)).
9758 if Is_Child_Unit
(S
) then
9760 ("child unit overrides inherited subprogram in parent",
9765 if Is_Non_Overriding_Operation
(E
, S
) then
9766 Enter_Overloaded_Entity
(S
);
9768 if No
(Derived_Type
)
9769 or else Is_Tagged_Type
(Derived_Type
)
9771 Check_Dispatching_Operation
(S
, Empty
);
9777 -- E is a derived operation or an internal operator which
9778 -- is being overridden. Remove E from further visibility.
9779 -- Furthermore, if E is a dispatching operation, it must be
9780 -- replaced in the list of primitive operations of its type
9781 -- (see Override_Dispatching_Operation).
9783 Overridden_Subp
:= E
;
9789 Prev
:= First_Entity
(Current_Scope
);
9790 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
9794 -- It is possible for E to be in the current scope and
9795 -- yet not in the entity chain. This can only occur in a
9796 -- generic context where E is an implicit concatenation
9797 -- in the formal part, because in a generic body the
9798 -- entity chain starts with the formals.
9800 -- In GNATprove mode, a wrapper for an operation with
9801 -- axiomatization may be a homonym of another declaration
9802 -- for an actual subprogram (needs refinement ???).
9806 and then GNATprove_Mode
9808 Nkind
(Original_Node
(Unit_Declaration_Node
(S
))) =
9809 N_Subprogram_Renaming_Declaration
9813 pragma Assert
(Chars
(E
) = Name_Op_Concat
);
9818 -- E must be removed both from the entity_list of the
9819 -- current scope, and from the visibility chain.
9821 if Debug_Flag_E
then
9822 Write_Str
("Override implicit operation ");
9823 Write_Int
(Int
(E
));
9827 -- If E is a predefined concatenation, it stands for four
9828 -- different operations. As a result, a single explicit
9829 -- declaration does not hide it. In a possible ambiguous
9830 -- situation, Disambiguate chooses the user-defined op,
9831 -- so it is correct to retain the previous internal one.
9833 if Chars
(E
) /= Name_Op_Concat
9834 or else Ekind
(E
) /= E_Operator
9836 -- For nondispatching derived operations that are
9837 -- overridden by a subprogram declared in the private
9838 -- part of a package, we retain the derived subprogram
9839 -- but mark it as not immediately visible. If the
9840 -- derived operation was declared in the visible part
9841 -- then this ensures that it will still be visible
9842 -- outside the package with the proper signature
9843 -- (calls from outside must also be directed to this
9844 -- version rather than the overriding one, unlike the
9845 -- dispatching case). Calls from inside the package
9846 -- will still resolve to the overriding subprogram
9847 -- since the derived one is marked as not visible
9848 -- within the package.
9850 -- If the private operation is dispatching, we achieve
9851 -- the overriding by keeping the implicit operation
9852 -- but setting its alias to be the overriding one. In
9853 -- this fashion the proper body is executed in all
9854 -- cases, but the original signature is used outside
9857 -- If the overriding is not in the private part, we
9858 -- remove the implicit operation altogether.
9860 if Is_Private_Declaration
(S
) then
9861 if not Is_Dispatching_Operation
(E
) then
9862 Set_Is_Immediately_Visible
(E
, False);
9864 -- Work done in Override_Dispatching_Operation,
9865 -- so nothing else needs to be done here.
9871 -- Find predecessor of E in Homonym chain
9873 if E
= Current_Entity
(E
) then
9876 Prev_Vis
:= Current_Entity
(E
);
9877 while Homonym
(Prev_Vis
) /= E
loop
9878 Prev_Vis
:= Homonym
(Prev_Vis
);
9882 if Prev_Vis
/= Empty
then
9884 -- Skip E in the visibility chain
9886 Set_Homonym
(Prev_Vis
, Homonym
(E
));
9889 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
9892 Set_Next_Entity
(Prev
, Next_Entity
(E
));
9894 if No
(Next_Entity
(Prev
)) then
9895 Set_Last_Entity
(Current_Scope
, Prev
);
9900 Enter_Overloaded_Entity
(S
);
9902 -- For entities generated by Derive_Subprograms the
9903 -- overridden operation is the inherited primitive
9904 -- (which is available through the attribute alias).
9906 if not (Comes_From_Source
(E
))
9907 and then Is_Dispatching_Operation
(E
)
9908 and then Find_Dispatching_Type
(E
) =
9909 Find_Dispatching_Type
(S
)
9910 and then Present
(Alias
(E
))
9911 and then Comes_From_Source
(Alias
(E
))
9913 Set_Overridden_Operation
(S
, Alias
(E
));
9914 Inherit_Subprogram_Contract
(S
, Alias
(E
));
9916 -- Normal case of setting entity as overridden
9918 -- Note: Static_Initialization and Overridden_Operation
9919 -- attributes use the same field in subprogram entities.
9920 -- Static_Initialization is only defined for internal
9921 -- initialization procedures, where Overridden_Operation
9922 -- is irrelevant. Therefore the setting of this attribute
9923 -- must check whether the target is an init_proc.
9925 elsif not Is_Init_Proc
(S
) then
9926 Set_Overridden_Operation
(S
, E
);
9927 Inherit_Subprogram_Contract
(S
, E
);
9930 Check_Overriding_Indicator
(S
, E
, Is_Primitive
=> True);
9932 -- The Ghost policy in effect at the point of declaration
9933 -- of a parent subprogram and an overriding subprogram
9934 -- must match (SPARK RM 6.9(17)).
9936 Check_Ghost_Overriding
(S
, E
);
9938 -- If S is a user-defined subprogram or a null procedure
9939 -- expanded to override an inherited null procedure, or a
9940 -- predefined dispatching primitive then indicate that E
9941 -- overrides the operation from which S is inherited.
9943 if Comes_From_Source
(S
)
9945 (Present
(Parent
(S
))
9947 Nkind
(Parent
(S
)) = N_Procedure_Specification
9949 Null_Present
(Parent
(S
)))
9951 (Present
(Alias
(E
))
9953 Is_Predefined_Dispatching_Operation
(Alias
(E
)))
9955 if Present
(Alias
(E
)) then
9956 Set_Overridden_Operation
(S
, Alias
(E
));
9957 Inherit_Subprogram_Contract
(S
, Alias
(E
));
9961 if Is_Dispatching_Operation
(E
) then
9963 -- An overriding dispatching subprogram inherits the
9964 -- convention of the overridden subprogram (AI-117).
9966 Set_Convention
(S
, Convention
(E
));
9967 Check_Dispatching_Operation
(S
, E
);
9969 -- In GNATprove_Mode, create the pragmas corresponding
9970 -- to inherited class-wide conditions.
9972 if GNATprove_Mode
then
9973 Collect_Inherited_Class_Wide_Conditions
(S
);
9977 Check_Dispatching_Operation
(S
, Empty
);
9980 Check_For_Primitive_Subprogram
9981 (Is_Primitive_Subp
, Is_Overriding
=> True);
9982 goto Check_Inequality
;
9985 -- Apparent redeclarations in instances can occur when two
9986 -- formal types get the same actual type. The subprograms in
9987 -- in the instance are legal, even if not callable from the
9988 -- outside. Calls from within are disambiguated elsewhere.
9989 -- For dispatching operations in the visible part, the usual
9990 -- rules apply, and operations with the same profile are not
9993 elsif (In_Instance_Visible_Part
9994 and then not Is_Dispatching_Operation
(E
))
9995 or else In_Instance_Not_Visible
9999 -- Here we have a real error (identical profile)
10002 Error_Msg_Sloc
:= Sloc
(E
);
10004 -- Avoid cascaded errors if the entity appears in
10005 -- subsequent calls.
10007 Set_Scope
(S
, Current_Scope
);
10009 -- Generate error, with extra useful warning for the case
10010 -- of a generic instance with no completion.
10012 if Is_Generic_Instance
(S
)
10013 and then not Has_Completion
(E
)
10016 ("instantiation cannot provide body for&", S
);
10017 Error_Msg_N
("\& conflicts with declaration#", S
);
10019 Error_Msg_N
("& conflicts with declaration#", S
);
10026 -- If one subprogram has an access parameter and the other
10027 -- a parameter of an access type, calls to either might be
10028 -- ambiguous. Verify that parameters match except for the
10029 -- access parameter.
10031 if May_Hide_Profile
then
10037 F1
:= First_Formal
(S
);
10038 F2
:= First_Formal
(E
);
10039 while Present
(F1
) and then Present
(F2
) loop
10040 if Is_Access_Type
(Etype
(F1
)) then
10041 if not Is_Access_Type
(Etype
(F2
))
10042 or else not Conforming_Types
10043 (Designated_Type
(Etype
(F1
)),
10044 Designated_Type
(Etype
(F2
)),
10047 May_Hide_Profile
:= False;
10051 not Conforming_Types
10052 (Etype
(F1
), Etype
(F2
), Type_Conformant
)
10054 May_Hide_Profile
:= False;
10061 if May_Hide_Profile
10065 Error_Msg_NE
("calls to& may be ambiguous??", S
, S
);
10074 -- On exit, we know that S is a new entity
10076 Enter_Overloaded_Entity
(S
);
10077 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
10078 Check_Overriding_Indicator
10079 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
10081 -- The Ghost policy in effect at the point of declaration of a parent
10082 -- subprogram and an overriding subprogram must match
10083 -- (SPARK RM 6.9(17)).
10085 Check_Ghost_Overriding
(S
, Overridden_Subp
);
10087 -- Overloading is not allowed in SPARK, except for operators
10089 if Nkind
(S
) /= N_Defining_Operator_Symbol
then
10090 Error_Msg_Sloc
:= Sloc
(Homonym
(S
));
10091 Check_SPARK_05_Restriction
10092 ("overloading not allowed with entity#", S
);
10095 -- If S is a derived operation for an untagged type then by
10096 -- definition it's not a dispatching operation (even if the parent
10097 -- operation was dispatching), so Check_Dispatching_Operation is not
10098 -- called in that case.
10100 if No
(Derived_Type
)
10101 or else Is_Tagged_Type
(Derived_Type
)
10103 Check_Dispatching_Operation
(S
, Empty
);
10107 -- If this is a user-defined equality operator that is not a derived
10108 -- subprogram, create the corresponding inequality. If the operation is
10109 -- dispatching, the expansion is done elsewhere, and we do not create
10110 -- an explicit inequality operation.
10112 <<Check_Inequality
>>
10113 if Chars
(S
) = Name_Op_Eq
10114 and then Etype
(S
) = Standard_Boolean
10115 and then Present
(Parent
(S
))
10116 and then not Is_Dispatching_Operation
(S
)
10118 Make_Inequality_Operator
(S
);
10119 Check_Untagged_Equality
(S
);
10121 end New_Overloaded_Entity
;
10123 ---------------------
10124 -- Process_Formals --
10125 ---------------------
10127 procedure Process_Formals
10129 Related_Nod
: Node_Id
)
10131 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean;
10132 -- Determine whether an access type designates a type coming from a
10135 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean;
10136 -- Check whether the default has a class-wide type. After analysis the
10137 -- default has the type of the formal, so we must also check explicitly
10138 -- for an access attribute.
10140 ----------------------------------
10141 -- Designates_From_Limited_With --
10142 ----------------------------------
10144 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean is
10145 Desig
: Entity_Id
:= Typ
;
10148 if Is_Access_Type
(Desig
) then
10149 Desig
:= Directly_Designated_Type
(Desig
);
10152 if Is_Class_Wide_Type
(Desig
) then
10153 Desig
:= Root_Type
(Desig
);
10157 Ekind
(Desig
) = E_Incomplete_Type
10158 and then From_Limited_With
(Desig
);
10159 end Designates_From_Limited_With
;
10161 ---------------------------
10162 -- Is_Class_Wide_Default --
10163 ---------------------------
10165 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean is
10167 return Is_Class_Wide_Type
(Designated_Type
(Etype
(D
)))
10168 or else (Nkind
(D
) = N_Attribute_Reference
10169 and then Attribute_Name
(D
) = Name_Access
10170 and then Is_Class_Wide_Type
(Etype
(Prefix
(D
))));
10171 end Is_Class_Wide_Default
;
10175 Context
: constant Node_Id
:= Parent
(Parent
(T
));
10177 Formal
: Entity_Id
;
10178 Formal_Type
: Entity_Id
;
10179 Param_Spec
: Node_Id
;
10182 Num_Out_Params
: Nat
:= 0;
10183 First_Out_Param
: Entity_Id
:= Empty
;
10184 -- Used for setting Is_Only_Out_Parameter
10186 -- Start of processing for Process_Formals
10189 -- In order to prevent premature use of the formals in the same formal
10190 -- part, the Ekind is left undefined until all default expressions are
10191 -- analyzed. The Ekind is established in a separate loop at the end.
10193 Param_Spec
:= First
(T
);
10194 while Present
(Param_Spec
) loop
10195 Formal
:= Defining_Identifier
(Param_Spec
);
10196 Set_Never_Set_In_Source
(Formal
, True);
10197 Enter_Name
(Formal
);
10199 -- Case of ordinary parameters
10201 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
10202 Find_Type
(Parameter_Type
(Param_Spec
));
10203 Ptype
:= Parameter_Type
(Param_Spec
);
10205 if Ptype
= Error
then
10209 Formal_Type
:= Entity
(Ptype
);
10211 if Is_Incomplete_Type
(Formal_Type
)
10213 (Is_Class_Wide_Type
(Formal_Type
)
10214 and then Is_Incomplete_Type
(Root_Type
(Formal_Type
)))
10216 -- Ada 2005 (AI-326): Tagged incomplete types allowed in
10217 -- primitive operations, as long as their completion is
10218 -- in the same declarative part. If in the private part
10219 -- this means that the type cannot be a Taft-amendment type.
10220 -- Check is done on package exit. For access to subprograms,
10221 -- the use is legal for Taft-amendment types.
10223 -- Ada 2012: tagged incomplete types are allowed as generic
10224 -- formal types. They do not introduce dependencies and the
10225 -- corresponding generic subprogram does not have a delayed
10226 -- freeze, because it does not need a freeze node. However,
10227 -- it is still the case that untagged incomplete types cannot
10228 -- be Taft-amendment types and must be completed in private
10229 -- part, so the subprogram must appear in the list of private
10230 -- dependents of the type. If the type is class-wide, it is
10231 -- not a primitive, but the freezing of the subprogram must
10232 -- also be delayed to force the creation of a freeze node.
10234 if Is_Tagged_Type
(Formal_Type
)
10235 or else (Ada_Version
>= Ada_2012
10236 and then not From_Limited_With
(Formal_Type
)
10237 and then not Is_Generic_Type
(Formal_Type
))
10239 if Ekind
(Scope
(Current_Scope
)) = E_Package
10240 and then not Is_Generic_Type
(Formal_Type
)
10243 (Parent
(T
), N_Access_Function_Definition
,
10244 N_Access_Procedure_Definition
)
10246 -- A limited view has no private dependents
10248 if not Is_Class_Wide_Type
(Formal_Type
)
10249 and then not From_Limited_With
(Formal_Type
)
10251 Append_Elmt
(Current_Scope
,
10252 Private_Dependents
(Base_Type
(Formal_Type
)));
10255 -- Freezing is delayed to ensure that Register_Prim
10256 -- will get called for this operation, which is needed
10257 -- in cases where static dispatch tables aren't built.
10258 -- (Note that the same is done for controlling access
10259 -- parameter cases in function Access_Definition.)
10261 if not Is_Thunk
(Current_Scope
) then
10262 Set_Has_Delayed_Freeze
(Current_Scope
);
10267 elsif not Nkind_In
(Parent
(T
), N_Access_Function_Definition
,
10268 N_Access_Procedure_Definition
)
10270 -- AI05-0151: Tagged incomplete types are allowed in all
10271 -- formal parts. Untagged incomplete types are not allowed
10272 -- in bodies. Limited views of either kind are not allowed
10273 -- if there is no place at which the non-limited view can
10274 -- become available.
10276 -- Incomplete formal untagged types are not allowed in
10277 -- subprogram bodies (but are legal in their declarations).
10278 -- This excludes bodies created for null procedures, which
10279 -- are basic declarations.
10281 if Is_Generic_Type
(Formal_Type
)
10282 and then not Is_Tagged_Type
(Formal_Type
)
10283 and then Nkind
(Parent
(Related_Nod
)) = N_Subprogram_Body
10286 ("invalid use of formal incomplete type", Param_Spec
);
10288 elsif Ada_Version
>= Ada_2012
then
10289 if Is_Tagged_Type
(Formal_Type
)
10290 and then (not From_Limited_With
(Formal_Type
)
10291 or else not In_Package_Body
)
10295 elsif Nkind_In
(Context
, N_Accept_Statement
,
10296 N_Accept_Alternative
,
10298 or else (Nkind
(Context
) = N_Subprogram_Body
10299 and then Comes_From_Source
(Context
))
10302 ("invalid use of untagged incomplete type &",
10303 Ptype
, Formal_Type
);
10308 ("invalid use of incomplete type&",
10309 Param_Spec
, Formal_Type
);
10311 -- Further checks on the legality of incomplete types
10312 -- in formal parts are delayed until the freeze point
10313 -- of the enclosing subprogram or access to subprogram.
10317 elsif Ekind
(Formal_Type
) = E_Void
then
10319 ("premature use of&",
10320 Parameter_Type
(Param_Spec
), Formal_Type
);
10323 -- Ada 2012 (AI-142): Handle aliased parameters
10325 if Ada_Version
>= Ada_2012
10326 and then Aliased_Present
(Param_Spec
)
10328 Set_Is_Aliased
(Formal
);
10331 -- Ada 2005 (AI-231): Create and decorate an internal subtype
10332 -- declaration corresponding to the null-excluding type of the
10333 -- formal in the enclosing scope. Finally, replace the parameter
10334 -- type of the formal with the internal subtype.
10336 if Ada_Version
>= Ada_2005
10337 and then Null_Exclusion_Present
(Param_Spec
)
10339 if not Is_Access_Type
(Formal_Type
) then
10341 ("`NOT NULL` allowed only for an access type", Param_Spec
);
10344 if Can_Never_Be_Null
(Formal_Type
)
10345 and then Comes_From_Source
(Related_Nod
)
10348 ("`NOT NULL` not allowed (& already excludes null)",
10349 Param_Spec
, Formal_Type
);
10353 Create_Null_Excluding_Itype
10355 Related_Nod
=> Related_Nod
,
10356 Scope_Id
=> Scope
(Current_Scope
));
10358 -- If the designated type of the itype is an itype that is
10359 -- not frozen yet, we set the Has_Delayed_Freeze attribute
10360 -- on the access subtype, to prevent order-of-elaboration
10361 -- issues in the backend.
10364 -- type T is access procedure;
10365 -- procedure Op (O : not null T);
10367 if Is_Itype
(Directly_Designated_Type
(Formal_Type
))
10369 not Is_Frozen
(Directly_Designated_Type
(Formal_Type
))
10371 Set_Has_Delayed_Freeze
(Formal_Type
);
10376 -- An access formal type
10380 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
10382 -- No need to continue if we already notified errors
10384 if not Present
(Formal_Type
) then
10388 -- Ada 2005 (AI-254)
10391 AD
: constant Node_Id
:=
10392 Access_To_Subprogram_Definition
10393 (Parameter_Type
(Param_Spec
));
10395 if Present
(AD
) and then Protected_Present
(AD
) then
10397 Replace_Anonymous_Access_To_Protected_Subprogram
10403 Set_Etype
(Formal
, Formal_Type
);
10405 -- Deal with default expression if present
10407 Default
:= Expression
(Param_Spec
);
10409 if Present
(Default
) then
10410 Check_SPARK_05_Restriction
10411 ("default expression is not allowed", Default
);
10413 if Out_Present
(Param_Spec
) then
10415 ("default initialization only allowed for IN parameters",
10419 -- Do the special preanalysis of the expression (see section on
10420 -- "Handling of Default Expressions" in the spec of package Sem).
10422 Preanalyze_Spec_Expression
(Default
, Formal_Type
);
10424 -- An access to constant cannot be the default for
10425 -- an access parameter that is an access to variable.
10427 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
10428 and then not Is_Access_Constant
(Formal_Type
)
10429 and then Is_Access_Type
(Etype
(Default
))
10430 and then Is_Access_Constant
(Etype
(Default
))
10433 ("formal that is access to variable cannot be initialized "
10434 & "with an access-to-constant expression", Default
);
10437 -- Check that the designated type of an access parameter's default
10438 -- is not a class-wide type unless the parameter's designated type
10439 -- is also class-wide.
10441 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
10442 and then not Designates_From_Limited_With
(Formal_Type
)
10443 and then Is_Class_Wide_Default
(Default
)
10444 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
10447 ("access to class-wide expression not allowed here", Default
);
10450 -- Check incorrect use of dynamically tagged expressions
10452 if Is_Tagged_Type
(Formal_Type
) then
10453 Check_Dynamically_Tagged_Expression
10455 Typ
=> Formal_Type
,
10456 Related_Nod
=> Default
);
10460 -- Ada 2005 (AI-231): Static checks
10462 if Ada_Version
>= Ada_2005
10463 and then Is_Access_Type
(Etype
(Formal
))
10464 and then Can_Never_Be_Null
(Etype
(Formal
))
10466 Null_Exclusion_Static_Checks
(Param_Spec
);
10469 -- The following checks are relevant only when SPARK_Mode is on as
10470 -- these are not standard Ada legality rules.
10472 if SPARK_Mode
= On
then
10473 if Ekind_In
(Scope
(Formal
), E_Function
, E_Generic_Function
) then
10475 -- A function cannot have a parameter of mode IN OUT or OUT
10478 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_Out_Parameter
) then
10480 ("function cannot have parameter of mode `OUT` or "
10481 & "`IN OUT`", Formal
);
10484 -- A procedure cannot have an effectively volatile formal
10485 -- parameter of mode IN because it behaves as a constant
10486 -- (SPARK RM 7.1.3(6)).
10488 elsif Ekind
(Scope
(Formal
)) = E_Procedure
10489 and then Ekind
(Formal
) = E_In_Parameter
10490 and then Is_Effectively_Volatile
(Formal
)
10493 ("formal parameter of mode `IN` cannot be volatile", Formal
);
10501 -- If this is the formal part of a function specification, analyze the
10502 -- subtype mark in the context where the formals are visible but not
10503 -- yet usable, and may hide outer homographs.
10505 if Nkind
(Related_Nod
) = N_Function_Specification
then
10506 Analyze_Return_Type
(Related_Nod
);
10508 -- If return type is class-wide, subprogram freezing may be
10509 -- delayed as well, unless the declaration is a compilation unit
10510 -- in which case the freeze node would appear too late.
10512 if Is_Class_Wide_Type
(Etype
(Current_Scope
))
10513 and then not Is_Thunk
(Current_Scope
)
10514 and then not Is_Compilation_Unit
(Current_Scope
)
10515 and then Nkind
(Unit_Declaration_Node
(Current_Scope
)) =
10516 N_Subprogram_Declaration
10518 Set_Has_Delayed_Freeze
(Current_Scope
);
10522 -- Now set the kind (mode) of each formal
10524 Param_Spec
:= First
(T
);
10525 while Present
(Param_Spec
) loop
10526 Formal
:= Defining_Identifier
(Param_Spec
);
10527 Set_Formal_Mode
(Formal
);
10529 if Ekind
(Formal
) = E_In_Parameter
then
10530 Set_Default_Value
(Formal
, Expression
(Param_Spec
));
10532 if Present
(Expression
(Param_Spec
)) then
10533 Default
:= Expression
(Param_Spec
);
10535 if Is_Scalar_Type
(Etype
(Default
)) then
10536 if Nkind
(Parameter_Type
(Param_Spec
)) /=
10537 N_Access_Definition
10539 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
10543 (Related_Nod
, Parameter_Type
(Param_Spec
));
10546 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
10550 elsif Ekind
(Formal
) = E_Out_Parameter
then
10551 Num_Out_Params
:= Num_Out_Params
+ 1;
10553 if Num_Out_Params
= 1 then
10554 First_Out_Param
:= Formal
;
10557 elsif Ekind
(Formal
) = E_In_Out_Parameter
then
10558 Num_Out_Params
:= Num_Out_Params
+ 1;
10561 -- Skip remaining processing if formal type was in error
10563 if Etype
(Formal
) = Any_Type
or else Error_Posted
(Formal
) then
10564 goto Next_Parameter
;
10567 -- Force call by reference if aliased
10569 if Is_Aliased
(Formal
) then
10570 Set_Mechanism
(Formal
, By_Reference
);
10572 -- Warn if user asked this to be passed by copy
10574 if Convention
(Formal_Type
) = Convention_Ada_Pass_By_Copy
then
10576 ("cannot pass aliased parameter & by copy??", Formal
);
10579 -- Force mechanism if type has Convention Ada_Pass_By_Ref/Copy
10581 elsif Convention
(Formal_Type
) = Convention_Ada_Pass_By_Copy
then
10582 Set_Mechanism
(Formal
, By_Copy
);
10584 elsif Convention
(Formal_Type
) = Convention_Ada_Pass_By_Reference
then
10585 Set_Mechanism
(Formal
, By_Reference
);
10592 if Present
(First_Out_Param
) and then Num_Out_Params
= 1 then
10593 Set_Is_Only_Out_Parameter
(First_Out_Param
);
10595 end Process_Formals
;
10597 ----------------------------
10598 -- Reference_Body_Formals --
10599 ----------------------------
10601 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
) is
10606 if Error_Posted
(Spec
) then
10610 -- Iterate over both lists. They may be of different lengths if the two
10611 -- specs are not conformant.
10613 Fs
:= First_Formal
(Spec
);
10614 Fb
:= First_Formal
(Bod
);
10615 while Present
(Fs
) and then Present
(Fb
) loop
10616 Generate_Reference
(Fs
, Fb
, 'b');
10618 if Style_Check
then
10619 Style
.Check_Identifier
(Fb
, Fs
);
10622 Set_Spec_Entity
(Fb
, Fs
);
10623 Set_Referenced
(Fs
, False);
10627 end Reference_Body_Formals
;
10629 -------------------------
10630 -- Set_Actual_Subtypes --
10631 -------------------------
10633 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
10635 Formal
: Entity_Id
;
10637 First_Stmt
: Node_Id
:= Empty
;
10638 AS_Needed
: Boolean;
10641 -- If this is an empty initialization procedure, no need to create
10642 -- actual subtypes (small optimization).
10644 if Ekind
(Subp
) = E_Procedure
and then Is_Null_Init_Proc
(Subp
) then
10648 Formal
:= First_Formal
(Subp
);
10649 while Present
(Formal
) loop
10650 T
:= Etype
(Formal
);
10652 -- We never need an actual subtype for a constrained formal
10654 if Is_Constrained
(T
) then
10655 AS_Needed
:= False;
10657 -- If we have unknown discriminants, then we do not need an actual
10658 -- subtype, or more accurately we cannot figure it out. Note that
10659 -- all class-wide types have unknown discriminants.
10661 elsif Has_Unknown_Discriminants
(T
) then
10662 AS_Needed
:= False;
10664 -- At this stage we have an unconstrained type that may need an
10665 -- actual subtype. For sure the actual subtype is needed if we have
10666 -- an unconstrained array type.
10668 elsif Is_Array_Type
(T
) then
10671 -- The only other case needing an actual subtype is an unconstrained
10672 -- record type which is an IN parameter (we cannot generate actual
10673 -- subtypes for the OUT or IN OUT case, since an assignment can
10674 -- change the discriminant values. However we exclude the case of
10675 -- initialization procedures, since discriminants are handled very
10676 -- specially in this context, see the section entitled "Handling of
10677 -- Discriminants" in Einfo.
10679 -- We also exclude the case of Discrim_SO_Functions (functions used
10680 -- in front end layout mode for size/offset values), since in such
10681 -- functions only discriminants are referenced, and not only are such
10682 -- subtypes not needed, but they cannot always be generated, because
10683 -- of order of elaboration issues.
10685 elsif Is_Record_Type
(T
)
10686 and then Ekind
(Formal
) = E_In_Parameter
10687 and then Chars
(Formal
) /= Name_uInit
10688 and then not Is_Unchecked_Union
(T
)
10689 and then not Is_Discrim_SO_Function
(Subp
)
10693 -- All other cases do not need an actual subtype
10696 AS_Needed
:= False;
10699 -- Generate actual subtypes for unconstrained arrays and
10700 -- unconstrained discriminated records.
10703 if Nkind
(N
) = N_Accept_Statement
then
10705 -- If expansion is active, the formal is replaced by a local
10706 -- variable that renames the corresponding entry of the
10707 -- parameter block, and it is this local variable that may
10708 -- require an actual subtype.
10710 if Expander_Active
then
10711 Decl
:= Build_Actual_Subtype
(T
, Renamed_Object
(Formal
));
10713 Decl
:= Build_Actual_Subtype
(T
, Formal
);
10716 if Present
(Handled_Statement_Sequence
(N
)) then
10718 First
(Statements
(Handled_Statement_Sequence
(N
)));
10719 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
10720 Mark_Rewrite_Insertion
(Decl
);
10722 -- If the accept statement has no body, there will be no
10723 -- reference to the actuals, so no need to compute actual
10730 Decl
:= Build_Actual_Subtype
(T
, Formal
);
10731 Prepend
(Decl
, Declarations
(N
));
10732 Mark_Rewrite_Insertion
(Decl
);
10735 -- The declaration uses the bounds of an existing object, and
10736 -- therefore needs no constraint checks.
10738 Analyze
(Decl
, Suppress
=> All_Checks
);
10740 -- We need to freeze manually the generated type when it is
10741 -- inserted anywhere else than in a declarative part.
10743 if Present
(First_Stmt
) then
10744 Insert_List_Before_And_Analyze
(First_Stmt
,
10745 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
10747 -- Ditto if the type has a dynamic predicate, because the
10748 -- generated function will mention the actual subtype.
10750 elsif Has_Dynamic_Predicate_Aspect
(T
) then
10751 Insert_List_Before_And_Analyze
(Decl
,
10752 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
10755 if Nkind
(N
) = N_Accept_Statement
10756 and then Expander_Active
10758 Set_Actual_Subtype
(Renamed_Object
(Formal
),
10759 Defining_Identifier
(Decl
));
10761 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
10765 Next_Formal
(Formal
);
10767 end Set_Actual_Subtypes
;
10769 ---------------------
10770 -- Set_Formal_Mode --
10771 ---------------------
10773 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
10774 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
10775 Id
: constant Entity_Id
:= Scope
(Formal_Id
);
10778 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
10779 -- since we ensure that corresponding actuals are always valid at the
10780 -- point of the call.
10782 if Out_Present
(Spec
) then
10783 if Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
10784 or else Is_Subprogram_Or_Generic_Subprogram
(Id
)
10786 Set_Has_Out_Or_In_Out_Parameter
(Id
, True);
10789 if Ekind_In
(Id
, E_Function
, E_Generic_Function
) then
10791 -- [IN] OUT parameters allowed for functions in Ada 2012
10793 if Ada_Version
>= Ada_2012
then
10795 -- Even in Ada 2012 operators can only have IN parameters
10797 if Is_Operator_Symbol_Name
(Chars
(Scope
(Formal_Id
))) then
10798 Error_Msg_N
("operators can only have IN parameters", Spec
);
10801 if In_Present
(Spec
) then
10802 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
10804 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
10807 -- But not in earlier versions of Ada
10810 Error_Msg_N
("functions can only have IN parameters", Spec
);
10811 Set_Ekind
(Formal_Id
, E_In_Parameter
);
10814 elsif In_Present
(Spec
) then
10815 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
10818 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
10819 Set_Never_Set_In_Source
(Formal_Id
, True);
10820 Set_Is_True_Constant
(Formal_Id
, False);
10821 Set_Current_Value
(Formal_Id
, Empty
);
10825 Set_Ekind
(Formal_Id
, E_In_Parameter
);
10828 -- Set Is_Known_Non_Null for access parameters since the language
10829 -- guarantees that access parameters are always non-null. We also set
10830 -- Can_Never_Be_Null, since there is no way to change the value.
10832 if Nkind
(Parameter_Type
(Spec
)) = N_Access_Definition
then
10834 -- Ada 2005 (AI-231): In Ada 95, access parameters are always non-
10835 -- null; In Ada 2005, only if then null_exclusion is explicit.
10837 if Ada_Version
< Ada_2005
10838 or else Can_Never_Be_Null
(Etype
(Formal_Id
))
10840 Set_Is_Known_Non_Null
(Formal_Id
);
10841 Set_Can_Never_Be_Null
(Formal_Id
);
10844 -- Ada 2005 (AI-231): Null-exclusion access subtype
10846 elsif Is_Access_Type
(Etype
(Formal_Id
))
10847 and then Can_Never_Be_Null
(Etype
(Formal_Id
))
10849 Set_Is_Known_Non_Null
(Formal_Id
);
10851 -- We can also set Can_Never_Be_Null (thus preventing some junk
10852 -- access checks) for the case of an IN parameter, which cannot
10853 -- be changed, or for an IN OUT parameter, which can be changed but
10854 -- not to a null value. But for an OUT parameter, the initial value
10855 -- passed in can be null, so we can't set this flag in that case.
10857 if Ekind
(Formal_Id
) /= E_Out_Parameter
then
10858 Set_Can_Never_Be_Null
(Formal_Id
);
10862 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
10863 Set_Formal_Validity
(Formal_Id
);
10864 end Set_Formal_Mode
;
10866 -------------------------
10867 -- Set_Formal_Validity --
10868 -------------------------
10870 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
10872 -- If no validity checking, then we cannot assume anything about the
10873 -- validity of parameters, since we do not know there is any checking
10874 -- of the validity on the call side.
10876 if not Validity_Checks_On
then
10879 -- If validity checking for parameters is enabled, this means we are
10880 -- not supposed to make any assumptions about argument values.
10882 elsif Validity_Check_Parameters
then
10885 -- If we are checking in parameters, we will assume that the caller is
10886 -- also checking parameters, so we can assume the parameter is valid.
10888 elsif Ekind
(Formal_Id
) = E_In_Parameter
10889 and then Validity_Check_In_Params
10891 Set_Is_Known_Valid
(Formal_Id
, True);
10893 -- Similar treatment for IN OUT parameters
10895 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
10896 and then Validity_Check_In_Out_Params
10898 Set_Is_Known_Valid
(Formal_Id
, True);
10900 end Set_Formal_Validity
;
10902 ------------------------
10903 -- Subtype_Conformant --
10904 ------------------------
10906 function Subtype_Conformant
10907 (New_Id
: Entity_Id
;
10908 Old_Id
: Entity_Id
;
10909 Skip_Controlling_Formals
: Boolean := False) return Boolean
10913 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
,
10914 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
10916 end Subtype_Conformant
;
10918 ---------------------
10919 -- Type_Conformant --
10920 ---------------------
10922 function Type_Conformant
10923 (New_Id
: Entity_Id
;
10924 Old_Id
: Entity_Id
;
10925 Skip_Controlling_Formals
: Boolean := False) return Boolean
10929 May_Hide_Profile
:= False;
10931 (New_Id
, Old_Id
, Type_Conformant
, False, Result
,
10932 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
10934 end Type_Conformant
;
10936 -------------------------------
10937 -- Valid_Operator_Definition --
10938 -------------------------------
10940 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
10943 Id
: constant Name_Id
:= Chars
(Designator
);
10947 F
:= First_Formal
(Designator
);
10948 while Present
(F
) loop
10951 if Present
(Default_Value
(F
)) then
10953 ("default values not allowed for operator parameters",
10956 -- For function instantiations that are operators, we must check
10957 -- separately that the corresponding generic only has in-parameters.
10958 -- For subprogram declarations this is done in Set_Formal_Mode. Such
10959 -- an error could not arise in earlier versions of the language.
10961 elsif Ekind
(F
) /= E_In_Parameter
then
10962 Error_Msg_N
("operators can only have IN parameters", F
);
10968 -- Verify that user-defined operators have proper number of arguments
10969 -- First case of operators which can only be unary
10971 if Nam_In
(Id
, Name_Op_Not
, Name_Op_Abs
) then
10974 -- Case of operators which can be unary or binary
10976 elsif Nam_In
(Id
, Name_Op_Add
, Name_Op_Subtract
) then
10977 N_OK
:= (N
in 1 .. 2);
10979 -- All other operators can only be binary
10987 ("incorrect number of arguments for operator", Designator
);
10991 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
10992 and then not Is_Intrinsic_Subprogram
(Designator
)
10995 ("explicit definition of inequality not allowed", Designator
);
10997 end Valid_Operator_Definition
;