1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with 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 Ghost
; use Ghost
;
44 with Inline
; use Inline
;
45 with Itypes
; use Itypes
;
46 with Lib
.Xref
; use Lib
.Xref
;
47 with Layout
; use Layout
;
48 with Namet
; use Namet
;
50 with Nlists
; use Nlists
;
51 with Nmake
; use Nmake
;
53 with Output
; use Output
;
54 with Restrict
; use Restrict
;
55 with Rident
; use Rident
;
56 with Rtsfind
; use Rtsfind
;
58 with Sem_Aux
; use Sem_Aux
;
59 with Sem_Cat
; use Sem_Cat
;
60 with Sem_Ch3
; use Sem_Ch3
;
61 with Sem_Ch4
; use Sem_Ch4
;
62 with Sem_Ch5
; use Sem_Ch5
;
63 with Sem_Ch8
; use Sem_Ch8
;
64 with Sem_Ch10
; use Sem_Ch10
;
65 with Sem_Ch12
; use Sem_Ch12
;
66 with Sem_Ch13
; use Sem_Ch13
;
67 with Sem_Dim
; use Sem_Dim
;
68 with Sem_Disp
; use Sem_Disp
;
69 with Sem_Dist
; use Sem_Dist
;
70 with Sem_Elim
; use Sem_Elim
;
71 with Sem_Eval
; use Sem_Eval
;
72 with Sem_Mech
; use Sem_Mech
;
73 with Sem_Prag
; use Sem_Prag
;
74 with Sem_Res
; use Sem_Res
;
75 with Sem_Util
; use Sem_Util
;
76 with Sem_Type
; use Sem_Type
;
77 with Sem_Warn
; use Sem_Warn
;
78 with Sinput
; use Sinput
;
79 with Stand
; use Stand
;
80 with Sinfo
; use Sinfo
;
81 with Sinfo
.CN
; use Sinfo
.CN
;
82 with Snames
; use Snames
;
83 with Stringt
; use Stringt
;
85 with Stylesw
; use Stylesw
;
86 with Targparm
; use Targparm
;
87 with Tbuild
; use Tbuild
;
88 with Uintp
; use Uintp
;
89 with Urealp
; use Urealp
;
90 with Validsw
; use Validsw
;
92 package body Sem_Ch6
is
94 May_Hide_Profile
: Boolean := False;
95 -- This flag is used to indicate that two formals in two subprograms being
96 -- checked for conformance differ only in that one is an access parameter
97 -- while the other is of a general access type with the same designated
98 -- type. In this case, if the rest of the signatures match, a call to
99 -- either subprogram may be ambiguous, which is worth a warning. The flag
100 -- is set in Compatible_Types, and the warning emitted in
101 -- New_Overloaded_Entity.
103 -----------------------
104 -- Local Subprograms --
105 -----------------------
107 procedure Analyze_Null_Procedure
109 Is_Completion
: out Boolean);
110 -- A null procedure can be a declaration or (Ada 2012) a completion
112 procedure Analyze_Return_Statement
(N
: Node_Id
);
113 -- Common processing for simple and extended return statements
115 procedure Analyze_Function_Return
(N
: Node_Id
);
116 -- Subsidiary to Analyze_Return_Statement. Called when the return statement
117 -- applies to a [generic] function.
119 procedure Analyze_Return_Type
(N
: Node_Id
);
120 -- Subsidiary to Process_Formals: analyze subtype mark in function
121 -- specification in a context where the formals are visible and hide
124 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
);
125 -- Does all the real work of Analyze_Subprogram_Body. This is split out so
126 -- that we can use RETURN but not skip the debug output at the end.
128 procedure Analyze_Generic_Subprogram_Body
(N
: Node_Id
; Gen_Id
: Entity_Id
);
129 -- Analyze a generic subprogram body. N is the body to be analyzed, and
130 -- Gen_Id is the defining entity Id for the corresponding spec.
132 function Can_Override_Operator
(Subp
: Entity_Id
) return Boolean;
133 -- Returns true if Subp can override a predefined operator.
135 procedure Check_Conformance
138 Ctype
: Conformance_Type
;
140 Conforms
: out Boolean;
141 Err_Loc
: Node_Id
:= Empty
;
142 Get_Inst
: Boolean := False;
143 Skip_Controlling_Formals
: Boolean := False);
144 -- Given two entities, this procedure checks that the profiles associated
145 -- with these entities meet the conformance criterion given by the third
146 -- parameter. If they conform, Conforms is set True and control returns
147 -- to the caller. If they do not conform, Conforms is set to False, and
148 -- in addition, if Errmsg is True on the call, proper messages are output
149 -- to complain about the conformance failure. If Err_Loc is non_Empty
150 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
151 -- error messages are placed on the appropriate part of the construct
152 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
153 -- against a formal access-to-subprogram type so Get_Instance_Of must
156 procedure Check_Subprogram_Order
(N
: Node_Id
);
157 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
158 -- the alpha ordering rule for N if this ordering requirement applicable.
160 procedure Check_Returns
164 Proc
: Entity_Id
:= Empty
);
165 -- Called to check for missing return statements in a function body, or for
166 -- returns present in a procedure body which has No_Return set. HSS is the
167 -- handled statement sequence for the subprogram body. This procedure
168 -- checks all flow paths to make sure they either have return (Mode = 'F',
169 -- used for functions) or do not have a return (Mode = 'P', used for
170 -- No_Return procedures). The flag Err is set if there are any control
171 -- paths not explicitly terminated by a return in the function case, and is
172 -- True otherwise. Proc is the entity for the procedure case and is used
173 -- in posting the warning message.
175 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
);
176 -- In Ada 2012, a primitive equality operator on an untagged record type
177 -- must appear before the type is frozen, and have the same visibility as
178 -- that of the type. This procedure checks that this rule is met, and
179 -- otherwise emits an error on the subprogram declaration and a warning
180 -- on the earlier freeze point if it is easy to locate. In Ada 2012 mode,
181 -- this routine outputs errors (or warnings if -gnatd.E is set). In earlier
182 -- versions of Ada, warnings are output if Warn_On_Ada_2012_Incompatibility
183 -- is set, otherwise the call has no effect.
185 procedure Enter_Overloaded_Entity
(S
: Entity_Id
);
186 -- This procedure makes S, a new overloaded entity, into the first visible
187 -- entity with that name.
189 function Is_Non_Overriding_Operation
191 New_E
: Entity_Id
) return Boolean;
192 -- Enforce the rule given in 12.3(18): a private operation in an instance
193 -- overrides an inherited operation only if the corresponding operation
194 -- was overriding in the generic. This needs to be checked for primitive
195 -- operations of types derived (in the generic unit) from formal private
196 -- or formal derived types.
198 procedure Make_Inequality_Operator
(S
: Entity_Id
);
199 -- Create the declaration for an inequality operator that is implicitly
200 -- created by a user-defined equality operator that yields a boolean.
202 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
);
203 -- Formal_Id is an formal parameter entity. This procedure deals with
204 -- setting the proper validity status for this entity, which depends on
205 -- the kind of parameter and the validity checking mode.
207 ---------------------------------------------
208 -- Analyze_Abstract_Subprogram_Declaration --
209 ---------------------------------------------
211 procedure Analyze_Abstract_Subprogram_Declaration
(N
: Node_Id
) is
212 Designator
: constant Entity_Id
:=
213 Analyze_Subprogram_Specification
(Specification
(N
));
214 Scop
: constant Entity_Id
:= Current_Scope
;
217 -- The abstract subprogram declaration may be subject to pragma Ghost
218 -- with policy Ignore. Set the mode now to ensure that any nodes
219 -- generated during analysis and expansion are properly flagged as
223 Check_SPARK_05_Restriction
("abstract subprogram is not allowed", N
);
225 Generate_Definition
(Designator
);
226 Set_Contract
(Designator
, Make_Contract
(Sloc
(Designator
)));
227 Set_Is_Abstract_Subprogram
(Designator
);
228 New_Overloaded_Entity
(Designator
);
229 Check_Delayed_Subprogram
(Designator
);
231 Set_Categorization_From_Scope
(Designator
, Scop
);
233 -- An abstract subprogram declared within a Ghost region is rendered
234 -- Ghost (SPARK RM 6.9(2)).
236 if Comes_From_Source
(Designator
) and then Ghost_Mode
> None
then
237 Set_Is_Ghost_Entity
(Designator
);
240 if Ekind
(Scope
(Designator
)) = E_Protected_Type
then
242 ("abstract subprogram not allowed in protected type", N
);
244 -- Issue a warning if the abstract subprogram is neither a dispatching
245 -- operation nor an operation that overrides an inherited subprogram or
246 -- predefined operator, since this most likely indicates a mistake.
248 elsif Warn_On_Redundant_Constructs
249 and then not Is_Dispatching_Operation
(Designator
)
250 and then not Present
(Overridden_Operation
(Designator
))
251 and then (not Is_Operator_Symbol_Name
(Chars
(Designator
))
252 or else Scop
/= Scope
(Etype
(First_Formal
(Designator
))))
255 ("abstract subprogram is not dispatching or overriding?r?", N
);
258 Generate_Reference_To_Formals
(Designator
);
259 Check_Eliminated
(Designator
);
261 if Has_Aspects
(N
) then
262 Analyze_Aspect_Specifications
(N
, Designator
);
264 end Analyze_Abstract_Subprogram_Declaration
;
266 ---------------------------------
267 -- Analyze_Expression_Function --
268 ---------------------------------
270 procedure Analyze_Expression_Function
(N
: Node_Id
) is
271 Loc
: constant Source_Ptr
:= Sloc
(N
);
272 LocX
: constant Source_Ptr
:= Sloc
(Expression
(N
));
273 Expr
: constant Node_Id
:= Expression
(N
);
274 Spec
: constant Node_Id
:= Specification
(N
);
279 -- If the expression is a completion, Prev is the entity whose
280 -- declaration is completed. Def_Id is needed to analyze the spec.
287 -- This is one of the occasions on which we transform the tree during
288 -- semantic analysis. If this is a completion, transform the expression
289 -- function into an equivalent subprogram body, and analyze it.
291 -- Expression functions are inlined unconditionally. The back-end will
292 -- determine whether this is possible.
294 Inline_Processing_Required
:= True;
296 -- Create a specification for the generated body. Types and defauts in
297 -- the profile are copies of the spec, but new entities must be created
298 -- for the unit name and the formals.
300 New_Spec
:= New_Copy_Tree
(Spec
);
301 Set_Defining_Unit_Name
(New_Spec
,
302 Make_Defining_Identifier
(Sloc
(Defining_Unit_Name
(Spec
)),
303 Chars
(Defining_Unit_Name
(Spec
))));
305 if Present
(Parameter_Specifications
(New_Spec
)) then
307 Formal_Spec
: Node_Id
;
311 Formal_Spec
:= First
(Parameter_Specifications
(New_Spec
));
313 -- Create a new formal parameter at the same source position
315 while Present
(Formal_Spec
) loop
316 Def
:= Defining_Identifier
(Formal_Spec
);
317 Set_Defining_Identifier
(Formal_Spec
,
318 Make_Defining_Identifier
(Sloc
(Def
),
319 Chars
=> Chars
(Def
)));
325 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
327 -- If there are previous overloadable entities with the same name,
328 -- check whether any of them is completed by the expression function.
329 -- In a generic context a formal subprogram has no completion.
332 and then Is_Overloadable
(Prev
)
333 and then not Is_Formal_Subprogram
(Prev
)
335 Def_Id
:= Analyze_Subprogram_Specification
(Spec
);
336 Prev
:= Find_Corresponding_Spec
(N
);
338 -- The previous entity may be an expression function as well, in
339 -- which case the redeclaration is illegal.
342 and then Nkind
(Original_Node
(Unit_Declaration_Node
(Prev
))) =
343 N_Expression_Function
345 Error_Msg_Sloc
:= Sloc
(Prev
);
346 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
351 Ret
:= Make_Simple_Return_Statement
(LocX
, Expression
(N
));
354 Make_Subprogram_Body
(Loc
,
355 Specification
=> New_Spec
,
356 Declarations
=> Empty_List
,
357 Handled_Statement_Sequence
=>
358 Make_Handled_Sequence_Of_Statements
(LocX
,
359 Statements
=> New_List
(Ret
)));
361 -- If the expression completes a generic subprogram, we must create a
362 -- separate node for the body, because at instantiation the original
363 -- node of the generic copy must be a generic subprogram body, and
364 -- cannot be a expression function. Otherwise we just rewrite the
365 -- expression with the non-generic body.
367 if Present
(Prev
) and then Ekind
(Prev
) = E_Generic_Function
then
368 Insert_After
(N
, New_Body
);
370 -- Propagate any aspects or pragmas that apply to the expression
371 -- function to the proper body when the expression function acts
374 if Has_Aspects
(N
) then
375 Move_Aspects
(N
, To
=> New_Body
);
378 Relocate_Pragmas_To_Body
(New_Body
);
380 Rewrite
(N
, Make_Null_Statement
(Loc
));
381 Set_Has_Completion
(Prev
, False);
384 Set_Is_Inlined
(Prev
);
386 -- If the expression function is a completion, the previous declaration
387 -- must come from source. We know already that appears in the current
388 -- scope. The entity itself may be internally created if within a body
392 and then Comes_From_Source
(Parent
(Prev
))
393 and then not Is_Formal_Subprogram
(Prev
)
395 Set_Has_Completion
(Prev
, False);
397 -- An expression function that is a completion freezes the
398 -- expression. This means freezing the return type, and if it is
399 -- an access type, freezing its designated type as well.
401 -- Note that we cannot defer this freezing to the analysis of the
402 -- expression itself, because a freeze node might appear in a nested
403 -- scope, leading to an elaboration order issue in gigi.
405 Freeze_Before
(N
, Etype
(Prev
));
407 if Is_Access_Type
(Etype
(Prev
)) then
408 Freeze_Before
(N
, Designated_Type
(Etype
(Prev
)));
411 -- For navigation purposes, indicate that the function is a body
413 Generate_Reference
(Prev
, Defining_Entity
(N
), 'b', Force
=> True);
414 Rewrite
(N
, New_Body
);
416 -- Correct the parent pointer of the aspect specification list to
417 -- reference the rewritten node.
419 if Has_Aspects
(N
) then
420 Set_Parent
(Aspect_Specifications
(N
), N
);
423 -- Propagate any pragmas that apply to the expression function to the
424 -- proper body when the expression function acts as a completion.
425 -- Aspects are automatically transfered because of node rewriting.
427 Relocate_Pragmas_To_Body
(N
);
430 -- Prev is the previous entity with the same name, but it is can
431 -- be an unrelated spec that is not completed by the expression
432 -- function. In that case the relevant entity is the one in the body.
433 -- Not clear that the backend can inline it in this case ???
435 if Has_Completion
(Prev
) then
436 Set_Is_Inlined
(Prev
);
438 -- The formals of the expression function are body formals,
439 -- and do not appear in the ali file, which will only contain
440 -- references to the formals of the original subprogram spec.
447 F1
:= First_Formal
(Def_Id
);
448 F2
:= First_Formal
(Prev
);
450 while Present
(F1
) loop
451 Set_Spec_Entity
(F1
, F2
);
458 Set_Is_Inlined
(Defining_Entity
(New_Body
));
461 -- If this is not a completion, create both a declaration and a body, so
462 -- that the expression can be inlined whenever possible.
465 -- An expression function that is not a completion is not a
466 -- subprogram declaration, and thus cannot appear in a protected
469 if Nkind
(Parent
(N
)) = N_Protected_Definition
then
471 ("an expression function is not a legal protected operation", N
);
474 Rewrite
(N
, Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
));
476 -- Correct the parent pointer of the aspect specification list to
477 -- reference the rewritten node.
479 if Has_Aspects
(N
) then
480 Set_Parent
(Aspect_Specifications
(N
), N
);
485 -- Within a generic pre-analyze the original expression for name
486 -- capture. The body is also generated but plays no role in
487 -- this because it is not part of the original source.
489 if Inside_A_Generic
then
491 Id
: constant Entity_Id
:= Defining_Entity
(N
);
494 Set_Has_Completion
(Id
);
496 Install_Formals
(Id
);
497 Preanalyze_Spec_Expression
(Expr
, Etype
(Id
));
502 Set_Is_Inlined
(Defining_Entity
(N
));
504 -- Establish the linkages between the spec and the body. These are
505 -- used when the expression function acts as the prefix of attribute
506 -- 'Access in order to freeze the original expression which has been
507 -- moved to the generated body.
509 Set_Corresponding_Body
(N
, Defining_Entity
(New_Body
));
510 Set_Corresponding_Spec
(New_Body
, Defining_Entity
(N
));
512 -- To prevent premature freeze action, insert the new body at the end
513 -- of the current declarations, or at the end of the package spec.
514 -- However, resolve usage names now, to prevent spurious visibility
515 -- on later entities. Note that the function can now be called in
516 -- the current declarative part, which will appear to be prior to
517 -- the presence of the body in the code. There are nevertheless no
518 -- order of elaboration issues because all name resolution has taken
519 -- place at the point of declaration.
522 Decls
: List_Id
:= List_Containing
(N
);
523 Par
: constant Node_Id
:= Parent
(Decls
);
524 Id
: constant Entity_Id
:= Defining_Entity
(N
);
527 -- If this is a wrapper created for in an instance for a formal
528 -- subprogram, insert body after declaration, to be analyzed when
529 -- the enclosing instance is analyzed.
532 and then Is_Generic_Actual_Subprogram
(Defining_Entity
(N
))
534 Insert_After
(N
, New_Body
);
537 if Nkind
(Par
) = N_Package_Specification
538 and then Decls
= Visible_Declarations
(Par
)
539 and then Present
(Private_Declarations
(Par
))
540 and then not Is_Empty_List
(Private_Declarations
(Par
))
542 Decls
:= Private_Declarations
(Par
);
545 Insert_After
(Last
(Decls
), New_Body
);
547 Install_Formals
(Id
);
549 -- Preanalyze the expression for name capture, except in an
550 -- instance, where this has been done during generic analysis,
551 -- and will be redone when analyzing the body.
554 Expr
: constant Node_Id
:= Expression
(Ret
);
557 Set_Parent
(Expr
, Ret
);
559 if not In_Instance
then
560 Preanalyze_Spec_Expression
(Expr
, Etype
(Id
));
569 -- If the return expression is a static constant, we suppress warning
570 -- messages on unused formals, which in most cases will be noise.
572 Set_Is_Trivial_Subprogram
(Defining_Entity
(New_Body
),
573 Is_OK_Static_Expression
(Expr
));
574 end Analyze_Expression_Function
;
576 ----------------------------------------
577 -- Analyze_Extended_Return_Statement --
578 ----------------------------------------
580 procedure Analyze_Extended_Return_Statement
(N
: Node_Id
) is
582 Check_Compiler_Unit
("extended return statement", N
);
583 Analyze_Return_Statement
(N
);
584 end Analyze_Extended_Return_Statement
;
586 ----------------------------
587 -- Analyze_Function_Call --
588 ----------------------------
590 procedure Analyze_Function_Call
(N
: Node_Id
) is
591 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
592 Func_Nam
: constant Node_Id
:= Name
(N
);
598 -- A call of the form A.B (X) may be an Ada 2005 call, which is
599 -- rewritten as B (A, X). If the rewriting is successful, the call
600 -- has been analyzed and we just return.
602 if Nkind
(Func_Nam
) = N_Selected_Component
603 and then Name
(N
) /= Func_Nam
604 and then Is_Rewrite_Substitution
(N
)
605 and then Present
(Etype
(N
))
610 -- If error analyzing name, then set Any_Type as result type and return
612 if Etype
(Func_Nam
) = Any_Type
then
613 Set_Etype
(N
, Any_Type
);
617 -- Otherwise analyze the parameters
619 if Present
(Actuals
) then
620 Actual
:= First
(Actuals
);
621 while Present
(Actual
) loop
623 Check_Parameterless_Call
(Actual
);
629 end Analyze_Function_Call
;
631 -----------------------------
632 -- Analyze_Function_Return --
633 -----------------------------
635 procedure Analyze_Function_Return
(N
: Node_Id
) is
636 Loc
: constant Source_Ptr
:= Sloc
(N
);
637 Stm_Entity
: constant Entity_Id
:= Return_Statement_Entity
(N
);
638 Scope_Id
: constant Entity_Id
:= Return_Applies_To
(Stm_Entity
);
640 R_Type
: constant Entity_Id
:= Etype
(Scope_Id
);
641 -- Function result subtype
643 procedure Check_Limited_Return
(Expr
: Node_Id
);
644 -- Check the appropriate (Ada 95 or Ada 2005) rules for returning
645 -- limited types. Used only for simple return statements.
646 -- Expr is the expression returned.
648 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
);
649 -- Check that the return_subtype_indication properly matches the result
650 -- subtype of the function, as required by RM-6.5(5.1/2-5.3/2).
652 --------------------------
653 -- Check_Limited_Return --
654 --------------------------
656 procedure Check_Limited_Return
(Expr
: Node_Id
) is
658 -- Ada 2005 (AI-318-02): Return-by-reference types have been
659 -- removed and replaced by anonymous access results. This is an
660 -- incompatibility with Ada 95. Not clear whether this should be
661 -- enforced yet or perhaps controllable with special switch. ???
663 -- A limited interface that is not immutably limited is OK.
665 if Is_Limited_Interface
(R_Type
)
667 not (Is_Task_Interface
(R_Type
)
668 or else Is_Protected_Interface
(R_Type
)
669 or else Is_Synchronized_Interface
(R_Type
))
673 elsif Is_Limited_Type
(R_Type
)
674 and then not Is_Interface
(R_Type
)
675 and then Comes_From_Source
(N
)
676 and then not In_Instance_Body
677 and then not OK_For_Limited_Init_In_05
(R_Type
, Expr
)
681 if Ada_Version
>= Ada_2005
682 and then not Debug_Flag_Dot_L
683 and then not GNAT_Mode
686 ("(Ada 2005) cannot copy object of a limited type "
687 & "(RM-2005 6.5(5.5/2))", Expr
);
689 if Is_Limited_View
(R_Type
) then
691 ("\return by reference not permitted in Ada 2005", Expr
);
694 -- Warn in Ada 95 mode, to give folks a heads up about this
697 -- In GNAT mode, this is just a warning, to allow it to be
698 -- evilly turned off. Otherwise it is a real error.
700 -- In a generic context, simplify the warning because it makes
701 -- no sense to discuss pass-by-reference or copy.
703 elsif Warn_On_Ada_2005_Compatibility
or GNAT_Mode
then
704 if Inside_A_Generic
then
706 ("return of limited object not permitted in Ada 2005 "
707 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
709 elsif Is_Limited_View
(R_Type
) then
711 ("return by reference not permitted in Ada 2005 "
712 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
715 ("cannot copy object of a limited type in Ada 2005 "
716 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
719 -- Ada 95 mode, compatibility warnings disabled
722 return; -- skip continuation messages below
725 if not Inside_A_Generic
then
727 ("\consider switching to return of access type", Expr
);
728 Explain_Limited_Type
(R_Type
, Expr
);
731 end Check_Limited_Return
;
733 -------------------------------------
734 -- Check_Return_Subtype_Indication --
735 -------------------------------------
737 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
) is
738 Return_Obj
: constant Node_Id
:= Defining_Identifier
(Obj_Decl
);
740 R_Stm_Type
: constant Entity_Id
:= Etype
(Return_Obj
);
741 -- Subtype given in the extended return statement (must match R_Type)
743 Subtype_Ind
: constant Node_Id
:=
744 Object_Definition
(Original_Node
(Obj_Decl
));
746 R_Type_Is_Anon_Access
: constant Boolean :=
748 E_Anonymous_Access_Subprogram_Type
,
749 E_Anonymous_Access_Protected_Subprogram_Type
,
750 E_Anonymous_Access_Type
);
751 -- True if return type of the function is an anonymous access type
752 -- Can't we make Is_Anonymous_Access_Type in einfo ???
754 R_Stm_Type_Is_Anon_Access
: constant Boolean :=
755 Ekind_In
(R_Stm_Type
,
756 E_Anonymous_Access_Subprogram_Type
,
757 E_Anonymous_Access_Protected_Subprogram_Type
,
758 E_Anonymous_Access_Type
);
759 -- True if type of the return object is an anonymous access type
761 procedure Error_No_Match
(N
: Node_Id
);
762 -- Output error messages for case where types do not statically
763 -- match. N is the location for the messages.
769 procedure Error_No_Match
(N
: Node_Id
) is
772 ("subtype must statically match function result subtype", N
);
774 if not Predicates_Match
(R_Stm_Type
, R_Type
) then
775 Error_Msg_Node_2
:= R_Type
;
777 ("\predicate of& does not match predicate of&",
782 -- Start of processing for Check_Return_Subtype_Indication
785 -- First, avoid cascaded errors
787 if Error_Posted
(Obj_Decl
) or else Error_Posted
(Subtype_Ind
) then
791 -- "return access T" case; check that the return statement also has
792 -- "access T", and that the subtypes statically match:
793 -- if this is an access to subprogram the signatures must match.
795 if R_Type_Is_Anon_Access
then
796 if R_Stm_Type_Is_Anon_Access
then
798 Ekind
(Designated_Type
(R_Stm_Type
)) /= E_Subprogram_Type
800 if Base_Type
(Designated_Type
(R_Stm_Type
)) /=
801 Base_Type
(Designated_Type
(R_Type
))
802 or else not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
)
804 Error_No_Match
(Subtype_Mark
(Subtype_Ind
));
808 -- For two anonymous access to subprogram types, the
809 -- types themselves must be type conformant.
811 if not Conforming_Types
812 (R_Stm_Type
, R_Type
, Fully_Conformant
)
814 Error_No_Match
(Subtype_Ind
);
819 Error_Msg_N
("must use anonymous access type", Subtype_Ind
);
822 -- If the return object is of an anonymous access type, then report
823 -- an error if the function's result type is not also anonymous.
825 elsif R_Stm_Type_Is_Anon_Access
826 and then not R_Type_Is_Anon_Access
828 Error_Msg_N
("anonymous access not allowed for function with "
829 & "named access result", Subtype_Ind
);
831 -- Subtype indication case: check that the return object's type is
832 -- covered by the result type, and that the subtypes statically match
833 -- when the result subtype is constrained. Also handle record types
834 -- with unknown discriminants for which we have built the underlying
835 -- record view. Coverage is needed to allow specific-type return
836 -- objects when the result type is class-wide (see AI05-32).
838 elsif Covers
(Base_Type
(R_Type
), Base_Type
(R_Stm_Type
))
839 or else (Is_Underlying_Record_View
(Base_Type
(R_Stm_Type
))
843 Underlying_Record_View
(Base_Type
(R_Stm_Type
))))
845 -- A null exclusion may be present on the return type, on the
846 -- function specification, on the object declaration or on the
849 if Is_Access_Type
(R_Type
)
851 (Can_Never_Be_Null
(R_Type
)
852 or else Null_Exclusion_Present
(Parent
(Scope_Id
))) /=
853 Can_Never_Be_Null
(R_Stm_Type
)
855 Error_No_Match
(Subtype_Ind
);
858 -- AI05-103: for elementary types, subtypes must statically match
860 if Is_Constrained
(R_Type
)
861 or else Is_Access_Type
(R_Type
)
863 if not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
) then
864 Error_No_Match
(Subtype_Ind
);
868 -- All remaining cases are illegal
870 -- Note: previous versions of this subprogram allowed the return
871 -- value to be the ancestor of the return type if the return type
872 -- was a null extension. This was plainly incorrect.
876 ("wrong type for return_subtype_indication", Subtype_Ind
);
878 end Check_Return_Subtype_Indication
;
880 ---------------------
881 -- Local Variables --
882 ---------------------
887 -- Start of processing for Analyze_Function_Return
890 Set_Return_Present
(Scope_Id
);
892 if Nkind
(N
) = N_Simple_Return_Statement
then
893 Expr
:= Expression
(N
);
895 -- Guard against a malformed expression. The parser may have tried to
896 -- recover but the node is not analyzable.
898 if Nkind
(Expr
) = N_Error
then
899 Set_Etype
(Expr
, Any_Type
);
900 Expander_Mode_Save_And_Set
(False);
904 -- The resolution of a controlled [extension] aggregate associated
905 -- with a return statement creates a temporary which needs to be
906 -- finalized on function exit. Wrap the return statement inside a
907 -- block so that the finalization machinery can detect this case.
908 -- This early expansion is done only when the return statement is
909 -- not part of a handled sequence of statements.
911 if Nkind_In
(Expr
, N_Aggregate
,
912 N_Extension_Aggregate
)
913 and then Needs_Finalization
(R_Type
)
914 and then Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
917 Make_Block_Statement
(Loc
,
918 Handled_Statement_Sequence
=>
919 Make_Handled_Sequence_Of_Statements
(Loc
,
920 Statements
=> New_List
(Relocate_Node
(N
)))));
928 -- Ada 2005 (AI-251): If the type of the returned object is
929 -- an access to an interface type then we add an implicit type
930 -- conversion to force the displacement of the "this" pointer to
931 -- reference the secondary dispatch table. We cannot delay the
932 -- generation of this implicit conversion until the expansion
933 -- because in this case the type resolution changes the decoration
934 -- of the expression node to match R_Type; by contrast, if the
935 -- returned object is a class-wide interface type then it is too
936 -- early to generate here the implicit conversion since the return
937 -- statement may be rewritten by the expander into an extended
938 -- return statement whose expansion takes care of adding the
939 -- implicit type conversion to displace the pointer to the object.
942 and then Serious_Errors_Detected
= 0
943 and then Is_Access_Type
(R_Type
)
944 and then Nkind
(Expr
) /= N_Null
945 and then Is_Interface
(Designated_Type
(R_Type
))
946 and then Is_Progenitor
(Designated_Type
(R_Type
),
947 Designated_Type
(Etype
(Expr
)))
949 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
953 Resolve
(Expr
, R_Type
);
954 Check_Limited_Return
(Expr
);
957 -- RETURN only allowed in SPARK as the last statement in function
959 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
961 (Nkind
(Parent
(Parent
(N
))) /= N_Subprogram_Body
962 or else Present
(Next
(N
)))
964 Check_SPARK_05_Restriction
965 ("RETURN should be the last statement in function", N
);
969 Check_SPARK_05_Restriction
("extended RETURN is not allowed", N
);
970 Obj_Decl
:= Last
(Return_Object_Declarations
(N
));
972 -- Analyze parts specific to extended_return_statement:
975 Has_Aliased
: constant Boolean := Aliased_Present
(Obj_Decl
);
976 HSS
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
979 Expr
:= Expression
(Obj_Decl
);
981 -- Note: The check for OK_For_Limited_Init will happen in
982 -- Analyze_Object_Declaration; we treat it as a normal
983 -- object declaration.
985 Set_Is_Return_Object
(Defining_Identifier
(Obj_Decl
));
988 Check_Return_Subtype_Indication
(Obj_Decl
);
990 if Present
(HSS
) then
993 if Present
(Exception_Handlers
(HSS
)) then
995 -- ???Has_Nested_Block_With_Handler needs to be set.
996 -- Probably by creating an actual N_Block_Statement.
997 -- Probably in Expand.
1003 -- Mark the return object as referenced, since the return is an
1004 -- implicit reference of the object.
1006 Set_Referenced
(Defining_Identifier
(Obj_Decl
));
1008 Check_References
(Stm_Entity
);
1010 -- Check RM 6.5 (5.9/3)
1013 if Ada_Version
< Ada_2012
then
1015 -- Shouldn't this test Warn_On_Ada_2012_Compatibility ???
1016 -- Can it really happen (extended return???)
1019 ("aliased only allowed for limited return objects "
1020 & "in Ada 2012??", N
);
1022 elsif not Is_Limited_View
(R_Type
) then
1024 ("aliased only allowed for limited return objects", N
);
1030 -- Case of Expr present
1034 -- Defend against previous errors
1036 and then Nkind
(Expr
) /= N_Empty
1037 and then Present
(Etype
(Expr
))
1039 -- Apply constraint check. Note that this is done before the implicit
1040 -- conversion of the expression done for anonymous access types to
1041 -- ensure correct generation of the null-excluding check associated
1042 -- with null-excluding expressions found in return statements.
1044 Apply_Constraint_Check
(Expr
, R_Type
);
1046 -- Ada 2005 (AI-318-02): When the result type is an anonymous access
1047 -- type, apply an implicit conversion of the expression to that type
1048 -- to force appropriate static and run-time accessibility checks.
1050 if Ada_Version
>= Ada_2005
1051 and then Ekind
(R_Type
) = E_Anonymous_Access_Type
1053 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
1054 Analyze_And_Resolve
(Expr
, R_Type
);
1056 -- If this is a local anonymous access to subprogram, the
1057 -- accessibility check can be applied statically. The return is
1058 -- illegal if the access type of the return expression is declared
1059 -- inside of the subprogram (except if it is the subtype indication
1060 -- of an extended return statement).
1062 elsif Ekind
(R_Type
) = E_Anonymous_Access_Subprogram_Type
then
1063 if not Comes_From_Source
(Current_Scope
)
1064 or else Ekind
(Current_Scope
) = E_Return_Statement
1069 Scope_Depth
(Scope
(Etype
(Expr
))) >= Scope_Depth
(Scope_Id
)
1071 Error_Msg_N
("cannot return local access to subprogram", N
);
1074 -- The expression cannot be of a formal incomplete type
1076 elsif Ekind
(Etype
(Expr
)) = E_Incomplete_Type
1077 and then Is_Generic_Type
(Etype
(Expr
))
1080 ("cannot return expression of a formal incomplete type", N
);
1083 -- If the result type is class-wide, then check that the return
1084 -- expression's type is not declared at a deeper level than the
1085 -- function (RM05-6.5(5.6/2)).
1087 if Ada_Version
>= Ada_2005
1088 and then Is_Class_Wide_Type
(R_Type
)
1090 if Type_Access_Level
(Etype
(Expr
)) >
1091 Subprogram_Access_Level
(Scope_Id
)
1094 ("level of return expression type is deeper than "
1095 & "class-wide function!", Expr
);
1099 -- Check incorrect use of dynamically tagged expression
1101 if Is_Tagged_Type
(R_Type
) then
1102 Check_Dynamically_Tagged_Expression
1108 -- ??? A real run-time accessibility check is needed in cases
1109 -- involving dereferences of access parameters. For now we just
1110 -- check the static cases.
1112 if (Ada_Version
< Ada_2005
or else Debug_Flag_Dot_L
)
1113 and then Is_Limited_View
(Etype
(Scope_Id
))
1114 and then Object_Access_Level
(Expr
) >
1115 Subprogram_Access_Level
(Scope_Id
)
1117 -- Suppress the message in a generic, where the rewriting
1120 if Inside_A_Generic
then
1125 Make_Raise_Program_Error
(Loc
,
1126 Reason
=> PE_Accessibility_Check_Failed
));
1129 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1130 Error_Msg_N
("cannot return a local value by reference<<", N
);
1131 Error_Msg_NE
("\& [<<", N
, Standard_Program_Error
);
1135 if Known_Null
(Expr
)
1136 and then Nkind
(Parent
(Scope_Id
)) = N_Function_Specification
1137 and then Null_Exclusion_Present
(Parent
(Scope_Id
))
1139 Apply_Compile_Time_Constraint_Error
1141 Msg
=> "(Ada 2005) null not allowed for "
1142 & "null-excluding return??",
1143 Reason
=> CE_Null_Not_Allowed
);
1146 -- RM 6.5 (5.4/3): accessibility checks also apply if the return object
1147 -- has no initializing expression.
1149 elsif Ada_Version
> Ada_2005
and then Is_Class_Wide_Type
(R_Type
) then
1150 if Type_Access_Level
(Etype
(Defining_Identifier
(Obj_Decl
))) >
1151 Subprogram_Access_Level
(Scope_Id
)
1154 ("level of return expression type is deeper than "
1155 & "class-wide function!", Obj_Decl
);
1158 end Analyze_Function_Return
;
1160 -------------------------------------
1161 -- Analyze_Generic_Subprogram_Body --
1162 -------------------------------------
1164 procedure Analyze_Generic_Subprogram_Body
1168 Gen_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Gen_Id
);
1169 Kind
: constant Entity_Kind
:= Ekind
(Gen_Id
);
1170 Body_Id
: Entity_Id
;
1175 -- Copy body and disable expansion while analyzing the generic For a
1176 -- stub, do not copy the stub (which would load the proper body), this
1177 -- will be done when the proper body is analyzed.
1179 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1180 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
1185 Spec
:= Specification
(N
);
1187 -- Within the body of the generic, the subprogram is callable, and
1188 -- behaves like the corresponding non-generic unit.
1190 Body_Id
:= Defining_Entity
(Spec
);
1192 if Kind
= E_Generic_Procedure
1193 and then Nkind
(Spec
) /= N_Procedure_Specification
1195 Error_Msg_N
("invalid body for generic procedure ", Body_Id
);
1198 elsif Kind
= E_Generic_Function
1199 and then Nkind
(Spec
) /= N_Function_Specification
1201 Error_Msg_N
("invalid body for generic function ", Body_Id
);
1205 Set_Corresponding_Body
(Gen_Decl
, Body_Id
);
1207 if Has_Completion
(Gen_Id
)
1208 and then Nkind
(Parent
(N
)) /= N_Subunit
1210 Error_Msg_N
("duplicate generic body", N
);
1213 Set_Has_Completion
(Gen_Id
);
1216 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1217 Set_Ekind
(Defining_Entity
(Specification
(N
)), Kind
);
1219 Set_Corresponding_Spec
(N
, Gen_Id
);
1222 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1223 Set_Cunit_Entity
(Current_Sem_Unit
, Defining_Entity
(N
));
1226 -- Make generic parameters immediately visible in the body. They are
1227 -- needed to process the formals declarations. Then make the formals
1228 -- visible in a separate step.
1230 Push_Scope
(Gen_Id
);
1234 First_Ent
: Entity_Id
;
1237 First_Ent
:= First_Entity
(Gen_Id
);
1240 while Present
(E
) and then not Is_Formal
(E
) loop
1245 Set_Use
(Generic_Formal_Declarations
(Gen_Decl
));
1247 -- Now generic formals are visible, and the specification can be
1248 -- analyzed, for subsequent conformance check.
1250 Body_Id
:= Analyze_Subprogram_Specification
(Spec
);
1252 -- Make formal parameters visible
1256 -- E is the first formal parameter, we loop through the formals
1257 -- installing them so that they will be visible.
1259 Set_First_Entity
(Gen_Id
, E
);
1260 while Present
(E
) loop
1266 -- Visible generic entity is callable within its own body
1268 Set_Ekind
(Gen_Id
, Ekind
(Body_Id
));
1269 Set_Contract
(Body_Id
, Make_Contract
(Sloc
(Body_Id
)));
1270 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
1271 Set_Convention
(Body_Id
, Convention
(Gen_Id
));
1272 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Gen_Id
));
1273 Set_Scope
(Body_Id
, Scope
(Gen_Id
));
1275 -- Inherit the "ghostness" of the generic spec. Note that this
1276 -- property is not directly inherited as the body may be subject
1277 -- to a different Ghost assertion policy.
1279 if Is_Ghost_Entity
(Gen_Id
) or else Ghost_Mode
> None
then
1280 Set_Is_Ghost_Entity
(Body_Id
);
1282 -- The Ghost policy in effect at the point of declaration and at
1283 -- the point of completion must match (SPARK RM 6.9(15)).
1285 Check_Ghost_Completion
(Gen_Id
, Body_Id
);
1288 Check_Fully_Conformant
(Body_Id
, Gen_Id
, Body_Id
);
1290 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1292 -- No body to analyze, so restore state of generic unit
1294 Set_Ekind
(Gen_Id
, Kind
);
1295 Set_Ekind
(Body_Id
, Kind
);
1297 if Present
(First_Ent
) then
1298 Set_First_Entity
(Gen_Id
, First_Ent
);
1305 -- If this is a compilation unit, it must be made visible explicitly,
1306 -- because the compilation of the declaration, unlike other library
1307 -- unit declarations, does not. If it is not a unit, the following
1308 -- is redundant but harmless.
1310 Set_Is_Immediately_Visible
(Gen_Id
);
1311 Reference_Body_Formals
(Gen_Id
, Body_Id
);
1313 if Is_Child_Unit
(Gen_Id
) then
1314 Generate_Reference
(Gen_Id
, Scope
(Gen_Id
), 'k', False);
1317 Set_Actual_Subtypes
(N
, Current_Scope
);
1319 -- Deal with [refined] preconditions, postconditions, Contract_Cases,
1320 -- invariants and predicates associated with the body and its spec.
1321 -- Note that this is not pure expansion as Expand_Subprogram_Contract
1322 -- prepares the contract assertions for generic subprograms or for
1323 -- ASIS. Do not generate contract checks in SPARK mode.
1325 if not GNATprove_Mode
then
1326 Expand_Subprogram_Contract
(N
, Gen_Id
, Body_Id
);
1329 -- If the generic unit carries pre- or post-conditions, copy them
1330 -- to the original generic tree, so that they are properly added
1331 -- to any instantiation.
1334 Orig
: constant Node_Id
:= Original_Node
(N
);
1338 Cond
:= First
(Declarations
(N
));
1339 while Present
(Cond
) loop
1340 if Nkind
(Cond
) = N_Pragma
1341 and then Pragma_Name
(Cond
) = Name_Check
1343 Prepend
(New_Copy_Tree
(Cond
), Declarations
(Orig
));
1345 elsif Nkind
(Cond
) = N_Pragma
1346 and then Pragma_Name
(Cond
) = Name_Postcondition
1348 Set_Ekind
(Defining_Entity
(Orig
), Ekind
(Gen_Id
));
1349 Prepend
(New_Copy_Tree
(Cond
), Declarations
(Orig
));
1358 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
1359 Set_SPARK_Pragma_Inherited
(Body_Id
, True);
1361 Analyze_Declarations
(Declarations
(N
));
1363 Analyze
(Handled_Statement_Sequence
(N
));
1365 Save_Global_References
(Original_Node
(N
));
1367 -- Prior to exiting the scope, include generic formals again (if any
1368 -- are present) in the set of local entities.
1370 if Present
(First_Ent
) then
1371 Set_First_Entity
(Gen_Id
, First_Ent
);
1374 Check_References
(Gen_Id
);
1377 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Current_Scope
);
1379 Check_Subprogram_Order
(N
);
1381 -- Outside of its body, unit is generic again
1383 Set_Ekind
(Gen_Id
, Kind
);
1384 Generate_Reference
(Gen_Id
, Body_Id
, 'b', Set_Ref
=> False);
1387 Style
.Check_Identifier
(Body_Id
, Gen_Id
);
1391 end Analyze_Generic_Subprogram_Body
;
1393 ----------------------------
1394 -- Analyze_Null_Procedure --
1395 ----------------------------
1397 procedure Analyze_Null_Procedure
1399 Is_Completion
: out Boolean)
1401 Loc
: constant Source_Ptr
:= Sloc
(N
);
1402 Spec
: constant Node_Id
:= Specification
(N
);
1403 Designator
: Entity_Id
;
1405 Null_Body
: Node_Id
:= Empty
;
1409 -- Capture the profile of the null procedure before analysis, for
1410 -- expansion at the freeze point and at each point of call. The body is
1411 -- used if the procedure has preconditions, or if it is a completion. In
1412 -- the first case the body is analyzed at the freeze point, in the other
1413 -- it replaces the null procedure declaration.
1416 Make_Subprogram_Body
(Loc
,
1417 Specification
=> New_Copy_Tree
(Spec
),
1418 Declarations
=> New_List
,
1419 Handled_Statement_Sequence
=>
1420 Make_Handled_Sequence_Of_Statements
(Loc
,
1421 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
1423 -- Create new entities for body and formals
1425 Set_Defining_Unit_Name
(Specification
(Null_Body
),
1426 Make_Defining_Identifier
1427 (Sloc
(Defining_Entity
(N
)),
1428 Chars
(Defining_Entity
(N
))));
1430 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1431 while Present
(Form
) loop
1432 Set_Defining_Identifier
(Form
,
1433 Make_Defining_Identifier
1434 (Sloc
(Defining_Identifier
(Form
)),
1435 Chars
(Defining_Identifier
(Form
))));
1439 -- Determine whether the null procedure may be a completion of a generic
1440 -- suprogram, in which case we use the new null body as the completion
1441 -- and set minimal semantic information on the original declaration,
1442 -- which is rewritten as a null statement.
1444 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
1446 if Present
(Prev
) and then Is_Generic_Subprogram
(Prev
) then
1447 Insert_Before
(N
, Null_Body
);
1448 Set_Ekind
(Defining_Entity
(N
), Ekind
(Prev
));
1449 Set_Contract
(Defining_Entity
(N
), Make_Contract
(Loc
));
1451 Rewrite
(N
, Make_Null_Statement
(Loc
));
1452 Analyze_Generic_Subprogram_Body
(Null_Body
, Prev
);
1453 Is_Completion
:= True;
1457 -- Resolve the types of the formals now, because the freeze point
1458 -- may appear in a different context, e.g. an instantiation.
1460 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1461 while Present
(Form
) loop
1462 if Nkind
(Parameter_Type
(Form
)) /= N_Access_Definition
then
1463 Find_Type
(Parameter_Type
(Form
));
1466 No
(Access_To_Subprogram_Definition
(Parameter_Type
(Form
)))
1468 Find_Type
(Subtype_Mark
(Parameter_Type
(Form
)));
1471 -- The case of a null procedure with a formal that is an
1472 -- access_to_subprogram type, and that is used as an actual
1473 -- in an instantiation is left to the enthusiastic reader.
1482 -- If there are previous overloadable entities with the same name,
1483 -- check whether any of them is completed by the null procedure.
1485 if Present
(Prev
) and then Is_Overloadable
(Prev
) then
1486 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1487 Prev
:= Find_Corresponding_Spec
(N
);
1490 if No
(Prev
) or else not Comes_From_Source
(Prev
) then
1491 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1492 Set_Has_Completion
(Designator
);
1494 -- Signal to caller that this is a procedure declaration
1496 Is_Completion
:= False;
1498 -- Null procedures are always inlined, but generic formal subprograms
1499 -- which appear as such in the internal instance of formal packages,
1500 -- need no completion and are not marked Inline.
1503 and then Nkind
(N
) /= N_Formal_Concrete_Subprogram_Declaration
1505 Set_Corresponding_Body
(N
, Defining_Entity
(Null_Body
));
1506 Set_Body_To_Inline
(N
, Null_Body
);
1507 Set_Is_Inlined
(Designator
);
1511 -- The null procedure is a completion. We unconditionally rewrite
1512 -- this as a null body (even if expansion is not active), because
1513 -- there are various error checks that are applied on this body
1514 -- when it is analyzed (e.g. correct aspect placement).
1516 if Has_Completion
(Prev
) then
1517 Error_Msg_Sloc
:= Sloc
(Prev
);
1518 Error_Msg_NE
("duplicate body for & declared#", N
, Prev
);
1521 Is_Completion
:= True;
1522 Rewrite
(N
, Null_Body
);
1525 end Analyze_Null_Procedure
;
1527 -----------------------------
1528 -- Analyze_Operator_Symbol --
1529 -----------------------------
1531 -- An operator symbol such as "+" or "and" may appear in context where the
1532 -- literal denotes an entity name, such as "+"(x, y) or in context when it
1533 -- is just a string, as in (conjunction = "or"). In these cases the parser
1534 -- generates this node, and the semantics does the disambiguation. Other
1535 -- such case are actuals in an instantiation, the generic unit in an
1536 -- instantiation, and pragma arguments.
1538 procedure Analyze_Operator_Symbol
(N
: Node_Id
) is
1539 Par
: constant Node_Id
:= Parent
(N
);
1542 if (Nkind
(Par
) = N_Function_Call
and then N
= Name
(Par
))
1543 or else Nkind
(Par
) = N_Function_Instantiation
1544 or else (Nkind
(Par
) = N_Indexed_Component
and then N
= Prefix
(Par
))
1545 or else (Nkind
(Par
) = N_Pragma_Argument_Association
1546 and then not Is_Pragma_String_Literal
(Par
))
1547 or else Nkind
(Par
) = N_Subprogram_Renaming_Declaration
1548 or else (Nkind
(Par
) = N_Attribute_Reference
1549 and then Attribute_Name
(Par
) /= Name_Value
)
1551 Find_Direct_Name
(N
);
1554 Change_Operator_Symbol_To_String_Literal
(N
);
1557 end Analyze_Operator_Symbol
;
1559 -----------------------------------
1560 -- Analyze_Parameter_Association --
1561 -----------------------------------
1563 procedure Analyze_Parameter_Association
(N
: Node_Id
) is
1565 Analyze
(Explicit_Actual_Parameter
(N
));
1566 end Analyze_Parameter_Association
;
1568 ----------------------------
1569 -- Analyze_Procedure_Call --
1570 ----------------------------
1572 procedure Analyze_Procedure_Call
(N
: Node_Id
) is
1573 Loc
: constant Source_Ptr
:= Sloc
(N
);
1574 P
: constant Node_Id
:= Name
(N
);
1575 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
1579 procedure Analyze_Call_And_Resolve
;
1580 -- Do Analyze and Resolve calls for procedure call
1581 -- At end, check illegal order dependence.
1583 ------------------------------
1584 -- Analyze_Call_And_Resolve --
1585 ------------------------------
1587 procedure Analyze_Call_And_Resolve
is
1589 if Nkind
(N
) = N_Procedure_Call_Statement
then
1591 Resolve
(N
, Standard_Void_Type
);
1595 end Analyze_Call_And_Resolve
;
1597 -- Start of processing for Analyze_Procedure_Call
1600 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
1601 -- a procedure call or an entry call. The prefix may denote an access
1602 -- to subprogram type, in which case an implicit dereference applies.
1603 -- If the prefix is an indexed component (without implicit dereference)
1604 -- then the construct denotes a call to a member of an entire family.
1605 -- If the prefix is a simple name, it may still denote a call to a
1606 -- parameterless member of an entry family. Resolution of these various
1607 -- interpretations is delicate.
1611 -- If this is a call of the form Obj.Op, the call may have been
1612 -- analyzed and possibly rewritten into a block, in which case
1615 if Analyzed
(N
) then
1619 -- If there is an error analyzing the name (which may have been
1620 -- rewritten if the original call was in prefix notation) then error
1621 -- has been emitted already, mark node and return.
1623 if Error_Posted
(N
) or else Etype
(Name
(N
)) = Any_Type
then
1624 Set_Etype
(N
, Any_Type
);
1628 -- The name of the procedure call may reference an entity subject to
1629 -- pragma Ghost with policy Ignore. Set the mode now to ensure that any
1630 -- nodes generated during analysis and expansion are properly flagged as
1635 -- Otherwise analyze the parameters
1637 if Present
(Actuals
) then
1638 Actual
:= First
(Actuals
);
1640 while Present
(Actual
) loop
1642 Check_Parameterless_Call
(Actual
);
1647 -- Special processing for Elab_Spec, Elab_Body and Elab_Subp_Body calls
1649 if Nkind
(P
) = N_Attribute_Reference
1650 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Spec
,
1652 Name_Elab_Subp_Body
)
1654 if Present
(Actuals
) then
1656 ("no parameters allowed for this call", First
(Actuals
));
1660 Set_Etype
(N
, Standard_Void_Type
);
1663 elsif Is_Entity_Name
(P
)
1664 and then Is_Record_Type
(Etype
(Entity
(P
)))
1665 and then Remote_AST_I_Dereference
(P
)
1669 elsif Is_Entity_Name
(P
)
1670 and then Ekind
(Entity
(P
)) /= E_Entry_Family
1672 if Is_Access_Type
(Etype
(P
))
1673 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1674 and then No
(Actuals
)
1675 and then Comes_From_Source
(N
)
1677 Error_Msg_N
("missing explicit dereference in call", N
);
1680 Analyze_Call_And_Resolve
;
1682 -- If the prefix is the simple name of an entry family, this is
1683 -- a parameterless call from within the task body itself.
1685 elsif Is_Entity_Name
(P
)
1686 and then Nkind
(P
) = N_Identifier
1687 and then Ekind
(Entity
(P
)) = E_Entry_Family
1688 and then Present
(Actuals
)
1689 and then No
(Next
(First
(Actuals
)))
1691 -- Can be call to parameterless entry family. What appears to be the
1692 -- sole argument is in fact the entry index. Rewrite prefix of node
1693 -- accordingly. Source representation is unchanged by this
1697 Make_Indexed_Component
(Loc
,
1699 Make_Selected_Component
(Loc
,
1700 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(P
)), Loc
),
1701 Selector_Name
=> New_Occurrence_Of
(Entity
(P
), Loc
)),
1702 Expressions
=> Actuals
);
1703 Set_Name
(N
, New_N
);
1704 Set_Etype
(New_N
, Standard_Void_Type
);
1705 Set_Parameter_Associations
(N
, No_List
);
1706 Analyze_Call_And_Resolve
;
1708 elsif Nkind
(P
) = N_Explicit_Dereference
then
1709 if Ekind
(Etype
(P
)) = E_Subprogram_Type
then
1710 Analyze_Call_And_Resolve
;
1712 Error_Msg_N
("expect access to procedure in call", P
);
1715 -- The name can be a selected component or an indexed component that
1716 -- yields an access to subprogram. Such a prefix is legal if the call
1717 -- has parameter associations.
1719 elsif Is_Access_Type
(Etype
(P
))
1720 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1722 if Present
(Actuals
) then
1723 Analyze_Call_And_Resolve
;
1725 Error_Msg_N
("missing explicit dereference in call ", N
);
1728 -- If not an access to subprogram, then the prefix must resolve to the
1729 -- name of an entry, entry family, or protected operation.
1731 -- For the case of a simple entry call, P is a selected component where
1732 -- the prefix is the task and the selector name is the entry. A call to
1733 -- a protected procedure will have the same syntax. If the protected
1734 -- object contains overloaded operations, the entity may appear as a
1735 -- function, the context will select the operation whose type is Void.
1737 elsif Nkind
(P
) = N_Selected_Component
1738 and then Ekind_In
(Entity
(Selector_Name
(P
)), E_Entry
,
1742 Analyze_Call_And_Resolve
;
1744 elsif Nkind
(P
) = N_Selected_Component
1745 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
1746 and then Present
(Actuals
)
1747 and then No
(Next
(First
(Actuals
)))
1749 -- Can be call to parameterless entry family. What appears to be the
1750 -- sole argument is in fact the entry index. Rewrite prefix of node
1751 -- accordingly. Source representation is unchanged by this
1755 Make_Indexed_Component
(Loc
,
1756 Prefix
=> New_Copy
(P
),
1757 Expressions
=> Actuals
);
1758 Set_Name
(N
, New_N
);
1759 Set_Etype
(New_N
, Standard_Void_Type
);
1760 Set_Parameter_Associations
(N
, No_List
);
1761 Analyze_Call_And_Resolve
;
1763 -- For the case of a reference to an element of an entry family, P is
1764 -- an indexed component whose prefix is a selected component (task and
1765 -- entry family), and whose index is the entry family index.
1767 elsif Nkind
(P
) = N_Indexed_Component
1768 and then Nkind
(Prefix
(P
)) = N_Selected_Component
1769 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) = E_Entry_Family
1771 Analyze_Call_And_Resolve
;
1773 -- If the prefix is the name of an entry family, it is a call from
1774 -- within the task body itself.
1776 elsif Nkind
(P
) = N_Indexed_Component
1777 and then Nkind
(Prefix
(P
)) = N_Identifier
1778 and then Ekind
(Entity
(Prefix
(P
))) = E_Entry_Family
1781 Make_Selected_Component
(Loc
,
1782 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(Prefix
(P
))), Loc
),
1783 Selector_Name
=> New_Occurrence_Of
(Entity
(Prefix
(P
)), Loc
));
1784 Rewrite
(Prefix
(P
), New_N
);
1786 Analyze_Call_And_Resolve
;
1788 -- In Ada 2012. a qualified expression is a name, but it cannot be a
1789 -- procedure name, so the construct can only be a qualified expression.
1791 elsif Nkind
(P
) = N_Qualified_Expression
1792 and then Ada_Version
>= Ada_2012
1794 Rewrite
(N
, Make_Code_Statement
(Loc
, Expression
=> P
));
1797 -- Anything else is an error
1800 Error_Msg_N
("invalid procedure or entry call", N
);
1802 end Analyze_Procedure_Call
;
1804 ------------------------------
1805 -- Analyze_Return_Statement --
1806 ------------------------------
1808 procedure Analyze_Return_Statement
(N
: Node_Id
) is
1810 pragma Assert
(Nkind_In
(N
, N_Simple_Return_Statement
,
1811 N_Extended_Return_Statement
));
1813 Returns_Object
: constant Boolean :=
1814 Nkind
(N
) = N_Extended_Return_Statement
1816 (Nkind
(N
) = N_Simple_Return_Statement
1817 and then Present
(Expression
(N
)));
1818 -- True if we're returning something; that is, "return <expression>;"
1819 -- or "return Result : T [:= ...]". False for "return;". Used for error
1820 -- checking: If Returns_Object is True, N should apply to a function
1821 -- body; otherwise N should apply to a procedure body, entry body,
1822 -- accept statement, or extended return statement.
1824 function Find_What_It_Applies_To
return Entity_Id
;
1825 -- Find the entity representing the innermost enclosing body, accept
1826 -- statement, or extended return statement. If the result is a callable
1827 -- construct or extended return statement, then this will be the value
1828 -- of the Return_Applies_To attribute. Otherwise, the program is
1829 -- illegal. See RM-6.5(4/2).
1831 -----------------------------
1832 -- Find_What_It_Applies_To --
1833 -----------------------------
1835 function Find_What_It_Applies_To
return Entity_Id
is
1836 Result
: Entity_Id
:= Empty
;
1839 -- Loop outward through the Scope_Stack, skipping blocks, loops,
1840 -- and postconditions.
1842 for J
in reverse 0 .. Scope_Stack
.Last
loop
1843 Result
:= Scope_Stack
.Table
(J
).Entity
;
1844 exit when not Ekind_In
(Result
, E_Block
, E_Loop
)
1845 and then Chars
(Result
) /= Name_uPostconditions
;
1848 pragma Assert
(Present
(Result
));
1850 end Find_What_It_Applies_To
;
1852 -- Local declarations
1854 Scope_Id
: constant Entity_Id
:= Find_What_It_Applies_To
;
1855 Kind
: constant Entity_Kind
:= Ekind
(Scope_Id
);
1856 Loc
: constant Source_Ptr
:= Sloc
(N
);
1857 Stm_Entity
: constant Entity_Id
:=
1859 (E_Return_Statement
, Current_Scope
, Loc
, 'R');
1861 -- Start of processing for Analyze_Return_Statement
1864 Set_Return_Statement_Entity
(N
, Stm_Entity
);
1866 Set_Etype
(Stm_Entity
, Standard_Void_Type
);
1867 Set_Return_Applies_To
(Stm_Entity
, Scope_Id
);
1869 -- Place Return entity on scope stack, to simplify enforcement of 6.5
1870 -- (4/2): an inner return statement will apply to this extended return.
1872 if Nkind
(N
) = N_Extended_Return_Statement
then
1873 Push_Scope
(Stm_Entity
);
1876 -- Check that pragma No_Return is obeyed. Don't complain about the
1877 -- implicitly-generated return that is placed at the end.
1879 if No_Return
(Scope_Id
) and then Comes_From_Source
(N
) then
1880 Error_Msg_N
("RETURN statement not allowed (No_Return)", N
);
1883 -- Warn on any unassigned OUT parameters if in procedure
1885 if Ekind
(Scope_Id
) = E_Procedure
then
1886 Warn_On_Unassigned_Out_Parameter
(N
, Scope_Id
);
1889 -- Check that functions return objects, and other things do not
1891 if Kind
= E_Function
or else Kind
= E_Generic_Function
then
1892 if not Returns_Object
then
1893 Error_Msg_N
("missing expression in return from function", N
);
1896 elsif Kind
= E_Procedure
or else Kind
= E_Generic_Procedure
then
1897 if Returns_Object
then
1898 Error_Msg_N
("procedure cannot return value (use function)", N
);
1901 elsif Kind
= E_Entry
or else Kind
= E_Entry_Family
then
1902 if Returns_Object
then
1903 if Is_Protected_Type
(Scope
(Scope_Id
)) then
1904 Error_Msg_N
("entry body cannot return value", N
);
1906 Error_Msg_N
("accept statement cannot return value", N
);
1910 elsif Kind
= E_Return_Statement
then
1912 -- We are nested within another return statement, which must be an
1913 -- extended_return_statement.
1915 if Returns_Object
then
1916 if Nkind
(N
) = N_Extended_Return_Statement
then
1918 ("extended return statement cannot be nested (use `RETURN;`)",
1921 -- Case of a simple return statement with a value inside extended
1922 -- return statement.
1926 ("return nested in extended return statement cannot return "
1927 & "value (use `RETURN;`)", N
);
1932 Error_Msg_N
("illegal context for return statement", N
);
1935 if Ekind_In
(Kind
, E_Function
, E_Generic_Function
) then
1936 Analyze_Function_Return
(N
);
1938 elsif Ekind_In
(Kind
, E_Procedure
, E_Generic_Procedure
) then
1939 Set_Return_Present
(Scope_Id
);
1942 if Nkind
(N
) = N_Extended_Return_Statement
then
1946 Kill_Current_Values
(Last_Assignment_Only
=> True);
1947 Check_Unreachable_Code
(N
);
1949 Analyze_Dimension
(N
);
1950 end Analyze_Return_Statement
;
1952 -------------------------------------
1953 -- Analyze_Simple_Return_Statement --
1954 -------------------------------------
1956 procedure Analyze_Simple_Return_Statement
(N
: Node_Id
) is
1958 if Present
(Expression
(N
)) then
1959 Mark_Coextensions
(N
, Expression
(N
));
1962 Analyze_Return_Statement
(N
);
1963 end Analyze_Simple_Return_Statement
;
1965 -------------------------
1966 -- Analyze_Return_Type --
1967 -------------------------
1969 procedure Analyze_Return_Type
(N
: Node_Id
) is
1970 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
1971 Typ
: Entity_Id
:= Empty
;
1974 -- Normal case where result definition does not indicate an error
1976 if Result_Definition
(N
) /= Error
then
1977 if Nkind
(Result_Definition
(N
)) = N_Access_Definition
then
1978 Check_SPARK_05_Restriction
1979 ("access result is not allowed", Result_Definition
(N
));
1981 -- Ada 2005 (AI-254): Handle anonymous access to subprograms
1984 AD
: constant Node_Id
:=
1985 Access_To_Subprogram_Definition
(Result_Definition
(N
));
1987 if Present
(AD
) and then Protected_Present
(AD
) then
1988 Typ
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
1990 Typ
:= Access_Definition
(N
, Result_Definition
(N
));
1994 Set_Parent
(Typ
, Result_Definition
(N
));
1995 Set_Is_Local_Anonymous_Access
(Typ
);
1996 Set_Etype
(Designator
, Typ
);
1998 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
2000 Null_Exclusion_Static_Checks
(N
);
2002 -- Subtype_Mark case
2005 Find_Type
(Result_Definition
(N
));
2006 Typ
:= Entity
(Result_Definition
(N
));
2007 Set_Etype
(Designator
, Typ
);
2009 -- Unconstrained array as result is not allowed in SPARK
2011 if Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
2012 Check_SPARK_05_Restriction
2013 ("returning an unconstrained array is not allowed",
2014 Result_Definition
(N
));
2017 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
2019 Null_Exclusion_Static_Checks
(N
);
2021 -- If a null exclusion is imposed on the result type, then create
2022 -- a null-excluding itype (an access subtype) and use it as the
2023 -- function's Etype. Note that the null exclusion checks are done
2024 -- right before this, because they don't get applied to types that
2025 -- do not come from source.
2027 if Is_Access_Type
(Typ
) and then Null_Exclusion_Present
(N
) then
2028 Set_Etype
(Designator
,
2029 Create_Null_Excluding_Itype
2032 Scope_Id
=> Scope
(Current_Scope
)));
2034 -- The new subtype must be elaborated before use because
2035 -- it is visible outside of the function. However its base
2036 -- type may not be frozen yet, so the reference that will
2037 -- force elaboration must be attached to the freezing of
2040 -- If the return specification appears on a proper body,
2041 -- the subtype will have been created already on the spec.
2043 if Is_Frozen
(Typ
) then
2044 if Nkind
(Parent
(N
)) = N_Subprogram_Body
2045 and then Nkind
(Parent
(Parent
(N
))) = N_Subunit
2049 Build_Itype_Reference
(Etype
(Designator
), Parent
(N
));
2053 Ensure_Freeze_Node
(Typ
);
2056 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(N
));
2058 Set_Itype
(IR
, Etype
(Designator
));
2059 Append_Freeze_Actions
(Typ
, New_List
(IR
));
2064 Set_Etype
(Designator
, Typ
);
2067 if Ekind
(Typ
) = E_Incomplete_Type
2068 and then Is_Value_Type
(Typ
)
2072 elsif Ekind
(Typ
) = E_Incomplete_Type
2073 or else (Is_Class_Wide_Type
(Typ
)
2074 and then Ekind
(Root_Type
(Typ
)) = E_Incomplete_Type
)
2076 -- AI05-0151: Tagged incomplete types are allowed in all formal
2077 -- parts. Untagged incomplete types are not allowed in bodies.
2078 -- As a consequence, limited views cannot appear in a basic
2079 -- declaration that is itself within a body, because there is
2080 -- no point at which the non-limited view will become visible.
2082 if Ada_Version
>= Ada_2012
then
2083 if From_Limited_With
(Typ
) and then In_Package_Body
then
2085 ("invalid use of incomplete type&",
2086 Result_Definition
(N
), Typ
);
2088 -- The return type of a subprogram body cannot be of a
2089 -- formal incomplete type.
2091 elsif Is_Generic_Type
(Typ
)
2092 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
2095 ("return type cannot be a formal incomplete type",
2096 Result_Definition
(N
));
2098 elsif Is_Class_Wide_Type
(Typ
)
2099 and then Is_Generic_Type
(Root_Type
(Typ
))
2100 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
2103 ("return type cannot be a formal incomplete type",
2104 Result_Definition
(N
));
2106 elsif Is_Tagged_Type
(Typ
) then
2109 -- Use is legal in a thunk generated for an operation
2110 -- inherited from a progenitor.
2112 elsif Is_Thunk
(Designator
)
2113 and then Present
(Non_Limited_View
(Typ
))
2117 elsif Nkind
(Parent
(N
)) = N_Subprogram_Body
2118 or else Nkind_In
(Parent
(Parent
(N
)), N_Accept_Statement
,
2122 ("invalid use of untagged incomplete type&",
2126 -- The type must be completed in the current package. This
2127 -- is checked at the end of the package declaration when
2128 -- Taft-amendment types are identified. If the return type
2129 -- is class-wide, there is no required check, the type can
2130 -- be a bona fide TAT.
2132 if Ekind
(Scope
(Current_Scope
)) = E_Package
2133 and then In_Private_Part
(Scope
(Current_Scope
))
2134 and then not Is_Class_Wide_Type
(Typ
)
2136 Append_Elmt
(Designator
, Private_Dependents
(Typ
));
2141 ("invalid use of incomplete type&", Designator
, Typ
);
2146 -- Case where result definition does indicate an error
2149 Set_Etype
(Designator
, Any_Type
);
2151 end Analyze_Return_Type
;
2153 -----------------------------
2154 -- Analyze_Subprogram_Body --
2155 -----------------------------
2157 procedure Analyze_Subprogram_Body
(N
: Node_Id
) is
2158 Loc
: constant Source_Ptr
:= Sloc
(N
);
2159 Body_Spec
: constant Node_Id
:= Specification
(N
);
2160 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Spec
);
2163 if Debug_Flag_C
then
2164 Write_Str
("==> subprogram body ");
2165 Write_Name
(Chars
(Body_Id
));
2166 Write_Str
(" from ");
2167 Write_Location
(Loc
);
2172 Trace_Scope
(N
, Body_Id
, " Analyze subprogram: ");
2174 -- The real work is split out into the helper, so it can do "return;"
2175 -- without skipping the debug output:
2177 Analyze_Subprogram_Body_Helper
(N
);
2179 if Debug_Flag_C
then
2181 Write_Str
("<== subprogram body ");
2182 Write_Name
(Chars
(Body_Id
));
2183 Write_Str
(" from ");
2184 Write_Location
(Loc
);
2187 end Analyze_Subprogram_Body
;
2189 --------------------------------------
2190 -- Analyze_Subprogram_Body_Contract --
2191 --------------------------------------
2193 procedure Analyze_Subprogram_Body_Contract
(Body_Id
: Entity_Id
) is
2194 Body_Decl
: constant Node_Id
:= Parent
(Parent
(Body_Id
));
2195 Mode
: SPARK_Mode_Type
;
2197 Ref_Depends
: Node_Id
:= Empty
;
2198 Ref_Global
: Node_Id
:= Empty
;
2199 Spec_Id
: Entity_Id
;
2202 -- Due to the timing of contract analysis, delayed pragmas may be
2203 -- subject to the wrong SPARK_Mode, usually that of the enclosing
2204 -- context. To remedy this, restore the original SPARK_Mode of the
2205 -- related subprogram body.
2207 Save_SPARK_Mode_And_Set
(Body_Id
, Mode
);
2209 -- When a subprogram body declaration is illegal, its defining entity is
2210 -- left unanalyzed. There is nothing left to do in this case because the
2211 -- body lacks a contract, or even a proper Ekind.
2213 if Ekind
(Body_Id
) = E_Void
then
2217 if Nkind
(Body_Decl
) = N_Subprogram_Body_Stub
then
2218 Spec_Id
:= Corresponding_Spec_Of_Stub
(Body_Decl
);
2220 Spec_Id
:= Corresponding_Spec
(Body_Decl
);
2223 -- Locate and store pragmas Refined_Depends and Refined_Global since
2224 -- their order of analysis matters.
2226 Prag
:= Classifications
(Contract
(Body_Id
));
2227 while Present
(Prag
) loop
2228 if Pragma_Name
(Prag
) = Name_Refined_Depends
then
2229 Ref_Depends
:= Prag
;
2230 elsif Pragma_Name
(Prag
) = Name_Refined_Global
then
2234 Prag
:= Next_Pragma
(Prag
);
2237 -- Analyze Refined_Global first as Refined_Depends may mention items
2238 -- classified in the global refinement.
2240 if Present
(Ref_Global
) then
2241 Analyze_Refined_Global_In_Decl_Part
(Ref_Global
);
2243 -- When the corresponding Global aspect/pragma references a state with
2244 -- visible refinement, the body requires Refined_Global. Refinement is
2245 -- not required when SPARK checks are suppressed.
2247 elsif Present
(Spec_Id
) then
2248 Prag
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
2250 if SPARK_Mode
/= Off
2251 and then Present
(Prag
)
2252 and then Contains_Refined_State
(Prag
)
2255 ("body of subprogram& requires global refinement",
2256 Body_Decl
, Spec_Id
);
2260 -- Refined_Depends must be analyzed after Refined_Global in order to see
2261 -- the modes of all global refinements.
2263 if Present
(Ref_Depends
) then
2264 Analyze_Refined_Depends_In_Decl_Part
(Ref_Depends
);
2266 -- When the corresponding Depends aspect/pragma references a state with
2267 -- visible refinement, the body requires Refined_Depends. Refinement is
2268 -- not required when SPARK checks are suppressed.
2270 elsif Present
(Spec_Id
) then
2271 Prag
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
2273 if SPARK_Mode
/= Off
2274 and then Present
(Prag
)
2275 and then Contains_Refined_State
(Prag
)
2278 ("body of subprogram& requires dependance refinement",
2279 Body_Decl
, Spec_Id
);
2283 -- Restore the SPARK_Mode of the enclosing context after all delayed
2284 -- pragmas have been analyzed.
2286 Restore_SPARK_Mode
(Mode
);
2287 end Analyze_Subprogram_Body_Contract
;
2289 ------------------------------------
2290 -- Analyze_Subprogram_Body_Helper --
2291 ------------------------------------
2293 -- This procedure is called for regular subprogram bodies, generic bodies,
2294 -- and for subprogram stubs of both kinds. In the case of stubs, only the
2295 -- specification matters, and is used to create a proper declaration for
2296 -- the subprogram, or to perform conformance checks.
2298 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
) is
2299 Loc
: constant Source_Ptr
:= Sloc
(N
);
2300 Body_Spec
: constant Node_Id
:= Specification
(N
);
2301 Body_Id
: Entity_Id
:= Defining_Entity
(Body_Spec
);
2302 Prev_Id
: constant Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
2303 Conformant
: Boolean;
2305 Prot_Typ
: Entity_Id
:= Empty
;
2306 Spec_Id
: Entity_Id
;
2307 Spec_Decl
: Node_Id
:= Empty
;
2309 Last_Real_Spec_Entity
: Entity_Id
:= Empty
;
2310 -- When we analyze a separate spec, the entity chain ends up containing
2311 -- the formals, as well as any itypes generated during analysis of the
2312 -- default expressions for parameters, or the arguments of associated
2313 -- precondition/postcondition pragmas (which are analyzed in the context
2314 -- of the spec since they have visibility on formals).
2316 -- These entities belong with the spec and not the body. However we do
2317 -- the analysis of the body in the context of the spec (again to obtain
2318 -- visibility to the formals), and all the entities generated during
2319 -- this analysis end up also chained to the entity chain of the spec.
2320 -- But they really belong to the body, and there is circuitry to move
2321 -- them from the spec to the body.
2323 -- However, when we do this move, we don't want to move the real spec
2324 -- entities (first para above) to the body. The Last_Real_Spec_Entity
2325 -- variable points to the last real spec entity, so we only move those
2326 -- chained beyond that point. It is initialized to Empty to deal with
2327 -- the case where there is no separate spec.
2329 procedure Analyze_Aspects_On_Body_Or_Stub
;
2330 -- Analyze the aspect specifications of a subprogram body [stub]. It is
2331 -- assumed that N has aspects.
2333 function Body_Has_Contract
return Boolean;
2334 -- Check whether unanalyzed body has an aspect or pragma that may
2335 -- generate a SPARK contract.
2337 procedure Check_Anonymous_Return
;
2338 -- Ada 2005: if a function returns an access type that denotes a task,
2339 -- or a type that contains tasks, we must create a master entity for
2340 -- the anonymous type, which typically will be used in an allocator
2341 -- in the body of the function.
2343 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
);
2344 -- Look ahead to recognize a pragma that may appear after the body.
2345 -- If there is a previous spec, check that it appears in the same
2346 -- declarative part. If the pragma is Inline_Always, perform inlining
2347 -- unconditionally, otherwise only if Front_End_Inlining is requested.
2348 -- If the body acts as a spec, and inlining is required, we create a
2349 -- subprogram declaration for it, in order to attach the body to inline.
2350 -- If pragma does not appear after the body, check whether there is
2351 -- an inline pragma before any local declarations.
2353 procedure Check_Missing_Return
;
2354 -- Checks for a function with a no return statements, and also performs
2355 -- the warning checks implemented by Check_Returns. In formal mode, also
2356 -- verify that a function ends with a RETURN and that a procedure does
2357 -- not contain any RETURN.
2359 function Disambiguate_Spec
return Entity_Id
;
2360 -- When a primitive is declared between the private view and the full
2361 -- view of a concurrent type which implements an interface, a special
2362 -- mechanism is used to find the corresponding spec of the primitive
2365 procedure Exchange_Limited_Views
(Subp_Id
: Entity_Id
);
2366 -- Ada 2012 (AI05-0151): Detect whether the profile of Subp_Id contains
2367 -- incomplete types coming from a limited context and swap their limited
2368 -- views with the non-limited ones.
2370 function Is_Private_Concurrent_Primitive
2371 (Subp_Id
: Entity_Id
) return Boolean;
2372 -- Determine whether subprogram Subp_Id is a primitive of a concurrent
2373 -- type that implements an interface and has a private view.
2375 procedure Set_Trivial_Subprogram
(N
: Node_Id
);
2376 -- Sets the Is_Trivial_Subprogram flag in both spec and body of the
2377 -- subprogram whose body is being analyzed. N is the statement node
2378 -- causing the flag to be set, if the following statement is a return
2379 -- of an entity, we mark the entity as set in source to suppress any
2380 -- warning on the stylized use of function stubs with a dummy return.
2382 procedure Verify_Overriding_Indicator
;
2383 -- If there was a previous spec, the entity has been entered in the
2384 -- current scope previously. If the body itself carries an overriding
2385 -- indicator, check that it is consistent with the known status of the
2388 -------------------------------------
2389 -- Analyze_Aspects_On_Body_Or_Stub --
2390 -------------------------------------
2392 procedure Analyze_Aspects_On_Body_Or_Stub
is
2393 procedure Diagnose_Misplaced_Aspects
;
2394 -- Subprogram body [stub] N has aspects, but they are not properly
2395 -- placed. Provide precise diagnostics depending on the aspects
2398 --------------------------------
2399 -- Diagnose_Misplaced_Aspects --
2400 --------------------------------
2402 procedure Diagnose_Misplaced_Aspects
is
2406 -- The current aspect along with its name and id
2408 procedure SPARK_Aspect_Error
(Ref_Nam
: Name_Id
);
2409 -- Emit an error message concerning SPARK aspect Asp. Ref_Nam is
2410 -- the name of the refined version of the aspect.
2412 ------------------------
2413 -- SPARK_Aspect_Error --
2414 ------------------------
2416 procedure SPARK_Aspect_Error
(Ref_Nam
: Name_Id
) is
2418 -- The corresponding spec already contains the aspect in
2419 -- question and the one appearing on the body must be the
2422 -- procedure P with Global ...;
2423 -- procedure P with Global ... is ... end P;
2427 if Has_Aspect
(Spec_Id
, Asp_Id
) then
2428 Error_Msg_Name_1
:= Asp_Nam
;
2430 -- Subunits cannot carry aspects that apply to a subprogram
2433 if Nkind
(Parent
(N
)) = N_Subunit
then
2434 Error_Msg_N
("aspect % cannot apply to a subunit", Asp
);
2437 Error_Msg_Name_2
:= Ref_Nam
;
2438 Error_Msg_N
("aspect % should be %", Asp
);
2441 -- Otherwise the aspect must appear in the spec, not in the
2445 -- procedure P with Global ... is ... end P;
2449 ("aspect specification must appear in subprogram "
2450 & "declaration", Asp
);
2452 end SPARK_Aspect_Error
;
2454 -- Start of processing for Diagnose_Misplaced_Aspects
2457 -- Iterate over the aspect specifications and emit specific errors
2458 -- where applicable.
2460 Asp
:= First
(Aspect_Specifications
(N
));
2461 while Present
(Asp
) loop
2462 Asp_Nam
:= Chars
(Identifier
(Asp
));
2463 Asp_Id
:= Get_Aspect_Id
(Asp_Nam
);
2465 -- Do not emit errors on aspects that can appear on a
2466 -- subprogram body. This scenario occurs when the aspect
2467 -- specification list contains both misplaced and properly
2470 if Aspect_On_Body_Or_Stub_OK
(Asp_Id
) then
2473 -- Special diagnostics for SPARK aspects
2475 elsif Asp_Nam
= Name_Depends
then
2476 SPARK_Aspect_Error
(Name_Refined_Depends
);
2478 elsif Asp_Nam
= Name_Global
then
2479 SPARK_Aspect_Error
(Name_Refined_Global
);
2481 elsif Asp_Nam
= Name_Post
then
2482 SPARK_Aspect_Error
(Name_Refined_Post
);
2486 ("aspect specification must appear in subprogram "
2487 & "declaration", Asp
);
2492 end Diagnose_Misplaced_Aspects
;
2494 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
2497 -- Language-defined aspects cannot be associated with a subprogram
2498 -- body [stub] if the subprogram has a spec. Certain implementation
2499 -- defined aspects are allowed to break this rule (for list, see
2500 -- table Aspect_On_Body_Or_Stub_OK).
2502 if Present
(Spec_Id
) and then not Aspects_On_Body_Or_Stub_OK
(N
) then
2503 Diagnose_Misplaced_Aspects
;
2505 Analyze_Aspect_Specifications
(N
, Body_Id
);
2507 end Analyze_Aspects_On_Body_Or_Stub
;
2509 -----------------------
2510 -- Body_Has_Contract --
2511 -----------------------
2513 function Body_Has_Contract
return Boolean is
2514 Decls
: constant List_Id
:= Declarations
(N
);
2521 -- Check for unanalyzed aspects in the body that will
2522 -- generate a contract.
2524 if Present
(Aspect_Specifications
(N
)) then
2525 A_Spec
:= First
(Aspect_Specifications
(N
));
2526 while Present
(A_Spec
) loop
2527 A
:= Get_Aspect_Id
(Chars
(Identifier
(A_Spec
)));
2529 if A
= Aspect_Contract_Cases
or else
2530 A
= Aspect_Depends
or else
2531 A
= Aspect_Global
or else
2532 A
= Aspect_Pre
or else
2533 A
= Aspect_Precondition
or else
2534 A
= Aspect_Post
or else
2535 A
= Aspect_Postcondition
2544 -- Check for pragmas that may generate a contract
2546 if Present
(Decls
) then
2547 Decl
:= First
(Decls
);
2548 while Present
(Decl
) loop
2549 if Nkind
(Decl
) = N_Pragma
then
2550 P_Id
:= Get_Pragma_Id
(Pragma_Name
(Decl
));
2552 if P_Id
= Pragma_Contract_Cases
or else
2553 P_Id
= Pragma_Depends
or else
2554 P_Id
= Pragma_Global
or else
2555 P_Id
= Pragma_Pre
or else
2556 P_Id
= Pragma_Precondition
or else
2557 P_Id
= Pragma_Post
or else
2558 P_Id
= Pragma_Postcondition
2569 end Body_Has_Contract
;
2571 ----------------------------
2572 -- Check_Anonymous_Return --
2573 ----------------------------
2575 procedure Check_Anonymous_Return
is
2581 if Present
(Spec_Id
) then
2587 if Ekind
(Scop
) = E_Function
2588 and then Ekind
(Etype
(Scop
)) = E_Anonymous_Access_Type
2589 and then not Is_Thunk
(Scop
)
2591 -- Skip internally built functions which handle the case of
2592 -- a null access (see Expand_Interface_Conversion)
2594 and then not (Is_Interface
(Designated_Type
(Etype
(Scop
)))
2595 and then not Comes_From_Source
(Parent
(Scop
)))
2597 and then (Has_Task
(Designated_Type
(Etype
(Scop
)))
2599 (Is_Class_Wide_Type
(Designated_Type
(Etype
(Scop
)))
2601 Is_Limited_Record
(Designated_Type
(Etype
(Scop
)))))
2602 and then Expander_Active
2604 -- Avoid cases with no tasking support
2606 and then RTE_Available
(RE_Current_Master
)
2607 and then not Restriction_Active
(No_Task_Hierarchy
)
2610 Make_Object_Declaration
(Loc
,
2611 Defining_Identifier
=>
2612 Make_Defining_Identifier
(Loc
, Name_uMaster
),
2613 Constant_Present
=> True,
2614 Object_Definition
=>
2615 New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
2617 Make_Explicit_Dereference
(Loc
,
2618 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
2620 if Present
(Declarations
(N
)) then
2621 Prepend
(Decl
, Declarations
(N
));
2623 Set_Declarations
(N
, New_List
(Decl
));
2626 Set_Master_Id
(Etype
(Scop
), Defining_Identifier
(Decl
));
2627 Set_Has_Master_Entity
(Scop
);
2629 -- Now mark the containing scope as a task master
2632 while Nkind
(Par
) /= N_Compilation_Unit
loop
2633 Par
:= Parent
(Par
);
2634 pragma Assert
(Present
(Par
));
2636 -- If we fall off the top, we are at the outer level, and
2637 -- the environment task is our effective master, so nothing
2641 (Par
, N_Task_Body
, N_Block_Statement
, N_Subprogram_Body
)
2643 Set_Is_Task_Master
(Par
, True);
2648 end Check_Anonymous_Return
;
2650 -------------------------
2651 -- Check_Inline_Pragma --
2652 -------------------------
2654 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
) is
2658 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean;
2659 -- True when N is a pragma Inline or Inline_Always that applies
2660 -- to this subprogram.
2662 -----------------------
2663 -- Is_Inline_Pragma --
2664 -----------------------
2666 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean is
2669 Nkind
(N
) = N_Pragma
2671 (Pragma_Name
(N
) = Name_Inline_Always
2672 or else (Front_End_Inlining
2673 and then Pragma_Name
(N
) = Name_Inline
))
2676 (Expression
(First
(Pragma_Argument_Associations
(N
)))) =
2678 end Is_Inline_Pragma
;
2680 -- Start of processing for Check_Inline_Pragma
2683 if not Expander_Active
then
2687 if Is_List_Member
(N
)
2688 and then Present
(Next
(N
))
2689 and then Is_Inline_Pragma
(Next
(N
))
2693 elsif Nkind
(N
) /= N_Subprogram_Body_Stub
2694 and then Present
(Declarations
(N
))
2695 and then Is_Inline_Pragma
(First
(Declarations
(N
)))
2697 Prag
:= First
(Declarations
(N
));
2703 if Present
(Prag
) then
2704 if Present
(Spec_Id
) then
2705 if In_Same_List
(N
, Unit_Declaration_Node
(Spec_Id
)) then
2710 -- Create a subprogram declaration, to make treatment uniform
2713 Subp
: constant Entity_Id
:=
2714 Make_Defining_Identifier
(Loc
, Chars
(Body_Id
));
2715 Decl
: constant Node_Id
:=
2716 Make_Subprogram_Declaration
(Loc
,
2718 New_Copy_Tree
(Specification
(N
)));
2721 Set_Defining_Unit_Name
(Specification
(Decl
), Subp
);
2723 if Present
(First_Formal
(Body_Id
)) then
2724 Plist
:= Copy_Parameter_List
(Body_Id
);
2725 Set_Parameter_Specifications
2726 (Specification
(Decl
), Plist
);
2729 Insert_Before
(N
, Decl
);
2732 Set_Has_Pragma_Inline
(Subp
);
2734 if Pragma_Name
(Prag
) = Name_Inline_Always
then
2735 Set_Is_Inlined
(Subp
);
2736 Set_Has_Pragma_Inline_Always
(Subp
);
2739 -- Prior to copying the subprogram body to create a template
2740 -- for it for subsequent inlining, remove the pragma from
2741 -- the current body so that the copy that will produce the
2742 -- new body will start from a completely unanalyzed tree.
2744 if Nkind
(Parent
(Prag
)) = N_Subprogram_Body
then
2745 Rewrite
(Prag
, Make_Null_Statement
(Sloc
(Prag
)));
2752 end Check_Inline_Pragma
;
2754 --------------------------
2755 -- Check_Missing_Return --
2756 --------------------------
2758 procedure Check_Missing_Return
is
2760 Missing_Ret
: Boolean;
2763 if Nkind
(Body_Spec
) = N_Function_Specification
then
2764 if Present
(Spec_Id
) then
2770 if Return_Present
(Id
) then
2771 Check_Returns
(HSS
, 'F', Missing_Ret
);
2774 Set_Has_Missing_Return
(Id
);
2777 elsif Is_Generic_Subprogram
(Id
)
2778 or else not Is_Machine_Code_Subprogram
(Id
)
2780 Error_Msg_N
("missing RETURN statement in function body", N
);
2783 -- If procedure with No_Return, check returns
2785 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
2786 and then Present
(Spec_Id
)
2787 and then No_Return
(Spec_Id
)
2789 Check_Returns
(HSS
, 'P', Missing_Ret
, Spec_Id
);
2792 -- Special checks in SPARK mode
2794 if Nkind
(Body_Spec
) = N_Function_Specification
then
2796 -- In SPARK mode, last statement of a function should be a return
2799 Stat
: constant Node_Id
:= Last_Source_Statement
(HSS
);
2802 and then not Nkind_In
(Stat
, N_Simple_Return_Statement
,
2803 N_Extended_Return_Statement
)
2805 Check_SPARK_05_Restriction
2806 ("last statement in function should be RETURN", Stat
);
2810 -- In SPARK mode, verify that a procedure has no return
2812 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
then
2813 if Present
(Spec_Id
) then
2819 -- Would be nice to point to return statement here, can we
2820 -- borrow the Check_Returns procedure here ???
2822 if Return_Present
(Id
) then
2823 Check_SPARK_05_Restriction
2824 ("procedure should not have RETURN", N
);
2827 end Check_Missing_Return
;
2829 -----------------------
2830 -- Disambiguate_Spec --
2831 -----------------------
2833 function Disambiguate_Spec
return Entity_Id
is
2834 Priv_Spec
: Entity_Id
;
2837 procedure Replace_Types
(To_Corresponding
: Boolean);
2838 -- Depending on the flag, replace the type of formal parameters of
2839 -- Body_Id if it is a concurrent type implementing interfaces with
2840 -- the corresponding record type or the other way around.
2842 procedure Replace_Types
(To_Corresponding
: Boolean) is
2844 Formal_Typ
: Entity_Id
;
2847 Formal
:= First_Formal
(Body_Id
);
2848 while Present
(Formal
) loop
2849 Formal_Typ
:= Etype
(Formal
);
2851 if Is_Class_Wide_Type
(Formal_Typ
) then
2852 Formal_Typ
:= Root_Type
(Formal_Typ
);
2855 -- From concurrent type to corresponding record
2857 if To_Corresponding
then
2858 if Is_Concurrent_Type
(Formal_Typ
)
2859 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
2862 (Corresponding_Record_Type
(Formal_Typ
)))
2865 Corresponding_Record_Type
(Formal_Typ
));
2868 -- From corresponding record to concurrent type
2871 if Is_Concurrent_Record_Type
(Formal_Typ
)
2872 and then Present
(Interfaces
(Formal_Typ
))
2875 Corresponding_Concurrent_Type
(Formal_Typ
));
2879 Next_Formal
(Formal
);
2883 -- Start of processing for Disambiguate_Spec
2886 -- Try to retrieve the specification of the body as is. All error
2887 -- messages are suppressed because the body may not have a spec in
2888 -- its current state.
2890 Spec_N
:= Find_Corresponding_Spec
(N
, False);
2892 -- It is possible that this is the body of a primitive declared
2893 -- between a private and a full view of a concurrent type. The
2894 -- controlling parameter of the spec carries the concurrent type,
2895 -- not the corresponding record type as transformed by Analyze_
2896 -- Subprogram_Specification. In such cases, we undo the change
2897 -- made by the analysis of the specification and try to find the
2900 -- Note that wrappers already have their corresponding specs and
2901 -- bodies set during their creation, so if the candidate spec is
2902 -- a wrapper, then we definitely need to swap all types to their
2903 -- original concurrent status.
2906 or else Is_Primitive_Wrapper
(Spec_N
)
2908 -- Restore all references of corresponding record types to the
2909 -- original concurrent types.
2911 Replace_Types
(To_Corresponding
=> False);
2912 Priv_Spec
:= Find_Corresponding_Spec
(N
, False);
2914 -- The current body truly belongs to a primitive declared between
2915 -- a private and a full view. We leave the modified body as is,
2916 -- and return the true spec.
2918 if Present
(Priv_Spec
)
2919 and then Is_Private_Primitive
(Priv_Spec
)
2924 -- In case that this is some sort of error, restore the original
2925 -- state of the body.
2927 Replace_Types
(To_Corresponding
=> True);
2931 end Disambiguate_Spec
;
2933 ----------------------------
2934 -- Exchange_Limited_Views --
2935 ----------------------------
2937 procedure Exchange_Limited_Views
(Subp_Id
: Entity_Id
) is
2938 procedure Detect_And_Exchange
(Id
: Entity_Id
);
2939 -- Determine whether Id's type denotes an incomplete type associated
2940 -- with a limited with clause and exchange the limited view with the
2943 -------------------------
2944 -- Detect_And_Exchange --
2945 -------------------------
2947 procedure Detect_And_Exchange
(Id
: Entity_Id
) is
2948 Typ
: constant Entity_Id
:= Etype
(Id
);
2951 if Ekind
(Typ
) = E_Incomplete_Type
2952 and then From_Limited_With
(Typ
)
2953 and then Present
(Non_Limited_View
(Typ
))
2955 Set_Etype
(Id
, Non_Limited_View
(Typ
));
2957 end Detect_And_Exchange
;
2963 -- Start of processing for Exchange_Limited_Views
2966 if No
(Subp_Id
) then
2969 -- Do not process subprogram bodies as they already use the non-
2970 -- limited view of types.
2972 elsif not Ekind_In
(Subp_Id
, E_Function
, E_Procedure
) then
2976 -- Examine all formals and swap views when applicable
2978 Formal
:= First_Formal
(Subp_Id
);
2979 while Present
(Formal
) loop
2980 Detect_And_Exchange
(Formal
);
2982 Next_Formal
(Formal
);
2985 -- Process the return type of a function
2987 if Ekind
(Subp_Id
) = E_Function
then
2988 Detect_And_Exchange
(Subp_Id
);
2990 end Exchange_Limited_Views
;
2992 -------------------------------------
2993 -- Is_Private_Concurrent_Primitive --
2994 -------------------------------------
2996 function Is_Private_Concurrent_Primitive
2997 (Subp_Id
: Entity_Id
) return Boolean
2999 Formal_Typ
: Entity_Id
;
3002 if Present
(First_Formal
(Subp_Id
)) then
3003 Formal_Typ
:= Etype
(First_Formal
(Subp_Id
));
3005 if Is_Concurrent_Record_Type
(Formal_Typ
) then
3006 if Is_Class_Wide_Type
(Formal_Typ
) then
3007 Formal_Typ
:= Root_Type
(Formal_Typ
);
3010 Formal_Typ
:= Corresponding_Concurrent_Type
(Formal_Typ
);
3013 -- The type of the first formal is a concurrent tagged type with
3017 Is_Concurrent_Type
(Formal_Typ
)
3018 and then Is_Tagged_Type
(Formal_Typ
)
3019 and then Has_Private_Declaration
(Formal_Typ
);
3023 end Is_Private_Concurrent_Primitive
;
3025 ----------------------------
3026 -- Set_Trivial_Subprogram --
3027 ----------------------------
3029 procedure Set_Trivial_Subprogram
(N
: Node_Id
) is
3030 Nxt
: constant Node_Id
:= Next
(N
);
3033 Set_Is_Trivial_Subprogram
(Body_Id
);
3035 if Present
(Spec_Id
) then
3036 Set_Is_Trivial_Subprogram
(Spec_Id
);
3040 and then Nkind
(Nxt
) = N_Simple_Return_Statement
3041 and then No
(Next
(Nxt
))
3042 and then Present
(Expression
(Nxt
))
3043 and then Is_Entity_Name
(Expression
(Nxt
))
3045 Set_Never_Set_In_Source
(Entity
(Expression
(Nxt
)), False);
3047 end Set_Trivial_Subprogram
;
3049 ---------------------------------
3050 -- Verify_Overriding_Indicator --
3051 ---------------------------------
3053 procedure Verify_Overriding_Indicator
is
3055 if Must_Override
(Body_Spec
) then
3056 if Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
3057 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
3061 elsif not Present
(Overridden_Operation
(Spec_Id
)) then
3063 ("subprogram& is not overriding", Body_Spec
, Spec_Id
);
3065 -- Overriding indicators aren't allowed for protected subprogram
3066 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
3067 -- this to a warning if -gnatd.E is enabled.
3069 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
3070 Error_Msg_Warn
:= Error_To_Warning
;
3072 ("<<overriding indicator not allowed for protected "
3073 & "subprogram body", Body_Spec
);
3076 elsif Must_Not_Override
(Body_Spec
) then
3077 if Present
(Overridden_Operation
(Spec_Id
)) then
3079 ("subprogram& overrides inherited operation",
3080 Body_Spec
, Spec_Id
);
3082 elsif Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
3083 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
3086 ("subprogram& overrides predefined operator ",
3087 Body_Spec
, Spec_Id
);
3089 -- Overriding indicators aren't allowed for protected subprogram
3090 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
3091 -- this to a warning if -gnatd.E is enabled.
3093 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
3094 Error_Msg_Warn
:= Error_To_Warning
;
3097 ("<<overriding indicator not allowed "
3098 & "for protected subprogram body", Body_Spec
);
3100 -- If this is not a primitive operation, then the overriding
3101 -- indicator is altogether illegal.
3103 elsif not Is_Primitive
(Spec_Id
) then
3105 ("overriding indicator only allowed "
3106 & "if subprogram is primitive", Body_Spec
);
3109 -- If checking the style rule and the operation overrides, then
3110 -- issue a warning about a missing overriding_indicator. Protected
3111 -- subprogram bodies are excluded from this style checking, since
3112 -- they aren't primitives (even though their declarations can
3113 -- override) and aren't allowed to have an overriding_indicator.
3116 and then Present
(Overridden_Operation
(Spec_Id
))
3117 and then Ekind
(Scope
(Spec_Id
)) /= E_Protected_Type
3119 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
3120 Style
.Missing_Overriding
(N
, Body_Id
);
3123 and then Can_Override_Operator
(Spec_Id
)
3124 and then not Is_Predefined_File_Name
3125 (Unit_File_Name
(Get_Source_Unit
(Spec_Id
)))
3127 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
3128 Style
.Missing_Overriding
(N
, Body_Id
);
3130 end Verify_Overriding_Indicator
;
3132 -- Start of processing for Analyze_Subprogram_Body_Helper
3135 -- Generic subprograms are handled separately. They always have a
3136 -- generic specification. Determine whether current scope has a
3137 -- previous declaration.
3139 -- If the subprogram body is defined within an instance of the same
3140 -- name, the instance appears as a package renaming, and will be hidden
3141 -- within the subprogram.
3143 if Present
(Prev_Id
)
3144 and then not Is_Overloadable
(Prev_Id
)
3145 and then (Nkind
(Parent
(Prev_Id
)) /= N_Package_Renaming_Declaration
3146 or else Comes_From_Source
(Prev_Id
))
3148 if Is_Generic_Subprogram
(Prev_Id
) then
3151 -- The corresponding spec may be subject to pragma Ghost with
3152 -- policy Ignore. Set the mode now to ensure that any nodes
3153 -- generated during analysis and expansion are properly flagged
3154 -- as ignored Ghost.
3156 Set_Ghost_Mode
(N
, Spec_Id
);
3157 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3158 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3160 Analyze_Generic_Subprogram_Body
(N
, Spec_Id
);
3162 if Nkind
(N
) = N_Subprogram_Body
then
3163 HSS
:= Handled_Statement_Sequence
(N
);
3164 Check_Missing_Return
;
3170 -- Previous entity conflicts with subprogram name. Attempting to
3171 -- enter name will post error.
3173 Enter_Name
(Body_Id
);
3177 -- Non-generic case, find the subprogram declaration, if one was seen,
3178 -- or enter new overloaded entity in the current scope. If the
3179 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
3180 -- part of the context of one of its subunits. No need to redo the
3183 elsif Prev_Id
= Body_Id
and then Has_Completion
(Body_Id
) then
3187 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
3189 if Nkind
(N
) = N_Subprogram_Body_Stub
3190 or else No
(Corresponding_Spec
(N
))
3192 if Is_Private_Concurrent_Primitive
(Body_Id
) then
3193 Spec_Id
:= Disambiguate_Spec
;
3195 -- The corresponding spec may be subject to pragma Ghost with
3196 -- policy Ignore. Set the mode now to ensure that any nodes
3197 -- generated during analysis and expansion are properly flagged
3198 -- as ignored Ghost.
3200 Set_Ghost_Mode
(N
, Spec_Id
);
3203 Spec_Id
:= Find_Corresponding_Spec
(N
);
3205 -- The corresponding spec may be subject to pragma Ghost with
3206 -- policy Ignore. Set the mode now to ensure that any nodes
3207 -- generated during analysis and expansion are properly flagged
3208 -- as ignored Ghost.
3210 Set_Ghost_Mode
(N
, Spec_Id
);
3212 -- In GNATprove mode, if the body has no previous spec, create
3213 -- one so that the inlining machinery can operate properly.
3214 -- Transfer aspects, if any, to the new spec, so that they
3215 -- are legal and can be processed ahead of the body.
3216 -- We make two copies of the given spec, one for the new
3217 -- declaration, and one for the body.
3220 and then GNATprove_Mode
3222 -- Inlining does not apply during pre-analysis of code
3224 and then Full_Analysis
3226 -- Inlining only applies to full bodies, not stubs
3228 and then Nkind
(N
) /= N_Subprogram_Body_Stub
3230 -- Inlining only applies to bodies in the source code, not to
3231 -- those generated by the compiler. In particular, expression
3232 -- functions, whose body is generated by the compiler, are
3233 -- treated specially by GNATprove.
3235 and then Comes_From_Source
(Body_Id
)
3237 -- This cannot be done for a compilation unit, which is not
3238 -- in a context where we can insert a new spec.
3240 and then Is_List_Member
(N
)
3242 -- Inlining only applies to subprograms without contracts,
3243 -- as a contract is a sign that GNATprove should perform a
3244 -- modular analysis of the subprogram instead of a contextual
3245 -- analysis at each call site. The same test is performed in
3246 -- Inline.Can_Be_Inlined_In_GNATprove_Mode. It is repeated
3247 -- here in another form (because the contract has not
3248 -- been attached to the body) to avoid frontend errors in
3249 -- case pragmas are used instead of aspects, because the
3250 -- corresponding pragmas in the body would not be transferred
3251 -- to the spec, leading to legality errors.
3253 and then not Body_Has_Contract
3256 Body_Spec
: constant Node_Id
:=
3257 Copy_Separate_Tree
(Specification
(N
));
3258 New_Decl
: constant Node_Id
:=
3259 Make_Subprogram_Declaration
(Loc
,
3260 Copy_Separate_Tree
(Specification
(N
)));
3262 SPARK_Mode_Aspect
: Node_Id
;
3264 Prag
, Aspect
: Node_Id
;
3267 Insert_Before
(N
, New_Decl
);
3268 Move_Aspects
(From
=> N
, To
=> New_Decl
);
3270 -- Mark the newly moved aspects as not analyzed, so that
3271 -- their effect on New_Decl is properly analyzed.
3273 Aspect
:= First
(Aspect_Specifications
(New_Decl
));
3274 while Present
(Aspect
) loop
3275 Set_Analyzed
(Aspect
, False);
3281 -- The analysis of the generated subprogram declaration
3282 -- may have introduced pragmas that need to be analyzed.
3284 Prag
:= Next
(New_Decl
);
3285 while Prag
/= N
loop
3290 Spec_Id
:= Defining_Entity
(New_Decl
);
3292 -- As Body_Id originally comes from source, mark the new
3293 -- Spec_Id as such, which is required so that calls to
3294 -- this subprogram are registered in the local effects
3295 -- stored in ALI files for GNATprove.
3297 Set_Comes_From_Source
(Spec_Id
, True);
3299 -- If aspect SPARK_Mode was specified on the body, it
3300 -- needs to be repeated on the generated decl and the
3301 -- body. Since the original aspect was moved to the
3302 -- generated decl, copy it for the body.
3304 if Has_Aspect
(Spec_Id
, Aspect_SPARK_Mode
) then
3305 SPARK_Mode_Aspect
:=
3306 New_Copy
(Find_Aspect
(Spec_Id
, Aspect_SPARK_Mode
));
3307 Set_Analyzed
(SPARK_Mode_Aspect
, False);
3308 Aspects
:= New_List
(SPARK_Mode_Aspect
);
3309 Set_Aspect_Specifications
(N
, Aspects
);
3312 Set_Specification
(N
, Body_Spec
);
3313 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
3314 Set_Corresponding_Spec
(N
, Spec_Id
);
3319 -- If this is a duplicate body, no point in analyzing it
3321 if Error_Posted
(N
) then
3325 -- A subprogram body should cause freezing of its own declaration,
3326 -- but if there was no previous explicit declaration, then the
3327 -- subprogram will get frozen too late (there may be code within
3328 -- the body that depends on the subprogram having been frozen,
3329 -- such as uses of extra formals), so we force it to be frozen
3330 -- here. Same holds if the body and spec are compilation units.
3331 -- Finally, if the return type is an anonymous access to protected
3332 -- subprogram, it must be frozen before the body because its
3333 -- expansion has generated an equivalent type that is used when
3334 -- elaborating the body.
3336 -- An exception in the case of Ada 2012, AI05-177: The bodies
3337 -- created for expression functions do not freeze.
3340 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3342 Freeze_Before
(N
, Body_Id
);
3344 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3345 Freeze_Before
(N
, Spec_Id
);
3347 elsif Is_Access_Subprogram_Type
(Etype
(Body_Id
)) then
3348 Freeze_Before
(N
, Etype
(Body_Id
));
3352 Spec_Id
:= Corresponding_Spec
(N
);
3354 -- The corresponding spec may be subject to pragma Ghost with
3355 -- policy Ignore. Set the mode now to ensure that any nodes
3356 -- generated during analysis and expansion are properly flagged
3357 -- as ignored Ghost.
3359 Set_Ghost_Mode
(N
, Spec_Id
);
3363 -- Previously we scanned the body to look for nested subprograms, and
3364 -- rejected an inline directive if nested subprograms were present,
3365 -- because the back-end would generate conflicting symbols for the
3366 -- nested bodies. This is now unnecessary.
3368 -- Look ahead to recognize a pragma Inline that appears after the body
3370 Check_Inline_Pragma
(Spec_Id
);
3372 -- Deal with special case of a fully private operation in the body of
3373 -- the protected type. We must create a declaration for the subprogram,
3374 -- in order to attach the protected subprogram that will be used in
3375 -- internal calls. We exclude compiler generated bodies from the
3376 -- expander since the issue does not arise for those cases.
3379 and then Comes_From_Source
(N
)
3380 and then Is_Protected_Type
(Current_Scope
)
3382 Spec_Id
:= Build_Private_Protected_Declaration
(N
);
3385 -- If a separate spec is present, then deal with freezing issues
3387 if Present
(Spec_Id
) then
3388 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
3389 Verify_Overriding_Indicator
;
3391 -- In general, the spec will be frozen when we start analyzing the
3392 -- body. However, for internally generated operations, such as
3393 -- wrapper functions for inherited operations with controlling
3394 -- results, the spec may not have been frozen by the time we expand
3395 -- the freeze actions that include the bodies. In particular, extra
3396 -- formals for accessibility or for return-in-place may need to be
3397 -- generated. Freeze nodes, if any, are inserted before the current
3398 -- body. These freeze actions are also needed in ASIS mode to enable
3399 -- the proper back-annotations.
3401 if not Is_Frozen
(Spec_Id
)
3402 and then (Expander_Active
or ASIS_Mode
)
3404 -- Force the generation of its freezing node to ensure proper
3405 -- management of access types in the backend.
3407 -- This is definitely needed for some cases, but it is not clear
3408 -- why, to be investigated further???
3410 Set_Has_Delayed_Freeze
(Spec_Id
);
3411 Freeze_Before
(N
, Spec_Id
);
3415 -- Mark presence of postcondition procedure in current scope and mark
3416 -- the procedure itself as needing debug info. The latter is important
3417 -- when analyzing decision coverage (for example, for MC/DC coverage).
3419 if Chars
(Body_Id
) = Name_uPostconditions
then
3420 Set_Has_Postconditions
(Current_Scope
);
3421 Set_Debug_Info_Needed
(Body_Id
);
3424 -- Place subprogram on scope stack, and make formals visible. If there
3425 -- is a spec, the visible entity remains that of the spec.
3427 if Present
(Spec_Id
) then
3428 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
3430 if Is_Child_Unit
(Spec_Id
) then
3431 Generate_Reference
(Spec_Id
, Scope
(Spec_Id
), 'k', False);
3435 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
3438 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3439 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3441 if Is_Abstract_Subprogram
(Spec_Id
) then
3442 Error_Msg_N
("an abstract subprogram cannot have a body", N
);
3446 Set_Convention
(Body_Id
, Convention
(Spec_Id
));
3447 Set_Has_Completion
(Spec_Id
);
3449 -- Inherit the "ghostness" of the subprogram spec. Note that this
3450 -- property is not directly inherited as the body may be subject
3451 -- to a different Ghost assertion policy.
3453 if Is_Ghost_Entity
(Spec_Id
) or else Ghost_Mode
> None
then
3454 Set_Is_Ghost_Entity
(Body_Id
);
3456 -- The Ghost policy in effect at the point of declaration and
3457 -- at the point of completion must match (SPARK RM 6.9(15)).
3459 Check_Ghost_Completion
(Spec_Id
, Body_Id
);
3462 if Is_Protected_Type
(Scope
(Spec_Id
)) then
3463 Prot_Typ
:= Scope
(Spec_Id
);
3466 -- If this is a body generated for a renaming, do not check for
3467 -- full conformance. The check is redundant, because the spec of
3468 -- the body is a copy of the spec in the renaming declaration,
3469 -- and the test can lead to spurious errors on nested defaults.
3471 if Present
(Spec_Decl
)
3472 and then not Comes_From_Source
(N
)
3474 (Nkind
(Original_Node
(Spec_Decl
)) =
3475 N_Subprogram_Renaming_Declaration
3476 or else (Present
(Corresponding_Body
(Spec_Decl
))
3478 Nkind
(Unit_Declaration_Node
3479 (Corresponding_Body
(Spec_Decl
))) =
3480 N_Subprogram_Renaming_Declaration
))
3484 -- Conversely, the spec may have been generated for specless body
3485 -- with an inline pragma.
3487 elsif Comes_From_Source
(N
)
3488 and then not Comes_From_Source
(Spec_Id
)
3489 and then Has_Pragma_Inline
(Spec_Id
)
3496 Fully_Conformant
, True, Conformant
, Body_Id
);
3499 -- If the body is not fully conformant, we have to decide if we
3500 -- should analyze it or not. If it has a really messed up profile
3501 -- then we probably should not analyze it, since we will get too
3502 -- many bogus messages.
3504 -- Our decision is to go ahead in the non-fully conformant case
3505 -- only if it is at least mode conformant with the spec. Note
3506 -- that the call to Check_Fully_Conformant has issued the proper
3507 -- error messages to complain about the lack of conformance.
3510 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
3516 if Spec_Id
/= Body_Id
then
3517 Reference_Body_Formals
(Spec_Id
, Body_Id
);
3520 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
3522 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3523 Set_Corresponding_Spec_Of_Stub
(N
, Spec_Id
);
3528 Set_Corresponding_Spec
(N
, Spec_Id
);
3530 -- Ada 2005 (AI-345): If the operation is a primitive operation
3531 -- of a concurrent type, the type of the first parameter has been
3532 -- replaced with the corresponding record, which is the proper
3533 -- run-time structure to use. However, within the body there may
3534 -- be uses of the formals that depend on primitive operations
3535 -- of the type (in particular calls in prefixed form) for which
3536 -- we need the original concurrent type. The operation may have
3537 -- several controlling formals, so the replacement must be done
3540 if Comes_From_Source
(Spec_Id
)
3541 and then Present
(First_Entity
(Spec_Id
))
3542 and then Ekind
(Etype
(First_Entity
(Spec_Id
))) = E_Record_Type
3543 and then Is_Tagged_Type
(Etype
(First_Entity
(Spec_Id
)))
3544 and then Present
(Interfaces
(Etype
(First_Entity
(Spec_Id
))))
3545 and then Present
(Corresponding_Concurrent_Type
3546 (Etype
(First_Entity
(Spec_Id
))))
3549 Typ
: constant Entity_Id
:= Etype
(First_Entity
(Spec_Id
));
3553 Form
:= First_Formal
(Spec_Id
);
3554 while Present
(Form
) loop
3555 if Etype
(Form
) = Typ
then
3556 Set_Etype
(Form
, Corresponding_Concurrent_Type
(Typ
));
3564 -- Make the formals visible, and place subprogram on scope stack.
3565 -- This is also the point at which we set Last_Real_Spec_Entity
3566 -- to mark the entities which will not be moved to the body.
3568 Install_Formals
(Spec_Id
);
3569 Last_Real_Spec_Entity
:= Last_Entity
(Spec_Id
);
3571 -- Within an instance, add local renaming declarations so that
3572 -- gdb can retrieve the values of actuals more easily. This is
3573 -- only relevant if generating code (and indeed we definitely
3574 -- do not want these definitions -gnatc mode, because that would
3577 if Is_Generic_Instance
(Spec_Id
)
3578 and then Is_Wrapper_Package
(Current_Scope
)
3579 and then Expander_Active
3581 Build_Subprogram_Instance_Renamings
(N
, Current_Scope
);
3584 Push_Scope
(Spec_Id
);
3586 -- Make sure that the subprogram is immediately visible. For
3587 -- child units that have no separate spec this is indispensable.
3588 -- Otherwise it is safe albeit redundant.
3590 Set_Is_Immediately_Visible
(Spec_Id
);
3593 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
3594 Set_Contract
(Body_Id
, Make_Contract
(Sloc
(Body_Id
)));
3595 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
3596 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Spec_Id
));
3598 -- Case of subprogram body with no previous spec
3601 -- Check for style warning required
3605 -- Only apply check for source level subprograms for which checks
3606 -- have not been suppressed.
3608 and then Comes_From_Source
(Body_Id
)
3609 and then not Suppress_Style_Checks
(Body_Id
)
3611 -- No warnings within an instance
3613 and then not In_Instance
3615 -- No warnings for expression functions
3617 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3619 Style
.Body_With_No_Spec
(N
);
3622 New_Overloaded_Entity
(Body_Id
);
3624 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
3625 Set_Acts_As_Spec
(N
);
3626 Generate_Definition
(Body_Id
);
3627 Set_Contract
(Body_Id
, Make_Contract
(Sloc
(Body_Id
)));
3629 (Body_Id
, Body_Id
, 'b', Set_Ref
=> False, Force
=> True);
3630 Install_Formals
(Body_Id
);
3632 Push_Scope
(Body_Id
);
3635 -- For stubs and bodies with no previous spec, generate references to
3638 Generate_Reference_To_Formals
(Body_Id
);
3641 -- Set SPARK_Mode from context
3643 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
3644 Set_SPARK_Pragma_Inherited
(Body_Id
, True);
3646 -- If the return type is an anonymous access type whose designated type
3647 -- is the limited view of a class-wide type and the non-limited view is
3648 -- available, update the return type accordingly.
3650 if Ada_Version
>= Ada_2005
and then Comes_From_Source
(N
) then
3656 Rtyp
:= Etype
(Current_Scope
);
3658 if Ekind
(Rtyp
) = E_Anonymous_Access_Type
then
3659 Etyp
:= Directly_Designated_Type
(Rtyp
);
3661 if Is_Class_Wide_Type
(Etyp
)
3662 and then From_Limited_With
(Etyp
)
3664 Set_Directly_Designated_Type
3665 (Etype
(Current_Scope
), Available_View
(Etyp
));
3671 -- If this is the proper body of a stub, we must verify that the stub
3672 -- conforms to the body, and to the previous spec if one was present.
3673 -- We know already that the body conforms to that spec. This test is
3674 -- only required for subprograms that come from source.
3676 if Nkind
(Parent
(N
)) = N_Subunit
3677 and then Comes_From_Source
(N
)
3678 and then not Error_Posted
(Body_Id
)
3679 and then Nkind
(Corresponding_Stub
(Parent
(N
))) =
3680 N_Subprogram_Body_Stub
3683 Old_Id
: constant Entity_Id
:=
3685 (Specification
(Corresponding_Stub
(Parent
(N
))));
3687 Conformant
: Boolean := False;
3690 if No
(Spec_Id
) then
3691 Check_Fully_Conformant
(Body_Id
, Old_Id
);
3695 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
3697 if not Conformant
then
3699 -- The stub was taken to be a new declaration. Indicate that
3702 Set_Has_Completion
(Old_Id
, False);
3708 Set_Has_Completion
(Body_Id
);
3709 Check_Eliminated
(Body_Id
);
3711 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3713 -- Analyze any aspect specifications that appear on the subprogram
3716 if Has_Aspects
(N
) then
3717 Analyze_Aspects_On_Body_Or_Stub
;
3720 -- Stop the analysis now as the stub cannot be inlined, plus it does
3721 -- not have declarative or statement lists.
3726 -- Handle frontend inlining
3728 -- Note: Normally we don't do any inlining if expansion is off, since
3729 -- we won't generate code in any case. An exception arises in GNATprove
3730 -- mode where we want to expand some calls in place, even with expansion
3731 -- disabled, since the inlining eases formal verification.
3733 if not GNATprove_Mode
3734 and then Expander_Active
3735 and then Serious_Errors_Detected
= 0
3736 and then Present
(Spec_Id
)
3737 and then Has_Pragma_Inline
(Spec_Id
)
3739 -- Legacy implementation (relying on frontend inlining)
3741 if not Back_End_Inlining
then
3742 if Has_Pragma_Inline_Always
(Spec_Id
)
3743 or else (Has_Pragma_Inline
(Spec_Id
) and Front_End_Inlining
)
3745 Build_Body_To_Inline
(N
, Spec_Id
);
3748 -- New implementation (relying on backend inlining)
3751 if Has_Pragma_Inline_Always
(Spec_Id
)
3752 or else Optimization_Level
> 0
3754 -- Handle function returning an unconstrained type
3756 if Comes_From_Source
(Body_Id
)
3757 and then Ekind
(Spec_Id
) = E_Function
3758 and then Returns_Unconstrained_Type
(Spec_Id
)
3760 -- If function builds in place, i.e. returns a limited type,
3761 -- inlining cannot be done.
3763 and then not Is_Limited_Type
(Etype
(Spec_Id
))
3765 Check_And_Split_Unconstrained_Function
(N
, Spec_Id
, Body_Id
);
3769 Subp_Body
: constant Node_Id
:=
3770 Unit_Declaration_Node
(Body_Id
);
3771 Subp_Decl
: constant List_Id
:= Declarations
(Subp_Body
);
3774 -- Do not pass inlining to the backend if the subprogram
3775 -- has declarations or statements which cannot be inlined
3776 -- by the backend. This check is done here to emit an
3777 -- error instead of the generic warning message reported
3778 -- by the GCC backend (ie. "function might not be
3781 if Present
(Subp_Decl
)
3782 and then Has_Excluded_Declaration
(Spec_Id
, Subp_Decl
)
3786 elsif Has_Excluded_Statement
3789 (Handled_Statement_Sequence
(Subp_Body
)))
3793 -- If the backend inlining is available then at this
3794 -- stage we only have to mark the subprogram as inlined.
3795 -- The expander will take care of registering it in the
3796 -- table of subprograms inlined by the backend a part of
3797 -- processing calls to it (cf. Expand_Call)
3800 Set_Is_Inlined
(Spec_Id
);
3807 -- In GNATprove mode, inline only when there is a separate subprogram
3808 -- declaration for now, as inlining of subprogram bodies acting as
3809 -- declarations, or subprogram stubs, are not supported by frontend
3810 -- inlining. This inlining should occur after analysis of the body, so
3811 -- that it is known whether the value of SPARK_Mode applicable to the
3812 -- body, which can be defined by a pragma inside the body.
3814 elsif GNATprove_Mode
3815 and then Full_Analysis
3816 and then not Inside_A_Generic
3817 and then Present
(Spec_Id
)
3818 and then Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Declaration
3819 and then Can_Be_Inlined_In_GNATprove_Mode
(Spec_Id
, Body_Id
)
3820 and then not Body_Has_Contract
3822 Build_Body_To_Inline
(N
, Spec_Id
);
3825 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
3826 -- of the specification we have to install the private withed units.
3827 -- This holds for child units as well.
3829 if Is_Compilation_Unit
(Body_Id
)
3830 or else Nkind
(Parent
(N
)) = N_Compilation_Unit
3832 Install_Private_With_Clauses
(Body_Id
);
3835 Check_Anonymous_Return
;
3837 -- Set the Protected_Formal field of each extra formal of the protected
3838 -- subprogram to reference the corresponding extra formal of the
3839 -- subprogram that implements it. For regular formals this occurs when
3840 -- the protected subprogram's declaration is expanded, but the extra
3841 -- formals don't get created until the subprogram is frozen. We need to
3842 -- do this before analyzing the protected subprogram's body so that any
3843 -- references to the original subprogram's extra formals will be changed
3844 -- refer to the implementing subprogram's formals (see Expand_Formal).
3846 if Present
(Spec_Id
)
3847 and then Is_Protected_Type
(Scope
(Spec_Id
))
3848 and then Present
(Protected_Body_Subprogram
(Spec_Id
))
3851 Impl_Subp
: constant Entity_Id
:=
3852 Protected_Body_Subprogram
(Spec_Id
);
3853 Prot_Ext_Formal
: Entity_Id
:= Extra_Formals
(Spec_Id
);
3854 Impl_Ext_Formal
: Entity_Id
:= Extra_Formals
(Impl_Subp
);
3856 while Present
(Prot_Ext_Formal
) loop
3857 pragma Assert
(Present
(Impl_Ext_Formal
));
3858 Set_Protected_Formal
(Prot_Ext_Formal
, Impl_Ext_Formal
);
3859 Next_Formal_With_Extras
(Prot_Ext_Formal
);
3860 Next_Formal_With_Extras
(Impl_Ext_Formal
);
3865 -- Now we can go on to analyze the body
3867 HSS
:= Handled_Statement_Sequence
(N
);
3868 Set_Actual_Subtypes
(N
, Current_Scope
);
3870 -- Add a declaration for the Protection object, renaming declarations
3871 -- for discriminals and privals and finally a declaration for the entry
3872 -- family index (if applicable). This form of early expansion is done
3873 -- when the Expander is active because Install_Private_Data_Declarations
3874 -- references entities which were created during regular expansion. The
3875 -- subprogram entity must come from source, and not be an internally
3876 -- generated subprogram.
3879 and then Present
(Prot_Typ
)
3880 and then Present
(Spec_Id
)
3881 and then Comes_From_Source
(Spec_Id
)
3882 and then not Is_Eliminated
(Spec_Id
)
3884 Install_Private_Data_Declarations
3885 (Sloc
(N
), Spec_Id
, Prot_Typ
, N
, Declarations
(N
));
3888 -- Ada 2012 (AI05-0151): Incomplete types coming from a limited context
3889 -- may now appear in parameter and result profiles. Since the analysis
3890 -- of a subprogram body may use the parameter and result profile of the
3891 -- spec, swap any limited views with their non-limited counterpart.
3893 if Ada_Version
>= Ada_2012
then
3894 Exchange_Limited_Views
(Spec_Id
);
3897 -- Analyze any aspect specifications that appear on the subprogram body
3899 if Has_Aspects
(N
) then
3900 Analyze_Aspects_On_Body_Or_Stub
;
3903 -- Deal with [refined] preconditions, postconditions, Contract_Cases,
3904 -- invariants and predicates associated with the body and its spec.
3905 -- Note that this is not pure expansion as Expand_Subprogram_Contract
3906 -- prepares the contract assertions for generic subprograms or for ASIS.
3907 -- Do not generate contract checks in SPARK mode.
3909 if not GNATprove_Mode
then
3910 Expand_Subprogram_Contract
(N
, Spec_Id
, Body_Id
);
3913 -- Analyze the declarations (this call will analyze the precondition
3914 -- Check pragmas we prepended to the list, as well as the declaration
3915 -- of the _Postconditions procedure).
3917 Analyze_Declarations
(Declarations
(N
));
3919 -- Verify that the SPARK_Mode of the body agrees with that of its spec
3921 if Present
(Spec_Id
) and then Present
(SPARK_Pragma
(Body_Id
)) then
3922 if Present
(SPARK_Pragma
(Spec_Id
)) then
3923 if Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Spec_Id
)) = Off
3925 Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Body_Id
)) = On
3927 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
3928 Error_Msg_N
("incorrect application of SPARK_Mode#", N
);
3929 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Spec_Id
));
3931 ("\value Off was set for SPARK_Mode on & #", N
, Spec_Id
);
3934 elsif Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Body_Stub
then
3938 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
3939 Error_Msg_N
("incorrect application of SPARK_Mode #", N
);
3940 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
3942 ("\no value was set for SPARK_Mode on & #", N
, Spec_Id
);
3946 -- If SPARK_Mode for body is not On, disable frontend inlining for this
3947 -- subprogram in GNATprove mode, as its body should not be analyzed.
3950 and then GNATprove_Mode
3951 and then Present
(Spec_Id
)
3952 and then Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Declaration
3954 Set_Body_To_Inline
(Parent
(Parent
(Spec_Id
)), Empty
);
3955 Set_Is_Inlined_Always
(Spec_Id
, False);
3958 -- Check completion, and analyze the statements
3961 Inspect_Deferred_Constant_Completion
(Declarations
(N
));
3964 -- Deal with end of scope processing for the body
3966 Process_End_Label
(HSS
, 't', Current_Scope
);
3968 Check_Subprogram_Order
(N
);
3969 Set_Analyzed
(Body_Id
);
3971 -- If we have a separate spec, then the analysis of the declarations
3972 -- caused the entities in the body to be chained to the spec id, but
3973 -- we want them chained to the body id. Only the formal parameters
3974 -- end up chained to the spec id in this case.
3976 if Present
(Spec_Id
) then
3978 -- We must conform to the categorization of our spec
3980 Validate_Categorization_Dependency
(N
, Spec_Id
);
3982 -- And if this is a child unit, the parent units must conform
3984 if Is_Child_Unit
(Spec_Id
) then
3985 Validate_Categorization_Dependency
3986 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
3989 -- Here is where we move entities from the spec to the body
3991 -- Case where there are entities that stay with the spec
3993 if Present
(Last_Real_Spec_Entity
) then
3995 -- No body entities (happens when the only real spec entities come
3996 -- from precondition and postcondition pragmas).
3998 if No
(Last_Entity
(Body_Id
)) then
4000 (Body_Id
, Next_Entity
(Last_Real_Spec_Entity
));
4002 -- Body entities present (formals), so chain stuff past them
4006 (Last_Entity
(Body_Id
), Next_Entity
(Last_Real_Spec_Entity
));
4009 Set_Next_Entity
(Last_Real_Spec_Entity
, Empty
);
4010 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
4011 Set_Last_Entity
(Spec_Id
, Last_Real_Spec_Entity
);
4013 -- Case where there are no spec entities, in this case there can be
4014 -- no body entities either, so just move everything.
4016 -- If the body is generated for an expression function, it may have
4017 -- been preanalyzed already, if 'access was applied to it.
4020 if Nkind
(Original_Node
(Unit_Declaration_Node
(Spec_Id
))) /=
4021 N_Expression_Function
4023 pragma Assert
(No
(Last_Entity
(Body_Id
)));
4027 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
4028 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
4029 Set_First_Entity
(Spec_Id
, Empty
);
4030 Set_Last_Entity
(Spec_Id
, Empty
);
4034 Check_Missing_Return
;
4036 -- Now we are going to check for variables that are never modified in
4037 -- the body of the procedure. But first we deal with a special case
4038 -- where we want to modify this check. If the body of the subprogram
4039 -- starts with a raise statement or its equivalent, or if the body
4040 -- consists entirely of a null statement, then it is pretty obvious that
4041 -- it is OK to not reference the parameters. For example, this might be
4042 -- the following common idiom for a stubbed function: statement of the
4043 -- procedure raises an exception. In particular this deals with the
4044 -- common idiom of a stubbed function, which appears something like:
4046 -- function F (A : Integer) return Some_Type;
4049 -- raise Program_Error;
4053 -- Here the purpose of X is simply to satisfy the annoying requirement
4054 -- in Ada that there be at least one return, and we certainly do not
4055 -- want to go posting warnings on X that it is not initialized. On
4056 -- the other hand, if X is entirely unreferenced that should still
4059 -- What we do is to detect these cases, and if we find them, flag the
4060 -- subprogram as being Is_Trivial_Subprogram and then use that flag to
4061 -- suppress unwanted warnings. For the case of the function stub above
4062 -- we have a special test to set X as apparently assigned to suppress
4069 -- Skip initial labels (for one thing this occurs when we are in
4070 -- front end ZCX mode, but in any case it is irrelevant), and also
4071 -- initial Push_xxx_Error_Label nodes, which are also irrelevant.
4073 Stm
:= First
(Statements
(HSS
));
4074 while Nkind
(Stm
) = N_Label
4075 or else Nkind
(Stm
) in N_Push_xxx_Label
4080 -- Do the test on the original statement before expansion
4083 Ostm
: constant Node_Id
:= Original_Node
(Stm
);
4086 -- If explicit raise statement, turn on flag
4088 if Nkind
(Ostm
) = N_Raise_Statement
then
4089 Set_Trivial_Subprogram
(Stm
);
4091 -- If null statement, and no following statements, turn on flag
4093 elsif Nkind
(Stm
) = N_Null_Statement
4094 and then Comes_From_Source
(Stm
)
4095 and then No
(Next
(Stm
))
4097 Set_Trivial_Subprogram
(Stm
);
4099 -- Check for explicit call cases which likely raise an exception
4101 elsif Nkind
(Ostm
) = N_Procedure_Call_Statement
then
4102 if Is_Entity_Name
(Name
(Ostm
)) then
4104 Ent
: constant Entity_Id
:= Entity
(Name
(Ostm
));
4107 -- If the procedure is marked No_Return, then likely it
4108 -- raises an exception, but in any case it is not coming
4109 -- back here, so turn on the flag.
4112 and then Ekind
(Ent
) = E_Procedure
4113 and then No_Return
(Ent
)
4115 Set_Trivial_Subprogram
(Stm
);
4123 -- Check for variables that are never modified
4129 -- If there is a separate spec, then transfer Never_Set_In_Source
4130 -- flags from out parameters to the corresponding entities in the
4131 -- body. The reason we do that is we want to post error flags on
4132 -- the body entities, not the spec entities.
4134 if Present
(Spec_Id
) then
4135 E1
:= First_Entity
(Spec_Id
);
4136 while Present
(E1
) loop
4137 if Ekind
(E1
) = E_Out_Parameter
then
4138 E2
:= First_Entity
(Body_Id
);
4139 while Present
(E2
) loop
4140 exit when Chars
(E1
) = Chars
(E2
);
4144 if Present
(E2
) then
4145 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
4153 -- Check references in body
4155 Check_References
(Body_Id
);
4157 end Analyze_Subprogram_Body_Helper
;
4159 ---------------------------------
4160 -- Analyze_Subprogram_Contract --
4161 ---------------------------------
4163 procedure Analyze_Subprogram_Contract
(Subp
: Entity_Id
) is
4164 Items
: constant Node_Id
:= Contract
(Subp
);
4165 Case_Prag
: Node_Id
:= Empty
;
4166 Depends
: Node_Id
:= Empty
;
4167 Global
: Node_Id
:= Empty
;
4168 Mode
: SPARK_Mode_Type
;
4170 Post_Prag
: Node_Id
:= Empty
;
4172 Seen_In_Case
: Boolean := False;
4173 Seen_In_Post
: Boolean := False;
4176 -- Due to the timing of contract analysis, delayed pragmas may be
4177 -- subject to the wrong SPARK_Mode, usually that of the enclosing
4178 -- context. To remedy this, restore the original SPARK_Mode of the
4179 -- related subprogram body.
4181 Save_SPARK_Mode_And_Set
(Subp
, Mode
);
4183 if Present
(Items
) then
4185 -- Analyze pre- and postconditions
4187 Prag
:= Pre_Post_Conditions
(Items
);
4188 while Present
(Prag
) loop
4189 Analyze_Pre_Post_Condition_In_Decl_Part
(Prag
, Subp
);
4191 -- Verify whether a postcondition mentions attribute 'Result and
4192 -- its expression introduces a post-state.
4194 if Warn_On_Suspicious_Contract
4195 and then Pragma_Name
(Prag
) = Name_Postcondition
4198 Check_Result_And_Post_State
(Prag
, Seen_In_Post
);
4201 Prag
:= Next_Pragma
(Prag
);
4204 -- Analyze contract-cases and test-cases
4206 Prag
:= Contract_Test_Cases
(Items
);
4207 while Present
(Prag
) loop
4208 Nam
:= Pragma_Name
(Prag
);
4210 if Nam
= Name_Contract_Cases
then
4211 Analyze_Contract_Cases_In_Decl_Part
(Prag
);
4213 -- Verify whether contract-cases mention attribute 'Result and
4214 -- its expression introduces a post-state. Perform the check
4215 -- only when the pragma is legal.
4217 if Warn_On_Suspicious_Contract
4218 and then not Error_Posted
(Prag
)
4221 Check_Result_And_Post_State
(Prag
, Seen_In_Case
);
4225 pragma Assert
(Nam
= Name_Test_Case
);
4226 Analyze_Test_Case_In_Decl_Part
(Prag
, Subp
);
4229 Prag
:= Next_Pragma
(Prag
);
4232 -- Analyze classification pragmas
4234 Prag
:= Classifications
(Items
);
4235 while Present
(Prag
) loop
4236 Nam
:= Pragma_Name
(Prag
);
4238 if Nam
= Name_Depends
then
4241 elsif Nam
= Name_Global
then
4244 -- Note that pragma Extensions_Visible has already been analyzed
4248 Prag
:= Next_Pragma
(Prag
);
4251 -- Analyze Global first as Depends may mention items classified in
4252 -- the global categorization.
4254 if Present
(Global
) then
4255 Analyze_Global_In_Decl_Part
(Global
);
4258 -- Depends must be analyzed after Global in order to see the modes of
4259 -- all global items.
4261 if Present
(Depends
) then
4262 Analyze_Depends_In_Decl_Part
(Depends
);
4266 -- Emit an error when neither the postconditions nor the contract-cases
4267 -- mention attribute 'Result in the context of a function.
4269 if Warn_On_Suspicious_Contract
4270 and then Ekind_In
(Subp
, E_Function
, E_Generic_Function
)
4272 if Present
(Case_Prag
)
4273 and then not Seen_In_Case
4274 and then Present
(Post_Prag
)
4275 and then not Seen_In_Post
4278 ("neither function postcondition nor contract cases mention "
4279 & "result?T?", Post_Prag
);
4281 elsif Present
(Case_Prag
) and then not Seen_In_Case
then
4283 ("contract cases do not mention result?T?", Case_Prag
);
4285 -- OK if we have at least one IN OUT parameter
4287 elsif Present
(Post_Prag
) and then not Seen_In_Post
then
4291 F
:= First_Formal
(Subp
);
4292 while Present
(F
) loop
4293 if Ekind
(F
) = E_In_Out_Parameter
then
4301 -- If no in-out parameters and no mention of Result, the contract
4302 -- is certainly suspicious.
4305 ("function postcondition does not mention result?T?", Post_Prag
);
4309 -- Restore the SPARK_Mode of the enclosing context after all delayed
4310 -- pragmas have been analyzed.
4312 Restore_SPARK_Mode
(Mode
);
4313 end Analyze_Subprogram_Contract
;
4315 ------------------------------------
4316 -- Analyze_Subprogram_Declaration --
4317 ------------------------------------
4319 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
4320 Scop
: constant Entity_Id
:= Current_Scope
;
4321 Designator
: Entity_Id
;
4323 Is_Completion
: Boolean;
4324 -- Indicates whether a null procedure declaration is a completion
4327 -- The subprogram declaration may be subject to pragma Ghost with policy
4328 -- Ignore. Set the mode now to ensure that any nodes generated during
4329 -- analysis and expansion are properly flagged as ignored Ghost.
4333 -- Null procedures are not allowed in SPARK
4335 if Nkind
(Specification
(N
)) = N_Procedure_Specification
4336 and then Null_Present
(Specification
(N
))
4338 Check_SPARK_05_Restriction
("null procedure is not allowed", N
);
4340 if Is_Protected_Type
(Current_Scope
) then
4341 Error_Msg_N
("protected operation cannot be a null procedure", N
);
4344 Analyze_Null_Procedure
(N
, Is_Completion
);
4346 if Is_Completion
then
4348 -- The null procedure acts as a body, nothing further is needed.
4354 Designator
:= Analyze_Subprogram_Specification
(Specification
(N
));
4356 -- A reference may already have been generated for the unit name, in
4357 -- which case the following call is redundant. However it is needed for
4358 -- declarations that are the rewriting of an expression function.
4360 Generate_Definition
(Designator
);
4362 -- Set SPARK mode from current context (may be overwritten later with
4363 -- explicit pragma).
4365 Set_SPARK_Pragma
(Designator
, SPARK_Mode_Pragma
);
4366 Set_SPARK_Pragma_Inherited
(Designator
);
4368 -- A subprogram declared within a Ghost region is automatically Ghost
4369 -- (SPARK RM 6.9(2)).
4371 if Comes_From_Source
(Designator
) and then Ghost_Mode
> None
then
4372 Set_Is_Ghost_Entity
(Designator
);
4375 if Debug_Flag_C
then
4376 Write_Str
("==> subprogram spec ");
4377 Write_Name
(Chars
(Designator
));
4378 Write_Str
(" from ");
4379 Write_Location
(Sloc
(N
));
4384 Validate_RCI_Subprogram_Declaration
(N
);
4385 New_Overloaded_Entity
(Designator
);
4386 Check_Delayed_Subprogram
(Designator
);
4388 -- If the type of the first formal of the current subprogram is a non-
4389 -- generic tagged private type, mark the subprogram as being a private
4390 -- primitive. Ditto if this is a function with controlling result, and
4391 -- the return type is currently private. In both cases, the type of the
4392 -- controlling argument or result must be in the current scope for the
4393 -- operation to be primitive.
4395 if Has_Controlling_Result
(Designator
)
4396 and then Is_Private_Type
(Etype
(Designator
))
4397 and then Scope
(Etype
(Designator
)) = Current_Scope
4398 and then not Is_Generic_Actual_Type
(Etype
(Designator
))
4400 Set_Is_Private_Primitive
(Designator
);
4402 elsif Present
(First_Formal
(Designator
)) then
4404 Formal_Typ
: constant Entity_Id
:=
4405 Etype
(First_Formal
(Designator
));
4407 Set_Is_Private_Primitive
(Designator
,
4408 Is_Tagged_Type
(Formal_Typ
)
4409 and then Scope
(Formal_Typ
) = Current_Scope
4410 and then Is_Private_Type
(Formal_Typ
)
4411 and then not Is_Generic_Actual_Type
(Formal_Typ
));
4415 -- Ada 2005 (AI-251): Abstract interface primitives must be abstract
4418 if Ada_Version
>= Ada_2005
4419 and then Comes_From_Source
(N
)
4420 and then Is_Dispatching_Operation
(Designator
)
4427 if Has_Controlling_Result
(Designator
) then
4428 Etyp
:= Etype
(Designator
);
4431 E
:= First_Entity
(Designator
);
4433 and then Is_Formal
(E
)
4434 and then not Is_Controlling_Formal
(E
)
4442 if Is_Access_Type
(Etyp
) then
4443 Etyp
:= Directly_Designated_Type
(Etyp
);
4446 if Is_Interface
(Etyp
)
4447 and then not Is_Abstract_Subprogram
(Designator
)
4448 and then not (Ekind
(Designator
) = E_Procedure
4449 and then Null_Present
(Specification
(N
)))
4451 Error_Msg_Name_1
:= Chars
(Defining_Entity
(N
));
4453 -- Specialize error message based on procedures vs. functions,
4454 -- since functions can't be null subprograms.
4456 if Ekind
(Designator
) = E_Procedure
then
4458 ("interface procedure % must be abstract or null", N
);
4461 ("interface function % must be abstract", N
);
4467 -- What is the following code for, it used to be
4469 -- ??? Set_Suppress_Elaboration_Checks
4470 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
4472 -- The following seems equivalent, but a bit dubious
4474 if Elaboration_Checks_Suppressed
(Designator
) then
4475 Set_Kill_Elaboration_Checks
(Designator
);
4478 if Scop
/= Standard_Standard
and then not Is_Child_Unit
(Designator
) then
4479 Set_Categorization_From_Scope
(Designator
, Scop
);
4482 -- For a compilation unit, check for library-unit pragmas
4484 Push_Scope
(Designator
);
4485 Set_Categorization_From_Pragmas
(N
);
4486 Validate_Categorization_Dependency
(N
, Designator
);
4490 -- For a compilation unit, set body required. This flag will only be
4491 -- reset if a valid Import or Interface pragma is processed later on.
4493 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
4494 Set_Body_Required
(Parent
(N
), True);
4496 if Ada_Version
>= Ada_2005
4497 and then Nkind
(Specification
(N
)) = N_Procedure_Specification
4498 and then Null_Present
(Specification
(N
))
4501 ("null procedure cannot be declared at library level", N
);
4505 Generate_Reference_To_Formals
(Designator
);
4506 Check_Eliminated
(Designator
);
4508 if Debug_Flag_C
then
4510 Write_Str
("<== subprogram spec ");
4511 Write_Name
(Chars
(Designator
));
4512 Write_Str
(" from ");
4513 Write_Location
(Sloc
(N
));
4517 if Is_Protected_Type
(Current_Scope
) then
4519 -- Indicate that this is a protected operation, because it may be
4520 -- used in subsequent declarations within the protected type.
4522 Set_Convention
(Designator
, Convention_Protected
);
4525 List_Inherited_Pre_Post_Aspects
(Designator
);
4527 if Has_Aspects
(N
) then
4528 Analyze_Aspect_Specifications
(N
, Designator
);
4530 end Analyze_Subprogram_Declaration
;
4532 --------------------------------------
4533 -- Analyze_Subprogram_Specification --
4534 --------------------------------------
4536 -- Reminder: N here really is a subprogram specification (not a subprogram
4537 -- declaration). This procedure is called to analyze the specification in
4538 -- both subprogram bodies and subprogram declarations (specs).
4540 function Analyze_Subprogram_Specification
(N
: Node_Id
) return Entity_Id
is
4541 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
4542 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
4544 -- Start of processing for Analyze_Subprogram_Specification
4547 -- User-defined operator is not allowed in SPARK, except as a renaming
4549 if Nkind
(Defining_Unit_Name
(N
)) = N_Defining_Operator_Symbol
4550 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
4552 Check_SPARK_05_Restriction
4553 ("user-defined operator is not allowed", N
);
4556 -- Proceed with analysis. Do not emit a cross-reference entry if the
4557 -- specification comes from an expression function, because it may be
4558 -- the completion of a previous declaration. It is is not, the cross-
4559 -- reference entry will be emitted for the new subprogram declaration.
4561 if Nkind
(Parent
(N
)) /= N_Expression_Function
then
4562 Generate_Definition
(Designator
);
4565 Set_Contract
(Designator
, Make_Contract
(Sloc
(Designator
)));
4567 if Nkind
(N
) = N_Function_Specification
then
4568 Set_Ekind
(Designator
, E_Function
);
4569 Set_Mechanism
(Designator
, Default_Mechanism
);
4571 Set_Ekind
(Designator
, E_Procedure
);
4572 Set_Etype
(Designator
, Standard_Void_Type
);
4575 -- Flag Is_Inlined_Always is True by default, and reversed to False for
4576 -- those subprograms which could be inlined in GNATprove mode (because
4577 -- Body_To_Inline is non-Empty) but cannot be inlined.
4579 if GNATprove_Mode
then
4580 Set_Is_Inlined_Always
(Designator
);
4583 -- Introduce new scope for analysis of the formals and the return type
4585 Set_Scope
(Designator
, Current_Scope
);
4587 if Present
(Formals
) then
4588 Push_Scope
(Designator
);
4589 Process_Formals
(Formals
, N
);
4591 -- Check dimensions in N for formals with default expression
4593 Analyze_Dimension_Formals
(N
, Formals
);
4595 -- Ada 2005 (AI-345): If this is an overriding operation of an
4596 -- inherited interface operation, and the controlling type is
4597 -- a synchronized type, replace the type with its corresponding
4598 -- record, to match the proper signature of an overriding operation.
4599 -- Same processing for an access parameter whose designated type is
4600 -- derived from a synchronized interface.
4602 if Ada_Version
>= Ada_2005
then
4605 Formal_Typ
: Entity_Id
;
4606 Rec_Typ
: Entity_Id
;
4607 Desig_Typ
: Entity_Id
;
4610 Formal
:= First_Formal
(Designator
);
4611 while Present
(Formal
) loop
4612 Formal_Typ
:= Etype
(Formal
);
4614 if Is_Concurrent_Type
(Formal_Typ
)
4615 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
4617 Rec_Typ
:= Corresponding_Record_Type
(Formal_Typ
);
4619 if Present
(Interfaces
(Rec_Typ
)) then
4620 Set_Etype
(Formal
, Rec_Typ
);
4623 elsif Ekind
(Formal_Typ
) = E_Anonymous_Access_Type
then
4624 Desig_Typ
:= Designated_Type
(Formal_Typ
);
4626 if Is_Concurrent_Type
(Desig_Typ
)
4627 and then Present
(Corresponding_Record_Type
(Desig_Typ
))
4629 Rec_Typ
:= Corresponding_Record_Type
(Desig_Typ
);
4631 if Present
(Interfaces
(Rec_Typ
)) then
4632 Set_Directly_Designated_Type
(Formal_Typ
, Rec_Typ
);
4637 Next_Formal
(Formal
);
4644 -- The subprogram scope is pushed and popped around the processing of
4645 -- the return type for consistency with call above to Process_Formals
4646 -- (which itself can call Analyze_Return_Type), and to ensure that any
4647 -- itype created for the return type will be associated with the proper
4650 elsif Nkind
(N
) = N_Function_Specification
then
4651 Push_Scope
(Designator
);
4652 Analyze_Return_Type
(N
);
4658 if Nkind
(N
) = N_Function_Specification
then
4660 -- Deal with operator symbol case
4662 if Nkind
(Designator
) = N_Defining_Operator_Symbol
then
4663 Valid_Operator_Definition
(Designator
);
4666 May_Need_Actuals
(Designator
);
4668 -- Ada 2005 (AI-251): If the return type is abstract, verify that
4669 -- the subprogram is abstract also. This does not apply to renaming
4670 -- declarations, where abstractness is inherited, and to subprogram
4671 -- bodies generated for stream operations, which become renamings as
4674 -- In case of primitives associated with abstract interface types
4675 -- the check is applied later (see Analyze_Subprogram_Declaration).
4677 if not Nkind_In
(Original_Node
(Parent
(N
)),
4678 N_Subprogram_Renaming_Declaration
,
4679 N_Abstract_Subprogram_Declaration
,
4680 N_Formal_Abstract_Subprogram_Declaration
)
4682 if Is_Abstract_Type
(Etype
(Designator
))
4683 and then not Is_Interface
(Etype
(Designator
))
4686 ("function that returns abstract type must be abstract", N
);
4688 -- Ada 2012 (AI-0073): Extend this test to subprograms with an
4689 -- access result whose designated type is abstract.
4691 elsif Nkind
(Result_Definition
(N
)) = N_Access_Definition
4693 not Is_Class_Wide_Type
(Designated_Type
(Etype
(Designator
)))
4694 and then Is_Abstract_Type
(Designated_Type
(Etype
(Designator
)))
4695 and then Ada_Version
>= Ada_2012
4697 Error_Msg_N
("function whose access result designates "
4698 & "abstract type must be abstract", N
);
4704 end Analyze_Subprogram_Specification
;
4706 -----------------------
4707 -- Check_Conformance --
4708 -----------------------
4710 procedure Check_Conformance
4711 (New_Id
: Entity_Id
;
4713 Ctype
: Conformance_Type
;
4715 Conforms
: out Boolean;
4716 Err_Loc
: Node_Id
:= Empty
;
4717 Get_Inst
: Boolean := False;
4718 Skip_Controlling_Formals
: Boolean := False)
4720 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
4721 -- Sets Conforms to False. If Errmsg is False, then that's all it does.
4722 -- If Errmsg is True, then processing continues to post an error message
4723 -- for conformance error on given node. Two messages are output. The
4724 -- first message points to the previous declaration with a general "no
4725 -- conformance" message. The second is the detailed reason, supplied as
4726 -- Msg. The parameter N provide information for a possible & insertion
4727 -- in the message, and also provides the location for posting the
4728 -- message in the absence of a specified Err_Loc location.
4730 -----------------------
4731 -- Conformance_Error --
4732 -----------------------
4734 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
4741 if No
(Err_Loc
) then
4747 Error_Msg_Sloc
:= Sloc
(Old_Id
);
4750 when Type_Conformant
=>
4751 Error_Msg_N
-- CODEFIX
4752 ("not type conformant with declaration#!", Enode
);
4754 when Mode_Conformant
=>
4755 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4757 ("not mode conformant with operation inherited#!",
4761 ("not mode conformant with declaration#!", Enode
);
4764 when Subtype_Conformant
=>
4765 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4767 ("not subtype conformant with operation inherited#!",
4771 ("not subtype conformant with declaration#!", Enode
);
4774 when Fully_Conformant
=>
4775 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4776 Error_Msg_N
-- CODEFIX
4777 ("not fully conformant with operation inherited#!",
4780 Error_Msg_N
-- CODEFIX
4781 ("not fully conformant with declaration#!", Enode
);
4785 Error_Msg_NE
(Msg
, Enode
, N
);
4787 end Conformance_Error
;
4791 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
4792 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
4793 Old_Formal
: Entity_Id
;
4794 New_Formal
: Entity_Id
;
4795 Access_Types_Match
: Boolean;
4796 Old_Formal_Base
: Entity_Id
;
4797 New_Formal_Base
: Entity_Id
;
4799 -- Start of processing for Check_Conformance
4804 -- We need a special case for operators, since they don't appear
4807 if Ctype
= Type_Conformant
then
4808 if Ekind
(New_Id
) = E_Operator
4809 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
4815 -- If both are functions/operators, check return types conform
4817 if Old_Type
/= Standard_Void_Type
4819 New_Type
/= Standard_Void_Type
4821 -- If we are checking interface conformance we omit controlling
4822 -- arguments and result, because we are only checking the conformance
4823 -- of the remaining parameters.
4825 if Has_Controlling_Result
(Old_Id
)
4826 and then Has_Controlling_Result
(New_Id
)
4827 and then Skip_Controlling_Formals
4831 elsif not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
4832 if Ctype
>= Subtype_Conformant
4833 and then not Predicates_Match
(Old_Type
, New_Type
)
4836 ("\predicate of return type does not match!", New_Id
);
4839 ("\return type does not match!", New_Id
);
4845 -- Ada 2005 (AI-231): In case of anonymous access types check the
4846 -- null-exclusion and access-to-constant attributes match.
4848 if Ada_Version
>= Ada_2005
4849 and then Ekind
(Etype
(Old_Type
)) = E_Anonymous_Access_Type
4851 (Can_Never_Be_Null
(Old_Type
) /= Can_Never_Be_Null
(New_Type
)
4852 or else Is_Access_Constant
(Etype
(Old_Type
)) /=
4853 Is_Access_Constant
(Etype
(New_Type
)))
4855 Conformance_Error
("\return type does not match!", New_Id
);
4859 -- If either is a function/operator and the other isn't, error
4861 elsif Old_Type
/= Standard_Void_Type
4862 or else New_Type
/= Standard_Void_Type
4864 Conformance_Error
("\functions can only match functions!", New_Id
);
4868 -- In subtype conformant case, conventions must match (RM 6.3.1(16)).
4869 -- If this is a renaming as body, refine error message to indicate that
4870 -- the conflict is with the original declaration. If the entity is not
4871 -- frozen, the conventions don't have to match, the one of the renamed
4872 -- entity is inherited.
4874 if Ctype
>= Subtype_Conformant
then
4875 if Convention
(Old_Id
) /= Convention
(New_Id
) then
4876 if not Is_Frozen
(New_Id
) then
4879 elsif Present
(Err_Loc
)
4880 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
4881 and then Present
(Corresponding_Spec
(Err_Loc
))
4883 Error_Msg_Name_1
:= Chars
(New_Id
);
4885 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
4886 Conformance_Error
("\prior declaration for% has convention %!");
4889 Conformance_Error
("\calling conventions do not match!");
4894 elsif Is_Formal_Subprogram
(Old_Id
)
4895 or else Is_Formal_Subprogram
(New_Id
)
4897 Conformance_Error
("\formal subprograms not allowed!");
4900 -- Pragma Ghost behaves as a convention in the context of subtype
4901 -- conformance (SPARK RM 6.9(5)). Do not check internally generated
4902 -- subprograms as their spec may reside in a Ghost region and their
4903 -- body not, or vice versa.
4905 elsif Comes_From_Source
(Old_Id
)
4906 and then Comes_From_Source
(New_Id
)
4907 and then Is_Ghost_Entity
(Old_Id
) /= Is_Ghost_Entity
(New_Id
)
4909 Conformance_Error
("\ghost modes do not match!");
4914 -- Deal with parameters
4916 -- Note: we use the entity information, rather than going directly
4917 -- to the specification in the tree. This is not only simpler, but
4918 -- absolutely necessary for some cases of conformance tests between
4919 -- operators, where the declaration tree simply does not exist.
4921 Old_Formal
:= First_Formal
(Old_Id
);
4922 New_Formal
:= First_Formal
(New_Id
);
4923 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
4924 if Is_Controlling_Formal
(Old_Formal
)
4925 and then Is_Controlling_Formal
(New_Formal
)
4926 and then Skip_Controlling_Formals
4928 -- The controlling formals will have different types when
4929 -- comparing an interface operation with its match, but both
4930 -- or neither must be access parameters.
4932 if Is_Access_Type
(Etype
(Old_Formal
))
4934 Is_Access_Type
(Etype
(New_Formal
))
4936 goto Skip_Controlling_Formal
;
4939 ("\access parameter does not match!", New_Formal
);
4943 -- Ada 2012: Mode conformance also requires that formal parameters
4944 -- be both aliased, or neither.
4946 if Ctype
>= Mode_Conformant
and then Ada_Version
>= Ada_2012
then
4947 if Is_Aliased
(Old_Formal
) /= Is_Aliased
(New_Formal
) then
4949 ("\aliased parameter mismatch!", New_Formal
);
4953 if Ctype
= Fully_Conformant
then
4955 -- Names must match. Error message is more accurate if we do
4956 -- this before checking that the types of the formals match.
4958 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
4959 Conformance_Error
("\name& does not match!", New_Formal
);
4961 -- Set error posted flag on new formal as well to stop
4962 -- junk cascaded messages in some cases.
4964 Set_Error_Posted
(New_Formal
);
4968 -- Null exclusion must match
4970 if Null_Exclusion_Present
(Parent
(Old_Formal
))
4972 Null_Exclusion_Present
(Parent
(New_Formal
))
4974 -- Only give error if both come from source. This should be
4975 -- investigated some time, since it should not be needed ???
4977 if Comes_From_Source
(Old_Formal
)
4979 Comes_From_Source
(New_Formal
)
4982 ("\null exclusion for& does not match", New_Formal
);
4984 -- Mark error posted on the new formal to avoid duplicated
4985 -- complaint about types not matching.
4987 Set_Error_Posted
(New_Formal
);
4992 -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This
4993 -- case occurs whenever a subprogram is being renamed and one of its
4994 -- parameters imposes a null exclusion. For example:
4996 -- type T is null record;
4997 -- type Acc_T is access T;
4998 -- subtype Acc_T_Sub is Acc_T;
5000 -- procedure P (Obj : not null Acc_T_Sub); -- itype
5001 -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype
5004 Old_Formal_Base
:= Etype
(Old_Formal
);
5005 New_Formal_Base
:= Etype
(New_Formal
);
5008 Old_Formal_Base
:= Get_Instance_Of
(Old_Formal_Base
);
5009 New_Formal_Base
:= Get_Instance_Of
(New_Formal_Base
);
5012 Access_Types_Match
:= Ada_Version
>= Ada_2005
5014 -- Ensure that this rule is only applied when New_Id is a
5015 -- renaming of Old_Id.
5017 and then Nkind
(Parent
(Parent
(New_Id
))) =
5018 N_Subprogram_Renaming_Declaration
5019 and then Nkind
(Name
(Parent
(Parent
(New_Id
)))) in N_Has_Entity
5020 and then Present
(Entity
(Name
(Parent
(Parent
(New_Id
)))))
5021 and then Entity
(Name
(Parent
(Parent
(New_Id
)))) = Old_Id
5023 -- Now handle the allowed access-type case
5025 and then Is_Access_Type
(Old_Formal_Base
)
5026 and then Is_Access_Type
(New_Formal_Base
)
5028 -- The type kinds must match. The only exception occurs with
5029 -- multiple generics of the form:
5032 -- type F is private; type A is private;
5033 -- type F_Ptr is access F; type A_Ptr is access A;
5034 -- with proc F_P (X : F_Ptr); with proc A_P (X : A_Ptr);
5035 -- package F_Pack is ... package A_Pack is
5036 -- package F_Inst is
5037 -- new F_Pack (A, A_Ptr, A_P);
5039 -- When checking for conformance between the parameters of A_P
5040 -- and F_P, the type kinds of F_Ptr and A_Ptr will not match
5041 -- because the compiler has transformed A_Ptr into a subtype of
5042 -- F_Ptr. We catch this case in the code below.
5044 and then (Ekind
(Old_Formal_Base
) = Ekind
(New_Formal_Base
)
5046 (Is_Generic_Type
(Old_Formal_Base
)
5047 and then Is_Generic_Type
(New_Formal_Base
)
5048 and then Is_Internal
(New_Formal_Base
)
5049 and then Etype
(Etype
(New_Formal_Base
)) =
5051 and then Directly_Designated_Type
(Old_Formal_Base
) =
5052 Directly_Designated_Type
(New_Formal_Base
)
5053 and then ((Is_Itype
(Old_Formal_Base
)
5054 and then Can_Never_Be_Null
(Old_Formal_Base
))
5056 (Is_Itype
(New_Formal_Base
)
5057 and then Can_Never_Be_Null
(New_Formal_Base
)));
5059 -- Types must always match. In the visible part of an instance,
5060 -- usual overloading rules for dispatching operations apply, and
5061 -- we check base types (not the actual subtypes).
5063 if In_Instance_Visible_Part
5064 and then Is_Dispatching_Operation
(New_Id
)
5066 if not Conforming_Types
5067 (T1
=> Base_Type
(Etype
(Old_Formal
)),
5068 T2
=> Base_Type
(Etype
(New_Formal
)),
5070 Get_Inst
=> Get_Inst
)
5071 and then not Access_Types_Match
5073 Conformance_Error
("\type of & does not match!", New_Formal
);
5077 elsif not Conforming_Types
5078 (T1
=> Old_Formal_Base
,
5079 T2
=> New_Formal_Base
,
5081 Get_Inst
=> Get_Inst
)
5082 and then not Access_Types_Match
5084 -- Don't give error message if old type is Any_Type. This test
5085 -- avoids some cascaded errors, e.g. in case of a bad spec.
5087 if Errmsg
and then Old_Formal_Base
= Any_Type
then
5090 if Ctype
>= Subtype_Conformant
5092 not Predicates_Match
(Old_Formal_Base
, New_Formal_Base
)
5095 ("\predicate of & does not match!", New_Formal
);
5098 ("\type of & does not match!", New_Formal
);
5105 -- For mode conformance, mode must match
5107 if Ctype
>= Mode_Conformant
then
5108 if Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
) then
5109 if not Ekind_In
(New_Id
, E_Function
, E_Procedure
)
5110 or else not Is_Primitive_Wrapper
(New_Id
)
5112 Conformance_Error
("\mode of & does not match!", New_Formal
);
5116 T
: constant Entity_Id
:= Find_Dispatching_Type
(New_Id
);
5118 if Is_Protected_Type
(Corresponding_Concurrent_Type
(T
))
5120 Error_Msg_PT
(New_Id
, Ultimate_Alias
(Old_Id
));
5123 ("\mode of & does not match!", New_Formal
);
5130 -- Part of mode conformance for access types is having the same
5131 -- constant modifier.
5133 elsif Access_Types_Match
5134 and then Is_Access_Constant
(Old_Formal_Base
) /=
5135 Is_Access_Constant
(New_Formal_Base
)
5138 ("\constant modifier does not match!", New_Formal
);
5143 if Ctype
>= Subtype_Conformant
then
5145 -- Ada 2005 (AI-231): In case of anonymous access types check
5146 -- the null-exclusion and access-to-constant attributes must
5147 -- match. For null exclusion, we test the types rather than the
5148 -- formals themselves, since the attribute is only set reliably
5149 -- on the formals in the Ada 95 case, and we exclude the case
5150 -- where Old_Formal is marked as controlling, to avoid errors
5151 -- when matching completing bodies with dispatching declarations
5152 -- (access formals in the bodies aren't marked Can_Never_Be_Null).
5154 if Ada_Version
>= Ada_2005
5155 and then Ekind
(Etype
(Old_Formal
)) = E_Anonymous_Access_Type
5156 and then Ekind
(Etype
(New_Formal
)) = E_Anonymous_Access_Type
5158 ((Can_Never_Be_Null
(Etype
(Old_Formal
)) /=
5159 Can_Never_Be_Null
(Etype
(New_Formal
))
5161 not Is_Controlling_Formal
(Old_Formal
))
5163 Is_Access_Constant
(Etype
(Old_Formal
)) /=
5164 Is_Access_Constant
(Etype
(New_Formal
)))
5166 -- Do not complain if error already posted on New_Formal. This
5167 -- avoids some redundant error messages.
5169 and then not Error_Posted
(New_Formal
)
5171 -- It is allowed to omit the null-exclusion in case of stream
5172 -- attribute subprograms. We recognize stream subprograms
5173 -- through their TSS-generated suffix.
5176 TSS_Name
: constant TSS_Name_Type
:= Get_TSS_Name
(New_Id
);
5179 if TSS_Name
/= TSS_Stream_Read
5180 and then TSS_Name
/= TSS_Stream_Write
5181 and then TSS_Name
/= TSS_Stream_Input
5182 and then TSS_Name
/= TSS_Stream_Output
5184 -- Here we have a definite conformance error. It is worth
5185 -- special casing the error message for the case of a
5186 -- controlling formal (which excludes null).
5188 if Is_Controlling_Formal
(New_Formal
) then
5189 Error_Msg_Node_2
:= Scope
(New_Formal
);
5191 ("\controlling formal & of & excludes null, "
5192 & "declaration must exclude null as well",
5195 -- Normal case (couldn't we give more detail here???)
5199 ("\type of & does not match!", New_Formal
);
5208 -- Full conformance checks
5210 if Ctype
= Fully_Conformant
then
5212 -- We have checked already that names match
5214 if Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
5216 -- Check default expressions for in parameters
5219 NewD
: constant Boolean :=
5220 Present
(Default_Value
(New_Formal
));
5221 OldD
: constant Boolean :=
5222 Present
(Default_Value
(Old_Formal
));
5224 if NewD
or OldD
then
5226 -- The old default value has been analyzed because the
5227 -- current full declaration will have frozen everything
5228 -- before. The new default value has not been analyzed,
5229 -- so analyze it now before we check for conformance.
5232 Push_Scope
(New_Id
);
5233 Preanalyze_Spec_Expression
5234 (Default_Value
(New_Formal
), Etype
(New_Formal
));
5238 if not (NewD
and OldD
)
5239 or else not Fully_Conformant_Expressions
5240 (Default_Value
(Old_Formal
),
5241 Default_Value
(New_Formal
))
5244 ("\default expression for & does not match!",
5253 -- A couple of special checks for Ada 83 mode. These checks are
5254 -- skipped if either entity is an operator in package Standard,
5255 -- or if either old or new instance is not from the source program.
5257 if Ada_Version
= Ada_83
5258 and then Sloc
(Old_Id
) > Standard_Location
5259 and then Sloc
(New_Id
) > Standard_Location
5260 and then Comes_From_Source
(Old_Id
)
5261 and then Comes_From_Source
(New_Id
)
5264 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
5265 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
5268 -- Explicit IN must be present or absent in both cases. This
5269 -- test is required only in the full conformance case.
5271 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
5272 and then Ctype
= Fully_Conformant
5275 ("\(Ada 83) IN must appear in both declarations",
5280 -- Grouping (use of comma in param lists) must be the same
5281 -- This is where we catch a misconformance like:
5284 -- A : Integer; B : Integer
5286 -- which are represented identically in the tree except
5287 -- for the setting of the flags More_Ids and Prev_Ids.
5289 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
5290 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
5293 ("\grouping of & does not match!", New_Formal
);
5299 -- This label is required when skipping controlling formals
5301 <<Skip_Controlling_Formal
>>
5303 Next_Formal
(Old_Formal
);
5304 Next_Formal
(New_Formal
);
5307 if Present
(Old_Formal
) then
5308 Conformance_Error
("\too few parameters!");
5311 elsif Present
(New_Formal
) then
5312 Conformance_Error
("\too many parameters!", New_Formal
);
5315 end Check_Conformance
;
5317 -----------------------
5318 -- Check_Conventions --
5319 -----------------------
5321 procedure Check_Conventions
(Typ
: Entity_Id
) is
5322 Ifaces_List
: Elist_Id
;
5324 procedure Check_Convention
(Op
: Entity_Id
);
5325 -- Verify that the convention of inherited dispatching operation Op is
5326 -- consistent among all subprograms it overrides. In order to minimize
5327 -- the search, Search_From is utilized to designate a specific point in
5328 -- the list rather than iterating over the whole list once more.
5330 ----------------------
5331 -- Check_Convention --
5332 ----------------------
5334 procedure Check_Convention
(Op
: Entity_Id
) is
5335 Op_Conv
: constant Convention_Id
:= Convention
(Op
);
5336 Iface_Conv
: Convention_Id
;
5337 Iface_Elmt
: Elmt_Id
;
5338 Iface_Prim_Elmt
: Elmt_Id
;
5339 Iface_Prim
: Entity_Id
;
5342 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
5343 while Present
(Iface_Elmt
) loop
5345 First_Elmt
(Primitive_Operations
(Node
(Iface_Elmt
)));
5346 while Present
(Iface_Prim_Elmt
) loop
5347 Iface_Prim
:= Node
(Iface_Prim_Elmt
);
5348 Iface_Conv
:= Convention
(Iface_Prim
);
5350 if Is_Interface_Conformant
(Typ
, Iface_Prim
, Op
)
5351 and then Iface_Conv
/= Op_Conv
5354 ("inconsistent conventions in primitive operations", Typ
);
5356 Error_Msg_Name_1
:= Chars
(Op
);
5357 Error_Msg_Name_2
:= Get_Convention_Name
(Op_Conv
);
5358 Error_Msg_Sloc
:= Sloc
(Op
);
5360 if Comes_From_Source
(Op
) or else No
(Alias
(Op
)) then
5361 if not Present
(Overridden_Operation
(Op
)) then
5362 Error_Msg_N
("\\primitive % defined #", Typ
);
5365 ("\\overriding operation % with "
5366 & "convention % defined #", Typ
);
5369 else pragma Assert
(Present
(Alias
(Op
)));
5370 Error_Msg_Sloc
:= Sloc
(Alias
(Op
));
5371 Error_Msg_N
("\\inherited operation % with "
5372 & "convention % defined #", Typ
);
5375 Error_Msg_Name_1
:= Chars
(Op
);
5376 Error_Msg_Name_2
:= Get_Convention_Name
(Iface_Conv
);
5377 Error_Msg_Sloc
:= Sloc
(Iface_Prim
);
5378 Error_Msg_N
("\\overridden operation % with "
5379 & "convention % defined #", Typ
);
5381 -- Avoid cascading errors
5386 Next_Elmt
(Iface_Prim_Elmt
);
5389 Next_Elmt
(Iface_Elmt
);
5391 end Check_Convention
;
5395 Prim_Op
: Entity_Id
;
5396 Prim_Op_Elmt
: Elmt_Id
;
5398 -- Start of processing for Check_Conventions
5401 if not Has_Interfaces
(Typ
) then
5405 Collect_Interfaces
(Typ
, Ifaces_List
);
5407 -- The algorithm checks every overriding dispatching operation against
5408 -- all the corresponding overridden dispatching operations, detecting
5409 -- differences in conventions.
5411 Prim_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5412 while Present
(Prim_Op_Elmt
) loop
5413 Prim_Op
:= Node
(Prim_Op_Elmt
);
5415 -- A small optimization: skip the predefined dispatching operations
5416 -- since they always have the same convention.
5418 if not Is_Predefined_Dispatching_Operation
(Prim_Op
) then
5419 Check_Convention
(Prim_Op
);
5422 Next_Elmt
(Prim_Op_Elmt
);
5424 end Check_Conventions
;
5426 ------------------------------
5427 -- Check_Delayed_Subprogram --
5428 ------------------------------
5430 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
5433 procedure Possible_Freeze
(T
: Entity_Id
);
5434 -- T is the type of either a formal parameter or of the return type.
5435 -- If T is not yet frozen and needs a delayed freeze, then the
5436 -- subprogram itself must be delayed. If T is the limited view of an
5437 -- incomplete type the subprogram must be frozen as well, because
5438 -- T may depend on local types that have not been frozen yet.
5440 ---------------------
5441 -- Possible_Freeze --
5442 ---------------------
5444 procedure Possible_Freeze
(T
: Entity_Id
) is
5446 if Has_Delayed_Freeze
(T
) and then not Is_Frozen
(T
) then
5447 Set_Has_Delayed_Freeze
(Designator
);
5449 elsif Is_Access_Type
(T
)
5450 and then Has_Delayed_Freeze
(Designated_Type
(T
))
5451 and then not Is_Frozen
(Designated_Type
(T
))
5453 Set_Has_Delayed_Freeze
(Designator
);
5455 elsif Ekind
(T
) = E_Incomplete_Type
5456 and then From_Limited_With
(T
)
5458 Set_Has_Delayed_Freeze
(Designator
);
5460 -- AI05-0151: In Ada 2012, Incomplete types can appear in the profile
5461 -- of a subprogram or entry declaration.
5463 elsif Ekind
(T
) = E_Incomplete_Type
5464 and then Ada_Version
>= Ada_2012
5466 Set_Has_Delayed_Freeze
(Designator
);
5469 end Possible_Freeze
;
5471 -- Start of processing for Check_Delayed_Subprogram
5474 -- All subprograms, including abstract subprograms, may need a freeze
5475 -- node if some formal type or the return type needs one.
5477 Possible_Freeze
(Etype
(Designator
));
5478 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
5480 -- Need delayed freeze if any of the formal types themselves need
5481 -- a delayed freeze and are not yet frozen.
5483 F
:= First_Formal
(Designator
);
5484 while Present
(F
) loop
5485 Possible_Freeze
(Etype
(F
));
5486 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
5490 -- Mark functions that return by reference. Note that it cannot be
5491 -- done for delayed_freeze subprograms because the underlying
5492 -- returned type may not be known yet (for private types)
5494 if not Has_Delayed_Freeze
(Designator
) and then Expander_Active
then
5496 Typ
: constant Entity_Id
:= Etype
(Designator
);
5497 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
5499 if Is_Limited_View
(Typ
) then
5500 Set_Returns_By_Ref
(Designator
);
5501 elsif Present
(Utyp
) and then CW_Or_Has_Controlled_Part
(Utyp
) then
5502 Set_Returns_By_Ref
(Designator
);
5506 end Check_Delayed_Subprogram
;
5508 ------------------------------------
5509 -- Check_Discriminant_Conformance --
5510 ------------------------------------
5512 procedure Check_Discriminant_Conformance
5517 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
5518 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
5519 New_Discr_Id
: Entity_Id
;
5520 New_Discr_Type
: Entity_Id
;
5522 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
5523 -- Post error message for conformance error on given node. Two messages
5524 -- are output. The first points to the previous declaration with a
5525 -- general "no conformance" message. The second is the detailed reason,
5526 -- supplied as Msg. The parameter N provide information for a possible
5527 -- & insertion in the message.
5529 -----------------------
5530 -- Conformance_Error --
5531 -----------------------
5533 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
5535 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
5536 Error_Msg_N
-- CODEFIX
5537 ("not fully conformant with declaration#!", N
);
5538 Error_Msg_NE
(Msg
, N
, N
);
5539 end Conformance_Error
;
5541 -- Start of processing for Check_Discriminant_Conformance
5544 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
5545 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
5547 -- The subtype mark of the discriminant on the full type has not
5548 -- been analyzed so we do it here. For an access discriminant a new
5551 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
5553 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
5556 Analyze
(Discriminant_Type
(New_Discr
));
5557 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
5559 -- Ada 2005: if the discriminant definition carries a null
5560 -- exclusion, create an itype to check properly for consistency
5561 -- with partial declaration.
5563 if Is_Access_Type
(New_Discr_Type
)
5564 and then Null_Exclusion_Present
(New_Discr
)
5567 Create_Null_Excluding_Itype
5568 (T
=> New_Discr_Type
,
5569 Related_Nod
=> New_Discr
,
5570 Scope_Id
=> Current_Scope
);
5574 if not Conforming_Types
5575 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
5577 Conformance_Error
("type of & does not match!", New_Discr_Id
);
5580 -- Treat the new discriminant as an occurrence of the old one,
5581 -- for navigation purposes, and fill in some semantic
5582 -- information, for completeness.
5584 Generate_Reference
(Old_Discr
, New_Discr_Id
, 'r');
5585 Set_Etype
(New_Discr_Id
, Etype
(Old_Discr
));
5586 Set_Scope
(New_Discr_Id
, Scope
(Old_Discr
));
5591 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
5592 Conformance_Error
("name & does not match!", New_Discr_Id
);
5596 -- Default expressions must match
5599 NewD
: constant Boolean :=
5600 Present
(Expression
(New_Discr
));
5601 OldD
: constant Boolean :=
5602 Present
(Expression
(Parent
(Old_Discr
)));
5605 if NewD
or OldD
then
5607 -- The old default value has been analyzed and expanded,
5608 -- because the current full declaration will have frozen
5609 -- everything before. The new default values have not been
5610 -- expanded, so expand now to check conformance.
5613 Preanalyze_Spec_Expression
5614 (Expression
(New_Discr
), New_Discr_Type
);
5617 if not (NewD
and OldD
)
5618 or else not Fully_Conformant_Expressions
5619 (Expression
(Parent
(Old_Discr
)),
5620 Expression
(New_Discr
))
5624 ("default expression for & does not match!",
5631 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
5633 if Ada_Version
= Ada_83
then
5635 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
5638 -- Grouping (use of comma in param lists) must be the same
5639 -- This is where we catch a misconformance like:
5642 -- A : Integer; B : Integer
5644 -- which are represented identically in the tree except
5645 -- for the setting of the flags More_Ids and Prev_Ids.
5647 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
5648 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
5651 ("grouping of & does not match!", New_Discr_Id
);
5657 Next_Discriminant
(Old_Discr
);
5661 if Present
(Old_Discr
) then
5662 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
5665 elsif Present
(New_Discr
) then
5667 ("too many discriminants!", Defining_Identifier
(New_Discr
));
5670 end Check_Discriminant_Conformance
;
5672 ----------------------------
5673 -- Check_Fully_Conformant --
5674 ----------------------------
5676 procedure Check_Fully_Conformant
5677 (New_Id
: Entity_Id
;
5679 Err_Loc
: Node_Id
:= Empty
)
5682 pragma Warnings
(Off
, Result
);
5685 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
5686 end Check_Fully_Conformant
;
5688 ---------------------------
5689 -- Check_Mode_Conformant --
5690 ---------------------------
5692 procedure Check_Mode_Conformant
5693 (New_Id
: Entity_Id
;
5695 Err_Loc
: Node_Id
:= Empty
;
5696 Get_Inst
: Boolean := False)
5699 pragma Warnings
(Off
, Result
);
5702 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
5703 end Check_Mode_Conformant
;
5705 --------------------------------
5706 -- Check_Overriding_Indicator --
5707 --------------------------------
5709 procedure Check_Overriding_Indicator
5711 Overridden_Subp
: Entity_Id
;
5712 Is_Primitive
: Boolean)
5718 -- No overriding indicator for literals
5720 if Ekind
(Subp
) = E_Enumeration_Literal
then
5723 elsif Ekind
(Subp
) = E_Entry
then
5724 Decl
:= Parent
(Subp
);
5726 -- No point in analyzing a malformed operator
5728 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
5729 and then Error_Posted
(Subp
)
5734 Decl
:= Unit_Declaration_Node
(Subp
);
5737 if Nkind_In
(Decl
, N_Subprogram_Body
,
5738 N_Subprogram_Body_Stub
,
5739 N_Subprogram_Declaration
,
5740 N_Abstract_Subprogram_Declaration
,
5741 N_Subprogram_Renaming_Declaration
)
5743 Spec
:= Specification
(Decl
);
5745 elsif Nkind
(Decl
) = N_Entry_Declaration
then
5752 -- The overriding operation is type conformant with the overridden one,
5753 -- but the names of the formals are not required to match. If the names
5754 -- appear permuted in the overriding operation, this is a possible
5755 -- source of confusion that is worth diagnosing. Controlling formals
5756 -- often carry names that reflect the type, and it is not worthwhile
5757 -- requiring that their names match.
5759 if Present
(Overridden_Subp
)
5760 and then Nkind
(Subp
) /= N_Defining_Operator_Symbol
5767 Form1
:= First_Formal
(Subp
);
5768 Form2
:= First_Formal
(Overridden_Subp
);
5770 -- If the overriding operation is a synchronized operation, skip
5771 -- the first parameter of the overridden operation, which is
5772 -- implicit in the new one. If the operation is declared in the
5773 -- body it is not primitive and all formals must match.
5775 if Is_Concurrent_Type
(Scope
(Subp
))
5776 and then Is_Tagged_Type
(Scope
(Subp
))
5777 and then not Has_Completion
(Scope
(Subp
))
5779 Form2
:= Next_Formal
(Form2
);
5782 if Present
(Form1
) then
5783 Form1
:= Next_Formal
(Form1
);
5784 Form2
:= Next_Formal
(Form2
);
5787 while Present
(Form1
) loop
5788 if not Is_Controlling_Formal
(Form1
)
5789 and then Present
(Next_Formal
(Form2
))
5790 and then Chars
(Form1
) = Chars
(Next_Formal
(Form2
))
5792 Error_Msg_Node_2
:= Alias
(Overridden_Subp
);
5793 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
5795 ("& does not match corresponding formal of&#",
5800 Next_Formal
(Form1
);
5801 Next_Formal
(Form2
);
5806 -- If there is an overridden subprogram, then check that there is no
5807 -- "not overriding" indicator, and mark the subprogram as overriding.
5808 -- This is not done if the overridden subprogram is marked as hidden,
5809 -- which can occur for the case of inherited controlled operations
5810 -- (see Derive_Subprogram), unless the inherited subprogram's parent
5811 -- subprogram is not itself hidden. (Note: This condition could probably
5812 -- be simplified, leaving out the testing for the specific controlled
5813 -- cases, but it seems safer and clearer this way, and echoes similar
5814 -- special-case tests of this kind in other places.)
5816 if Present
(Overridden_Subp
)
5817 and then (not Is_Hidden
(Overridden_Subp
)
5819 (Nam_In
(Chars
(Overridden_Subp
), Name_Initialize
,
5822 and then Present
(Alias
(Overridden_Subp
))
5823 and then not Is_Hidden
(Alias
(Overridden_Subp
))))
5825 if Must_Not_Override
(Spec
) then
5826 Error_Msg_Sloc
:= Sloc
(Overridden_Subp
);
5828 if Ekind
(Subp
) = E_Entry
then
5830 ("entry & overrides inherited operation #", Spec
, Subp
);
5833 ("subprogram & overrides inherited operation #", Spec
, Subp
);
5836 -- Special-case to fix a GNAT oddity: Limited_Controlled is declared
5837 -- as an extension of Root_Controlled, and thus has a useless Adjust
5838 -- operation. This operation should not be inherited by other limited
5839 -- controlled types. An explicit Adjust for them is not overriding.
5841 elsif Must_Override
(Spec
)
5842 and then Chars
(Overridden_Subp
) = Name_Adjust
5843 and then Is_Limited_Type
(Etype
(First_Formal
(Subp
)))
5844 and then Present
(Alias
(Overridden_Subp
))
5846 Is_Predefined_File_Name
5847 (Unit_File_Name
(Get_Source_Unit
(Alias
(Overridden_Subp
))))
5849 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
5851 elsif Is_Subprogram
(Subp
) then
5852 if Is_Init_Proc
(Subp
) then
5855 elsif No
(Overridden_Operation
(Subp
)) then
5857 -- For entities generated by Derive_Subprograms the overridden
5858 -- operation is the inherited primitive (which is available
5859 -- through the attribute alias)
5861 if (Is_Dispatching_Operation
(Subp
)
5862 or else Is_Dispatching_Operation
(Overridden_Subp
))
5863 and then not Comes_From_Source
(Overridden_Subp
)
5864 and then Find_Dispatching_Type
(Overridden_Subp
) =
5865 Find_Dispatching_Type
(Subp
)
5866 and then Present
(Alias
(Overridden_Subp
))
5867 and then Comes_From_Source
(Alias
(Overridden_Subp
))
5869 Set_Overridden_Operation
(Subp
, Alias
(Overridden_Subp
));
5870 Inherit_Subprogram_Contract
(Subp
, Alias
(Overridden_Subp
));
5873 Set_Overridden_Operation
(Subp
, Overridden_Subp
);
5874 Inherit_Subprogram_Contract
(Subp
, Overridden_Subp
);
5879 -- If primitive flag is set or this is a protected operation, then
5880 -- the operation is overriding at the point of its declaration, so
5881 -- warn if necessary. Otherwise it may have been declared before the
5882 -- operation it overrides and no check is required.
5885 and then not Must_Override
(Spec
)
5886 and then (Is_Primitive
5887 or else Ekind
(Scope
(Subp
)) = E_Protected_Type
)
5889 Style
.Missing_Overriding
(Decl
, Subp
);
5892 -- If Subp is an operator, it may override a predefined operation, if
5893 -- it is defined in the same scope as the type to which it applies.
5894 -- In that case Overridden_Subp is empty because of our implicit
5895 -- representation for predefined operators. We have to check whether the
5896 -- signature of Subp matches that of a predefined operator. Note that
5897 -- first argument provides the name of the operator, and the second
5898 -- argument the signature that may match that of a standard operation.
5899 -- If the indicator is overriding, then the operator must match a
5900 -- predefined signature, because we know already that there is no
5901 -- explicit overridden operation.
5903 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
then
5904 if Must_Not_Override
(Spec
) then
5906 -- If this is not a primitive or a protected subprogram, then
5907 -- "not overriding" is illegal.
5910 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
5912 Error_Msg_N
("overriding indicator only allowed "
5913 & "if subprogram is primitive", Subp
);
5915 elsif Can_Override_Operator
(Subp
) then
5917 ("subprogram& overrides predefined operator ", Spec
, Subp
);
5920 elsif Must_Override
(Spec
) then
5921 if No
(Overridden_Operation
(Subp
))
5922 and then not Can_Override_Operator
(Subp
)
5924 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
5927 elsif not Error_Posted
(Subp
)
5928 and then Style_Check
5929 and then Can_Override_Operator
(Subp
)
5931 not Is_Predefined_File_Name
5932 (Unit_File_Name
(Get_Source_Unit
(Subp
)))
5934 -- If style checks are enabled, indicate that the indicator is
5935 -- missing. However, at the point of declaration, the type of
5936 -- which this is a primitive operation may be private, in which
5937 -- case the indicator would be premature.
5939 if Has_Private_Declaration
(Etype
(Subp
))
5940 or else Has_Private_Declaration
(Etype
(First_Formal
(Subp
)))
5944 Style
.Missing_Overriding
(Decl
, Subp
);
5948 elsif Must_Override
(Spec
) then
5949 if Ekind
(Subp
) = E_Entry
then
5950 Error_Msg_NE
("entry & is not overriding", Spec
, Subp
);
5952 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
5955 -- If the operation is marked "not overriding" and it's not primitive
5956 -- then an error is issued, unless this is an operation of a task or
5957 -- protected type (RM05-8.3.1(3/2-4/2)). Error cases where "overriding"
5958 -- has been specified have already been checked above.
5960 elsif Must_Not_Override
(Spec
)
5961 and then not Is_Primitive
5962 and then Ekind
(Subp
) /= E_Entry
5963 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
5966 ("overriding indicator only allowed if subprogram is primitive",
5970 end Check_Overriding_Indicator
;
5976 -- Note: this procedure needs to know far too much about how the expander
5977 -- messes with exceptions. The use of the flag Exception_Junk and the
5978 -- incorporation of knowledge of Exp_Ch11.Expand_Local_Exception_Handlers
5979 -- works, but is not very clean. It would be better if the expansion
5980 -- routines would leave Original_Node working nicely, and we could use
5981 -- Original_Node here to ignore all the peculiar expander messing ???
5983 procedure Check_Returns
5987 Proc
: Entity_Id
:= Empty
)
5991 procedure Check_Statement_Sequence
(L
: List_Id
);
5992 -- Internal recursive procedure to check a list of statements for proper
5993 -- termination by a return statement (or a transfer of control or a
5994 -- compound statement that is itself internally properly terminated).
5996 ------------------------------
5997 -- Check_Statement_Sequence --
5998 ------------------------------
6000 procedure Check_Statement_Sequence
(L
: List_Id
) is
6005 function Assert_False
return Boolean;
6006 -- Returns True if Last_Stm is a pragma Assert (False) that has been
6007 -- rewritten as a null statement when assertions are off. The assert
6008 -- is not active, but it is still enough to kill the warning.
6014 function Assert_False
return Boolean is
6015 Orig
: constant Node_Id
:= Original_Node
(Last_Stm
);
6018 if Nkind
(Orig
) = N_Pragma
6019 and then Pragma_Name
(Orig
) = Name_Assert
6020 and then not Error_Posted
(Orig
)
6023 Arg
: constant Node_Id
:=
6024 First
(Pragma_Argument_Associations
(Orig
));
6025 Exp
: constant Node_Id
:= Expression
(Arg
);
6027 return Nkind
(Exp
) = N_Identifier
6028 and then Chars
(Exp
) = Name_False
;
6038 Raise_Exception_Call
: Boolean;
6039 -- Set True if statement sequence terminated by Raise_Exception call
6040 -- or a Reraise_Occurrence call.
6042 -- Start of processing for Check_Statement_Sequence
6045 Raise_Exception_Call
:= False;
6047 -- Get last real statement
6049 Last_Stm
:= Last
(L
);
6051 -- Deal with digging out exception handler statement sequences that
6052 -- have been transformed by the local raise to goto optimization.
6053 -- See Exp_Ch11.Expand_Local_Exception_Handlers for details. If this
6054 -- optimization has occurred, we are looking at something like:
6057 -- original stmts in block
6061 -- goto L1; | omitted if No_Exception_Propagation
6066 -- goto L3; -- skip handler when exception not raised
6068 -- <<L1>> -- target label for local exception
6082 -- and what we have to do is to dig out the estmts1 and estmts2
6083 -- sequences (which were the original sequences of statements in
6084 -- the exception handlers) and check them.
6086 if Nkind
(Last_Stm
) = N_Label
and then Exception_Junk
(Last_Stm
) then
6091 exit when Nkind
(Stm
) /= N_Block_Statement
;
6092 exit when not Exception_Junk
(Stm
);
6095 exit when Nkind
(Stm
) /= N_Label
;
6096 exit when not Exception_Junk
(Stm
);
6097 Check_Statement_Sequence
6098 (Statements
(Handled_Statement_Sequence
(Next
(Stm
))));
6103 exit when Nkind
(Stm
) /= N_Goto_Statement
;
6104 exit when not Exception_Junk
(Stm
);
6108 -- Don't count pragmas
6110 while Nkind
(Last_Stm
) = N_Pragma
6112 -- Don't count call to SS_Release (can happen after Raise_Exception)
6115 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
6117 Nkind
(Name
(Last_Stm
)) = N_Identifier
6119 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
6121 -- Don't count exception junk
6124 (Nkind_In
(Last_Stm
, N_Goto_Statement
,
6126 N_Object_Declaration
)
6127 and then Exception_Junk
(Last_Stm
))
6128 or else Nkind
(Last_Stm
) in N_Push_xxx_Label
6129 or else Nkind
(Last_Stm
) in N_Pop_xxx_Label
6131 -- Inserted code, such as finalization calls, is irrelevant: we only
6132 -- need to check original source.
6134 or else Is_Rewrite_Insertion
(Last_Stm
)
6139 -- Here we have the "real" last statement
6141 Kind
:= Nkind
(Last_Stm
);
6143 -- Transfer of control, OK. Note that in the No_Return procedure
6144 -- case, we already diagnosed any explicit return statements, so
6145 -- we can treat them as OK in this context.
6147 if Is_Transfer
(Last_Stm
) then
6150 -- Check cases of explicit non-indirect procedure calls
6152 elsif Kind
= N_Procedure_Call_Statement
6153 and then Is_Entity_Name
(Name
(Last_Stm
))
6155 -- Check call to Raise_Exception procedure which is treated
6156 -- specially, as is a call to Reraise_Occurrence.
6158 -- We suppress the warning in these cases since it is likely that
6159 -- the programmer really does not expect to deal with the case
6160 -- of Null_Occurrence, and thus would find a warning about a
6161 -- missing return curious, and raising Program_Error does not
6162 -- seem such a bad behavior if this does occur.
6164 -- Note that in the Ada 2005 case for Raise_Exception, the actual
6165 -- behavior will be to raise Constraint_Error (see AI-329).
6167 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
6169 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
6171 Raise_Exception_Call
:= True;
6173 -- For Raise_Exception call, test first argument, if it is
6174 -- an attribute reference for a 'Identity call, then we know
6175 -- that the call cannot possibly return.
6178 Arg
: constant Node_Id
:=
6179 Original_Node
(First_Actual
(Last_Stm
));
6181 if Nkind
(Arg
) = N_Attribute_Reference
6182 and then Attribute_Name
(Arg
) = Name_Identity
6189 -- If statement, need to look inside if there is an else and check
6190 -- each constituent statement sequence for proper termination.
6192 elsif Kind
= N_If_Statement
6193 and then Present
(Else_Statements
(Last_Stm
))
6195 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
6196 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
6198 if Present
(Elsif_Parts
(Last_Stm
)) then
6200 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
6203 while Present
(Elsif_Part
) loop
6204 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
6212 -- Case statement, check each case for proper termination
6214 elsif Kind
= N_Case_Statement
then
6218 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
6219 while Present
(Case_Alt
) loop
6220 Check_Statement_Sequence
(Statements
(Case_Alt
));
6221 Next_Non_Pragma
(Case_Alt
);
6227 -- Block statement, check its handled sequence of statements
6229 elsif Kind
= N_Block_Statement
then
6235 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
6244 -- Loop statement. If there is an iteration scheme, we can definitely
6245 -- fall out of the loop. Similarly if there is an exit statement, we
6246 -- can fall out. In either case we need a following return.
6248 elsif Kind
= N_Loop_Statement
then
6249 if Present
(Iteration_Scheme
(Last_Stm
))
6250 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
6254 -- A loop with no exit statement or iteration scheme is either
6255 -- an infinite loop, or it has some other exit (raise/return).
6256 -- In either case, no warning is required.
6262 -- Timed entry call, check entry call and delay alternatives
6264 -- Note: in expanded code, the timed entry call has been converted
6265 -- to a set of expanded statements on which the check will work
6266 -- correctly in any case.
6268 elsif Kind
= N_Timed_Entry_Call
then
6270 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
6271 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
6274 -- If statement sequence of entry call alternative is missing,
6275 -- then we can definitely fall through, and we post the error
6276 -- message on the entry call alternative itself.
6278 if No
(Statements
(ECA
)) then
6281 -- If statement sequence of delay alternative is missing, then
6282 -- we can definitely fall through, and we post the error
6283 -- message on the delay alternative itself.
6285 -- Note: if both ECA and DCA are missing the return, then we
6286 -- post only one message, should be enough to fix the bugs.
6287 -- If not we will get a message next time on the DCA when the
6290 elsif No
(Statements
(DCA
)) then
6293 -- Else check both statement sequences
6296 Check_Statement_Sequence
(Statements
(ECA
));
6297 Check_Statement_Sequence
(Statements
(DCA
));
6302 -- Conditional entry call, check entry call and else part
6304 -- Note: in expanded code, the conditional entry call has been
6305 -- converted to a set of expanded statements on which the check
6306 -- will work correctly in any case.
6308 elsif Kind
= N_Conditional_Entry_Call
then
6310 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
6313 -- If statement sequence of entry call alternative is missing,
6314 -- then we can definitely fall through, and we post the error
6315 -- message on the entry call alternative itself.
6317 if No
(Statements
(ECA
)) then
6320 -- Else check statement sequence and else part
6323 Check_Statement_Sequence
(Statements
(ECA
));
6324 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
6330 -- If we fall through, issue appropriate message
6334 -- Kill warning if last statement is a raise exception call,
6335 -- or a pragma Assert (False). Note that with assertions enabled,
6336 -- such a pragma has been converted into a raise exception call
6337 -- already, so the Assert_False is for the assertions off case.
6339 if not Raise_Exception_Call
and then not Assert_False
then
6341 -- In GNATprove mode, it is an error to have a missing return
6343 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6345 -- Issue error message or warning
6348 ("RETURN statement missing following this statement<<!",
6351 ("\Program_Error ]<<!", Last_Stm
);
6354 -- Note: we set Err even though we have not issued a warning
6355 -- because we still have a case of a missing return. This is
6356 -- an extremely marginal case, probably will never be noticed
6357 -- but we might as well get it right.
6361 -- Otherwise we have the case of a procedure marked No_Return
6364 if not Raise_Exception_Call
then
6365 if GNATprove_Mode
then
6367 ("implied return after this statement "
6368 & "would have raised Program_Error", Last_Stm
);
6371 ("implied return after this statement "
6372 & "will raise Program_Error??", Last_Stm
);
6375 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6377 ("\procedure & is marked as No_Return<<!", Last_Stm
, Proc
);
6381 RE
: constant Node_Id
:=
6382 Make_Raise_Program_Error
(Sloc
(Last_Stm
),
6383 Reason
=> PE_Implicit_Return
);
6385 Insert_After
(Last_Stm
, RE
);
6389 end Check_Statement_Sequence
;
6391 -- Start of processing for Check_Returns
6395 Check_Statement_Sequence
(Statements
(HSS
));
6397 if Present
(Exception_Handlers
(HSS
)) then
6398 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
6399 while Present
(Handler
) loop
6400 Check_Statement_Sequence
(Statements
(Handler
));
6401 Next_Non_Pragma
(Handler
);
6406 ----------------------------
6407 -- Check_Subprogram_Order --
6408 ----------------------------
6410 procedure Check_Subprogram_Order
(N
: Node_Id
) is
6412 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
6413 -- This is used to check if S1 > S2 in the sense required by this test,
6414 -- for example nameab < namec, but name2 < name10.
6416 -----------------------------
6417 -- Subprogram_Name_Greater --
6418 -----------------------------
6420 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
6425 -- Deal with special case where names are identical except for a
6426 -- numerical suffix. These are handled specially, taking the numeric
6427 -- ordering from the suffix into account.
6430 while S1
(L1
) in '0' .. '9' loop
6435 while S2
(L2
) in '0' .. '9' loop
6439 -- If non-numeric parts non-equal, do straight compare
6441 if S1
(S1
'First .. L1
) /= S2
(S2
'First .. L2
) then
6444 -- If non-numeric parts equal, compare suffixed numeric parts. Note
6445 -- that a missing suffix is treated as numeric zero in this test.
6449 while L1
< S1
'Last loop
6451 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
6455 while L2
< S2
'Last loop
6457 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
6462 end Subprogram_Name_Greater
;
6464 -- Start of processing for Check_Subprogram_Order
6467 -- Check body in alpha order if this is option
6470 and then Style_Check_Order_Subprograms
6471 and then Nkind
(N
) = N_Subprogram_Body
6472 and then Comes_From_Source
(N
)
6473 and then In_Extended_Main_Source_Unit
(N
)
6477 renames Scope_Stack
.Table
6478 (Scope_Stack
.Last
).Last_Subprogram_Name
;
6480 Body_Id
: constant Entity_Id
:=
6481 Defining_Entity
(Specification
(N
));
6484 Get_Decoded_Name_String
(Chars
(Body_Id
));
6487 if Subprogram_Name_Greater
6488 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
6490 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
6496 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
6499 end Check_Subprogram_Order;
6501 ------------------------------
6502 -- Check_Subtype_Conformant --
6503 ------------------------------
6505 procedure Check_Subtype_Conformant
6506 (New_Id : Entity_Id;
6508 Err_Loc : Node_Id := Empty;
6509 Skip_Controlling_Formals : Boolean := False;
6510 Get_Inst : Boolean := False)
6513 pragma Warnings (Off, Result);
6516 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc,
6517 Skip_Controlling_Formals => Skip_Controlling_Formals,
6518 Get_Inst => Get_Inst);
6519 end Check_Subtype_Conformant;
6521 ---------------------------
6522 -- Check_Type_Conformant --
6523 ---------------------------
6525 procedure Check_Type_Conformant
6526 (New_Id : Entity_Id;
6528 Err_Loc : Node_Id := Empty)
6531 pragma Warnings (Off, Result);
6534 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
6535 end Check_Type_Conformant;
6537 ---------------------------
6538 -- Can_Override_Operator --
6539 ---------------------------
6541 function Can_Override_Operator (Subp : Entity_Id) return Boolean is
6545 if Nkind (Subp) /= N_Defining_Operator_Symbol then
6549 Typ := Base_Type (Etype (First_Formal (Subp)));
6551 -- Check explicitly that the operation is a primitive of the type
6553 return Operator_Matches_Spec (Subp, Subp)
6554 and then not Is_Generic_Type (Typ)
6555 and then Scope (Subp) = Scope (Typ)
6556 and then not Is_Class_Wide_Type (Typ);
6558 end Can_Override_Operator;
6560 ----------------------
6561 -- Conforming_Types --
6562 ----------------------
6564 function Conforming_Types
6567 Ctype : Conformance_Type;
6568 Get_Inst : Boolean := False) return Boolean
6570 Type_1 : Entity_Id := T1;
6571 Type_2 : Entity_Id := T2;
6572 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
6574 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
6575 -- If neither T1 nor T2 are generic actual types, or if they are in
6576 -- different scopes (e.g. parent and child instances), then verify that
6577 -- the base types are equal. Otherwise T1 and T2 must be on the same
6578 -- subtype chain. The whole purpose of this procedure is to prevent
6579 -- spurious ambiguities in an instantiation that may arise if two
6580 -- distinct generic types are instantiated with the same actual.
6582 function Find_Designated_Type (T : Entity_Id) return Entity_Id;
6583 -- An access parameter can designate an incomplete type. If the
6584 -- incomplete type is the limited view of a type from a limited_
6585 -- with_clause, check whether the non-limited view is available. If
6586 -- it is a (non-limited) incomplete type, get the full view.
6588 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean;
6589 -- Returns True if and only if either T1 denotes a limited view of T2
6590 -- or T2 denotes a limited view of T1. This can arise when the limited
6591 -- with view of a type is used in a subprogram declaration and the
6592 -- subprogram body is in the scope of a regular with clause for the
6593 -- same unit. In such a case, the two type entities can be considered
6594 -- identical for purposes of conformance checking.
6596 ----------------------
6597 -- Base_Types_Match --
6598 ----------------------
6600 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
6601 BT1 : constant Entity_Id := Base_Type (T1);
6602 BT2 : constant Entity_Id := Base_Type (T2);
6608 elsif BT1 = BT2 then
6610 -- The following is too permissive. A more precise test should
6611 -- check that the generic actual is an ancestor subtype of the
6614 -- See code in Find_Corresponding_Spec that applies an additional
6615 -- filter to handle accidental amiguities in instances.
6617 return not Is_Generic_Actual_Type (T1)
6618 or else not Is_Generic_Actual_Type (T2)
6619 or else Scope (T1) /= Scope (T2);
6621 -- If T2 is a generic actual type it is declared as the subtype of
6622 -- the actual. If that actual is itself a subtype we need to use its
6623 -- own base type to check for compatibility.
6625 elsif Ekind (BT2) = Ekind (T2) and then BT1 = Base_Type (BT2) then
6628 elsif Ekind (BT1) = Ekind (T1) and then BT2 = Base_Type (BT1) then
6634 end Base_Types_Match;
6636 --------------------------
6637 -- Find_Designated_Type --
6638 --------------------------
6640 function Find_Designated_Type (T : Entity_Id) return Entity_Id is
6644 Desig := Directly_Designated_Type (T);
6646 if Ekind (Desig) = E_Incomplete_Type then
6648 -- If regular incomplete type, get full view if available
6650 if Present (Full_View (Desig)) then
6651 Desig := Full_View (Desig);
6653 -- If limited view of a type, get non-limited view if available,
6654 -- and check again for a regular incomplete type.
6656 elsif Present (Non_Limited_View (Desig)) then
6657 Desig := Get_Full_View (Non_Limited_View (Desig));
6662 end Find_Designated_Type;
6664 -------------------------------
6665 -- Matches_Limited_With_View --
6666 -------------------------------
6668 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean is
6670 -- In some cases a type imported through a limited_with clause, and
6671 -- its nonlimited view are both visible, for example in an anonymous
6672 -- access-to-class-wide type in a formal, or when building the body
6673 -- for a subprogram renaming after the subprogram has been frozen.
6674 -- In these cases Both entities designate the same type. In addition,
6675 -- if one of them is an actual in an instance, it may be a subtype of
6676 -- the non-limited view of the other.
6678 if From_Limited_With (T1)
6679 and then (T2 = Available_View (T1)
6680 or else Is_Subtype_Of (T2, Available_View (T1)))
6684 elsif From_Limited_With (T2)
6685 and then (T1 = Available_View (T2)
6686 or else Is_Subtype_Of (T1, Available_View (T2)))
6690 elsif From_Limited_With (T1)
6691 and then From_Limited_With (T2)
6692 and then Available_View (T1) = Available_View (T2)
6699 end Matches_Limited_With_View;
6701 -- Start of processing for Conforming_Types
6704 -- The context is an instance association for a formal access-to-
6705 -- subprogram type; the formal parameter types require mapping because
6706 -- they may denote other formal parameters of the generic unit.
6709 Type_1 := Get_Instance_Of (T1);
6710 Type_2 := Get_Instance_Of (T2);
6713 -- If one of the types is a view of the other introduced by a limited
6714 -- with clause, treat these as conforming for all purposes.
6716 if Matches_Limited_With_View (T1, T2) then
6719 elsif Base_Types_Match (Type_1, Type_2) then
6720 return Ctype <= Mode_Conformant
6721 or else Subtypes_Statically_Match (Type_1, Type_2);
6723 elsif Is_Incomplete_Or_Private_Type (Type_1)
6724 and then Present (Full_View (Type_1))
6725 and then Base_Types_Match (Full_View (Type_1), Type_2)
6727 return Ctype <= Mode_Conformant
6728 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
6730 elsif Ekind (Type_2) = E_Incomplete_Type
6731 and then Present (Full_View (Type_2))
6732 and then Base_Types_Match (Type_1, Full_View (Type_2))
6734 return Ctype <= Mode_Conformant
6735 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
6737 elsif Is_Private_Type (Type_2)
6738 and then In_Instance
6739 and then Present (Full_View (Type_2))
6740 and then Base_Types_Match (Type_1, Full_View (Type_2))
6742 return Ctype <= Mode_Conformant
6743 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
6746 -- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be
6747 -- treated recursively because they carry a signature. As far as
6748 -- conformance is concerned, convention plays no role, and either
6749 -- or both could be access to protected subprograms.
6751 Are_Anonymous_Access_To_Subprogram_Types :=
6752 Ekind_In (Type_1, E_Anonymous_Access_Subprogram_Type,
6753 E_Anonymous_Access_Protected_Subprogram_Type)
6755 Ekind_In (Type_2, E_Anonymous_Access_Subprogram_Type,
6756 E_Anonymous_Access_Protected_Subprogram_Type);
6758 -- Test anonymous access type case. For this case, static subtype
6759 -- matching is required for mode conformance (RM 6.3.1(15)). We check
6760 -- the base types because we may have built internal subtype entities
6761 -- to handle null-excluding types (see Process_Formals).
6763 if (Ekind (Base_Type (Type_1)) = E_Anonymous_Access_Type
6765 Ekind (Base_Type (Type_2)) = E_Anonymous_Access_Type)
6767 -- Ada 2005 (AI-254)
6769 or else Are_Anonymous_Access_To_Subprogram_Types
6772 Desig_1 : Entity_Id;
6773 Desig_2 : Entity_Id;
6776 -- In Ada 2005, access constant indicators must match for
6777 -- subtype conformance.
6779 if Ada_Version >= Ada_2005
6780 and then Ctype >= Subtype_Conformant
6782 Is_Access_Constant (Type_1) /= Is_Access_Constant (Type_2)
6787 Desig_1 := Find_Designated_Type (Type_1);
6788 Desig_2 := Find_Designated_Type (Type_2);
6790 -- If the context is an instance association for a formal
6791 -- access-to-subprogram type; formal access parameter designated
6792 -- types require mapping because they may denote other formal
6793 -- parameters of the generic unit.
6796 Desig_1 := Get_Instance_Of (Desig_1);
6797 Desig_2 := Get_Instance_Of (Desig_2);
6800 -- It is possible for a Class_Wide_Type to be introduced for an
6801 -- incomplete type, in which case there is a separate class_ wide
6802 -- type for the full view. The types conform if their Etypes
6803 -- conform, i.e. one may be the full view of the other. This can
6804 -- only happen in the context of an access parameter, other uses
6805 -- of an incomplete Class_Wide_Type are illegal.
6807 if Is_Class_Wide_Type (Desig_1)
6809 Is_Class_Wide_Type (Desig_2)
6813 (Etype (Base_Type (Desig_1)),
6814 Etype (Base_Type (Desig_2)), Ctype);
6816 elsif Are_Anonymous_Access_To_Subprogram_Types then
6817 if Ada_Version < Ada_2005 then
6818 return Ctype = Type_Conformant
6820 Subtypes_Statically_Match (Desig_1, Desig_2);
6822 -- We must check the conformance of the signatures themselves
6826 Conformant : Boolean;
6829 (Desig_1, Desig_2, Ctype, False, Conformant);
6835 return Base_Type (Desig_1) = Base_Type (Desig_2)
6836 and then (Ctype = Type_Conformant
6838 Subtypes_Statically_Match (Desig_1, Desig_2));
6842 -- Otherwise definitely no match
6845 if ((Ekind (Type_1) = E_Anonymous_Access_Type
6846 and then Is_Access_Type (Type_2))
6847 or else (Ekind (Type_2) = E_Anonymous_Access_Type
6848 and then Is_Access_Type (Type_1)))
6851 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
6853 May_Hide_Profile := True;
6858 end Conforming_Types;
6860 --------------------------
6861 -- Create_Extra_Formals --
6862 --------------------------
6864 procedure Create_Extra_Formals (E : Entity_Id) is
6866 First_Extra : Entity_Id := Empty;
6867 Last_Extra : Entity_Id;
6868 Formal_Type : Entity_Id;
6869 P_Formal : Entity_Id := Empty;
6871 function Add_Extra_Formal
6872 (Assoc_Entity : Entity_Id;
6875 Suffix : String) return Entity_Id;
6876 -- Add an extra formal to the current list of formals and extra formals.
6877 -- The extra formal is added to the end of the list of extra formals,
6878 -- and also returned as the result. These formals are always of mode IN.
6879 -- The new formal has the type Typ, is declared in Scope, and its name
6880 -- is given by a concatenation of the name of Assoc_Entity and Suffix.
6881 -- The following suffixes are currently used. They should not be changed
6882 -- without coordinating with CodePeer, which makes use of these to
6883 -- provide better messages.
6885 -- O denotes the Constrained bit.
6886 -- L denotes the accessibility level.
6887 -- BIP_xxx denotes an extra formal for a build-in-place function. See
6888 -- the full list in exp_ch6.BIP_Formal_Kind.
6890 ----------------------
6891 -- Add_Extra_Formal --
6892 ----------------------
6894 function Add_Extra_Formal
6895 (Assoc_Entity : Entity_Id;
6898 Suffix : String) return Entity_Id
6900 EF : constant Entity_Id :=
6901 Make_Defining_Identifier (Sloc (Assoc_Entity),
6902 Chars => New_External_Name (Chars (Assoc_Entity),
6906 -- A little optimization. Never generate an extra formal for the
6907 -- _init operand of an initialization procedure, since it could
6910 if Chars (Formal) = Name_uInit then
6914 Set_Ekind (EF, E_In_Parameter);
6915 Set_Actual_Subtype (EF, Typ);
6916 Set_Etype (EF, Typ);
6917 Set_Scope (EF, Scope);
6918 Set_Mechanism (EF, Default_Mechanism);
6919 Set_Formal_Validity (EF);
6921 if No (First_Extra) then
6923 Set_Extra_Formals (Scope, First_Extra);
6926 if Present (Last_Extra) then
6927 Set_Extra_Formal (Last_Extra, EF);
6933 end Add_Extra_Formal;
6935 -- Start of processing for Create_Extra_Formals
6938 -- We never generate extra formals if expansion is not active because we
6939 -- don't need them unless we are generating code.
6941 if not Expander_Active then
6945 -- No need to generate extra formals in interface thunks whose target
6946 -- primitive has no extra formals.
6948 if Is_Thunk (E) and then No (Extra_Formals (Thunk_Entity (E))) then
6952 -- If this is a derived subprogram then the subtypes of the parent
6953 -- subprogram's formal parameters will be used to determine the need
6954 -- for extra formals.
6956 if Is_Overloadable (E) and then Present (Alias (E)) then
6957 P_Formal := First_Formal (Alias (E));
6960 Last_Extra := Empty;
6961 Formal := First_Formal (E);
6962 while Present (Formal) loop
6963 Last_Extra := Formal;
6964 Next_Formal (Formal);
6967 -- If Extra_formals were already created, don't do it again. This
6968 -- situation may arise for subprogram types created as part of
6969 -- dispatching calls (see Expand_Dispatching_Call)
6971 if Present (Last_Extra) and then Present (Extra_Formal (Last_Extra)) then
6975 -- If the subprogram is a predefined dispatching subprogram then don't
6976 -- generate any extra constrained or accessibility level formals. In
6977 -- general we suppress these for internal subprograms (by not calling
6978 -- Freeze_Subprogram and Create_Extra_Formals at all), but internally
6979 -- generated stream attributes do get passed through because extra
6980 -- build-in-place formals are needed in some cases (limited 'Input
).
6982 if Is_Predefined_Internal_Operation
(E
) then
6983 goto Test_For_Func_Result_Extras
;
6986 Formal
:= First_Formal
(E
);
6987 while Present
(Formal
) loop
6989 -- Create extra formal for supporting the attribute 'Constrained.
6990 -- The case of a private type view without discriminants also
6991 -- requires the extra formal if the underlying type has defaulted
6994 if Ekind
(Formal
) /= E_In_Parameter
then
6995 if Present
(P_Formal
) then
6996 Formal_Type
:= Etype
(P_Formal
);
6998 Formal_Type
:= Etype
(Formal
);
7001 -- Do not produce extra formals for Unchecked_Union parameters.
7002 -- Jump directly to the end of the loop.
7004 if Is_Unchecked_Union
(Base_Type
(Formal_Type
)) then
7005 goto Skip_Extra_Formal_Generation
;
7008 if not Has_Discriminants
(Formal_Type
)
7009 and then Ekind
(Formal_Type
) in Private_Kind
7010 and then Present
(Underlying_Type
(Formal_Type
))
7012 Formal_Type
:= Underlying_Type
(Formal_Type
);
7015 -- Suppress the extra formal if formal's subtype is constrained or
7016 -- indefinite, or we're compiling for Ada 2012 and the underlying
7017 -- type is tagged and limited. In Ada 2012, a limited tagged type
7018 -- can have defaulted discriminants, but 'Constrained is required
7019 -- to return True, so the formal is never needed (see AI05-0214).
7020 -- Note that this ensures consistency of calling sequences for
7021 -- dispatching operations when some types in a class have defaults
7022 -- on discriminants and others do not (and requiring the extra
7023 -- formal would introduce distributed overhead).
7025 -- If the type does not have a completion yet, treat as prior to
7026 -- Ada 2012 for consistency.
7028 if Has_Discriminants
(Formal_Type
)
7029 and then not Is_Constrained
(Formal_Type
)
7030 and then not Is_Indefinite_Subtype
(Formal_Type
)
7031 and then (Ada_Version
< Ada_2012
7032 or else No
(Underlying_Type
(Formal_Type
))
7034 (Is_Limited_Type
(Formal_Type
)
7037 (Underlying_Type
(Formal_Type
)))))
7039 Set_Extra_Constrained
7040 (Formal
, Add_Extra_Formal
(Formal
, Standard_Boolean
, E
, "O"));
7044 -- Create extra formal for supporting accessibility checking. This
7045 -- is done for both anonymous access formals and formals of named
7046 -- access types that are marked as controlling formals. The latter
7047 -- case can occur when Expand_Dispatching_Call creates a subprogram
7048 -- type and substitutes the types of access-to-class-wide actuals
7049 -- for the anonymous access-to-specific-type of controlling formals.
7050 -- Base_Type is applied because in cases where there is a null
7051 -- exclusion the formal may have an access subtype.
7053 -- This is suppressed if we specifically suppress accessibility
7054 -- checks at the package level for either the subprogram, or the
7055 -- package in which it resides. However, we do not suppress it
7056 -- simply if the scope has accessibility checks suppressed, since
7057 -- this could cause trouble when clients are compiled with a
7058 -- different suppression setting. The explicit checks at the
7059 -- package level are safe from this point of view.
7061 if (Ekind
(Base_Type
(Etype
(Formal
))) = E_Anonymous_Access_Type
7062 or else (Is_Controlling_Formal
(Formal
)
7063 and then Is_Access_Type
(Base_Type
(Etype
(Formal
)))))
7065 (Explicit_Suppress
(E
, Accessibility_Check
)
7067 Explicit_Suppress
(Scope
(E
), Accessibility_Check
))
7070 or else Present
(Extra_Accessibility
(P_Formal
)))
7072 Set_Extra_Accessibility
7073 (Formal
, Add_Extra_Formal
(Formal
, Standard_Natural
, E
, "L"));
7076 -- This label is required when skipping extra formal generation for
7077 -- Unchecked_Union parameters.
7079 <<Skip_Extra_Formal_Generation
>>
7081 if Present
(P_Formal
) then
7082 Next_Formal
(P_Formal
);
7085 Next_Formal
(Formal
);
7088 <<Test_For_Func_Result_Extras
>>
7090 -- Ada 2012 (AI05-234): "the accessibility level of the result of a
7091 -- function call is ... determined by the point of call ...".
7093 if Needs_Result_Accessibility_Level
(E
) then
7094 Set_Extra_Accessibility_Of_Result
7095 (E
, Add_Extra_Formal
(E
, Standard_Natural
, E
, "L"));
7098 -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add
7099 -- appropriate extra formals. See type Exp_Ch6.BIP_Formal_Kind.
7101 if Ada_Version
>= Ada_2005
and then Is_Build_In_Place_Function
(E
) then
7103 Result_Subt
: constant Entity_Id
:= Etype
(E
);
7104 Full_Subt
: constant Entity_Id
:= Available_View
(Result_Subt
);
7105 Formal_Typ
: Entity_Id
;
7107 Discard
: Entity_Id
;
7108 pragma Warnings
(Off
, Discard
);
7111 -- In the case of functions with unconstrained result subtypes,
7112 -- add a 4-state formal indicating whether the return object is
7113 -- allocated by the caller (1), or should be allocated by the
7114 -- callee on the secondary stack (2), in the global heap (3), or
7115 -- in a user-defined storage pool (4). For the moment we just use
7116 -- Natural for the type of this formal. Note that this formal
7117 -- isn't usually needed in the case where the result subtype is
7118 -- constrained, but it is needed when the function has a tagged
7119 -- result, because generally such functions can be called in a
7120 -- dispatching context and such calls must be handled like calls
7121 -- to a class-wide function.
7123 if Needs_BIP_Alloc_Form
(E
) then
7126 (E
, Standard_Natural
,
7127 E
, BIP_Formal_Suffix
(BIP_Alloc_Form
));
7129 -- Add BIP_Storage_Pool, in case BIP_Alloc_Form indicates to
7130 -- use a user-defined pool. This formal is not added on
7131 -- .NET/JVM/ZFP as those targets do not support pools.
7133 if VM_Target
= No_VM
7134 and then RTE_Available
(RE_Root_Storage_Pool_Ptr
)
7138 (E
, RTE
(RE_Root_Storage_Pool_Ptr
),
7139 E
, BIP_Formal_Suffix
(BIP_Storage_Pool
));
7143 -- In the case of functions whose result type needs finalization,
7144 -- add an extra formal which represents the finalization master.
7146 if Needs_BIP_Finalization_Master
(E
) then
7149 (E
, RTE
(RE_Finalization_Master_Ptr
),
7150 E
, BIP_Formal_Suffix
(BIP_Finalization_Master
));
7153 -- When the result type contains tasks, add two extra formals: the
7154 -- master of the tasks to be created, and the caller's activation
7157 if Has_Task
(Full_Subt
) then
7160 (E
, RTE
(RE_Master_Id
),
7161 E
, BIP_Formal_Suffix
(BIP_Task_Master
));
7164 (E
, RTE
(RE_Activation_Chain_Access
),
7165 E
, BIP_Formal_Suffix
(BIP_Activation_Chain
));
7168 -- All build-in-place functions get an extra formal that will be
7169 -- passed the address of the return object within the caller.
7172 Create_Itype
(E_Anonymous_Access_Type
, E
, Scope_Id
=> Scope
(E
));
7174 Set_Directly_Designated_Type
(Formal_Typ
, Result_Subt
);
7175 Set_Etype
(Formal_Typ
, Formal_Typ
);
7176 Set_Depends_On_Private
7177 (Formal_Typ
, Has_Private_Component
(Formal_Typ
));
7178 Set_Is_Public
(Formal_Typ
, Is_Public
(Scope
(Formal_Typ
)));
7179 Set_Is_Access_Constant
(Formal_Typ
, False);
7181 -- Ada 2005 (AI-50217): Propagate the attribute that indicates
7182 -- the designated type comes from the limited view (for back-end
7185 Set_From_Limited_With
7186 (Formal_Typ
, From_Limited_With
(Result_Subt
));
7188 Layout_Type
(Formal_Typ
);
7192 (E
, Formal_Typ
, E
, BIP_Formal_Suffix
(BIP_Object_Access
));
7195 end Create_Extra_Formals
;
7197 -----------------------------
7198 -- Enter_Overloaded_Entity --
7199 -----------------------------
7201 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
7202 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
7203 C_E
: Entity_Id
:= Current_Entity
(S
);
7207 Set_Has_Homonym
(E
);
7208 Set_Has_Homonym
(S
);
7211 Set_Is_Immediately_Visible
(S
);
7212 Set_Scope
(S
, Current_Scope
);
7214 -- Chain new entity if front of homonym in current scope, so that
7215 -- homonyms are contiguous.
7217 if Present
(E
) and then E
/= C_E
then
7218 while Homonym
(C_E
) /= E
loop
7219 C_E
:= Homonym
(C_E
);
7222 Set_Homonym
(C_E
, S
);
7226 Set_Current_Entity
(S
);
7231 if Is_Inherited_Operation
(S
) then
7232 Append_Inherited_Subprogram
(S
);
7234 Append_Entity
(S
, Current_Scope
);
7237 Set_Public_Status
(S
);
7239 if Debug_Flag_E
then
7240 Write_Str
("New overloaded entity chain: ");
7241 Write_Name
(Chars
(S
));
7244 while Present
(E
) loop
7245 Write_Str
(" "); Write_Int
(Int
(E
));
7252 -- Generate warning for hiding
7255 and then Comes_From_Source
(S
)
7256 and then In_Extended_Main_Source_Unit
(S
)
7263 -- Warn unless genuine overloading. Do not emit warning on
7264 -- hiding predefined operators in Standard (these are either an
7265 -- (artifact of our implicit declarations, or simple noise) but
7266 -- keep warning on a operator defined on a local subtype, because
7267 -- of the real danger that different operators may be applied in
7268 -- various parts of the program.
7270 -- Note that if E and S have the same scope, there is never any
7271 -- hiding. Either the two conflict, and the program is illegal,
7272 -- or S is overriding an implicit inherited subprogram.
7274 if Scope
(E
) /= Scope
(S
)
7275 and then (not Is_Overloadable
(E
)
7276 or else Subtype_Conformant
(E
, S
))
7277 and then (Is_Immediately_Visible
(E
)
7279 Is_Potentially_Use_Visible
(S
))
7281 if Scope
(E
) /= Standard_Standard
then
7282 Error_Msg_Sloc
:= Sloc
(E
);
7283 Error_Msg_N
("declaration of & hides one #?h?", S
);
7285 elsif Nkind
(S
) = N_Defining_Operator_Symbol
7287 Scope
(Base_Type
(Etype
(First_Formal
(S
)))) /= Scope
(S
)
7290 ("declaration of & hides predefined operator?h?", S
);
7295 end Enter_Overloaded_Entity
;
7297 -----------------------------
7298 -- Check_Untagged_Equality --
7299 -----------------------------
7301 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
) is
7302 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Eq_Op
));
7303 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Eq_Op
);
7307 -- This check applies only if we have a subprogram declaration with an
7308 -- untagged record type.
7310 if Nkind
(Decl
) /= N_Subprogram_Declaration
7311 or else not Is_Record_Type
(Typ
)
7312 or else Is_Tagged_Type
(Typ
)
7317 -- In Ada 2012 case, we will output errors or warnings depending on
7318 -- the setting of debug flag -gnatd.E.
7320 if Ada_Version
>= Ada_2012
then
7321 Error_Msg_Warn
:= Debug_Flag_Dot_EE
;
7323 -- In earlier versions of Ada, nothing to do unless we are warning on
7324 -- Ada 2012 incompatibilities (Warn_On_Ada_2012_Incompatibility set).
7327 if not Warn_On_Ada_2012_Compatibility
then
7332 -- Cases where the type has already been frozen
7334 if Is_Frozen
(Typ
) then
7336 -- If the type is not declared in a package, or if we are in the body
7337 -- of the package or in some other scope, the new operation is not
7338 -- primitive, and therefore legal, though suspicious. Should we
7339 -- generate a warning in this case ???
7341 if Ekind
(Scope
(Typ
)) /= E_Package
7342 or else Scope
(Typ
) /= Current_Scope
7346 -- If the type is a generic actual (sub)type, the operation is not
7347 -- primitive either because the base type is declared elsewhere.
7349 elsif Is_Generic_Actual_Type
(Typ
) then
7352 -- Here we have a definite error of declaration after freezing
7355 if Ada_Version
>= Ada_2012
then
7357 ("equality operator must be declared before type & is "
7358 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)<<", Eq_Op
, Typ
);
7360 -- In Ada 2012 mode with error turned to warning, output one
7361 -- more warning to warn that the equality operation may not
7362 -- compose. This is the consequence of ignoring the error.
7364 if Error_Msg_Warn
then
7365 Error_Msg_N
("\equality operation may not compose??", Eq_Op
);
7370 ("equality operator must be declared before type& is "
7371 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)?y?", Eq_Op
, Typ
);
7374 -- If we are in the package body, we could just move the
7375 -- declaration to the package spec, so add a message saying that.
7377 if In_Package_Body
(Scope
(Typ
)) then
7378 if Ada_Version
>= Ada_2012
then
7380 ("\move declaration to package spec<<", Eq_Op
);
7383 ("\move declaration to package spec (Ada 2012)?y?", Eq_Op
);
7386 -- Otherwise try to find the freezing point
7389 Obj_Decl
:= Next
(Parent
(Typ
));
7390 while Present
(Obj_Decl
) and then Obj_Decl
/= Decl
loop
7391 if Nkind
(Obj_Decl
) = N_Object_Declaration
7392 and then Etype
(Defining_Identifier
(Obj_Decl
)) = Typ
7394 -- Freezing point, output warnings
7396 if Ada_Version
>= Ada_2012
then
7398 ("type& is frozen by declaration??", Obj_Decl
, Typ
);
7400 ("\an equality operator cannot be declared after "
7405 ("type& is frozen by declaration (Ada 2012)?y?",
7408 ("\an equality operator cannot be declared after "
7409 & "this point (Ada 2012)?y?",
7421 -- Here if type is not frozen yet. It is illegal to have a primitive
7422 -- equality declared in the private part if the type is visible.
7424 elsif not In_Same_List
(Parent
(Typ
), Decl
)
7425 and then not Is_Limited_Type
(Typ
)
7427 -- Shouldn't we give an RM reference here???
7429 if Ada_Version
>= Ada_2012
then
7431 ("equality operator appears too late<<", Eq_Op
);
7434 ("equality operator appears too late (Ada 2012)?y?", Eq_Op
);
7437 -- No error detected
7442 end Check_Untagged_Equality
;
7444 -----------------------------
7445 -- Find_Corresponding_Spec --
7446 -----------------------------
7448 function Find_Corresponding_Spec
7450 Post_Error
: Boolean := True) return Entity_Id
7452 Spec
: constant Node_Id
:= Specification
(N
);
7453 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
7457 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean;
7458 -- Even if fully conformant, a body may depend on a generic actual when
7459 -- the spec does not, or vice versa, in which case they were distinct
7460 -- entities in the generic.
7462 -------------------------------
7463 -- Different_Generic_Profile --
7464 -------------------------------
7466 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean is
7469 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean;
7470 -- Check that the types of corresponding formals have the same
7471 -- generic actual if any. We have to account for subtypes of a
7472 -- generic formal, declared between a spec and a body, which may
7473 -- appear distinct in an instance but matched in the generic, and
7474 -- the subtype may be used either in the spec or the body of the
7475 -- subprogram being checked.
7477 -------------------------
7478 -- Same_Generic_Actual --
7479 -------------------------
7481 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean is
7483 function Is_Declared_Subtype
(S1
, S2
: Entity_Id
) return Boolean;
7484 -- Predicate to check whether S1 is a subtype of S2 in the source
7487 -------------------------
7488 -- Is_Declared_Subtype --
7489 -------------------------
7491 function Is_Declared_Subtype
(S1
, S2
: Entity_Id
) return Boolean is
7493 return Comes_From_Source
(Parent
(S1
))
7494 and then Nkind
(Parent
(S1
)) = N_Subtype_Declaration
7495 and then Is_Entity_Name
(Subtype_Indication
(Parent
(S1
)))
7496 and then Entity
(Subtype_Indication
(Parent
(S1
))) = S2
;
7497 end Is_Declared_Subtype
;
7499 -- Start of processing for Same_Generic_Actual
7502 return Is_Generic_Actual_Type
(T1
) = Is_Generic_Actual_Type
(T2
)
7503 or else Is_Declared_Subtype
(T1
, T2
)
7504 or else Is_Declared_Subtype
(T2
, T1
);
7505 end Same_Generic_Actual
;
7507 -- Start of processing for Different_Generic_Profile
7510 if not In_Instance
then
7513 elsif Ekind
(E
) = E_Function
7514 and then not Same_Generic_Actual
(Etype
(E
), Etype
(Designator
))
7519 F1
:= First_Formal
(Designator
);
7520 F2
:= First_Formal
(E
);
7521 while Present
(F1
) loop
7522 if not Same_Generic_Actual
(Etype
(F1
), Etype
(F2
)) then
7531 end Different_Generic_Profile
;
7533 -- Start of processing for Find_Corresponding_Spec
7536 E
:= Current_Entity
(Designator
);
7537 while Present
(E
) loop
7539 -- We are looking for a matching spec. It must have the same scope,
7540 -- and the same name, and either be type conformant, or be the case
7541 -- of a library procedure spec and its body (which belong to one
7542 -- another regardless of whether they are type conformant or not).
7544 if Scope
(E
) = Current_Scope
then
7545 if Current_Scope
= Standard_Standard
7546 or else (Ekind
(E
) = Ekind
(Designator
)
7547 and then Type_Conformant
(E
, Designator
))
7549 -- Within an instantiation, we know that spec and body are
7550 -- subtype conformant, because they were subtype conformant in
7551 -- the generic. We choose the subtype-conformant entity here as
7552 -- well, to resolve spurious ambiguities in the instance that
7553 -- were not present in the generic (i.e. when two different
7554 -- types are given the same actual). If we are looking for a
7555 -- spec to match a body, full conformance is expected.
7559 -- Inherit the convention and "ghostness" of the matching
7560 -- spec to ensure proper full and subtype conformance.
7562 Set_Convention
(Designator
, Convention
(E
));
7564 if Is_Ghost_Entity
(E
) then
7565 Set_Is_Ghost_Entity
(Designator
);
7568 -- Skip past subprogram bodies and subprogram renamings that
7569 -- may appear to have a matching spec, but that aren't fully
7570 -- conformant with it. That can occur in cases where an
7571 -- actual type causes unrelated homographs in the instance.
7573 if Nkind_In
(N
, N_Subprogram_Body
,
7574 N_Subprogram_Renaming_Declaration
)
7575 and then Present
(Homonym
(E
))
7576 and then not Fully_Conformant
(Designator
, E
)
7580 elsif not Subtype_Conformant
(Designator
, E
) then
7583 elsif Different_Generic_Profile
(E
) then
7588 -- Ada 2012 (AI05-0165): For internally generated bodies of
7589 -- null procedures locate the internally generated spec. We
7590 -- enforce mode conformance since a tagged type may inherit
7591 -- from interfaces several null primitives which differ only
7592 -- in the mode of the formals.
7594 if not (Comes_From_Source
(E
))
7595 and then Is_Null_Procedure
(E
)
7596 and then not Mode_Conformant
(Designator
, E
)
7600 -- For null procedures coming from source that are completions,
7601 -- analysis of the generated body will establish the link.
7603 elsif Comes_From_Source
(E
)
7604 and then Nkind
(Spec
) = N_Procedure_Specification
7605 and then Null_Present
(Spec
)
7609 elsif not Has_Completion
(E
) then
7610 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
7611 Set_Corresponding_Spec
(N
, E
);
7614 Set_Has_Completion
(E
);
7617 elsif Nkind
(Parent
(N
)) = N_Subunit
then
7619 -- If this is the proper body of a subunit, the completion
7620 -- flag is set when analyzing the stub.
7624 -- If E is an internal function with a controlling result that
7625 -- was created for an operation inherited by a null extension,
7626 -- it may be overridden by a body without a previous spec (one
7627 -- more reason why these should be shunned). In that case we
7628 -- remove the generated body if present, because the current
7629 -- one is the explicit overriding.
7631 elsif Ekind
(E
) = E_Function
7632 and then Ada_Version
>= Ada_2005
7633 and then not Comes_From_Source
(E
)
7634 and then Has_Controlling_Result
(E
)
7635 and then Is_Null_Extension
(Etype
(E
))
7636 and then Comes_From_Source
(Spec
)
7638 Set_Has_Completion
(E
, False);
7641 and then Nkind
(Parent
(E
)) = N_Function_Specification
7644 (Unit_Declaration_Node
7645 (Corresponding_Body
(Unit_Declaration_Node
(E
))));
7649 -- If expansion is disabled, or if the wrapper function has
7650 -- not been generated yet, this a late body overriding an
7651 -- inherited operation, or it is an overriding by some other
7652 -- declaration before the controlling result is frozen. In
7653 -- either case this is a declaration of a new entity.
7659 -- If the body already exists, then this is an error unless
7660 -- the previous declaration is the implicit declaration of a
7661 -- derived subprogram. It is also legal for an instance to
7662 -- contain type conformant overloadable declarations (but the
7663 -- generic declaration may not), per 8.3(26/2).
7665 elsif No
(Alias
(E
))
7666 and then not Is_Intrinsic_Subprogram
(E
)
7667 and then not In_Instance
7670 Error_Msg_Sloc
:= Sloc
(E
);
7672 if Is_Imported
(E
) then
7674 ("body not allowed for imported subprogram & declared#",
7677 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
7681 -- Child units cannot be overloaded, so a conformance mismatch
7682 -- between body and a previous spec is an error.
7684 elsif Is_Child_Unit
(E
)
7686 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
7688 Nkind
(Parent
(Unit_Declaration_Node
(Designator
))) =
7693 ("body of child unit does not match previous declaration", N
);
7701 -- On exit, we know that no previous declaration of subprogram exists
7704 end Find_Corresponding_Spec
;
7706 ----------------------
7707 -- Fully_Conformant --
7708 ----------------------
7710 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
7713 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
7715 end Fully_Conformant
;
7717 ----------------------------------
7718 -- Fully_Conformant_Expressions --
7719 ----------------------------------
7721 function Fully_Conformant_Expressions
7722 (Given_E1
: Node_Id
;
7723 Given_E2
: Node_Id
) return Boolean
7725 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
7726 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
7727 -- We always test conformance on original nodes, since it is possible
7728 -- for analysis and/or expansion to make things look as though they
7729 -- conform when they do not, e.g. by converting 1+2 into 3.
7731 function FCE
(Given_E1
, Given_E2
: Node_Id
) return Boolean
7732 renames Fully_Conformant_Expressions
;
7734 function FCL
(L1
, L2
: List_Id
) return Boolean;
7735 -- Compare elements of two lists for conformance. Elements have to be
7736 -- conformant, and actuals inserted as default parameters do not match
7737 -- explicit actuals with the same value.
7739 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean;
7740 -- Compare an operator node with a function call
7746 function FCL
(L1
, L2
: List_Id
) return Boolean is
7750 if L1
= No_List
then
7756 if L2
= No_List
then
7762 -- Compare two lists, skipping rewrite insertions (we want to compare
7763 -- the original trees, not the expanded versions).
7766 if Is_Rewrite_Insertion
(N1
) then
7768 elsif Is_Rewrite_Insertion
(N2
) then
7774 elsif not FCE
(N1
, N2
) then
7787 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean is
7788 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
7793 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
7798 Act
:= First
(Actuals
);
7800 if Nkind
(Op_Node
) in N_Binary_Op
then
7801 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
7808 return Present
(Act
)
7809 and then FCE
(Right_Opnd
(Op_Node
), Act
)
7810 and then No
(Next
(Act
));
7814 -- Start of processing for Fully_Conformant_Expressions
7817 -- Non-conformant if paren count does not match. Note: if some idiot
7818 -- complains that we don't do this right for more than 3 levels of
7819 -- parentheses, they will be treated with the respect they deserve.
7821 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
7824 -- If same entities are referenced, then they are conformant even if
7825 -- they have different forms (RM 8.3.1(19-20)).
7827 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
7828 if Present
(Entity
(E1
)) then
7829 return Entity
(E1
) = Entity
(E2
)
7830 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
7831 and then Ekind
(Entity
(E1
)) = E_Discriminant
7832 and then Ekind
(Entity
(E2
)) = E_In_Parameter
);
7834 elsif Nkind
(E1
) = N_Expanded_Name
7835 and then Nkind
(E2
) = N_Expanded_Name
7836 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
7837 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
7839 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
7842 -- Identifiers in component associations don't always have
7843 -- entities, but their names must conform.
7845 return Nkind
(E1
) = N_Identifier
7846 and then Nkind
(E2
) = N_Identifier
7847 and then Chars
(E1
) = Chars
(E2
);
7850 elsif Nkind
(E1
) = N_Character_Literal
7851 and then Nkind
(E2
) = N_Expanded_Name
7853 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
7854 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
7856 elsif Nkind
(E2
) = N_Character_Literal
7857 and then Nkind
(E1
) = N_Expanded_Name
7859 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
7860 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
7862 elsif Nkind
(E1
) in N_Op
and then Nkind
(E2
) = N_Function_Call
then
7863 return FCO
(E1
, E2
);
7865 elsif Nkind
(E2
) in N_Op
and then Nkind
(E1
) = N_Function_Call
then
7866 return FCO
(E2
, E1
);
7868 -- Otherwise we must have the same syntactic entity
7870 elsif Nkind
(E1
) /= Nkind
(E2
) then
7873 -- At this point, we specialize by node type
7880 FCL
(Expressions
(E1
), Expressions
(E2
))
7882 FCL
(Component_Associations
(E1
),
7883 Component_Associations
(E2
));
7886 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
7888 Nkind
(Expression
(E2
)) = N_Qualified_Expression
7890 return FCE
(Expression
(E1
), Expression
(E2
));
7892 -- Check that the subtype marks and any constraints
7897 Indic1
: constant Node_Id
:= Expression
(E1
);
7898 Indic2
: constant Node_Id
:= Expression
(E2
);
7903 if Nkind
(Indic1
) /= N_Subtype_Indication
then
7905 Nkind
(Indic2
) /= N_Subtype_Indication
7906 and then Entity
(Indic1
) = Entity
(Indic2
);
7908 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
7910 Nkind
(Indic1
) /= N_Subtype_Indication
7911 and then Entity
(Indic1
) = Entity
(Indic2
);
7914 if Entity
(Subtype_Mark
(Indic1
)) /=
7915 Entity
(Subtype_Mark
(Indic2
))
7920 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
7921 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
7922 while Present
(Elt1
) and then Present
(Elt2
) loop
7923 if not FCE
(Elt1
, Elt2
) then
7936 when N_Attribute_Reference
=>
7938 Attribute_Name
(E1
) = Attribute_Name
(E2
)
7939 and then FCL
(Expressions
(E1
), Expressions
(E2
));
7943 Entity
(E1
) = Entity
(E2
)
7944 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
7945 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
7947 when N_Short_Circuit | N_Membership_Test
=>
7949 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
7951 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
7953 when N_Case_Expression
=>
7959 if not FCE
(Expression
(E1
), Expression
(E2
)) then
7963 Alt1
:= First
(Alternatives
(E1
));
7964 Alt2
:= First
(Alternatives
(E2
));
7966 if Present
(Alt1
) /= Present
(Alt2
) then
7968 elsif No
(Alt1
) then
7972 if not FCE
(Expression
(Alt1
), Expression
(Alt2
))
7973 or else not FCL
(Discrete_Choices
(Alt1
),
7974 Discrete_Choices
(Alt2
))
7985 when N_Character_Literal
=>
7987 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
7989 when N_Component_Association
=>
7991 FCL
(Choices
(E1
), Choices
(E2
))
7993 FCE
(Expression
(E1
), Expression
(E2
));
7995 when N_Explicit_Dereference
=>
7997 FCE
(Prefix
(E1
), Prefix
(E2
));
7999 when N_Extension_Aggregate
=>
8001 FCL
(Expressions
(E1
), Expressions
(E2
))
8002 and then Null_Record_Present
(E1
) =
8003 Null_Record_Present
(E2
)
8004 and then FCL
(Component_Associations
(E1
),
8005 Component_Associations
(E2
));
8007 when N_Function_Call
=>
8009 FCE
(Name
(E1
), Name
(E2
))
8011 FCL
(Parameter_Associations
(E1
),
8012 Parameter_Associations
(E2
));
8014 when N_If_Expression
=>
8016 FCL
(Expressions
(E1
), Expressions
(E2
));
8018 when N_Indexed_Component
=>
8020 FCE
(Prefix
(E1
), Prefix
(E2
))
8022 FCL
(Expressions
(E1
), Expressions
(E2
));
8024 when N_Integer_Literal
=>
8025 return (Intval
(E1
) = Intval
(E2
));
8030 when N_Operator_Symbol
=>
8032 Chars
(E1
) = Chars
(E2
);
8034 when N_Others_Choice
=>
8037 when N_Parameter_Association
=>
8039 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
8040 and then FCE
(Explicit_Actual_Parameter
(E1
),
8041 Explicit_Actual_Parameter
(E2
));
8043 when N_Qualified_Expression
=>
8045 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
8047 FCE
(Expression
(E1
), Expression
(E2
));
8049 when N_Quantified_Expression
=>
8050 if not FCE
(Condition
(E1
), Condition
(E2
)) then
8054 if Present
(Loop_Parameter_Specification
(E1
))
8055 and then Present
(Loop_Parameter_Specification
(E2
))
8058 L1
: constant Node_Id
:=
8059 Loop_Parameter_Specification
(E1
);
8060 L2
: constant Node_Id
:=
8061 Loop_Parameter_Specification
(E2
);
8065 Reverse_Present
(L1
) = Reverse_Present
(L2
)
8067 FCE
(Defining_Identifier
(L1
),
8068 Defining_Identifier
(L2
))
8070 FCE
(Discrete_Subtype_Definition
(L1
),
8071 Discrete_Subtype_Definition
(L2
));
8074 elsif Present
(Iterator_Specification
(E1
))
8075 and then Present
(Iterator_Specification
(E2
))
8078 I1
: constant Node_Id
:= Iterator_Specification
(E1
);
8079 I2
: constant Node_Id
:= Iterator_Specification
(E2
);
8083 FCE
(Defining_Identifier
(I1
),
8084 Defining_Identifier
(I2
))
8086 Of_Present
(I1
) = Of_Present
(I2
)
8088 Reverse_Present
(I1
) = Reverse_Present
(I2
)
8089 and then FCE
(Name
(I1
), Name
(I2
))
8090 and then FCE
(Subtype_Indication
(I1
),
8091 Subtype_Indication
(I2
));
8094 -- The quantified expressions used different specifications to
8095 -- walk their respective ranges.
8103 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
8105 FCE
(High_Bound
(E1
), High_Bound
(E2
));
8107 when N_Real_Literal
=>
8108 return (Realval
(E1
) = Realval
(E2
));
8110 when N_Selected_Component
=>
8112 FCE
(Prefix
(E1
), Prefix
(E2
))
8114 FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
8118 FCE
(Prefix
(E1
), Prefix
(E2
))
8120 FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
8122 when N_String_Literal
=>
8124 S1
: constant String_Id
:= Strval
(E1
);
8125 S2
: constant String_Id
:= Strval
(E2
);
8126 L1
: constant Nat
:= String_Length
(S1
);
8127 L2
: constant Nat
:= String_Length
(S2
);
8134 for J
in 1 .. L1
loop
8135 if Get_String_Char
(S1
, J
) /=
8136 Get_String_Char
(S2
, J
)
8146 when N_Type_Conversion
=>
8148 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
8150 FCE
(Expression
(E1
), Expression
(E2
));
8154 Entity
(E1
) = Entity
(E2
)
8156 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
8158 when N_Unchecked_Type_Conversion
=>
8160 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
8162 FCE
(Expression
(E1
), Expression
(E2
));
8164 -- All other node types cannot appear in this context. Strictly
8165 -- we should raise a fatal internal error. Instead we just ignore
8166 -- the nodes. This means that if anyone makes a mistake in the
8167 -- expander and mucks an expression tree irretrievably, the result
8168 -- will be a failure to detect a (probably very obscure) case
8169 -- of non-conformance, which is better than bombing on some
8170 -- case where two expressions do in fact conform.
8177 end Fully_Conformant_Expressions
;
8179 ----------------------------------------
8180 -- Fully_Conformant_Discrete_Subtypes --
8181 ----------------------------------------
8183 function Fully_Conformant_Discrete_Subtypes
8184 (Given_S1
: Node_Id
;
8185 Given_S2
: Node_Id
) return Boolean
8187 S1
: constant Node_Id
:= Original_Node
(Given_S1
);
8188 S2
: constant Node_Id
:= Original_Node
(Given_S2
);
8190 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean;
8191 -- Special-case for a bound given by a discriminant, which in the body
8192 -- is replaced with the discriminal of the enclosing type.
8194 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean;
8195 -- Check both bounds
8197 -----------------------
8198 -- Conforming_Bounds --
8199 -----------------------
8201 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean is
8203 if Is_Entity_Name
(B1
)
8204 and then Is_Entity_Name
(B2
)
8205 and then Ekind
(Entity
(B1
)) = E_Discriminant
8207 return Chars
(B1
) = Chars
(B2
);
8210 return Fully_Conformant_Expressions
(B1
, B2
);
8212 end Conforming_Bounds
;
8214 -----------------------
8215 -- Conforming_Ranges --
8216 -----------------------
8218 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean is
8221 Conforming_Bounds
(Low_Bound
(R1
), Low_Bound
(R2
))
8223 Conforming_Bounds
(High_Bound
(R1
), High_Bound
(R2
));
8224 end Conforming_Ranges
;
8226 -- Start of processing for Fully_Conformant_Discrete_Subtypes
8229 if Nkind
(S1
) /= Nkind
(S2
) then
8232 elsif Is_Entity_Name
(S1
) then
8233 return Entity
(S1
) = Entity
(S2
);
8235 elsif Nkind
(S1
) = N_Range
then
8236 return Conforming_Ranges
(S1
, S2
);
8238 elsif Nkind
(S1
) = N_Subtype_Indication
then
8240 Entity
(Subtype_Mark
(S1
)) = Entity
(Subtype_Mark
(S2
))
8243 (Range_Expression
(Constraint
(S1
)),
8244 Range_Expression
(Constraint
(S2
)));
8248 end Fully_Conformant_Discrete_Subtypes
;
8250 --------------------
8251 -- Install_Entity --
8252 --------------------
8254 procedure Install_Entity
(E
: Entity_Id
) is
8255 Prev
: constant Entity_Id
:= Current_Entity
(E
);
8257 Set_Is_Immediately_Visible
(E
);
8258 Set_Current_Entity
(E
);
8259 Set_Homonym
(E
, Prev
);
8262 ---------------------
8263 -- Install_Formals --
8264 ---------------------
8266 procedure Install_Formals
(Id
: Entity_Id
) is
8269 F
:= First_Formal
(Id
);
8270 while Present
(F
) loop
8274 end Install_Formals
;
8276 -----------------------------
8277 -- Is_Interface_Conformant --
8278 -----------------------------
8280 function Is_Interface_Conformant
8281 (Tagged_Type
: Entity_Id
;
8282 Iface_Prim
: Entity_Id
;
8283 Prim
: Entity_Id
) return Boolean
8285 -- The operation may in fact be an inherited (implicit) operation
8286 -- rather than the original interface primitive, so retrieve the
8287 -- ultimate ancestor.
8289 Iface
: constant Entity_Id
:=
8290 Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
));
8291 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Prim
);
8293 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
;
8294 -- Return the controlling formal of Prim
8296 ------------------------
8297 -- Controlling_Formal --
8298 ------------------------
8300 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
is
8304 E
:= First_Entity
(Prim
);
8305 while Present
(E
) loop
8306 if Is_Formal
(E
) and then Is_Controlling_Formal
(E
) then
8314 end Controlling_Formal
;
8318 Iface_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Iface_Prim
);
8319 Prim_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Prim
);
8321 -- Start of processing for Is_Interface_Conformant
8324 pragma Assert
(Is_Subprogram
(Iface_Prim
)
8325 and then Is_Subprogram
(Prim
)
8326 and then Is_Dispatching_Operation
(Iface_Prim
)
8327 and then Is_Dispatching_Operation
(Prim
));
8329 pragma Assert
(Is_Interface
(Iface
)
8330 or else (Present
(Alias
(Iface_Prim
))
8333 (Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
)))));
8335 if Prim
= Iface_Prim
8336 or else not Is_Subprogram
(Prim
)
8337 or else Ekind
(Prim
) /= Ekind
(Iface_Prim
)
8338 or else not Is_Dispatching_Operation
(Prim
)
8339 or else Scope
(Prim
) /= Scope
(Tagged_Type
)
8341 or else Base_Type
(Typ
) /= Base_Type
(Tagged_Type
)
8342 or else not Primitive_Names_Match
(Iface_Prim
, Prim
)
8346 -- The mode of the controlling formals must match
8348 elsif Present
(Iface_Ctrl_F
)
8349 and then Present
(Prim_Ctrl_F
)
8350 and then Ekind
(Iface_Ctrl_F
) /= Ekind
(Prim_Ctrl_F
)
8354 -- Case of a procedure, or a function whose result type matches the
8355 -- result type of the interface primitive, or a function that has no
8356 -- controlling result (I or access I).
8358 elsif Ekind
(Iface_Prim
) = E_Procedure
8359 or else Etype
(Prim
) = Etype
(Iface_Prim
)
8360 or else not Has_Controlling_Result
(Prim
)
8362 return Type_Conformant
8363 (Iface_Prim
, Prim
, Skip_Controlling_Formals
=> True);
8365 -- Case of a function returning an interface, or an access to one. Check
8366 -- that the return types correspond.
8368 elsif Implements_Interface
(Typ
, Iface
) then
8369 if (Ekind
(Etype
(Prim
)) = E_Anonymous_Access_Type
)
8371 (Ekind
(Etype
(Iface_Prim
)) = E_Anonymous_Access_Type
)
8376 Type_Conformant
(Prim
, Ultimate_Alias
(Iface_Prim
),
8377 Skip_Controlling_Formals
=> True);
8383 end Is_Interface_Conformant
;
8385 ---------------------------------
8386 -- Is_Non_Overriding_Operation --
8387 ---------------------------------
8389 function Is_Non_Overriding_Operation
8390 (Prev_E
: Entity_Id
;
8391 New_E
: Entity_Id
) return Boolean
8395 G_Typ
: Entity_Id
:= Empty
;
8397 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
8398 -- If F_Type is a derived type associated with a generic actual subtype,
8399 -- then return its Generic_Parent_Type attribute, else return Empty.
8401 function Types_Correspond
8402 (P_Type
: Entity_Id
;
8403 N_Type
: Entity_Id
) return Boolean;
8404 -- Returns true if and only if the types (or designated types in the
8405 -- case of anonymous access types) are the same or N_Type is derived
8406 -- directly or indirectly from P_Type.
8408 -----------------------------
8409 -- Get_Generic_Parent_Type --
8410 -----------------------------
8412 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
8418 if Is_Derived_Type
(F_Typ
)
8419 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
8421 -- The tree must be traversed to determine the parent subtype in
8422 -- the generic unit, which unfortunately isn't always available
8423 -- via semantic attributes. ??? (Note: The use of Original_Node
8424 -- is needed for cases where a full derived type has been
8427 Defn
:= Type_Definition
(Original_Node
(Parent
(F_Typ
)));
8428 if Nkind
(Defn
) = N_Derived_Type_Definition
then
8429 Indic
:= Subtype_Indication
(Defn
);
8431 if Nkind
(Indic
) = N_Subtype_Indication
then
8432 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
8434 G_Typ
:= Entity
(Indic
);
8437 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
8438 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
8440 return Generic_Parent_Type
(Parent
(G_Typ
));
8446 end Get_Generic_Parent_Type
;
8448 ----------------------
8449 -- Types_Correspond --
8450 ----------------------
8452 function Types_Correspond
8453 (P_Type
: Entity_Id
;
8454 N_Type
: Entity_Id
) return Boolean
8456 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
8457 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
8460 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
8461 Prev_Type
:= Designated_Type
(Prev_Type
);
8464 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
8465 New_Type
:= Designated_Type
(New_Type
);
8468 if Prev_Type
= New_Type
then
8471 elsif not Is_Class_Wide_Type
(New_Type
) then
8472 while Etype
(New_Type
) /= New_Type
loop
8473 New_Type
:= Etype
(New_Type
);
8474 if New_Type
= Prev_Type
then
8480 end Types_Correspond
;
8482 -- Start of processing for Is_Non_Overriding_Operation
8485 -- In the case where both operations are implicit derived subprograms
8486 -- then neither overrides the other. This can only occur in certain
8487 -- obscure cases (e.g., derivation from homographs created in a generic
8490 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
8493 elsif Ekind
(Current_Scope
) = E_Package
8494 and then Is_Generic_Instance
(Current_Scope
)
8495 and then In_Private_Part
(Current_Scope
)
8496 and then Comes_From_Source
(New_E
)
8498 -- We examine the formals and result type of the inherited operation,
8499 -- to determine whether their type is derived from (the instance of)
8500 -- a generic type. The first such formal or result type is the one
8503 Formal
:= First_Formal
(Prev_E
);
8504 while Present
(Formal
) loop
8505 F_Typ
:= Base_Type
(Etype
(Formal
));
8507 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
8508 F_Typ
:= Designated_Type
(F_Typ
);
8511 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
8512 exit when Present
(G_Typ
);
8514 Next_Formal
(Formal
);
8517 if No
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
8518 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
8525 -- If the generic type is a private type, then the original operation
8526 -- was not overriding in the generic, because there was no primitive
8527 -- operation to override.
8529 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
8530 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
8531 N_Formal_Private_Type_Definition
8535 -- The generic parent type is the ancestor of a formal derived
8536 -- type declaration. We need to check whether it has a primitive
8537 -- operation that should be overridden by New_E in the generic.
8541 P_Formal
: Entity_Id
;
8542 N_Formal
: Entity_Id
;
8546 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
8549 while Present
(Prim_Elt
) loop
8550 P_Prim
:= Node
(Prim_Elt
);
8552 if Chars
(P_Prim
) = Chars
(New_E
)
8553 and then Ekind
(P_Prim
) = Ekind
(New_E
)
8555 P_Formal
:= First_Formal
(P_Prim
);
8556 N_Formal
:= First_Formal
(New_E
);
8557 while Present
(P_Formal
) and then Present
(N_Formal
) loop
8558 P_Typ
:= Etype
(P_Formal
);
8559 N_Typ
:= Etype
(N_Formal
);
8561 if not Types_Correspond
(P_Typ
, N_Typ
) then
8565 Next_Entity
(P_Formal
);
8566 Next_Entity
(N_Formal
);
8569 -- Found a matching primitive operation belonging to the
8570 -- formal ancestor type, so the new subprogram is
8574 and then No
(N_Formal
)
8575 and then (Ekind
(New_E
) /= E_Function
8578 (Etype
(P_Prim
), Etype
(New_E
)))
8584 Next_Elmt
(Prim_Elt
);
8587 -- If no match found, then the new subprogram does not override
8588 -- in the generic (nor in the instance).
8590 -- If the type in question is not abstract, and the subprogram
8591 -- is, this will be an error if the new operation is in the
8592 -- private part of the instance. Emit a warning now, which will
8593 -- make the subsequent error message easier to understand.
8595 if not Is_Abstract_Type
(F_Typ
)
8596 and then Is_Abstract_Subprogram
(Prev_E
)
8597 and then In_Private_Part
(Current_Scope
)
8599 Error_Msg_Node_2
:= F_Typ
;
8601 ("private operation& in generic unit does not override "
8602 & "any primitive operation of& (RM 12.3 (18))??",
8612 end Is_Non_Overriding_Operation
;
8614 -------------------------------------
8615 -- List_Inherited_Pre_Post_Aspects --
8616 -------------------------------------
8618 procedure List_Inherited_Pre_Post_Aspects
(E
: Entity_Id
) is
8620 if Opt
.List_Inherited_Aspects
8621 and then Is_Subprogram_Or_Generic_Subprogram
(E
)
8624 Inherited
: constant Subprogram_List
:= Inherited_Subprograms
(E
);
8628 for J
in Inherited
'Range loop
8629 P
:= Pre_Post_Conditions
(Contract
(Inherited
(J
)));
8630 while Present
(P
) loop
8631 Error_Msg_Sloc
:= Sloc
(P
);
8633 if Class_Present
(P
) and then not Split_PPC
(P
) then
8634 if Pragma_Name
(P
) = Name_Precondition
then
8635 Error_Msg_N
("info: & inherits `Pre''Class` aspect "
8638 Error_Msg_N
("info: & inherits `Post''Class` aspect "
8643 P
:= Next_Pragma
(P
);
8648 end List_Inherited_Pre_Post_Aspects
;
8650 ------------------------------
8651 -- Make_Inequality_Operator --
8652 ------------------------------
8654 -- S is the defining identifier of an equality operator. We build a
8655 -- subprogram declaration with the right signature. This operation is
8656 -- intrinsic, because it is always expanded as the negation of the
8657 -- call to the equality function.
8659 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
8660 Loc
: constant Source_Ptr
:= Sloc
(S
);
8663 Op_Name
: Entity_Id
;
8665 FF
: constant Entity_Id
:= First_Formal
(S
);
8666 NF
: constant Entity_Id
:= Next_Formal
(FF
);
8669 -- Check that equality was properly defined, ignore call if not
8676 A
: constant Entity_Id
:=
8677 Make_Defining_Identifier
(Sloc
(FF
),
8678 Chars
=> Chars
(FF
));
8680 B
: constant Entity_Id
:=
8681 Make_Defining_Identifier
(Sloc
(NF
),
8682 Chars
=> Chars
(NF
));
8685 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
8687 Formals
:= New_List
(
8688 Make_Parameter_Specification
(Loc
,
8689 Defining_Identifier
=> A
,
8691 New_Occurrence_Of
(Etype
(First_Formal
(S
)),
8692 Sloc
(Etype
(First_Formal
(S
))))),
8694 Make_Parameter_Specification
(Loc
,
8695 Defining_Identifier
=> B
,
8697 New_Occurrence_Of
(Etype
(Next_Formal
(First_Formal
(S
))),
8698 Sloc
(Etype
(Next_Formal
(First_Formal
(S
)))))));
8701 Make_Subprogram_Declaration
(Loc
,
8703 Make_Function_Specification
(Loc
,
8704 Defining_Unit_Name
=> Op_Name
,
8705 Parameter_Specifications
=> Formals
,
8706 Result_Definition
=>
8707 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
8709 -- Insert inequality right after equality if it is explicit or after
8710 -- the derived type when implicit. These entities are created only
8711 -- for visibility purposes, and eventually replaced in the course
8712 -- of expansion, so they do not need to be attached to the tree and
8713 -- seen by the back-end. Keeping them internal also avoids spurious
8714 -- freezing problems. The declaration is inserted in the tree for
8715 -- analysis, and removed afterwards. If the equality operator comes
8716 -- from an explicit declaration, attach the inequality immediately
8717 -- after. Else the equality is inherited from a derived type
8718 -- declaration, so insert inequality after that declaration.
8720 if No
(Alias
(S
)) then
8721 Insert_After
(Unit_Declaration_Node
(S
), Decl
);
8722 elsif Is_List_Member
(Parent
(S
)) then
8723 Insert_After
(Parent
(S
), Decl
);
8725 Insert_After
(Parent
(Etype
(First_Formal
(S
))), Decl
);
8728 Mark_Rewrite_Insertion
(Decl
);
8729 Set_Is_Intrinsic_Subprogram
(Op_Name
);
8732 Set_Has_Completion
(Op_Name
);
8733 Set_Corresponding_Equality
(Op_Name
, S
);
8734 Set_Is_Abstract_Subprogram
(Op_Name
, Is_Abstract_Subprogram
(S
));
8736 end Make_Inequality_Operator
;
8738 ----------------------
8739 -- May_Need_Actuals --
8740 ----------------------
8742 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
8747 F
:= First_Formal
(Fun
);
8749 while Present
(F
) loop
8750 if No
(Default_Value
(F
)) then
8758 Set_Needs_No_Actuals
(Fun
, B
);
8759 end May_Need_Actuals
;
8761 ---------------------
8762 -- Mode_Conformant --
8763 ---------------------
8765 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
8768 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
8770 end Mode_Conformant
;
8772 ---------------------------
8773 -- New_Overloaded_Entity --
8774 ---------------------------
8776 procedure New_Overloaded_Entity
8778 Derived_Type
: Entity_Id
:= Empty
)
8780 Overridden_Subp
: Entity_Id
:= Empty
;
8781 -- Set if the current scope has an operation that is type-conformant
8782 -- with S, and becomes hidden by S.
8784 Is_Primitive_Subp
: Boolean;
8785 -- Set to True if the new subprogram is primitive
8788 -- Entity that S overrides
8790 Prev_Vis
: Entity_Id
:= Empty
;
8791 -- Predecessor of E in Homonym chain
8793 procedure Check_For_Primitive_Subprogram
8794 (Is_Primitive
: out Boolean;
8795 Is_Overriding
: Boolean := False);
8796 -- If the subprogram being analyzed is a primitive operation of the type
8797 -- of a formal or result, set the Has_Primitive_Operations flag on the
8798 -- type, and set Is_Primitive to True (otherwise set to False). Set the
8799 -- corresponding flag on the entity itself for later use.
8801 procedure Check_Synchronized_Overriding
8802 (Def_Id
: Entity_Id
;
8803 Overridden_Subp
: out Entity_Id
);
8804 -- First determine if Def_Id is an entry or a subprogram either defined
8805 -- in the scope of a task or protected type, or is a primitive of such
8806 -- a type. Check whether Def_Id overrides a subprogram of an interface
8807 -- implemented by the synchronized type, return the overridden entity
8810 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
8811 -- Check that E is declared in the private part of the current package,
8812 -- or in the package body, where it may hide a previous declaration.
8813 -- We can't use In_Private_Part by itself because this flag is also
8814 -- set when freezing entities, so we must examine the place of the
8815 -- declaration in the tree, and recognize wrapper packages as well.
8817 function Is_Overriding_Alias
8819 New_E
: Entity_Id
) return Boolean;
8820 -- Check whether new subprogram and old subprogram are both inherited
8821 -- from subprograms that have distinct dispatch table entries. This can
8822 -- occur with derivations from instances with accidental homonyms. The
8823 -- function is conservative given that the converse is only true within
8824 -- instances that contain accidental overloadings.
8826 ------------------------------------
8827 -- Check_For_Primitive_Subprogram --
8828 ------------------------------------
8830 procedure Check_For_Primitive_Subprogram
8831 (Is_Primitive
: out Boolean;
8832 Is_Overriding
: Boolean := False)
8838 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
8839 -- Returns true if T is declared in the visible part of the current
8840 -- package scope; otherwise returns false. Assumes that T is declared
8843 procedure Check_Private_Overriding
(T
: Entity_Id
);
8844 -- Checks that if a primitive abstract subprogram of a visible
8845 -- abstract type is declared in a private part, then it must override
8846 -- an abstract subprogram declared in the visible part. Also checks
8847 -- that if a primitive function with a controlling result is declared
8848 -- in a private part, then it must override a function declared in
8849 -- the visible part.
8851 ------------------------------
8852 -- Check_Private_Overriding --
8853 ------------------------------
8855 procedure Check_Private_Overriding
(T
: Entity_Id
) is
8857 if Is_Package_Or_Generic_Package
(Current_Scope
)
8858 and then In_Private_Part
(Current_Scope
)
8859 and then Visible_Part_Type
(T
)
8860 and then not In_Instance
8862 if Is_Abstract_Type
(T
)
8863 and then Is_Abstract_Subprogram
(S
)
8864 and then (not Is_Overriding
8865 or else not Is_Abstract_Subprogram
(E
))
8867 Error_Msg_N
("abstract subprograms must be visible "
8868 & "(RM 3.9.3(10))!", S
);
8870 elsif Ekind
(S
) = E_Function
and then not Is_Overriding
then
8871 if Is_Tagged_Type
(T
) and then T
= Base_Type
(Etype
(S
)) then
8872 Error_Msg_N
("private function with tagged result must"
8873 & " override visible-part function", S
);
8874 Error_Msg_N
("\move subprogram to the visible part"
8875 & " (RM 3.9.3(10))", S
);
8877 -- AI05-0073: extend this test to the case of a function
8878 -- with a controlling access result.
8880 elsif Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
8881 and then Is_Tagged_Type
(Designated_Type
(Etype
(S
)))
8883 not Is_Class_Wide_Type
(Designated_Type
(Etype
(S
)))
8884 and then Ada_Version
>= Ada_2012
8887 ("private function with controlling access result "
8888 & "must override visible-part function", S
);
8890 ("\move subprogram to the visible part"
8891 & " (RM 3.9.3(10))", S
);
8895 end Check_Private_Overriding
;
8897 -----------------------
8898 -- Visible_Part_Type --
8899 -----------------------
8901 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
8902 P
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
8906 -- If the entity is a private type, then it must be declared in a
8909 if Ekind
(T
) in Private_Kind
then
8913 -- Otherwise, we traverse the visible part looking for its
8914 -- corresponding declaration. We cannot use the declaration
8915 -- node directly because in the private part the entity of a
8916 -- private type is the one in the full view, which does not
8917 -- indicate that it is the completion of something visible.
8919 N
:= First
(Visible_Declarations
(Specification
(P
)));
8920 while Present
(N
) loop
8921 if Nkind
(N
) = N_Full_Type_Declaration
8922 and then Present
(Defining_Identifier
(N
))
8923 and then T
= Defining_Identifier
(N
)
8927 elsif Nkind_In
(N
, N_Private_Type_Declaration
,
8928 N_Private_Extension_Declaration
)
8929 and then Present
(Defining_Identifier
(N
))
8930 and then T
= Full_View
(Defining_Identifier
(N
))
8939 end Visible_Part_Type
;
8941 -- Start of processing for Check_For_Primitive_Subprogram
8944 Is_Primitive
:= False;
8946 if not Comes_From_Source
(S
) then
8949 -- If subprogram is at library level, it is not primitive operation
8951 elsif Current_Scope
= Standard_Standard
then
8954 elsif (Is_Package_Or_Generic_Package
(Current_Scope
)
8955 and then not In_Package_Body
(Current_Scope
))
8956 or else Is_Overriding
8958 -- For function, check return type
8960 if Ekind
(S
) = E_Function
then
8961 if Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
then
8962 F_Typ
:= Designated_Type
(Etype
(S
));
8967 B_Typ
:= Base_Type
(F_Typ
);
8969 if Scope
(B_Typ
) = Current_Scope
8970 and then not Is_Class_Wide_Type
(B_Typ
)
8971 and then not Is_Generic_Type
(B_Typ
)
8973 Is_Primitive
:= True;
8974 Set_Has_Primitive_Operations
(B_Typ
);
8975 Set_Is_Primitive
(S
);
8976 Check_Private_Overriding
(B_Typ
);
8980 -- For all subprograms, check formals
8982 Formal
:= First_Formal
(S
);
8983 while Present
(Formal
) loop
8984 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
8985 F_Typ
:= Designated_Type
(Etype
(Formal
));
8987 F_Typ
:= Etype
(Formal
);
8990 B_Typ
:= Base_Type
(F_Typ
);
8992 if Ekind
(B_Typ
) = E_Access_Subtype
then
8993 B_Typ
:= Base_Type
(B_Typ
);
8996 if Scope
(B_Typ
) = Current_Scope
8997 and then not Is_Class_Wide_Type
(B_Typ
)
8998 and then not Is_Generic_Type
(B_Typ
)
9000 Is_Primitive
:= True;
9001 Set_Is_Primitive
(S
);
9002 Set_Has_Primitive_Operations
(B_Typ
);
9003 Check_Private_Overriding
(B_Typ
);
9006 Next_Formal
(Formal
);
9009 -- Special case: An equality function can be redefined for a type
9010 -- occurring in a declarative part, and won't otherwise be treated as
9011 -- a primitive because it doesn't occur in a package spec and doesn't
9012 -- override an inherited subprogram. It's important that we mark it
9013 -- primitive so it can be returned by Collect_Primitive_Operations
9014 -- and be used in composing the equality operation of later types
9015 -- that have a component of the type.
9017 elsif Chars
(S
) = Name_Op_Eq
9018 and then Etype
(S
) = Standard_Boolean
9020 B_Typ
:= Base_Type
(Etype
(First_Formal
(S
)));
9022 if Scope
(B_Typ
) = Current_Scope
9024 Base_Type
(Etype
(Next_Formal
(First_Formal
(S
)))) = B_Typ
9025 and then not Is_Limited_Type
(B_Typ
)
9027 Is_Primitive
:= True;
9028 Set_Is_Primitive
(S
);
9029 Set_Has_Primitive_Operations
(B_Typ
);
9030 Check_Private_Overriding
(B_Typ
);
9033 end Check_For_Primitive_Subprogram
;
9035 -----------------------------------
9036 -- Check_Synchronized_Overriding --
9037 -----------------------------------
9039 procedure Check_Synchronized_Overriding
9040 (Def_Id
: Entity_Id
;
9041 Overridden_Subp
: out Entity_Id
)
9043 Ifaces_List
: Elist_Id
;
9047 function Matches_Prefixed_View_Profile
9048 (Prim_Params
: List_Id
;
9049 Iface_Params
: List_Id
) return Boolean;
9050 -- Determine whether a subprogram's parameter profile Prim_Params
9051 -- matches that of a potentially overridden interface subprogram
9052 -- Iface_Params. Also determine if the type of first parameter of
9053 -- Iface_Params is an implemented interface.
9055 -----------------------------------
9056 -- Matches_Prefixed_View_Profile --
9057 -----------------------------------
9059 function Matches_Prefixed_View_Profile
9060 (Prim_Params
: List_Id
;
9061 Iface_Params
: List_Id
) return Boolean
9063 Iface_Id
: Entity_Id
;
9064 Iface_Param
: Node_Id
;
9065 Iface_Typ
: Entity_Id
;
9066 Prim_Id
: Entity_Id
;
9067 Prim_Param
: Node_Id
;
9068 Prim_Typ
: Entity_Id
;
9070 function Is_Implemented
9071 (Ifaces_List
: Elist_Id
;
9072 Iface
: Entity_Id
) return Boolean;
9073 -- Determine if Iface is implemented by the current task or
9076 --------------------
9077 -- Is_Implemented --
9078 --------------------
9080 function Is_Implemented
9081 (Ifaces_List
: Elist_Id
;
9082 Iface
: Entity_Id
) return Boolean
9084 Iface_Elmt
: Elmt_Id
;
9087 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
9088 while Present
(Iface_Elmt
) loop
9089 if Node
(Iface_Elmt
) = Iface
then
9093 Next_Elmt
(Iface_Elmt
);
9099 -- Start of processing for Matches_Prefixed_View_Profile
9102 Iface_Param
:= First
(Iface_Params
);
9103 Iface_Typ
:= Etype
(Defining_Identifier
(Iface_Param
));
9105 if Is_Access_Type
(Iface_Typ
) then
9106 Iface_Typ
:= Designated_Type
(Iface_Typ
);
9109 Prim_Param
:= First
(Prim_Params
);
9111 -- The first parameter of the potentially overridden subprogram
9112 -- must be an interface implemented by Prim.
9114 if not Is_Interface
(Iface_Typ
)
9115 or else not Is_Implemented
(Ifaces_List
, Iface_Typ
)
9120 -- The checks on the object parameters are done, move onto the
9121 -- rest of the parameters.
9123 if not In_Scope
then
9124 Prim_Param
:= Next
(Prim_Param
);
9127 Iface_Param
:= Next
(Iface_Param
);
9128 while Present
(Iface_Param
) and then Present
(Prim_Param
) loop
9129 Iface_Id
:= Defining_Identifier
(Iface_Param
);
9130 Iface_Typ
:= Find_Parameter_Type
(Iface_Param
);
9132 Prim_Id
:= Defining_Identifier
(Prim_Param
);
9133 Prim_Typ
:= Find_Parameter_Type
(Prim_Param
);
9135 if Ekind
(Iface_Typ
) = E_Anonymous_Access_Type
9136 and then Ekind
(Prim_Typ
) = E_Anonymous_Access_Type
9137 and then Is_Concurrent_Type
(Designated_Type
(Prim_Typ
))
9139 Iface_Typ
:= Designated_Type
(Iface_Typ
);
9140 Prim_Typ
:= Designated_Type
(Prim_Typ
);
9143 -- Case of multiple interface types inside a parameter profile
9145 -- (Obj_Param : in out Iface; ...; Param : Iface)
9147 -- If the interface type is implemented, then the matching type
9148 -- in the primitive should be the implementing record type.
9150 if Ekind
(Iface_Typ
) = E_Record_Type
9151 and then Is_Interface
(Iface_Typ
)
9152 and then Is_Implemented
(Ifaces_List
, Iface_Typ
)
9154 if Prim_Typ
/= Typ
then
9158 -- The two parameters must be both mode and subtype conformant
9160 elsif Ekind
(Iface_Id
) /= Ekind
(Prim_Id
)
9162 Conforming_Types
(Iface_Typ
, Prim_Typ
, Subtype_Conformant
)
9171 -- One of the two lists contains more parameters than the other
9173 if Present
(Iface_Param
) or else Present
(Prim_Param
) then
9178 end Matches_Prefixed_View_Profile
;
9180 -- Start of processing for Check_Synchronized_Overriding
9183 Overridden_Subp
:= Empty
;
9185 -- Def_Id must be an entry or a subprogram. We should skip predefined
9186 -- primitives internally generated by the frontend; however at this
9187 -- stage predefined primitives are still not fully decorated. As a
9188 -- minor optimization we skip here internally generated subprograms.
9190 if (Ekind
(Def_Id
) /= E_Entry
9191 and then Ekind
(Def_Id
) /= E_Function
9192 and then Ekind
(Def_Id
) /= E_Procedure
)
9193 or else not Comes_From_Source
(Def_Id
)
9198 -- Search for the concurrent declaration since it contains the list
9199 -- of all implemented interfaces. In this case, the subprogram is
9200 -- declared within the scope of a protected or a task type.
9202 if Present
(Scope
(Def_Id
))
9203 and then Is_Concurrent_Type
(Scope
(Def_Id
))
9204 and then not Is_Generic_Actual_Type
(Scope
(Def_Id
))
9206 Typ
:= Scope
(Def_Id
);
9209 -- The enclosing scope is not a synchronized type and the subprogram
9212 elsif No
(First_Formal
(Def_Id
)) then
9215 -- The subprogram has formals and hence it may be a primitive of a
9219 Typ
:= Etype
(First_Formal
(Def_Id
));
9221 if Is_Access_Type
(Typ
) then
9222 Typ
:= Directly_Designated_Type
(Typ
);
9225 if Is_Concurrent_Type
(Typ
)
9226 and then not Is_Generic_Actual_Type
(Typ
)
9230 -- This case occurs when the concurrent type is declared within
9231 -- a generic unit. As a result the corresponding record has been
9232 -- built and used as the type of the first formal, we just have
9233 -- to retrieve the corresponding concurrent type.
9235 elsif Is_Concurrent_Record_Type
(Typ
)
9236 and then not Is_Class_Wide_Type
(Typ
)
9237 and then Present
(Corresponding_Concurrent_Type
(Typ
))
9239 Typ
:= Corresponding_Concurrent_Type
(Typ
);
9247 -- There is no overriding to check if is an inherited operation in a
9248 -- type derivation on for a generic actual.
9250 Collect_Interfaces
(Typ
, Ifaces_List
);
9252 if Is_Empty_Elmt_List
(Ifaces_List
) then
9256 -- Determine whether entry or subprogram Def_Id overrides a primitive
9257 -- operation that belongs to one of the interfaces in Ifaces_List.
9260 Candidate
: Entity_Id
:= Empty
;
9261 Hom
: Entity_Id
:= Empty
;
9262 Iface_Typ
: Entity_Id
;
9263 Subp
: Entity_Id
:= Empty
;
9266 -- Traverse the homonym chain, looking for a potentially
9267 -- overridden subprogram that belongs to an implemented
9270 Hom
:= Current_Entity_In_Scope
(Def_Id
);
9271 while Present
(Hom
) loop
9275 or else not Is_Overloadable
(Subp
)
9276 or else not Is_Primitive
(Subp
)
9277 or else not Is_Dispatching_Operation
(Subp
)
9278 or else not Present
(Find_Dispatching_Type
(Subp
))
9279 or else not Is_Interface
(Find_Dispatching_Type
(Subp
))
9283 -- Entries and procedures can override abstract or null
9284 -- interface procedures.
9286 elsif (Ekind
(Def_Id
) = E_Procedure
9287 or else Ekind
(Def_Id
) = E_Entry
)
9288 and then Ekind
(Subp
) = E_Procedure
9289 and then Matches_Prefixed_View_Profile
9290 (Parameter_Specifications
(Parent
(Def_Id
)),
9291 Parameter_Specifications
(Parent
(Subp
)))
9295 -- For an overridden subprogram Subp, check whether the mode
9296 -- of its first parameter is correct depending on the kind
9297 -- of synchronized type.
9300 Formal
: constant Node_Id
:= First_Formal
(Candidate
);
9303 -- In order for an entry or a protected procedure to
9304 -- override, the first parameter of the overridden
9305 -- routine must be of mode "out", "in out" or
9306 -- access-to-variable.
9308 if Ekind_In
(Candidate
, E_Entry
, E_Procedure
)
9309 and then Is_Protected_Type
(Typ
)
9310 and then Ekind
(Formal
) /= E_In_Out_Parameter
9311 and then Ekind
(Formal
) /= E_Out_Parameter
9312 and then Nkind
(Parameter_Type
(Parent
(Formal
))) /=
9317 -- All other cases are OK since a task entry or routine
9318 -- does not have a restriction on the mode of the first
9319 -- parameter of the overridden interface routine.
9322 Overridden_Subp
:= Candidate
;
9327 -- Functions can override abstract interface functions
9329 elsif Ekind
(Def_Id
) = E_Function
9330 and then Ekind
(Subp
) = E_Function
9331 and then Matches_Prefixed_View_Profile
9332 (Parameter_Specifications
(Parent
(Def_Id
)),
9333 Parameter_Specifications
(Parent
(Subp
)))
9334 and then Etype
(Result_Definition
(Parent
(Def_Id
))) =
9335 Etype
(Result_Definition
(Parent
(Subp
)))
9337 Overridden_Subp
:= Subp
;
9341 Hom
:= Homonym
(Hom
);
9344 -- After examining all candidates for overriding, we are left with
9345 -- the best match which is a mode incompatible interface routine.
9346 -- Do not emit an error if the Expander is active since this error
9347 -- will be detected later on after all concurrent types are
9348 -- expanded and all wrappers are built. This check is meant for
9349 -- spec-only compilations.
9351 if Present
(Candidate
) and then not Expander_Active
then
9353 Find_Parameter_Type
(Parent
(First_Formal
(Candidate
)));
9355 -- Def_Id is primitive of a protected type, declared inside the
9356 -- type, and the candidate is primitive of a limited or
9357 -- synchronized interface.
9360 and then Is_Protected_Type
(Typ
)
9362 (Is_Limited_Interface
(Iface_Typ
)
9363 or else Is_Protected_Interface
(Iface_Typ
)
9364 or else Is_Synchronized_Interface
(Iface_Typ
)
9365 or else Is_Task_Interface
(Iface_Typ
))
9367 Error_Msg_PT
(Def_Id
, Candidate
);
9371 Overridden_Subp
:= Candidate
;
9374 end Check_Synchronized_Overriding
;
9376 ----------------------------
9377 -- Is_Private_Declaration --
9378 ----------------------------
9380 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
9381 Priv_Decls
: List_Id
;
9382 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
9385 if Is_Package_Or_Generic_Package
(Current_Scope
)
9386 and then In_Private_Part
(Current_Scope
)
9389 Private_Declarations
(Package_Specification
(Current_Scope
));
9391 return In_Package_Body
(Current_Scope
)
9393 (Is_List_Member
(Decl
)
9394 and then List_Containing
(Decl
) = Priv_Decls
)
9395 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
9398 (Defining_Entity
(Parent
(Decl
)))
9399 and then List_Containing
(Parent
(Parent
(Decl
))) =
9404 end Is_Private_Declaration
;
9406 --------------------------
9407 -- Is_Overriding_Alias --
9408 --------------------------
9410 function Is_Overriding_Alias
9412 New_E
: Entity_Id
) return Boolean
9414 AO
: constant Entity_Id
:= Alias
(Old_E
);
9415 AN
: constant Entity_Id
:= Alias
(New_E
);
9417 return Scope
(AO
) /= Scope
(AN
)
9418 or else No
(DTC_Entity
(AO
))
9419 or else No
(DTC_Entity
(AN
))
9420 or else DT_Position
(AO
) = DT_Position
(AN
);
9421 end Is_Overriding_Alias
;
9423 -- Start of processing for New_Overloaded_Entity
9426 -- We need to look for an entity that S may override. This must be a
9427 -- homonym in the current scope, so we look for the first homonym of
9428 -- S in the current scope as the starting point for the search.
9430 E
:= Current_Entity_In_Scope
(S
);
9432 -- Ada 2005 (AI-251): Derivation of abstract interface primitives.
9433 -- They are directly added to the list of primitive operations of
9434 -- Derived_Type, unless this is a rederivation in the private part
9435 -- of an operation that was already derived in the visible part of
9436 -- the current package.
9438 if Ada_Version
>= Ada_2005
9439 and then Present
(Derived_Type
)
9440 and then Present
(Alias
(S
))
9441 and then Is_Dispatching_Operation
(Alias
(S
))
9442 and then Present
(Find_Dispatching_Type
(Alias
(S
)))
9443 and then Is_Interface
(Find_Dispatching_Type
(Alias
(S
)))
9445 -- For private types, when the full-view is processed we propagate to
9446 -- the full view the non-overridden entities whose attribute "alias"
9447 -- references an interface primitive. These entities were added by
9448 -- Derive_Subprograms to ensure that interface primitives are
9451 -- Inside_Freeze_Actions is non zero when S corresponds with an
9452 -- internal entity that links an interface primitive with its
9453 -- covering primitive through attribute Interface_Alias (see
9454 -- Add_Internal_Interface_Entities).
9456 if Inside_Freezing_Actions
= 0
9457 and then Is_Package_Or_Generic_Package
(Current_Scope
)
9458 and then In_Private_Part
(Current_Scope
)
9459 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
9460 and then Nkind
(Parent
(S
)) = N_Full_Type_Declaration
9461 and then Full_View
(Defining_Identifier
(Parent
(E
)))
9462 = Defining_Identifier
(Parent
(S
))
9463 and then Alias
(E
) = Alias
(S
)
9465 Check_Operation_From_Private_View
(S
, E
);
9466 Set_Is_Dispatching_Operation
(S
);
9471 Enter_Overloaded_Entity
(S
);
9472 Check_Dispatching_Operation
(S
, Empty
);
9473 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
9479 -- If there is no homonym then this is definitely not overriding
9482 Enter_Overloaded_Entity
(S
);
9483 Check_Dispatching_Operation
(S
, Empty
);
9484 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
9486 -- If subprogram has an explicit declaration, check whether it has an
9487 -- overriding indicator.
9489 if Comes_From_Source
(S
) then
9490 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
9492 -- (Ada 2012: AI05-0125-1): If S is a dispatching operation then
9493 -- it may have overridden some hidden inherited primitive. Update
9494 -- Overridden_Subp to avoid spurious errors when checking the
9495 -- overriding indicator.
9497 if Ada_Version
>= Ada_2012
9498 and then No
(Overridden_Subp
)
9499 and then Is_Dispatching_Operation
(S
)
9500 and then Present
(Overridden_Operation
(S
))
9502 Overridden_Subp
:= Overridden_Operation
(S
);
9505 Check_Overriding_Indicator
9506 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
9509 -- If there is a homonym that is not overloadable, then we have an
9510 -- error, except for the special cases checked explicitly below.
9512 elsif not Is_Overloadable
(E
) then
9514 -- Check for spurious conflict produced by a subprogram that has the
9515 -- same name as that of the enclosing generic package. The conflict
9516 -- occurs within an instance, between the subprogram and the renaming
9517 -- declaration for the package. After the subprogram, the package
9518 -- renaming declaration becomes hidden.
9520 if Ekind
(E
) = E_Package
9521 and then Present
(Renamed_Object
(E
))
9522 and then Renamed_Object
(E
) = Current_Scope
9523 and then Nkind
(Parent
(Renamed_Object
(E
))) =
9524 N_Package_Specification
9525 and then Present
(Generic_Parent
(Parent
(Renamed_Object
(E
))))
9528 Set_Is_Immediately_Visible
(E
, False);
9529 Enter_Overloaded_Entity
(S
);
9530 Set_Homonym
(S
, Homonym
(E
));
9531 Check_Dispatching_Operation
(S
, Empty
);
9532 Check_Overriding_Indicator
(S
, Empty
, Is_Primitive
=> False);
9534 -- If the subprogram is implicit it is hidden by the previous
9535 -- declaration. However if it is dispatching, it must appear in the
9536 -- dispatch table anyway, because it can be dispatched to even if it
9537 -- cannot be called directly.
9539 elsif Present
(Alias
(S
)) and then not Comes_From_Source
(S
) then
9540 Set_Scope
(S
, Current_Scope
);
9542 if Is_Dispatching_Operation
(Alias
(S
)) then
9543 Check_Dispatching_Operation
(S
, Empty
);
9549 Error_Msg_Sloc
:= Sloc
(E
);
9551 -- Generate message, with useful additional warning if in generic
9553 if Is_Generic_Unit
(E
) then
9554 Error_Msg_N
("previous generic unit cannot be overloaded", S
);
9555 Error_Msg_N
("\& conflicts with declaration#", S
);
9557 Error_Msg_N
("& conflicts with declaration#", S
);
9563 -- E exists and is overloadable
9566 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
9568 -- Loop through E and its homonyms to determine if any of them is
9569 -- the candidate for overriding by S.
9571 while Present
(E
) loop
9573 -- Definitely not interesting if not in the current scope
9575 if Scope
(E
) /= Current_Scope
then
9578 -- A function can overload the name of an abstract state. The
9579 -- state can be viewed as a function with a profile that cannot
9580 -- be matched by anything.
9582 elsif Ekind
(S
) = E_Function
9583 and then Ekind
(E
) = E_Abstract_State
9585 Enter_Overloaded_Entity
(S
);
9588 -- Ada 2012 (AI05-0165): For internally generated bodies of null
9589 -- procedures locate the internally generated spec. We enforce
9590 -- mode conformance since a tagged type may inherit from
9591 -- interfaces several null primitives which differ only in
9592 -- the mode of the formals.
9594 elsif not Comes_From_Source
(S
)
9595 and then Is_Null_Procedure
(S
)
9596 and then not Mode_Conformant
(E
, S
)
9600 -- Check if we have type conformance
9602 elsif Type_Conformant
(E
, S
) then
9604 -- If the old and new entities have the same profile and one
9605 -- is not the body of the other, then this is an error, unless
9606 -- one of them is implicitly declared.
9608 -- There are some cases when both can be implicit, for example
9609 -- when both a literal and a function that overrides it are
9610 -- inherited in a derivation, or when an inherited operation
9611 -- of a tagged full type overrides the inherited operation of
9612 -- a private extension. Ada 83 had a special rule for the
9613 -- literal case. In Ada 95, the later implicit operation hides
9614 -- the former, and the literal is always the former. In the
9615 -- odd case where both are derived operations declared at the
9616 -- same point, both operations should be declared, and in that
9617 -- case we bypass the following test and proceed to the next
9618 -- part. This can only occur for certain obscure cases in
9619 -- instances, when an operation on a type derived from a formal
9620 -- private type does not override a homograph inherited from
9621 -- the actual. In subsequent derivations of such a type, the
9622 -- DT positions of these operations remain distinct, if they
9625 if Present
(Alias
(S
))
9626 and then (No
(Alias
(E
))
9627 or else Comes_From_Source
(E
)
9628 or else Is_Abstract_Subprogram
(S
)
9630 (Is_Dispatching_Operation
(E
)
9631 and then Is_Overriding_Alias
(E
, S
)))
9632 and then Ekind
(E
) /= E_Enumeration_Literal
9634 -- When an derived operation is overloaded it may be due to
9635 -- the fact that the full view of a private extension
9636 -- re-inherits. It has to be dealt with.
9638 if Is_Package_Or_Generic_Package
(Current_Scope
)
9639 and then In_Private_Part
(Current_Scope
)
9641 Check_Operation_From_Private_View
(S
, E
);
9644 -- In any case the implicit operation remains hidden by the
9645 -- existing declaration, which is overriding. Indicate that
9646 -- E overrides the operation from which S is inherited.
9648 if Present
(Alias
(S
)) then
9649 Set_Overridden_Operation
(E
, Alias
(S
));
9650 Inherit_Subprogram_Contract
(E
, Alias
(S
));
9653 Set_Overridden_Operation
(E
, S
);
9654 Inherit_Subprogram_Contract
(E
, S
);
9657 if Comes_From_Source
(E
) then
9658 Check_Overriding_Indicator
(E
, S
, Is_Primitive
=> False);
9663 -- Within an instance, the renaming declarations for actual
9664 -- subprograms may become ambiguous, but they do not hide each
9667 elsif Ekind
(E
) /= E_Entry
9668 and then not Comes_From_Source
(E
)
9669 and then not Is_Generic_Instance
(E
)
9670 and then (Present
(Alias
(E
))
9671 or else Is_Intrinsic_Subprogram
(E
))
9672 and then (not In_Instance
9673 or else No
(Parent
(E
))
9674 or else Nkind
(Unit_Declaration_Node
(E
)) /=
9675 N_Subprogram_Renaming_Declaration
)
9677 -- A subprogram child unit is not allowed to override an
9678 -- inherited subprogram (10.1.1(20)).
9680 if Is_Child_Unit
(S
) then
9682 ("child unit overrides inherited subprogram in parent",
9687 if Is_Non_Overriding_Operation
(E
, S
) then
9688 Enter_Overloaded_Entity
(S
);
9690 if No
(Derived_Type
)
9691 or else Is_Tagged_Type
(Derived_Type
)
9693 Check_Dispatching_Operation
(S
, Empty
);
9699 -- E is a derived operation or an internal operator which
9700 -- is being overridden. Remove E from further visibility.
9701 -- Furthermore, if E is a dispatching operation, it must be
9702 -- replaced in the list of primitive operations of its type
9703 -- (see Override_Dispatching_Operation).
9705 Overridden_Subp
:= E
;
9711 Prev
:= First_Entity
(Current_Scope
);
9712 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
9716 -- It is possible for E to be in the current scope and
9717 -- yet not in the entity chain. This can only occur in a
9718 -- generic context where E is an implicit concatenation
9719 -- in the formal part, because in a generic body the
9720 -- entity chain starts with the formals.
9722 -- In GNATprove mode, a wrapper for an operation with
9723 -- axiomatization may be a homonym of another declaration
9724 -- for an actual subprogram (needs refinement ???).
9728 and then GNATprove_Mode
9730 Nkind
(Original_Node
(Unit_Declaration_Node
(S
))) =
9731 N_Subprogram_Renaming_Declaration
9735 pragma Assert
(Chars
(E
) = Name_Op_Concat
);
9740 -- E must be removed both from the entity_list of the
9741 -- current scope, and from the visibility chain.
9743 if Debug_Flag_E
then
9744 Write_Str
("Override implicit operation ");
9745 Write_Int
(Int
(E
));
9749 -- If E is a predefined concatenation, it stands for four
9750 -- different operations. As a result, a single explicit
9751 -- declaration does not hide it. In a possible ambiguous
9752 -- situation, Disambiguate chooses the user-defined op,
9753 -- so it is correct to retain the previous internal one.
9755 if Chars
(E
) /= Name_Op_Concat
9756 or else Ekind
(E
) /= E_Operator
9758 -- For nondispatching derived operations that are
9759 -- overridden by a subprogram declared in the private
9760 -- part of a package, we retain the derived subprogram
9761 -- but mark it as not immediately visible. If the
9762 -- derived operation was declared in the visible part
9763 -- then this ensures that it will still be visible
9764 -- outside the package with the proper signature
9765 -- (calls from outside must also be directed to this
9766 -- version rather than the overriding one, unlike the
9767 -- dispatching case). Calls from inside the package
9768 -- will still resolve to the overriding subprogram
9769 -- since the derived one is marked as not visible
9770 -- within the package.
9772 -- If the private operation is dispatching, we achieve
9773 -- the overriding by keeping the implicit operation
9774 -- but setting its alias to be the overriding one. In
9775 -- this fashion the proper body is executed in all
9776 -- cases, but the original signature is used outside
9779 -- If the overriding is not in the private part, we
9780 -- remove the implicit operation altogether.
9782 if Is_Private_Declaration
(S
) then
9783 if not Is_Dispatching_Operation
(E
) then
9784 Set_Is_Immediately_Visible
(E
, False);
9786 -- Work done in Override_Dispatching_Operation,
9787 -- so nothing else needs to be done here.
9793 -- Find predecessor of E in Homonym chain
9795 if E
= Current_Entity
(E
) then
9798 Prev_Vis
:= Current_Entity
(E
);
9799 while Homonym
(Prev_Vis
) /= E
loop
9800 Prev_Vis
:= Homonym
(Prev_Vis
);
9804 if Prev_Vis
/= Empty
then
9806 -- Skip E in the visibility chain
9808 Set_Homonym
(Prev_Vis
, Homonym
(E
));
9811 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
9814 Set_Next_Entity
(Prev
, Next_Entity
(E
));
9816 if No
(Next_Entity
(Prev
)) then
9817 Set_Last_Entity
(Current_Scope
, Prev
);
9822 Enter_Overloaded_Entity
(S
);
9824 -- For entities generated by Derive_Subprograms the
9825 -- overridden operation is the inherited primitive
9826 -- (which is available through the attribute alias).
9828 if not (Comes_From_Source
(E
))
9829 and then Is_Dispatching_Operation
(E
)
9830 and then Find_Dispatching_Type
(E
) =
9831 Find_Dispatching_Type
(S
)
9832 and then Present
(Alias
(E
))
9833 and then Comes_From_Source
(Alias
(E
))
9835 Set_Overridden_Operation
(S
, Alias
(E
));
9836 Inherit_Subprogram_Contract
(S
, Alias
(E
));
9838 -- Normal case of setting entity as overridden
9840 -- Note: Static_Initialization and Overridden_Operation
9841 -- attributes use the same field in subprogram entities.
9842 -- Static_Initialization is only defined for internal
9843 -- initialization procedures, where Overridden_Operation
9844 -- is irrelevant. Therefore the setting of this attribute
9845 -- must check whether the target is an init_proc.
9847 elsif not Is_Init_Proc
(S
) then
9848 Set_Overridden_Operation
(S
, E
);
9849 Inherit_Subprogram_Contract
(S
, E
);
9852 Check_Overriding_Indicator
(S
, E
, Is_Primitive
=> True);
9854 -- If S is a user-defined subprogram or a null procedure
9855 -- expanded to override an inherited null procedure, or a
9856 -- predefined dispatching primitive then indicate that E
9857 -- overrides the operation from which S is inherited.
9859 if Comes_From_Source
(S
)
9861 (Present
(Parent
(S
))
9863 Nkind
(Parent
(S
)) = N_Procedure_Specification
9865 Null_Present
(Parent
(S
)))
9867 (Present
(Alias
(E
))
9869 Is_Predefined_Dispatching_Operation
(Alias
(E
)))
9871 if Present
(Alias
(E
)) then
9872 Set_Overridden_Operation
(S
, Alias
(E
));
9873 Inherit_Subprogram_Contract
(S
, Alias
(E
));
9877 if Is_Dispatching_Operation
(E
) then
9879 -- An overriding dispatching subprogram inherits the
9880 -- convention of the overridden subprogram (AI-117).
9882 Set_Convention
(S
, Convention
(E
));
9883 Check_Dispatching_Operation
(S
, E
);
9886 Check_Dispatching_Operation
(S
, Empty
);
9889 Check_For_Primitive_Subprogram
9890 (Is_Primitive_Subp
, Is_Overriding
=> True);
9891 goto Check_Inequality
;
9894 -- Apparent redeclarations in instances can occur when two
9895 -- formal types get the same actual type. The subprograms in
9896 -- in the instance are legal, even if not callable from the
9897 -- outside. Calls from within are disambiguated elsewhere.
9898 -- For dispatching operations in the visible part, the usual
9899 -- rules apply, and operations with the same profile are not
9902 elsif (In_Instance_Visible_Part
9903 and then not Is_Dispatching_Operation
(E
))
9904 or else In_Instance_Not_Visible
9908 -- Here we have a real error (identical profile)
9911 Error_Msg_Sloc
:= Sloc
(E
);
9913 -- Avoid cascaded errors if the entity appears in
9914 -- subsequent calls.
9916 Set_Scope
(S
, Current_Scope
);
9918 -- Generate error, with extra useful warning for the case
9919 -- of a generic instance with no completion.
9921 if Is_Generic_Instance
(S
)
9922 and then not Has_Completion
(E
)
9925 ("instantiation cannot provide body for&", S
);
9926 Error_Msg_N
("\& conflicts with declaration#", S
);
9928 Error_Msg_N
("& conflicts with declaration#", S
);
9935 -- If one subprogram has an access parameter and the other
9936 -- a parameter of an access type, calls to either might be
9937 -- ambiguous. Verify that parameters match except for the
9938 -- access parameter.
9940 if May_Hide_Profile
then
9946 F1
:= First_Formal
(S
);
9947 F2
:= First_Formal
(E
);
9948 while Present
(F1
) and then Present
(F2
) loop
9949 if Is_Access_Type
(Etype
(F1
)) then
9950 if not Is_Access_Type
(Etype
(F2
))
9951 or else not Conforming_Types
9952 (Designated_Type
(Etype
(F1
)),
9953 Designated_Type
(Etype
(F2
)),
9956 May_Hide_Profile
:= False;
9960 not Conforming_Types
9961 (Etype
(F1
), Etype
(F2
), Type_Conformant
)
9963 May_Hide_Profile
:= False;
9974 Error_Msg_NE
("calls to& may be ambiguous??", S
, S
);
9983 -- On exit, we know that S is a new entity
9985 Enter_Overloaded_Entity
(S
);
9986 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
9987 Check_Overriding_Indicator
9988 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
9990 -- Overloading is not allowed in SPARK, except for operators
9992 if Nkind
(S
) /= N_Defining_Operator_Symbol
then
9993 Error_Msg_Sloc
:= Sloc
(Homonym
(S
));
9994 Check_SPARK_05_Restriction
9995 ("overloading not allowed with entity#", S
);
9998 -- If S is a derived operation for an untagged type then by
9999 -- definition it's not a dispatching operation (even if the parent
10000 -- operation was dispatching), so Check_Dispatching_Operation is not
10001 -- called in that case.
10003 if No
(Derived_Type
)
10004 or else Is_Tagged_Type
(Derived_Type
)
10006 Check_Dispatching_Operation
(S
, Empty
);
10010 -- If this is a user-defined equality operator that is not a derived
10011 -- subprogram, create the corresponding inequality. If the operation is
10012 -- dispatching, the expansion is done elsewhere, and we do not create
10013 -- an explicit inequality operation.
10015 <<Check_Inequality
>>
10016 if Chars
(S
) = Name_Op_Eq
10017 and then Etype
(S
) = Standard_Boolean
10018 and then Present
(Parent
(S
))
10019 and then not Is_Dispatching_Operation
(S
)
10021 Make_Inequality_Operator
(S
);
10022 Check_Untagged_Equality
(S
);
10024 end New_Overloaded_Entity
;
10026 ---------------------
10027 -- Process_Formals --
10028 ---------------------
10030 procedure Process_Formals
10032 Related_Nod
: Node_Id
)
10034 Param_Spec
: Node_Id
;
10035 Formal
: Entity_Id
;
10036 Formal_Type
: Entity_Id
;
10040 Num_Out_Params
: Nat
:= 0;
10041 First_Out_Param
: Entity_Id
:= Empty
;
10042 -- Used for setting Is_Only_Out_Parameter
10044 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean;
10045 -- Determine whether an access type designates a type coming from a
10048 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean;
10049 -- Check whether the default has a class-wide type. After analysis the
10050 -- default has the type of the formal, so we must also check explicitly
10051 -- for an access attribute.
10053 ----------------------------------
10054 -- Designates_From_Limited_With --
10055 ----------------------------------
10057 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean is
10058 Desig
: Entity_Id
:= Typ
;
10061 if Is_Access_Type
(Desig
) then
10062 Desig
:= Directly_Designated_Type
(Desig
);
10065 if Is_Class_Wide_Type
(Desig
) then
10066 Desig
:= Root_Type
(Desig
);
10070 Ekind
(Desig
) = E_Incomplete_Type
10071 and then From_Limited_With
(Desig
);
10072 end Designates_From_Limited_With
;
10074 ---------------------------
10075 -- Is_Class_Wide_Default --
10076 ---------------------------
10078 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean is
10080 return Is_Class_Wide_Type
(Designated_Type
(Etype
(D
)))
10081 or else (Nkind
(D
) = N_Attribute_Reference
10082 and then Attribute_Name
(D
) = Name_Access
10083 and then Is_Class_Wide_Type
(Etype
(Prefix
(D
))));
10084 end Is_Class_Wide_Default
;
10086 -- Start of processing for Process_Formals
10089 -- In order to prevent premature use of the formals in the same formal
10090 -- part, the Ekind is left undefined until all default expressions are
10091 -- analyzed. The Ekind is established in a separate loop at the end.
10093 Param_Spec
:= First
(T
);
10094 while Present
(Param_Spec
) loop
10095 Formal
:= Defining_Identifier
(Param_Spec
);
10096 Set_Never_Set_In_Source
(Formal
, True);
10097 Enter_Name
(Formal
);
10099 -- Case of ordinary parameters
10101 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
10102 Find_Type
(Parameter_Type
(Param_Spec
));
10103 Ptype
:= Parameter_Type
(Param_Spec
);
10105 if Ptype
= Error
then
10109 Formal_Type
:= Entity
(Ptype
);
10111 if Is_Incomplete_Type
(Formal_Type
)
10113 (Is_Class_Wide_Type
(Formal_Type
)
10114 and then Is_Incomplete_Type
(Root_Type
(Formal_Type
)))
10116 -- Ada 2005 (AI-326): Tagged incomplete types allowed in
10117 -- primitive operations, as long as their completion is
10118 -- in the same declarative part. If in the private part
10119 -- this means that the type cannot be a Taft-amendment type.
10120 -- Check is done on package exit. For access to subprograms,
10121 -- the use is legal for Taft-amendment types.
10123 -- Ada 2012: tagged incomplete types are allowed as generic
10124 -- formal types. They do not introduce dependencies and the
10125 -- corresponding generic subprogram does not have a delayed
10126 -- freeze, because it does not need a freeze node. However,
10127 -- it is still the case that untagged incomplete types cannot
10128 -- be Taft-amendment types and must be completed in private
10129 -- part, so the subprogram must appear in the list of private
10130 -- dependents of the type.
10132 if Is_Tagged_Type
(Formal_Type
)
10133 or else (Ada_Version
>= Ada_2012
10134 and then not From_Limited_With
(Formal_Type
)
10135 and then not Is_Generic_Type
(Formal_Type
))
10137 if Ekind
(Scope
(Current_Scope
)) = E_Package
10138 and then not Is_Generic_Type
(Formal_Type
)
10139 and then not Is_Class_Wide_Type
(Formal_Type
)
10142 (Parent
(T
), N_Access_Function_Definition
,
10143 N_Access_Procedure_Definition
)
10147 To
=> Private_Dependents
(Base_Type
(Formal_Type
)));
10149 -- Freezing is delayed to ensure that Register_Prim
10150 -- will get called for this operation, which is needed
10151 -- in cases where static dispatch tables aren't built.
10152 -- (Note that the same is done for controlling access
10153 -- parameter cases in function Access_Definition.)
10155 if not Is_Thunk
(Current_Scope
) then
10156 Set_Has_Delayed_Freeze
(Current_Scope
);
10161 -- Special handling of Value_Type for CIL case
10163 elsif Is_Value_Type
(Formal_Type
) then
10166 elsif not Nkind_In
(Parent
(T
), N_Access_Function_Definition
,
10167 N_Access_Procedure_Definition
)
10169 -- AI05-0151: Tagged incomplete types are allowed in all
10170 -- formal parts. Untagged incomplete types are not allowed
10171 -- in bodies. Limited views of either kind are not allowed
10172 -- if there is no place at which the non-limited view can
10173 -- become available.
10175 -- Incomplete formal untagged types are not allowed in
10176 -- subprogram bodies (but are legal in their declarations).
10178 if Is_Generic_Type
(Formal_Type
)
10179 and then not Is_Tagged_Type
(Formal_Type
)
10180 and then Nkind
(Parent
(Related_Nod
)) = N_Subprogram_Body
10183 ("invalid use of formal incomplete type", Param_Spec
);
10185 elsif Ada_Version
>= Ada_2012
then
10186 if Is_Tagged_Type
(Formal_Type
)
10187 and then (not From_Limited_With
(Formal_Type
)
10188 or else not In_Package_Body
)
10192 elsif Nkind_In
(Parent
(Parent
(T
)), N_Accept_Statement
,
10193 N_Accept_Alternative
,
10198 ("invalid use of untagged incomplete type&",
10199 Ptype
, Formal_Type
);
10204 ("invalid use of incomplete type&",
10205 Param_Spec
, Formal_Type
);
10207 -- Further checks on the legality of incomplete types
10208 -- in formal parts are delayed until the freeze point
10209 -- of the enclosing subprogram or access to subprogram.
10213 elsif Ekind
(Formal_Type
) = E_Void
then
10215 ("premature use of&",
10216 Parameter_Type
(Param_Spec
), Formal_Type
);
10219 -- Ada 2012 (AI-142): Handle aliased parameters
10221 if Ada_Version
>= Ada_2012
10222 and then Aliased_Present
(Param_Spec
)
10224 Set_Is_Aliased
(Formal
);
10227 -- Ada 2005 (AI-231): Create and decorate an internal subtype
10228 -- declaration corresponding to the null-excluding type of the
10229 -- formal in the enclosing scope. Finally, replace the parameter
10230 -- type of the formal with the internal subtype.
10232 if Ada_Version
>= Ada_2005
10233 and then Null_Exclusion_Present
(Param_Spec
)
10235 if not Is_Access_Type
(Formal_Type
) then
10237 ("`NOT NULL` allowed only for an access type", Param_Spec
);
10240 if Can_Never_Be_Null
(Formal_Type
)
10241 and then Comes_From_Source
(Related_Nod
)
10244 ("`NOT NULL` not allowed (& already excludes null)",
10245 Param_Spec
, Formal_Type
);
10249 Create_Null_Excluding_Itype
10251 Related_Nod
=> Related_Nod
,
10252 Scope_Id
=> Scope
(Current_Scope
));
10254 -- If the designated type of the itype is an itype that is
10255 -- not frozen yet, we set the Has_Delayed_Freeze attribute
10256 -- on the access subtype, to prevent order-of-elaboration
10257 -- issues in the backend.
10260 -- type T is access procedure;
10261 -- procedure Op (O : not null T);
10263 if Is_Itype
(Directly_Designated_Type
(Formal_Type
))
10265 not Is_Frozen
(Directly_Designated_Type
(Formal_Type
))
10267 Set_Has_Delayed_Freeze
(Formal_Type
);
10272 -- An access formal type
10276 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
10278 -- No need to continue if we already notified errors
10280 if not Present
(Formal_Type
) then
10284 -- Ada 2005 (AI-254)
10287 AD
: constant Node_Id
:=
10288 Access_To_Subprogram_Definition
10289 (Parameter_Type
(Param_Spec
));
10291 if Present
(AD
) and then Protected_Present
(AD
) then
10293 Replace_Anonymous_Access_To_Protected_Subprogram
10299 Set_Etype
(Formal
, Formal_Type
);
10301 -- Deal with default expression if present
10303 Default
:= Expression
(Param_Spec
);
10305 if Present
(Default
) then
10306 Check_SPARK_05_Restriction
10307 ("default expression is not allowed", Default
);
10309 if Out_Present
(Param_Spec
) then
10311 ("default initialization only allowed for IN parameters",
10315 -- Do the special preanalysis of the expression (see section on
10316 -- "Handling of Default Expressions" in the spec of package Sem).
10318 Preanalyze_Spec_Expression
(Default
, Formal_Type
);
10320 -- An access to constant cannot be the default for
10321 -- an access parameter that is an access to variable.
10323 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
10324 and then not Is_Access_Constant
(Formal_Type
)
10325 and then Is_Access_Type
(Etype
(Default
))
10326 and then Is_Access_Constant
(Etype
(Default
))
10329 ("formal that is access to variable cannot be initialized "
10330 & "with an access-to-constant expression", Default
);
10333 -- Check that the designated type of an access parameter's default
10334 -- is not a class-wide type unless the parameter's designated type
10335 -- is also class-wide.
10337 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
10338 and then not Designates_From_Limited_With
(Formal_Type
)
10339 and then Is_Class_Wide_Default
(Default
)
10340 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
10343 ("access to class-wide expression not allowed here", Default
);
10346 -- Check incorrect use of dynamically tagged expressions
10348 if Is_Tagged_Type
(Formal_Type
) then
10349 Check_Dynamically_Tagged_Expression
10351 Typ
=> Formal_Type
,
10352 Related_Nod
=> Default
);
10356 -- Ada 2005 (AI-231): Static checks
10358 if Ada_Version
>= Ada_2005
10359 and then Is_Access_Type
(Etype
(Formal
))
10360 and then Can_Never_Be_Null
(Etype
(Formal
))
10362 Null_Exclusion_Static_Checks
(Param_Spec
);
10365 -- The following checks are relevant when SPARK_Mode is on as these
10366 -- are not standard Ada legality rules.
10368 if SPARK_Mode
= On
then
10369 if Ekind_In
(Scope
(Formal
), E_Function
, E_Generic_Function
) then
10371 -- A function cannot have a parameter of mode IN OUT or OUT
10374 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_Out_Parameter
) then
10376 ("function cannot have parameter of mode `OUT` or "
10377 & "`IN OUT`", Formal
);
10379 -- A function cannot have an effectively volatile formal
10380 -- parameter (SPARK RM 7.1.3(10)).
10382 elsif Is_Effectively_Volatile
(Formal
) then
10384 ("function cannot have a volatile formal parameter",
10388 -- A procedure cannot have an effectively volatile formal
10389 -- parameter of mode IN because it behaves as a constant
10390 -- (SPARK RM 7.1.3(6)).
10392 elsif Ekind
(Scope
(Formal
)) = E_Procedure
10393 and then Ekind
(Formal
) = E_In_Parameter
10394 and then Is_Effectively_Volatile
(Formal
)
10397 ("formal parameter of mode `IN` cannot be volatile", Formal
);
10405 -- If this is the formal part of a function specification, analyze the
10406 -- subtype mark in the context where the formals are visible but not
10407 -- yet usable, and may hide outer homographs.
10409 if Nkind
(Related_Nod
) = N_Function_Specification
then
10410 Analyze_Return_Type
(Related_Nod
);
10413 -- Now set the kind (mode) of each formal
10415 Param_Spec
:= First
(T
);
10416 while Present
(Param_Spec
) loop
10417 Formal
:= Defining_Identifier
(Param_Spec
);
10418 Set_Formal_Mode
(Formal
);
10420 if Ekind
(Formal
) = E_In_Parameter
then
10421 Set_Default_Value
(Formal
, Expression
(Param_Spec
));
10423 if Present
(Expression
(Param_Spec
)) then
10424 Default
:= Expression
(Param_Spec
);
10426 if Is_Scalar_Type
(Etype
(Default
)) then
10427 if Nkind
(Parameter_Type
(Param_Spec
)) /=
10428 N_Access_Definition
10430 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
10434 (Related_Nod
, Parameter_Type
(Param_Spec
));
10437 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
10441 elsif Ekind
(Formal
) = E_Out_Parameter
then
10442 Num_Out_Params
:= Num_Out_Params
+ 1;
10444 if Num_Out_Params
= 1 then
10445 First_Out_Param
:= Formal
;
10448 elsif Ekind
(Formal
) = E_In_Out_Parameter
then
10449 Num_Out_Params
:= Num_Out_Params
+ 1;
10452 -- Skip remaining processing if formal type was in error
10454 if Etype
(Formal
) = Any_Type
or else Error_Posted
(Formal
) then
10455 goto Next_Parameter
;
10458 -- Force call by reference if aliased
10460 if Is_Aliased
(Formal
) then
10461 Set_Mechanism
(Formal
, By_Reference
);
10463 -- Warn if user asked this to be passed by copy
10465 if Convention
(Formal_Type
) = Convention_Ada_Pass_By_Copy
then
10467 ("cannot pass aliased parameter & by copy??", Formal
);
10470 -- Force mechanism if type has Convention Ada_Pass_By_Ref/Copy
10472 elsif Convention
(Formal_Type
) = Convention_Ada_Pass_By_Copy
then
10473 Set_Mechanism
(Formal
, By_Copy
);
10475 elsif Convention
(Formal_Type
) = Convention_Ada_Pass_By_Reference
then
10476 Set_Mechanism
(Formal
, By_Reference
);
10483 if Present
(First_Out_Param
) and then Num_Out_Params
= 1 then
10484 Set_Is_Only_Out_Parameter
(First_Out_Param
);
10486 end Process_Formals
;
10488 ----------------------------
10489 -- Reference_Body_Formals --
10490 ----------------------------
10492 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
) is
10497 if Error_Posted
(Spec
) then
10501 -- Iterate over both lists. They may be of different lengths if the two
10502 -- specs are not conformant.
10504 Fs
:= First_Formal
(Spec
);
10505 Fb
:= First_Formal
(Bod
);
10506 while Present
(Fs
) and then Present
(Fb
) loop
10507 Generate_Reference
(Fs
, Fb
, 'b');
10509 if Style_Check
then
10510 Style
.Check_Identifier
(Fb
, Fs
);
10513 Set_Spec_Entity
(Fb
, Fs
);
10514 Set_Referenced
(Fs
, False);
10518 end Reference_Body_Formals
;
10520 -------------------------
10521 -- Set_Actual_Subtypes --
10522 -------------------------
10524 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
10526 Formal
: Entity_Id
;
10528 First_Stmt
: Node_Id
:= Empty
;
10529 AS_Needed
: Boolean;
10532 -- If this is an empty initialization procedure, no need to create
10533 -- actual subtypes (small optimization).
10535 if Ekind
(Subp
) = E_Procedure
and then Is_Null_Init_Proc
(Subp
) then
10539 Formal
:= First_Formal
(Subp
);
10540 while Present
(Formal
) loop
10541 T
:= Etype
(Formal
);
10543 -- We never need an actual subtype for a constrained formal
10545 if Is_Constrained
(T
) then
10546 AS_Needed
:= False;
10548 -- If we have unknown discriminants, then we do not need an actual
10549 -- subtype, or more accurately we cannot figure it out. Note that
10550 -- all class-wide types have unknown discriminants.
10552 elsif Has_Unknown_Discriminants
(T
) then
10553 AS_Needed
:= False;
10555 -- At this stage we have an unconstrained type that may need an
10556 -- actual subtype. For sure the actual subtype is needed if we have
10557 -- an unconstrained array type.
10559 elsif Is_Array_Type
(T
) then
10562 -- The only other case needing an actual subtype is an unconstrained
10563 -- record type which is an IN parameter (we cannot generate actual
10564 -- subtypes for the OUT or IN OUT case, since an assignment can
10565 -- change the discriminant values. However we exclude the case of
10566 -- initialization procedures, since discriminants are handled very
10567 -- specially in this context, see the section entitled "Handling of
10568 -- Discriminants" in Einfo.
10570 -- We also exclude the case of Discrim_SO_Functions (functions used
10571 -- in front end layout mode for size/offset values), since in such
10572 -- functions only discriminants are referenced, and not only are such
10573 -- subtypes not needed, but they cannot always be generated, because
10574 -- of order of elaboration issues.
10576 elsif Is_Record_Type
(T
)
10577 and then Ekind
(Formal
) = E_In_Parameter
10578 and then Chars
(Formal
) /= Name_uInit
10579 and then not Is_Unchecked_Union
(T
)
10580 and then not Is_Discrim_SO_Function
(Subp
)
10584 -- All other cases do not need an actual subtype
10587 AS_Needed
:= False;
10590 -- Generate actual subtypes for unconstrained arrays and
10591 -- unconstrained discriminated records.
10594 if Nkind
(N
) = N_Accept_Statement
then
10596 -- If expansion is active, the formal is replaced by a local
10597 -- variable that renames the corresponding entry of the
10598 -- parameter block, and it is this local variable that may
10599 -- require an actual subtype.
10601 if Expander_Active
then
10602 Decl
:= Build_Actual_Subtype
(T
, Renamed_Object
(Formal
));
10604 Decl
:= Build_Actual_Subtype
(T
, Formal
);
10607 if Present
(Handled_Statement_Sequence
(N
)) then
10609 First
(Statements
(Handled_Statement_Sequence
(N
)));
10610 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
10611 Mark_Rewrite_Insertion
(Decl
);
10613 -- If the accept statement has no body, there will be no
10614 -- reference to the actuals, so no need to compute actual
10621 Decl
:= Build_Actual_Subtype
(T
, Formal
);
10622 Prepend
(Decl
, Declarations
(N
));
10623 Mark_Rewrite_Insertion
(Decl
);
10626 -- The declaration uses the bounds of an existing object, and
10627 -- therefore needs no constraint checks.
10629 Analyze
(Decl
, Suppress
=> All_Checks
);
10631 -- We need to freeze manually the generated type when it is
10632 -- inserted anywhere else than in a declarative part.
10634 if Present
(First_Stmt
) then
10635 Insert_List_Before_And_Analyze
(First_Stmt
,
10636 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
10638 -- Ditto if the type has a dynamic predicate, because the
10639 -- generated function will mention the actual subtype.
10641 elsif Has_Dynamic_Predicate_Aspect
(T
) then
10642 Insert_List_Before_And_Analyze
(Decl
,
10643 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
10646 if Nkind
(N
) = N_Accept_Statement
10647 and then Expander_Active
10649 Set_Actual_Subtype
(Renamed_Object
(Formal
),
10650 Defining_Identifier
(Decl
));
10652 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
10656 Next_Formal
(Formal
);
10658 end Set_Actual_Subtypes
;
10660 ---------------------
10661 -- Set_Formal_Mode --
10662 ---------------------
10664 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
10665 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
10668 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
10669 -- since we ensure that corresponding actuals are always valid at the
10670 -- point of the call.
10672 if Out_Present
(Spec
) then
10673 if Ekind_In
(Scope
(Formal_Id
), E_Function
, E_Generic_Function
) then
10675 -- [IN] OUT parameters allowed for functions in Ada 2012
10677 if Ada_Version
>= Ada_2012
then
10679 -- Even in Ada 2012 operators can only have IN parameters
10681 if Is_Operator_Symbol_Name
(Chars
(Scope
(Formal_Id
))) then
10682 Error_Msg_N
("operators can only have IN parameters", Spec
);
10685 if In_Present
(Spec
) then
10686 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
10688 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
10691 Set_Has_Out_Or_In_Out_Parameter
(Scope
(Formal_Id
), True);
10693 -- But not in earlier versions of Ada
10696 Error_Msg_N
("functions can only have IN parameters", Spec
);
10697 Set_Ekind
(Formal_Id
, E_In_Parameter
);
10700 elsif In_Present
(Spec
) then
10701 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
10704 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
10705 Set_Never_Set_In_Source
(Formal_Id
, True);
10706 Set_Is_True_Constant
(Formal_Id
, False);
10707 Set_Current_Value
(Formal_Id
, Empty
);
10711 Set_Ekind
(Formal_Id
, E_In_Parameter
);
10714 -- Set Is_Known_Non_Null for access parameters since the language
10715 -- guarantees that access parameters are always non-null. We also set
10716 -- Can_Never_Be_Null, since there is no way to change the value.
10718 if Nkind
(Parameter_Type
(Spec
)) = N_Access_Definition
then
10720 -- Ada 2005 (AI-231): In Ada 95, access parameters are always non-
10721 -- null; In Ada 2005, only if then null_exclusion is explicit.
10723 if Ada_Version
< Ada_2005
10724 or else Can_Never_Be_Null
(Etype
(Formal_Id
))
10726 Set_Is_Known_Non_Null
(Formal_Id
);
10727 Set_Can_Never_Be_Null
(Formal_Id
);
10730 -- Ada 2005 (AI-231): Null-exclusion access subtype
10732 elsif Is_Access_Type
(Etype
(Formal_Id
))
10733 and then Can_Never_Be_Null
(Etype
(Formal_Id
))
10735 Set_Is_Known_Non_Null
(Formal_Id
);
10737 -- We can also set Can_Never_Be_Null (thus preventing some junk
10738 -- access checks) for the case of an IN parameter, which cannot
10739 -- be changed, or for an IN OUT parameter, which can be changed but
10740 -- not to a null value. But for an OUT parameter, the initial value
10741 -- passed in can be null, so we can't set this flag in that case.
10743 if Ekind
(Formal_Id
) /= E_Out_Parameter
then
10744 Set_Can_Never_Be_Null
(Formal_Id
);
10748 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
10749 Set_Formal_Validity
(Formal_Id
);
10750 end Set_Formal_Mode
;
10752 -------------------------
10753 -- Set_Formal_Validity --
10754 -------------------------
10756 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
10758 -- If no validity checking, then we cannot assume anything about the
10759 -- validity of parameters, since we do not know there is any checking
10760 -- of the validity on the call side.
10762 if not Validity_Checks_On
then
10765 -- If validity checking for parameters is enabled, this means we are
10766 -- not supposed to make any assumptions about argument values.
10768 elsif Validity_Check_Parameters
then
10771 -- If we are checking in parameters, we will assume that the caller is
10772 -- also checking parameters, so we can assume the parameter is valid.
10774 elsif Ekind
(Formal_Id
) = E_In_Parameter
10775 and then Validity_Check_In_Params
10777 Set_Is_Known_Valid
(Formal_Id
, True);
10779 -- Similar treatment for IN OUT parameters
10781 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
10782 and then Validity_Check_In_Out_Params
10784 Set_Is_Known_Valid
(Formal_Id
, True);
10786 end Set_Formal_Validity
;
10788 ------------------------
10789 -- Subtype_Conformant --
10790 ------------------------
10792 function Subtype_Conformant
10793 (New_Id
: Entity_Id
;
10794 Old_Id
: Entity_Id
;
10795 Skip_Controlling_Formals
: Boolean := False) return Boolean
10799 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
,
10800 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
10802 end Subtype_Conformant
;
10804 ---------------------
10805 -- Type_Conformant --
10806 ---------------------
10808 function Type_Conformant
10809 (New_Id
: Entity_Id
;
10810 Old_Id
: Entity_Id
;
10811 Skip_Controlling_Formals
: Boolean := False) return Boolean
10815 May_Hide_Profile
:= False;
10817 (New_Id
, Old_Id
, Type_Conformant
, False, Result
,
10818 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
10820 end Type_Conformant
;
10822 -------------------------------
10823 -- Valid_Operator_Definition --
10824 -------------------------------
10826 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
10829 Id
: constant Name_Id
:= Chars
(Designator
);
10833 F
:= First_Formal
(Designator
);
10834 while Present
(F
) loop
10837 if Present
(Default_Value
(F
)) then
10839 ("default values not allowed for operator parameters",
10842 -- For function instantiations that are operators, we must check
10843 -- separately that the corresponding generic only has in-parameters.
10844 -- For subprogram declarations this is done in Set_Formal_Mode. Such
10845 -- an error could not arise in earlier versions of the language.
10847 elsif Ekind
(F
) /= E_In_Parameter
then
10848 Error_Msg_N
("operators can only have IN parameters", F
);
10854 -- Verify that user-defined operators have proper number of arguments
10855 -- First case of operators which can only be unary
10857 if Nam_In
(Id
, Name_Op_Not
, Name_Op_Abs
) then
10860 -- Case of operators which can be unary or binary
10862 elsif Nam_In
(Id
, Name_Op_Add
, Name_Op_Subtract
) then
10863 N_OK
:= (N
in 1 .. 2);
10865 -- All other operators can only be binary
10873 ("incorrect number of arguments for operator", Designator
);
10877 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
10878 and then not Is_Intrinsic_Subprogram
(Designator
)
10881 ("explicit definition of inequality not allowed", Designator
);
10883 end Valid_Operator_Definition
;