1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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 Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Expander
; use Expander
;
34 with Exp_Ch6
; use Exp_Ch6
;
35 with Exp_Ch7
; use Exp_Ch7
;
36 with Exp_Ch9
; use Exp_Ch9
;
37 with Exp_Dbug
; use Exp_Dbug
;
38 with Exp_Disp
; use Exp_Disp
;
39 with Exp_Tss
; use Exp_Tss
;
40 with Exp_Util
; use Exp_Util
;
41 with Fname
; use Fname
;
42 with Freeze
; use Freeze
;
43 with Inline
; use Inline
;
44 with Itypes
; use Itypes
;
45 with Lib
.Xref
; use Lib
.Xref
;
46 with Layout
; use Layout
;
47 with Namet
; use Namet
;
49 with Nlists
; use Nlists
;
50 with Nmake
; use Nmake
;
52 with Output
; use Output
;
53 with Restrict
; use Restrict
;
54 with Rident
; use Rident
;
55 with Rtsfind
; use Rtsfind
;
57 with Sem_Aux
; use Sem_Aux
;
58 with Sem_Cat
; use Sem_Cat
;
59 with Sem_Ch3
; use Sem_Ch3
;
60 with Sem_Ch4
; use Sem_Ch4
;
61 with Sem_Ch5
; use Sem_Ch5
;
62 with Sem_Ch8
; use Sem_Ch8
;
63 with Sem_Ch10
; use Sem_Ch10
;
64 with Sem_Ch12
; use Sem_Ch12
;
65 with Sem_Ch13
; use Sem_Ch13
;
66 with Sem_Dim
; use Sem_Dim
;
67 with Sem_Disp
; use Sem_Disp
;
68 with Sem_Dist
; use Sem_Dist
;
69 with Sem_Elim
; use Sem_Elim
;
70 with Sem_Eval
; use Sem_Eval
;
71 with Sem_Mech
; use Sem_Mech
;
72 with Sem_Prag
; use Sem_Prag
;
73 with Sem_Res
; use Sem_Res
;
74 with Sem_Util
; use Sem_Util
;
75 with Sem_Type
; use Sem_Type
;
76 with Sem_Warn
; use Sem_Warn
;
77 with Sinput
; use Sinput
;
78 with Stand
; use Stand
;
79 with Sinfo
; use Sinfo
;
80 with Sinfo
.CN
; use Sinfo
.CN
;
81 with Snames
; use Snames
;
82 with Stringt
; use Stringt
;
84 with Stylesw
; use Stylesw
;
85 with Targparm
; use Targparm
;
86 with Tbuild
; use Tbuild
;
87 with Uintp
; use Uintp
;
88 with Urealp
; use Urealp
;
89 with Validsw
; use Validsw
;
91 package body Sem_Ch6
is
93 May_Hide_Profile
: Boolean := False;
94 -- This flag is used to indicate that two formals in two subprograms being
95 -- checked for conformance differ only in that one is an access parameter
96 -- while the other is of a general access type with the same designated
97 -- type. In this case, if the rest of the signatures match, a call to
98 -- either subprogram may be ambiguous, which is worth a warning. The flag
99 -- is set in Compatible_Types, and the warning emitted in
100 -- New_Overloaded_Entity.
102 -----------------------
103 -- Local Subprograms --
104 -----------------------
106 procedure Analyze_Null_Procedure
108 Is_Completion
: out Boolean);
109 -- A null procedure can be a declaration or (Ada 2012) a completion
111 procedure Analyze_Return_Statement
(N
: Node_Id
);
112 -- Common processing for simple and extended return statements
114 procedure Analyze_Function_Return
(N
: Node_Id
);
115 -- Subsidiary to Analyze_Return_Statement. Called when the return statement
116 -- applies to a [generic] function.
118 procedure Analyze_Return_Type
(N
: Node_Id
);
119 -- Subsidiary to Process_Formals: analyze subtype mark in function
120 -- specification in a context where the formals are visible and hide
123 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
);
124 -- Does all the real work of Analyze_Subprogram_Body. This is split out so
125 -- that we can use RETURN but not skip the debug output at the end.
127 procedure Analyze_Generic_Subprogram_Body
(N
: Node_Id
; Gen_Id
: Entity_Id
);
128 -- Analyze a generic subprogram body. N is the body to be analyzed, and
129 -- Gen_Id is the defining entity Id for the corresponding spec.
131 function Can_Override_Operator
(Subp
: Entity_Id
) return Boolean;
132 -- Returns true if Subp can override a predefined operator.
134 procedure Check_Conformance
137 Ctype
: Conformance_Type
;
139 Conforms
: out Boolean;
140 Err_Loc
: Node_Id
:= Empty
;
141 Get_Inst
: Boolean := False;
142 Skip_Controlling_Formals
: Boolean := False);
143 -- Given two entities, this procedure checks that the profiles associated
144 -- with these entities meet the conformance criterion given by the third
145 -- parameter. If they conform, Conforms is set True and control returns
146 -- to the caller. If they do not conform, Conforms is set to False, and
147 -- in addition, if Errmsg is True on the call, proper messages are output
148 -- to complain about the conformance failure. If Err_Loc is non_Empty
149 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
150 -- error messages are placed on the appropriate part of the construct
151 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
152 -- against a formal access-to-subprogram type so Get_Instance_Of must
155 procedure Check_Subprogram_Order
(N
: Node_Id
);
156 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
157 -- the alpha ordering rule for N if this ordering requirement applicable.
159 procedure Check_Returns
163 Proc
: Entity_Id
:= Empty
);
164 -- Called to check for missing return statements in a function body, or for
165 -- returns present in a procedure body which has No_Return set. HSS is the
166 -- handled statement sequence for the subprogram body. This procedure
167 -- checks all flow paths to make sure they either have return (Mode = 'F',
168 -- used for functions) or do not have a return (Mode = 'P', used for
169 -- No_Return procedures). The flag Err is set if there are any control
170 -- paths not explicitly terminated by a return in the function case, and is
171 -- True otherwise. Proc is the entity for the procedure case and is used
172 -- in posting the warning message.
174 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
);
175 -- In Ada 2012, a primitive equality operator on an untagged record type
176 -- must appear before the type is frozen, and have the same visibility as
177 -- that of the type. This procedure checks that this rule is met, and
178 -- otherwise emits an error on the subprogram declaration and a warning
179 -- on the earlier freeze point if it is easy to locate. In Ada 2012 mode,
180 -- this routine outputs errors (or warnings if -gnatd.E is set). In earlier
181 -- versions of Ada, warnings are output if Warn_On_Ada_2012_Incompatibility
182 -- is set, otherwise the call has no effect.
184 procedure Enter_Overloaded_Entity
(S
: Entity_Id
);
185 -- This procedure makes S, a new overloaded entity, into the first visible
186 -- entity with that name.
188 function Is_Non_Overriding_Operation
190 New_E
: Entity_Id
) return Boolean;
191 -- Enforce the rule given in 12.3(18): a private operation in an instance
192 -- overrides an inherited operation only if the corresponding operation
193 -- was overriding in the generic. This needs to be checked for primitive
194 -- operations of types derived (in the generic unit) from formal private
195 -- or formal derived types.
197 procedure Make_Inequality_Operator
(S
: Entity_Id
);
198 -- Create the declaration for an inequality operator that is implicitly
199 -- created by a user-defined equality operator that yields a boolean.
201 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
);
202 -- Formal_Id is an formal parameter entity. This procedure deals with
203 -- setting the proper validity status for this entity, which depends on
204 -- the kind of parameter and the validity checking mode.
206 ---------------------------------------------
207 -- Analyze_Abstract_Subprogram_Declaration --
208 ---------------------------------------------
210 procedure Analyze_Abstract_Subprogram_Declaration
(N
: Node_Id
) is
211 Designator
: constant Entity_Id
:=
212 Analyze_Subprogram_Specification
(Specification
(N
));
213 Scop
: constant Entity_Id
:= Current_Scope
;
216 Check_SPARK_05_Restriction
("abstract subprogram is not allowed", N
);
218 Generate_Definition
(Designator
);
219 Set_Contract
(Designator
, Make_Contract
(Sloc
(Designator
)));
220 Set_Is_Abstract_Subprogram
(Designator
);
221 New_Overloaded_Entity
(Designator
);
222 Check_Delayed_Subprogram
(Designator
);
224 Set_Categorization_From_Scope
(Designator
, Scop
);
226 -- An abstract subprogram declared within a Ghost scope is automatically
227 -- Ghost (SPARK RM 6.9(2)).
229 if Comes_From_Source
(Designator
) and then Within_Ghost_Scope
then
230 Set_Is_Ghost_Entity
(Designator
);
233 if Ekind
(Scope
(Designator
)) = E_Protected_Type
then
235 ("abstract subprogram not allowed in protected type", N
);
237 -- Issue a warning if the abstract subprogram is neither a dispatching
238 -- operation nor an operation that overrides an inherited subprogram or
239 -- predefined operator, since this most likely indicates a mistake.
241 elsif Warn_On_Redundant_Constructs
242 and then not Is_Dispatching_Operation
(Designator
)
243 and then not Present
(Overridden_Operation
(Designator
))
244 and then (not Is_Operator_Symbol_Name
(Chars
(Designator
))
245 or else Scop
/= Scope
(Etype
(First_Formal
(Designator
))))
248 ("abstract subprogram is not dispatching or overriding?r?", N
);
251 Generate_Reference_To_Formals
(Designator
);
252 Check_Eliminated
(Designator
);
254 if Has_Aspects
(N
) then
255 Analyze_Aspect_Specifications
(N
, Designator
);
257 end Analyze_Abstract_Subprogram_Declaration
;
259 ---------------------------------
260 -- Analyze_Expression_Function --
261 ---------------------------------
263 procedure Analyze_Expression_Function
(N
: Node_Id
) is
264 Loc
: constant Source_Ptr
:= Sloc
(N
);
265 LocX
: constant Source_Ptr
:= Sloc
(Expression
(N
));
266 Expr
: constant Node_Id
:= Expression
(N
);
267 Spec
: constant Node_Id
:= Specification
(N
);
272 -- If the expression is a completion, Prev is the entity whose
273 -- declaration is completed. Def_Id is needed to analyze the spec.
280 -- This is one of the occasions on which we transform the tree during
281 -- semantic analysis. If this is a completion, transform the expression
282 -- function into an equivalent subprogram body, and analyze it.
284 -- Expression functions are inlined unconditionally. The back-end will
285 -- determine whether this is possible.
287 Inline_Processing_Required
:= True;
289 -- Create a specification for the generated body. Types and defauts in
290 -- the profile are copies of the spec, but new entities must be created
291 -- for the unit name and the formals.
293 New_Spec
:= New_Copy_Tree
(Spec
);
294 Set_Defining_Unit_Name
(New_Spec
,
295 Make_Defining_Identifier
(Sloc
(Defining_Unit_Name
(Spec
)),
296 Chars
(Defining_Unit_Name
(Spec
))));
298 if Present
(Parameter_Specifications
(New_Spec
)) then
300 Formal_Spec
: Node_Id
;
304 Formal_Spec
:= First
(Parameter_Specifications
(New_Spec
));
306 -- Create a new formal parameter at the same source position
308 while Present
(Formal_Spec
) loop
309 Def
:= Defining_Identifier
(Formal_Spec
);
310 Set_Defining_Identifier
(Formal_Spec
,
311 Make_Defining_Identifier
(Sloc
(Def
),
312 Chars
=> Chars
(Def
)));
318 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
320 -- If there are previous overloadable entities with the same name,
321 -- check whether any of them is completed by the expression function.
322 -- In a generic context a formal subprogram has no completion.
324 if Present
(Prev
) and then Is_Overloadable
(Prev
)
325 and then not Is_Formal_Subprogram
(Prev
)
327 Def_Id
:= Analyze_Subprogram_Specification
(Spec
);
328 Prev
:= Find_Corresponding_Spec
(N
);
331 Ret
:= Make_Simple_Return_Statement
(LocX
, Expression
(N
));
334 Make_Subprogram_Body
(Loc
,
335 Specification
=> New_Spec
,
336 Declarations
=> Empty_List
,
337 Handled_Statement_Sequence
=>
338 Make_Handled_Sequence_Of_Statements
(LocX
,
339 Statements
=> New_List
(Ret
)));
341 -- If the expression completes a generic subprogram, we must create a
342 -- separate node for the body, because at instantiation the original
343 -- node of the generic copy must be a generic subprogram body, and
344 -- cannot be a expression function. Otherwise we just rewrite the
345 -- expression with the non-generic body.
347 if Present
(Prev
) and then Ekind
(Prev
) = E_Generic_Function
then
348 Insert_After
(N
, New_Body
);
350 -- Propagate any aspects or pragmas that apply to the expression
351 -- function to the proper body when the expression function acts
354 if Has_Aspects
(N
) then
355 Move_Aspects
(N
, To
=> New_Body
);
358 Relocate_Pragmas_To_Body
(New_Body
);
360 Rewrite
(N
, Make_Null_Statement
(Loc
));
361 Set_Has_Completion
(Prev
, False);
364 Set_Is_Inlined
(Prev
);
366 -- If the expression function is a completion, the previous declaration
367 -- must come from source. We know already that appears in the current
368 -- scope. The entity itself may be internally created if within a body
371 elsif Present
(Prev
) and then Comes_From_Source
(Parent
(Prev
))
372 and then not Is_Formal_Subprogram
(Prev
)
374 Set_Has_Completion
(Prev
, False);
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
415 Set_Is_Inlined
(Prev
);
417 -- The formals of the expression function are body formals,
418 -- and do not appear in the ali file, which will only contain
419 -- references to the formals of the original subprogram spec.
426 F1
:= First_Formal
(Def_Id
);
427 F2
:= First_Formal
(Prev
);
429 while Present
(F1
) loop
430 Set_Spec_Entity
(F1
, F2
);
437 Set_Is_Inlined
(Defining_Entity
(New_Body
));
440 -- If this is not a completion, create both a declaration and a body, so
441 -- that the expression can be inlined whenever possible.
444 -- An expression function that is not a completion is not a
445 -- subprogram declaration, and thus cannot appear in a protected
448 if Nkind
(Parent
(N
)) = N_Protected_Definition
then
450 ("an expression function is not a legal protected operation", N
);
453 Rewrite
(N
, Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
));
455 -- Correct the parent pointer of the aspect specification list to
456 -- reference the rewritten node.
458 if Has_Aspects
(N
) then
459 Set_Parent
(Aspect_Specifications
(N
), N
);
464 -- Within a generic pre-analyze the original expression for name
465 -- capture. The body is also generated but plays no role in
466 -- this because it is not part of the original source.
468 if Inside_A_Generic
then
470 Id
: constant Entity_Id
:= Defining_Entity
(N
);
473 Set_Has_Completion
(Id
);
475 Install_Formals
(Id
);
476 Preanalyze_Spec_Expression
(Expr
, Etype
(Id
));
481 Set_Is_Inlined
(Defining_Entity
(N
));
483 -- Establish the linkages between the spec and the body. These are
484 -- used when the expression function acts as the prefix of attribute
485 -- 'Access in order to freeze the original expression which has been
486 -- moved to the generated body.
488 Set_Corresponding_Body
(N
, Defining_Entity
(New_Body
));
489 Set_Corresponding_Spec
(New_Body
, Defining_Entity
(N
));
491 -- To prevent premature freeze action, insert the new body at the end
492 -- of the current declarations, or at the end of the package spec.
493 -- However, resolve usage names now, to prevent spurious visibility
494 -- on later entities. Note that the function can now be called in
495 -- the current declarative part, which will appear to be prior to
496 -- the presence of the body in the code. There are nevertheless no
497 -- order of elaboration issues because all name resolution has taken
498 -- place at the point of declaration.
501 Decls
: List_Id
:= List_Containing
(N
);
502 Par
: constant Node_Id
:= Parent
(Decls
);
503 Id
: constant Entity_Id
:= Defining_Entity
(N
);
506 -- If this is a wrapper created for in an instance for a formal
507 -- subprogram, insert body after declaration, to be analyzed when
508 -- the enclosing instance is analyzed.
511 and then Is_Generic_Actual_Subprogram
(Defining_Entity
(N
))
513 Insert_After
(N
, New_Body
);
516 if Nkind
(Par
) = N_Package_Specification
517 and then Decls
= Visible_Declarations
(Par
)
518 and then Present
(Private_Declarations
(Par
))
519 and then not Is_Empty_List
(Private_Declarations
(Par
))
521 Decls
:= Private_Declarations
(Par
);
524 Insert_After
(Last
(Decls
), New_Body
);
526 Install_Formals
(Id
);
528 -- Preanalyze the expression for name capture, except in an
529 -- instance, where this has been done during generic analysis,
530 -- and will be redone when analyzing the body.
533 Expr
: constant Node_Id
:= Expression
(Ret
);
536 Set_Parent
(Expr
, Ret
);
538 if not In_Instance
then
539 Preanalyze_Spec_Expression
(Expr
, Etype
(Id
));
548 -- If the return expression is a static constant, we suppress warning
549 -- messages on unused formals, which in most cases will be noise.
551 Set_Is_Trivial_Subprogram
(Defining_Entity
(New_Body
),
552 Is_OK_Static_Expression
(Expr
));
553 end Analyze_Expression_Function
;
555 ----------------------------------------
556 -- Analyze_Extended_Return_Statement --
557 ----------------------------------------
559 procedure Analyze_Extended_Return_Statement
(N
: Node_Id
) is
561 Check_Compiler_Unit
("extended return statement", N
);
562 Analyze_Return_Statement
(N
);
563 end Analyze_Extended_Return_Statement
;
565 ----------------------------
566 -- Analyze_Function_Call --
567 ----------------------------
569 procedure Analyze_Function_Call
(N
: Node_Id
) is
570 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
571 Func_Nam
: constant Node_Id
:= Name
(N
);
577 -- A call of the form A.B (X) may be an Ada 2005 call, which is
578 -- rewritten as B (A, X). If the rewriting is successful, the call
579 -- has been analyzed and we just return.
581 if Nkind
(Func_Nam
) = N_Selected_Component
582 and then Name
(N
) /= Func_Nam
583 and then Is_Rewrite_Substitution
(N
)
584 and then Present
(Etype
(N
))
589 -- If error analyzing name, then set Any_Type as result type and return
591 if Etype
(Func_Nam
) = Any_Type
then
592 Set_Etype
(N
, Any_Type
);
596 -- Otherwise analyze the parameters
598 if Present
(Actuals
) then
599 Actual
:= First
(Actuals
);
600 while Present
(Actual
) loop
602 Check_Parameterless_Call
(Actual
);
608 end Analyze_Function_Call
;
610 -----------------------------
611 -- Analyze_Function_Return --
612 -----------------------------
614 procedure Analyze_Function_Return
(N
: Node_Id
) is
615 Loc
: constant Source_Ptr
:= Sloc
(N
);
616 Stm_Entity
: constant Entity_Id
:= Return_Statement_Entity
(N
);
617 Scope_Id
: constant Entity_Id
:= Return_Applies_To
(Stm_Entity
);
619 R_Type
: constant Entity_Id
:= Etype
(Scope_Id
);
620 -- Function result subtype
622 procedure Check_Limited_Return
(Expr
: Node_Id
);
623 -- Check the appropriate (Ada 95 or Ada 2005) rules for returning
624 -- limited types. Used only for simple return statements.
625 -- Expr is the expression returned.
627 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
);
628 -- Check that the return_subtype_indication properly matches the result
629 -- subtype of the function, as required by RM-6.5(5.1/2-5.3/2).
631 --------------------------
632 -- Check_Limited_Return --
633 --------------------------
635 procedure Check_Limited_Return
(Expr
: Node_Id
) is
637 -- Ada 2005 (AI-318-02): Return-by-reference types have been
638 -- removed and replaced by anonymous access results. This is an
639 -- incompatibility with Ada 95. Not clear whether this should be
640 -- enforced yet or perhaps controllable with special switch. ???
642 -- A limited interface that is not immutably limited is OK.
644 if Is_Limited_Interface
(R_Type
)
646 not (Is_Task_Interface
(R_Type
)
647 or else Is_Protected_Interface
(R_Type
)
648 or else Is_Synchronized_Interface
(R_Type
))
652 elsif Is_Limited_Type
(R_Type
)
653 and then not Is_Interface
(R_Type
)
654 and then Comes_From_Source
(N
)
655 and then not In_Instance_Body
656 and then not OK_For_Limited_Init_In_05
(R_Type
, Expr
)
660 if Ada_Version
>= Ada_2005
661 and then not Debug_Flag_Dot_L
662 and then not GNAT_Mode
665 ("(Ada 2005) cannot copy object of a limited type "
666 & "(RM-2005 6.5(5.5/2))", Expr
);
668 if Is_Limited_View
(R_Type
) then
670 ("\return by reference not permitted in Ada 2005", Expr
);
673 -- Warn in Ada 95 mode, to give folks a heads up about this
676 -- In GNAT mode, this is just a warning, to allow it to be
677 -- evilly turned off. Otherwise it is a real error.
679 -- In a generic context, simplify the warning because it makes
680 -- no sense to discuss pass-by-reference or copy.
682 elsif Warn_On_Ada_2005_Compatibility
or GNAT_Mode
then
683 if Inside_A_Generic
then
685 ("return of limited object not permitted in Ada 2005 "
686 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
688 elsif Is_Limited_View
(R_Type
) then
690 ("return by reference not permitted in Ada 2005 "
691 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
694 ("cannot copy object of a limited type in Ada 2005 "
695 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
698 -- Ada 95 mode, compatibility warnings disabled
701 return; -- skip continuation messages below
704 if not Inside_A_Generic
then
706 ("\consider switching to return of access type", Expr
);
707 Explain_Limited_Type
(R_Type
, Expr
);
710 end Check_Limited_Return
;
712 -------------------------------------
713 -- Check_Return_Subtype_Indication --
714 -------------------------------------
716 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
) is
717 Return_Obj
: constant Node_Id
:= Defining_Identifier
(Obj_Decl
);
719 R_Stm_Type
: constant Entity_Id
:= Etype
(Return_Obj
);
720 -- Subtype given in the extended return statement (must match R_Type)
722 Subtype_Ind
: constant Node_Id
:=
723 Object_Definition
(Original_Node
(Obj_Decl
));
725 R_Type_Is_Anon_Access
: constant Boolean :=
727 E_Anonymous_Access_Subprogram_Type
,
728 E_Anonymous_Access_Protected_Subprogram_Type
,
729 E_Anonymous_Access_Type
);
730 -- True if return type of the function is an anonymous access type
731 -- Can't we make Is_Anonymous_Access_Type in einfo ???
733 R_Stm_Type_Is_Anon_Access
: constant Boolean :=
734 Ekind_In
(R_Stm_Type
,
735 E_Anonymous_Access_Subprogram_Type
,
736 E_Anonymous_Access_Protected_Subprogram_Type
,
737 E_Anonymous_Access_Type
);
738 -- True if type of the return object is an anonymous access type
740 procedure Error_No_Match
(N
: Node_Id
);
741 -- Output error messages for case where types do not statically
742 -- match. N is the location for the messages.
748 procedure Error_No_Match
(N
: Node_Id
) is
751 ("subtype must statically match function result subtype", N
);
753 if not Predicates_Match
(R_Stm_Type
, R_Type
) then
754 Error_Msg_Node_2
:= R_Type
;
756 ("\predicate of& does not match predicate of&",
761 -- Start of processing for Check_Return_Subtype_Indication
764 -- First, avoid cascaded errors
766 if Error_Posted
(Obj_Decl
) or else Error_Posted
(Subtype_Ind
) then
770 -- "return access T" case; check that the return statement also has
771 -- "access T", and that the subtypes statically match:
772 -- if this is an access to subprogram the signatures must match.
774 if R_Type_Is_Anon_Access
then
775 if R_Stm_Type_Is_Anon_Access
then
777 Ekind
(Designated_Type
(R_Stm_Type
)) /= E_Subprogram_Type
779 if Base_Type
(Designated_Type
(R_Stm_Type
)) /=
780 Base_Type
(Designated_Type
(R_Type
))
781 or else not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
)
783 Error_No_Match
(Subtype_Mark
(Subtype_Ind
));
787 -- For two anonymous access to subprogram types, the
788 -- types themselves must be type conformant.
790 if not Conforming_Types
791 (R_Stm_Type
, R_Type
, Fully_Conformant
)
793 Error_No_Match
(Subtype_Ind
);
798 Error_Msg_N
("must use anonymous access type", Subtype_Ind
);
801 -- If the return object is of an anonymous access type, then report
802 -- an error if the function's result type is not also anonymous.
804 elsif R_Stm_Type_Is_Anon_Access
805 and then not R_Type_Is_Anon_Access
807 Error_Msg_N
("anonymous access not allowed for function with "
808 & "named access result", Subtype_Ind
);
810 -- Subtype indication case: check that the return object's type is
811 -- covered by the result type, and that the subtypes statically match
812 -- when the result subtype is constrained. Also handle record types
813 -- with unknown discriminants for which we have built the underlying
814 -- record view. Coverage is needed to allow specific-type return
815 -- objects when the result type is class-wide (see AI05-32).
817 elsif Covers
(Base_Type
(R_Type
), Base_Type
(R_Stm_Type
))
818 or else (Is_Underlying_Record_View
(Base_Type
(R_Stm_Type
))
822 Underlying_Record_View
(Base_Type
(R_Stm_Type
))))
824 -- A null exclusion may be present on the return type, on the
825 -- function specification, on the object declaration or on the
828 if Is_Access_Type
(R_Type
)
830 (Can_Never_Be_Null
(R_Type
)
831 or else Null_Exclusion_Present
(Parent
(Scope_Id
))) /=
832 Can_Never_Be_Null
(R_Stm_Type
)
834 Error_No_Match
(Subtype_Ind
);
837 -- AI05-103: for elementary types, subtypes must statically match
839 if Is_Constrained
(R_Type
)
840 or else Is_Access_Type
(R_Type
)
842 if not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
) then
843 Error_No_Match
(Subtype_Ind
);
847 -- All remaining cases are illegal
849 -- Note: previous versions of this subprogram allowed the return
850 -- value to be the ancestor of the return type if the return type
851 -- was a null extension. This was plainly incorrect.
855 ("wrong type for return_subtype_indication", Subtype_Ind
);
857 end Check_Return_Subtype_Indication
;
859 ---------------------
860 -- Local Variables --
861 ---------------------
865 -- Start of processing for Analyze_Function_Return
868 Set_Return_Present
(Scope_Id
);
870 if Nkind
(N
) = N_Simple_Return_Statement
then
871 Expr
:= Expression
(N
);
873 -- Guard against a malformed expression. The parser may have tried to
874 -- recover but the node is not analyzable.
876 if Nkind
(Expr
) = N_Error
then
877 Set_Etype
(Expr
, Any_Type
);
878 Expander_Mode_Save_And_Set
(False);
882 -- The resolution of a controlled [extension] aggregate associated
883 -- with a return statement creates a temporary which needs to be
884 -- finalized on function exit. Wrap the return statement inside a
885 -- block so that the finalization machinery can detect this case.
886 -- This early expansion is done only when the return statement is
887 -- not part of a handled sequence of statements.
889 if Nkind_In
(Expr
, N_Aggregate
,
890 N_Extension_Aggregate
)
891 and then Needs_Finalization
(R_Type
)
892 and then Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
895 Make_Block_Statement
(Loc
,
896 Handled_Statement_Sequence
=>
897 Make_Handled_Sequence_Of_Statements
(Loc
,
898 Statements
=> New_List
(Relocate_Node
(N
)))));
904 Analyze_And_Resolve
(Expr
, R_Type
);
905 Check_Limited_Return
(Expr
);
908 -- RETURN only allowed in SPARK as the last statement in function
910 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
912 (Nkind
(Parent
(Parent
(N
))) /= N_Subprogram_Body
913 or else Present
(Next
(N
)))
915 Check_SPARK_05_Restriction
916 ("RETURN should be the last statement in function", N
);
920 Check_SPARK_05_Restriction
("extended RETURN is not allowed", N
);
922 -- Analyze parts specific to extended_return_statement:
925 Obj_Decl
: constant Node_Id
:=
926 Last
(Return_Object_Declarations
(N
));
927 Has_Aliased
: constant Boolean := Aliased_Present
(Obj_Decl
);
928 HSS
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
931 Expr
:= Expression
(Obj_Decl
);
933 -- Note: The check for OK_For_Limited_Init will happen in
934 -- Analyze_Object_Declaration; we treat it as a normal
935 -- object declaration.
937 Set_Is_Return_Object
(Defining_Identifier
(Obj_Decl
));
940 Check_Return_Subtype_Indication
(Obj_Decl
);
942 if Present
(HSS
) then
945 if Present
(Exception_Handlers
(HSS
)) then
947 -- ???Has_Nested_Block_With_Handler needs to be set.
948 -- Probably by creating an actual N_Block_Statement.
949 -- Probably in Expand.
955 -- Mark the return object as referenced, since the return is an
956 -- implicit reference of the object.
958 Set_Referenced
(Defining_Identifier
(Obj_Decl
));
960 Check_References
(Stm_Entity
);
962 -- Check RM 6.5 (5.9/3)
965 if Ada_Version
< Ada_2012
then
967 -- Shouldn't this test Warn_On_Ada_2012_Compatibility ???
968 -- Can it really happen (extended return???)
971 ("aliased only allowed for limited return objects "
972 & "in Ada 2012??", N
);
974 elsif not Is_Limited_View
(R_Type
) then
976 ("aliased only allowed for limited return objects", N
);
982 -- Case of Expr present
986 -- Defend against previous errors
988 and then Nkind
(Expr
) /= N_Empty
989 and then Present
(Etype
(Expr
))
991 -- Apply constraint check. Note that this is done before the implicit
992 -- conversion of the expression done for anonymous access types to
993 -- ensure correct generation of the null-excluding check associated
994 -- with null-excluding expressions found in return statements.
996 Apply_Constraint_Check
(Expr
, R_Type
);
998 -- Ada 2005 (AI-318-02): When the result type is an anonymous access
999 -- type, apply an implicit conversion of the expression to that type
1000 -- to force appropriate static and run-time accessibility checks.
1002 if Ada_Version
>= Ada_2005
1003 and then Ekind
(R_Type
) = E_Anonymous_Access_Type
1005 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
1006 Analyze_And_Resolve
(Expr
, R_Type
);
1008 -- If this is a local anonymous access to subprogram, the
1009 -- accessibility check can be applied statically. The return is
1010 -- illegal if the access type of the return expression is declared
1011 -- inside of the subprogram (except if it is the subtype indication
1012 -- of an extended return statement).
1014 elsif Ekind
(R_Type
) = E_Anonymous_Access_Subprogram_Type
then
1015 if not Comes_From_Source
(Current_Scope
)
1016 or else Ekind
(Current_Scope
) = E_Return_Statement
1021 Scope_Depth
(Scope
(Etype
(Expr
))) >= Scope_Depth
(Scope_Id
)
1023 Error_Msg_N
("cannot return local access to subprogram", N
);
1026 -- The expression cannot be of a formal incomplete type
1028 elsif Ekind
(Etype
(Expr
)) = E_Incomplete_Type
1029 and then Is_Generic_Type
(Etype
(Expr
))
1032 ("cannot return expression of a formal incomplete type", N
);
1035 -- If the result type is class-wide, then check that the return
1036 -- expression's type is not declared at a deeper level than the
1037 -- function (RM05-6.5(5.6/2)).
1039 if Ada_Version
>= Ada_2005
1040 and then Is_Class_Wide_Type
(R_Type
)
1042 if Type_Access_Level
(Etype
(Expr
)) >
1043 Subprogram_Access_Level
(Scope_Id
)
1046 ("level of return expression type is deeper than "
1047 & "class-wide function!", Expr
);
1051 -- Check incorrect use of dynamically tagged expression
1053 if Is_Tagged_Type
(R_Type
) then
1054 Check_Dynamically_Tagged_Expression
1060 -- ??? A real run-time accessibility check is needed in cases
1061 -- involving dereferences of access parameters. For now we just
1062 -- check the static cases.
1064 if (Ada_Version
< Ada_2005
or else Debug_Flag_Dot_L
)
1065 and then Is_Limited_View
(Etype
(Scope_Id
))
1066 and then Object_Access_Level
(Expr
) >
1067 Subprogram_Access_Level
(Scope_Id
)
1069 -- Suppress the message in a generic, where the rewriting
1072 if Inside_A_Generic
then
1077 Make_Raise_Program_Error
(Loc
,
1078 Reason
=> PE_Accessibility_Check_Failed
));
1081 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1082 Error_Msg_N
("cannot return a local value by reference<<", N
);
1083 Error_Msg_NE
("\& [<<", N
, Standard_Program_Error
);
1087 if Known_Null
(Expr
)
1088 and then Nkind
(Parent
(Scope_Id
)) = N_Function_Specification
1089 and then Null_Exclusion_Present
(Parent
(Scope_Id
))
1091 Apply_Compile_Time_Constraint_Error
1093 Msg
=> "(Ada 2005) null not allowed for "
1094 & "null-excluding return??",
1095 Reason
=> CE_Null_Not_Allowed
);
1098 end Analyze_Function_Return
;
1100 -------------------------------------
1101 -- Analyze_Generic_Subprogram_Body --
1102 -------------------------------------
1104 procedure Analyze_Generic_Subprogram_Body
1108 Gen_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Gen_Id
);
1109 Kind
: constant Entity_Kind
:= Ekind
(Gen_Id
);
1110 Body_Id
: Entity_Id
;
1115 -- Copy body and disable expansion while analyzing the generic For a
1116 -- stub, do not copy the stub (which would load the proper body), this
1117 -- will be done when the proper body is analyzed.
1119 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1120 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
1125 Spec
:= Specification
(N
);
1127 -- Within the body of the generic, the subprogram is callable, and
1128 -- behaves like the corresponding non-generic unit.
1130 Body_Id
:= Defining_Entity
(Spec
);
1132 if Kind
= E_Generic_Procedure
1133 and then Nkind
(Spec
) /= N_Procedure_Specification
1135 Error_Msg_N
("invalid body for generic procedure ", Body_Id
);
1138 elsif Kind
= E_Generic_Function
1139 and then Nkind
(Spec
) /= N_Function_Specification
1141 Error_Msg_N
("invalid body for generic function ", Body_Id
);
1145 Set_Corresponding_Body
(Gen_Decl
, Body_Id
);
1147 if Has_Completion
(Gen_Id
)
1148 and then Nkind
(Parent
(N
)) /= N_Subunit
1150 Error_Msg_N
("duplicate generic body", N
);
1153 Set_Has_Completion
(Gen_Id
);
1156 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1157 Set_Ekind
(Defining_Entity
(Specification
(N
)), Kind
);
1159 Set_Corresponding_Spec
(N
, Gen_Id
);
1162 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1163 Set_Cunit_Entity
(Current_Sem_Unit
, Defining_Entity
(N
));
1166 -- Make generic parameters immediately visible in the body. They are
1167 -- needed to process the formals declarations. Then make the formals
1168 -- visible in a separate step.
1170 Push_Scope
(Gen_Id
);
1174 First_Ent
: Entity_Id
;
1177 First_Ent
:= First_Entity
(Gen_Id
);
1180 while Present
(E
) and then not Is_Formal
(E
) loop
1185 Set_Use
(Generic_Formal_Declarations
(Gen_Decl
));
1187 -- Now generic formals are visible, and the specification can be
1188 -- analyzed, for subsequent conformance check.
1190 Body_Id
:= Analyze_Subprogram_Specification
(Spec
);
1192 -- Make formal parameters visible
1196 -- E is the first formal parameter, we loop through the formals
1197 -- installing them so that they will be visible.
1199 Set_First_Entity
(Gen_Id
, E
);
1200 while Present
(E
) loop
1206 -- Visible generic entity is callable within its own body
1208 Set_Ekind
(Gen_Id
, Ekind
(Body_Id
));
1209 Set_Contract
(Body_Id
, Make_Contract
(Sloc
(Body_Id
)));
1210 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
1211 Set_Convention
(Body_Id
, Convention
(Gen_Id
));
1212 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Gen_Id
));
1213 Set_Scope
(Body_Id
, Scope
(Gen_Id
));
1215 -- Inherit the "ghostness" of the generic spec. Note that this
1216 -- property is not directly inherited as the body may be subject
1217 -- to a different Ghost assertion policy.
1219 if Is_Ghost_Entity
(Gen_Id
) or else Within_Ghost_Scope
then
1220 Set_Is_Ghost_Entity
(Body_Id
);
1222 -- The Ghost policy in effect at the point of declaration and at
1223 -- the point of completion must match (SPARK RM 6.9(15)).
1225 Check_Ghost_Completion
(Gen_Id
, Body_Id
);
1228 Check_Fully_Conformant
(Body_Id
, Gen_Id
, Body_Id
);
1230 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1232 -- No body to analyze, so restore state of generic unit
1234 Set_Ekind
(Gen_Id
, Kind
);
1235 Set_Ekind
(Body_Id
, Kind
);
1237 if Present
(First_Ent
) then
1238 Set_First_Entity
(Gen_Id
, First_Ent
);
1245 -- If this is a compilation unit, it must be made visible explicitly,
1246 -- because the compilation of the declaration, unlike other library
1247 -- unit declarations, does not. If it is not a unit, the following
1248 -- is redundant but harmless.
1250 Set_Is_Immediately_Visible
(Gen_Id
);
1251 Reference_Body_Formals
(Gen_Id
, Body_Id
);
1253 if Is_Child_Unit
(Gen_Id
) then
1254 Generate_Reference
(Gen_Id
, Scope
(Gen_Id
), 'k', False);
1257 Set_Actual_Subtypes
(N
, Current_Scope
);
1259 -- Deal with [refined] preconditions, postconditions, Contract_Cases,
1260 -- invariants and predicates associated with the body and its spec.
1261 -- Note that this is not pure expansion as Expand_Subprogram_Contract
1262 -- prepares the contract assertions for generic subprograms or for
1263 -- ASIS. Do not generate contract checks in SPARK mode.
1265 if not GNATprove_Mode
then
1266 Expand_Subprogram_Contract
(N
, Gen_Id
, Body_Id
);
1269 -- If the generic unit carries pre- or post-conditions, copy them
1270 -- to the original generic tree, so that they are properly added
1271 -- to any instantiation.
1274 Orig
: constant Node_Id
:= Original_Node
(N
);
1278 Cond
:= First
(Declarations
(N
));
1279 while Present
(Cond
) loop
1280 if Nkind
(Cond
) = N_Pragma
1281 and then Pragma_Name
(Cond
) = Name_Check
1283 Prepend
(New_Copy_Tree
(Cond
), Declarations
(Orig
));
1285 elsif Nkind
(Cond
) = N_Pragma
1286 and then Pragma_Name
(Cond
) = Name_Postcondition
1288 Set_Ekind
(Defining_Entity
(Orig
), Ekind
(Gen_Id
));
1289 Prepend
(New_Copy_Tree
(Cond
), Declarations
(Orig
));
1298 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
1299 Set_SPARK_Pragma_Inherited
(Body_Id
, True);
1301 Analyze_Declarations
(Declarations
(N
));
1303 Analyze
(Handled_Statement_Sequence
(N
));
1305 Save_Global_References
(Original_Node
(N
));
1307 -- Prior to exiting the scope, include generic formals again (if any
1308 -- are present) in the set of local entities.
1310 if Present
(First_Ent
) then
1311 Set_First_Entity
(Gen_Id
, First_Ent
);
1314 Check_References
(Gen_Id
);
1317 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Current_Scope
);
1319 Check_Subprogram_Order
(N
);
1321 -- Outside of its body, unit is generic again
1323 Set_Ekind
(Gen_Id
, Kind
);
1324 Generate_Reference
(Gen_Id
, Body_Id
, 'b', Set_Ref
=> False);
1327 Style
.Check_Identifier
(Body_Id
, Gen_Id
);
1331 end Analyze_Generic_Subprogram_Body
;
1333 ----------------------------
1334 -- Analyze_Null_Procedure --
1335 ----------------------------
1337 procedure Analyze_Null_Procedure
1339 Is_Completion
: out Boolean)
1341 Loc
: constant Source_Ptr
:= Sloc
(N
);
1342 Spec
: constant Node_Id
:= Specification
(N
);
1343 Designator
: Entity_Id
;
1345 Null_Body
: Node_Id
:= Empty
;
1349 -- Capture the profile of the null procedure before analysis, for
1350 -- expansion at the freeze point and at each point of call. The body is
1351 -- used if the procedure has preconditions, or if it is a completion. In
1352 -- the first case the body is analyzed at the freeze point, in the other
1353 -- it replaces the null procedure declaration.
1356 Make_Subprogram_Body
(Loc
,
1357 Specification
=> New_Copy_Tree
(Spec
),
1358 Declarations
=> New_List
,
1359 Handled_Statement_Sequence
=>
1360 Make_Handled_Sequence_Of_Statements
(Loc
,
1361 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
1363 -- Create new entities for body and formals
1365 Set_Defining_Unit_Name
(Specification
(Null_Body
),
1366 Make_Defining_Identifier
1367 (Sloc
(Defining_Entity
(N
)),
1368 Chars
(Defining_Entity
(N
))));
1370 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1371 while Present
(Form
) loop
1372 Set_Defining_Identifier
(Form
,
1373 Make_Defining_Identifier
1374 (Sloc
(Defining_Identifier
(Form
)),
1375 Chars
(Defining_Identifier
(Form
))));
1379 -- Determine whether the null procedure may be a completion of a generic
1380 -- suprogram, in which case we use the new null body as the completion
1381 -- and set minimal semantic information on the original declaration,
1382 -- which is rewritten as a null statement.
1384 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
1386 if Present
(Prev
) and then Is_Generic_Subprogram
(Prev
) then
1387 Insert_Before
(N
, Null_Body
);
1388 Set_Ekind
(Defining_Entity
(N
), Ekind
(Prev
));
1389 Set_Contract
(Defining_Entity
(N
), Make_Contract
(Loc
));
1391 Rewrite
(N
, Make_Null_Statement
(Loc
));
1392 Analyze_Generic_Subprogram_Body
(Null_Body
, Prev
);
1393 Is_Completion
:= True;
1397 -- Resolve the types of the formals now, because the freeze point
1398 -- may appear in a different context, e.g. an instantiation.
1400 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1401 while Present
(Form
) loop
1402 if Nkind
(Parameter_Type
(Form
)) /= N_Access_Definition
then
1403 Find_Type
(Parameter_Type
(Form
));
1406 No
(Access_To_Subprogram_Definition
(Parameter_Type
(Form
)))
1408 Find_Type
(Subtype_Mark
(Parameter_Type
(Form
)));
1411 -- The case of a null procedure with a formal that is an
1412 -- access_to_subprogram type, and that is used as an actual
1413 -- in an instantiation is left to the enthusiastic reader.
1422 -- If there are previous overloadable entities with the same name,
1423 -- check whether any of them is completed by the null procedure.
1425 if Present
(Prev
) and then Is_Overloadable
(Prev
) then
1426 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1427 Prev
:= Find_Corresponding_Spec
(N
);
1430 if No
(Prev
) or else not Comes_From_Source
(Prev
) then
1431 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1432 Set_Has_Completion
(Designator
);
1434 -- Signal to caller that this is a procedure declaration
1436 Is_Completion
:= False;
1438 -- Null procedures are always inlined, but generic formal subprograms
1439 -- which appear as such in the internal instance of formal packages,
1440 -- need no completion and are not marked Inline.
1443 and then Nkind
(N
) /= N_Formal_Concrete_Subprogram_Declaration
1445 Set_Corresponding_Body
(N
, Defining_Entity
(Null_Body
));
1446 Set_Body_To_Inline
(N
, Null_Body
);
1447 Set_Is_Inlined
(Designator
);
1451 -- The null procedure is a completion. We unconditionally rewrite
1452 -- this as a null body (even if expansion is not active), because
1453 -- there are various error checks that are applied on this body
1454 -- when it is analyzed (e.g. correct aspect placement).
1456 if Has_Completion
(Prev
) then
1457 Error_Msg_Sloc
:= Sloc
(Prev
);
1458 Error_Msg_NE
("duplicate body for & declared#", N
, Prev
);
1461 Is_Completion
:= True;
1462 Rewrite
(N
, Null_Body
);
1465 end Analyze_Null_Procedure
;
1467 -----------------------------
1468 -- Analyze_Operator_Symbol --
1469 -----------------------------
1471 -- An operator symbol such as "+" or "and" may appear in context where the
1472 -- literal denotes an entity name, such as "+"(x, y) or in context when it
1473 -- is just a string, as in (conjunction = "or"). In these cases the parser
1474 -- generates this node, and the semantics does the disambiguation. Other
1475 -- such case are actuals in an instantiation, the generic unit in an
1476 -- instantiation, and pragma arguments.
1478 procedure Analyze_Operator_Symbol
(N
: Node_Id
) is
1479 Par
: constant Node_Id
:= Parent
(N
);
1482 if (Nkind
(Par
) = N_Function_Call
and then N
= Name
(Par
))
1483 or else Nkind
(Par
) = N_Function_Instantiation
1484 or else (Nkind
(Par
) = N_Indexed_Component
and then N
= Prefix
(Par
))
1485 or else (Nkind
(Par
) = N_Pragma_Argument_Association
1486 and then not Is_Pragma_String_Literal
(Par
))
1487 or else Nkind
(Par
) = N_Subprogram_Renaming_Declaration
1488 or else (Nkind
(Par
) = N_Attribute_Reference
1489 and then Attribute_Name
(Par
) /= Name_Value
)
1491 Find_Direct_Name
(N
);
1494 Change_Operator_Symbol_To_String_Literal
(N
);
1497 end Analyze_Operator_Symbol
;
1499 -----------------------------------
1500 -- Analyze_Parameter_Association --
1501 -----------------------------------
1503 procedure Analyze_Parameter_Association
(N
: Node_Id
) is
1505 Analyze
(Explicit_Actual_Parameter
(N
));
1506 end Analyze_Parameter_Association
;
1508 ----------------------------
1509 -- Analyze_Procedure_Call --
1510 ----------------------------
1512 procedure Analyze_Procedure_Call
(N
: Node_Id
) is
1513 Loc
: constant Source_Ptr
:= Sloc
(N
);
1514 P
: constant Node_Id
:= Name
(N
);
1515 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
1519 procedure Analyze_Call_And_Resolve
;
1520 -- Do Analyze and Resolve calls for procedure call
1521 -- At end, check illegal order dependence.
1523 ------------------------------
1524 -- Analyze_Call_And_Resolve --
1525 ------------------------------
1527 procedure Analyze_Call_And_Resolve
is
1529 if Nkind
(N
) = N_Procedure_Call_Statement
then
1531 Resolve
(N
, Standard_Void_Type
);
1535 end Analyze_Call_And_Resolve
;
1537 -- Start of processing for Analyze_Procedure_Call
1540 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
1541 -- a procedure call or an entry call. The prefix may denote an access
1542 -- to subprogram type, in which case an implicit dereference applies.
1543 -- If the prefix is an indexed component (without implicit dereference)
1544 -- then the construct denotes a call to a member of an entire family.
1545 -- If the prefix is a simple name, it may still denote a call to a
1546 -- parameterless member of an entry family. Resolution of these various
1547 -- interpretations is delicate.
1551 -- If this is a call of the form Obj.Op, the call may have been
1552 -- analyzed and possibly rewritten into a block, in which case
1555 if Analyzed
(N
) then
1559 -- If there is an error analyzing the name (which may have been
1560 -- rewritten if the original call was in prefix notation) then error
1561 -- has been emitted already, mark node and return.
1563 if Error_Posted
(N
) or else Etype
(Name
(N
)) = Any_Type
then
1564 Set_Etype
(N
, Any_Type
);
1568 -- Otherwise analyze the parameters
1570 if Present
(Actuals
) then
1571 Actual
:= First
(Actuals
);
1573 while Present
(Actual
) loop
1575 Check_Parameterless_Call
(Actual
);
1580 -- Special processing for Elab_Spec, Elab_Body and Elab_Subp_Body calls
1582 if Nkind
(P
) = N_Attribute_Reference
1583 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Spec
,
1585 Name_Elab_Subp_Body
)
1587 if Present
(Actuals
) then
1589 ("no parameters allowed for this call", First
(Actuals
));
1593 Set_Etype
(N
, Standard_Void_Type
);
1596 elsif Is_Entity_Name
(P
)
1597 and then Is_Record_Type
(Etype
(Entity
(P
)))
1598 and then Remote_AST_I_Dereference
(P
)
1602 elsif Is_Entity_Name
(P
)
1603 and then Ekind
(Entity
(P
)) /= E_Entry_Family
1605 if Is_Access_Type
(Etype
(P
))
1606 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1607 and then No
(Actuals
)
1608 and then Comes_From_Source
(N
)
1610 Error_Msg_N
("missing explicit dereference in call", N
);
1613 Analyze_Call_And_Resolve
;
1615 -- If the prefix is the simple name of an entry family, this is
1616 -- a parameterless call from within the task body itself.
1618 elsif Is_Entity_Name
(P
)
1619 and then Nkind
(P
) = N_Identifier
1620 and then Ekind
(Entity
(P
)) = E_Entry_Family
1621 and then Present
(Actuals
)
1622 and then No
(Next
(First
(Actuals
)))
1624 -- Can be call to parameterless entry family. What appears to be the
1625 -- sole argument is in fact the entry index. Rewrite prefix of node
1626 -- accordingly. Source representation is unchanged by this
1630 Make_Indexed_Component
(Loc
,
1632 Make_Selected_Component
(Loc
,
1633 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(P
)), Loc
),
1634 Selector_Name
=> New_Occurrence_Of
(Entity
(P
), Loc
)),
1635 Expressions
=> Actuals
);
1636 Set_Name
(N
, New_N
);
1637 Set_Etype
(New_N
, Standard_Void_Type
);
1638 Set_Parameter_Associations
(N
, No_List
);
1639 Analyze_Call_And_Resolve
;
1641 elsif Nkind
(P
) = N_Explicit_Dereference
then
1642 if Ekind
(Etype
(P
)) = E_Subprogram_Type
then
1643 Analyze_Call_And_Resolve
;
1645 Error_Msg_N
("expect access to procedure in call", P
);
1648 -- The name can be a selected component or an indexed component that
1649 -- yields an access to subprogram. Such a prefix is legal if the call
1650 -- has parameter associations.
1652 elsif Is_Access_Type
(Etype
(P
))
1653 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1655 if Present
(Actuals
) then
1656 Analyze_Call_And_Resolve
;
1658 Error_Msg_N
("missing explicit dereference in call ", N
);
1661 -- If not an access to subprogram, then the prefix must resolve to the
1662 -- name of an entry, entry family, or protected operation.
1664 -- For the case of a simple entry call, P is a selected component where
1665 -- the prefix is the task and the selector name is the entry. A call to
1666 -- a protected procedure will have the same syntax. If the protected
1667 -- object contains overloaded operations, the entity may appear as a
1668 -- function, the context will select the operation whose type is Void.
1670 elsif Nkind
(P
) = N_Selected_Component
1671 and then Ekind_In
(Entity
(Selector_Name
(P
)), E_Entry
,
1675 Analyze_Call_And_Resolve
;
1677 elsif Nkind
(P
) = N_Selected_Component
1678 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
1679 and then Present
(Actuals
)
1680 and then No
(Next
(First
(Actuals
)))
1682 -- Can be call to parameterless entry family. What appears to be the
1683 -- sole argument is in fact the entry index. Rewrite prefix of node
1684 -- accordingly. Source representation is unchanged by this
1688 Make_Indexed_Component
(Loc
,
1689 Prefix
=> New_Copy
(P
),
1690 Expressions
=> Actuals
);
1691 Set_Name
(N
, New_N
);
1692 Set_Etype
(New_N
, Standard_Void_Type
);
1693 Set_Parameter_Associations
(N
, No_List
);
1694 Analyze_Call_And_Resolve
;
1696 -- For the case of a reference to an element of an entry family, P is
1697 -- an indexed component whose prefix is a selected component (task and
1698 -- entry family), and whose index is the entry family index.
1700 elsif Nkind
(P
) = N_Indexed_Component
1701 and then Nkind
(Prefix
(P
)) = N_Selected_Component
1702 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) = E_Entry_Family
1704 Analyze_Call_And_Resolve
;
1706 -- If the prefix is the name of an entry family, it is a call from
1707 -- within the task body itself.
1709 elsif Nkind
(P
) = N_Indexed_Component
1710 and then Nkind
(Prefix
(P
)) = N_Identifier
1711 and then Ekind
(Entity
(Prefix
(P
))) = E_Entry_Family
1714 Make_Selected_Component
(Loc
,
1715 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(Prefix
(P
))), Loc
),
1716 Selector_Name
=> New_Occurrence_Of
(Entity
(Prefix
(P
)), Loc
));
1717 Rewrite
(Prefix
(P
), New_N
);
1719 Analyze_Call_And_Resolve
;
1721 -- In Ada 2012. a qualified expression is a name, but it cannot be a
1722 -- procedure name, so the construct can only be a qualified expression.
1724 elsif Nkind
(P
) = N_Qualified_Expression
1725 and then Ada_Version
>= Ada_2012
1727 Rewrite
(N
, Make_Code_Statement
(Loc
, Expression
=> P
));
1730 -- Anything else is an error
1733 Error_Msg_N
("invalid procedure or entry call", N
);
1735 end Analyze_Procedure_Call
;
1737 ------------------------------
1738 -- Analyze_Return_Statement --
1739 ------------------------------
1741 procedure Analyze_Return_Statement
(N
: Node_Id
) is
1743 pragma Assert
(Nkind_In
(N
, N_Simple_Return_Statement
,
1744 N_Extended_Return_Statement
));
1746 Returns_Object
: constant Boolean :=
1747 Nkind
(N
) = N_Extended_Return_Statement
1749 (Nkind
(N
) = N_Simple_Return_Statement
1750 and then Present
(Expression
(N
)));
1751 -- True if we're returning something; that is, "return <expression>;"
1752 -- or "return Result : T [:= ...]". False for "return;". Used for error
1753 -- checking: If Returns_Object is True, N should apply to a function
1754 -- body; otherwise N should apply to a procedure body, entry body,
1755 -- accept statement, or extended return statement.
1757 function Find_What_It_Applies_To
return Entity_Id
;
1758 -- Find the entity representing the innermost enclosing body, accept
1759 -- statement, or extended return statement. If the result is a callable
1760 -- construct or extended return statement, then this will be the value
1761 -- of the Return_Applies_To attribute. Otherwise, the program is
1762 -- illegal. See RM-6.5(4/2).
1764 -----------------------------
1765 -- Find_What_It_Applies_To --
1766 -----------------------------
1768 function Find_What_It_Applies_To
return Entity_Id
is
1769 Result
: Entity_Id
:= Empty
;
1772 -- Loop outward through the Scope_Stack, skipping blocks, loops,
1773 -- and postconditions.
1775 for J
in reverse 0 .. Scope_Stack
.Last
loop
1776 Result
:= Scope_Stack
.Table
(J
).Entity
;
1777 exit when not Ekind_In
(Result
, E_Block
, E_Loop
)
1778 and then Chars
(Result
) /= Name_uPostconditions
;
1781 pragma Assert
(Present
(Result
));
1783 end Find_What_It_Applies_To
;
1785 -- Local declarations
1787 Scope_Id
: constant Entity_Id
:= Find_What_It_Applies_To
;
1788 Kind
: constant Entity_Kind
:= Ekind
(Scope_Id
);
1789 Loc
: constant Source_Ptr
:= Sloc
(N
);
1790 Stm_Entity
: constant Entity_Id
:=
1792 (E_Return_Statement
, Current_Scope
, Loc
, 'R');
1794 -- Start of processing for Analyze_Return_Statement
1797 Set_Return_Statement_Entity
(N
, Stm_Entity
);
1799 Set_Etype
(Stm_Entity
, Standard_Void_Type
);
1800 Set_Return_Applies_To
(Stm_Entity
, Scope_Id
);
1802 -- Place Return entity on scope stack, to simplify enforcement of 6.5
1803 -- (4/2): an inner return statement will apply to this extended return.
1805 if Nkind
(N
) = N_Extended_Return_Statement
then
1806 Push_Scope
(Stm_Entity
);
1809 -- Check that pragma No_Return is obeyed. Don't complain about the
1810 -- implicitly-generated return that is placed at the end.
1812 if No_Return
(Scope_Id
) and then Comes_From_Source
(N
) then
1813 Error_Msg_N
("RETURN statement not allowed (No_Return)", N
);
1816 -- Warn on any unassigned OUT parameters if in procedure
1818 if Ekind
(Scope_Id
) = E_Procedure
then
1819 Warn_On_Unassigned_Out_Parameter
(N
, Scope_Id
);
1822 -- Check that functions return objects, and other things do not
1824 if Kind
= E_Function
or else Kind
= E_Generic_Function
then
1825 if not Returns_Object
then
1826 Error_Msg_N
("missing expression in return from function", N
);
1829 elsif Kind
= E_Procedure
or else Kind
= E_Generic_Procedure
then
1830 if Returns_Object
then
1831 Error_Msg_N
("procedure cannot return value (use function)", N
);
1834 elsif Kind
= E_Entry
or else Kind
= E_Entry_Family
then
1835 if Returns_Object
then
1836 if Is_Protected_Type
(Scope
(Scope_Id
)) then
1837 Error_Msg_N
("entry body cannot return value", N
);
1839 Error_Msg_N
("accept statement cannot return value", N
);
1843 elsif Kind
= E_Return_Statement
then
1845 -- We are nested within another return statement, which must be an
1846 -- extended_return_statement.
1848 if Returns_Object
then
1849 if Nkind
(N
) = N_Extended_Return_Statement
then
1851 ("extended return statement cannot be nested (use `RETURN;`)",
1854 -- Case of a simple return statement with a value inside extended
1855 -- return statement.
1859 ("return nested in extended return statement cannot return "
1860 & "value (use `RETURN;`)", N
);
1865 Error_Msg_N
("illegal context for return statement", N
);
1868 if Ekind_In
(Kind
, E_Function
, E_Generic_Function
) then
1869 Analyze_Function_Return
(N
);
1871 elsif Ekind_In
(Kind
, E_Procedure
, E_Generic_Procedure
) then
1872 Set_Return_Present
(Scope_Id
);
1875 if Nkind
(N
) = N_Extended_Return_Statement
then
1879 Kill_Current_Values
(Last_Assignment_Only
=> True);
1880 Check_Unreachable_Code
(N
);
1882 Analyze_Dimension
(N
);
1883 end Analyze_Return_Statement
;
1885 -------------------------------------
1886 -- Analyze_Simple_Return_Statement --
1887 -------------------------------------
1889 procedure Analyze_Simple_Return_Statement
(N
: Node_Id
) is
1891 if Present
(Expression
(N
)) then
1892 Mark_Coextensions
(N
, Expression
(N
));
1895 Analyze_Return_Statement
(N
);
1896 end Analyze_Simple_Return_Statement
;
1898 -------------------------
1899 -- Analyze_Return_Type --
1900 -------------------------
1902 procedure Analyze_Return_Type
(N
: Node_Id
) is
1903 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
1904 Typ
: Entity_Id
:= Empty
;
1907 -- Normal case where result definition does not indicate an error
1909 if Result_Definition
(N
) /= Error
then
1910 if Nkind
(Result_Definition
(N
)) = N_Access_Definition
then
1911 Check_SPARK_05_Restriction
1912 ("access result is not allowed", Result_Definition
(N
));
1914 -- Ada 2005 (AI-254): Handle anonymous access to subprograms
1917 AD
: constant Node_Id
:=
1918 Access_To_Subprogram_Definition
(Result_Definition
(N
));
1920 if Present
(AD
) and then Protected_Present
(AD
) then
1921 Typ
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
1923 Typ
:= Access_Definition
(N
, Result_Definition
(N
));
1927 Set_Parent
(Typ
, Result_Definition
(N
));
1928 Set_Is_Local_Anonymous_Access
(Typ
);
1929 Set_Etype
(Designator
, Typ
);
1931 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1933 Null_Exclusion_Static_Checks
(N
);
1935 -- Subtype_Mark case
1938 Find_Type
(Result_Definition
(N
));
1939 Typ
:= Entity
(Result_Definition
(N
));
1940 Set_Etype
(Designator
, Typ
);
1942 -- Unconstrained array as result is not allowed in SPARK
1944 if Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
1945 Check_SPARK_05_Restriction
1946 ("returning an unconstrained array is not allowed",
1947 Result_Definition
(N
));
1950 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1952 Null_Exclusion_Static_Checks
(N
);
1954 -- If a null exclusion is imposed on the result type, then create
1955 -- a null-excluding itype (an access subtype) and use it as the
1956 -- function's Etype. Note that the null exclusion checks are done
1957 -- right before this, because they don't get applied to types that
1958 -- do not come from source.
1960 if Is_Access_Type
(Typ
) and then Null_Exclusion_Present
(N
) then
1961 Set_Etype
(Designator
,
1962 Create_Null_Excluding_Itype
1965 Scope_Id
=> Scope
(Current_Scope
)));
1967 -- The new subtype must be elaborated before use because
1968 -- it is visible outside of the function. However its base
1969 -- type may not be frozen yet, so the reference that will
1970 -- force elaboration must be attached to the freezing of
1973 -- If the return specification appears on a proper body,
1974 -- the subtype will have been created already on the spec.
1976 if Is_Frozen
(Typ
) then
1977 if Nkind
(Parent
(N
)) = N_Subprogram_Body
1978 and then Nkind
(Parent
(Parent
(N
))) = N_Subunit
1982 Build_Itype_Reference
(Etype
(Designator
), Parent
(N
));
1986 Ensure_Freeze_Node
(Typ
);
1989 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(N
));
1991 Set_Itype
(IR
, Etype
(Designator
));
1992 Append_Freeze_Actions
(Typ
, New_List
(IR
));
1997 Set_Etype
(Designator
, Typ
);
2000 if Ekind
(Typ
) = E_Incomplete_Type
2001 and then Is_Value_Type
(Typ
)
2005 elsif Ekind
(Typ
) = E_Incomplete_Type
2006 or else (Is_Class_Wide_Type
(Typ
)
2007 and then Ekind
(Root_Type
(Typ
)) = E_Incomplete_Type
)
2009 -- AI05-0151: Tagged incomplete types are allowed in all formal
2010 -- parts. Untagged incomplete types are not allowed in bodies.
2011 -- As a consequence, limited views cannot appear in a basic
2012 -- declaration that is itself within a body, because there is
2013 -- no point at which the non-limited view will become visible.
2015 if Ada_Version
>= Ada_2012
then
2016 if From_Limited_With
(Typ
) and then In_Package_Body
then
2018 ("invalid use of incomplete type&",
2019 Result_Definition
(N
), Typ
);
2021 -- The return type of a subprogram body cannot be of a
2022 -- formal incomplete type.
2024 elsif Is_Generic_Type
(Typ
)
2025 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
2028 ("return type cannot be a formal incomplete type",
2029 Result_Definition
(N
));
2031 elsif Is_Class_Wide_Type
(Typ
)
2032 and then Is_Generic_Type
(Root_Type
(Typ
))
2033 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
2036 ("return type cannot be a formal incomplete type",
2037 Result_Definition
(N
));
2039 elsif Is_Tagged_Type
(Typ
) then
2042 elsif Nkind
(Parent
(N
)) = N_Subprogram_Body
2043 or else Nkind_In
(Parent
(Parent
(N
)), N_Accept_Statement
,
2047 ("invalid use of untagged incomplete type&",
2051 -- The type must be completed in the current package. This
2052 -- is checked at the end of the package declaration when
2053 -- Taft-amendment types are identified. If the return type
2054 -- is class-wide, there is no required check, the type can
2055 -- be a bona fide TAT.
2057 if Ekind
(Scope
(Current_Scope
)) = E_Package
2058 and then In_Private_Part
(Scope
(Current_Scope
))
2059 and then not Is_Class_Wide_Type
(Typ
)
2061 Append_Elmt
(Designator
, Private_Dependents
(Typ
));
2066 ("invalid use of incomplete type&", Designator
, Typ
);
2071 -- Case where result definition does indicate an error
2074 Set_Etype
(Designator
, Any_Type
);
2076 end Analyze_Return_Type
;
2078 -----------------------------
2079 -- Analyze_Subprogram_Body --
2080 -----------------------------
2082 procedure Analyze_Subprogram_Body
(N
: Node_Id
) is
2083 Loc
: constant Source_Ptr
:= Sloc
(N
);
2084 Body_Spec
: constant Node_Id
:= Specification
(N
);
2085 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Spec
);
2088 if Debug_Flag_C
then
2089 Write_Str
("==> subprogram body ");
2090 Write_Name
(Chars
(Body_Id
));
2091 Write_Str
(" from ");
2092 Write_Location
(Loc
);
2097 Trace_Scope
(N
, Body_Id
, " Analyze subprogram: ");
2099 -- The real work is split out into the helper, so it can do "return;"
2100 -- without skipping the debug output:
2102 Analyze_Subprogram_Body_Helper
(N
);
2104 if Debug_Flag_C
then
2106 Write_Str
("<== subprogram body ");
2107 Write_Name
(Chars
(Body_Id
));
2108 Write_Str
(" from ");
2109 Write_Location
(Loc
);
2112 end Analyze_Subprogram_Body
;
2114 --------------------------------------
2115 -- Analyze_Subprogram_Body_Contract --
2116 --------------------------------------
2118 procedure Analyze_Subprogram_Body_Contract
(Body_Id
: Entity_Id
) is
2119 Body_Decl
: constant Node_Id
:= Parent
(Parent
(Body_Id
));
2120 Mode
: SPARK_Mode_Type
;
2122 Ref_Depends
: Node_Id
:= Empty
;
2123 Ref_Global
: Node_Id
:= Empty
;
2124 Spec_Id
: Entity_Id
;
2127 -- Due to the timing of contract analysis, delayed pragmas may be
2128 -- subject to the wrong SPARK_Mode, usually that of the enclosing
2129 -- context. To remedy this, restore the original SPARK_Mode of the
2130 -- related subprogram body.
2132 Save_SPARK_Mode_And_Set
(Body_Id
, Mode
);
2134 -- When a subprogram body declaration is illegal, its defining entity is
2135 -- left unanalyzed. There is nothing left to do in this case because the
2136 -- body lacks a contract, or even a proper Ekind.
2138 if Ekind
(Body_Id
) = E_Void
then
2142 if Nkind
(Body_Decl
) = N_Subprogram_Body_Stub
then
2143 Spec_Id
:= Corresponding_Spec_Of_Stub
(Body_Decl
);
2145 Spec_Id
:= Corresponding_Spec
(Body_Decl
);
2148 -- Locate and store pragmas Refined_Depends and Refined_Global since
2149 -- their order of analysis matters.
2151 Prag
:= Classifications
(Contract
(Body_Id
));
2152 while Present
(Prag
) loop
2153 if Pragma_Name
(Prag
) = Name_Refined_Depends
then
2154 Ref_Depends
:= Prag
;
2155 elsif Pragma_Name
(Prag
) = Name_Refined_Global
then
2159 Prag
:= Next_Pragma
(Prag
);
2162 -- Analyze Refined_Global first as Refined_Depends may mention items
2163 -- classified in the global refinement.
2165 if Present
(Ref_Global
) then
2166 Analyze_Refined_Global_In_Decl_Part
(Ref_Global
);
2168 -- When the corresponding Global aspect/pragma references a state with
2169 -- visible refinement, the body requires Refined_Global. Refinement is
2170 -- not required when SPARK checks are suppressed.
2172 elsif Present
(Spec_Id
) then
2173 Prag
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
2175 if SPARK_Mode
/= Off
2176 and then Present
(Prag
)
2177 and then Contains_Refined_State
(Prag
)
2180 ("body of subprogram& requires global refinement",
2181 Body_Decl
, Spec_Id
);
2185 -- Refined_Depends must be analyzed after Refined_Global in order to see
2186 -- the modes of all global refinements.
2188 if Present
(Ref_Depends
) then
2189 Analyze_Refined_Depends_In_Decl_Part
(Ref_Depends
);
2191 -- When the corresponding Depends aspect/pragma references a state with
2192 -- visible refinement, the body requires Refined_Depends. Refinement is
2193 -- not required when SPARK checks are suppressed.
2195 elsif Present
(Spec_Id
) then
2196 Prag
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
2198 if SPARK_Mode
/= Off
2199 and then Present
(Prag
)
2200 and then Contains_Refined_State
(Prag
)
2203 ("body of subprogram& requires dependance refinement",
2204 Body_Decl
, Spec_Id
);
2208 -- Restore the SPARK_Mode of the enclosing context after all delayed
2209 -- pragmas have been analyzed.
2211 Restore_SPARK_Mode
(Mode
);
2212 end Analyze_Subprogram_Body_Contract
;
2214 ------------------------------------
2215 -- Analyze_Subprogram_Body_Helper --
2216 ------------------------------------
2218 -- This procedure is called for regular subprogram bodies, generic bodies,
2219 -- and for subprogram stubs of both kinds. In the case of stubs, only the
2220 -- specification matters, and is used to create a proper declaration for
2221 -- the subprogram, or to perform conformance checks.
2223 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
) is
2224 Loc
: constant Source_Ptr
:= Sloc
(N
);
2225 Body_Spec
: constant Node_Id
:= Specification
(N
);
2226 Body_Id
: Entity_Id
:= Defining_Entity
(Body_Spec
);
2227 Prev_Id
: constant Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
2228 Conformant
: Boolean;
2230 Prot_Typ
: Entity_Id
:= Empty
;
2231 Spec_Id
: Entity_Id
;
2232 Spec_Decl
: Node_Id
:= Empty
;
2234 Last_Real_Spec_Entity
: Entity_Id
:= Empty
;
2235 -- When we analyze a separate spec, the entity chain ends up containing
2236 -- the formals, as well as any itypes generated during analysis of the
2237 -- default expressions for parameters, or the arguments of associated
2238 -- precondition/postcondition pragmas (which are analyzed in the context
2239 -- of the spec since they have visibility on formals).
2241 -- These entities belong with the spec and not the body. However we do
2242 -- the analysis of the body in the context of the spec (again to obtain
2243 -- visibility to the formals), and all the entities generated during
2244 -- this analysis end up also chained to the entity chain of the spec.
2245 -- But they really belong to the body, and there is circuitry to move
2246 -- them from the spec to the body.
2248 -- However, when we do this move, we don't want to move the real spec
2249 -- entities (first para above) to the body. The Last_Real_Spec_Entity
2250 -- variable points to the last real spec entity, so we only move those
2251 -- chained beyond that point. It is initialized to Empty to deal with
2252 -- the case where there is no separate spec.
2254 procedure Analyze_Aspects_On_Body_Or_Stub
;
2255 -- Analyze the aspect specifications of a subprogram body [stub]. It is
2256 -- assumed that N has aspects.
2258 function Body_Has_Contract
return Boolean;
2259 -- Check whether unanalyzed body has an aspect or pragma that may
2260 -- generate a SPARK contract.
2262 procedure Check_Anonymous_Return
;
2263 -- Ada 2005: if a function returns an access type that denotes a task,
2264 -- or a type that contains tasks, we must create a master entity for
2265 -- the anonymous type, which typically will be used in an allocator
2266 -- in the body of the function.
2268 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
);
2269 -- Look ahead to recognize a pragma that may appear after the body.
2270 -- If there is a previous spec, check that it appears in the same
2271 -- declarative part. If the pragma is Inline_Always, perform inlining
2272 -- unconditionally, otherwise only if Front_End_Inlining is requested.
2273 -- If the body acts as a spec, and inlining is required, we create a
2274 -- subprogram declaration for it, in order to attach the body to inline.
2275 -- If pragma does not appear after the body, check whether there is
2276 -- an inline pragma before any local declarations.
2278 procedure Check_Missing_Return
;
2279 -- Checks for a function with a no return statements, and also performs
2280 -- the warning checks implemented by Check_Returns. In formal mode, also
2281 -- verify that a function ends with a RETURN and that a procedure does
2282 -- not contain any RETURN.
2284 function Disambiguate_Spec
return Entity_Id
;
2285 -- When a primitive is declared between the private view and the full
2286 -- view of a concurrent type which implements an interface, a special
2287 -- mechanism is used to find the corresponding spec of the primitive
2290 procedure Exchange_Limited_Views
(Subp_Id
: Entity_Id
);
2291 -- Ada 2012 (AI05-0151): Detect whether the profile of Subp_Id contains
2292 -- incomplete types coming from a limited context and swap their limited
2293 -- views with the non-limited ones.
2295 function Is_Private_Concurrent_Primitive
2296 (Subp_Id
: Entity_Id
) return Boolean;
2297 -- Determine whether subprogram Subp_Id is a primitive of a concurrent
2298 -- type that implements an interface and has a private view.
2300 procedure Set_Trivial_Subprogram
(N
: Node_Id
);
2301 -- Sets the Is_Trivial_Subprogram flag in both spec and body of the
2302 -- subprogram whose body is being analyzed. N is the statement node
2303 -- causing the flag to be set, if the following statement is a return
2304 -- of an entity, we mark the entity as set in source to suppress any
2305 -- warning on the stylized use of function stubs with a dummy return.
2307 procedure Verify_Overriding_Indicator
;
2308 -- If there was a previous spec, the entity has been entered in the
2309 -- current scope previously. If the body itself carries an overriding
2310 -- indicator, check that it is consistent with the known status of the
2313 -------------------------------------
2314 -- Analyze_Aspects_On_Body_Or_Stub --
2315 -------------------------------------
2317 procedure Analyze_Aspects_On_Body_Or_Stub
is
2318 procedure Diagnose_Misplaced_Aspects
;
2319 -- Subprogram body [stub] N has aspects, but they are not properly
2320 -- placed. Provide precise diagnostics depending on the aspects
2323 --------------------------------
2324 -- Diagnose_Misplaced_Aspects --
2325 --------------------------------
2327 procedure Diagnose_Misplaced_Aspects
is
2331 -- The current aspect along with its name and id
2333 procedure SPARK_Aspect_Error
(Ref_Nam
: Name_Id
);
2334 -- Emit an error message concerning SPARK aspect Asp. Ref_Nam is
2335 -- the name of the refined version of the aspect.
2337 ------------------------
2338 -- SPARK_Aspect_Error --
2339 ------------------------
2341 procedure SPARK_Aspect_Error
(Ref_Nam
: Name_Id
) is
2343 -- The corresponding spec already contains the aspect in
2344 -- question and the one appearing on the body must be the
2347 -- procedure P with Global ...;
2348 -- procedure P with Global ... is ... end P;
2352 if Has_Aspect
(Spec_Id
, Asp_Id
) then
2353 Error_Msg_Name_1
:= Asp_Nam
;
2355 -- Subunits cannot carry aspects that apply to a subprogram
2358 if Nkind
(Parent
(N
)) = N_Subunit
then
2359 Error_Msg_N
("aspect % cannot apply to a subunit", Asp
);
2362 Error_Msg_Name_2
:= Ref_Nam
;
2363 Error_Msg_N
("aspect % should be %", Asp
);
2366 -- Otherwise the aspect must appear in the spec, not in the
2370 -- procedure P with Global ... is ... end P;
2374 ("aspect specification must appear in subprogram "
2375 & "declaration", Asp
);
2377 end SPARK_Aspect_Error
;
2379 -- Start of processing for Diagnose_Misplaced_Aspects
2382 -- Iterate over the aspect specifications and emit specific errors
2383 -- where applicable.
2385 Asp
:= First
(Aspect_Specifications
(N
));
2386 while Present
(Asp
) loop
2387 Asp_Nam
:= Chars
(Identifier
(Asp
));
2388 Asp_Id
:= Get_Aspect_Id
(Asp_Nam
);
2390 -- Do not emit errors on aspects that can appear on a
2391 -- subprogram body. This scenario occurs when the aspect
2392 -- specification list contains both misplaced and properly
2395 if Aspect_On_Body_Or_Stub_OK
(Asp_Id
) then
2398 -- Special diagnostics for SPARK aspects
2400 elsif Asp_Nam
= Name_Depends
then
2401 SPARK_Aspect_Error
(Name_Refined_Depends
);
2403 elsif Asp_Nam
= Name_Global
then
2404 SPARK_Aspect_Error
(Name_Refined_Global
);
2406 elsif Asp_Nam
= Name_Post
then
2407 SPARK_Aspect_Error
(Name_Refined_Post
);
2411 ("aspect specification must appear in subprogram "
2412 & "declaration", Asp
);
2417 end Diagnose_Misplaced_Aspects
;
2419 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
2422 -- Language-defined aspects cannot be associated with a subprogram
2423 -- body [stub] if the subprogram has a spec. Certain implementation
2424 -- defined aspects are allowed to break this rule (for list, see
2425 -- table Aspect_On_Body_Or_Stub_OK).
2427 if Present
(Spec_Id
) and then not Aspects_On_Body_Or_Stub_OK
(N
) then
2428 Diagnose_Misplaced_Aspects
;
2430 Analyze_Aspect_Specifications
(N
, Body_Id
);
2432 end Analyze_Aspects_On_Body_Or_Stub
;
2434 -----------------------
2435 -- Body_Has_Contract --
2436 -----------------------
2438 function Body_Has_Contract
return Boolean is
2439 Decls
: constant List_Id
:= Declarations
(N
);
2446 -- Check for unanalyzed aspects in the body that will
2447 -- generate a contract.
2449 if Present
(Aspect_Specifications
(N
)) then
2450 A_Spec
:= First
(Aspect_Specifications
(N
));
2451 while Present
(A_Spec
) loop
2452 A
:= Get_Aspect_Id
(Chars
(Identifier
(A_Spec
)));
2454 if A
= Aspect_Contract_Cases
or else
2455 A
= Aspect_Depends
or else
2456 A
= Aspect_Global
or else
2457 A
= Aspect_Pre
or else
2458 A
= Aspect_Precondition
or else
2459 A
= Aspect_Post
or else
2460 A
= Aspect_Postcondition
2469 -- Check for pragmas that may generate a contract
2471 if Present
(Decls
) then
2472 Decl
:= First
(Decls
);
2473 while Present
(Decl
) loop
2474 if Nkind
(Decl
) = N_Pragma
then
2475 P_Id
:= Get_Pragma_Id
(Pragma_Name
(Decl
));
2477 if P_Id
= Pragma_Contract_Cases
or else
2478 P_Id
= Pragma_Depends
or else
2479 P_Id
= Pragma_Global
or else
2480 P_Id
= Pragma_Pre
or else
2481 P_Id
= Pragma_Precondition
or else
2482 P_Id
= Pragma_Post
or else
2483 P_Id
= Pragma_Postcondition
2494 end Body_Has_Contract
;
2496 ----------------------------
2497 -- Check_Anonymous_Return --
2498 ----------------------------
2500 procedure Check_Anonymous_Return
is
2506 if Present
(Spec_Id
) then
2512 if Ekind
(Scop
) = E_Function
2513 and then Ekind
(Etype
(Scop
)) = E_Anonymous_Access_Type
2514 and then not Is_Thunk
(Scop
)
2515 and then (Has_Task
(Designated_Type
(Etype
(Scop
)))
2517 (Is_Class_Wide_Type
(Designated_Type
(Etype
(Scop
)))
2519 Is_Limited_Record
(Designated_Type
(Etype
(Scop
)))))
2520 and then Expander_Active
2522 -- Avoid cases with no tasking support
2524 and then RTE_Available
(RE_Current_Master
)
2525 and then not Restriction_Active
(No_Task_Hierarchy
)
2528 Make_Object_Declaration
(Loc
,
2529 Defining_Identifier
=>
2530 Make_Defining_Identifier
(Loc
, Name_uMaster
),
2531 Constant_Present
=> True,
2532 Object_Definition
=>
2533 New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
2535 Make_Explicit_Dereference
(Loc
,
2536 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
2538 if Present
(Declarations
(N
)) then
2539 Prepend
(Decl
, Declarations
(N
));
2541 Set_Declarations
(N
, New_List
(Decl
));
2544 Set_Master_Id
(Etype
(Scop
), Defining_Identifier
(Decl
));
2545 Set_Has_Master_Entity
(Scop
);
2547 -- Now mark the containing scope as a task master
2550 while Nkind
(Par
) /= N_Compilation_Unit
loop
2551 Par
:= Parent
(Par
);
2552 pragma Assert
(Present
(Par
));
2554 -- If we fall off the top, we are at the outer level, and
2555 -- the environment task is our effective master, so nothing
2559 (Par
, N_Task_Body
, N_Block_Statement
, N_Subprogram_Body
)
2561 Set_Is_Task_Master
(Par
, True);
2566 end Check_Anonymous_Return
;
2568 -------------------------
2569 -- Check_Inline_Pragma --
2570 -------------------------
2572 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
) is
2576 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean;
2577 -- True when N is a pragma Inline or Inline_Always that applies
2578 -- to this subprogram.
2580 -----------------------
2581 -- Is_Inline_Pragma --
2582 -----------------------
2584 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean is
2587 Nkind
(N
) = N_Pragma
2589 (Pragma_Name
(N
) = Name_Inline_Always
2592 and then Pragma_Name
(N
) = Name_Inline
))
2595 (Expression
(First
(Pragma_Argument_Associations
(N
)))) =
2597 end Is_Inline_Pragma
;
2599 -- Start of processing for Check_Inline_Pragma
2602 if not Expander_Active
then
2606 if Is_List_Member
(N
)
2607 and then Present
(Next
(N
))
2608 and then Is_Inline_Pragma
(Next
(N
))
2612 elsif Nkind
(N
) /= N_Subprogram_Body_Stub
2613 and then Present
(Declarations
(N
))
2614 and then Is_Inline_Pragma
(First
(Declarations
(N
)))
2616 Prag
:= First
(Declarations
(N
));
2622 if Present
(Prag
) then
2623 if Present
(Spec_Id
) then
2624 if In_Same_List
(N
, Unit_Declaration_Node
(Spec_Id
)) then
2629 -- Create a subprogram declaration, to make treatment uniform
2632 Subp
: constant Entity_Id
:=
2633 Make_Defining_Identifier
(Loc
, Chars
(Body_Id
));
2634 Decl
: constant Node_Id
:=
2635 Make_Subprogram_Declaration
(Loc
,
2637 New_Copy_Tree
(Specification
(N
)));
2640 Set_Defining_Unit_Name
(Specification
(Decl
), Subp
);
2642 if Present
(First_Formal
(Body_Id
)) then
2643 Plist
:= Copy_Parameter_List
(Body_Id
);
2644 Set_Parameter_Specifications
2645 (Specification
(Decl
), Plist
);
2648 Insert_Before
(N
, Decl
);
2651 Set_Has_Pragma_Inline
(Subp
);
2653 if Pragma_Name
(Prag
) = Name_Inline_Always
then
2654 Set_Is_Inlined
(Subp
);
2655 Set_Has_Pragma_Inline_Always
(Subp
);
2658 -- Prior to copying the subprogram body to create a template
2659 -- for it for subsequent inlining, remove the pragma from
2660 -- the current body so that the copy that will produce the
2661 -- new body will start from a completely unanalyzed tree.
2663 if Nkind
(Parent
(Prag
)) = N_Subprogram_Body
then
2664 Rewrite
(Prag
, Make_Null_Statement
(Sloc
(Prag
)));
2671 end Check_Inline_Pragma
;
2673 --------------------------
2674 -- Check_Missing_Return --
2675 --------------------------
2677 procedure Check_Missing_Return
is
2679 Missing_Ret
: Boolean;
2682 if Nkind
(Body_Spec
) = N_Function_Specification
then
2683 if Present
(Spec_Id
) then
2689 if Return_Present
(Id
) then
2690 Check_Returns
(HSS
, 'F', Missing_Ret
);
2693 Set_Has_Missing_Return
(Id
);
2696 elsif Is_Generic_Subprogram
(Id
)
2697 or else not Is_Machine_Code_Subprogram
(Id
)
2699 Error_Msg_N
("missing RETURN statement in function body", N
);
2702 -- If procedure with No_Return, check returns
2704 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
2705 and then Present
(Spec_Id
)
2706 and then No_Return
(Spec_Id
)
2708 Check_Returns
(HSS
, 'P', Missing_Ret
, Spec_Id
);
2711 -- Special checks in SPARK mode
2713 if Nkind
(Body_Spec
) = N_Function_Specification
then
2715 -- In SPARK mode, last statement of a function should be a return
2718 Stat
: constant Node_Id
:= Last_Source_Statement
(HSS
);
2721 and then not Nkind_In
(Stat
, N_Simple_Return_Statement
,
2722 N_Extended_Return_Statement
)
2724 Check_SPARK_05_Restriction
2725 ("last statement in function should be RETURN", Stat
);
2729 -- In SPARK mode, verify that a procedure has no return
2731 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
then
2732 if Present
(Spec_Id
) then
2738 -- Would be nice to point to return statement here, can we
2739 -- borrow the Check_Returns procedure here ???
2741 if Return_Present
(Id
) then
2742 Check_SPARK_05_Restriction
2743 ("procedure should not have RETURN", N
);
2746 end Check_Missing_Return
;
2748 -----------------------
2749 -- Disambiguate_Spec --
2750 -----------------------
2752 function Disambiguate_Spec
return Entity_Id
is
2753 Priv_Spec
: Entity_Id
;
2756 procedure Replace_Types
(To_Corresponding
: Boolean);
2757 -- Depending on the flag, replace the type of formal parameters of
2758 -- Body_Id if it is a concurrent type implementing interfaces with
2759 -- the corresponding record type or the other way around.
2761 procedure Replace_Types
(To_Corresponding
: Boolean) is
2763 Formal_Typ
: Entity_Id
;
2766 Formal
:= First_Formal
(Body_Id
);
2767 while Present
(Formal
) loop
2768 Formal_Typ
:= Etype
(Formal
);
2770 if Is_Class_Wide_Type
(Formal_Typ
) then
2771 Formal_Typ
:= Root_Type
(Formal_Typ
);
2774 -- From concurrent type to corresponding record
2776 if To_Corresponding
then
2777 if Is_Concurrent_Type
(Formal_Typ
)
2778 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
2779 and then Present
(Interfaces
(
2780 Corresponding_Record_Type
(Formal_Typ
)))
2783 Corresponding_Record_Type
(Formal_Typ
));
2786 -- From corresponding record to concurrent type
2789 if Is_Concurrent_Record_Type
(Formal_Typ
)
2790 and then Present
(Interfaces
(Formal_Typ
))
2793 Corresponding_Concurrent_Type
(Formal_Typ
));
2797 Next_Formal
(Formal
);
2801 -- Start of processing for Disambiguate_Spec
2804 -- Try to retrieve the specification of the body as is. All error
2805 -- messages are suppressed because the body may not have a spec in
2806 -- its current state.
2808 Spec_N
:= Find_Corresponding_Spec
(N
, False);
2810 -- It is possible that this is the body of a primitive declared
2811 -- between a private and a full view of a concurrent type. The
2812 -- controlling parameter of the spec carries the concurrent type,
2813 -- not the corresponding record type as transformed by Analyze_
2814 -- Subprogram_Specification. In such cases, we undo the change
2815 -- made by the analysis of the specification and try to find the
2818 -- Note that wrappers already have their corresponding specs and
2819 -- bodies set during their creation, so if the candidate spec is
2820 -- a wrapper, then we definitely need to swap all types to their
2821 -- original concurrent status.
2824 or else Is_Primitive_Wrapper
(Spec_N
)
2826 -- Restore all references of corresponding record types to the
2827 -- original concurrent types.
2829 Replace_Types
(To_Corresponding
=> False);
2830 Priv_Spec
:= Find_Corresponding_Spec
(N
, False);
2832 -- The current body truly belongs to a primitive declared between
2833 -- a private and a full view. We leave the modified body as is,
2834 -- and return the true spec.
2836 if Present
(Priv_Spec
)
2837 and then Is_Private_Primitive
(Priv_Spec
)
2842 -- In case that this is some sort of error, restore the original
2843 -- state of the body.
2845 Replace_Types
(To_Corresponding
=> True);
2849 end Disambiguate_Spec
;
2851 ----------------------------
2852 -- Exchange_Limited_Views --
2853 ----------------------------
2855 procedure Exchange_Limited_Views
(Subp_Id
: Entity_Id
) is
2856 procedure Detect_And_Exchange
(Id
: Entity_Id
);
2857 -- Determine whether Id's type denotes an incomplete type associated
2858 -- with a limited with clause and exchange the limited view with the
2861 -------------------------
2862 -- Detect_And_Exchange --
2863 -------------------------
2865 procedure Detect_And_Exchange
(Id
: Entity_Id
) is
2866 Typ
: constant Entity_Id
:= Etype
(Id
);
2869 if Ekind
(Typ
) = E_Incomplete_Type
2870 and then From_Limited_With
(Typ
)
2871 and then Present
(Non_Limited_View
(Typ
))
2873 Set_Etype
(Id
, Non_Limited_View
(Typ
));
2875 end Detect_And_Exchange
;
2881 -- Start of processing for Exchange_Limited_Views
2884 if No
(Subp_Id
) then
2887 -- Do not process subprogram bodies as they already use the non-
2888 -- limited view of types.
2890 elsif not Ekind_In
(Subp_Id
, E_Function
, E_Procedure
) then
2894 -- Examine all formals and swap views when applicable
2896 Formal
:= First_Formal
(Subp_Id
);
2897 while Present
(Formal
) loop
2898 Detect_And_Exchange
(Formal
);
2900 Next_Formal
(Formal
);
2903 -- Process the return type of a function
2905 if Ekind
(Subp_Id
) = E_Function
then
2906 Detect_And_Exchange
(Subp_Id
);
2908 end Exchange_Limited_Views
;
2910 -------------------------------------
2911 -- Is_Private_Concurrent_Primitive --
2912 -------------------------------------
2914 function Is_Private_Concurrent_Primitive
2915 (Subp_Id
: Entity_Id
) return Boolean
2917 Formal_Typ
: Entity_Id
;
2920 if Present
(First_Formal
(Subp_Id
)) then
2921 Formal_Typ
:= Etype
(First_Formal
(Subp_Id
));
2923 if Is_Concurrent_Record_Type
(Formal_Typ
) then
2924 if Is_Class_Wide_Type
(Formal_Typ
) then
2925 Formal_Typ
:= Root_Type
(Formal_Typ
);
2928 Formal_Typ
:= Corresponding_Concurrent_Type
(Formal_Typ
);
2931 -- The type of the first formal is a concurrent tagged type with
2935 Is_Concurrent_Type
(Formal_Typ
)
2936 and then Is_Tagged_Type
(Formal_Typ
)
2937 and then Has_Private_Declaration
(Formal_Typ
);
2941 end Is_Private_Concurrent_Primitive
;
2943 ----------------------------
2944 -- Set_Trivial_Subprogram --
2945 ----------------------------
2947 procedure Set_Trivial_Subprogram
(N
: Node_Id
) is
2948 Nxt
: constant Node_Id
:= Next
(N
);
2951 Set_Is_Trivial_Subprogram
(Body_Id
);
2953 if Present
(Spec_Id
) then
2954 Set_Is_Trivial_Subprogram
(Spec_Id
);
2958 and then Nkind
(Nxt
) = N_Simple_Return_Statement
2959 and then No
(Next
(Nxt
))
2960 and then Present
(Expression
(Nxt
))
2961 and then Is_Entity_Name
(Expression
(Nxt
))
2963 Set_Never_Set_In_Source
(Entity
(Expression
(Nxt
)), False);
2965 end Set_Trivial_Subprogram
;
2967 ---------------------------------
2968 -- Verify_Overriding_Indicator --
2969 ---------------------------------
2971 procedure Verify_Overriding_Indicator
is
2973 if Must_Override
(Body_Spec
) then
2974 if Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
2975 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
2979 elsif not Present
(Overridden_Operation
(Spec_Id
)) then
2981 ("subprogram& is not overriding", Body_Spec
, Spec_Id
);
2983 -- Overriding indicators aren't allowed for protected subprogram
2984 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
2985 -- this to a warning if -gnatd.E is enabled.
2987 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
2988 Error_Msg_Warn
:= Error_To_Warning
;
2990 ("<<overriding indicator not allowed for protected "
2991 & "subprogram body", Body_Spec
);
2994 elsif Must_Not_Override
(Body_Spec
) then
2995 if Present
(Overridden_Operation
(Spec_Id
)) then
2997 ("subprogram& overrides inherited operation",
2998 Body_Spec
, Spec_Id
);
3000 elsif Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
3001 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
3004 ("subprogram& overrides predefined operator ",
3005 Body_Spec
, Spec_Id
);
3007 -- Overriding indicators aren't allowed for protected subprogram
3008 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
3009 -- this to a warning if -gnatd.E is enabled.
3011 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
3012 Error_Msg_Warn
:= Error_To_Warning
;
3015 ("<<overriding indicator not allowed "
3016 & "for protected subprogram body", Body_Spec
);
3018 -- If this is not a primitive operation, then the overriding
3019 -- indicator is altogether illegal.
3021 elsif not Is_Primitive
(Spec_Id
) then
3023 ("overriding indicator only allowed "
3024 & "if subprogram is primitive", Body_Spec
);
3027 -- If checking the style rule and the operation overrides, then
3028 -- issue a warning about a missing overriding_indicator. Protected
3029 -- subprogram bodies are excluded from this style checking, since
3030 -- they aren't primitives (even though their declarations can
3031 -- override) and aren't allowed to have an overriding_indicator.
3034 and then Present
(Overridden_Operation
(Spec_Id
))
3035 and then Ekind
(Scope
(Spec_Id
)) /= E_Protected_Type
3037 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
3038 Style
.Missing_Overriding
(N
, Body_Id
);
3041 and then Can_Override_Operator
(Spec_Id
)
3042 and then not Is_Predefined_File_Name
3043 (Unit_File_Name
(Get_Source_Unit
(Spec_Id
)))
3045 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
3046 Style
.Missing_Overriding
(N
, Body_Id
);
3048 end Verify_Overriding_Indicator
;
3050 -- Start of processing for Analyze_Subprogram_Body_Helper
3053 -- Generic subprograms are handled separately. They always have a
3054 -- generic specification. Determine whether current scope has a
3055 -- previous declaration.
3057 -- If the subprogram body is defined within an instance of the same
3058 -- name, the instance appears as a package renaming, and will be hidden
3059 -- within the subprogram.
3061 if Present
(Prev_Id
)
3062 and then not Is_Overloadable
(Prev_Id
)
3063 and then (Nkind
(Parent
(Prev_Id
)) /= N_Package_Renaming_Declaration
3064 or else Comes_From_Source
(Prev_Id
))
3066 if Is_Generic_Subprogram
(Prev_Id
) then
3068 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3069 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3071 Analyze_Generic_Subprogram_Body
(N
, Spec_Id
);
3073 if Nkind
(N
) = N_Subprogram_Body
then
3074 HSS
:= Handled_Statement_Sequence
(N
);
3075 Check_Missing_Return
;
3081 -- Previous entity conflicts with subprogram name. Attempting to
3082 -- enter name will post error.
3084 Enter_Name
(Body_Id
);
3088 -- Non-generic case, find the subprogram declaration, if one was seen,
3089 -- or enter new overloaded entity in the current scope. If the
3090 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
3091 -- part of the context of one of its subunits. No need to redo the
3094 elsif Prev_Id
= Body_Id
and then Has_Completion
(Body_Id
) then
3098 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
3100 if Nkind
(N
) = N_Subprogram_Body_Stub
3101 or else No
(Corresponding_Spec
(N
))
3103 if Is_Private_Concurrent_Primitive
(Body_Id
) then
3104 Spec_Id
:= Disambiguate_Spec
;
3106 Spec_Id
:= Find_Corresponding_Spec
(N
);
3108 -- In GNATprove mode, if the body has no previous spec, create
3109 -- one so that the inlining machinery can operate properly.
3110 -- Transfer aspects, if any, to the new spec, so that they
3111 -- are legal and can be processed ahead of the body.
3112 -- We make two copies of the given spec, one for the new
3113 -- declaration, and one for the body.
3116 and then GNATprove_Mode
3118 -- Inlining does not apply during pre-analysis of code
3120 and then Full_Analysis
3122 -- Inlining only applies to full bodies, not stubs
3124 and then Nkind
(N
) /= N_Subprogram_Body_Stub
3126 -- Inlining only applies to bodies in the source code, not to
3127 -- those generated by the compiler. In particular, expression
3128 -- functions, whose body is generated by the compiler, are
3129 -- treated specially by GNATprove.
3131 and then Comes_From_Source
(Body_Id
)
3133 -- This cannot be done for a compilation unit, which is not
3134 -- in a context where we can insert a new spec.
3136 and then Is_List_Member
(N
)
3138 -- Inlining only applies to subprograms without contracts,
3139 -- as a contract is a sign that GNATprove should perform a
3140 -- modular analysis of the subprogram instead of a contextual
3141 -- analysis at each call site. The same test is performed in
3142 -- Inline.Can_Be_Inlined_In_GNATprove_Mode. It is repeated
3143 -- here in another form (because the contract has not
3144 -- been attached to the body) to avoid frontend errors in
3145 -- case pragmas are used instead of aspects, because the
3146 -- corresponding pragmas in the body would not be transferred
3147 -- to the spec, leading to legality errors.
3149 and then not Body_Has_Contract
3152 Body_Spec
: constant Node_Id
:=
3153 Copy_Separate_Tree
(Specification
(N
));
3154 New_Decl
: constant Node_Id
:=
3155 Make_Subprogram_Declaration
(Loc
,
3156 Copy_Separate_Tree
(Specification
(N
)));
3158 SPARK_Mode_Aspect
: Node_Id
;
3160 Prag
, Aspect
: Node_Id
;
3163 Insert_Before
(N
, New_Decl
);
3164 Move_Aspects
(From
=> N
, To
=> New_Decl
);
3166 -- Mark the newly moved aspects as not analyzed, so that
3167 -- their effect on New_Decl is properly analyzed.
3169 Aspect
:= First
(Aspect_Specifications
(New_Decl
));
3170 while Present
(Aspect
) loop
3171 Set_Analyzed
(Aspect
, False);
3177 -- The analysis of the generated subprogram declaration
3178 -- may have introduced pragmas that need to be analyzed.
3180 Prag
:= Next
(New_Decl
);
3181 while Prag
/= N
loop
3186 Spec_Id
:= Defining_Entity
(New_Decl
);
3188 -- As Body_Id originally comes from source, mark the new
3189 -- Spec_Id as such, which is required so that calls to
3190 -- this subprogram are registered in the local effects
3191 -- stored in ALI files for GNATprove.
3193 Set_Comes_From_Source
(Spec_Id
, True);
3195 -- If aspect SPARK_Mode was specified on the body, it
3196 -- needs to be repeated on the generated decl and the
3197 -- body. Since the original aspect was moved to the
3198 -- generated decl, copy it for the body.
3200 if Has_Aspect
(Spec_Id
, Aspect_SPARK_Mode
) then
3201 SPARK_Mode_Aspect
:=
3202 New_Copy
(Find_Aspect
(Spec_Id
, Aspect_SPARK_Mode
));
3203 Set_Analyzed
(SPARK_Mode_Aspect
, False);
3204 Aspects
:= New_List
(SPARK_Mode_Aspect
);
3205 Set_Aspect_Specifications
(N
, Aspects
);
3208 Set_Specification
(N
, Body_Spec
);
3209 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
3210 Set_Corresponding_Spec
(N
, Spec_Id
);
3215 -- If this is a duplicate body, no point in analyzing it
3217 if Error_Posted
(N
) then
3221 -- A subprogram body should cause freezing of its own declaration,
3222 -- but if there was no previous explicit declaration, then the
3223 -- subprogram will get frozen too late (there may be code within
3224 -- the body that depends on the subprogram having been frozen,
3225 -- such as uses of extra formals), so we force it to be frozen
3226 -- here. Same holds if the body and spec are compilation units.
3227 -- Finally, if the return type is an anonymous access to protected
3228 -- subprogram, it must be frozen before the body because its
3229 -- expansion has generated an equivalent type that is used when
3230 -- elaborating the body.
3232 -- An exception in the case of Ada 2012, AI05-177: The bodies
3233 -- created for expression functions do not freeze.
3236 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3238 Freeze_Before
(N
, Body_Id
);
3240 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3241 Freeze_Before
(N
, Spec_Id
);
3243 elsif Is_Access_Subprogram_Type
(Etype
(Body_Id
)) then
3244 Freeze_Before
(N
, Etype
(Body_Id
));
3248 Spec_Id
:= Corresponding_Spec
(N
);
3252 -- Previously we scanned the body to look for nested subprograms, and
3253 -- rejected an inline directive if nested subprograms were present,
3254 -- because the back-end would generate conflicting symbols for the
3255 -- nested bodies. This is now unnecessary.
3257 -- Look ahead to recognize a pragma Inline that appears after the body
3259 Check_Inline_Pragma
(Spec_Id
);
3261 -- Deal with special case of a fully private operation in the body of
3262 -- the protected type. We must create a declaration for the subprogram,
3263 -- in order to attach the protected subprogram that will be used in
3264 -- internal calls. We exclude compiler generated bodies from the
3265 -- expander since the issue does not arise for those cases.
3268 and then Comes_From_Source
(N
)
3269 and then Is_Protected_Type
(Current_Scope
)
3271 Spec_Id
:= Build_Private_Protected_Declaration
(N
);
3274 -- If a separate spec is present, then deal with freezing issues
3276 if Present
(Spec_Id
) then
3277 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
3278 Verify_Overriding_Indicator
;
3280 -- In general, the spec will be frozen when we start analyzing the
3281 -- body. However, for internally generated operations, such as
3282 -- wrapper functions for inherited operations with controlling
3283 -- results, the spec may not have been frozen by the time we expand
3284 -- the freeze actions that include the bodies. In particular, extra
3285 -- formals for accessibility or for return-in-place may need to be
3286 -- generated. Freeze nodes, if any, are inserted before the current
3287 -- body. These freeze actions are also needed in ASIS mode to enable
3288 -- the proper back-annotations.
3290 if not Is_Frozen
(Spec_Id
)
3291 and then (Expander_Active
or ASIS_Mode
)
3293 -- Force the generation of its freezing node to ensure proper
3294 -- management of access types in the backend.
3296 -- This is definitely needed for some cases, but it is not clear
3297 -- why, to be investigated further???
3299 Set_Has_Delayed_Freeze
(Spec_Id
);
3300 Freeze_Before
(N
, Spec_Id
);
3304 -- Mark presence of postcondition procedure in current scope and mark
3305 -- the procedure itself as needing debug info. The latter is important
3306 -- when analyzing decision coverage (for example, for MC/DC coverage).
3308 if Chars
(Body_Id
) = Name_uPostconditions
then
3309 Set_Has_Postconditions
(Current_Scope
);
3310 Set_Debug_Info_Needed
(Body_Id
);
3313 -- Place subprogram on scope stack, and make formals visible. If there
3314 -- is a spec, the visible entity remains that of the spec.
3316 if Present
(Spec_Id
) then
3317 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
3319 if Is_Child_Unit
(Spec_Id
) then
3320 Generate_Reference
(Spec_Id
, Scope
(Spec_Id
), 'k', False);
3324 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
3327 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3328 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3330 if Is_Abstract_Subprogram
(Spec_Id
) then
3331 Error_Msg_N
("an abstract subprogram cannot have a body", N
);
3335 Set_Convention
(Body_Id
, Convention
(Spec_Id
));
3336 Set_Has_Completion
(Spec_Id
);
3338 -- Inherit the "ghostness" of the subprogram spec. Note that this
3339 -- property is not directly inherited as the body may be subject
3340 -- to a different Ghost assertion policy.
3342 if Is_Ghost_Entity
(Spec_Id
) or else Within_Ghost_Scope
then
3343 Set_Is_Ghost_Entity
(Body_Id
);
3345 -- The Ghost policy in effect at the point of declaration and
3346 -- at the point of completion must match (SPARK RM 6.9(15)).
3348 Check_Ghost_Completion
(Spec_Id
, Body_Id
);
3351 if Is_Protected_Type
(Scope
(Spec_Id
)) then
3352 Prot_Typ
:= Scope
(Spec_Id
);
3355 -- If this is a body generated for a renaming, do not check for
3356 -- full conformance. The check is redundant, because the spec of
3357 -- the body is a copy of the spec in the renaming declaration,
3358 -- and the test can lead to spurious errors on nested defaults.
3360 if Present
(Spec_Decl
)
3361 and then not Comes_From_Source
(N
)
3363 (Nkind
(Original_Node
(Spec_Decl
)) =
3364 N_Subprogram_Renaming_Declaration
3365 or else (Present
(Corresponding_Body
(Spec_Decl
))
3367 Nkind
(Unit_Declaration_Node
3368 (Corresponding_Body
(Spec_Decl
))) =
3369 N_Subprogram_Renaming_Declaration
))
3373 -- Conversely, the spec may have been generated for specless body
3374 -- with an inline pragma.
3376 elsif Comes_From_Source
(N
)
3377 and then not Comes_From_Source
(Spec_Id
)
3378 and then Has_Pragma_Inline
(Spec_Id
)
3385 Fully_Conformant
, True, Conformant
, Body_Id
);
3388 -- If the body is not fully conformant, we have to decide if we
3389 -- should analyze it or not. If it has a really messed up profile
3390 -- then we probably should not analyze it, since we will get too
3391 -- many bogus messages.
3393 -- Our decision is to go ahead in the non-fully conformant case
3394 -- only if it is at least mode conformant with the spec. Note
3395 -- that the call to Check_Fully_Conformant has issued the proper
3396 -- error messages to complain about the lack of conformance.
3399 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
3405 if Spec_Id
/= Body_Id
then
3406 Reference_Body_Formals
(Spec_Id
, Body_Id
);
3409 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
3411 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3412 Set_Corresponding_Spec_Of_Stub
(N
, Spec_Id
);
3417 Set_Corresponding_Spec
(N
, Spec_Id
);
3419 -- Ada 2005 (AI-345): If the operation is a primitive operation
3420 -- of a concurrent type, the type of the first parameter has been
3421 -- replaced with the corresponding record, which is the proper
3422 -- run-time structure to use. However, within the body there may
3423 -- be uses of the formals that depend on primitive operations
3424 -- of the type (in particular calls in prefixed form) for which
3425 -- we need the original concurrent type. The operation may have
3426 -- several controlling formals, so the replacement must be done
3429 if Comes_From_Source
(Spec_Id
)
3430 and then Present
(First_Entity
(Spec_Id
))
3431 and then Ekind
(Etype
(First_Entity
(Spec_Id
))) = E_Record_Type
3432 and then Is_Tagged_Type
(Etype
(First_Entity
(Spec_Id
)))
3433 and then Present
(Interfaces
(Etype
(First_Entity
(Spec_Id
))))
3434 and then Present
(Corresponding_Concurrent_Type
3435 (Etype
(First_Entity
(Spec_Id
))))
3438 Typ
: constant Entity_Id
:= Etype
(First_Entity
(Spec_Id
));
3442 Form
:= First_Formal
(Spec_Id
);
3443 while Present
(Form
) loop
3444 if Etype
(Form
) = Typ
then
3445 Set_Etype
(Form
, Corresponding_Concurrent_Type
(Typ
));
3453 -- Make the formals visible, and place subprogram on scope stack.
3454 -- This is also the point at which we set Last_Real_Spec_Entity
3455 -- to mark the entities which will not be moved to the body.
3457 Install_Formals
(Spec_Id
);
3458 Last_Real_Spec_Entity
:= Last_Entity
(Spec_Id
);
3460 -- Within an instance, add local renaming declarations so that
3461 -- gdb can retrieve the values of actuals more easily. This is
3462 -- only relevant if generating code (and indeed we definitely
3463 -- do not want these definitions -gnatc mode, because that would
3466 if Is_Generic_Instance
(Spec_Id
)
3467 and then Is_Wrapper_Package
(Current_Scope
)
3468 and then Expander_Active
3470 Build_Subprogram_Instance_Renamings
(N
, Current_Scope
);
3473 Push_Scope
(Spec_Id
);
3475 -- Make sure that the subprogram is immediately visible. For
3476 -- child units that have no separate spec this is indispensable.
3477 -- Otherwise it is safe albeit redundant.
3479 Set_Is_Immediately_Visible
(Spec_Id
);
3482 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
3483 Set_Contract
(Body_Id
, Make_Contract
(Sloc
(Body_Id
)));
3484 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
3485 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Spec_Id
));
3487 -- Case of subprogram body with no previous spec
3490 -- Check for style warning required
3494 -- Only apply check for source level subprograms for which checks
3495 -- have not been suppressed.
3497 and then Comes_From_Source
(Body_Id
)
3498 and then not Suppress_Style_Checks
(Body_Id
)
3500 -- No warnings within an instance
3502 and then not In_Instance
3504 -- No warnings for expression functions
3506 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3508 Style
.Body_With_No_Spec
(N
);
3511 New_Overloaded_Entity
(Body_Id
);
3513 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
3514 Set_Acts_As_Spec
(N
);
3515 Generate_Definition
(Body_Id
);
3516 Set_Contract
(Body_Id
, Make_Contract
(Sloc
(Body_Id
)));
3518 (Body_Id
, Body_Id
, 'b', Set_Ref
=> False, Force
=> True);
3519 Install_Formals
(Body_Id
);
3521 Push_Scope
(Body_Id
);
3524 -- For stubs and bodies with no previous spec, generate references to
3527 Generate_Reference_To_Formals
(Body_Id
);
3530 -- Set SPARK_Mode from context
3532 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
3533 Set_SPARK_Pragma_Inherited
(Body_Id
, True);
3535 -- If the return type is an anonymous access type whose designated type
3536 -- is the limited view of a class-wide type and the non-limited view is
3537 -- available, update the return type accordingly.
3539 if Ada_Version
>= Ada_2005
and then Comes_From_Source
(N
) then
3545 Rtyp
:= Etype
(Current_Scope
);
3547 if Ekind
(Rtyp
) = E_Anonymous_Access_Type
then
3548 Etyp
:= Directly_Designated_Type
(Rtyp
);
3550 if Is_Class_Wide_Type
(Etyp
)
3551 and then From_Limited_With
(Etyp
)
3553 Set_Directly_Designated_Type
3554 (Etype
(Current_Scope
), Available_View
(Etyp
));
3560 -- If this is the proper body of a stub, we must verify that the stub
3561 -- conforms to the body, and to the previous spec if one was present.
3562 -- We know already that the body conforms to that spec. This test is
3563 -- only required for subprograms that come from source.
3565 if Nkind
(Parent
(N
)) = N_Subunit
3566 and then Comes_From_Source
(N
)
3567 and then not Error_Posted
(Body_Id
)
3568 and then Nkind
(Corresponding_Stub
(Parent
(N
))) =
3569 N_Subprogram_Body_Stub
3572 Old_Id
: constant Entity_Id
:=
3574 (Specification
(Corresponding_Stub
(Parent
(N
))));
3576 Conformant
: Boolean := False;
3579 if No
(Spec_Id
) then
3580 Check_Fully_Conformant
(Body_Id
, Old_Id
);
3584 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
3586 if not Conformant
then
3588 -- The stub was taken to be a new declaration. Indicate that
3591 Set_Has_Completion
(Old_Id
, False);
3597 Set_Has_Completion
(Body_Id
);
3598 Check_Eliminated
(Body_Id
);
3600 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3602 -- Analyze any aspect specifications that appear on the subprogram
3605 if Has_Aspects
(N
) then
3606 Analyze_Aspects_On_Body_Or_Stub
;
3609 -- Stop the analysis now as the stub cannot be inlined, plus it does
3610 -- not have declarative or statement lists.
3615 -- Handle frontend inlining
3617 -- Note: Normally we don't do any inlining if expansion is off, since
3618 -- we won't generate code in any case. An exception arises in GNATprove
3619 -- mode where we want to expand some calls in place, even with expansion
3620 -- disabled, since the inlining eases formal verification.
3622 if not GNATprove_Mode
3623 and then Expander_Active
3624 and then Serious_Errors_Detected
= 0
3625 and then Present
(Spec_Id
)
3626 and then Has_Pragma_Inline
(Spec_Id
)
3628 -- Legacy implementation (relying on frontend inlining)
3630 if not Back_End_Inlining
then
3631 if Has_Pragma_Inline_Always
(Spec_Id
)
3632 or else (Has_Pragma_Inline
(Spec_Id
) and Front_End_Inlining
)
3634 Build_Body_To_Inline
(N
, Spec_Id
);
3637 -- New implementation (relying on backend inlining)
3640 if Has_Pragma_Inline_Always
(Spec_Id
)
3641 or else Optimization_Level
> 0
3643 -- Handle function returning an unconstrained type
3645 if Comes_From_Source
(Body_Id
)
3646 and then Ekind
(Spec_Id
) = E_Function
3647 and then Returns_Unconstrained_Type
(Spec_Id
)
3649 Check_And_Split_Unconstrained_Function
(N
, Spec_Id
, Body_Id
);
3653 Subp_Body
: constant Node_Id
:=
3654 Unit_Declaration_Node
(Body_Id
);
3655 Subp_Decl
: constant List_Id
:= Declarations
(Subp_Body
);
3658 -- Do not pass inlining to the backend if the subprogram
3659 -- has declarations or statements which cannot be inlined
3660 -- by the backend. This check is done here to emit an
3661 -- error instead of the generic warning message reported
3662 -- by the GCC backend (ie. "function might not be
3665 if Present
(Subp_Decl
)
3666 and then Has_Excluded_Declaration
(Spec_Id
, Subp_Decl
)
3670 elsif Has_Excluded_Statement
3673 (Handled_Statement_Sequence
(Subp_Body
)))
3677 -- If the backend inlining is available then at this
3678 -- stage we only have to mark the subprogram as inlined.
3679 -- The expander will take care of registering it in the
3680 -- table of subprograms inlined by the backend a part of
3681 -- processing calls to it (cf. Expand_Call)
3684 Set_Is_Inlined
(Spec_Id
);
3691 -- In GNATprove mode, inline only when there is a separate subprogram
3692 -- declaration for now, as inlining of subprogram bodies acting as
3693 -- declarations, or subprogram stubs, are not supported by frontend
3694 -- inlining. This inlining should occur after analysis of the body, so
3695 -- that it is known whether the value of SPARK_Mode applicable to the
3696 -- body, which can be defined by a pragma inside the body.
3698 elsif GNATprove_Mode
3699 and then Full_Analysis
3700 and then not Inside_A_Generic
3701 and then Present
(Spec_Id
)
3702 and then Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Declaration
3703 and then Can_Be_Inlined_In_GNATprove_Mode
(Spec_Id
, Body_Id
)
3704 and then not Body_Has_Contract
3706 Build_Body_To_Inline
(N
, Spec_Id
);
3709 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
3710 -- of the specification we have to install the private withed units.
3711 -- This holds for child units as well.
3713 if Is_Compilation_Unit
(Body_Id
)
3714 or else Nkind
(Parent
(N
)) = N_Compilation_Unit
3716 Install_Private_With_Clauses
(Body_Id
);
3719 Check_Anonymous_Return
;
3721 -- Set the Protected_Formal field of each extra formal of the protected
3722 -- subprogram to reference the corresponding extra formal of the
3723 -- subprogram that implements it. For regular formals this occurs when
3724 -- the protected subprogram's declaration is expanded, but the extra
3725 -- formals don't get created until the subprogram is frozen. We need to
3726 -- do this before analyzing the protected subprogram's body so that any
3727 -- references to the original subprogram's extra formals will be changed
3728 -- refer to the implementing subprogram's formals (see Expand_Formal).
3730 if Present
(Spec_Id
)
3731 and then Is_Protected_Type
(Scope
(Spec_Id
))
3732 and then Present
(Protected_Body_Subprogram
(Spec_Id
))
3735 Impl_Subp
: constant Entity_Id
:=
3736 Protected_Body_Subprogram
(Spec_Id
);
3737 Prot_Ext_Formal
: Entity_Id
:= Extra_Formals
(Spec_Id
);
3738 Impl_Ext_Formal
: Entity_Id
:= Extra_Formals
(Impl_Subp
);
3740 while Present
(Prot_Ext_Formal
) loop
3741 pragma Assert
(Present
(Impl_Ext_Formal
));
3742 Set_Protected_Formal
(Prot_Ext_Formal
, Impl_Ext_Formal
);
3743 Next_Formal_With_Extras
(Prot_Ext_Formal
);
3744 Next_Formal_With_Extras
(Impl_Ext_Formal
);
3749 -- Now we can go on to analyze the body
3751 HSS
:= Handled_Statement_Sequence
(N
);
3752 Set_Actual_Subtypes
(N
, Current_Scope
);
3754 -- Add a declaration for the Protection object, renaming declarations
3755 -- for discriminals and privals and finally a declaration for the entry
3756 -- family index (if applicable). This form of early expansion is done
3757 -- when the Expander is active because Install_Private_Data_Declarations
3758 -- references entities which were created during regular expansion. The
3759 -- subprogram entity must come from source, and not be an internally
3760 -- generated subprogram.
3763 and then Present
(Prot_Typ
)
3764 and then Present
(Spec_Id
)
3765 and then Comes_From_Source
(Spec_Id
)
3766 and then not Is_Eliminated
(Spec_Id
)
3768 Install_Private_Data_Declarations
3769 (Sloc
(N
), Spec_Id
, Prot_Typ
, N
, Declarations
(N
));
3772 -- Ada 2012 (AI05-0151): Incomplete types coming from a limited context
3773 -- may now appear in parameter and result profiles. Since the analysis
3774 -- of a subprogram body may use the parameter and result profile of the
3775 -- spec, swap any limited views with their non-limited counterpart.
3777 if Ada_Version
>= Ada_2012
then
3778 Exchange_Limited_Views
(Spec_Id
);
3781 -- Analyze any aspect specifications that appear on the subprogram body
3783 if Has_Aspects
(N
) then
3784 Analyze_Aspects_On_Body_Or_Stub
;
3787 -- Deal with [refined] preconditions, postconditions, Contract_Cases,
3788 -- invariants and predicates associated with the body and its spec.
3789 -- Note that this is not pure expansion as Expand_Subprogram_Contract
3790 -- prepares the contract assertions for generic subprograms or for ASIS.
3791 -- Do not generate contract checks in SPARK mode.
3793 if not GNATprove_Mode
then
3794 Expand_Subprogram_Contract
(N
, Spec_Id
, Body_Id
);
3797 -- Analyze the declarations (this call will analyze the precondition
3798 -- Check pragmas we prepended to the list, as well as the declaration
3799 -- of the _Postconditions procedure).
3801 Analyze_Declarations
(Declarations
(N
));
3803 -- Verify that the SPARK_Mode of the body agrees with that of its spec
3805 if Present
(Spec_Id
) and then Present
(SPARK_Pragma
(Body_Id
)) then
3806 if Present
(SPARK_Pragma
(Spec_Id
)) then
3807 if Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Spec_Id
)) = Off
3809 Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Body_Id
)) = On
3811 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
3812 Error_Msg_N
("incorrect application of SPARK_Mode#", N
);
3813 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Spec_Id
));
3815 ("\value Off was set for SPARK_Mode on & #", N
, Spec_Id
);
3818 elsif Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Body_Stub
then
3822 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
3823 Error_Msg_N
("incorrect application of SPARK_Mode #", N
);
3824 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
3826 ("\no value was set for SPARK_Mode on & #", N
, Spec_Id
);
3830 -- If SPARK_Mode for body is not On, disable frontend inlining for this
3831 -- subprogram in GNATprove mode, as its body should not be analyzed.
3834 and then GNATprove_Mode
3835 and then Present
(Spec_Id
)
3836 and then Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Declaration
3838 Set_Body_To_Inline
(Parent
(Parent
(Spec_Id
)), Empty
);
3839 Set_Is_Inlined_Always
(Spec_Id
, False);
3842 -- Check completion, and analyze the statements
3845 Inspect_Deferred_Constant_Completion
(Declarations
(N
));
3848 -- Deal with end of scope processing for the body
3850 Process_End_Label
(HSS
, 't', Current_Scope
);
3852 Check_Subprogram_Order
(N
);
3853 Set_Analyzed
(Body_Id
);
3855 -- If we have a separate spec, then the analysis of the declarations
3856 -- caused the entities in the body to be chained to the spec id, but
3857 -- we want them chained to the body id. Only the formal parameters
3858 -- end up chained to the spec id in this case.
3860 if Present
(Spec_Id
) then
3862 -- We must conform to the categorization of our spec
3864 Validate_Categorization_Dependency
(N
, Spec_Id
);
3866 -- And if this is a child unit, the parent units must conform
3868 if Is_Child_Unit
(Spec_Id
) then
3869 Validate_Categorization_Dependency
3870 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
3873 -- Here is where we move entities from the spec to the body
3875 -- Case where there are entities that stay with the spec
3877 if Present
(Last_Real_Spec_Entity
) then
3879 -- No body entities (happens when the only real spec entities come
3880 -- from precondition and postcondition pragmas).
3882 if No
(Last_Entity
(Body_Id
)) then
3884 (Body_Id
, Next_Entity
(Last_Real_Spec_Entity
));
3886 -- Body entities present (formals), so chain stuff past them
3890 (Last_Entity
(Body_Id
), Next_Entity
(Last_Real_Spec_Entity
));
3893 Set_Next_Entity
(Last_Real_Spec_Entity
, Empty
);
3894 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
3895 Set_Last_Entity
(Spec_Id
, Last_Real_Spec_Entity
);
3897 -- Case where there are no spec entities, in this case there can be
3898 -- no body entities either, so just move everything.
3901 pragma Assert
(No
(Last_Entity
(Body_Id
)));
3902 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
3903 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
3904 Set_First_Entity
(Spec_Id
, Empty
);
3905 Set_Last_Entity
(Spec_Id
, Empty
);
3909 Check_Missing_Return
;
3911 -- Now we are going to check for variables that are never modified in
3912 -- the body of the procedure. But first we deal with a special case
3913 -- where we want to modify this check. If the body of the subprogram
3914 -- starts with a raise statement or its equivalent, or if the body
3915 -- consists entirely of a null statement, then it is pretty obvious that
3916 -- it is OK to not reference the parameters. For example, this might be
3917 -- the following common idiom for a stubbed function: statement of the
3918 -- procedure raises an exception. In particular this deals with the
3919 -- common idiom of a stubbed function, which appears something like:
3921 -- function F (A : Integer) return Some_Type;
3924 -- raise Program_Error;
3928 -- Here the purpose of X is simply to satisfy the annoying requirement
3929 -- in Ada that there be at least one return, and we certainly do not
3930 -- want to go posting warnings on X that it is not initialized. On
3931 -- the other hand, if X is entirely unreferenced that should still
3934 -- What we do is to detect these cases, and if we find them, flag the
3935 -- subprogram as being Is_Trivial_Subprogram and then use that flag to
3936 -- suppress unwanted warnings. For the case of the function stub above
3937 -- we have a special test to set X as apparently assigned to suppress
3944 -- Skip initial labels (for one thing this occurs when we are in
3945 -- front end ZCX mode, but in any case it is irrelevant), and also
3946 -- initial Push_xxx_Error_Label nodes, which are also irrelevant.
3948 Stm
:= First
(Statements
(HSS
));
3949 while Nkind
(Stm
) = N_Label
3950 or else Nkind
(Stm
) in N_Push_xxx_Label
3955 -- Do the test on the original statement before expansion
3958 Ostm
: constant Node_Id
:= Original_Node
(Stm
);
3961 -- If explicit raise statement, turn on flag
3963 if Nkind
(Ostm
) = N_Raise_Statement
then
3964 Set_Trivial_Subprogram
(Stm
);
3966 -- If null statement, and no following statements, turn on flag
3968 elsif Nkind
(Stm
) = N_Null_Statement
3969 and then Comes_From_Source
(Stm
)
3970 and then No
(Next
(Stm
))
3972 Set_Trivial_Subprogram
(Stm
);
3974 -- Check for explicit call cases which likely raise an exception
3976 elsif Nkind
(Ostm
) = N_Procedure_Call_Statement
then
3977 if Is_Entity_Name
(Name
(Ostm
)) then
3979 Ent
: constant Entity_Id
:= Entity
(Name
(Ostm
));
3982 -- If the procedure is marked No_Return, then likely it
3983 -- raises an exception, but in any case it is not coming
3984 -- back here, so turn on the flag.
3987 and then Ekind
(Ent
) = E_Procedure
3988 and then No_Return
(Ent
)
3990 Set_Trivial_Subprogram
(Stm
);
3998 -- Check for variables that are never modified
4004 -- If there is a separate spec, then transfer Never_Set_In_Source
4005 -- flags from out parameters to the corresponding entities in the
4006 -- body. The reason we do that is we want to post error flags on
4007 -- the body entities, not the spec entities.
4009 if Present
(Spec_Id
) then
4010 E1
:= First_Entity
(Spec_Id
);
4011 while Present
(E1
) loop
4012 if Ekind
(E1
) = E_Out_Parameter
then
4013 E2
:= First_Entity
(Body_Id
);
4014 while Present
(E2
) loop
4015 exit when Chars
(E1
) = Chars
(E2
);
4019 if Present
(E2
) then
4020 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
4028 -- Check references in body
4030 Check_References
(Body_Id
);
4032 end Analyze_Subprogram_Body_Helper
;
4034 ---------------------------------
4035 -- Analyze_Subprogram_Contract --
4036 ---------------------------------
4038 procedure Analyze_Subprogram_Contract
(Subp
: Entity_Id
) is
4039 Items
: constant Node_Id
:= Contract
(Subp
);
4040 Case_Prag
: Node_Id
:= Empty
;
4041 Depends
: Node_Id
:= Empty
;
4042 Global
: Node_Id
:= Empty
;
4043 Mode
: SPARK_Mode_Type
;
4045 Post_Prag
: Node_Id
:= Empty
;
4047 Seen_In_Case
: Boolean := False;
4048 Seen_In_Post
: Boolean := False;
4051 -- Due to the timing of contract analysis, delayed pragmas may be
4052 -- subject to the wrong SPARK_Mode, usually that of the enclosing
4053 -- context. To remedy this, restore the original SPARK_Mode of the
4054 -- related subprogram body.
4056 Save_SPARK_Mode_And_Set
(Subp
, Mode
);
4058 if Present
(Items
) then
4060 -- Analyze pre- and postconditions
4062 Prag
:= Pre_Post_Conditions
(Items
);
4063 while Present
(Prag
) loop
4064 Analyze_Pre_Post_Condition_In_Decl_Part
(Prag
, Subp
);
4066 -- Verify whether a postcondition mentions attribute 'Result and
4067 -- its expression introduces a post-state.
4069 if Warn_On_Suspicious_Contract
4070 and then Pragma_Name
(Prag
) = Name_Postcondition
4073 Check_Result_And_Post_State
(Prag
, Seen_In_Post
);
4076 Prag
:= Next_Pragma
(Prag
);
4079 -- Analyze contract-cases and test-cases
4081 Prag
:= Contract_Test_Cases
(Items
);
4082 while Present
(Prag
) loop
4083 Nam
:= Pragma_Name
(Prag
);
4085 if Nam
= Name_Contract_Cases
then
4086 Analyze_Contract_Cases_In_Decl_Part
(Prag
);
4088 -- Verify whether contract-cases mention attribute 'Result and
4089 -- its expression introduces a post-state. Perform the check
4090 -- only when the pragma is legal.
4092 if Warn_On_Suspicious_Contract
4093 and then not Error_Posted
(Prag
)
4096 Check_Result_And_Post_State
(Prag
, Seen_In_Case
);
4100 pragma Assert
(Nam
= Name_Test_Case
);
4101 Analyze_Test_Case_In_Decl_Part
(Prag
, Subp
);
4104 Prag
:= Next_Pragma
(Prag
);
4107 -- Analyze classification pragmas
4109 Prag
:= Classifications
(Items
);
4110 while Present
(Prag
) loop
4111 Nam
:= Pragma_Name
(Prag
);
4113 if Nam
= Name_Depends
then
4116 elsif Nam
= Name_Global
then
4119 -- Note that pragma Extensions_Visible has already been analyzed
4123 Prag
:= Next_Pragma
(Prag
);
4126 -- Analyze Global first as Depends may mention items classified in
4127 -- the global categorization.
4129 if Present
(Global
) then
4130 Analyze_Global_In_Decl_Part
(Global
);
4133 -- Depends must be analyzed after Global in order to see the modes of
4134 -- all global items.
4136 if Present
(Depends
) then
4137 Analyze_Depends_In_Decl_Part
(Depends
);
4141 -- Emit an error when neither the postconditions nor the contract-cases
4142 -- mention attribute 'Result in the context of a function.
4144 if Warn_On_Suspicious_Contract
4145 and then Ekind_In
(Subp
, E_Function
, E_Generic_Function
)
4147 if Present
(Case_Prag
)
4148 and then not Seen_In_Case
4149 and then Present
(Post_Prag
)
4150 and then not Seen_In_Post
4153 ("neither function postcondition nor contract cases mention "
4154 & "result?T?", Post_Prag
);
4156 elsif Present
(Case_Prag
) and then not Seen_In_Case
then
4158 ("contract cases do not mention result?T?", Case_Prag
);
4160 -- OK if we have at least one IN OUT parameter
4162 elsif Present
(Post_Prag
) and then not Seen_In_Post
then
4166 F
:= First_Formal
(Subp
);
4167 while Present
(F
) loop
4168 if Ekind
(F
) = E_In_Out_Parameter
then
4176 -- If no in-out parameters and no mention of Result, the contract
4177 -- is certainly suspicious.
4180 ("function postcondition does not mention result?T?", Post_Prag
);
4184 -- Restore the SPARK_Mode of the enclosing context after all delayed
4185 -- pragmas have been analyzed.
4187 Restore_SPARK_Mode
(Mode
);
4188 end Analyze_Subprogram_Contract
;
4190 ------------------------------------
4191 -- Analyze_Subprogram_Declaration --
4192 ------------------------------------
4194 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
4195 Scop
: constant Entity_Id
:= Current_Scope
;
4196 Designator
: Entity_Id
;
4198 Is_Completion
: Boolean;
4199 -- Indicates whether a null procedure declaration is a completion
4202 -- Null procedures are not allowed in SPARK
4204 if Nkind
(Specification
(N
)) = N_Procedure_Specification
4205 and then Null_Present
(Specification
(N
))
4207 Check_SPARK_05_Restriction
("null procedure is not allowed", N
);
4209 if Is_Protected_Type
(Current_Scope
) then
4210 Error_Msg_N
("protected operation cannot be a null procedure", N
);
4213 Analyze_Null_Procedure
(N
, Is_Completion
);
4215 if Is_Completion
then
4217 -- The null procedure acts as a body, nothing further is needed.
4223 Designator
:= Analyze_Subprogram_Specification
(Specification
(N
));
4225 -- A reference may already have been generated for the unit name, in
4226 -- which case the following call is redundant. However it is needed for
4227 -- declarations that are the rewriting of an expression function.
4229 Generate_Definition
(Designator
);
4231 -- Set SPARK mode from current context (may be overwritten later with
4232 -- explicit pragma).
4234 Set_SPARK_Pragma
(Designator
, SPARK_Mode_Pragma
);
4235 Set_SPARK_Pragma_Inherited
(Designator
, True);
4237 -- A subprogram declared within a Ghost scope is automatically Ghost
4238 -- (SPARK RM 6.9(2)).
4240 if Comes_From_Source
(Designator
) and then Within_Ghost_Scope
then
4241 Set_Is_Ghost_Entity
(Designator
);
4244 if Debug_Flag_C
then
4245 Write_Str
("==> subprogram spec ");
4246 Write_Name
(Chars
(Designator
));
4247 Write_Str
(" from ");
4248 Write_Location
(Sloc
(N
));
4253 Validate_RCI_Subprogram_Declaration
(N
);
4254 New_Overloaded_Entity
(Designator
);
4255 Check_Delayed_Subprogram
(Designator
);
4257 -- If the type of the first formal of the current subprogram is a non-
4258 -- generic tagged private type, mark the subprogram as being a private
4259 -- primitive. Ditto if this is a function with controlling result, and
4260 -- the return type is currently private. In both cases, the type of the
4261 -- controlling argument or result must be in the current scope for the
4262 -- operation to be primitive.
4264 if Has_Controlling_Result
(Designator
)
4265 and then Is_Private_Type
(Etype
(Designator
))
4266 and then Scope
(Etype
(Designator
)) = Current_Scope
4267 and then not Is_Generic_Actual_Type
(Etype
(Designator
))
4269 Set_Is_Private_Primitive
(Designator
);
4271 elsif Present
(First_Formal
(Designator
)) then
4273 Formal_Typ
: constant Entity_Id
:=
4274 Etype
(First_Formal
(Designator
));
4276 Set_Is_Private_Primitive
(Designator
,
4277 Is_Tagged_Type
(Formal_Typ
)
4278 and then Scope
(Formal_Typ
) = Current_Scope
4279 and then Is_Private_Type
(Formal_Typ
)
4280 and then not Is_Generic_Actual_Type
(Formal_Typ
));
4284 -- Ada 2005 (AI-251): Abstract interface primitives must be abstract
4287 if Ada_Version
>= Ada_2005
4288 and then Comes_From_Source
(N
)
4289 and then Is_Dispatching_Operation
(Designator
)
4296 if Has_Controlling_Result
(Designator
) then
4297 Etyp
:= Etype
(Designator
);
4300 E
:= First_Entity
(Designator
);
4302 and then Is_Formal
(E
)
4303 and then not Is_Controlling_Formal
(E
)
4311 if Is_Access_Type
(Etyp
) then
4312 Etyp
:= Directly_Designated_Type
(Etyp
);
4315 if Is_Interface
(Etyp
)
4316 and then not Is_Abstract_Subprogram
(Designator
)
4317 and then not (Ekind
(Designator
) = E_Procedure
4318 and then Null_Present
(Specification
(N
)))
4320 Error_Msg_Name_1
:= Chars
(Defining_Entity
(N
));
4322 -- Specialize error message based on procedures vs. functions,
4323 -- since functions can't be null subprograms.
4325 if Ekind
(Designator
) = E_Procedure
then
4327 ("interface procedure % must be abstract or null", N
);
4330 ("interface function % must be abstract", N
);
4336 -- What is the following code for, it used to be
4338 -- ??? Set_Suppress_Elaboration_Checks
4339 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
4341 -- The following seems equivalent, but a bit dubious
4343 if Elaboration_Checks_Suppressed
(Designator
) then
4344 Set_Kill_Elaboration_Checks
(Designator
);
4347 if Scop
/= Standard_Standard
and then not Is_Child_Unit
(Designator
) then
4348 Set_Categorization_From_Scope
(Designator
, Scop
);
4351 -- For a compilation unit, check for library-unit pragmas
4353 Push_Scope
(Designator
);
4354 Set_Categorization_From_Pragmas
(N
);
4355 Validate_Categorization_Dependency
(N
, Designator
);
4359 -- For a compilation unit, set body required. This flag will only be
4360 -- reset if a valid Import or Interface pragma is processed later on.
4362 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
4363 Set_Body_Required
(Parent
(N
), True);
4365 if Ada_Version
>= Ada_2005
4366 and then Nkind
(Specification
(N
)) = N_Procedure_Specification
4367 and then Null_Present
(Specification
(N
))
4370 ("null procedure cannot be declared at library level", N
);
4374 Generate_Reference_To_Formals
(Designator
);
4375 Check_Eliminated
(Designator
);
4377 if Debug_Flag_C
then
4379 Write_Str
("<== subprogram spec ");
4380 Write_Name
(Chars
(Designator
));
4381 Write_Str
(" from ");
4382 Write_Location
(Sloc
(N
));
4386 if Is_Protected_Type
(Current_Scope
) then
4388 -- Indicate that this is a protected operation, because it may be
4389 -- used in subsequent declarations within the protected type.
4391 Set_Convention
(Designator
, Convention_Protected
);
4394 List_Inherited_Pre_Post_Aspects
(Designator
);
4396 if Has_Aspects
(N
) then
4397 Analyze_Aspect_Specifications
(N
, Designator
);
4399 end Analyze_Subprogram_Declaration
;
4401 --------------------------------------
4402 -- Analyze_Subprogram_Specification --
4403 --------------------------------------
4405 -- Reminder: N here really is a subprogram specification (not a subprogram
4406 -- declaration). This procedure is called to analyze the specification in
4407 -- both subprogram bodies and subprogram declarations (specs).
4409 function Analyze_Subprogram_Specification
(N
: Node_Id
) return Entity_Id
is
4410 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
4411 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
4413 -- Start of processing for Analyze_Subprogram_Specification
4416 -- User-defined operator is not allowed in SPARK, except as a renaming
4418 if Nkind
(Defining_Unit_Name
(N
)) = N_Defining_Operator_Symbol
4419 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
4421 Check_SPARK_05_Restriction
4422 ("user-defined operator is not allowed", N
);
4425 -- Proceed with analysis. Do not emit a cross-reference entry if the
4426 -- specification comes from an expression function, because it may be
4427 -- the completion of a previous declaration. It is is not, the cross-
4428 -- reference entry will be emitted for the new subprogram declaration.
4430 if Nkind
(Parent
(N
)) /= N_Expression_Function
then
4431 Generate_Definition
(Designator
);
4434 Set_Contract
(Designator
, Make_Contract
(Sloc
(Designator
)));
4436 if Nkind
(N
) = N_Function_Specification
then
4437 Set_Ekind
(Designator
, E_Function
);
4438 Set_Mechanism
(Designator
, Default_Mechanism
);
4440 Set_Ekind
(Designator
, E_Procedure
);
4441 Set_Etype
(Designator
, Standard_Void_Type
);
4444 -- Flag Is_Inlined_Always is True by default, and reversed to False for
4445 -- those subprograms which could be inlined in GNATprove mode (because
4446 -- Body_To_Inline is non-Empty) but cannot be inlined.
4448 if GNATprove_Mode
then
4449 Set_Is_Inlined_Always
(Designator
);
4452 -- Introduce new scope for analysis of the formals and the return type
4454 Set_Scope
(Designator
, Current_Scope
);
4456 if Present
(Formals
) then
4457 Push_Scope
(Designator
);
4458 Process_Formals
(Formals
, N
);
4460 -- Check dimensions in N for formals with default expression
4462 Analyze_Dimension_Formals
(N
, Formals
);
4464 -- Ada 2005 (AI-345): If this is an overriding operation of an
4465 -- inherited interface operation, and the controlling type is
4466 -- a synchronized type, replace the type with its corresponding
4467 -- record, to match the proper signature of an overriding operation.
4468 -- Same processing for an access parameter whose designated type is
4469 -- derived from a synchronized interface.
4471 if Ada_Version
>= Ada_2005
then
4474 Formal_Typ
: Entity_Id
;
4475 Rec_Typ
: Entity_Id
;
4476 Desig_Typ
: Entity_Id
;
4479 Formal
:= First_Formal
(Designator
);
4480 while Present
(Formal
) loop
4481 Formal_Typ
:= Etype
(Formal
);
4483 if Is_Concurrent_Type
(Formal_Typ
)
4484 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
4486 Rec_Typ
:= Corresponding_Record_Type
(Formal_Typ
);
4488 if Present
(Interfaces
(Rec_Typ
)) then
4489 Set_Etype
(Formal
, Rec_Typ
);
4492 elsif Ekind
(Formal_Typ
) = E_Anonymous_Access_Type
then
4493 Desig_Typ
:= Designated_Type
(Formal_Typ
);
4495 if Is_Concurrent_Type
(Desig_Typ
)
4496 and then Present
(Corresponding_Record_Type
(Desig_Typ
))
4498 Rec_Typ
:= Corresponding_Record_Type
(Desig_Typ
);
4500 if Present
(Interfaces
(Rec_Typ
)) then
4501 Set_Directly_Designated_Type
(Formal_Typ
, Rec_Typ
);
4506 Next_Formal
(Formal
);
4513 -- The subprogram scope is pushed and popped around the processing of
4514 -- the return type for consistency with call above to Process_Formals
4515 -- (which itself can call Analyze_Return_Type), and to ensure that any
4516 -- itype created for the return type will be associated with the proper
4519 elsif Nkind
(N
) = N_Function_Specification
then
4520 Push_Scope
(Designator
);
4521 Analyze_Return_Type
(N
);
4527 if Nkind
(N
) = N_Function_Specification
then
4529 -- Deal with operator symbol case
4531 if Nkind
(Designator
) = N_Defining_Operator_Symbol
then
4532 Valid_Operator_Definition
(Designator
);
4535 May_Need_Actuals
(Designator
);
4537 -- Ada 2005 (AI-251): If the return type is abstract, verify that
4538 -- the subprogram is abstract also. This does not apply to renaming
4539 -- declarations, where abstractness is inherited, and to subprogram
4540 -- bodies generated for stream operations, which become renamings as
4543 -- In case of primitives associated with abstract interface types
4544 -- the check is applied later (see Analyze_Subprogram_Declaration).
4546 if not Nkind_In
(Original_Node
(Parent
(N
)),
4547 N_Subprogram_Renaming_Declaration
,
4548 N_Abstract_Subprogram_Declaration
,
4549 N_Formal_Abstract_Subprogram_Declaration
)
4551 if Is_Abstract_Type
(Etype
(Designator
))
4552 and then not Is_Interface
(Etype
(Designator
))
4555 ("function that returns abstract type must be abstract", N
);
4557 -- Ada 2012 (AI-0073): Extend this test to subprograms with an
4558 -- access result whose designated type is abstract.
4560 elsif Nkind
(Result_Definition
(N
)) = N_Access_Definition
4562 not Is_Class_Wide_Type
(Designated_Type
(Etype
(Designator
)))
4563 and then Is_Abstract_Type
(Designated_Type
(Etype
(Designator
)))
4564 and then Ada_Version
>= Ada_2012
4566 Error_Msg_N
("function whose access result designates "
4567 & "abstract type must be abstract", N
);
4573 end Analyze_Subprogram_Specification
;
4575 -----------------------
4576 -- Check_Conformance --
4577 -----------------------
4579 procedure Check_Conformance
4580 (New_Id
: Entity_Id
;
4582 Ctype
: Conformance_Type
;
4584 Conforms
: out Boolean;
4585 Err_Loc
: Node_Id
:= Empty
;
4586 Get_Inst
: Boolean := False;
4587 Skip_Controlling_Formals
: Boolean := False)
4589 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
4590 -- Sets Conforms to False. If Errmsg is False, then that's all it does.
4591 -- If Errmsg is True, then processing continues to post an error message
4592 -- for conformance error on given node. Two messages are output. The
4593 -- first message points to the previous declaration with a general "no
4594 -- conformance" message. The second is the detailed reason, supplied as
4595 -- Msg. The parameter N provide information for a possible & insertion
4596 -- in the message, and also provides the location for posting the
4597 -- message in the absence of a specified Err_Loc location.
4599 -----------------------
4600 -- Conformance_Error --
4601 -----------------------
4603 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
4610 if No
(Err_Loc
) then
4616 Error_Msg_Sloc
:= Sloc
(Old_Id
);
4619 when Type_Conformant
=>
4620 Error_Msg_N
-- CODEFIX
4621 ("not type conformant with declaration#!", Enode
);
4623 when Mode_Conformant
=>
4624 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4626 ("not mode conformant with operation inherited#!",
4630 ("not mode conformant with declaration#!", Enode
);
4633 when Subtype_Conformant
=>
4634 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4636 ("not subtype conformant with operation inherited#!",
4640 ("not subtype conformant with declaration#!", Enode
);
4643 when Fully_Conformant
=>
4644 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4645 Error_Msg_N
-- CODEFIX
4646 ("not fully conformant with operation inherited#!",
4649 Error_Msg_N
-- CODEFIX
4650 ("not fully conformant with declaration#!", Enode
);
4654 Error_Msg_NE
(Msg
, Enode
, N
);
4656 end Conformance_Error
;
4660 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
4661 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
4662 Old_Formal
: Entity_Id
;
4663 New_Formal
: Entity_Id
;
4664 Access_Types_Match
: Boolean;
4665 Old_Formal_Base
: Entity_Id
;
4666 New_Formal_Base
: Entity_Id
;
4668 -- Start of processing for Check_Conformance
4673 -- We need a special case for operators, since they don't appear
4676 if Ctype
= Type_Conformant
then
4677 if Ekind
(New_Id
) = E_Operator
4678 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
4684 -- If both are functions/operators, check return types conform
4686 if Old_Type
/= Standard_Void_Type
4687 and then New_Type
/= Standard_Void_Type
4689 -- If we are checking interface conformance we omit controlling
4690 -- arguments and result, because we are only checking the conformance
4691 -- of the remaining parameters.
4693 if Has_Controlling_Result
(Old_Id
)
4694 and then Has_Controlling_Result
(New_Id
)
4695 and then Skip_Controlling_Formals
4699 elsif not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
4700 if Ctype
>= Subtype_Conformant
4701 and then not Predicates_Match
(Old_Type
, New_Type
)
4704 ("\predicate of return type does not match!", New_Id
);
4707 ("\return type does not match!", New_Id
);
4713 -- Ada 2005 (AI-231): In case of anonymous access types check the
4714 -- null-exclusion and access-to-constant attributes match.
4716 if Ada_Version
>= Ada_2005
4717 and then Ekind
(Etype
(Old_Type
)) = E_Anonymous_Access_Type
4719 (Can_Never_Be_Null
(Old_Type
) /= Can_Never_Be_Null
(New_Type
)
4720 or else Is_Access_Constant
(Etype
(Old_Type
)) /=
4721 Is_Access_Constant
(Etype
(New_Type
)))
4723 Conformance_Error
("\return type does not match!", New_Id
);
4727 -- If either is a function/operator and the other isn't, error
4729 elsif Old_Type
/= Standard_Void_Type
4730 or else New_Type
/= Standard_Void_Type
4732 Conformance_Error
("\functions can only match functions!", New_Id
);
4736 -- In subtype conformant case, conventions must match (RM 6.3.1(16)).
4737 -- If this is a renaming as body, refine error message to indicate that
4738 -- the conflict is with the original declaration. If the entity is not
4739 -- frozen, the conventions don't have to match, the one of the renamed
4740 -- entity is inherited.
4742 if Ctype
>= Subtype_Conformant
then
4743 if Convention
(Old_Id
) /= Convention
(New_Id
) then
4744 if not Is_Frozen
(New_Id
) then
4747 elsif Present
(Err_Loc
)
4748 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
4749 and then Present
(Corresponding_Spec
(Err_Loc
))
4751 Error_Msg_Name_1
:= Chars
(New_Id
);
4753 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
4754 Conformance_Error
("\prior declaration for% has convention %!");
4757 Conformance_Error
("\calling conventions do not match!");
4762 elsif Is_Formal_Subprogram
(Old_Id
)
4763 or else Is_Formal_Subprogram
(New_Id
)
4765 Conformance_Error
("\formal subprograms not allowed!");
4768 -- Pragma Ghost behaves as a convention in the context of subtype
4769 -- conformance (SPARK RM 6.9(5)). Do not check internally generated
4770 -- subprograms as their spec may reside in a Ghost region and their
4771 -- body not, or vice versa.
4773 elsif Comes_From_Source
(Old_Id
)
4774 and then Comes_From_Source
(New_Id
)
4775 and then Is_Ghost_Entity
(Old_Id
) /= Is_Ghost_Entity
(New_Id
)
4777 Conformance_Error
("\ghost modes do not match!");
4782 -- Deal with parameters
4784 -- Note: we use the entity information, rather than going directly
4785 -- to the specification in the tree. This is not only simpler, but
4786 -- absolutely necessary for some cases of conformance tests between
4787 -- operators, where the declaration tree simply does not exist.
4789 Old_Formal
:= First_Formal
(Old_Id
);
4790 New_Formal
:= First_Formal
(New_Id
);
4791 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
4792 if Is_Controlling_Formal
(Old_Formal
)
4793 and then Is_Controlling_Formal
(New_Formal
)
4794 and then Skip_Controlling_Formals
4796 -- The controlling formals will have different types when
4797 -- comparing an interface operation with its match, but both
4798 -- or neither must be access parameters.
4800 if Is_Access_Type
(Etype
(Old_Formal
))
4802 Is_Access_Type
(Etype
(New_Formal
))
4804 goto Skip_Controlling_Formal
;
4807 ("\access parameter does not match!", New_Formal
);
4811 -- Ada 2012: Mode conformance also requires that formal parameters
4812 -- be both aliased, or neither.
4814 if Ctype
>= Mode_Conformant
and then Ada_Version
>= Ada_2012
then
4815 if Is_Aliased
(Old_Formal
) /= Is_Aliased
(New_Formal
) then
4817 ("\aliased parameter mismatch!", New_Formal
);
4821 if Ctype
= Fully_Conformant
then
4823 -- Names must match. Error message is more accurate if we do
4824 -- this before checking that the types of the formals match.
4826 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
4827 Conformance_Error
("\name& does not match!", New_Formal
);
4829 -- Set error posted flag on new formal as well to stop
4830 -- junk cascaded messages in some cases.
4832 Set_Error_Posted
(New_Formal
);
4836 -- Null exclusion must match
4838 if Null_Exclusion_Present
(Parent
(Old_Formal
))
4840 Null_Exclusion_Present
(Parent
(New_Formal
))
4842 -- Only give error if both come from source. This should be
4843 -- investigated some time, since it should not be needed ???
4845 if Comes_From_Source
(Old_Formal
)
4847 Comes_From_Source
(New_Formal
)
4850 ("\null exclusion for& does not match", New_Formal
);
4852 -- Mark error posted on the new formal to avoid duplicated
4853 -- complaint about types not matching.
4855 Set_Error_Posted
(New_Formal
);
4860 -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This
4861 -- case occurs whenever a subprogram is being renamed and one of its
4862 -- parameters imposes a null exclusion. For example:
4864 -- type T is null record;
4865 -- type Acc_T is access T;
4866 -- subtype Acc_T_Sub is Acc_T;
4868 -- procedure P (Obj : not null Acc_T_Sub); -- itype
4869 -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype
4872 Old_Formal_Base
:= Etype
(Old_Formal
);
4873 New_Formal_Base
:= Etype
(New_Formal
);
4876 Old_Formal_Base
:= Get_Instance_Of
(Old_Formal_Base
);
4877 New_Formal_Base
:= Get_Instance_Of
(New_Formal_Base
);
4880 Access_Types_Match
:= Ada_Version
>= Ada_2005
4882 -- Ensure that this rule is only applied when New_Id is a
4883 -- renaming of Old_Id.
4885 and then Nkind
(Parent
(Parent
(New_Id
))) =
4886 N_Subprogram_Renaming_Declaration
4887 and then Nkind
(Name
(Parent
(Parent
(New_Id
)))) in N_Has_Entity
4888 and then Present
(Entity
(Name
(Parent
(Parent
(New_Id
)))))
4889 and then Entity
(Name
(Parent
(Parent
(New_Id
)))) = Old_Id
4891 -- Now handle the allowed access-type case
4893 and then Is_Access_Type
(Old_Formal_Base
)
4894 and then Is_Access_Type
(New_Formal_Base
)
4896 -- The type kinds must match. The only exception occurs with
4897 -- multiple generics of the form:
4900 -- type F is private; type A is private;
4901 -- type F_Ptr is access F; type A_Ptr is access A;
4902 -- with proc F_P (X : F_Ptr); with proc A_P (X : A_Ptr);
4903 -- package F_Pack is ... package A_Pack is
4904 -- package F_Inst is
4905 -- new F_Pack (A, A_Ptr, A_P);
4907 -- When checking for conformance between the parameters of A_P
4908 -- and F_P, the type kinds of F_Ptr and A_Ptr will not match
4909 -- because the compiler has transformed A_Ptr into a subtype of
4910 -- F_Ptr. We catch this case in the code below.
4912 and then (Ekind
(Old_Formal_Base
) = Ekind
(New_Formal_Base
)
4914 (Is_Generic_Type
(Old_Formal_Base
)
4915 and then Is_Generic_Type
(New_Formal_Base
)
4916 and then Is_Internal
(New_Formal_Base
)
4917 and then Etype
(Etype
(New_Formal_Base
)) =
4919 and then Directly_Designated_Type
(Old_Formal_Base
) =
4920 Directly_Designated_Type
(New_Formal_Base
)
4921 and then ((Is_Itype
(Old_Formal_Base
)
4922 and then Can_Never_Be_Null
(Old_Formal_Base
))
4924 (Is_Itype
(New_Formal_Base
)
4925 and then Can_Never_Be_Null
(New_Formal_Base
)));
4927 -- Types must always match. In the visible part of an instance,
4928 -- usual overloading rules for dispatching operations apply, and
4929 -- we check base types (not the actual subtypes).
4931 if In_Instance_Visible_Part
4932 and then Is_Dispatching_Operation
(New_Id
)
4934 if not Conforming_Types
4935 (T1
=> Base_Type
(Etype
(Old_Formal
)),
4936 T2
=> Base_Type
(Etype
(New_Formal
)),
4938 Get_Inst
=> Get_Inst
)
4939 and then not Access_Types_Match
4941 Conformance_Error
("\type of & does not match!", New_Formal
);
4945 elsif not Conforming_Types
4946 (T1
=> Old_Formal_Base
,
4947 T2
=> New_Formal_Base
,
4949 Get_Inst
=> Get_Inst
)
4950 and then not Access_Types_Match
4952 -- Don't give error message if old type is Any_Type. This test
4953 -- avoids some cascaded errors, e.g. in case of a bad spec.
4955 if Errmsg
and then Old_Formal_Base
= Any_Type
then
4958 if Ctype
>= Subtype_Conformant
4960 not Predicates_Match
(Old_Formal_Base
, New_Formal_Base
)
4963 ("\predicate of & does not match!", New_Formal
);
4966 ("\type of & does not match!", New_Formal
);
4973 -- For mode conformance, mode must match
4975 if Ctype
>= Mode_Conformant
then
4976 if Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
) then
4977 if not Ekind_In
(New_Id
, E_Function
, E_Procedure
)
4978 or else not Is_Primitive_Wrapper
(New_Id
)
4980 Conformance_Error
("\mode of & does not match!", New_Formal
);
4984 T
: constant Entity_Id
:= Find_Dispatching_Type
(New_Id
);
4986 if Is_Protected_Type
(Corresponding_Concurrent_Type
(T
))
4988 Error_Msg_PT
(T
, New_Id
);
4991 ("\mode of & does not match!", New_Formal
);
4998 -- Part of mode conformance for access types is having the same
4999 -- constant modifier.
5001 elsif Access_Types_Match
5002 and then Is_Access_Constant
(Old_Formal_Base
) /=
5003 Is_Access_Constant
(New_Formal_Base
)
5006 ("\constant modifier does not match!", New_Formal
);
5011 if Ctype
>= Subtype_Conformant
then
5013 -- Ada 2005 (AI-231): In case of anonymous access types check
5014 -- the null-exclusion and access-to-constant attributes must
5015 -- match. For null exclusion, we test the types rather than the
5016 -- formals themselves, since the attribute is only set reliably
5017 -- on the formals in the Ada 95 case, and we exclude the case
5018 -- where Old_Formal is marked as controlling, to avoid errors
5019 -- when matching completing bodies with dispatching declarations
5020 -- (access formals in the bodies aren't marked Can_Never_Be_Null).
5022 if Ada_Version
>= Ada_2005
5023 and then Ekind
(Etype
(Old_Formal
)) = E_Anonymous_Access_Type
5024 and then Ekind
(Etype
(New_Formal
)) = E_Anonymous_Access_Type
5026 ((Can_Never_Be_Null
(Etype
(Old_Formal
)) /=
5027 Can_Never_Be_Null
(Etype
(New_Formal
))
5029 not Is_Controlling_Formal
(Old_Formal
))
5031 Is_Access_Constant
(Etype
(Old_Formal
)) /=
5032 Is_Access_Constant
(Etype
(New_Formal
)))
5034 -- Do not complain if error already posted on New_Formal. This
5035 -- avoids some redundant error messages.
5037 and then not Error_Posted
(New_Formal
)
5039 -- It is allowed to omit the null-exclusion in case of stream
5040 -- attribute subprograms. We recognize stream subprograms
5041 -- through their TSS-generated suffix.
5044 TSS_Name
: constant TSS_Name_Type
:= Get_TSS_Name
(New_Id
);
5047 if TSS_Name
/= TSS_Stream_Read
5048 and then TSS_Name
/= TSS_Stream_Write
5049 and then TSS_Name
/= TSS_Stream_Input
5050 and then TSS_Name
/= TSS_Stream_Output
5052 -- Here we have a definite conformance error. It is worth
5053 -- special casing the error message for the case of a
5054 -- controlling formal (which excludes null).
5056 if Is_Controlling_Formal
(New_Formal
) then
5057 Error_Msg_Node_2
:= Scope
(New_Formal
);
5059 ("\controlling formal & of & excludes null, "
5060 & "declaration must exclude null as well",
5063 -- Normal case (couldn't we give more detail here???)
5067 ("\type of & does not match!", New_Formal
);
5076 -- Full conformance checks
5078 if Ctype
= Fully_Conformant
then
5080 -- We have checked already that names match
5082 if Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
5084 -- Check default expressions for in parameters
5087 NewD
: constant Boolean :=
5088 Present
(Default_Value
(New_Formal
));
5089 OldD
: constant Boolean :=
5090 Present
(Default_Value
(Old_Formal
));
5092 if NewD
or OldD
then
5094 -- The old default value has been analyzed because the
5095 -- current full declaration will have frozen everything
5096 -- before. The new default value has not been analyzed,
5097 -- so analyze it now before we check for conformance.
5100 Push_Scope
(New_Id
);
5101 Preanalyze_Spec_Expression
5102 (Default_Value
(New_Formal
), Etype
(New_Formal
));
5106 if not (NewD
and OldD
)
5107 or else not Fully_Conformant_Expressions
5108 (Default_Value
(Old_Formal
),
5109 Default_Value
(New_Formal
))
5112 ("\default expression for & does not match!",
5121 -- A couple of special checks for Ada 83 mode. These checks are
5122 -- skipped if either entity is an operator in package Standard,
5123 -- or if either old or new instance is not from the source program.
5125 if Ada_Version
= Ada_83
5126 and then Sloc
(Old_Id
) > Standard_Location
5127 and then Sloc
(New_Id
) > Standard_Location
5128 and then Comes_From_Source
(Old_Id
)
5129 and then Comes_From_Source
(New_Id
)
5132 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
5133 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
5136 -- Explicit IN must be present or absent in both cases. This
5137 -- test is required only in the full conformance case.
5139 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
5140 and then Ctype
= Fully_Conformant
5143 ("\(Ada 83) IN must appear in both declarations",
5148 -- Grouping (use of comma in param lists) must be the same
5149 -- This is where we catch a misconformance like:
5152 -- A : Integer; B : Integer
5154 -- which are represented identically in the tree except
5155 -- for the setting of the flags More_Ids and Prev_Ids.
5157 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
5158 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
5161 ("\grouping of & does not match!", New_Formal
);
5167 -- This label is required when skipping controlling formals
5169 <<Skip_Controlling_Formal
>>
5171 Next_Formal
(Old_Formal
);
5172 Next_Formal
(New_Formal
);
5175 if Present
(Old_Formal
) then
5176 Conformance_Error
("\too few parameters!");
5179 elsif Present
(New_Formal
) then
5180 Conformance_Error
("\too many parameters!", New_Formal
);
5183 end Check_Conformance
;
5185 -----------------------
5186 -- Check_Conventions --
5187 -----------------------
5189 procedure Check_Conventions
(Typ
: Entity_Id
) is
5190 Ifaces_List
: Elist_Id
;
5192 procedure Check_Convention
(Op
: Entity_Id
);
5193 -- Verify that the convention of inherited dispatching operation Op is
5194 -- consistent among all subprograms it overrides. In order to minimize
5195 -- the search, Search_From is utilized to designate a specific point in
5196 -- the list rather than iterating over the whole list once more.
5198 ----------------------
5199 -- Check_Convention --
5200 ----------------------
5202 procedure Check_Convention
(Op
: Entity_Id
) is
5203 Op_Conv
: constant Convention_Id
:= Convention
(Op
);
5204 Iface_Conv
: Convention_Id
;
5205 Iface_Elmt
: Elmt_Id
;
5206 Iface_Prim_Elmt
: Elmt_Id
;
5207 Iface_Prim
: Entity_Id
;
5210 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
5211 while Present
(Iface_Elmt
) loop
5213 First_Elmt
(Primitive_Operations
(Node
(Iface_Elmt
)));
5214 while Present
(Iface_Prim_Elmt
) loop
5215 Iface_Prim
:= Node
(Iface_Prim_Elmt
);
5216 Iface_Conv
:= Convention
(Iface_Prim
);
5218 if Is_Interface_Conformant
(Typ
, Iface_Prim
, Op
)
5219 and then Iface_Conv
/= Op_Conv
5222 ("inconsistent conventions in primitive operations", Typ
);
5224 Error_Msg_Name_1
:= Chars
(Op
);
5225 Error_Msg_Name_2
:= Get_Convention_Name
(Op_Conv
);
5226 Error_Msg_Sloc
:= Sloc
(Op
);
5228 if Comes_From_Source
(Op
) or else No
(Alias
(Op
)) then
5229 if not Present
(Overridden_Operation
(Op
)) then
5230 Error_Msg_N
("\\primitive % defined #", Typ
);
5233 ("\\overriding operation % with "
5234 & "convention % defined #", Typ
);
5237 else pragma Assert
(Present
(Alias
(Op
)));
5238 Error_Msg_Sloc
:= Sloc
(Alias
(Op
));
5239 Error_Msg_N
("\\inherited operation % with "
5240 & "convention % defined #", Typ
);
5243 Error_Msg_Name_1
:= Chars
(Op
);
5244 Error_Msg_Name_2
:= Get_Convention_Name
(Iface_Conv
);
5245 Error_Msg_Sloc
:= Sloc
(Iface_Prim
);
5246 Error_Msg_N
("\\overridden operation % with "
5247 & "convention % defined #", Typ
);
5249 -- Avoid cascading errors
5254 Next_Elmt
(Iface_Prim_Elmt
);
5257 Next_Elmt
(Iface_Elmt
);
5259 end Check_Convention
;
5263 Prim_Op
: Entity_Id
;
5264 Prim_Op_Elmt
: Elmt_Id
;
5266 -- Start of processing for Check_Conventions
5269 if not Has_Interfaces
(Typ
) then
5273 Collect_Interfaces
(Typ
, Ifaces_List
);
5275 -- The algorithm checks every overriding dispatching operation against
5276 -- all the corresponding overridden dispatching operations, detecting
5277 -- differences in conventions.
5279 Prim_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5280 while Present
(Prim_Op_Elmt
) loop
5281 Prim_Op
:= Node
(Prim_Op_Elmt
);
5283 -- A small optimization: skip the predefined dispatching operations
5284 -- since they always have the same convention.
5286 if not Is_Predefined_Dispatching_Operation
(Prim_Op
) then
5287 Check_Convention
(Prim_Op
);
5290 Next_Elmt
(Prim_Op_Elmt
);
5292 end Check_Conventions
;
5294 ------------------------------
5295 -- Check_Delayed_Subprogram --
5296 ------------------------------
5298 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
5301 procedure Possible_Freeze
(T
: Entity_Id
);
5302 -- T is the type of either a formal parameter or of the return type.
5303 -- If T is not yet frozen and needs a delayed freeze, then the
5304 -- subprogram itself must be delayed. If T is the limited view of an
5305 -- incomplete type the subprogram must be frozen as well, because
5306 -- T may depend on local types that have not been frozen yet.
5308 ---------------------
5309 -- Possible_Freeze --
5310 ---------------------
5312 procedure Possible_Freeze
(T
: Entity_Id
) is
5314 if Has_Delayed_Freeze
(T
) and then not Is_Frozen
(T
) then
5315 Set_Has_Delayed_Freeze
(Designator
);
5317 elsif Is_Access_Type
(T
)
5318 and then Has_Delayed_Freeze
(Designated_Type
(T
))
5319 and then not Is_Frozen
(Designated_Type
(T
))
5321 Set_Has_Delayed_Freeze
(Designator
);
5323 elsif Ekind
(T
) = E_Incomplete_Type
5324 and then From_Limited_With
(T
)
5326 Set_Has_Delayed_Freeze
(Designator
);
5328 -- AI05-0151: In Ada 2012, Incomplete types can appear in the profile
5329 -- of a subprogram or entry declaration.
5331 elsif Ekind
(T
) = E_Incomplete_Type
5332 and then Ada_Version
>= Ada_2012
5334 Set_Has_Delayed_Freeze
(Designator
);
5337 end Possible_Freeze
;
5339 -- Start of processing for Check_Delayed_Subprogram
5342 -- All subprograms, including abstract subprograms, may need a freeze
5343 -- node if some formal type or the return type needs one.
5345 Possible_Freeze
(Etype
(Designator
));
5346 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
5348 -- Need delayed freeze if any of the formal types themselves need
5349 -- a delayed freeze and are not yet frozen.
5351 F
:= First_Formal
(Designator
);
5352 while Present
(F
) loop
5353 Possible_Freeze
(Etype
(F
));
5354 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
5358 -- Mark functions that return by reference. Note that it cannot be
5359 -- done for delayed_freeze subprograms because the underlying
5360 -- returned type may not be known yet (for private types)
5362 if not Has_Delayed_Freeze
(Designator
) and then Expander_Active
then
5364 Typ
: constant Entity_Id
:= Etype
(Designator
);
5365 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
5367 if Is_Limited_View
(Typ
) then
5368 Set_Returns_By_Ref
(Designator
);
5369 elsif Present
(Utyp
) and then CW_Or_Has_Controlled_Part
(Utyp
) then
5370 Set_Returns_By_Ref
(Designator
);
5374 end Check_Delayed_Subprogram
;
5376 ------------------------------------
5377 -- Check_Discriminant_Conformance --
5378 ------------------------------------
5380 procedure Check_Discriminant_Conformance
5385 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
5386 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
5387 New_Discr_Id
: Entity_Id
;
5388 New_Discr_Type
: Entity_Id
;
5390 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
5391 -- Post error message for conformance error on given node. Two messages
5392 -- are output. The first points to the previous declaration with a
5393 -- general "no conformance" message. The second is the detailed reason,
5394 -- supplied as Msg. The parameter N provide information for a possible
5395 -- & insertion in the message.
5397 -----------------------
5398 -- Conformance_Error --
5399 -----------------------
5401 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
5403 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
5404 Error_Msg_N
-- CODEFIX
5405 ("not fully conformant with declaration#!", N
);
5406 Error_Msg_NE
(Msg
, N
, N
);
5407 end Conformance_Error
;
5409 -- Start of processing for Check_Discriminant_Conformance
5412 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
5413 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
5415 -- The subtype mark of the discriminant on the full type has not
5416 -- been analyzed so we do it here. For an access discriminant a new
5419 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
5421 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
5424 Analyze
(Discriminant_Type
(New_Discr
));
5425 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
5427 -- Ada 2005: if the discriminant definition carries a null
5428 -- exclusion, create an itype to check properly for consistency
5429 -- with partial declaration.
5431 if Is_Access_Type
(New_Discr_Type
)
5432 and then Null_Exclusion_Present
(New_Discr
)
5435 Create_Null_Excluding_Itype
5436 (T
=> New_Discr_Type
,
5437 Related_Nod
=> New_Discr
,
5438 Scope_Id
=> Current_Scope
);
5442 if not Conforming_Types
5443 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
5445 Conformance_Error
("type of & does not match!", New_Discr_Id
);
5448 -- Treat the new discriminant as an occurrence of the old one,
5449 -- for navigation purposes, and fill in some semantic
5450 -- information, for completeness.
5452 Generate_Reference
(Old_Discr
, New_Discr_Id
, 'r');
5453 Set_Etype
(New_Discr_Id
, Etype
(Old_Discr
));
5454 Set_Scope
(New_Discr_Id
, Scope
(Old_Discr
));
5459 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
5460 Conformance_Error
("name & does not match!", New_Discr_Id
);
5464 -- Default expressions must match
5467 NewD
: constant Boolean :=
5468 Present
(Expression
(New_Discr
));
5469 OldD
: constant Boolean :=
5470 Present
(Expression
(Parent
(Old_Discr
)));
5473 if NewD
or OldD
then
5475 -- The old default value has been analyzed and expanded,
5476 -- because the current full declaration will have frozen
5477 -- everything before. The new default values have not been
5478 -- expanded, so expand now to check conformance.
5481 Preanalyze_Spec_Expression
5482 (Expression
(New_Discr
), New_Discr_Type
);
5485 if not (NewD
and OldD
)
5486 or else not Fully_Conformant_Expressions
5487 (Expression
(Parent
(Old_Discr
)),
5488 Expression
(New_Discr
))
5492 ("default expression for & does not match!",
5499 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
5501 if Ada_Version
= Ada_83
then
5503 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
5506 -- Grouping (use of comma in param lists) must be the same
5507 -- This is where we catch a misconformance like:
5510 -- A : Integer; B : Integer
5512 -- which are represented identically in the tree except
5513 -- for the setting of the flags More_Ids and Prev_Ids.
5515 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
5516 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
5519 ("grouping of & does not match!", New_Discr_Id
);
5525 Next_Discriminant
(Old_Discr
);
5529 if Present
(Old_Discr
) then
5530 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
5533 elsif Present
(New_Discr
) then
5535 ("too many discriminants!", Defining_Identifier
(New_Discr
));
5538 end Check_Discriminant_Conformance
;
5540 ----------------------------
5541 -- Check_Fully_Conformant --
5542 ----------------------------
5544 procedure Check_Fully_Conformant
5545 (New_Id
: Entity_Id
;
5547 Err_Loc
: Node_Id
:= Empty
)
5550 pragma Warnings
(Off
, Result
);
5553 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
5554 end Check_Fully_Conformant
;
5556 ---------------------------
5557 -- Check_Mode_Conformant --
5558 ---------------------------
5560 procedure Check_Mode_Conformant
5561 (New_Id
: Entity_Id
;
5563 Err_Loc
: Node_Id
:= Empty
;
5564 Get_Inst
: Boolean := False)
5567 pragma Warnings
(Off
, Result
);
5570 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
5571 end Check_Mode_Conformant
;
5573 --------------------------------
5574 -- Check_Overriding_Indicator --
5575 --------------------------------
5577 procedure Check_Overriding_Indicator
5579 Overridden_Subp
: Entity_Id
;
5580 Is_Primitive
: Boolean)
5586 -- No overriding indicator for literals
5588 if Ekind
(Subp
) = E_Enumeration_Literal
then
5591 elsif Ekind
(Subp
) = E_Entry
then
5592 Decl
:= Parent
(Subp
);
5594 -- No point in analyzing a malformed operator
5596 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
5597 and then Error_Posted
(Subp
)
5602 Decl
:= Unit_Declaration_Node
(Subp
);
5605 if Nkind_In
(Decl
, N_Subprogram_Body
,
5606 N_Subprogram_Body_Stub
,
5607 N_Subprogram_Declaration
,
5608 N_Abstract_Subprogram_Declaration
,
5609 N_Subprogram_Renaming_Declaration
)
5611 Spec
:= Specification
(Decl
);
5613 elsif Nkind
(Decl
) = N_Entry_Declaration
then
5620 -- The overriding operation is type conformant with the overridden one,
5621 -- but the names of the formals are not required to match. If the names
5622 -- appear permuted in the overriding operation, this is a possible
5623 -- source of confusion that is worth diagnosing. Controlling formals
5624 -- often carry names that reflect the type, and it is not worthwhile
5625 -- requiring that their names match.
5627 if Present
(Overridden_Subp
)
5628 and then Nkind
(Subp
) /= N_Defining_Operator_Symbol
5635 Form1
:= First_Formal
(Subp
);
5636 Form2
:= First_Formal
(Overridden_Subp
);
5638 -- If the overriding operation is a synchronized operation, skip
5639 -- the first parameter of the overridden operation, which is
5640 -- implicit in the new one. If the operation is declared in the
5641 -- body it is not primitive and all formals must match.
5643 if Is_Concurrent_Type
(Scope
(Subp
))
5644 and then Is_Tagged_Type
(Scope
(Subp
))
5645 and then not Has_Completion
(Scope
(Subp
))
5647 Form2
:= Next_Formal
(Form2
);
5650 if Present
(Form1
) then
5651 Form1
:= Next_Formal
(Form1
);
5652 Form2
:= Next_Formal
(Form2
);
5655 while Present
(Form1
) loop
5656 if not Is_Controlling_Formal
(Form1
)
5657 and then Present
(Next_Formal
(Form2
))
5658 and then Chars
(Form1
) = Chars
(Next_Formal
(Form2
))
5660 Error_Msg_Node_2
:= Alias
(Overridden_Subp
);
5661 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
5663 ("& does not match corresponding formal of&#",
5668 Next_Formal
(Form1
);
5669 Next_Formal
(Form2
);
5674 -- If there is an overridden subprogram, then check that there is no
5675 -- "not overriding" indicator, and mark the subprogram as overriding.
5676 -- This is not done if the overridden subprogram is marked as hidden,
5677 -- which can occur for the case of inherited controlled operations
5678 -- (see Derive_Subprogram), unless the inherited subprogram's parent
5679 -- subprogram is not itself hidden. (Note: This condition could probably
5680 -- be simplified, leaving out the testing for the specific controlled
5681 -- cases, but it seems safer and clearer this way, and echoes similar
5682 -- special-case tests of this kind in other places.)
5684 if Present
(Overridden_Subp
)
5685 and then (not Is_Hidden
(Overridden_Subp
)
5687 (Nam_In
(Chars
(Overridden_Subp
), Name_Initialize
,
5690 and then Present
(Alias
(Overridden_Subp
))
5691 and then not Is_Hidden
(Alias
(Overridden_Subp
))))
5693 if Must_Not_Override
(Spec
) then
5694 Error_Msg_Sloc
:= Sloc
(Overridden_Subp
);
5696 if Ekind
(Subp
) = E_Entry
then
5698 ("entry & overrides inherited operation #", Spec
, Subp
);
5701 ("subprogram & overrides inherited operation #", Spec
, Subp
);
5704 -- Special-case to fix a GNAT oddity: Limited_Controlled is declared
5705 -- as an extension of Root_Controlled, and thus has a useless Adjust
5706 -- operation. This operation should not be inherited by other limited
5707 -- controlled types. An explicit Adjust for them is not overriding.
5709 elsif Must_Override
(Spec
)
5710 and then Chars
(Overridden_Subp
) = Name_Adjust
5711 and then Is_Limited_Type
(Etype
(First_Formal
(Subp
)))
5712 and then Present
(Alias
(Overridden_Subp
))
5714 Is_Predefined_File_Name
5715 (Unit_File_Name
(Get_Source_Unit
(Alias
(Overridden_Subp
))))
5717 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
5719 elsif Is_Subprogram
(Subp
) then
5720 if Is_Init_Proc
(Subp
) then
5723 elsif No
(Overridden_Operation
(Subp
)) then
5725 -- For entities generated by Derive_Subprograms the overridden
5726 -- operation is the inherited primitive (which is available
5727 -- through the attribute alias)
5729 if (Is_Dispatching_Operation
(Subp
)
5730 or else Is_Dispatching_Operation
(Overridden_Subp
))
5731 and then not Comes_From_Source
(Overridden_Subp
)
5732 and then Find_Dispatching_Type
(Overridden_Subp
) =
5733 Find_Dispatching_Type
(Subp
)
5734 and then Present
(Alias
(Overridden_Subp
))
5735 and then Comes_From_Source
(Alias
(Overridden_Subp
))
5737 Set_Overridden_Operation
(Subp
, Alias
(Overridden_Subp
));
5738 Inherit_Subprogram_Contract
(Subp
, Alias
(Overridden_Subp
));
5741 Set_Overridden_Operation
(Subp
, Overridden_Subp
);
5742 Inherit_Subprogram_Contract
(Subp
, Overridden_Subp
);
5747 -- If primitive flag is set or this is a protected operation, then
5748 -- the operation is overriding at the point of its declaration, so
5749 -- warn if necessary. Otherwise it may have been declared before the
5750 -- operation it overrides and no check is required.
5753 and then not Must_Override
(Spec
)
5754 and then (Is_Primitive
5755 or else Ekind
(Scope
(Subp
)) = E_Protected_Type
)
5757 Style
.Missing_Overriding
(Decl
, Subp
);
5760 -- If Subp is an operator, it may override a predefined operation, if
5761 -- it is defined in the same scope as the type to which it applies.
5762 -- In that case Overridden_Subp is empty because of our implicit
5763 -- representation for predefined operators. We have to check whether the
5764 -- signature of Subp matches that of a predefined operator. Note that
5765 -- first argument provides the name of the operator, and the second
5766 -- argument the signature that may match that of a standard operation.
5767 -- If the indicator is overriding, then the operator must match a
5768 -- predefined signature, because we know already that there is no
5769 -- explicit overridden operation.
5771 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
then
5772 if Must_Not_Override
(Spec
) then
5774 -- If this is not a primitive or a protected subprogram, then
5775 -- "not overriding" is illegal.
5778 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
5780 Error_Msg_N
("overriding indicator only allowed "
5781 & "if subprogram is primitive", Subp
);
5783 elsif Can_Override_Operator
(Subp
) then
5785 ("subprogram& overrides predefined operator ", Spec
, Subp
);
5788 elsif Must_Override
(Spec
) then
5789 if No
(Overridden_Operation
(Subp
))
5790 and then not Can_Override_Operator
(Subp
)
5792 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
5795 elsif not Error_Posted
(Subp
)
5796 and then Style_Check
5797 and then Can_Override_Operator
(Subp
)
5799 not Is_Predefined_File_Name
5800 (Unit_File_Name
(Get_Source_Unit
(Subp
)))
5802 -- If style checks are enabled, indicate that the indicator is
5803 -- missing. However, at the point of declaration, the type of
5804 -- which this is a primitive operation may be private, in which
5805 -- case the indicator would be premature.
5807 if Has_Private_Declaration
(Etype
(Subp
))
5808 or else Has_Private_Declaration
(Etype
(First_Formal
(Subp
)))
5812 Style
.Missing_Overriding
(Decl
, Subp
);
5816 elsif Must_Override
(Spec
) then
5817 if Ekind
(Subp
) = E_Entry
then
5818 Error_Msg_NE
("entry & is not overriding", Spec
, Subp
);
5820 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
5823 -- If the operation is marked "not overriding" and it's not primitive
5824 -- then an error is issued, unless this is an operation of a task or
5825 -- protected type (RM05-8.3.1(3/2-4/2)). Error cases where "overriding"
5826 -- has been specified have already been checked above.
5828 elsif Must_Not_Override
(Spec
)
5829 and then not Is_Primitive
5830 and then Ekind
(Subp
) /= E_Entry
5831 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
5834 ("overriding indicator only allowed if subprogram is primitive",
5838 end Check_Overriding_Indicator
;
5844 -- Note: this procedure needs to know far too much about how the expander
5845 -- messes with exceptions. The use of the flag Exception_Junk and the
5846 -- incorporation of knowledge of Exp_Ch11.Expand_Local_Exception_Handlers
5847 -- works, but is not very clean. It would be better if the expansion
5848 -- routines would leave Original_Node working nicely, and we could use
5849 -- Original_Node here to ignore all the peculiar expander messing ???
5851 procedure Check_Returns
5855 Proc
: Entity_Id
:= Empty
)
5859 procedure Check_Statement_Sequence
(L
: List_Id
);
5860 -- Internal recursive procedure to check a list of statements for proper
5861 -- termination by a return statement (or a transfer of control or a
5862 -- compound statement that is itself internally properly terminated).
5864 ------------------------------
5865 -- Check_Statement_Sequence --
5866 ------------------------------
5868 procedure Check_Statement_Sequence
(L
: List_Id
) is
5873 function Assert_False
return Boolean;
5874 -- Returns True if Last_Stm is a pragma Assert (False) that has been
5875 -- rewritten as a null statement when assertions are off. The assert
5876 -- is not active, but it is still enough to kill the warning.
5882 function Assert_False
return Boolean is
5883 Orig
: constant Node_Id
:= Original_Node
(Last_Stm
);
5886 if Nkind
(Orig
) = N_Pragma
5887 and then Pragma_Name
(Orig
) = Name_Assert
5888 and then not Error_Posted
(Orig
)
5891 Arg
: constant Node_Id
:=
5892 First
(Pragma_Argument_Associations
(Orig
));
5893 Exp
: constant Node_Id
:= Expression
(Arg
);
5895 return Nkind
(Exp
) = N_Identifier
5896 and then Chars
(Exp
) = Name_False
;
5906 Raise_Exception_Call
: Boolean;
5907 -- Set True if statement sequence terminated by Raise_Exception call
5908 -- or a Reraise_Occurrence call.
5910 -- Start of processing for Check_Statement_Sequence
5913 Raise_Exception_Call
:= False;
5915 -- Get last real statement
5917 Last_Stm
:= Last
(L
);
5919 -- Deal with digging out exception handler statement sequences that
5920 -- have been transformed by the local raise to goto optimization.
5921 -- See Exp_Ch11.Expand_Local_Exception_Handlers for details. If this
5922 -- optimization has occurred, we are looking at something like:
5925 -- original stmts in block
5929 -- goto L1; | omitted if No_Exception_Propagation
5934 -- goto L3; -- skip handler when exception not raised
5936 -- <<L1>> -- target label for local exception
5950 -- and what we have to do is to dig out the estmts1 and estmts2
5951 -- sequences (which were the original sequences of statements in
5952 -- the exception handlers) and check them.
5954 if Nkind
(Last_Stm
) = N_Label
and then Exception_Junk
(Last_Stm
) then
5959 exit when Nkind
(Stm
) /= N_Block_Statement
;
5960 exit when not Exception_Junk
(Stm
);
5963 exit when Nkind
(Stm
) /= N_Label
;
5964 exit when not Exception_Junk
(Stm
);
5965 Check_Statement_Sequence
5966 (Statements
(Handled_Statement_Sequence
(Next
(Stm
))));
5971 exit when Nkind
(Stm
) /= N_Goto_Statement
;
5972 exit when not Exception_Junk
(Stm
);
5976 -- Don't count pragmas
5978 while Nkind
(Last_Stm
) = N_Pragma
5980 -- Don't count call to SS_Release (can happen after Raise_Exception)
5983 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
5985 Nkind
(Name
(Last_Stm
)) = N_Identifier
5987 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
5989 -- Don't count exception junk
5992 (Nkind_In
(Last_Stm
, N_Goto_Statement
,
5994 N_Object_Declaration
)
5995 and then Exception_Junk
(Last_Stm
))
5996 or else Nkind
(Last_Stm
) in N_Push_xxx_Label
5997 or else Nkind
(Last_Stm
) in N_Pop_xxx_Label
5999 -- Inserted code, such as finalization calls, is irrelevant: we only
6000 -- need to check original source.
6002 or else Is_Rewrite_Insertion
(Last_Stm
)
6007 -- Here we have the "real" last statement
6009 Kind
:= Nkind
(Last_Stm
);
6011 -- Transfer of control, OK. Note that in the No_Return procedure
6012 -- case, we already diagnosed any explicit return statements, so
6013 -- we can treat them as OK in this context.
6015 if Is_Transfer
(Last_Stm
) then
6018 -- Check cases of explicit non-indirect procedure calls
6020 elsif Kind
= N_Procedure_Call_Statement
6021 and then Is_Entity_Name
(Name
(Last_Stm
))
6023 -- Check call to Raise_Exception procedure which is treated
6024 -- specially, as is a call to Reraise_Occurrence.
6026 -- We suppress the warning in these cases since it is likely that
6027 -- the programmer really does not expect to deal with the case
6028 -- of Null_Occurrence, and thus would find a warning about a
6029 -- missing return curious, and raising Program_Error does not
6030 -- seem such a bad behavior if this does occur.
6032 -- Note that in the Ada 2005 case for Raise_Exception, the actual
6033 -- behavior will be to raise Constraint_Error (see AI-329).
6035 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
6037 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
6039 Raise_Exception_Call
:= True;
6041 -- For Raise_Exception call, test first argument, if it is
6042 -- an attribute reference for a 'Identity call, then we know
6043 -- that the call cannot possibly return.
6046 Arg
: constant Node_Id
:=
6047 Original_Node
(First_Actual
(Last_Stm
));
6049 if Nkind
(Arg
) = N_Attribute_Reference
6050 and then Attribute_Name
(Arg
) = Name_Identity
6057 -- If statement, need to look inside if there is an else and check
6058 -- each constituent statement sequence for proper termination.
6060 elsif Kind
= N_If_Statement
6061 and then Present
(Else_Statements
(Last_Stm
))
6063 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
6064 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
6066 if Present
(Elsif_Parts
(Last_Stm
)) then
6068 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
6071 while Present
(Elsif_Part
) loop
6072 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
6080 -- Case statement, check each case for proper termination
6082 elsif Kind
= N_Case_Statement
then
6086 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
6087 while Present
(Case_Alt
) loop
6088 Check_Statement_Sequence
(Statements
(Case_Alt
));
6089 Next_Non_Pragma
(Case_Alt
);
6095 -- Block statement, check its handled sequence of statements
6097 elsif Kind
= N_Block_Statement
then
6103 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
6112 -- Loop statement. If there is an iteration scheme, we can definitely
6113 -- fall out of the loop. Similarly if there is an exit statement, we
6114 -- can fall out. In either case we need a following return.
6116 elsif Kind
= N_Loop_Statement
then
6117 if Present
(Iteration_Scheme
(Last_Stm
))
6118 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
6122 -- A loop with no exit statement or iteration scheme is either
6123 -- an infinite loop, or it has some other exit (raise/return).
6124 -- In either case, no warning is required.
6130 -- Timed entry call, check entry call and delay alternatives
6132 -- Note: in expanded code, the timed entry call has been converted
6133 -- to a set of expanded statements on which the check will work
6134 -- correctly in any case.
6136 elsif Kind
= N_Timed_Entry_Call
then
6138 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
6139 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
6142 -- If statement sequence of entry call alternative is missing,
6143 -- then we can definitely fall through, and we post the error
6144 -- message on the entry call alternative itself.
6146 if No
(Statements
(ECA
)) then
6149 -- If statement sequence of delay alternative is missing, then
6150 -- we can definitely fall through, and we post the error
6151 -- message on the delay alternative itself.
6153 -- Note: if both ECA and DCA are missing the return, then we
6154 -- post only one message, should be enough to fix the bugs.
6155 -- If not we will get a message next time on the DCA when the
6158 elsif No
(Statements
(DCA
)) then
6161 -- Else check both statement sequences
6164 Check_Statement_Sequence
(Statements
(ECA
));
6165 Check_Statement_Sequence
(Statements
(DCA
));
6170 -- Conditional entry call, check entry call and else part
6172 -- Note: in expanded code, the conditional entry call has been
6173 -- converted to a set of expanded statements on which the check
6174 -- will work correctly in any case.
6176 elsif Kind
= N_Conditional_Entry_Call
then
6178 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
6181 -- If statement sequence of entry call alternative is missing,
6182 -- then we can definitely fall through, and we post the error
6183 -- message on the entry call alternative itself.
6185 if No
(Statements
(ECA
)) then
6188 -- Else check statement sequence and else part
6191 Check_Statement_Sequence
(Statements
(ECA
));
6192 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
6198 -- If we fall through, issue appropriate message
6202 -- Kill warning if last statement is a raise exception call,
6203 -- or a pragma Assert (False). Note that with assertions enabled,
6204 -- such a pragma has been converted into a raise exception call
6205 -- already, so the Assert_False is for the assertions off case.
6207 if not Raise_Exception_Call
and then not Assert_False
then
6209 -- In GNATprove mode, it is an error to have a missing return
6211 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6213 -- Issue error message or warning
6216 ("RETURN statement missing following this statement<<!",
6219 ("\Program_Error ]<<!", Last_Stm
);
6222 -- Note: we set Err even though we have not issued a warning
6223 -- because we still have a case of a missing return. This is
6224 -- an extremely marginal case, probably will never be noticed
6225 -- but we might as well get it right.
6229 -- Otherwise we have the case of a procedure marked No_Return
6232 if not Raise_Exception_Call
then
6233 if GNATprove_Mode
then
6235 ("implied return after this statement "
6236 & "would have raised Program_Error", Last_Stm
);
6239 ("implied return after this statement "
6240 & "will raise Program_Error??", Last_Stm
);
6243 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6245 ("\procedure & is marked as No_Return<<!", Last_Stm
, Proc
);
6249 RE
: constant Node_Id
:=
6250 Make_Raise_Program_Error
(Sloc
(Last_Stm
),
6251 Reason
=> PE_Implicit_Return
);
6253 Insert_After
(Last_Stm
, RE
);
6257 end Check_Statement_Sequence
;
6259 -- Start of processing for Check_Returns
6263 Check_Statement_Sequence
(Statements
(HSS
));
6265 if Present
(Exception_Handlers
(HSS
)) then
6266 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
6267 while Present
(Handler
) loop
6268 Check_Statement_Sequence
(Statements
(Handler
));
6269 Next_Non_Pragma
(Handler
);
6274 ----------------------------
6275 -- Check_Subprogram_Order --
6276 ----------------------------
6278 procedure Check_Subprogram_Order
(N
: Node_Id
) is
6280 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
6281 -- This is used to check if S1 > S2 in the sense required by this test,
6282 -- for example nameab < namec, but name2 < name10.
6284 -----------------------------
6285 -- Subprogram_Name_Greater --
6286 -----------------------------
6288 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
6293 -- Deal with special case where names are identical except for a
6294 -- numerical suffix. These are handled specially, taking the numeric
6295 -- ordering from the suffix into account.
6298 while S1
(L1
) in '0' .. '9' loop
6303 while S2
(L2
) in '0' .. '9' loop
6307 -- If non-numeric parts non-equal, do straight compare
6309 if S1
(S1
'First .. L1
) /= S2
(S2
'First .. L2
) then
6312 -- If non-numeric parts equal, compare suffixed numeric parts. Note
6313 -- that a missing suffix is treated as numeric zero in this test.
6317 while L1
< S1
'Last loop
6319 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
6323 while L2
< S2
'Last loop
6325 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
6330 end Subprogram_Name_Greater
;
6332 -- Start of processing for Check_Subprogram_Order
6335 -- Check body in alpha order if this is option
6338 and then Style_Check_Order_Subprograms
6339 and then Nkind
(N
) = N_Subprogram_Body
6340 and then Comes_From_Source
(N
)
6341 and then In_Extended_Main_Source_Unit
(N
)
6345 renames Scope_Stack
.Table
6346 (Scope_Stack
.Last
).Last_Subprogram_Name
;
6348 Body_Id
: constant Entity_Id
:=
6349 Defining_Entity
(Specification
(N
));
6352 Get_Decoded_Name_String
(Chars
(Body_Id
));
6355 if Subprogram_Name_Greater
6356 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
6358 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
6364 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
6367 end Check_Subprogram_Order;
6369 ------------------------------
6370 -- Check_Subtype_Conformant --
6371 ------------------------------
6373 procedure Check_Subtype_Conformant
6374 (New_Id : Entity_Id;
6376 Err_Loc : Node_Id := Empty;
6377 Skip_Controlling_Formals : Boolean := False;
6378 Get_Inst : Boolean := False)
6381 pragma Warnings (Off, Result);
6384 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc,
6385 Skip_Controlling_Formals => Skip_Controlling_Formals,
6386 Get_Inst => Get_Inst);
6387 end Check_Subtype_Conformant;
6389 ---------------------------
6390 -- Check_Type_Conformant --
6391 ---------------------------
6393 procedure Check_Type_Conformant
6394 (New_Id : Entity_Id;
6396 Err_Loc : Node_Id := Empty)
6399 pragma Warnings (Off, Result);
6402 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
6403 end Check_Type_Conformant;
6405 ---------------------------
6406 -- Can_Override_Operator --
6407 ---------------------------
6409 function Can_Override_Operator (Subp : Entity_Id) return Boolean is
6413 if Nkind (Subp) /= N_Defining_Operator_Symbol then
6417 Typ := Base_Type (Etype (First_Formal (Subp)));
6419 -- Check explicitly that the operation is a primitive of the type
6421 return Operator_Matches_Spec (Subp, Subp)
6422 and then not Is_Generic_Type (Typ)
6423 and then Scope (Subp) = Scope (Typ)
6424 and then not Is_Class_Wide_Type (Typ);
6426 end Can_Override_Operator;
6428 ----------------------
6429 -- Conforming_Types --
6430 ----------------------
6432 function Conforming_Types
6435 Ctype : Conformance_Type;
6436 Get_Inst : Boolean := False) return Boolean
6438 Type_1 : Entity_Id := T1;
6439 Type_2 : Entity_Id := T2;
6440 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
6442 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
6443 -- If neither T1 nor T2 are generic actual types, or if they are in
6444 -- different scopes (e.g. parent and child instances), then verify that
6445 -- the base types are equal. Otherwise T1 and T2 must be on the same
6446 -- subtype chain. The whole purpose of this procedure is to prevent
6447 -- spurious ambiguities in an instantiation that may arise if two
6448 -- distinct generic types are instantiated with the same actual.
6450 function Find_Designated_Type (T : Entity_Id) return Entity_Id;
6451 -- An access parameter can designate an incomplete type. If the
6452 -- incomplete type is the limited view of a type from a limited_
6453 -- with_clause, check whether the non-limited view is available. If
6454 -- it is a (non-limited) incomplete type, get the full view.
6456 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean;
6457 -- Returns True if and only if either T1 denotes a limited view of T2
6458 -- or T2 denotes a limited view of T1. This can arise when the limited
6459 -- with view of a type is used in a subprogram declaration and the
6460 -- subprogram body is in the scope of a regular with clause for the
6461 -- same unit. In such a case, the two type entities can be considered
6462 -- identical for purposes of conformance checking.
6464 ----------------------
6465 -- Base_Types_Match --
6466 ----------------------
6468 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
6469 BT1 : constant Entity_Id := Base_Type (T1);
6470 BT2 : constant Entity_Id := Base_Type (T2);
6476 elsif BT1 = BT2 then
6478 -- The following is too permissive. A more precise test should
6479 -- check that the generic actual is an ancestor subtype of the
6482 -- See code in Find_Corresponding_Spec that applies an additional
6483 -- filter to handle accidental amiguities in instances.
6485 return not Is_Generic_Actual_Type (T1)
6486 or else not Is_Generic_Actual_Type (T2)
6487 or else Scope (T1) /= Scope (T2);
6489 -- If T2 is a generic actual type it is declared as the subtype of
6490 -- the actual. If that actual is itself a subtype we need to use its
6491 -- own base type to check for compatibility.
6493 elsif Ekind (BT2) = Ekind (T2) and then BT1 = Base_Type (BT2) then
6496 elsif Ekind (BT1) = Ekind (T1) and then BT2 = Base_Type (BT1) then
6502 end Base_Types_Match;
6504 --------------------------
6505 -- Find_Designated_Type --
6506 --------------------------
6508 function Find_Designated_Type (T : Entity_Id) return Entity_Id is
6512 Desig := Directly_Designated_Type (T);
6514 if Ekind (Desig) = E_Incomplete_Type then
6516 -- If regular incomplete type, get full view if available
6518 if Present (Full_View (Desig)) then
6519 Desig := Full_View (Desig);
6521 -- If limited view of a type, get non-limited view if available,
6522 -- and check again for a regular incomplete type.
6524 elsif Present (Non_Limited_View (Desig)) then
6525 Desig := Get_Full_View (Non_Limited_View (Desig));
6530 end Find_Designated_Type;
6532 -------------------------------
6533 -- Matches_Limited_With_View --
6534 -------------------------------
6536 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean is
6538 -- In some cases a type imported through a limited_with clause, and
6539 -- its nonlimited view are both visible, for example in an anonymous
6540 -- access-to-class-wide type in a formal. Both entities designate the
6543 if From_Limited_With (T1) and then T2 = Available_View (T1) then
6546 elsif From_Limited_With (T2) and then T1 = Available_View (T2) then
6549 elsif From_Limited_With (T1)
6550 and then From_Limited_With (T2)
6551 and then Available_View (T1) = Available_View (T2)
6558 end Matches_Limited_With_View;
6560 -- Start of processing for Conforming_Types
6563 -- The context is an instance association for a formal access-to-
6564 -- subprogram type; the formal parameter types require mapping because
6565 -- they may denote other formal parameters of the generic unit.
6568 Type_1 := Get_Instance_Of (T1);
6569 Type_2 := Get_Instance_Of (T2);
6572 -- If one of the types is a view of the other introduced by a limited
6573 -- with clause, treat these as conforming for all purposes.
6575 if Matches_Limited_With_View (T1, T2) then
6578 elsif Base_Types_Match (Type_1, Type_2) then
6579 return Ctype <= Mode_Conformant
6580 or else Subtypes_Statically_Match (Type_1, Type_2);
6582 elsif Is_Incomplete_Or_Private_Type (Type_1)
6583 and then Present (Full_View (Type_1))
6584 and then Base_Types_Match (Full_View (Type_1), Type_2)
6586 return Ctype <= Mode_Conformant
6587 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
6589 elsif Ekind (Type_2) = E_Incomplete_Type
6590 and then Present (Full_View (Type_2))
6591 and then Base_Types_Match (Type_1, Full_View (Type_2))
6593 return Ctype <= Mode_Conformant
6594 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
6596 elsif Is_Private_Type (Type_2)
6597 and then In_Instance
6598 and then Present (Full_View (Type_2))
6599 and then Base_Types_Match (Type_1, Full_View (Type_2))
6601 return Ctype <= Mode_Conformant
6602 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
6605 -- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be
6606 -- treated recursively because they carry a signature. As far as
6607 -- conformance is concerned, convention plays no role, and either
6608 -- or both could be access to protected subprograms.
6610 Are_Anonymous_Access_To_Subprogram_Types :=
6611 Ekind_In (Type_1, E_Anonymous_Access_Subprogram_Type,
6612 E_Anonymous_Access_Protected_Subprogram_Type)
6614 Ekind_In (Type_2, E_Anonymous_Access_Subprogram_Type,
6615 E_Anonymous_Access_Protected_Subprogram_Type);
6617 -- Test anonymous access type case. For this case, static subtype
6618 -- matching is required for mode conformance (RM 6.3.1(15)). We check
6619 -- the base types because we may have built internal subtype entities
6620 -- to handle null-excluding types (see Process_Formals).
6622 if (Ekind (Base_Type (Type_1)) = E_Anonymous_Access_Type
6624 Ekind (Base_Type (Type_2)) = E_Anonymous_Access_Type)
6626 -- Ada 2005 (AI-254)
6628 or else Are_Anonymous_Access_To_Subprogram_Types
6631 Desig_1 : Entity_Id;
6632 Desig_2 : Entity_Id;
6635 -- In Ada 2005, access constant indicators must match for
6636 -- subtype conformance.
6638 if Ada_Version >= Ada_2005
6639 and then Ctype >= Subtype_Conformant
6641 Is_Access_Constant (Type_1) /= Is_Access_Constant (Type_2)
6646 Desig_1 := Find_Designated_Type (Type_1);
6647 Desig_2 := Find_Designated_Type (Type_2);
6649 -- If the context is an instance association for a formal
6650 -- access-to-subprogram type; formal access parameter designated
6651 -- types require mapping because they may denote other formal
6652 -- parameters of the generic unit.
6655 Desig_1 := Get_Instance_Of (Desig_1);
6656 Desig_2 := Get_Instance_Of (Desig_2);
6659 -- It is possible for a Class_Wide_Type to be introduced for an
6660 -- incomplete type, in which case there is a separate class_ wide
6661 -- type for the full view. The types conform if their Etypes
6662 -- conform, i.e. one may be the full view of the other. This can
6663 -- only happen in the context of an access parameter, other uses
6664 -- of an incomplete Class_Wide_Type are illegal.
6666 if Is_Class_Wide_Type (Desig_1)
6668 Is_Class_Wide_Type (Desig_2)
6672 (Etype (Base_Type (Desig_1)),
6673 Etype (Base_Type (Desig_2)), Ctype);
6675 elsif Are_Anonymous_Access_To_Subprogram_Types then
6676 if Ada_Version < Ada_2005 then
6677 return Ctype = Type_Conformant
6679 Subtypes_Statically_Match (Desig_1, Desig_2);
6681 -- We must check the conformance of the signatures themselves
6685 Conformant : Boolean;
6688 (Desig_1, Desig_2, Ctype, False, Conformant);
6694 return Base_Type (Desig_1) = Base_Type (Desig_2)
6695 and then (Ctype = Type_Conformant
6697 Subtypes_Statically_Match (Desig_1, Desig_2));
6701 -- Otherwise definitely no match
6704 if ((Ekind (Type_1) = E_Anonymous_Access_Type
6705 and then Is_Access_Type (Type_2))
6706 or else (Ekind (Type_2) = E_Anonymous_Access_Type
6707 and then Is_Access_Type (Type_1)))
6710 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
6712 May_Hide_Profile := True;
6717 end Conforming_Types;
6719 --------------------------
6720 -- Create_Extra_Formals --
6721 --------------------------
6723 procedure Create_Extra_Formals (E : Entity_Id) is
6725 First_Extra : Entity_Id := Empty;
6726 Last_Extra : Entity_Id;
6727 Formal_Type : Entity_Id;
6728 P_Formal : Entity_Id := Empty;
6730 function Add_Extra_Formal
6731 (Assoc_Entity : Entity_Id;
6734 Suffix : String) return Entity_Id;
6735 -- Add an extra formal to the current list of formals and extra formals.
6736 -- The extra formal is added to the end of the list of extra formals,
6737 -- and also returned as the result. These formals are always of mode IN.
6738 -- The new formal has the type Typ, is declared in Scope, and its name
6739 -- is given by a concatenation of the name of Assoc_Entity and Suffix.
6740 -- The following suffixes are currently used. They should not be changed
6741 -- without coordinating with CodePeer, which makes use of these to
6742 -- provide better messages.
6744 -- O denotes the Constrained bit.
6745 -- L denotes the accessibility level.
6746 -- BIP_xxx denotes an extra formal for a build-in-place function. See
6747 -- the full list in exp_ch6.BIP_Formal_Kind.
6749 ----------------------
6750 -- Add_Extra_Formal --
6751 ----------------------
6753 function Add_Extra_Formal
6754 (Assoc_Entity : Entity_Id;
6757 Suffix : String) return Entity_Id
6759 EF : constant Entity_Id :=
6760 Make_Defining_Identifier (Sloc (Assoc_Entity),
6761 Chars => New_External_Name (Chars (Assoc_Entity),
6765 -- A little optimization. Never generate an extra formal for the
6766 -- _init operand of an initialization procedure, since it could
6769 if Chars (Formal) = Name_uInit then
6773 Set_Ekind (EF, E_In_Parameter);
6774 Set_Actual_Subtype (EF, Typ);
6775 Set_Etype (EF, Typ);
6776 Set_Scope (EF, Scope);
6777 Set_Mechanism (EF, Default_Mechanism);
6778 Set_Formal_Validity (EF);
6780 if No (First_Extra) then
6782 Set_Extra_Formals (Scope, First_Extra);
6785 if Present (Last_Extra) then
6786 Set_Extra_Formal (Last_Extra, EF);
6792 end Add_Extra_Formal;
6794 -- Start of processing for Create_Extra_Formals
6797 -- We never generate extra formals if expansion is not active because we
6798 -- don't need them unless we are generating code.
6800 if not Expander_Active then
6804 -- No need to generate extra formals in interface thunks whose target
6805 -- primitive has no extra formals.
6807 if Is_Thunk (E) and then No (Extra_Formals (Thunk_Entity (E))) then
6811 -- If this is a derived subprogram then the subtypes of the parent
6812 -- subprogram's formal parameters will be used to determine the need
6813 -- for extra formals.
6815 if Is_Overloadable (E) and then Present (Alias (E)) then
6816 P_Formal := First_Formal (Alias (E));
6819 Last_Extra := Empty;
6820 Formal := First_Formal (E);
6821 while Present (Formal) loop
6822 Last_Extra := Formal;
6823 Next_Formal (Formal);
6826 -- If Extra_formals were already created, don't do it again. This
6827 -- situation may arise for subprogram types created as part of
6828 -- dispatching calls (see Expand_Dispatching_Call)
6830 if Present (Last_Extra) and then Present (Extra_Formal (Last_Extra)) then
6834 -- If the subprogram is a predefined dispatching subprogram then don't
6835 -- generate any extra constrained or accessibility level formals. In
6836 -- general we suppress these for internal subprograms (by not calling
6837 -- Freeze_Subprogram and Create_Extra_Formals at all), but internally
6838 -- generated stream attributes do get passed through because extra
6839 -- build-in-place formals are needed in some cases (limited 'Input
).
6841 if Is_Predefined_Internal_Operation
(E
) then
6842 goto Test_For_Func_Result_Extras
;
6845 Formal
:= First_Formal
(E
);
6846 while Present
(Formal
) loop
6848 -- Create extra formal for supporting the attribute 'Constrained.
6849 -- The case of a private type view without discriminants also
6850 -- requires the extra formal if the underlying type has defaulted
6853 if Ekind
(Formal
) /= E_In_Parameter
then
6854 if Present
(P_Formal
) then
6855 Formal_Type
:= Etype
(P_Formal
);
6857 Formal_Type
:= Etype
(Formal
);
6860 -- Do not produce extra formals for Unchecked_Union parameters.
6861 -- Jump directly to the end of the loop.
6863 if Is_Unchecked_Union
(Base_Type
(Formal_Type
)) then
6864 goto Skip_Extra_Formal_Generation
;
6867 if not Has_Discriminants
(Formal_Type
)
6868 and then Ekind
(Formal_Type
) in Private_Kind
6869 and then Present
(Underlying_Type
(Formal_Type
))
6871 Formal_Type
:= Underlying_Type
(Formal_Type
);
6874 -- Suppress the extra formal if formal's subtype is constrained or
6875 -- indefinite, or we're compiling for Ada 2012 and the underlying
6876 -- type is tagged and limited. In Ada 2012, a limited tagged type
6877 -- can have defaulted discriminants, but 'Constrained is required
6878 -- to return True, so the formal is never needed (see AI05-0214).
6879 -- Note that this ensures consistency of calling sequences for
6880 -- dispatching operations when some types in a class have defaults
6881 -- on discriminants and others do not (and requiring the extra
6882 -- formal would introduce distributed overhead).
6884 -- If the type does not have a completion yet, treat as prior to
6885 -- Ada 2012 for consistency.
6887 if Has_Discriminants
(Formal_Type
)
6888 and then not Is_Constrained
(Formal_Type
)
6889 and then not Is_Indefinite_Subtype
(Formal_Type
)
6890 and then (Ada_Version
< Ada_2012
6891 or else No
(Underlying_Type
(Formal_Type
))
6893 (Is_Limited_Type
(Formal_Type
)
6896 (Underlying_Type
(Formal_Type
)))))
6898 Set_Extra_Constrained
6899 (Formal
, Add_Extra_Formal
(Formal
, Standard_Boolean
, E
, "O"));
6903 -- Create extra formal for supporting accessibility checking. This
6904 -- is done for both anonymous access formals and formals of named
6905 -- access types that are marked as controlling formals. The latter
6906 -- case can occur when Expand_Dispatching_Call creates a subprogram
6907 -- type and substitutes the types of access-to-class-wide actuals
6908 -- for the anonymous access-to-specific-type of controlling formals.
6909 -- Base_Type is applied because in cases where there is a null
6910 -- exclusion the formal may have an access subtype.
6912 -- This is suppressed if we specifically suppress accessibility
6913 -- checks at the package level for either the subprogram, or the
6914 -- package in which it resides. However, we do not suppress it
6915 -- simply if the scope has accessibility checks suppressed, since
6916 -- this could cause trouble when clients are compiled with a
6917 -- different suppression setting. The explicit checks at the
6918 -- package level are safe from this point of view.
6920 if (Ekind
(Base_Type
(Etype
(Formal
))) = E_Anonymous_Access_Type
6921 or else (Is_Controlling_Formal
(Formal
)
6922 and then Is_Access_Type
(Base_Type
(Etype
(Formal
)))))
6924 (Explicit_Suppress
(E
, Accessibility_Check
)
6926 Explicit_Suppress
(Scope
(E
), Accessibility_Check
))
6929 or else Present
(Extra_Accessibility
(P_Formal
)))
6931 Set_Extra_Accessibility
6932 (Formal
, Add_Extra_Formal
(Formal
, Standard_Natural
, E
, "L"));
6935 -- This label is required when skipping extra formal generation for
6936 -- Unchecked_Union parameters.
6938 <<Skip_Extra_Formal_Generation
>>
6940 if Present
(P_Formal
) then
6941 Next_Formal
(P_Formal
);
6944 Next_Formal
(Formal
);
6947 <<Test_For_Func_Result_Extras
>>
6949 -- Ada 2012 (AI05-234): "the accessibility level of the result of a
6950 -- function call is ... determined by the point of call ...".
6952 if Needs_Result_Accessibility_Level
(E
) then
6953 Set_Extra_Accessibility_Of_Result
6954 (E
, Add_Extra_Formal
(E
, Standard_Natural
, E
, "L"));
6957 -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add
6958 -- appropriate extra formals. See type Exp_Ch6.BIP_Formal_Kind.
6960 if Ada_Version
>= Ada_2005
and then Is_Build_In_Place_Function
(E
) then
6962 Result_Subt
: constant Entity_Id
:= Etype
(E
);
6963 Full_Subt
: constant Entity_Id
:= Available_View
(Result_Subt
);
6964 Formal_Typ
: Entity_Id
;
6966 Discard
: Entity_Id
;
6967 pragma Warnings
(Off
, Discard
);
6970 -- In the case of functions with unconstrained result subtypes,
6971 -- add a 4-state formal indicating whether the return object is
6972 -- allocated by the caller (1), or should be allocated by the
6973 -- callee on the secondary stack (2), in the global heap (3), or
6974 -- in a user-defined storage pool (4). For the moment we just use
6975 -- Natural for the type of this formal. Note that this formal
6976 -- isn't usually needed in the case where the result subtype is
6977 -- constrained, but it is needed when the function has a tagged
6978 -- result, because generally such functions can be called in a
6979 -- dispatching context and such calls must be handled like calls
6980 -- to a class-wide function.
6982 if Needs_BIP_Alloc_Form
(E
) then
6985 (E
, Standard_Natural
,
6986 E
, BIP_Formal_Suffix
(BIP_Alloc_Form
));
6988 -- Add BIP_Storage_Pool, in case BIP_Alloc_Form indicates to
6989 -- use a user-defined pool. This formal is not added on
6990 -- .NET/JVM/ZFP as those targets do not support pools.
6992 if VM_Target
= No_VM
6993 and then RTE_Available
(RE_Root_Storage_Pool_Ptr
)
6997 (E
, RTE
(RE_Root_Storage_Pool_Ptr
),
6998 E
, BIP_Formal_Suffix
(BIP_Storage_Pool
));
7002 -- In the case of functions whose result type needs finalization,
7003 -- add an extra formal which represents the finalization master.
7005 if Needs_BIP_Finalization_Master
(E
) then
7008 (E
, RTE
(RE_Finalization_Master_Ptr
),
7009 E
, BIP_Formal_Suffix
(BIP_Finalization_Master
));
7012 -- When the result type contains tasks, add two extra formals: the
7013 -- master of the tasks to be created, and the caller's activation
7016 if Has_Task
(Full_Subt
) then
7019 (E
, RTE
(RE_Master_Id
),
7020 E
, BIP_Formal_Suffix
(BIP_Task_Master
));
7023 (E
, RTE
(RE_Activation_Chain_Access
),
7024 E
, BIP_Formal_Suffix
(BIP_Activation_Chain
));
7027 -- All build-in-place functions get an extra formal that will be
7028 -- passed the address of the return object within the caller.
7031 Create_Itype
(E_Anonymous_Access_Type
, E
, Scope_Id
=> Scope
(E
));
7033 Set_Directly_Designated_Type
(Formal_Typ
, Result_Subt
);
7034 Set_Etype
(Formal_Typ
, Formal_Typ
);
7035 Set_Depends_On_Private
7036 (Formal_Typ
, Has_Private_Component
(Formal_Typ
));
7037 Set_Is_Public
(Formal_Typ
, Is_Public
(Scope
(Formal_Typ
)));
7038 Set_Is_Access_Constant
(Formal_Typ
, False);
7040 -- Ada 2005 (AI-50217): Propagate the attribute that indicates
7041 -- the designated type comes from the limited view (for back-end
7044 Set_From_Limited_With
7045 (Formal_Typ
, From_Limited_With
(Result_Subt
));
7047 Layout_Type
(Formal_Typ
);
7051 (E
, Formal_Typ
, E
, BIP_Formal_Suffix
(BIP_Object_Access
));
7054 end Create_Extra_Formals
;
7056 -----------------------------
7057 -- Enter_Overloaded_Entity --
7058 -----------------------------
7060 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
7061 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
7062 C_E
: Entity_Id
:= Current_Entity
(S
);
7066 Set_Has_Homonym
(E
);
7067 Set_Has_Homonym
(S
);
7070 Set_Is_Immediately_Visible
(S
);
7071 Set_Scope
(S
, Current_Scope
);
7073 -- Chain new entity if front of homonym in current scope, so that
7074 -- homonyms are contiguous.
7076 if Present
(E
) and then E
/= C_E
then
7077 while Homonym
(C_E
) /= E
loop
7078 C_E
:= Homonym
(C_E
);
7081 Set_Homonym
(C_E
, S
);
7085 Set_Current_Entity
(S
);
7090 if Is_Inherited_Operation
(S
) then
7091 Append_Inherited_Subprogram
(S
);
7093 Append_Entity
(S
, Current_Scope
);
7096 Set_Public_Status
(S
);
7098 if Debug_Flag_E
then
7099 Write_Str
("New overloaded entity chain: ");
7100 Write_Name
(Chars
(S
));
7103 while Present
(E
) loop
7104 Write_Str
(" "); Write_Int
(Int
(E
));
7111 -- Generate warning for hiding
7114 and then Comes_From_Source
(S
)
7115 and then In_Extended_Main_Source_Unit
(S
)
7122 -- Warn unless genuine overloading. Do not emit warning on
7123 -- hiding predefined operators in Standard (these are either an
7124 -- (artifact of our implicit declarations, or simple noise) but
7125 -- keep warning on a operator defined on a local subtype, because
7126 -- of the real danger that different operators may be applied in
7127 -- various parts of the program.
7129 -- Note that if E and S have the same scope, there is never any
7130 -- hiding. Either the two conflict, and the program is illegal,
7131 -- or S is overriding an implicit inherited subprogram.
7133 if Scope
(E
) /= Scope
(S
)
7134 and then (not Is_Overloadable
(E
)
7135 or else Subtype_Conformant
(E
, S
))
7136 and then (Is_Immediately_Visible
(E
)
7138 Is_Potentially_Use_Visible
(S
))
7140 if Scope
(E
) /= Standard_Standard
then
7141 Error_Msg_Sloc
:= Sloc
(E
);
7142 Error_Msg_N
("declaration of & hides one #?h?", S
);
7144 elsif Nkind
(S
) = N_Defining_Operator_Symbol
7146 Scope
(Base_Type
(Etype
(First_Formal
(S
)))) /= Scope
(S
)
7149 ("declaration of & hides predefined operator?h?", S
);
7154 end Enter_Overloaded_Entity
;
7156 -----------------------------
7157 -- Check_Untagged_Equality --
7158 -----------------------------
7160 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
) is
7161 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Eq_Op
));
7162 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Eq_Op
);
7166 -- This check applies only if we have a subprogram declaration with an
7167 -- untagged record type.
7169 if Nkind
(Decl
) /= N_Subprogram_Declaration
7170 or else not Is_Record_Type
(Typ
)
7171 or else Is_Tagged_Type
(Typ
)
7176 -- In Ada 2012 case, we will output errors or warnings depending on
7177 -- the setting of debug flag -gnatd.E.
7179 if Ada_Version
>= Ada_2012
then
7180 Error_Msg_Warn
:= Debug_Flag_Dot_EE
;
7182 -- In earlier versions of Ada, nothing to do unless we are warning on
7183 -- Ada 2012 incompatibilities (Warn_On_Ada_2012_Incompatibility set).
7186 if not Warn_On_Ada_2012_Compatibility
then
7191 -- Cases where the type has already been frozen
7193 if Is_Frozen
(Typ
) then
7195 -- If the type is not declared in a package, or if we are in the body
7196 -- of the package or in some other scope, the new operation is not
7197 -- primitive, and therefore legal, though suspicious. Should we
7198 -- generate a warning in this case ???
7200 if Ekind
(Scope
(Typ
)) /= E_Package
7201 or else Scope
(Typ
) /= Current_Scope
7205 -- If the type is a generic actual (sub)type, the operation is not
7206 -- primitive either because the base type is declared elsewhere.
7208 elsif Is_Generic_Actual_Type
(Typ
) then
7211 -- Here we have a definite error of declaration after freezing
7214 if Ada_Version
>= Ada_2012
then
7216 ("equality operator must be declared before type & is "
7217 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)<<", Eq_Op
, Typ
);
7219 -- In Ada 2012 mode with error turned to warning, output one
7220 -- more warning to warn that the equality operation may not
7221 -- compose. This is the consequence of ignoring the error.
7223 if Error_Msg_Warn
then
7224 Error_Msg_N
("\equality operation may not compose??", Eq_Op
);
7229 ("equality operator must be declared before type& is "
7230 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)?y?", Eq_Op
, Typ
);
7233 -- If we are in the package body, we could just move the
7234 -- declaration to the package spec, so add a message saying that.
7236 if In_Package_Body
(Scope
(Typ
)) then
7237 if Ada_Version
>= Ada_2012
then
7239 ("\move declaration to package spec<<", Eq_Op
);
7242 ("\move declaration to package spec (Ada 2012)?y?", Eq_Op
);
7245 -- Otherwise try to find the freezing point
7248 Obj_Decl
:= Next
(Parent
(Typ
));
7249 while Present
(Obj_Decl
) and then Obj_Decl
/= Decl
loop
7250 if Nkind
(Obj_Decl
) = N_Object_Declaration
7251 and then Etype
(Defining_Identifier
(Obj_Decl
)) = Typ
7253 -- Freezing point, output warnings
7255 if Ada_Version
>= Ada_2012
then
7257 ("type& is frozen by declaration??", Obj_Decl
, Typ
);
7259 ("\an equality operator cannot be declared after "
7264 ("type& is frozen by declaration (Ada 2012)?y?",
7267 ("\an equality operator cannot be declared after "
7268 & "this point (Ada 2012)?y?",
7280 -- Here if type is not frozen yet. It is illegal to have a primitive
7281 -- equality declared in the private part if the type is visible.
7283 elsif not In_Same_List
(Parent
(Typ
), Decl
)
7284 and then not Is_Limited_Type
(Typ
)
7286 -- Shouldn't we give an RM reference here???
7288 if Ada_Version
>= Ada_2012
then
7290 ("equality operator appears too late<<", Eq_Op
);
7293 ("equality operator appears too late (Ada 2012)?y?", Eq_Op
);
7296 -- No error detected
7301 end Check_Untagged_Equality
;
7303 -----------------------------
7304 -- Find_Corresponding_Spec --
7305 -----------------------------
7307 function Find_Corresponding_Spec
7309 Post_Error
: Boolean := True) return Entity_Id
7311 Spec
: constant Node_Id
:= Specification
(N
);
7312 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
7316 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean;
7317 -- Even if fully conformant, a body may depend on a generic actual when
7318 -- the spec does not, or vice versa, in which case they were distinct
7319 -- entities in the generic.
7321 -------------------------------
7322 -- Different_Generic_Profile --
7323 -------------------------------
7325 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean is
7328 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean;
7329 -- Check that the types of corresponding formals have the same
7330 -- generic actual if any. We have to account for subtypes of a
7331 -- generic formal, declared between a spec and a body, which may
7332 -- appear distinct in an instance but matched in the generic, and
7333 -- the subtype may be used either in the spec or the body of the
7334 -- subprogram being checked.
7336 -------------------------
7337 -- Same_Generic_Actual --
7338 -------------------------
7340 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean is
7342 function Is_Declared_Subtype
(S1
, S2
: Entity_Id
) return Boolean;
7343 -- Predicate to check whether S1 is a subtype of S2 in the source
7346 -------------------------
7347 -- Is_Declared_Subtype --
7348 -------------------------
7350 function Is_Declared_Subtype
(S1
, S2
: Entity_Id
) return Boolean is
7352 return Comes_From_Source
(Parent
(S1
))
7353 and then Nkind
(Parent
(S1
)) = N_Subtype_Declaration
7354 and then Is_Entity_Name
(Subtype_Indication
(Parent
(S1
)))
7355 and then Entity
(Subtype_Indication
(Parent
(S1
))) = S2
;
7356 end Is_Declared_Subtype
;
7358 -- Start of processing for Same_Generic_Actual
7361 return Is_Generic_Actual_Type
(T1
) = Is_Generic_Actual_Type
(T2
)
7362 or else Is_Declared_Subtype
(T1
, T2
)
7363 or else Is_Declared_Subtype
(T2
, T1
);
7364 end Same_Generic_Actual
;
7366 -- Start of processing for Different_Generic_Profile
7369 if not In_Instance
then
7372 elsif Ekind
(E
) = E_Function
7373 and then not Same_Generic_Actual
(Etype
(E
), Etype
(Designator
))
7378 F1
:= First_Formal
(Designator
);
7379 F2
:= First_Formal
(E
);
7380 while Present
(F1
) loop
7381 if not Same_Generic_Actual
(Etype
(F1
), Etype
(F2
)) then
7390 end Different_Generic_Profile
;
7392 -- Start of processing for Find_Corresponding_Spec
7395 E
:= Current_Entity
(Designator
);
7396 while Present
(E
) loop
7398 -- We are looking for a matching spec. It must have the same scope,
7399 -- and the same name, and either be type conformant, or be the case
7400 -- of a library procedure spec and its body (which belong to one
7401 -- another regardless of whether they are type conformant or not).
7403 if Scope
(E
) = Current_Scope
then
7404 if Current_Scope
= Standard_Standard
7405 or else (Ekind
(E
) = Ekind
(Designator
)
7406 and then Type_Conformant
(E
, Designator
))
7408 -- Within an instantiation, we know that spec and body are
7409 -- subtype conformant, because they were subtype conformant in
7410 -- the generic. We choose the subtype-conformant entity here as
7411 -- well, to resolve spurious ambiguities in the instance that
7412 -- were not present in the generic (i.e. when two different
7413 -- types are given the same actual). If we are looking for a
7414 -- spec to match a body, full conformance is expected.
7417 Set_Convention
(Designator
, Convention
(E
));
7419 -- Skip past subprogram bodies and subprogram renamings that
7420 -- may appear to have a matching spec, but that aren't fully
7421 -- conformant with it. That can occur in cases where an
7422 -- actual type causes unrelated homographs in the instance.
7424 if Nkind_In
(N
, N_Subprogram_Body
,
7425 N_Subprogram_Renaming_Declaration
)
7426 and then Present
(Homonym
(E
))
7427 and then not Fully_Conformant
(Designator
, E
)
7431 elsif not Subtype_Conformant
(Designator
, E
) then
7434 elsif Different_Generic_Profile
(E
) then
7439 -- Ada 2012 (AI05-0165): For internally generated bodies of
7440 -- null procedures locate the internally generated spec. We
7441 -- enforce mode conformance since a tagged type may inherit
7442 -- from interfaces several null primitives which differ only
7443 -- in the mode of the formals.
7445 if not (Comes_From_Source
(E
))
7446 and then Is_Null_Procedure
(E
)
7447 and then not Mode_Conformant
(Designator
, E
)
7451 -- For null procedures coming from source that are completions,
7452 -- analysis of the generated body will establish the link.
7454 elsif Comes_From_Source
(E
)
7455 and then Nkind
(Spec
) = N_Procedure_Specification
7456 and then Null_Present
(Spec
)
7460 elsif not Has_Completion
(E
) then
7461 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
7462 Set_Corresponding_Spec
(N
, E
);
7465 Set_Has_Completion
(E
);
7468 elsif Nkind
(Parent
(N
)) = N_Subunit
then
7470 -- If this is the proper body of a subunit, the completion
7471 -- flag is set when analyzing the stub.
7475 -- If E is an internal function with a controlling result that
7476 -- was created for an operation inherited by a null extension,
7477 -- it may be overridden by a body without a previous spec (one
7478 -- more reason why these should be shunned). In that case we
7479 -- remove the generated body if present, because the current
7480 -- one is the explicit overriding.
7482 elsif Ekind
(E
) = E_Function
7483 and then Ada_Version
>= Ada_2005
7484 and then not Comes_From_Source
(E
)
7485 and then Has_Controlling_Result
(E
)
7486 and then Is_Null_Extension
(Etype
(E
))
7487 and then Comes_From_Source
(Spec
)
7489 Set_Has_Completion
(E
, False);
7492 and then Nkind
(Parent
(E
)) = N_Function_Specification
7495 (Unit_Declaration_Node
7496 (Corresponding_Body
(Unit_Declaration_Node
(E
))));
7500 -- If expansion is disabled, or if the wrapper function has
7501 -- not been generated yet, this a late body overriding an
7502 -- inherited operation, or it is an overriding by some other
7503 -- declaration before the controlling result is frozen. In
7504 -- either case this is a declaration of a new entity.
7510 -- If the body already exists, then this is an error unless
7511 -- the previous declaration is the implicit declaration of a
7512 -- derived subprogram. It is also legal for an instance to
7513 -- contain type conformant overloadable declarations (but the
7514 -- generic declaration may not), per 8.3(26/2).
7516 elsif No
(Alias
(E
))
7517 and then not Is_Intrinsic_Subprogram
(E
)
7518 and then not In_Instance
7521 Error_Msg_Sloc
:= Sloc
(E
);
7523 if Is_Imported
(E
) then
7525 ("body not allowed for imported subprogram & declared#",
7528 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
7532 -- Child units cannot be overloaded, so a conformance mismatch
7533 -- between body and a previous spec is an error.
7535 elsif Is_Child_Unit
(E
)
7537 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
7539 Nkind
(Parent
(Unit_Declaration_Node
(Designator
))) =
7544 ("body of child unit does not match previous declaration", N
);
7552 -- On exit, we know that no previous declaration of subprogram exists
7555 end Find_Corresponding_Spec
;
7557 ----------------------
7558 -- Fully_Conformant --
7559 ----------------------
7561 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
7564 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
7566 end Fully_Conformant
;
7568 ----------------------------------
7569 -- Fully_Conformant_Expressions --
7570 ----------------------------------
7572 function Fully_Conformant_Expressions
7573 (Given_E1
: Node_Id
;
7574 Given_E2
: Node_Id
) return Boolean
7576 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
7577 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
7578 -- We always test conformance on original nodes, since it is possible
7579 -- for analysis and/or expansion to make things look as though they
7580 -- conform when they do not, e.g. by converting 1+2 into 3.
7582 function FCE
(Given_E1
, Given_E2
: Node_Id
) return Boolean
7583 renames Fully_Conformant_Expressions
;
7585 function FCL
(L1
, L2
: List_Id
) return Boolean;
7586 -- Compare elements of two lists for conformance. Elements have to be
7587 -- conformant, and actuals inserted as default parameters do not match
7588 -- explicit actuals with the same value.
7590 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean;
7591 -- Compare an operator node with a function call
7597 function FCL
(L1
, L2
: List_Id
) return Boolean is
7601 if L1
= No_List
then
7607 if L2
= No_List
then
7613 -- Compare two lists, skipping rewrite insertions (we want to compare
7614 -- the original trees, not the expanded versions).
7617 if Is_Rewrite_Insertion
(N1
) then
7619 elsif Is_Rewrite_Insertion
(N2
) then
7625 elsif not FCE
(N1
, N2
) then
7638 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean is
7639 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
7644 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
7649 Act
:= First
(Actuals
);
7651 if Nkind
(Op_Node
) in N_Binary_Op
then
7652 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
7659 return Present
(Act
)
7660 and then FCE
(Right_Opnd
(Op_Node
), Act
)
7661 and then No
(Next
(Act
));
7665 -- Start of processing for Fully_Conformant_Expressions
7668 -- Non-conformant if paren count does not match. Note: if some idiot
7669 -- complains that we don't do this right for more than 3 levels of
7670 -- parentheses, they will be treated with the respect they deserve.
7672 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
7675 -- If same entities are referenced, then they are conformant even if
7676 -- they have different forms (RM 8.3.1(19-20)).
7678 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
7679 if Present
(Entity
(E1
)) then
7680 return Entity
(E1
) = Entity
(E2
)
7681 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
7682 and then Ekind
(Entity
(E1
)) = E_Discriminant
7683 and then Ekind
(Entity
(E2
)) = E_In_Parameter
);
7685 elsif Nkind
(E1
) = N_Expanded_Name
7686 and then Nkind
(E2
) = N_Expanded_Name
7687 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
7688 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
7690 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
7693 -- Identifiers in component associations don't always have
7694 -- entities, but their names must conform.
7696 return Nkind
(E1
) = N_Identifier
7697 and then Nkind
(E2
) = N_Identifier
7698 and then Chars
(E1
) = Chars
(E2
);
7701 elsif Nkind
(E1
) = N_Character_Literal
7702 and then Nkind
(E2
) = N_Expanded_Name
7704 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
7705 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
7707 elsif Nkind
(E2
) = N_Character_Literal
7708 and then Nkind
(E1
) = N_Expanded_Name
7710 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
7711 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
7713 elsif Nkind
(E1
) in N_Op
and then Nkind
(E2
) = N_Function_Call
then
7714 return FCO
(E1
, E2
);
7716 elsif Nkind
(E2
) in N_Op
and then Nkind
(E1
) = N_Function_Call
then
7717 return FCO
(E2
, E1
);
7719 -- Otherwise we must have the same syntactic entity
7721 elsif Nkind
(E1
) /= Nkind
(E2
) then
7724 -- At this point, we specialize by node type
7731 FCL
(Expressions
(E1
), Expressions
(E2
))
7733 FCL
(Component_Associations
(E1
),
7734 Component_Associations
(E2
));
7737 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
7739 Nkind
(Expression
(E2
)) = N_Qualified_Expression
7741 return FCE
(Expression
(E1
), Expression
(E2
));
7743 -- Check that the subtype marks and any constraints
7748 Indic1
: constant Node_Id
:= Expression
(E1
);
7749 Indic2
: constant Node_Id
:= Expression
(E2
);
7754 if Nkind
(Indic1
) /= N_Subtype_Indication
then
7756 Nkind
(Indic2
) /= N_Subtype_Indication
7757 and then Entity
(Indic1
) = Entity
(Indic2
);
7759 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
7761 Nkind
(Indic1
) /= N_Subtype_Indication
7762 and then Entity
(Indic1
) = Entity
(Indic2
);
7765 if Entity
(Subtype_Mark
(Indic1
)) /=
7766 Entity
(Subtype_Mark
(Indic2
))
7771 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
7772 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
7773 while Present
(Elt1
) and then Present
(Elt2
) loop
7774 if not FCE
(Elt1
, Elt2
) then
7787 when N_Attribute_Reference
=>
7789 Attribute_Name
(E1
) = Attribute_Name
(E2
)
7790 and then FCL
(Expressions
(E1
), Expressions
(E2
));
7794 Entity
(E1
) = Entity
(E2
)
7795 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
7796 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
7798 when N_Short_Circuit | N_Membership_Test
=>
7800 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
7802 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
7804 when N_Case_Expression
=>
7810 if not FCE
(Expression
(E1
), Expression
(E2
)) then
7814 Alt1
:= First
(Alternatives
(E1
));
7815 Alt2
:= First
(Alternatives
(E2
));
7817 if Present
(Alt1
) /= Present
(Alt2
) then
7819 elsif No
(Alt1
) then
7823 if not FCE
(Expression
(Alt1
), Expression
(Alt2
))
7824 or else not FCL
(Discrete_Choices
(Alt1
),
7825 Discrete_Choices
(Alt2
))
7836 when N_Character_Literal
=>
7838 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
7840 when N_Component_Association
=>
7842 FCL
(Choices
(E1
), Choices
(E2
))
7844 FCE
(Expression
(E1
), Expression
(E2
));
7846 when N_Explicit_Dereference
=>
7848 FCE
(Prefix
(E1
), Prefix
(E2
));
7850 when N_Extension_Aggregate
=>
7852 FCL
(Expressions
(E1
), Expressions
(E2
))
7853 and then Null_Record_Present
(E1
) =
7854 Null_Record_Present
(E2
)
7855 and then FCL
(Component_Associations
(E1
),
7856 Component_Associations
(E2
));
7858 when N_Function_Call
=>
7860 FCE
(Name
(E1
), Name
(E2
))
7862 FCL
(Parameter_Associations
(E1
),
7863 Parameter_Associations
(E2
));
7865 when N_If_Expression
=>
7867 FCL
(Expressions
(E1
), Expressions
(E2
));
7869 when N_Indexed_Component
=>
7871 FCE
(Prefix
(E1
), Prefix
(E2
))
7873 FCL
(Expressions
(E1
), Expressions
(E2
));
7875 when N_Integer_Literal
=>
7876 return (Intval
(E1
) = Intval
(E2
));
7881 when N_Operator_Symbol
=>
7883 Chars
(E1
) = Chars
(E2
);
7885 when N_Others_Choice
=>
7888 when N_Parameter_Association
=>
7890 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
7891 and then FCE
(Explicit_Actual_Parameter
(E1
),
7892 Explicit_Actual_Parameter
(E2
));
7894 when N_Qualified_Expression
=>
7896 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
7898 FCE
(Expression
(E1
), Expression
(E2
));
7900 when N_Quantified_Expression
=>
7901 if not FCE
(Condition
(E1
), Condition
(E2
)) then
7905 if Present
(Loop_Parameter_Specification
(E1
))
7906 and then Present
(Loop_Parameter_Specification
(E2
))
7909 L1
: constant Node_Id
:=
7910 Loop_Parameter_Specification
(E1
);
7911 L2
: constant Node_Id
:=
7912 Loop_Parameter_Specification
(E2
);
7916 Reverse_Present
(L1
) = Reverse_Present
(L2
)
7918 FCE
(Defining_Identifier
(L1
),
7919 Defining_Identifier
(L2
))
7921 FCE
(Discrete_Subtype_Definition
(L1
),
7922 Discrete_Subtype_Definition
(L2
));
7925 elsif Present
(Iterator_Specification
(E1
))
7926 and then Present
(Iterator_Specification
(E2
))
7929 I1
: constant Node_Id
:= Iterator_Specification
(E1
);
7930 I2
: constant Node_Id
:= Iterator_Specification
(E2
);
7934 FCE
(Defining_Identifier
(I1
),
7935 Defining_Identifier
(I2
))
7937 Of_Present
(I1
) = Of_Present
(I2
)
7939 Reverse_Present
(I1
) = Reverse_Present
(I2
)
7940 and then FCE
(Name
(I1
), Name
(I2
))
7941 and then FCE
(Subtype_Indication
(I1
),
7942 Subtype_Indication
(I2
));
7945 -- The quantified expressions used different specifications to
7946 -- walk their respective ranges.
7954 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
7956 FCE
(High_Bound
(E1
), High_Bound
(E2
));
7958 when N_Real_Literal
=>
7959 return (Realval
(E1
) = Realval
(E2
));
7961 when N_Selected_Component
=>
7963 FCE
(Prefix
(E1
), Prefix
(E2
))
7965 FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
7969 FCE
(Prefix
(E1
), Prefix
(E2
))
7971 FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
7973 when N_String_Literal
=>
7975 S1
: constant String_Id
:= Strval
(E1
);
7976 S2
: constant String_Id
:= Strval
(E2
);
7977 L1
: constant Nat
:= String_Length
(S1
);
7978 L2
: constant Nat
:= String_Length
(S2
);
7985 for J
in 1 .. L1
loop
7986 if Get_String_Char
(S1
, J
) /=
7987 Get_String_Char
(S2
, J
)
7997 when N_Type_Conversion
=>
7999 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
8001 FCE
(Expression
(E1
), Expression
(E2
));
8005 Entity
(E1
) = Entity
(E2
)
8007 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
8009 when N_Unchecked_Type_Conversion
=>
8011 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
8013 FCE
(Expression
(E1
), Expression
(E2
));
8015 -- All other node types cannot appear in this context. Strictly
8016 -- we should raise a fatal internal error. Instead we just ignore
8017 -- the nodes. This means that if anyone makes a mistake in the
8018 -- expander and mucks an expression tree irretrievably, the result
8019 -- will be a failure to detect a (probably very obscure) case
8020 -- of non-conformance, which is better than bombing on some
8021 -- case where two expressions do in fact conform.
8028 end Fully_Conformant_Expressions
;
8030 ----------------------------------------
8031 -- Fully_Conformant_Discrete_Subtypes --
8032 ----------------------------------------
8034 function Fully_Conformant_Discrete_Subtypes
8035 (Given_S1
: Node_Id
;
8036 Given_S2
: Node_Id
) return Boolean
8038 S1
: constant Node_Id
:= Original_Node
(Given_S1
);
8039 S2
: constant Node_Id
:= Original_Node
(Given_S2
);
8041 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean;
8042 -- Special-case for a bound given by a discriminant, which in the body
8043 -- is replaced with the discriminal of the enclosing type.
8045 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean;
8046 -- Check both bounds
8048 -----------------------
8049 -- Conforming_Bounds --
8050 -----------------------
8052 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean is
8054 if Is_Entity_Name
(B1
)
8055 and then Is_Entity_Name
(B2
)
8056 and then Ekind
(Entity
(B1
)) = E_Discriminant
8058 return Chars
(B1
) = Chars
(B2
);
8061 return Fully_Conformant_Expressions
(B1
, B2
);
8063 end Conforming_Bounds
;
8065 -----------------------
8066 -- Conforming_Ranges --
8067 -----------------------
8069 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean is
8072 Conforming_Bounds
(Low_Bound
(R1
), Low_Bound
(R2
))
8074 Conforming_Bounds
(High_Bound
(R1
), High_Bound
(R2
));
8075 end Conforming_Ranges
;
8077 -- Start of processing for Fully_Conformant_Discrete_Subtypes
8080 if Nkind
(S1
) /= Nkind
(S2
) then
8083 elsif Is_Entity_Name
(S1
) then
8084 return Entity
(S1
) = Entity
(S2
);
8086 elsif Nkind
(S1
) = N_Range
then
8087 return Conforming_Ranges
(S1
, S2
);
8089 elsif Nkind
(S1
) = N_Subtype_Indication
then
8091 Entity
(Subtype_Mark
(S1
)) = Entity
(Subtype_Mark
(S2
))
8094 (Range_Expression
(Constraint
(S1
)),
8095 Range_Expression
(Constraint
(S2
)));
8099 end Fully_Conformant_Discrete_Subtypes
;
8101 --------------------
8102 -- Install_Entity --
8103 --------------------
8105 procedure Install_Entity
(E
: Entity_Id
) is
8106 Prev
: constant Entity_Id
:= Current_Entity
(E
);
8108 Set_Is_Immediately_Visible
(E
);
8109 Set_Current_Entity
(E
);
8110 Set_Homonym
(E
, Prev
);
8113 ---------------------
8114 -- Install_Formals --
8115 ---------------------
8117 procedure Install_Formals
(Id
: Entity_Id
) is
8120 F
:= First_Formal
(Id
);
8121 while Present
(F
) loop
8125 end Install_Formals
;
8127 -----------------------------
8128 -- Is_Interface_Conformant --
8129 -----------------------------
8131 function Is_Interface_Conformant
8132 (Tagged_Type
: Entity_Id
;
8133 Iface_Prim
: Entity_Id
;
8134 Prim
: Entity_Id
) return Boolean
8136 -- The operation may in fact be an inherited (implicit) operation
8137 -- rather than the original interface primitive, so retrieve the
8138 -- ultimate ancestor.
8140 Iface
: constant Entity_Id
:=
8141 Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
));
8142 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Prim
);
8144 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
;
8145 -- Return the controlling formal of Prim
8147 ------------------------
8148 -- Controlling_Formal --
8149 ------------------------
8151 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
is
8155 E
:= First_Entity
(Prim
);
8156 while Present
(E
) loop
8157 if Is_Formal
(E
) and then Is_Controlling_Formal
(E
) then
8165 end Controlling_Formal
;
8169 Iface_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Iface_Prim
);
8170 Prim_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Prim
);
8172 -- Start of processing for Is_Interface_Conformant
8175 pragma Assert
(Is_Subprogram
(Iface_Prim
)
8176 and then Is_Subprogram
(Prim
)
8177 and then Is_Dispatching_Operation
(Iface_Prim
)
8178 and then Is_Dispatching_Operation
(Prim
));
8180 pragma Assert
(Is_Interface
(Iface
)
8181 or else (Present
(Alias
(Iface_Prim
))
8184 (Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
)))));
8186 if Prim
= Iface_Prim
8187 or else not Is_Subprogram
(Prim
)
8188 or else Ekind
(Prim
) /= Ekind
(Iface_Prim
)
8189 or else not Is_Dispatching_Operation
(Prim
)
8190 or else Scope
(Prim
) /= Scope
(Tagged_Type
)
8192 or else Base_Type
(Typ
) /= Base_Type
(Tagged_Type
)
8193 or else not Primitive_Names_Match
(Iface_Prim
, Prim
)
8197 -- The mode of the controlling formals must match
8199 elsif Present
(Iface_Ctrl_F
)
8200 and then Present
(Prim_Ctrl_F
)
8201 and then Ekind
(Iface_Ctrl_F
) /= Ekind
(Prim_Ctrl_F
)
8205 -- Case of a procedure, or a function whose result type matches the
8206 -- result type of the interface primitive, or a function that has no
8207 -- controlling result (I or access I).
8209 elsif Ekind
(Iface_Prim
) = E_Procedure
8210 or else Etype
(Prim
) = Etype
(Iface_Prim
)
8211 or else not Has_Controlling_Result
(Prim
)
8213 return Type_Conformant
8214 (Iface_Prim
, Prim
, Skip_Controlling_Formals
=> True);
8216 -- Case of a function returning an interface, or an access to one. Check
8217 -- that the return types correspond.
8219 elsif Implements_Interface
(Typ
, Iface
) then
8220 if (Ekind
(Etype
(Prim
)) = E_Anonymous_Access_Type
)
8222 (Ekind
(Etype
(Iface_Prim
)) = E_Anonymous_Access_Type
)
8227 Type_Conformant
(Prim
, Ultimate_Alias
(Iface_Prim
),
8228 Skip_Controlling_Formals
=> True);
8234 end Is_Interface_Conformant
;
8236 ---------------------------------
8237 -- Is_Non_Overriding_Operation --
8238 ---------------------------------
8240 function Is_Non_Overriding_Operation
8241 (Prev_E
: Entity_Id
;
8242 New_E
: Entity_Id
) return Boolean
8246 G_Typ
: Entity_Id
:= Empty
;
8248 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
8249 -- If F_Type is a derived type associated with a generic actual subtype,
8250 -- then return its Generic_Parent_Type attribute, else return Empty.
8252 function Types_Correspond
8253 (P_Type
: Entity_Id
;
8254 N_Type
: Entity_Id
) return Boolean;
8255 -- Returns true if and only if the types (or designated types in the
8256 -- case of anonymous access types) are the same or N_Type is derived
8257 -- directly or indirectly from P_Type.
8259 -----------------------------
8260 -- Get_Generic_Parent_Type --
8261 -----------------------------
8263 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
8269 if Is_Derived_Type
(F_Typ
)
8270 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
8272 -- The tree must be traversed to determine the parent subtype in
8273 -- the generic unit, which unfortunately isn't always available
8274 -- via semantic attributes. ??? (Note: The use of Original_Node
8275 -- is needed for cases where a full derived type has been
8278 Defn
:= Type_Definition
(Original_Node
(Parent
(F_Typ
)));
8279 if Nkind
(Defn
) = N_Derived_Type_Definition
then
8280 Indic
:= Subtype_Indication
(Defn
);
8282 if Nkind
(Indic
) = N_Subtype_Indication
then
8283 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
8285 G_Typ
:= Entity
(Indic
);
8288 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
8289 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
8291 return Generic_Parent_Type
(Parent
(G_Typ
));
8297 end Get_Generic_Parent_Type
;
8299 ----------------------
8300 -- Types_Correspond --
8301 ----------------------
8303 function Types_Correspond
8304 (P_Type
: Entity_Id
;
8305 N_Type
: Entity_Id
) return Boolean
8307 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
8308 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
8311 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
8312 Prev_Type
:= Designated_Type
(Prev_Type
);
8315 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
8316 New_Type
:= Designated_Type
(New_Type
);
8319 if Prev_Type
= New_Type
then
8322 elsif not Is_Class_Wide_Type
(New_Type
) then
8323 while Etype
(New_Type
) /= New_Type
loop
8324 New_Type
:= Etype
(New_Type
);
8325 if New_Type
= Prev_Type
then
8331 end Types_Correspond
;
8333 -- Start of processing for Is_Non_Overriding_Operation
8336 -- In the case where both operations are implicit derived subprograms
8337 -- then neither overrides the other. This can only occur in certain
8338 -- obscure cases (e.g., derivation from homographs created in a generic
8341 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
8344 elsif Ekind
(Current_Scope
) = E_Package
8345 and then Is_Generic_Instance
(Current_Scope
)
8346 and then In_Private_Part
(Current_Scope
)
8347 and then Comes_From_Source
(New_E
)
8349 -- We examine the formals and result type of the inherited operation,
8350 -- to determine whether their type is derived from (the instance of)
8351 -- a generic type. The first such formal or result type is the one
8354 Formal
:= First_Formal
(Prev_E
);
8355 while Present
(Formal
) loop
8356 F_Typ
:= Base_Type
(Etype
(Formal
));
8358 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
8359 F_Typ
:= Designated_Type
(F_Typ
);
8362 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
8363 exit when Present
(G_Typ
);
8365 Next_Formal
(Formal
);
8368 if No
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
8369 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
8376 -- If the generic type is a private type, then the original operation
8377 -- was not overriding in the generic, because there was no primitive
8378 -- operation to override.
8380 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
8381 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
8382 N_Formal_Private_Type_Definition
8386 -- The generic parent type is the ancestor of a formal derived
8387 -- type declaration. We need to check whether it has a primitive
8388 -- operation that should be overridden by New_E in the generic.
8392 P_Formal
: Entity_Id
;
8393 N_Formal
: Entity_Id
;
8397 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
8400 while Present
(Prim_Elt
) loop
8401 P_Prim
:= Node
(Prim_Elt
);
8403 if Chars
(P_Prim
) = Chars
(New_E
)
8404 and then Ekind
(P_Prim
) = Ekind
(New_E
)
8406 P_Formal
:= First_Formal
(P_Prim
);
8407 N_Formal
:= First_Formal
(New_E
);
8408 while Present
(P_Formal
) and then Present
(N_Formal
) loop
8409 P_Typ
:= Etype
(P_Formal
);
8410 N_Typ
:= Etype
(N_Formal
);
8412 if not Types_Correspond
(P_Typ
, N_Typ
) then
8416 Next_Entity
(P_Formal
);
8417 Next_Entity
(N_Formal
);
8420 -- Found a matching primitive operation belonging to the
8421 -- formal ancestor type, so the new subprogram is
8425 and then No
(N_Formal
)
8426 and then (Ekind
(New_E
) /= E_Function
8429 (Etype
(P_Prim
), Etype
(New_E
)))
8435 Next_Elmt
(Prim_Elt
);
8438 -- If no match found, then the new subprogram does not override
8439 -- in the generic (nor in the instance).
8441 -- If the type in question is not abstract, and the subprogram
8442 -- is, this will be an error if the new operation is in the
8443 -- private part of the instance. Emit a warning now, which will
8444 -- make the subsequent error message easier to understand.
8446 if not Is_Abstract_Type
(F_Typ
)
8447 and then Is_Abstract_Subprogram
(Prev_E
)
8448 and then In_Private_Part
(Current_Scope
)
8450 Error_Msg_Node_2
:= F_Typ
;
8452 ("private operation& in generic unit does not override "
8453 & "any primitive operation of& (RM 12.3 (18))??",
8463 end Is_Non_Overriding_Operation
;
8465 -------------------------------------
8466 -- List_Inherited_Pre_Post_Aspects --
8467 -------------------------------------
8469 procedure List_Inherited_Pre_Post_Aspects
(E
: Entity_Id
) is
8471 if Opt
.List_Inherited_Aspects
8472 and then Is_Subprogram_Or_Generic_Subprogram
(E
)
8475 Inherited
: constant Subprogram_List
:= Inherited_Subprograms
(E
);
8479 for J
in Inherited
'Range loop
8480 P
:= Pre_Post_Conditions
(Contract
(Inherited
(J
)));
8481 while Present
(P
) loop
8482 Error_Msg_Sloc
:= Sloc
(P
);
8484 if Class_Present
(P
) and then not Split_PPC
(P
) then
8485 if Pragma_Name
(P
) = Name_Precondition
then
8486 Error_Msg_N
("info: & inherits `Pre''Class` aspect "
8489 Error_Msg_N
("info: & inherits `Post''Class` aspect "
8494 P
:= Next_Pragma
(P
);
8499 end List_Inherited_Pre_Post_Aspects
;
8501 ------------------------------
8502 -- Make_Inequality_Operator --
8503 ------------------------------
8505 -- S is the defining identifier of an equality operator. We build a
8506 -- subprogram declaration with the right signature. This operation is
8507 -- intrinsic, because it is always expanded as the negation of the
8508 -- call to the equality function.
8510 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
8511 Loc
: constant Source_Ptr
:= Sloc
(S
);
8514 Op_Name
: Entity_Id
;
8516 FF
: constant Entity_Id
:= First_Formal
(S
);
8517 NF
: constant Entity_Id
:= Next_Formal
(FF
);
8520 -- Check that equality was properly defined, ignore call if not
8527 A
: constant Entity_Id
:=
8528 Make_Defining_Identifier
(Sloc
(FF
),
8529 Chars
=> Chars
(FF
));
8531 B
: constant Entity_Id
:=
8532 Make_Defining_Identifier
(Sloc
(NF
),
8533 Chars
=> Chars
(NF
));
8536 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
8538 Formals
:= New_List
(
8539 Make_Parameter_Specification
(Loc
,
8540 Defining_Identifier
=> A
,
8542 New_Occurrence_Of
(Etype
(First_Formal
(S
)),
8543 Sloc
(Etype
(First_Formal
(S
))))),
8545 Make_Parameter_Specification
(Loc
,
8546 Defining_Identifier
=> B
,
8548 New_Occurrence_Of
(Etype
(Next_Formal
(First_Formal
(S
))),
8549 Sloc
(Etype
(Next_Formal
(First_Formal
(S
)))))));
8552 Make_Subprogram_Declaration
(Loc
,
8554 Make_Function_Specification
(Loc
,
8555 Defining_Unit_Name
=> Op_Name
,
8556 Parameter_Specifications
=> Formals
,
8557 Result_Definition
=>
8558 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
8560 -- Insert inequality right after equality if it is explicit or after
8561 -- the derived type when implicit. These entities are created only
8562 -- for visibility purposes, and eventually replaced in the course
8563 -- of expansion, so they do not need to be attached to the tree and
8564 -- seen by the back-end. Keeping them internal also avoids spurious
8565 -- freezing problems. The declaration is inserted in the tree for
8566 -- analysis, and removed afterwards. If the equality operator comes
8567 -- from an explicit declaration, attach the inequality immediately
8568 -- after. Else the equality is inherited from a derived type
8569 -- declaration, so insert inequality after that declaration.
8571 if No
(Alias
(S
)) then
8572 Insert_After
(Unit_Declaration_Node
(S
), Decl
);
8573 elsif Is_List_Member
(Parent
(S
)) then
8574 Insert_After
(Parent
(S
), Decl
);
8576 Insert_After
(Parent
(Etype
(First_Formal
(S
))), Decl
);
8579 Mark_Rewrite_Insertion
(Decl
);
8580 Set_Is_Intrinsic_Subprogram
(Op_Name
);
8583 Set_Has_Completion
(Op_Name
);
8584 Set_Corresponding_Equality
(Op_Name
, S
);
8585 Set_Is_Abstract_Subprogram
(Op_Name
, Is_Abstract_Subprogram
(S
));
8587 end Make_Inequality_Operator
;
8589 ----------------------
8590 -- May_Need_Actuals --
8591 ----------------------
8593 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
8598 F
:= First_Formal
(Fun
);
8600 while Present
(F
) loop
8601 if No
(Default_Value
(F
)) then
8609 Set_Needs_No_Actuals
(Fun
, B
);
8610 end May_Need_Actuals
;
8612 ---------------------
8613 -- Mode_Conformant --
8614 ---------------------
8616 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
8619 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
8621 end Mode_Conformant
;
8623 ---------------------------
8624 -- New_Overloaded_Entity --
8625 ---------------------------
8627 procedure New_Overloaded_Entity
8629 Derived_Type
: Entity_Id
:= Empty
)
8631 Overridden_Subp
: Entity_Id
:= Empty
;
8632 -- Set if the current scope has an operation that is type-conformant
8633 -- with S, and becomes hidden by S.
8635 Is_Primitive_Subp
: Boolean;
8636 -- Set to True if the new subprogram is primitive
8639 -- Entity that S overrides
8641 Prev_Vis
: Entity_Id
:= Empty
;
8642 -- Predecessor of E in Homonym chain
8644 procedure Check_For_Primitive_Subprogram
8645 (Is_Primitive
: out Boolean;
8646 Is_Overriding
: Boolean := False);
8647 -- If the subprogram being analyzed is a primitive operation of the type
8648 -- of a formal or result, set the Has_Primitive_Operations flag on the
8649 -- type, and set Is_Primitive to True (otherwise set to False). Set the
8650 -- corresponding flag on the entity itself for later use.
8652 procedure Check_Synchronized_Overriding
8653 (Def_Id
: Entity_Id
;
8654 Overridden_Subp
: out Entity_Id
);
8655 -- First determine if Def_Id is an entry or a subprogram either defined
8656 -- in the scope of a task or protected type, or is a primitive of such
8657 -- a type. Check whether Def_Id overrides a subprogram of an interface
8658 -- implemented by the synchronized type, return the overridden entity
8661 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
8662 -- Check that E is declared in the private part of the current package,
8663 -- or in the package body, where it may hide a previous declaration.
8664 -- We can't use In_Private_Part by itself because this flag is also
8665 -- set when freezing entities, so we must examine the place of the
8666 -- declaration in the tree, and recognize wrapper packages as well.
8668 function Is_Overriding_Alias
8670 New_E
: Entity_Id
) return Boolean;
8671 -- Check whether new subprogram and old subprogram are both inherited
8672 -- from subprograms that have distinct dispatch table entries. This can
8673 -- occur with derivations from instances with accidental homonyms. The
8674 -- function is conservative given that the converse is only true within
8675 -- instances that contain accidental overloadings.
8677 ------------------------------------
8678 -- Check_For_Primitive_Subprogram --
8679 ------------------------------------
8681 procedure Check_For_Primitive_Subprogram
8682 (Is_Primitive
: out Boolean;
8683 Is_Overriding
: Boolean := False)
8689 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
8690 -- Returns true if T is declared in the visible part of the current
8691 -- package scope; otherwise returns false. Assumes that T is declared
8694 procedure Check_Private_Overriding
(T
: Entity_Id
);
8695 -- Checks that if a primitive abstract subprogram of a visible
8696 -- abstract type is declared in a private part, then it must override
8697 -- an abstract subprogram declared in the visible part. Also checks
8698 -- that if a primitive function with a controlling result is declared
8699 -- in a private part, then it must override a function declared in
8700 -- the visible part.
8702 ------------------------------
8703 -- Check_Private_Overriding --
8704 ------------------------------
8706 procedure Check_Private_Overriding
(T
: Entity_Id
) is
8708 if Is_Package_Or_Generic_Package
(Current_Scope
)
8709 and then In_Private_Part
(Current_Scope
)
8710 and then Visible_Part_Type
(T
)
8711 and then not In_Instance
8713 if Is_Abstract_Type
(T
)
8714 and then Is_Abstract_Subprogram
(S
)
8715 and then (not Is_Overriding
8716 or else not Is_Abstract_Subprogram
(E
))
8718 Error_Msg_N
("abstract subprograms must be visible "
8719 & "(RM 3.9.3(10))!", S
);
8721 elsif Ekind
(S
) = E_Function
and then not Is_Overriding
then
8722 if Is_Tagged_Type
(T
) and then T
= Base_Type
(Etype
(S
)) then
8723 Error_Msg_N
("private function with tagged result must"
8724 & " override visible-part function", S
);
8725 Error_Msg_N
("\move subprogram to the visible part"
8726 & " (RM 3.9.3(10))", S
);
8728 -- AI05-0073: extend this test to the case of a function
8729 -- with a controlling access result.
8731 elsif Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
8732 and then Is_Tagged_Type
(Designated_Type
(Etype
(S
)))
8734 not Is_Class_Wide_Type
(Designated_Type
(Etype
(S
)))
8735 and then Ada_Version
>= Ada_2012
8738 ("private function with controlling access result "
8739 & "must override visible-part function", S
);
8741 ("\move subprogram to the visible part"
8742 & " (RM 3.9.3(10))", S
);
8746 end Check_Private_Overriding
;
8748 -----------------------
8749 -- Visible_Part_Type --
8750 -----------------------
8752 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
8753 P
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
8757 -- If the entity is a private type, then it must be declared in a
8760 if Ekind
(T
) in Private_Kind
then
8764 -- Otherwise, we traverse the visible part looking for its
8765 -- corresponding declaration. We cannot use the declaration
8766 -- node directly because in the private part the entity of a
8767 -- private type is the one in the full view, which does not
8768 -- indicate that it is the completion of something visible.
8770 N
:= First
(Visible_Declarations
(Specification
(P
)));
8771 while Present
(N
) loop
8772 if Nkind
(N
) = N_Full_Type_Declaration
8773 and then Present
(Defining_Identifier
(N
))
8774 and then T
= Defining_Identifier
(N
)
8778 elsif Nkind_In
(N
, N_Private_Type_Declaration
,
8779 N_Private_Extension_Declaration
)
8780 and then Present
(Defining_Identifier
(N
))
8781 and then T
= Full_View
(Defining_Identifier
(N
))
8790 end Visible_Part_Type
;
8792 -- Start of processing for Check_For_Primitive_Subprogram
8795 Is_Primitive
:= False;
8797 if not Comes_From_Source
(S
) then
8800 -- If subprogram is at library level, it is not primitive operation
8802 elsif Current_Scope
= Standard_Standard
then
8805 elsif (Is_Package_Or_Generic_Package
(Current_Scope
)
8806 and then not In_Package_Body
(Current_Scope
))
8807 or else Is_Overriding
8809 -- For function, check return type
8811 if Ekind
(S
) = E_Function
then
8812 if Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
then
8813 F_Typ
:= Designated_Type
(Etype
(S
));
8818 B_Typ
:= Base_Type
(F_Typ
);
8820 if Scope
(B_Typ
) = Current_Scope
8821 and then not Is_Class_Wide_Type
(B_Typ
)
8822 and then not Is_Generic_Type
(B_Typ
)
8824 Is_Primitive
:= True;
8825 Set_Has_Primitive_Operations
(B_Typ
);
8826 Set_Is_Primitive
(S
);
8827 Check_Private_Overriding
(B_Typ
);
8831 -- For all subprograms, check formals
8833 Formal
:= First_Formal
(S
);
8834 while Present
(Formal
) loop
8835 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
8836 F_Typ
:= Designated_Type
(Etype
(Formal
));
8838 F_Typ
:= Etype
(Formal
);
8841 B_Typ
:= Base_Type
(F_Typ
);
8843 if Ekind
(B_Typ
) = E_Access_Subtype
then
8844 B_Typ
:= Base_Type
(B_Typ
);
8847 if Scope
(B_Typ
) = Current_Scope
8848 and then not Is_Class_Wide_Type
(B_Typ
)
8849 and then not Is_Generic_Type
(B_Typ
)
8851 Is_Primitive
:= True;
8852 Set_Is_Primitive
(S
);
8853 Set_Has_Primitive_Operations
(B_Typ
);
8854 Check_Private_Overriding
(B_Typ
);
8857 Next_Formal
(Formal
);
8860 -- Special case: An equality function can be redefined for a type
8861 -- occurring in a declarative part, and won't otherwise be treated as
8862 -- a primitive because it doesn't occur in a package spec and doesn't
8863 -- override an inherited subprogram. It's important that we mark it
8864 -- primitive so it can be returned by Collect_Primitive_Operations
8865 -- and be used in composing the equality operation of later types
8866 -- that have a component of the type.
8868 elsif Chars
(S
) = Name_Op_Eq
8869 and then Etype
(S
) = Standard_Boolean
8871 B_Typ
:= Base_Type
(Etype
(First_Formal
(S
)));
8873 if Scope
(B_Typ
) = Current_Scope
8875 Base_Type
(Etype
(Next_Formal
(First_Formal
(S
)))) = B_Typ
8876 and then not Is_Limited_Type
(B_Typ
)
8878 Is_Primitive
:= True;
8879 Set_Is_Primitive
(S
);
8880 Set_Has_Primitive_Operations
(B_Typ
);
8881 Check_Private_Overriding
(B_Typ
);
8884 end Check_For_Primitive_Subprogram
;
8886 -----------------------------------
8887 -- Check_Synchronized_Overriding --
8888 -----------------------------------
8890 procedure Check_Synchronized_Overriding
8891 (Def_Id
: Entity_Id
;
8892 Overridden_Subp
: out Entity_Id
)
8894 Ifaces_List
: Elist_Id
;
8898 function Matches_Prefixed_View_Profile
8899 (Prim_Params
: List_Id
;
8900 Iface_Params
: List_Id
) return Boolean;
8901 -- Determine whether a subprogram's parameter profile Prim_Params
8902 -- matches that of a potentially overridden interface subprogram
8903 -- Iface_Params. Also determine if the type of first parameter of
8904 -- Iface_Params is an implemented interface.
8906 -----------------------------------
8907 -- Matches_Prefixed_View_Profile --
8908 -----------------------------------
8910 function Matches_Prefixed_View_Profile
8911 (Prim_Params
: List_Id
;
8912 Iface_Params
: List_Id
) return Boolean
8914 Iface_Id
: Entity_Id
;
8915 Iface_Param
: Node_Id
;
8916 Iface_Typ
: Entity_Id
;
8917 Prim_Id
: Entity_Id
;
8918 Prim_Param
: Node_Id
;
8919 Prim_Typ
: Entity_Id
;
8921 function Is_Implemented
8922 (Ifaces_List
: Elist_Id
;
8923 Iface
: Entity_Id
) return Boolean;
8924 -- Determine if Iface is implemented by the current task or
8927 --------------------
8928 -- Is_Implemented --
8929 --------------------
8931 function Is_Implemented
8932 (Ifaces_List
: Elist_Id
;
8933 Iface
: Entity_Id
) return Boolean
8935 Iface_Elmt
: Elmt_Id
;
8938 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
8939 while Present
(Iface_Elmt
) loop
8940 if Node
(Iface_Elmt
) = Iface
then
8944 Next_Elmt
(Iface_Elmt
);
8950 -- Start of processing for Matches_Prefixed_View_Profile
8953 Iface_Param
:= First
(Iface_Params
);
8954 Iface_Typ
:= Etype
(Defining_Identifier
(Iface_Param
));
8956 if Is_Access_Type
(Iface_Typ
) then
8957 Iface_Typ
:= Designated_Type
(Iface_Typ
);
8960 Prim_Param
:= First
(Prim_Params
);
8962 -- The first parameter of the potentially overridden subprogram
8963 -- must be an interface implemented by Prim.
8965 if not Is_Interface
(Iface_Typ
)
8966 or else not Is_Implemented
(Ifaces_List
, Iface_Typ
)
8971 -- The checks on the object parameters are done, move onto the
8972 -- rest of the parameters.
8974 if not In_Scope
then
8975 Prim_Param
:= Next
(Prim_Param
);
8978 Iface_Param
:= Next
(Iface_Param
);
8979 while Present
(Iface_Param
) and then Present
(Prim_Param
) loop
8980 Iface_Id
:= Defining_Identifier
(Iface_Param
);
8981 Iface_Typ
:= Find_Parameter_Type
(Iface_Param
);
8983 Prim_Id
:= Defining_Identifier
(Prim_Param
);
8984 Prim_Typ
:= Find_Parameter_Type
(Prim_Param
);
8986 if Ekind
(Iface_Typ
) = E_Anonymous_Access_Type
8987 and then Ekind
(Prim_Typ
) = E_Anonymous_Access_Type
8988 and then Is_Concurrent_Type
(Designated_Type
(Prim_Typ
))
8990 Iface_Typ
:= Designated_Type
(Iface_Typ
);
8991 Prim_Typ
:= Designated_Type
(Prim_Typ
);
8994 -- Case of multiple interface types inside a parameter profile
8996 -- (Obj_Param : in out Iface; ...; Param : Iface)
8998 -- If the interface type is implemented, then the matching type
8999 -- in the primitive should be the implementing record type.
9001 if Ekind
(Iface_Typ
) = E_Record_Type
9002 and then Is_Interface
(Iface_Typ
)
9003 and then Is_Implemented
(Ifaces_List
, Iface_Typ
)
9005 if Prim_Typ
/= Typ
then
9009 -- The two parameters must be both mode and subtype conformant
9011 elsif Ekind
(Iface_Id
) /= Ekind
(Prim_Id
)
9013 Conforming_Types
(Iface_Typ
, Prim_Typ
, Subtype_Conformant
)
9022 -- One of the two lists contains more parameters than the other
9024 if Present
(Iface_Param
) or else Present
(Prim_Param
) then
9029 end Matches_Prefixed_View_Profile
;
9031 -- Start of processing for Check_Synchronized_Overriding
9034 Overridden_Subp
:= Empty
;
9036 -- Def_Id must be an entry or a subprogram. We should skip predefined
9037 -- primitives internally generated by the frontend; however at this
9038 -- stage predefined primitives are still not fully decorated. As a
9039 -- minor optimization we skip here internally generated subprograms.
9041 if (Ekind
(Def_Id
) /= E_Entry
9042 and then Ekind
(Def_Id
) /= E_Function
9043 and then Ekind
(Def_Id
) /= E_Procedure
)
9044 or else not Comes_From_Source
(Def_Id
)
9049 -- Search for the concurrent declaration since it contains the list
9050 -- of all implemented interfaces. In this case, the subprogram is
9051 -- declared within the scope of a protected or a task type.
9053 if Present
(Scope
(Def_Id
))
9054 and then Is_Concurrent_Type
(Scope
(Def_Id
))
9055 and then not Is_Generic_Actual_Type
(Scope
(Def_Id
))
9057 Typ
:= Scope
(Def_Id
);
9060 -- The enclosing scope is not a synchronized type and the subprogram
9063 elsif No
(First_Formal
(Def_Id
)) then
9066 -- The subprogram has formals and hence it may be a primitive of a
9070 Typ
:= Etype
(First_Formal
(Def_Id
));
9072 if Is_Access_Type
(Typ
) then
9073 Typ
:= Directly_Designated_Type
(Typ
);
9076 if Is_Concurrent_Type
(Typ
)
9077 and then not Is_Generic_Actual_Type
(Typ
)
9081 -- This case occurs when the concurrent type is declared within
9082 -- a generic unit. As a result the corresponding record has been
9083 -- built and used as the type of the first formal, we just have
9084 -- to retrieve the corresponding concurrent type.
9086 elsif Is_Concurrent_Record_Type
(Typ
)
9087 and then not Is_Class_Wide_Type
(Typ
)
9088 and then Present
(Corresponding_Concurrent_Type
(Typ
))
9090 Typ
:= Corresponding_Concurrent_Type
(Typ
);
9098 -- There is no overriding to check if is an inherited operation in a
9099 -- type derivation on for a generic actual.
9101 Collect_Interfaces
(Typ
, Ifaces_List
);
9103 if Is_Empty_Elmt_List
(Ifaces_List
) then
9107 -- Determine whether entry or subprogram Def_Id overrides a primitive
9108 -- operation that belongs to one of the interfaces in Ifaces_List.
9111 Candidate
: Entity_Id
:= Empty
;
9112 Hom
: Entity_Id
:= Empty
;
9113 Iface_Typ
: Entity_Id
;
9114 Subp
: Entity_Id
:= Empty
;
9117 -- Traverse the homonym chain, looking for a potentially
9118 -- overridden subprogram that belongs to an implemented
9121 Hom
:= Current_Entity_In_Scope
(Def_Id
);
9122 while Present
(Hom
) loop
9126 or else not Is_Overloadable
(Subp
)
9127 or else not Is_Primitive
(Subp
)
9128 or else not Is_Dispatching_Operation
(Subp
)
9129 or else not Present
(Find_Dispatching_Type
(Subp
))
9130 or else not Is_Interface
(Find_Dispatching_Type
(Subp
))
9134 -- Entries and procedures can override abstract or null
9135 -- interface procedures.
9137 elsif (Ekind
(Def_Id
) = E_Procedure
9138 or else Ekind
(Def_Id
) = E_Entry
)
9139 and then Ekind
(Subp
) = E_Procedure
9140 and then Matches_Prefixed_View_Profile
9141 (Parameter_Specifications
(Parent
(Def_Id
)),
9142 Parameter_Specifications
(Parent
(Subp
)))
9146 -- For an overridden subprogram Subp, check whether the mode
9147 -- of its first parameter is correct depending on the kind
9148 -- of synchronized type.
9151 Formal
: constant Node_Id
:= First_Formal
(Candidate
);
9154 -- In order for an entry or a protected procedure to
9155 -- override, the first parameter of the overridden
9156 -- routine must be of mode "out", "in out" or
9157 -- access-to-variable.
9159 if Ekind_In
(Candidate
, E_Entry
, E_Procedure
)
9160 and then Is_Protected_Type
(Typ
)
9161 and then Ekind
(Formal
) /= E_In_Out_Parameter
9162 and then Ekind
(Formal
) /= E_Out_Parameter
9163 and then Nkind
(Parameter_Type
(Parent
(Formal
))) /=
9168 -- All other cases are OK since a task entry or routine
9169 -- does not have a restriction on the mode of the first
9170 -- parameter of the overridden interface routine.
9173 Overridden_Subp
:= Candidate
;
9178 -- Functions can override abstract interface functions
9180 elsif Ekind
(Def_Id
) = E_Function
9181 and then Ekind
(Subp
) = E_Function
9182 and then Matches_Prefixed_View_Profile
9183 (Parameter_Specifications
(Parent
(Def_Id
)),
9184 Parameter_Specifications
(Parent
(Subp
)))
9185 and then Etype
(Result_Definition
(Parent
(Def_Id
))) =
9186 Etype
(Result_Definition
(Parent
(Subp
)))
9188 Overridden_Subp
:= Subp
;
9192 Hom
:= Homonym
(Hom
);
9195 -- After examining all candidates for overriding, we are left with
9196 -- the best match which is a mode incompatible interface routine.
9197 -- Do not emit an error if the Expander is active since this error
9198 -- will be detected later on after all concurrent types are
9199 -- expanded and all wrappers are built. This check is meant for
9200 -- spec-only compilations.
9202 if Present
(Candidate
) and then not Expander_Active
then
9204 Find_Parameter_Type
(Parent
(First_Formal
(Candidate
)));
9206 -- Def_Id is primitive of a protected type, declared inside the
9207 -- type, and the candidate is primitive of a limited or
9208 -- synchronized interface.
9211 and then Is_Protected_Type
(Typ
)
9213 (Is_Limited_Interface
(Iface_Typ
)
9214 or else Is_Protected_Interface
(Iface_Typ
)
9215 or else Is_Synchronized_Interface
(Iface_Typ
)
9216 or else Is_Task_Interface
(Iface_Typ
))
9218 Error_Msg_PT
(Parent
(Typ
), Candidate
);
9222 Overridden_Subp
:= Candidate
;
9225 end Check_Synchronized_Overriding
;
9227 ----------------------------
9228 -- Is_Private_Declaration --
9229 ----------------------------
9231 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
9232 Priv_Decls
: List_Id
;
9233 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
9236 if Is_Package_Or_Generic_Package
(Current_Scope
)
9237 and then In_Private_Part
(Current_Scope
)
9240 Private_Declarations
(Package_Specification
(Current_Scope
));
9242 return In_Package_Body
(Current_Scope
)
9244 (Is_List_Member
(Decl
)
9245 and then List_Containing
(Decl
) = Priv_Decls
)
9246 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
9249 (Defining_Entity
(Parent
(Decl
)))
9250 and then List_Containing
(Parent
(Parent
(Decl
))) =
9255 end Is_Private_Declaration
;
9257 --------------------------
9258 -- Is_Overriding_Alias --
9259 --------------------------
9261 function Is_Overriding_Alias
9263 New_E
: Entity_Id
) return Boolean
9265 AO
: constant Entity_Id
:= Alias
(Old_E
);
9266 AN
: constant Entity_Id
:= Alias
(New_E
);
9268 return Scope
(AO
) /= Scope
(AN
)
9269 or else No
(DTC_Entity
(AO
))
9270 or else No
(DTC_Entity
(AN
))
9271 or else DT_Position
(AO
) = DT_Position
(AN
);
9272 end Is_Overriding_Alias
;
9274 -- Start of processing for New_Overloaded_Entity
9277 -- We need to look for an entity that S may override. This must be a
9278 -- homonym in the current scope, so we look for the first homonym of
9279 -- S in the current scope as the starting point for the search.
9281 E
:= Current_Entity_In_Scope
(S
);
9283 -- Ada 2005 (AI-251): Derivation of abstract interface primitives.
9284 -- They are directly added to the list of primitive operations of
9285 -- Derived_Type, unless this is a rederivation in the private part
9286 -- of an operation that was already derived in the visible part of
9287 -- the current package.
9289 if Ada_Version
>= Ada_2005
9290 and then Present
(Derived_Type
)
9291 and then Present
(Alias
(S
))
9292 and then Is_Dispatching_Operation
(Alias
(S
))
9293 and then Present
(Find_Dispatching_Type
(Alias
(S
)))
9294 and then Is_Interface
(Find_Dispatching_Type
(Alias
(S
)))
9296 -- For private types, when the full-view is processed we propagate to
9297 -- the full view the non-overridden entities whose attribute "alias"
9298 -- references an interface primitive. These entities were added by
9299 -- Derive_Subprograms to ensure that interface primitives are
9302 -- Inside_Freeze_Actions is non zero when S corresponds with an
9303 -- internal entity that links an interface primitive with its
9304 -- covering primitive through attribute Interface_Alias (see
9305 -- Add_Internal_Interface_Entities).
9307 if Inside_Freezing_Actions
= 0
9308 and then Is_Package_Or_Generic_Package
(Current_Scope
)
9309 and then In_Private_Part
(Current_Scope
)
9310 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
9311 and then Nkind
(Parent
(S
)) = N_Full_Type_Declaration
9312 and then Full_View
(Defining_Identifier
(Parent
(E
)))
9313 = Defining_Identifier
(Parent
(S
))
9314 and then Alias
(E
) = Alias
(S
)
9316 Check_Operation_From_Private_View
(S
, E
);
9317 Set_Is_Dispatching_Operation
(S
);
9322 Enter_Overloaded_Entity
(S
);
9323 Check_Dispatching_Operation
(S
, Empty
);
9324 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
9330 -- If there is no homonym then this is definitely not overriding
9333 Enter_Overloaded_Entity
(S
);
9334 Check_Dispatching_Operation
(S
, Empty
);
9335 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
9337 -- If subprogram has an explicit declaration, check whether it has an
9338 -- overriding indicator.
9340 if Comes_From_Source
(S
) then
9341 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
9343 -- (Ada 2012: AI05-0125-1): If S is a dispatching operation then
9344 -- it may have overridden some hidden inherited primitive. Update
9345 -- Overridden_Subp to avoid spurious errors when checking the
9346 -- overriding indicator.
9348 if Ada_Version
>= Ada_2012
9349 and then No
(Overridden_Subp
)
9350 and then Is_Dispatching_Operation
(S
)
9351 and then Present
(Overridden_Operation
(S
))
9353 Overridden_Subp
:= Overridden_Operation
(S
);
9356 Check_Overriding_Indicator
9357 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
9360 -- If there is a homonym that is not overloadable, then we have an
9361 -- error, except for the special cases checked explicitly below.
9363 elsif not Is_Overloadable
(E
) then
9365 -- Check for spurious conflict produced by a subprogram that has the
9366 -- same name as that of the enclosing generic package. The conflict
9367 -- occurs within an instance, between the subprogram and the renaming
9368 -- declaration for the package. After the subprogram, the package
9369 -- renaming declaration becomes hidden.
9371 if Ekind
(E
) = E_Package
9372 and then Present
(Renamed_Object
(E
))
9373 and then Renamed_Object
(E
) = Current_Scope
9374 and then Nkind
(Parent
(Renamed_Object
(E
))) =
9375 N_Package_Specification
9376 and then Present
(Generic_Parent
(Parent
(Renamed_Object
(E
))))
9379 Set_Is_Immediately_Visible
(E
, False);
9380 Enter_Overloaded_Entity
(S
);
9381 Set_Homonym
(S
, Homonym
(E
));
9382 Check_Dispatching_Operation
(S
, Empty
);
9383 Check_Overriding_Indicator
(S
, Empty
, Is_Primitive
=> False);
9385 -- If the subprogram is implicit it is hidden by the previous
9386 -- declaration. However if it is dispatching, it must appear in the
9387 -- dispatch table anyway, because it can be dispatched to even if it
9388 -- cannot be called directly.
9390 elsif Present
(Alias
(S
)) and then not Comes_From_Source
(S
) then
9391 Set_Scope
(S
, Current_Scope
);
9393 if Is_Dispatching_Operation
(Alias
(S
)) then
9394 Check_Dispatching_Operation
(S
, Empty
);
9400 Error_Msg_Sloc
:= Sloc
(E
);
9402 -- Generate message, with useful additional warning if in generic
9404 if Is_Generic_Unit
(E
) then
9405 Error_Msg_N
("previous generic unit cannot be overloaded", S
);
9406 Error_Msg_N
("\& conflicts with declaration#", S
);
9408 Error_Msg_N
("& conflicts with declaration#", S
);
9414 -- E exists and is overloadable
9417 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
9419 -- Loop through E and its homonyms to determine if any of them is
9420 -- the candidate for overriding by S.
9422 while Present
(E
) loop
9424 -- Definitely not interesting if not in the current scope
9426 if Scope
(E
) /= Current_Scope
then
9429 -- A function can overload the name of an abstract state. The
9430 -- state can be viewed as a function with a profile that cannot
9431 -- be matched by anything.
9433 elsif Ekind
(S
) = E_Function
9434 and then Ekind
(E
) = E_Abstract_State
9436 Enter_Overloaded_Entity
(S
);
9439 -- Ada 2012 (AI05-0165): For internally generated bodies of null
9440 -- procedures locate the internally generated spec. We enforce
9441 -- mode conformance since a tagged type may inherit from
9442 -- interfaces several null primitives which differ only in
9443 -- the mode of the formals.
9445 elsif not Comes_From_Source
(S
)
9446 and then Is_Null_Procedure
(S
)
9447 and then not Mode_Conformant
(E
, S
)
9451 -- Check if we have type conformance
9453 elsif Type_Conformant
(E
, S
) then
9455 -- If the old and new entities have the same profile and one
9456 -- is not the body of the other, then this is an error, unless
9457 -- one of them is implicitly declared.
9459 -- There are some cases when both can be implicit, for example
9460 -- when both a literal and a function that overrides it are
9461 -- inherited in a derivation, or when an inherited operation
9462 -- of a tagged full type overrides the inherited operation of
9463 -- a private extension. Ada 83 had a special rule for the
9464 -- literal case. In Ada 95, the later implicit operation hides
9465 -- the former, and the literal is always the former. In the
9466 -- odd case where both are derived operations declared at the
9467 -- same point, both operations should be declared, and in that
9468 -- case we bypass the following test and proceed to the next
9469 -- part. This can only occur for certain obscure cases in
9470 -- instances, when an operation on a type derived from a formal
9471 -- private type does not override a homograph inherited from
9472 -- the actual. In subsequent derivations of such a type, the
9473 -- DT positions of these operations remain distinct, if they
9476 if Present
(Alias
(S
))
9477 and then (No
(Alias
(E
))
9478 or else Comes_From_Source
(E
)
9479 or else Is_Abstract_Subprogram
(S
)
9481 (Is_Dispatching_Operation
(E
)
9482 and then Is_Overriding_Alias
(E
, S
)))
9483 and then Ekind
(E
) /= E_Enumeration_Literal
9485 -- When an derived operation is overloaded it may be due to
9486 -- the fact that the full view of a private extension
9487 -- re-inherits. It has to be dealt with.
9489 if Is_Package_Or_Generic_Package
(Current_Scope
)
9490 and then In_Private_Part
(Current_Scope
)
9492 Check_Operation_From_Private_View
(S
, E
);
9495 -- In any case the implicit operation remains hidden by the
9496 -- existing declaration, which is overriding. Indicate that
9497 -- E overrides the operation from which S is inherited.
9499 if Present
(Alias
(S
)) then
9500 Set_Overridden_Operation
(E
, Alias
(S
));
9501 Inherit_Subprogram_Contract
(E
, Alias
(S
));
9504 Set_Overridden_Operation
(E
, S
);
9505 Inherit_Subprogram_Contract
(E
, S
);
9508 if Comes_From_Source
(E
) then
9509 Check_Overriding_Indicator
(E
, S
, Is_Primitive
=> False);
9514 -- Within an instance, the renaming declarations for actual
9515 -- subprograms may become ambiguous, but they do not hide each
9518 elsif Ekind
(E
) /= E_Entry
9519 and then not Comes_From_Source
(E
)
9520 and then not Is_Generic_Instance
(E
)
9521 and then (Present
(Alias
(E
))
9522 or else Is_Intrinsic_Subprogram
(E
))
9523 and then (not In_Instance
9524 or else No
(Parent
(E
))
9525 or else Nkind
(Unit_Declaration_Node
(E
)) /=
9526 N_Subprogram_Renaming_Declaration
)
9528 -- A subprogram child unit is not allowed to override an
9529 -- inherited subprogram (10.1.1(20)).
9531 if Is_Child_Unit
(S
) then
9533 ("child unit overrides inherited subprogram in parent",
9538 if Is_Non_Overriding_Operation
(E
, S
) then
9539 Enter_Overloaded_Entity
(S
);
9541 if No
(Derived_Type
)
9542 or else Is_Tagged_Type
(Derived_Type
)
9544 Check_Dispatching_Operation
(S
, Empty
);
9550 -- E is a derived operation or an internal operator which
9551 -- is being overridden. Remove E from further visibility.
9552 -- Furthermore, if E is a dispatching operation, it must be
9553 -- replaced in the list of primitive operations of its type
9554 -- (see Override_Dispatching_Operation).
9556 Overridden_Subp
:= E
;
9562 Prev
:= First_Entity
(Current_Scope
);
9563 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
9567 -- It is possible for E to be in the current scope and
9568 -- yet not in the entity chain. This can only occur in a
9569 -- generic context where E is an implicit concatenation
9570 -- in the formal part, because in a generic body the
9571 -- entity chain starts with the formals.
9574 (Present
(Prev
) or else Chars
(E
) = Name_Op_Concat
);
9576 -- E must be removed both from the entity_list of the
9577 -- current scope, and from the visibility chain
9579 if Debug_Flag_E
then
9580 Write_Str
("Override implicit operation ");
9581 Write_Int
(Int
(E
));
9585 -- If E is a predefined concatenation, it stands for four
9586 -- different operations. As a result, a single explicit
9587 -- declaration does not hide it. In a possible ambiguous
9588 -- situation, Disambiguate chooses the user-defined op,
9589 -- so it is correct to retain the previous internal one.
9591 if Chars
(E
) /= Name_Op_Concat
9592 or else Ekind
(E
) /= E_Operator
9594 -- For nondispatching derived operations that are
9595 -- overridden by a subprogram declared in the private
9596 -- part of a package, we retain the derived subprogram
9597 -- but mark it as not immediately visible. If the
9598 -- derived operation was declared in the visible part
9599 -- then this ensures that it will still be visible
9600 -- outside the package with the proper signature
9601 -- (calls from outside must also be directed to this
9602 -- version rather than the overriding one, unlike the
9603 -- dispatching case). Calls from inside the package
9604 -- will still resolve to the overriding subprogram
9605 -- since the derived one is marked as not visible
9606 -- within the package.
9608 -- If the private operation is dispatching, we achieve
9609 -- the overriding by keeping the implicit operation
9610 -- but setting its alias to be the overriding one. In
9611 -- this fashion the proper body is executed in all
9612 -- cases, but the original signature is used outside
9615 -- If the overriding is not in the private part, we
9616 -- remove the implicit operation altogether.
9618 if Is_Private_Declaration
(S
) then
9619 if not Is_Dispatching_Operation
(E
) then
9620 Set_Is_Immediately_Visible
(E
, False);
9622 -- Work done in Override_Dispatching_Operation,
9623 -- so nothing else needs to be done here.
9629 -- Find predecessor of E in Homonym chain
9631 if E
= Current_Entity
(E
) then
9634 Prev_Vis
:= Current_Entity
(E
);
9635 while Homonym
(Prev_Vis
) /= E
loop
9636 Prev_Vis
:= Homonym
(Prev_Vis
);
9640 if Prev_Vis
/= Empty
then
9642 -- Skip E in the visibility chain
9644 Set_Homonym
(Prev_Vis
, Homonym
(E
));
9647 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
9650 Set_Next_Entity
(Prev
, Next_Entity
(E
));
9652 if No
(Next_Entity
(Prev
)) then
9653 Set_Last_Entity
(Current_Scope
, Prev
);
9658 Enter_Overloaded_Entity
(S
);
9660 -- For entities generated by Derive_Subprograms the
9661 -- overridden operation is the inherited primitive
9662 -- (which is available through the attribute alias).
9664 if not (Comes_From_Source
(E
))
9665 and then Is_Dispatching_Operation
(E
)
9666 and then Find_Dispatching_Type
(E
) =
9667 Find_Dispatching_Type
(S
)
9668 and then Present
(Alias
(E
))
9669 and then Comes_From_Source
(Alias
(E
))
9671 Set_Overridden_Operation
(S
, Alias
(E
));
9672 Inherit_Subprogram_Contract
(S
, Alias
(E
));
9674 -- Normal case of setting entity as overridden
9676 -- Note: Static_Initialization and Overridden_Operation
9677 -- attributes use the same field in subprogram entities.
9678 -- Static_Initialization is only defined for internal
9679 -- initialization procedures, where Overridden_Operation
9680 -- is irrelevant. Therefore the setting of this attribute
9681 -- must check whether the target is an init_proc.
9683 elsif not Is_Init_Proc
(S
) then
9684 Set_Overridden_Operation
(S
, E
);
9685 Inherit_Subprogram_Contract
(S
, E
);
9688 Check_Overriding_Indicator
(S
, E
, Is_Primitive
=> True);
9690 -- If S is a user-defined subprogram or a null procedure
9691 -- expanded to override an inherited null procedure, or a
9692 -- predefined dispatching primitive then indicate that E
9693 -- overrides the operation from which S is inherited.
9695 if Comes_From_Source
(S
)
9697 (Present
(Parent
(S
))
9699 Nkind
(Parent
(S
)) = N_Procedure_Specification
9701 Null_Present
(Parent
(S
)))
9703 (Present
(Alias
(E
))
9705 Is_Predefined_Dispatching_Operation
(Alias
(E
)))
9707 if Present
(Alias
(E
)) then
9708 Set_Overridden_Operation
(S
, Alias
(E
));
9709 Inherit_Subprogram_Contract
(S
, Alias
(E
));
9713 if Is_Dispatching_Operation
(E
) then
9715 -- An overriding dispatching subprogram inherits the
9716 -- convention of the overridden subprogram (AI-117).
9718 Set_Convention
(S
, Convention
(E
));
9719 Check_Dispatching_Operation
(S
, E
);
9722 Check_Dispatching_Operation
(S
, Empty
);
9725 Check_For_Primitive_Subprogram
9726 (Is_Primitive_Subp
, Is_Overriding
=> True);
9727 goto Check_Inequality
;
9730 -- Apparent redeclarations in instances can occur when two
9731 -- formal types get the same actual type. The subprograms in
9732 -- in the instance are legal, even if not callable from the
9733 -- outside. Calls from within are disambiguated elsewhere.
9734 -- For dispatching operations in the visible part, the usual
9735 -- rules apply, and operations with the same profile are not
9738 elsif (In_Instance_Visible_Part
9739 and then not Is_Dispatching_Operation
(E
))
9740 or else In_Instance_Not_Visible
9744 -- Here we have a real error (identical profile)
9747 Error_Msg_Sloc
:= Sloc
(E
);
9749 -- Avoid cascaded errors if the entity appears in
9750 -- subsequent calls.
9752 Set_Scope
(S
, Current_Scope
);
9754 -- Generate error, with extra useful warning for the case
9755 -- of a generic instance with no completion.
9757 if Is_Generic_Instance
(S
)
9758 and then not Has_Completion
(E
)
9761 ("instantiation cannot provide body for&", S
);
9762 Error_Msg_N
("\& conflicts with declaration#", S
);
9764 Error_Msg_N
("& conflicts with declaration#", S
);
9771 -- If one subprogram has an access parameter and the other
9772 -- a parameter of an access type, calls to either might be
9773 -- ambiguous. Verify that parameters match except for the
9774 -- access parameter.
9776 if May_Hide_Profile
then
9782 F1
:= First_Formal
(S
);
9783 F2
:= First_Formal
(E
);
9784 while Present
(F1
) and then Present
(F2
) loop
9785 if Is_Access_Type
(Etype
(F1
)) then
9786 if not Is_Access_Type
(Etype
(F2
))
9787 or else not Conforming_Types
9788 (Designated_Type
(Etype
(F1
)),
9789 Designated_Type
(Etype
(F2
)),
9792 May_Hide_Profile
:= False;
9796 not Conforming_Types
9797 (Etype
(F1
), Etype
(F2
), Type_Conformant
)
9799 May_Hide_Profile
:= False;
9810 Error_Msg_NE
("calls to& may be ambiguous??", S
, S
);
9819 -- On exit, we know that S is a new entity
9821 Enter_Overloaded_Entity
(S
);
9822 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
9823 Check_Overriding_Indicator
9824 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
9826 -- Overloading is not allowed in SPARK, except for operators
9828 if Nkind
(S
) /= N_Defining_Operator_Symbol
then
9829 Error_Msg_Sloc
:= Sloc
(Homonym
(S
));
9830 Check_SPARK_05_Restriction
9831 ("overloading not allowed with entity#", S
);
9834 -- If S is a derived operation for an untagged type then by
9835 -- definition it's not a dispatching operation (even if the parent
9836 -- operation was dispatching), so Check_Dispatching_Operation is not
9837 -- called in that case.
9839 if No
(Derived_Type
)
9840 or else Is_Tagged_Type
(Derived_Type
)
9842 Check_Dispatching_Operation
(S
, Empty
);
9846 -- If this is a user-defined equality operator that is not a derived
9847 -- subprogram, create the corresponding inequality. If the operation is
9848 -- dispatching, the expansion is done elsewhere, and we do not create
9849 -- an explicit inequality operation.
9851 <<Check_Inequality
>>
9852 if Chars
(S
) = Name_Op_Eq
9853 and then Etype
(S
) = Standard_Boolean
9854 and then Present
(Parent
(S
))
9855 and then not Is_Dispatching_Operation
(S
)
9857 Make_Inequality_Operator
(S
);
9858 Check_Untagged_Equality
(S
);
9860 end New_Overloaded_Entity
;
9862 ---------------------
9863 -- Process_Formals --
9864 ---------------------
9866 procedure Process_Formals
9868 Related_Nod
: Node_Id
)
9870 Param_Spec
: Node_Id
;
9872 Formal_Type
: Entity_Id
;
9876 Num_Out_Params
: Nat
:= 0;
9877 First_Out_Param
: Entity_Id
:= Empty
;
9878 -- Used for setting Is_Only_Out_Parameter
9880 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean;
9881 -- Determine whether an access type designates a type coming from a
9884 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean;
9885 -- Check whether the default has a class-wide type. After analysis the
9886 -- default has the type of the formal, so we must also check explicitly
9887 -- for an access attribute.
9889 ----------------------------------
9890 -- Designates_From_Limited_With --
9891 ----------------------------------
9893 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean is
9894 Desig
: Entity_Id
:= Typ
;
9897 if Is_Access_Type
(Desig
) then
9898 Desig
:= Directly_Designated_Type
(Desig
);
9901 if Is_Class_Wide_Type
(Desig
) then
9902 Desig
:= Root_Type
(Desig
);
9906 Ekind
(Desig
) = E_Incomplete_Type
9907 and then From_Limited_With
(Desig
);
9908 end Designates_From_Limited_With
;
9910 ---------------------------
9911 -- Is_Class_Wide_Default --
9912 ---------------------------
9914 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean is
9916 return Is_Class_Wide_Type
(Designated_Type
(Etype
(D
)))
9917 or else (Nkind
(D
) = N_Attribute_Reference
9918 and then Attribute_Name
(D
) = Name_Access
9919 and then Is_Class_Wide_Type
(Etype
(Prefix
(D
))));
9920 end Is_Class_Wide_Default
;
9922 -- Start of processing for Process_Formals
9925 -- In order to prevent premature use of the formals in the same formal
9926 -- part, the Ekind is left undefined until all default expressions are
9927 -- analyzed. The Ekind is established in a separate loop at the end.
9929 Param_Spec
:= First
(T
);
9930 while Present
(Param_Spec
) loop
9931 Formal
:= Defining_Identifier
(Param_Spec
);
9932 Set_Never_Set_In_Source
(Formal
, True);
9933 Enter_Name
(Formal
);
9935 -- Case of ordinary parameters
9937 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
9938 Find_Type
(Parameter_Type
(Param_Spec
));
9939 Ptype
:= Parameter_Type
(Param_Spec
);
9941 if Ptype
= Error
then
9945 Formal_Type
:= Entity
(Ptype
);
9947 if Is_Incomplete_Type
(Formal_Type
)
9949 (Is_Class_Wide_Type
(Formal_Type
)
9950 and then Is_Incomplete_Type
(Root_Type
(Formal_Type
)))
9952 -- Ada 2005 (AI-326): Tagged incomplete types allowed in
9953 -- primitive operations, as long as their completion is
9954 -- in the same declarative part. If in the private part
9955 -- this means that the type cannot be a Taft-amendment type.
9956 -- Check is done on package exit. For access to subprograms,
9957 -- the use is legal for Taft-amendment types.
9959 -- Ada 2012: tagged incomplete types are allowed as generic
9960 -- formal types. They do not introduce dependencies and the
9961 -- corresponding generic subprogram does not have a delayed
9962 -- freeze, because it does not need a freeze node. However,
9963 -- it is still the case that untagged incomplete types cannot
9964 -- be Taft-amendment types and must be completed in private
9965 -- part, so the subprogram must appear in the list of private
9966 -- dependents of the type.
9968 if Is_Tagged_Type
(Formal_Type
)
9969 or else (Ada_Version
>= Ada_2012
9970 and then not From_Limited_With
(Formal_Type
)
9971 and then not Is_Generic_Type
(Formal_Type
))
9973 if Ekind
(Scope
(Current_Scope
)) = E_Package
9974 and then not Is_Generic_Type
(Formal_Type
)
9975 and then not Is_Class_Wide_Type
(Formal_Type
)
9978 (Parent
(T
), N_Access_Function_Definition
,
9979 N_Access_Procedure_Definition
)
9983 To
=> Private_Dependents
(Base_Type
(Formal_Type
)));
9985 -- Freezing is delayed to ensure that Register_Prim
9986 -- will get called for this operation, which is needed
9987 -- in cases where static dispatch tables aren't built.
9988 -- (Note that the same is done for controlling access
9989 -- parameter cases in function Access_Definition.)
9991 if not Is_Thunk
(Current_Scope
) then
9992 Set_Has_Delayed_Freeze
(Current_Scope
);
9997 -- Special handling of Value_Type for CIL case
9999 elsif Is_Value_Type
(Formal_Type
) then
10002 elsif not Nkind_In
(Parent
(T
), N_Access_Function_Definition
,
10003 N_Access_Procedure_Definition
)
10005 -- AI05-0151: Tagged incomplete types are allowed in all
10006 -- formal parts. Untagged incomplete types are not allowed
10007 -- in bodies. Limited views of either kind are not allowed
10008 -- if there is no place at which the non-limited view can
10009 -- become available.
10011 -- Incomplete formal untagged types are not allowed in
10012 -- subprogram bodies (but are legal in their declarations).
10014 if Is_Generic_Type
(Formal_Type
)
10015 and then not Is_Tagged_Type
(Formal_Type
)
10016 and then Nkind
(Parent
(Related_Nod
)) = N_Subprogram_Body
10019 ("invalid use of formal incomplete type", Param_Spec
);
10021 elsif Ada_Version
>= Ada_2012
then
10022 if Is_Tagged_Type
(Formal_Type
)
10023 and then (not From_Limited_With
(Formal_Type
)
10024 or else not In_Package_Body
)
10028 elsif Nkind_In
(Parent
(Parent
(T
)), N_Accept_Statement
,
10029 N_Accept_Alternative
,
10034 ("invalid use of untagged incomplete type&",
10035 Ptype
, Formal_Type
);
10040 ("invalid use of incomplete type&",
10041 Param_Spec
, Formal_Type
);
10043 -- Further checks on the legality of incomplete types
10044 -- in formal parts are delayed until the freeze point
10045 -- of the enclosing subprogram or access to subprogram.
10049 elsif Ekind
(Formal_Type
) = E_Void
then
10051 ("premature use of&",
10052 Parameter_Type
(Param_Spec
), Formal_Type
);
10055 -- Ada 2012 (AI-142): Handle aliased parameters
10057 if Ada_Version
>= Ada_2012
10058 and then Aliased_Present
(Param_Spec
)
10060 Set_Is_Aliased
(Formal
);
10063 -- Ada 2005 (AI-231): Create and decorate an internal subtype
10064 -- declaration corresponding to the null-excluding type of the
10065 -- formal in the enclosing scope. Finally, replace the parameter
10066 -- type of the formal with the internal subtype.
10068 if Ada_Version
>= Ada_2005
10069 and then Null_Exclusion_Present
(Param_Spec
)
10071 if not Is_Access_Type
(Formal_Type
) then
10073 ("`NOT NULL` allowed only for an access type", Param_Spec
);
10076 if Can_Never_Be_Null
(Formal_Type
)
10077 and then Comes_From_Source
(Related_Nod
)
10080 ("`NOT NULL` not allowed (& already excludes null)",
10081 Param_Spec
, Formal_Type
);
10085 Create_Null_Excluding_Itype
10087 Related_Nod
=> Related_Nod
,
10088 Scope_Id
=> Scope
(Current_Scope
));
10090 -- If the designated type of the itype is an itype that is
10091 -- not frozen yet, we set the Has_Delayed_Freeze attribute
10092 -- on the access subtype, to prevent order-of-elaboration
10093 -- issues in the backend.
10096 -- type T is access procedure;
10097 -- procedure Op (O : not null T);
10099 if Is_Itype
(Directly_Designated_Type
(Formal_Type
))
10101 not Is_Frozen
(Directly_Designated_Type
(Formal_Type
))
10103 Set_Has_Delayed_Freeze
(Formal_Type
);
10108 -- An access formal type
10112 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
10114 -- No need to continue if we already notified errors
10116 if not Present
(Formal_Type
) then
10120 -- Ada 2005 (AI-254)
10123 AD
: constant Node_Id
:=
10124 Access_To_Subprogram_Definition
10125 (Parameter_Type
(Param_Spec
));
10127 if Present
(AD
) and then Protected_Present
(AD
) then
10129 Replace_Anonymous_Access_To_Protected_Subprogram
10135 Set_Etype
(Formal
, Formal_Type
);
10137 -- Deal with default expression if present
10139 Default
:= Expression
(Param_Spec
);
10141 if Present
(Default
) then
10142 Check_SPARK_05_Restriction
10143 ("default expression is not allowed", Default
);
10145 if Out_Present
(Param_Spec
) then
10147 ("default initialization only allowed for IN parameters",
10151 -- Do the special preanalysis of the expression (see section on
10152 -- "Handling of Default Expressions" in the spec of package Sem).
10154 Preanalyze_Spec_Expression
(Default
, Formal_Type
);
10156 -- An access to constant cannot be the default for
10157 -- an access parameter that is an access to variable.
10159 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
10160 and then not Is_Access_Constant
(Formal_Type
)
10161 and then Is_Access_Type
(Etype
(Default
))
10162 and then Is_Access_Constant
(Etype
(Default
))
10165 ("formal that is access to variable cannot be initialized "
10166 & "with an access-to-constant expression", Default
);
10169 -- Check that the designated type of an access parameter's default
10170 -- is not a class-wide type unless the parameter's designated type
10171 -- is also class-wide.
10173 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
10174 and then not Designates_From_Limited_With
(Formal_Type
)
10175 and then Is_Class_Wide_Default
(Default
)
10176 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
10179 ("access to class-wide expression not allowed here", Default
);
10182 -- Check incorrect use of dynamically tagged expressions
10184 if Is_Tagged_Type
(Formal_Type
) then
10185 Check_Dynamically_Tagged_Expression
10187 Typ
=> Formal_Type
,
10188 Related_Nod
=> Default
);
10192 -- Ada 2005 (AI-231): Static checks
10194 if Ada_Version
>= Ada_2005
10195 and then Is_Access_Type
(Etype
(Formal
))
10196 and then Can_Never_Be_Null
(Etype
(Formal
))
10198 Null_Exclusion_Static_Checks
(Param_Spec
);
10201 -- The following checks are relevant when SPARK_Mode is on as these
10202 -- are not standard Ada legality rules.
10204 if SPARK_Mode
= On
then
10205 if Ekind_In
(Scope
(Formal
), E_Function
, E_Generic_Function
) then
10207 -- A function cannot have a parameter of mode IN OUT or OUT
10210 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_Out_Parameter
) then
10212 ("function cannot have parameter of mode `OUT` or "
10213 & "`IN OUT`", Formal
);
10215 -- A function cannot have an effectively volatile formal
10216 -- parameter (SPARK RM 7.1.3(10)).
10218 elsif Is_Effectively_Volatile
(Formal
) then
10220 ("function cannot have a volatile formal parameter",
10224 -- A procedure cannot have an effectively volatile formal
10225 -- parameter of mode IN because it behaves as a constant
10226 -- (SPARK RM 7.1.3(6)).
10228 elsif Ekind
(Scope
(Formal
)) = E_Procedure
10229 and then Ekind
(Formal
) = E_In_Parameter
10230 and then Is_Effectively_Volatile
(Formal
)
10233 ("formal parameter of mode `IN` cannot be volatile", Formal
);
10241 -- If this is the formal part of a function specification, analyze the
10242 -- subtype mark in the context where the formals are visible but not
10243 -- yet usable, and may hide outer homographs.
10245 if Nkind
(Related_Nod
) = N_Function_Specification
then
10246 Analyze_Return_Type
(Related_Nod
);
10249 -- Now set the kind (mode) of each formal
10251 Param_Spec
:= First
(T
);
10252 while Present
(Param_Spec
) loop
10253 Formal
:= Defining_Identifier
(Param_Spec
);
10254 Set_Formal_Mode
(Formal
);
10256 if Ekind
(Formal
) = E_In_Parameter
then
10257 Set_Default_Value
(Formal
, Expression
(Param_Spec
));
10259 if Present
(Expression
(Param_Spec
)) then
10260 Default
:= Expression
(Param_Spec
);
10262 if Is_Scalar_Type
(Etype
(Default
)) then
10263 if Nkind
(Parameter_Type
(Param_Spec
)) /=
10264 N_Access_Definition
10266 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
10270 (Related_Nod
, Parameter_Type
(Param_Spec
));
10273 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
10277 elsif Ekind
(Formal
) = E_Out_Parameter
then
10278 Num_Out_Params
:= Num_Out_Params
+ 1;
10280 if Num_Out_Params
= 1 then
10281 First_Out_Param
:= Formal
;
10284 elsif Ekind
(Formal
) = E_In_Out_Parameter
then
10285 Num_Out_Params
:= Num_Out_Params
+ 1;
10288 -- Skip remaining processing if formal type was in error
10290 if Etype
(Formal
) = Any_Type
or else Error_Posted
(Formal
) then
10291 goto Next_Parameter
;
10294 -- Force call by reference if aliased
10296 if Is_Aliased
(Formal
) then
10297 Set_Mechanism
(Formal
, By_Reference
);
10299 -- Warn if user asked this to be passed by copy
10301 if Convention
(Formal_Type
) = Convention_Ada_Pass_By_Copy
then
10303 ("cannot pass aliased parameter & by copy??", Formal
);
10306 -- Force mechanism if type has Convention Ada_Pass_By_Ref/Copy
10308 elsif Convention
(Formal_Type
) = Convention_Ada_Pass_By_Copy
then
10309 Set_Mechanism
(Formal
, By_Copy
);
10311 elsif Convention
(Formal_Type
) = Convention_Ada_Pass_By_Reference
then
10312 Set_Mechanism
(Formal
, By_Reference
);
10319 if Present
(First_Out_Param
) and then Num_Out_Params
= 1 then
10320 Set_Is_Only_Out_Parameter
(First_Out_Param
);
10322 end Process_Formals
;
10324 ----------------------------
10325 -- Reference_Body_Formals --
10326 ----------------------------
10328 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
) is
10333 if Error_Posted
(Spec
) then
10337 -- Iterate over both lists. They may be of different lengths if the two
10338 -- specs are not conformant.
10340 Fs
:= First_Formal
(Spec
);
10341 Fb
:= First_Formal
(Bod
);
10342 while Present
(Fs
) and then Present
(Fb
) loop
10343 Generate_Reference
(Fs
, Fb
, 'b');
10345 if Style_Check
then
10346 Style
.Check_Identifier
(Fb
, Fs
);
10349 Set_Spec_Entity
(Fb
, Fs
);
10350 Set_Referenced
(Fs
, False);
10354 end Reference_Body_Formals
;
10356 -------------------------
10357 -- Set_Actual_Subtypes --
10358 -------------------------
10360 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
10362 Formal
: Entity_Id
;
10364 First_Stmt
: Node_Id
:= Empty
;
10365 AS_Needed
: Boolean;
10368 -- If this is an empty initialization procedure, no need to create
10369 -- actual subtypes (small optimization).
10371 if Ekind
(Subp
) = E_Procedure
and then Is_Null_Init_Proc
(Subp
) then
10375 Formal
:= First_Formal
(Subp
);
10376 while Present
(Formal
) loop
10377 T
:= Etype
(Formal
);
10379 -- We never need an actual subtype for a constrained formal
10381 if Is_Constrained
(T
) then
10382 AS_Needed
:= False;
10384 -- If we have unknown discriminants, then we do not need an actual
10385 -- subtype, or more accurately we cannot figure it out. Note that
10386 -- all class-wide types have unknown discriminants.
10388 elsif Has_Unknown_Discriminants
(T
) then
10389 AS_Needed
:= False;
10391 -- At this stage we have an unconstrained type that may need an
10392 -- actual subtype. For sure the actual subtype is needed if we have
10393 -- an unconstrained array type.
10395 elsif Is_Array_Type
(T
) then
10398 -- The only other case needing an actual subtype is an unconstrained
10399 -- record type which is an IN parameter (we cannot generate actual
10400 -- subtypes for the OUT or IN OUT case, since an assignment can
10401 -- change the discriminant values. However we exclude the case of
10402 -- initialization procedures, since discriminants are handled very
10403 -- specially in this context, see the section entitled "Handling of
10404 -- Discriminants" in Einfo.
10406 -- We also exclude the case of Discrim_SO_Functions (functions used
10407 -- in front end layout mode for size/offset values), since in such
10408 -- functions only discriminants are referenced, and not only are such
10409 -- subtypes not needed, but they cannot always be generated, because
10410 -- of order of elaboration issues.
10412 elsif Is_Record_Type
(T
)
10413 and then Ekind
(Formal
) = E_In_Parameter
10414 and then Chars
(Formal
) /= Name_uInit
10415 and then not Is_Unchecked_Union
(T
)
10416 and then not Is_Discrim_SO_Function
(Subp
)
10420 -- All other cases do not need an actual subtype
10423 AS_Needed
:= False;
10426 -- Generate actual subtypes for unconstrained arrays and
10427 -- unconstrained discriminated records.
10430 if Nkind
(N
) = N_Accept_Statement
then
10432 -- If expansion is active, the formal is replaced by a local
10433 -- variable that renames the corresponding entry of the
10434 -- parameter block, and it is this local variable that may
10435 -- require an actual subtype.
10437 if Expander_Active
then
10438 Decl
:= Build_Actual_Subtype
(T
, Renamed_Object
(Formal
));
10440 Decl
:= Build_Actual_Subtype
(T
, Formal
);
10443 if Present
(Handled_Statement_Sequence
(N
)) then
10445 First
(Statements
(Handled_Statement_Sequence
(N
)));
10446 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
10447 Mark_Rewrite_Insertion
(Decl
);
10449 -- If the accept statement has no body, there will be no
10450 -- reference to the actuals, so no need to compute actual
10457 Decl
:= Build_Actual_Subtype
(T
, Formal
);
10458 Prepend
(Decl
, Declarations
(N
));
10459 Mark_Rewrite_Insertion
(Decl
);
10462 -- The declaration uses the bounds of an existing object, and
10463 -- therefore needs no constraint checks.
10465 Analyze
(Decl
, Suppress
=> All_Checks
);
10467 -- We need to freeze manually the generated type when it is
10468 -- inserted anywhere else than in a declarative part.
10470 if Present
(First_Stmt
) then
10471 Insert_List_Before_And_Analyze
(First_Stmt
,
10472 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
10474 -- Ditto if the type has a dynamic predicate, because the
10475 -- generated function will mention the actual subtype.
10477 elsif Has_Dynamic_Predicate_Aspect
(T
) then
10478 Insert_List_Before_And_Analyze
(Decl
,
10479 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
10482 if Nkind
(N
) = N_Accept_Statement
10483 and then Expander_Active
10485 Set_Actual_Subtype
(Renamed_Object
(Formal
),
10486 Defining_Identifier
(Decl
));
10488 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
10492 Next_Formal
(Formal
);
10494 end Set_Actual_Subtypes
;
10496 ---------------------
10497 -- Set_Formal_Mode --
10498 ---------------------
10500 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
10501 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
10504 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
10505 -- since we ensure that corresponding actuals are always valid at the
10506 -- point of the call.
10508 if Out_Present
(Spec
) then
10509 if Ekind_In
(Scope
(Formal_Id
), E_Function
, E_Generic_Function
) then
10511 -- [IN] OUT parameters allowed for functions in Ada 2012
10513 if Ada_Version
>= Ada_2012
then
10515 -- Even in Ada 2012 operators can only have IN parameters
10517 if Is_Operator_Symbol_Name
(Chars
(Scope
(Formal_Id
))) then
10518 Error_Msg_N
("operators can only have IN parameters", Spec
);
10521 if In_Present
(Spec
) then
10522 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
10524 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
10527 Set_Has_Out_Or_In_Out_Parameter
(Scope
(Formal_Id
), True);
10529 -- But not in earlier versions of Ada
10532 Error_Msg_N
("functions can only have IN parameters", Spec
);
10533 Set_Ekind
(Formal_Id
, E_In_Parameter
);
10536 elsif In_Present
(Spec
) then
10537 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
10540 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
10541 Set_Never_Set_In_Source
(Formal_Id
, True);
10542 Set_Is_True_Constant
(Formal_Id
, False);
10543 Set_Current_Value
(Formal_Id
, Empty
);
10547 Set_Ekind
(Formal_Id
, E_In_Parameter
);
10550 -- Set Is_Known_Non_Null for access parameters since the language
10551 -- guarantees that access parameters are always non-null. We also set
10552 -- Can_Never_Be_Null, since there is no way to change the value.
10554 if Nkind
(Parameter_Type
(Spec
)) = N_Access_Definition
then
10556 -- Ada 2005 (AI-231): In Ada 95, access parameters are always non-
10557 -- null; In Ada 2005, only if then null_exclusion is explicit.
10559 if Ada_Version
< Ada_2005
10560 or else Can_Never_Be_Null
(Etype
(Formal_Id
))
10562 Set_Is_Known_Non_Null
(Formal_Id
);
10563 Set_Can_Never_Be_Null
(Formal_Id
);
10566 -- Ada 2005 (AI-231): Null-exclusion access subtype
10568 elsif Is_Access_Type
(Etype
(Formal_Id
))
10569 and then Can_Never_Be_Null
(Etype
(Formal_Id
))
10571 Set_Is_Known_Non_Null
(Formal_Id
);
10573 -- We can also set Can_Never_Be_Null (thus preventing some junk
10574 -- access checks) for the case of an IN parameter, which cannot
10575 -- be changed, or for an IN OUT parameter, which can be changed but
10576 -- not to a null value. But for an OUT parameter, the initial value
10577 -- passed in can be null, so we can't set this flag in that case.
10579 if Ekind
(Formal_Id
) /= E_Out_Parameter
then
10580 Set_Can_Never_Be_Null
(Formal_Id
);
10584 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
10585 Set_Formal_Validity
(Formal_Id
);
10586 end Set_Formal_Mode
;
10588 -------------------------
10589 -- Set_Formal_Validity --
10590 -------------------------
10592 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
10594 -- If no validity checking, then we cannot assume anything about the
10595 -- validity of parameters, since we do not know there is any checking
10596 -- of the validity on the call side.
10598 if not Validity_Checks_On
then
10601 -- If validity checking for parameters is enabled, this means we are
10602 -- not supposed to make any assumptions about argument values.
10604 elsif Validity_Check_Parameters
then
10607 -- If we are checking in parameters, we will assume that the caller is
10608 -- also checking parameters, so we can assume the parameter is valid.
10610 elsif Ekind
(Formal_Id
) = E_In_Parameter
10611 and then Validity_Check_In_Params
10613 Set_Is_Known_Valid
(Formal_Id
, True);
10615 -- Similar treatment for IN OUT parameters
10617 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
10618 and then Validity_Check_In_Out_Params
10620 Set_Is_Known_Valid
(Formal_Id
, True);
10622 end Set_Formal_Validity
;
10624 ------------------------
10625 -- Subtype_Conformant --
10626 ------------------------
10628 function Subtype_Conformant
10629 (New_Id
: Entity_Id
;
10630 Old_Id
: Entity_Id
;
10631 Skip_Controlling_Formals
: Boolean := False) return Boolean
10635 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
,
10636 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
10638 end Subtype_Conformant
;
10640 ---------------------
10641 -- Type_Conformant --
10642 ---------------------
10644 function Type_Conformant
10645 (New_Id
: Entity_Id
;
10646 Old_Id
: Entity_Id
;
10647 Skip_Controlling_Formals
: Boolean := False) return Boolean
10651 May_Hide_Profile
:= False;
10653 (New_Id
, Old_Id
, Type_Conformant
, False, Result
,
10654 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
10656 end Type_Conformant
;
10658 -------------------------------
10659 -- Valid_Operator_Definition --
10660 -------------------------------
10662 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
10665 Id
: constant Name_Id
:= Chars
(Designator
);
10669 F
:= First_Formal
(Designator
);
10670 while Present
(F
) loop
10673 if Present
(Default_Value
(F
)) then
10675 ("default values not allowed for operator parameters",
10678 -- For function instantiations that are operators, we must check
10679 -- separately that the corresponding generic only has in-parameters.
10680 -- For subprogram declarations this is done in Set_Formal_Mode. Such
10681 -- an error could not arise in earlier versions of the language.
10683 elsif Ekind
(F
) /= E_In_Parameter
then
10684 Error_Msg_N
("operators can only have IN parameters", F
);
10690 -- Verify that user-defined operators have proper number of arguments
10691 -- First case of operators which can only be unary
10693 if Nam_In
(Id
, Name_Op_Not
, Name_Op_Abs
) then
10696 -- Case of operators which can be unary or binary
10698 elsif Nam_In
(Id
, Name_Op_Add
, Name_Op_Subtract
) then
10699 N_OK
:= (N
in 1 .. 2);
10701 -- All other operators can only be binary
10709 ("incorrect number of arguments for operator", Designator
);
10713 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
10714 and then not Is_Intrinsic_Subprogram
(Designator
)
10717 ("explicit definition of inequality not allowed", Designator
);
10719 end Valid_Operator_Definition
;