1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Expander
; use Expander
;
34 with Exp_Ch6
; use Exp_Ch6
;
35 with Exp_Ch7
; use Exp_Ch7
;
36 with Exp_Ch9
; use Exp_Ch9
;
37 with Exp_Dbug
; use Exp_Dbug
;
38 with Exp_Disp
; use Exp_Disp
;
39 with Exp_Tss
; use Exp_Tss
;
40 with Exp_Util
; use Exp_Util
;
41 with Fname
; use Fname
;
42 with Freeze
; use Freeze
;
43 with Inline
; use Inline
;
44 with Itypes
; use Itypes
;
45 with Lib
.Xref
; use Lib
.Xref
;
46 with Layout
; use Layout
;
47 with Namet
; use Namet
;
49 with Nlists
; use Nlists
;
50 with Nmake
; use Nmake
;
52 with Output
; use Output
;
53 with Restrict
; use Restrict
;
54 with Rident
; use Rident
;
55 with Rtsfind
; use Rtsfind
;
57 with Sem_Aux
; use Sem_Aux
;
58 with Sem_Cat
; use Sem_Cat
;
59 with Sem_Ch3
; use Sem_Ch3
;
60 with Sem_Ch4
; use Sem_Ch4
;
61 with Sem_Ch5
; use Sem_Ch5
;
62 with Sem_Ch8
; use Sem_Ch8
;
63 with Sem_Ch10
; use Sem_Ch10
;
64 with Sem_Ch12
; use Sem_Ch12
;
65 with Sem_Ch13
; use Sem_Ch13
;
66 with Sem_Dim
; use Sem_Dim
;
67 with Sem_Disp
; use Sem_Disp
;
68 with Sem_Dist
; use Sem_Dist
;
69 with Sem_Elim
; use Sem_Elim
;
70 with Sem_Eval
; use Sem_Eval
;
71 with Sem_Mech
; use Sem_Mech
;
72 with Sem_Prag
; use Sem_Prag
;
73 with Sem_Res
; use Sem_Res
;
74 with Sem_Util
; use Sem_Util
;
75 with Sem_Type
; use Sem_Type
;
76 with Sem_Warn
; use Sem_Warn
;
77 with Sinput
; use Sinput
;
78 with Stand
; use Stand
;
79 with Sinfo
; use Sinfo
;
80 with Sinfo
.CN
; use Sinfo
.CN
;
81 with Snames
; use Snames
;
82 with Stringt
; use Stringt
;
84 with Stylesw
; use Stylesw
;
85 with Targparm
; use Targparm
;
86 with Tbuild
; use Tbuild
;
87 with Uintp
; use Uintp
;
88 with Urealp
; use Urealp
;
89 with Validsw
; use Validsw
;
91 package body Sem_Ch6
is
93 May_Hide_Profile
: Boolean := False;
94 -- This flag is used to indicate that two formals in two subprograms being
95 -- checked for conformance differ only in that one is an access parameter
96 -- while the other is of a general access type with the same designated
97 -- type. In this case, if the rest of the signatures match, a call to
98 -- either subprogram may be ambiguous, which is worth a warning. The flag
99 -- is set in Compatible_Types, and the warning emitted in
100 -- New_Overloaded_Entity.
102 -----------------------
103 -- Local Subprograms --
104 -----------------------
106 procedure Analyze_Null_Procedure
108 Is_Completion
: out Boolean);
109 -- A null procedure can be a declaration or (Ada 2012) a completion
111 procedure Analyze_Return_Statement
(N
: Node_Id
);
112 -- Common processing for simple and extended return statements
114 procedure Analyze_Function_Return
(N
: Node_Id
);
115 -- Subsidiary to Analyze_Return_Statement. Called when the return statement
116 -- applies to a [generic] function.
118 procedure Analyze_Return_Type
(N
: Node_Id
);
119 -- Subsidiary to Process_Formals: analyze subtype mark in function
120 -- specification in a context where the formals are visible and hide
123 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
);
124 -- Does all the real work of Analyze_Subprogram_Body. This is split out so
125 -- that we can use RETURN but not skip the debug output at the end.
127 procedure Analyze_Generic_Subprogram_Body
(N
: Node_Id
; Gen_Id
: Entity_Id
);
128 -- Analyze a generic subprogram body. N is the body to be analyzed, and
129 -- Gen_Id is the defining entity Id for the corresponding spec.
131 function Can_Override_Operator
(Subp
: Entity_Id
) return Boolean;
132 -- Returns true if Subp can override a predefined operator.
134 procedure Check_Conformance
137 Ctype
: Conformance_Type
;
139 Conforms
: out Boolean;
140 Err_Loc
: Node_Id
:= Empty
;
141 Get_Inst
: Boolean := False;
142 Skip_Controlling_Formals
: Boolean := False);
143 -- Given two entities, this procedure checks that the profiles associated
144 -- with these entities meet the conformance criterion given by the third
145 -- parameter. If they conform, Conforms is set True and control returns
146 -- to the caller. If they do not conform, Conforms is set to False, and
147 -- in addition, if Errmsg is True on the call, proper messages are output
148 -- to complain about the conformance failure. If Err_Loc is non_Empty
149 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
150 -- error messages are placed on the appropriate part of the construct
151 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
152 -- against a formal access-to-subprogram type so Get_Instance_Of must
155 procedure Check_Subprogram_Order
(N
: Node_Id
);
156 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
157 -- the alpha ordering rule for N if this ordering requirement applicable.
159 procedure Check_Returns
163 Proc
: Entity_Id
:= Empty
);
164 -- Called to check for missing return statements in a function body, or for
165 -- returns present in a procedure body which has No_Return set. HSS is the
166 -- handled statement sequence for the subprogram body. This procedure
167 -- checks all flow paths to make sure they either have return (Mode = 'F',
168 -- used for functions) or do not have a return (Mode = 'P', used for
169 -- No_Return procedures). The flag Err is set if there are any control
170 -- paths not explicitly terminated by a return in the function case, and is
171 -- True otherwise. Proc is the entity for the procedure case and is used
172 -- in posting the warning message.
174 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
);
175 -- In Ada 2012, a primitive equality operator on an untagged record type
176 -- must appear before the type is frozen, and have the same visibility as
177 -- that of the type. This procedure checks that this rule is met, and
178 -- otherwise emits an error on the subprogram declaration and a warning
179 -- on the earlier freeze point if it is easy to locate. In Ada 2012 mode,
180 -- this routine outputs errors (or warnings if -gnatd.E is set). In earlier
181 -- versions of Ada, warnings are output if Warn_On_Ada_2012_Incompatibility
182 -- is set, otherwise the call has no effect.
184 procedure Enter_Overloaded_Entity
(S
: Entity_Id
);
185 -- This procedure makes S, a new overloaded entity, into the first visible
186 -- entity with that name.
188 function Is_Non_Overriding_Operation
190 New_E
: Entity_Id
) return Boolean;
191 -- Enforce the rule given in 12.3(18): a private operation in an instance
192 -- overrides an inherited operation only if the corresponding operation
193 -- was overriding in the generic. This needs to be checked for primitive
194 -- operations of types derived (in the generic unit) from formal private
195 -- or formal derived types.
197 procedure Make_Inequality_Operator
(S
: Entity_Id
);
198 -- Create the declaration for an inequality operator that is implicitly
199 -- created by a user-defined equality operator that yields a boolean.
201 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
);
202 -- Formal_Id is an formal parameter entity. This procedure deals with
203 -- setting the proper validity status for this entity, which depends on
204 -- the kind of parameter and the validity checking mode.
206 ---------------------------------------------
207 -- Analyze_Abstract_Subprogram_Declaration --
208 ---------------------------------------------
210 procedure Analyze_Abstract_Subprogram_Declaration
(N
: Node_Id
) is
211 Designator
: constant Entity_Id
:=
212 Analyze_Subprogram_Specification
(Specification
(N
));
213 Scop
: constant Entity_Id
:= Current_Scope
;
216 Check_SPARK_Restriction
("abstract subprogram is not allowed", N
);
218 Generate_Definition
(Designator
);
219 Set_Contract
(Designator
, Make_Contract
(Sloc
(Designator
)));
220 Set_Is_Abstract_Subprogram
(Designator
);
221 New_Overloaded_Entity
(Designator
);
222 Check_Delayed_Subprogram
(Designator
);
224 Set_Categorization_From_Scope
(Designator
, Scop
);
226 if Ekind
(Scope
(Designator
)) = E_Protected_Type
then
228 ("abstract subprogram not allowed in protected type", N
);
230 -- Issue a warning if the abstract subprogram is neither a dispatching
231 -- operation nor an operation that overrides an inherited subprogram or
232 -- predefined operator, since this most likely indicates a mistake.
234 elsif Warn_On_Redundant_Constructs
235 and then not Is_Dispatching_Operation
(Designator
)
236 and then not Present
(Overridden_Operation
(Designator
))
237 and then (not Is_Operator_Symbol_Name
(Chars
(Designator
))
238 or else Scop
/= Scope
(Etype
(First_Formal
(Designator
))))
241 ("abstract subprogram is not dispatching or overriding?r?", N
);
244 Generate_Reference_To_Formals
(Designator
);
245 Check_Eliminated
(Designator
);
247 if Has_Aspects
(N
) then
248 Analyze_Aspect_Specifications
(N
, Designator
);
250 end Analyze_Abstract_Subprogram_Declaration
;
252 ---------------------------------
253 -- Analyze_Expression_Function --
254 ---------------------------------
256 procedure Analyze_Expression_Function
(N
: Node_Id
) is
257 Loc
: constant Source_Ptr
:= Sloc
(N
);
258 LocX
: constant Source_Ptr
:= Sloc
(Expression
(N
));
259 Expr
: constant Node_Id
:= Expression
(N
);
260 Spec
: constant Node_Id
:= Specification
(N
);
265 -- If the expression is a completion, Prev is the entity whose
266 -- declaration is completed. Def_Id is needed to analyze the spec.
273 -- This is one of the occasions on which we transform the tree during
274 -- semantic analysis. If this is a completion, transform the expression
275 -- function into an equivalent subprogram body, and analyze it.
277 -- Expression functions are inlined unconditionally. The back-end will
278 -- determine whether this is possible.
280 Inline_Processing_Required
:= True;
282 -- Create a specification for the generated body. Types and defauts in
283 -- the profile are copies of the spec, but new entities must be created
284 -- for the unit name and the formals.
286 New_Spec
:= New_Copy_Tree
(Spec
);
287 Set_Defining_Unit_Name
(New_Spec
,
288 Make_Defining_Identifier
(Sloc
(Defining_Unit_Name
(Spec
)),
289 Chars
(Defining_Unit_Name
(Spec
))));
291 if Present
(Parameter_Specifications
(New_Spec
)) then
293 Formal_Spec
: Node_Id
;
297 Formal_Spec
:= First
(Parameter_Specifications
(New_Spec
));
299 -- Create a new formal parameter at the same source position
301 while Present
(Formal_Spec
) loop
302 Def
:= Defining_Identifier
(Formal_Spec
);
303 Set_Defining_Identifier
(Formal_Spec
,
304 Make_Defining_Identifier
(Sloc
(Def
),
305 Chars
=> Chars
(Def
)));
311 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
313 -- If there are previous overloadable entities with the same name,
314 -- check whether any of them is completed by the expression function.
316 if Present
(Prev
) and then Is_Overloadable
(Prev
) then
317 Def_Id
:= Analyze_Subprogram_Specification
(Spec
);
318 Prev
:= Find_Corresponding_Spec
(N
);
321 Ret
:= Make_Simple_Return_Statement
(LocX
, Expression
(N
));
324 Make_Subprogram_Body
(Loc
,
325 Specification
=> New_Spec
,
326 Declarations
=> Empty_List
,
327 Handled_Statement_Sequence
=>
328 Make_Handled_Sequence_Of_Statements
(LocX
,
329 Statements
=> New_List
(Ret
)));
331 -- If the expression completes a generic subprogram, we must create a
332 -- separate node for the body, because at instantiation the original
333 -- node of the generic copy must be a generic subprogram body, and
334 -- cannot be a expression function. Otherwise we just rewrite the
335 -- expression with the non-generic body.
337 if Present
(Prev
) and then Ekind
(Prev
) = E_Generic_Function
then
338 Insert_After
(N
, New_Body
);
340 -- Propagate any aspects or pragmas that apply to the expression
341 -- function to the proper body when the expression function acts
344 if Has_Aspects
(N
) then
345 Move_Aspects
(N
, To
=> New_Body
);
348 Relocate_Pragmas_To_Body
(New_Body
);
350 Rewrite
(N
, Make_Null_Statement
(Loc
));
351 Set_Has_Completion
(Prev
, False);
354 Set_Is_Inlined
(Prev
);
356 -- If the expression function is a completion, the previous declaration
357 -- must come from source. We know already that appears in the current
358 -- scope. The entity itself may be internally created if within a body
361 elsif Present
(Prev
) and then Comes_From_Source
(Parent
(Prev
)) then
362 Set_Has_Completion
(Prev
, False);
364 -- An expression function that is a completion freezes the
365 -- expression. This means freezing the return type, and if it is
366 -- an access type, freezing its designated type as well.
368 -- Note that we cannot defer this freezing to the analysis of the
369 -- expression itself, because a freeze node might appear in a nested
370 -- scope, leading to an elaboration order issue in gigi.
372 Freeze_Before
(N
, Etype
(Prev
));
374 if Is_Access_Type
(Etype
(Prev
)) then
375 Freeze_Before
(N
, Designated_Type
(Etype
(Prev
)));
378 -- For navigation purposes, indicate that the function is a body
380 Generate_Reference
(Prev
, Defining_Entity
(N
), 'b', Force
=> True);
381 Rewrite
(N
, New_Body
);
383 -- Correct the parent pointer of the aspect specification list to
384 -- reference the rewritten node.
386 if Has_Aspects
(N
) then
387 Set_Parent
(Aspect_Specifications
(N
), N
);
390 -- Propagate any pragmas that apply to the expression function to the
391 -- proper body when the expression function acts as a completion.
392 -- Aspects are automatically transfered because of node rewriting.
394 Relocate_Pragmas_To_Body
(N
);
397 -- Prev is the previous entity with the same name, but it is can
398 -- be an unrelated spec that is not completed by the expression
399 -- function. In that case the relevant entity is the one in the body.
400 -- Not clear that the backend can inline it in this case ???
402 if Has_Completion
(Prev
) then
403 Set_Is_Inlined
(Prev
);
405 -- The formals of the expression function are body formals,
406 -- and do not appear in the ali file, which will only contain
407 -- references to the formals of the original subprogram spec.
414 F1
:= First_Formal
(Def_Id
);
415 F2
:= First_Formal
(Prev
);
417 while Present
(F1
) loop
418 Set_Spec_Entity
(F1
, F2
);
425 Set_Is_Inlined
(Defining_Entity
(New_Body
));
428 -- If this is not a completion, create both a declaration and a body, so
429 -- that the expression can be inlined whenever possible.
432 -- An expression function that is not a completion is not a
433 -- subprogram declaration, and thus cannot appear in a protected
436 if Nkind
(Parent
(N
)) = N_Protected_Definition
then
438 ("an expression function is not a legal protected operation", N
);
441 Rewrite
(N
, Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
));
443 -- Correct the parent pointer of the aspect specification list to
444 -- reference the rewritten node.
446 if Has_Aspects
(N
) then
447 Set_Parent
(Aspect_Specifications
(N
), N
);
451 Set_Is_Inlined
(Defining_Entity
(N
));
453 -- Establish the linkages between the spec and the body. These are
454 -- used when the expression function acts as the prefix of attribute
455 -- 'Access in order to freeze the original expression which has been
456 -- moved to the generated body.
458 Set_Corresponding_Body
(N
, Defining_Entity
(New_Body
));
459 Set_Corresponding_Spec
(New_Body
, Defining_Entity
(N
));
461 -- To prevent premature freeze action, insert the new body at the end
462 -- of the current declarations, or at the end of the package spec.
463 -- However, resolve usage names now, to prevent spurious visibility
464 -- on later entities. Note that the function can now be called in
465 -- the current declarative part, which will appear to be prior to
466 -- the presence of the body in the code. There are nevertheless no
467 -- order of elaboration issues because all name resolution has taken
468 -- place at the point of declaration.
471 Decls
: List_Id
:= List_Containing
(N
);
472 Par
: constant Node_Id
:= Parent
(Decls
);
473 Id
: constant Entity_Id
:= Defining_Entity
(N
);
476 if Nkind
(Par
) = N_Package_Specification
477 and then Decls
= Visible_Declarations
(Par
)
478 and then Present
(Private_Declarations
(Par
))
479 and then not Is_Empty_List
(Private_Declarations
(Par
))
481 Decls
:= Private_Declarations
(Par
);
484 Insert_After
(Last
(Decls
), New_Body
);
486 Install_Formals
(Id
);
488 -- Preanalyze the expression for name capture, except in an
489 -- instance, where this has been done during generic analysis,
490 -- and will be redone when analyzing the body.
493 Expr
: constant Node_Id
:= Expression
(Ret
);
496 Set_Parent
(Expr
, Ret
);
498 if not In_Instance
then
499 Preanalyze_Spec_Expression
(Expr
, Etype
(Id
));
507 -- If the return expression is a static constant, we suppress warning
508 -- messages on unused formals, which in most cases will be noise.
510 Set_Is_Trivial_Subprogram
(Defining_Entity
(New_Body
),
511 Is_OK_Static_Expression
(Expr
));
512 end Analyze_Expression_Function
;
514 ----------------------------------------
515 -- Analyze_Extended_Return_Statement --
516 ----------------------------------------
518 procedure Analyze_Extended_Return_Statement
(N
: Node_Id
) is
520 Check_Compiler_Unit
("extended return statement", N
);
521 Analyze_Return_Statement
(N
);
522 end Analyze_Extended_Return_Statement
;
524 ----------------------------
525 -- Analyze_Function_Call --
526 ----------------------------
528 procedure Analyze_Function_Call
(N
: Node_Id
) is
529 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
530 Func_Nam
: constant Node_Id
:= Name
(N
);
536 -- A call of the form A.B (X) may be an Ada 2005 call, which is
537 -- rewritten as B (A, X). If the rewriting is successful, the call
538 -- has been analyzed and we just return.
540 if Nkind
(Func_Nam
) = N_Selected_Component
541 and then Name
(N
) /= Func_Nam
542 and then Is_Rewrite_Substitution
(N
)
543 and then Present
(Etype
(N
))
548 -- If error analyzing name, then set Any_Type as result type and return
550 if Etype
(Func_Nam
) = Any_Type
then
551 Set_Etype
(N
, Any_Type
);
555 -- Otherwise analyze the parameters
557 if Present
(Actuals
) then
558 Actual
:= First
(Actuals
);
559 while Present
(Actual
) loop
561 Check_Parameterless_Call
(Actual
);
567 end Analyze_Function_Call
;
569 -----------------------------
570 -- Analyze_Function_Return --
571 -----------------------------
573 procedure Analyze_Function_Return
(N
: Node_Id
) is
574 Loc
: constant Source_Ptr
:= Sloc
(N
);
575 Stm_Entity
: constant Entity_Id
:= Return_Statement_Entity
(N
);
576 Scope_Id
: constant Entity_Id
:= Return_Applies_To
(Stm_Entity
);
578 R_Type
: constant Entity_Id
:= Etype
(Scope_Id
);
579 -- Function result subtype
581 procedure Check_Limited_Return
(Expr
: Node_Id
);
582 -- Check the appropriate (Ada 95 or Ada 2005) rules for returning
583 -- limited types. Used only for simple return statements.
584 -- Expr is the expression returned.
586 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
);
587 -- Check that the return_subtype_indication properly matches the result
588 -- subtype of the function, as required by RM-6.5(5.1/2-5.3/2).
590 --------------------------
591 -- Check_Limited_Return --
592 --------------------------
594 procedure Check_Limited_Return
(Expr
: Node_Id
) is
596 -- Ada 2005 (AI-318-02): Return-by-reference types have been
597 -- removed and replaced by anonymous access results. This is an
598 -- incompatibility with Ada 95. Not clear whether this should be
599 -- enforced yet or perhaps controllable with special switch. ???
601 -- A limited interface that is not immutably limited is OK.
603 if Is_Limited_Interface
(R_Type
)
605 not (Is_Task_Interface
(R_Type
)
606 or else Is_Protected_Interface
(R_Type
)
607 or else Is_Synchronized_Interface
(R_Type
))
611 elsif Is_Limited_Type
(R_Type
)
612 and then not Is_Interface
(R_Type
)
613 and then Comes_From_Source
(N
)
614 and then not In_Instance_Body
615 and then not OK_For_Limited_Init_In_05
(R_Type
, Expr
)
619 if Ada_Version
>= Ada_2005
620 and then not Debug_Flag_Dot_L
621 and then not GNAT_Mode
624 ("(Ada 2005) cannot copy object of a limited type " &
625 "(RM-2005 6.5(5.5/2))", Expr
);
627 if Is_Limited_View
(R_Type
) then
629 ("\return by reference not permitted in Ada 2005", Expr
);
632 -- Warn in Ada 95 mode, to give folks a heads up about this
635 -- In GNAT mode, this is just a warning, to allow it to be
636 -- evilly turned off. Otherwise it is a real error.
638 -- In a generic context, simplify the warning because it makes
639 -- no sense to discuss pass-by-reference or copy.
641 elsif Warn_On_Ada_2005_Compatibility
or GNAT_Mode
then
642 if Inside_A_Generic
then
644 ("return of limited object not permitted in Ada 2005 "
645 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
647 elsif Is_Limited_View
(R_Type
) then
649 ("return by reference not permitted in Ada 2005 "
650 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
653 ("cannot copy object of a limited type in Ada 2005 "
654 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
657 -- Ada 95 mode, compatibility warnings disabled
660 return; -- skip continuation messages below
663 if not Inside_A_Generic
then
665 ("\consider switching to return of access type", Expr
);
666 Explain_Limited_Type
(R_Type
, Expr
);
669 end Check_Limited_Return
;
671 -------------------------------------
672 -- Check_Return_Subtype_Indication --
673 -------------------------------------
675 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
) is
676 Return_Obj
: constant Node_Id
:= Defining_Identifier
(Obj_Decl
);
678 R_Stm_Type
: constant Entity_Id
:= Etype
(Return_Obj
);
679 -- Subtype given in the extended return statement (must match R_Type)
681 Subtype_Ind
: constant Node_Id
:=
682 Object_Definition
(Original_Node
(Obj_Decl
));
684 R_Type_Is_Anon_Access
: constant Boolean :=
686 E_Anonymous_Access_Subprogram_Type
,
687 E_Anonymous_Access_Protected_Subprogram_Type
,
688 E_Anonymous_Access_Type
);
689 -- True if return type of the function is an anonymous access type
690 -- Can't we make Is_Anonymous_Access_Type in einfo ???
692 R_Stm_Type_Is_Anon_Access
: constant Boolean :=
693 Ekind_In
(R_Stm_Type
,
694 E_Anonymous_Access_Subprogram_Type
,
695 E_Anonymous_Access_Protected_Subprogram_Type
,
696 E_Anonymous_Access_Type
);
697 -- True if type of the return object is an anonymous access type
699 procedure Error_No_Match
(N
: Node_Id
);
700 -- Output error messages for case where types do not statically
701 -- match. N is the location for the messages.
707 procedure Error_No_Match
(N
: Node_Id
) is
710 ("subtype must statically match function result subtype", N
);
712 if not Predicates_Match
(R_Stm_Type
, R_Type
) then
713 Error_Msg_Node_2
:= R_Type
;
715 ("\predicate of & does not match predicate of &",
720 -- Start of processing for Check_Return_Subtype_Indication
723 -- First, avoid cascaded errors
725 if Error_Posted
(Obj_Decl
) or else Error_Posted
(Subtype_Ind
) then
729 -- "return access T" case; check that the return statement also has
730 -- "access T", and that the subtypes statically match:
731 -- if this is an access to subprogram the signatures must match.
733 if R_Type_Is_Anon_Access
then
734 if R_Stm_Type_Is_Anon_Access
then
736 Ekind
(Designated_Type
(R_Stm_Type
)) /= E_Subprogram_Type
738 if Base_Type
(Designated_Type
(R_Stm_Type
)) /=
739 Base_Type
(Designated_Type
(R_Type
))
740 or else not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
)
742 Error_No_Match
(Subtype_Mark
(Subtype_Ind
));
746 -- For two anonymous access to subprogram types, the
747 -- types themselves must be type conformant.
749 if not Conforming_Types
750 (R_Stm_Type
, R_Type
, Fully_Conformant
)
752 Error_No_Match
(Subtype_Ind
);
757 Error_Msg_N
("must use anonymous access type", Subtype_Ind
);
760 -- If the return object is of an anonymous access type, then report
761 -- an error if the function's result type is not also anonymous.
763 elsif R_Stm_Type_Is_Anon_Access
764 and then not R_Type_Is_Anon_Access
766 Error_Msg_N
("anonymous access not allowed for function with " &
767 "named access result", Subtype_Ind
);
769 -- Subtype indication case: check that the return object's type is
770 -- covered by the result type, and that the subtypes statically match
771 -- when the result subtype is constrained. Also handle record types
772 -- with unknown discriminants for which we have built the underlying
773 -- record view. Coverage is needed to allow specific-type return
774 -- objects when the result type is class-wide (see AI05-32).
776 elsif Covers
(Base_Type
(R_Type
), Base_Type
(R_Stm_Type
))
777 or else (Is_Underlying_Record_View
(Base_Type
(R_Stm_Type
))
781 Underlying_Record_View
(Base_Type
(R_Stm_Type
))))
783 -- A null exclusion may be present on the return type, on the
784 -- function specification, on the object declaration or on the
787 if Is_Access_Type
(R_Type
)
789 (Can_Never_Be_Null
(R_Type
)
790 or else Null_Exclusion_Present
(Parent
(Scope_Id
))) /=
791 Can_Never_Be_Null
(R_Stm_Type
)
793 Error_No_Match
(Subtype_Ind
);
796 -- AI05-103: for elementary types, subtypes must statically match
798 if Is_Constrained
(R_Type
)
799 or else Is_Access_Type
(R_Type
)
801 if not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
) then
802 Error_No_Match
(Subtype_Ind
);
806 -- All remaining cases are illegal
808 -- Note: previous versions of this subprogram allowed the return
809 -- value to be the ancestor of the return type if the return type
810 -- was a null extension. This was plainly incorrect.
814 ("wrong type for return_subtype_indication", Subtype_Ind
);
816 end Check_Return_Subtype_Indication
;
818 ---------------------
819 -- Local Variables --
820 ---------------------
824 -- Start of processing for Analyze_Function_Return
827 Set_Return_Present
(Scope_Id
);
829 if Nkind
(N
) = N_Simple_Return_Statement
then
830 Expr
:= Expression
(N
);
832 -- Guard against a malformed expression. The parser may have tried to
833 -- recover but the node is not analyzable.
835 if Nkind
(Expr
) = N_Error
then
836 Set_Etype
(Expr
, Any_Type
);
837 Expander_Mode_Save_And_Set
(False);
841 -- The resolution of a controlled [extension] aggregate associated
842 -- with a return statement creates a temporary which needs to be
843 -- finalized on function exit. Wrap the return statement inside a
844 -- block so that the finalization machinery can detect this case.
845 -- This early expansion is done only when the return statement is
846 -- not part of a handled sequence of statements.
848 if Nkind_In
(Expr
, N_Aggregate
,
849 N_Extension_Aggregate
)
850 and then Needs_Finalization
(R_Type
)
851 and then Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
854 Make_Block_Statement
(Loc
,
855 Handled_Statement_Sequence
=>
856 Make_Handled_Sequence_Of_Statements
(Loc
,
857 Statements
=> New_List
(Relocate_Node
(N
)))));
863 Analyze_And_Resolve
(Expr
, R_Type
);
864 Check_Limited_Return
(Expr
);
867 -- RETURN only allowed in SPARK as the last statement in function
869 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
871 (Nkind
(Parent
(Parent
(N
))) /= N_Subprogram_Body
872 or else Present
(Next
(N
)))
874 Check_SPARK_Restriction
875 ("RETURN should be the last statement in function", N
);
879 Check_SPARK_Restriction
("extended RETURN is not allowed", N
);
881 -- Analyze parts specific to extended_return_statement:
884 Obj_Decl
: constant Node_Id
:=
885 Last
(Return_Object_Declarations
(N
));
886 Has_Aliased
: constant Boolean := Aliased_Present
(Obj_Decl
);
887 HSS
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
890 Expr
:= Expression
(Obj_Decl
);
892 -- Note: The check for OK_For_Limited_Init will happen in
893 -- Analyze_Object_Declaration; we treat it as a normal
894 -- object declaration.
896 Set_Is_Return_Object
(Defining_Identifier
(Obj_Decl
));
899 Check_Return_Subtype_Indication
(Obj_Decl
);
901 if Present
(HSS
) then
904 if Present
(Exception_Handlers
(HSS
)) then
906 -- ???Has_Nested_Block_With_Handler needs to be set.
907 -- Probably by creating an actual N_Block_Statement.
908 -- Probably in Expand.
914 -- Mark the return object as referenced, since the return is an
915 -- implicit reference of the object.
917 Set_Referenced
(Defining_Identifier
(Obj_Decl
));
919 Check_References
(Stm_Entity
);
921 -- Check RM 6.5 (5.9/3)
924 if Ada_Version
< Ada_2012
then
926 -- Shouldn't this test Warn_On_Ada_2012_Compatibility ???
927 -- Can it really happen (extended return???)
930 ("aliased only allowed for limited return objects "
931 & "in Ada 2012??", N
);
933 elsif not Is_Limited_View
(R_Type
) then
934 Error_Msg_N
("aliased only allowed for limited"
935 & " return objects", N
);
941 -- Case of Expr present
945 -- Defend against previous errors
947 and then Nkind
(Expr
) /= N_Empty
948 and then Present
(Etype
(Expr
))
950 -- Apply constraint check. Note that this is done before the implicit
951 -- conversion of the expression done for anonymous access types to
952 -- ensure correct generation of the null-excluding check associated
953 -- with null-excluding expressions found in return statements.
955 Apply_Constraint_Check
(Expr
, R_Type
);
957 -- Ada 2005 (AI-318-02): When the result type is an anonymous access
958 -- type, apply an implicit conversion of the expression to that type
959 -- to force appropriate static and run-time accessibility checks.
961 if Ada_Version
>= Ada_2005
962 and then Ekind
(R_Type
) = E_Anonymous_Access_Type
964 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
965 Analyze_And_Resolve
(Expr
, R_Type
);
967 -- If this is a local anonymous access to subprogram, the
968 -- accessibility check can be applied statically. The return is
969 -- illegal if the access type of the return expression is declared
970 -- inside of the subprogram (except if it is the subtype indication
971 -- of an extended return statement).
973 elsif Ekind
(R_Type
) = E_Anonymous_Access_Subprogram_Type
then
974 if not Comes_From_Source
(Current_Scope
)
975 or else Ekind
(Current_Scope
) = E_Return_Statement
980 Scope_Depth
(Scope
(Etype
(Expr
))) >= Scope_Depth
(Scope_Id
)
982 Error_Msg_N
("cannot return local access to subprogram", N
);
985 -- The expression cannot be of a formal incomplete type
987 elsif Ekind
(Etype
(Expr
)) = E_Incomplete_Type
988 and then Is_Generic_Type
(Etype
(Expr
))
991 ("cannot return expression of a formal incomplete type", N
);
994 -- If the result type is class-wide, then check that the return
995 -- expression's type is not declared at a deeper level than the
996 -- function (RM05-6.5(5.6/2)).
998 if Ada_Version
>= Ada_2005
999 and then Is_Class_Wide_Type
(R_Type
)
1001 if Type_Access_Level
(Etype
(Expr
)) >
1002 Subprogram_Access_Level
(Scope_Id
)
1005 ("level of return expression type is deeper than " &
1006 "class-wide function!", Expr
);
1010 -- Check incorrect use of dynamically tagged expression
1012 if Is_Tagged_Type
(R_Type
) then
1013 Check_Dynamically_Tagged_Expression
1019 -- ??? A real run-time accessibility check is needed in cases
1020 -- involving dereferences of access parameters. For now we just
1021 -- check the static cases.
1023 if (Ada_Version
< Ada_2005
or else Debug_Flag_Dot_L
)
1024 and then Is_Limited_View
(Etype
(Scope_Id
))
1025 and then Object_Access_Level
(Expr
) >
1026 Subprogram_Access_Level
(Scope_Id
)
1028 -- Suppress the message in a generic, where the rewriting
1031 if Inside_A_Generic
then
1036 Make_Raise_Program_Error
(Loc
,
1037 Reason
=> PE_Accessibility_Check_Failed
));
1040 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1041 Error_Msg_N
("cannot return a local value by reference<<", N
);
1042 Error_Msg_NE
("\& [<<", N
, Standard_Program_Error
);
1046 if Known_Null
(Expr
)
1047 and then Nkind
(Parent
(Scope_Id
)) = N_Function_Specification
1048 and then Null_Exclusion_Present
(Parent
(Scope_Id
))
1050 Apply_Compile_Time_Constraint_Error
1052 Msg
=> "(Ada 2005) null not allowed for "
1053 & "null-excluding return??",
1054 Reason
=> CE_Null_Not_Allowed
);
1057 end Analyze_Function_Return
;
1059 -------------------------------------
1060 -- Analyze_Generic_Subprogram_Body --
1061 -------------------------------------
1063 procedure Analyze_Generic_Subprogram_Body
1067 Gen_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Gen_Id
);
1068 Kind
: constant Entity_Kind
:= Ekind
(Gen_Id
);
1069 Body_Id
: Entity_Id
;
1074 -- Copy body and disable expansion while analyzing the generic For a
1075 -- stub, do not copy the stub (which would load the proper body), this
1076 -- will be done when the proper body is analyzed.
1078 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1079 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
1084 Spec
:= Specification
(N
);
1086 -- Within the body of the generic, the subprogram is callable, and
1087 -- behaves like the corresponding non-generic unit.
1089 Body_Id
:= Defining_Entity
(Spec
);
1091 if Kind
= E_Generic_Procedure
1092 and then Nkind
(Spec
) /= N_Procedure_Specification
1094 Error_Msg_N
("invalid body for generic procedure ", Body_Id
);
1097 elsif Kind
= E_Generic_Function
1098 and then Nkind
(Spec
) /= N_Function_Specification
1100 Error_Msg_N
("invalid body for generic function ", Body_Id
);
1104 Set_Corresponding_Body
(Gen_Decl
, Body_Id
);
1106 if Has_Completion
(Gen_Id
)
1107 and then Nkind
(Parent
(N
)) /= N_Subunit
1109 Error_Msg_N
("duplicate generic body", N
);
1112 Set_Has_Completion
(Gen_Id
);
1115 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1116 Set_Ekind
(Defining_Entity
(Specification
(N
)), Kind
);
1118 Set_Corresponding_Spec
(N
, Gen_Id
);
1121 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1122 Set_Cunit_Entity
(Current_Sem_Unit
, Defining_Entity
(N
));
1125 -- Make generic parameters immediately visible in the body. They are
1126 -- needed to process the formals declarations. Then make the formals
1127 -- visible in a separate step.
1129 Push_Scope
(Gen_Id
);
1133 First_Ent
: Entity_Id
;
1136 First_Ent
:= First_Entity
(Gen_Id
);
1139 while Present
(E
) and then not Is_Formal
(E
) loop
1144 Set_Use
(Generic_Formal_Declarations
(Gen_Decl
));
1146 -- Now generic formals are visible, and the specification can be
1147 -- analyzed, for subsequent conformance check.
1149 Body_Id
:= Analyze_Subprogram_Specification
(Spec
);
1151 -- Make formal parameters visible
1155 -- E is the first formal parameter, we loop through the formals
1156 -- installing them so that they will be visible.
1158 Set_First_Entity
(Gen_Id
, E
);
1159 while Present
(E
) loop
1165 -- Visible generic entity is callable within its own body
1167 Set_Ekind
(Gen_Id
, Ekind
(Body_Id
));
1168 Set_Contract
(Body_Id
, Make_Contract
(Sloc
(Body_Id
)));
1169 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
1170 Set_Convention
(Body_Id
, Convention
(Gen_Id
));
1171 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Gen_Id
));
1172 Set_Scope
(Body_Id
, Scope
(Gen_Id
));
1173 Check_Fully_Conformant
(Body_Id
, Gen_Id
, Body_Id
);
1175 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1177 -- No body to analyze, so restore state of generic unit
1179 Set_Ekind
(Gen_Id
, Kind
);
1180 Set_Ekind
(Body_Id
, Kind
);
1182 if Present
(First_Ent
) then
1183 Set_First_Entity
(Gen_Id
, First_Ent
);
1190 -- If this is a compilation unit, it must be made visible explicitly,
1191 -- because the compilation of the declaration, unlike other library
1192 -- unit declarations, does not. If it is not a unit, the following
1193 -- is redundant but harmless.
1195 Set_Is_Immediately_Visible
(Gen_Id
);
1196 Reference_Body_Formals
(Gen_Id
, Body_Id
);
1198 if Is_Child_Unit
(Gen_Id
) then
1199 Generate_Reference
(Gen_Id
, Scope
(Gen_Id
), 'k', False);
1202 Set_Actual_Subtypes
(N
, Current_Scope
);
1204 -- Deal with [refined] preconditions, postconditions, Contract_Cases,
1205 -- invariants and predicates associated with the body and its spec.
1206 -- Note that this is not pure expansion as Expand_Subprogram_Contract
1207 -- prepares the contract assertions for generic subprograms or for
1208 -- ASIS. Do not generate contract checks in SPARK mode.
1210 if not GNATprove_Mode
then
1211 Expand_Subprogram_Contract
(N
, Gen_Id
, Body_Id
);
1214 -- If the generic unit carries pre- or post-conditions, copy them
1215 -- to the original generic tree, so that they are properly added
1216 -- to any instantiation.
1219 Orig
: constant Node_Id
:= Original_Node
(N
);
1223 Cond
:= First
(Declarations
(N
));
1224 while Present
(Cond
) loop
1225 if Nkind
(Cond
) = N_Pragma
1226 and then Pragma_Name
(Cond
) = Name_Check
1228 Prepend
(New_Copy_Tree
(Cond
), Declarations
(Orig
));
1230 elsif Nkind
(Cond
) = N_Pragma
1231 and then Pragma_Name
(Cond
) = Name_Postcondition
1233 Set_Ekind
(Defining_Entity
(Orig
), Ekind
(Gen_Id
));
1234 Prepend
(New_Copy_Tree
(Cond
), Declarations
(Orig
));
1243 Check_SPARK_Mode_In_Generic
(N
);
1245 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
1246 Set_SPARK_Pragma_Inherited
(Body_Id
, True);
1248 Analyze_Declarations
(Declarations
(N
));
1250 Analyze
(Handled_Statement_Sequence
(N
));
1252 Save_Global_References
(Original_Node
(N
));
1254 -- Prior to exiting the scope, include generic formals again (if any
1255 -- are present) in the set of local entities.
1257 if Present
(First_Ent
) then
1258 Set_First_Entity
(Gen_Id
, First_Ent
);
1261 Check_References
(Gen_Id
);
1264 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Current_Scope
);
1266 Check_Subprogram_Order
(N
);
1268 -- Outside of its body, unit is generic again
1270 Set_Ekind
(Gen_Id
, Kind
);
1271 Generate_Reference
(Gen_Id
, Body_Id
, 'b', Set_Ref
=> False);
1274 Style
.Check_Identifier
(Body_Id
, Gen_Id
);
1278 end Analyze_Generic_Subprogram_Body
;
1280 ----------------------------
1281 -- Analyze_Null_Procedure --
1282 ----------------------------
1284 procedure Analyze_Null_Procedure
1286 Is_Completion
: out Boolean)
1288 Loc
: constant Source_Ptr
:= Sloc
(N
);
1289 Spec
: constant Node_Id
:= Specification
(N
);
1290 Designator
: Entity_Id
;
1292 Null_Body
: Node_Id
:= Empty
;
1296 -- Capture the profile of the null procedure before analysis, for
1297 -- expansion at the freeze point and at each point of call. The body is
1298 -- used if the procedure has preconditions, or if it is a completion. In
1299 -- the first case the body is analyzed at the freeze point, in the other
1300 -- it replaces the null procedure declaration.
1303 Make_Subprogram_Body
(Loc
,
1304 Specification
=> New_Copy_Tree
(Spec
),
1305 Declarations
=> New_List
,
1306 Handled_Statement_Sequence
=>
1307 Make_Handled_Sequence_Of_Statements
(Loc
,
1308 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
1310 -- Create new entities for body and formals
1312 Set_Defining_Unit_Name
(Specification
(Null_Body
),
1313 Make_Defining_Identifier
1314 (Sloc
(Defining_Entity
(N
)),
1315 Chars
(Defining_Entity
(N
))));
1317 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1318 while Present
(Form
) loop
1319 Set_Defining_Identifier
(Form
,
1320 Make_Defining_Identifier
1321 (Sloc
(Defining_Identifier
(Form
)),
1322 Chars
(Defining_Identifier
(Form
))));
1326 -- Determine whether the null procedure may be a completion of a generic
1327 -- suprogram, in which case we use the new null body as the completion
1328 -- and set minimal semantic information on the original declaration,
1329 -- which is rewritten as a null statement.
1331 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
1333 if Present
(Prev
) and then Is_Generic_Subprogram
(Prev
) then
1334 Insert_Before
(N
, Null_Body
);
1335 Set_Ekind
(Defining_Entity
(N
), Ekind
(Prev
));
1336 Set_Contract
(Defining_Entity
(N
), Make_Contract
(Loc
));
1338 Rewrite
(N
, Make_Null_Statement
(Loc
));
1339 Analyze_Generic_Subprogram_Body
(Null_Body
, Prev
);
1340 Is_Completion
:= True;
1344 -- Resolve the types of the formals now, because the freeze point
1345 -- may appear in a different context, e.g. an instantiation.
1347 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1348 while Present
(Form
) loop
1349 if Nkind
(Parameter_Type
(Form
)) /= N_Access_Definition
then
1350 Find_Type
(Parameter_Type
(Form
));
1353 No
(Access_To_Subprogram_Definition
(Parameter_Type
(Form
)))
1355 Find_Type
(Subtype_Mark
(Parameter_Type
(Form
)));
1358 -- The case of a null procedure with a formal that is an
1359 -- access_to_subprogram type, and that is used as an actual
1360 -- in an instantiation is left to the enthusiastic reader.
1369 -- If there are previous overloadable entities with the same name,
1370 -- check whether any of them is completed by the null procedure.
1372 if Present
(Prev
) and then Is_Overloadable
(Prev
) then
1373 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1374 Prev
:= Find_Corresponding_Spec
(N
);
1377 if No
(Prev
) or else not Comes_From_Source
(Prev
) then
1378 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1379 Set_Has_Completion
(Designator
);
1381 -- Signal to caller that this is a procedure declaration
1383 Is_Completion
:= False;
1385 -- Null procedures are always inlined, but generic formal subprograms
1386 -- which appear as such in the internal instance of formal packages,
1387 -- need no completion and are not marked Inline.
1390 and then Nkind
(N
) /= N_Formal_Concrete_Subprogram_Declaration
1392 Set_Corresponding_Body
(N
, Defining_Entity
(Null_Body
));
1393 Set_Body_To_Inline
(N
, Null_Body
);
1394 Set_Is_Inlined
(Designator
);
1398 -- The null procedure is a completion. We unconditionally rewrite
1399 -- this as a null body (even if expansion is not active), because
1400 -- there are various error checks that are applied on this body
1401 -- when it is analyzed (e.g. correct aspect placement).
1403 Is_Completion
:= True;
1404 Rewrite
(N
, Null_Body
);
1407 end Analyze_Null_Procedure
;
1409 -----------------------------
1410 -- Analyze_Operator_Symbol --
1411 -----------------------------
1413 -- An operator symbol such as "+" or "and" may appear in context where the
1414 -- literal denotes an entity name, such as "+"(x, y) or in context when it
1415 -- is just a string, as in (conjunction = "or"). In these cases the parser
1416 -- generates this node, and the semantics does the disambiguation. Other
1417 -- such case are actuals in an instantiation, the generic unit in an
1418 -- instantiation, and pragma arguments.
1420 procedure Analyze_Operator_Symbol
(N
: Node_Id
) is
1421 Par
: constant Node_Id
:= Parent
(N
);
1424 if (Nkind
(Par
) = N_Function_Call
and then N
= Name
(Par
))
1425 or else Nkind
(Par
) = N_Function_Instantiation
1426 or else (Nkind
(Par
) = N_Indexed_Component
and then N
= Prefix
(Par
))
1427 or else (Nkind
(Par
) = N_Pragma_Argument_Association
1428 and then not Is_Pragma_String_Literal
(Par
))
1429 or else Nkind
(Par
) = N_Subprogram_Renaming_Declaration
1430 or else (Nkind
(Par
) = N_Attribute_Reference
1431 and then Attribute_Name
(Par
) /= Name_Value
)
1433 Find_Direct_Name
(N
);
1436 Change_Operator_Symbol_To_String_Literal
(N
);
1439 end Analyze_Operator_Symbol
;
1441 -----------------------------------
1442 -- Analyze_Parameter_Association --
1443 -----------------------------------
1445 procedure Analyze_Parameter_Association
(N
: Node_Id
) is
1447 Analyze
(Explicit_Actual_Parameter
(N
));
1448 end Analyze_Parameter_Association
;
1450 ----------------------------
1451 -- Analyze_Procedure_Call --
1452 ----------------------------
1454 procedure Analyze_Procedure_Call
(N
: Node_Id
) is
1455 Loc
: constant Source_Ptr
:= Sloc
(N
);
1456 P
: constant Node_Id
:= Name
(N
);
1457 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
1461 procedure Analyze_Call_And_Resolve
;
1462 -- Do Analyze and Resolve calls for procedure call
1463 -- At end, check illegal order dependence.
1465 ------------------------------
1466 -- Analyze_Call_And_Resolve --
1467 ------------------------------
1469 procedure Analyze_Call_And_Resolve
is
1471 if Nkind
(N
) = N_Procedure_Call_Statement
then
1473 Resolve
(N
, Standard_Void_Type
);
1477 end Analyze_Call_And_Resolve
;
1479 -- Start of processing for Analyze_Procedure_Call
1482 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
1483 -- a procedure call or an entry call. The prefix may denote an access
1484 -- to subprogram type, in which case an implicit dereference applies.
1485 -- If the prefix is an indexed component (without implicit dereference)
1486 -- then the construct denotes a call to a member of an entire family.
1487 -- If the prefix is a simple name, it may still denote a call to a
1488 -- parameterless member of an entry family. Resolution of these various
1489 -- interpretations is delicate.
1493 -- If this is a call of the form Obj.Op, the call may have been
1494 -- analyzed and possibly rewritten into a block, in which case
1497 if Analyzed
(N
) then
1501 -- If there is an error analyzing the name (which may have been
1502 -- rewritten if the original call was in prefix notation) then error
1503 -- has been emitted already, mark node and return.
1505 if Error_Posted
(N
) or else Etype
(Name
(N
)) = Any_Type
then
1506 Set_Etype
(N
, Any_Type
);
1510 -- Otherwise analyze the parameters
1512 if Present
(Actuals
) then
1513 Actual
:= First
(Actuals
);
1515 while Present
(Actual
) loop
1517 Check_Parameterless_Call
(Actual
);
1522 -- Special processing for Elab_Spec, Elab_Body and Elab_Subp_Body calls
1524 if Nkind
(P
) = N_Attribute_Reference
1525 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Spec
,
1527 Name_Elab_Subp_Body
)
1529 if Present
(Actuals
) then
1531 ("no parameters allowed for this call", First
(Actuals
));
1535 Set_Etype
(N
, Standard_Void_Type
);
1538 elsif Is_Entity_Name
(P
)
1539 and then Is_Record_Type
(Etype
(Entity
(P
)))
1540 and then Remote_AST_I_Dereference
(P
)
1544 elsif Is_Entity_Name
(P
)
1545 and then Ekind
(Entity
(P
)) /= E_Entry_Family
1547 if Is_Access_Type
(Etype
(P
))
1548 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1549 and then No
(Actuals
)
1550 and then Comes_From_Source
(N
)
1552 Error_Msg_N
("missing explicit dereference in call", N
);
1555 Analyze_Call_And_Resolve
;
1557 -- If the prefix is the simple name of an entry family, this is
1558 -- a parameterless call from within the task body itself.
1560 elsif Is_Entity_Name
(P
)
1561 and then Nkind
(P
) = N_Identifier
1562 and then Ekind
(Entity
(P
)) = E_Entry_Family
1563 and then Present
(Actuals
)
1564 and then No
(Next
(First
(Actuals
)))
1566 -- Can be call to parameterless entry family. What appears to be the
1567 -- sole argument is in fact the entry index. Rewrite prefix of node
1568 -- accordingly. Source representation is unchanged by this
1572 Make_Indexed_Component
(Loc
,
1574 Make_Selected_Component
(Loc
,
1575 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(P
)), Loc
),
1576 Selector_Name
=> New_Occurrence_Of
(Entity
(P
), Loc
)),
1577 Expressions
=> Actuals
);
1578 Set_Name
(N
, New_N
);
1579 Set_Etype
(New_N
, Standard_Void_Type
);
1580 Set_Parameter_Associations
(N
, No_List
);
1581 Analyze_Call_And_Resolve
;
1583 elsif Nkind
(P
) = N_Explicit_Dereference
then
1584 if Ekind
(Etype
(P
)) = E_Subprogram_Type
then
1585 Analyze_Call_And_Resolve
;
1587 Error_Msg_N
("expect access to procedure in call", P
);
1590 -- The name can be a selected component or an indexed component that
1591 -- yields an access to subprogram. Such a prefix is legal if the call
1592 -- has parameter associations.
1594 elsif Is_Access_Type
(Etype
(P
))
1595 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1597 if Present
(Actuals
) then
1598 Analyze_Call_And_Resolve
;
1600 Error_Msg_N
("missing explicit dereference in call ", N
);
1603 -- If not an access to subprogram, then the prefix must resolve to the
1604 -- name of an entry, entry family, or protected operation.
1606 -- For the case of a simple entry call, P is a selected component where
1607 -- the prefix is the task and the selector name is the entry. A call to
1608 -- a protected procedure will have the same syntax. If the protected
1609 -- object contains overloaded operations, the entity may appear as a
1610 -- function, the context will select the operation whose type is Void.
1612 elsif Nkind
(P
) = N_Selected_Component
1613 and then Ekind_In
(Entity
(Selector_Name
(P
)), E_Entry
,
1617 Analyze_Call_And_Resolve
;
1619 elsif Nkind
(P
) = N_Selected_Component
1620 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
1621 and then Present
(Actuals
)
1622 and then No
(Next
(First
(Actuals
)))
1624 -- Can be call to parameterless entry family. What appears to be the
1625 -- sole argument is in fact the entry index. Rewrite prefix of node
1626 -- accordingly. Source representation is unchanged by this
1630 Make_Indexed_Component
(Loc
,
1631 Prefix
=> New_Copy
(P
),
1632 Expressions
=> Actuals
);
1633 Set_Name
(N
, New_N
);
1634 Set_Etype
(New_N
, Standard_Void_Type
);
1635 Set_Parameter_Associations
(N
, No_List
);
1636 Analyze_Call_And_Resolve
;
1638 -- For the case of a reference to an element of an entry family, P is
1639 -- an indexed component whose prefix is a selected component (task and
1640 -- entry family), and whose index is the entry family index.
1642 elsif Nkind
(P
) = N_Indexed_Component
1643 and then Nkind
(Prefix
(P
)) = N_Selected_Component
1644 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) = E_Entry_Family
1646 Analyze_Call_And_Resolve
;
1648 -- If the prefix is the name of an entry family, it is a call from
1649 -- within the task body itself.
1651 elsif Nkind
(P
) = N_Indexed_Component
1652 and then Nkind
(Prefix
(P
)) = N_Identifier
1653 and then Ekind
(Entity
(Prefix
(P
))) = E_Entry_Family
1656 Make_Selected_Component
(Loc
,
1657 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(Prefix
(P
))), Loc
),
1658 Selector_Name
=> New_Occurrence_Of
(Entity
(Prefix
(P
)), Loc
));
1659 Rewrite
(Prefix
(P
), New_N
);
1661 Analyze_Call_And_Resolve
;
1663 -- In Ada 2012. a qualified expression is a name, but it cannot be a
1664 -- procedure name, so the construct can only be a qualified expression.
1666 elsif Nkind
(P
) = N_Qualified_Expression
1667 and then Ada_Version
>= Ada_2012
1669 Rewrite
(N
, Make_Code_Statement
(Loc
, Expression
=> P
));
1672 -- Anything else is an error
1675 Error_Msg_N
("invalid procedure or entry call", N
);
1677 end Analyze_Procedure_Call
;
1679 ------------------------------
1680 -- Analyze_Return_Statement --
1681 ------------------------------
1683 procedure Analyze_Return_Statement
(N
: Node_Id
) is
1685 pragma Assert
(Nkind_In
(N
, N_Simple_Return_Statement
,
1686 N_Extended_Return_Statement
));
1688 Returns_Object
: constant Boolean :=
1689 Nkind
(N
) = N_Extended_Return_Statement
1691 (Nkind
(N
) = N_Simple_Return_Statement
1692 and then Present
(Expression
(N
)));
1693 -- True if we're returning something; that is, "return <expression>;"
1694 -- or "return Result : T [:= ...]". False for "return;". Used for error
1695 -- checking: If Returns_Object is True, N should apply to a function
1696 -- body; otherwise N should apply to a procedure body, entry body,
1697 -- accept statement, or extended return statement.
1699 function Find_What_It_Applies_To
return Entity_Id
;
1700 -- Find the entity representing the innermost enclosing body, accept
1701 -- statement, or extended return statement. If the result is a callable
1702 -- construct or extended return statement, then this will be the value
1703 -- of the Return_Applies_To attribute. Otherwise, the program is
1704 -- illegal. See RM-6.5(4/2).
1706 -----------------------------
1707 -- Find_What_It_Applies_To --
1708 -----------------------------
1710 function Find_What_It_Applies_To
return Entity_Id
is
1711 Result
: Entity_Id
:= Empty
;
1714 -- Loop outward through the Scope_Stack, skipping blocks, loops,
1715 -- and postconditions.
1717 for J
in reverse 0 .. Scope_Stack
.Last
loop
1718 Result
:= Scope_Stack
.Table
(J
).Entity
;
1719 exit when not Ekind_In
(Result
, E_Block
, E_Loop
)
1720 and then Chars
(Result
) /= Name_uPostconditions
;
1723 pragma Assert
(Present
(Result
));
1725 end Find_What_It_Applies_To
;
1727 -- Local declarations
1729 Scope_Id
: constant Entity_Id
:= Find_What_It_Applies_To
;
1730 Kind
: constant Entity_Kind
:= Ekind
(Scope_Id
);
1731 Loc
: constant Source_Ptr
:= Sloc
(N
);
1732 Stm_Entity
: constant Entity_Id
:=
1734 (E_Return_Statement
, Current_Scope
, Loc
, 'R');
1736 -- Start of processing for Analyze_Return_Statement
1739 Set_Return_Statement_Entity
(N
, Stm_Entity
);
1741 Set_Etype
(Stm_Entity
, Standard_Void_Type
);
1742 Set_Return_Applies_To
(Stm_Entity
, Scope_Id
);
1744 -- Place Return entity on scope stack, to simplify enforcement of 6.5
1745 -- (4/2): an inner return statement will apply to this extended return.
1747 if Nkind
(N
) = N_Extended_Return_Statement
then
1748 Push_Scope
(Stm_Entity
);
1751 -- Check that pragma No_Return is obeyed. Don't complain about the
1752 -- implicitly-generated return that is placed at the end.
1754 if No_Return
(Scope_Id
) and then Comes_From_Source
(N
) then
1755 Error_Msg_N
("RETURN statement not allowed (No_Return)", N
);
1758 -- Warn on any unassigned OUT parameters if in procedure
1760 if Ekind
(Scope_Id
) = E_Procedure
then
1761 Warn_On_Unassigned_Out_Parameter
(N
, Scope_Id
);
1764 -- Check that functions return objects, and other things do not
1766 if Kind
= E_Function
or else Kind
= E_Generic_Function
then
1767 if not Returns_Object
then
1768 Error_Msg_N
("missing expression in return from function", N
);
1771 elsif Kind
= E_Procedure
or else Kind
= E_Generic_Procedure
then
1772 if Returns_Object
then
1773 Error_Msg_N
("procedure cannot return value (use function)", N
);
1776 elsif Kind
= E_Entry
or else Kind
= E_Entry_Family
then
1777 if Returns_Object
then
1778 if Is_Protected_Type
(Scope
(Scope_Id
)) then
1779 Error_Msg_N
("entry body cannot return value", N
);
1781 Error_Msg_N
("accept statement cannot return value", N
);
1785 elsif Kind
= E_Return_Statement
then
1787 -- We are nested within another return statement, which must be an
1788 -- extended_return_statement.
1790 if Returns_Object
then
1791 if Nkind
(N
) = N_Extended_Return_Statement
then
1793 ("extended return statement cannot be nested (use `RETURN;`)",
1796 -- Case of a simple return statement with a value inside extended
1797 -- return statement.
1801 ("return nested in extended return statement cannot return " &
1802 "value (use `RETURN;`)", N
);
1807 Error_Msg_N
("illegal context for return statement", N
);
1810 if Ekind_In
(Kind
, E_Function
, E_Generic_Function
) then
1811 Analyze_Function_Return
(N
);
1813 elsif Ekind_In
(Kind
, E_Procedure
, E_Generic_Procedure
) then
1814 Set_Return_Present
(Scope_Id
);
1817 if Nkind
(N
) = N_Extended_Return_Statement
then
1821 Kill_Current_Values
(Last_Assignment_Only
=> True);
1822 Check_Unreachable_Code
(N
);
1824 Analyze_Dimension
(N
);
1825 end Analyze_Return_Statement
;
1827 -------------------------------------
1828 -- Analyze_Simple_Return_Statement --
1829 -------------------------------------
1831 procedure Analyze_Simple_Return_Statement
(N
: Node_Id
) is
1833 if Present
(Expression
(N
)) then
1834 Mark_Coextensions
(N
, Expression
(N
));
1837 Analyze_Return_Statement
(N
);
1838 end Analyze_Simple_Return_Statement
;
1840 -------------------------
1841 -- Analyze_Return_Type --
1842 -------------------------
1844 procedure Analyze_Return_Type
(N
: Node_Id
) is
1845 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
1846 Typ
: Entity_Id
:= Empty
;
1849 -- Normal case where result definition does not indicate an error
1851 if Result_Definition
(N
) /= Error
then
1852 if Nkind
(Result_Definition
(N
)) = N_Access_Definition
then
1853 Check_SPARK_Restriction
1854 ("access result is not allowed", Result_Definition
(N
));
1856 -- Ada 2005 (AI-254): Handle anonymous access to subprograms
1859 AD
: constant Node_Id
:=
1860 Access_To_Subprogram_Definition
(Result_Definition
(N
));
1862 if Present
(AD
) and then Protected_Present
(AD
) then
1863 Typ
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
1865 Typ
:= Access_Definition
(N
, Result_Definition
(N
));
1869 Set_Parent
(Typ
, Result_Definition
(N
));
1870 Set_Is_Local_Anonymous_Access
(Typ
);
1871 Set_Etype
(Designator
, Typ
);
1873 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1875 Null_Exclusion_Static_Checks
(N
);
1877 -- Subtype_Mark case
1880 Find_Type
(Result_Definition
(N
));
1881 Typ
:= Entity
(Result_Definition
(N
));
1882 Set_Etype
(Designator
, Typ
);
1884 -- Unconstrained array as result is not allowed in SPARK
1886 if Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
1887 Check_SPARK_Restriction
1888 ("returning an unconstrained array is not allowed",
1889 Result_Definition
(N
));
1892 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1894 Null_Exclusion_Static_Checks
(N
);
1896 -- If a null exclusion is imposed on the result type, then create
1897 -- a null-excluding itype (an access subtype) and use it as the
1898 -- function's Etype. Note that the null exclusion checks are done
1899 -- right before this, because they don't get applied to types that
1900 -- do not come from source.
1902 if Is_Access_Type
(Typ
) and then Null_Exclusion_Present
(N
) then
1903 Set_Etype
(Designator
,
1904 Create_Null_Excluding_Itype
1907 Scope_Id
=> Scope
(Current_Scope
)));
1909 -- The new subtype must be elaborated before use because
1910 -- it is visible outside of the function. However its base
1911 -- type may not be frozen yet, so the reference that will
1912 -- force elaboration must be attached to the freezing of
1915 -- If the return specification appears on a proper body,
1916 -- the subtype will have been created already on the spec.
1918 if Is_Frozen
(Typ
) then
1919 if Nkind
(Parent
(N
)) = N_Subprogram_Body
1920 and then Nkind
(Parent
(Parent
(N
))) = N_Subunit
1924 Build_Itype_Reference
(Etype
(Designator
), Parent
(N
));
1928 Ensure_Freeze_Node
(Typ
);
1931 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(N
));
1933 Set_Itype
(IR
, Etype
(Designator
));
1934 Append_Freeze_Actions
(Typ
, New_List
(IR
));
1939 Set_Etype
(Designator
, Typ
);
1942 if Ekind
(Typ
) = E_Incomplete_Type
1943 and then Is_Value_Type
(Typ
)
1947 elsif Ekind
(Typ
) = E_Incomplete_Type
1948 or else (Is_Class_Wide_Type
(Typ
)
1949 and then Ekind
(Root_Type
(Typ
)) = E_Incomplete_Type
)
1951 -- AI05-0151: Tagged incomplete types are allowed in all formal
1952 -- parts. Untagged incomplete types are not allowed in bodies.
1953 -- As a consequence, limited views cannot appear in a basic
1954 -- declaration that is itself within a body, because there is
1955 -- no point at which the non-limited view will become visible.
1957 if Ada_Version
>= Ada_2012
then
1958 if From_Limited_With
(Typ
) and then In_Package_Body
then
1960 ("invalid use of incomplete type&",
1961 Result_Definition
(N
), Typ
);
1963 -- The return type of a subprogram body cannot be of a
1964 -- formal incomplete type.
1966 elsif Is_Generic_Type
(Typ
)
1967 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
1970 ("return type cannot be a formal incomplete type",
1971 Result_Definition
(N
));
1973 elsif Is_Class_Wide_Type
(Typ
)
1974 and then Is_Generic_Type
(Root_Type
(Typ
))
1975 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
1978 ("return type cannot be a formal incomplete type",
1979 Result_Definition
(N
));
1981 elsif Is_Tagged_Type
(Typ
) then
1984 elsif Nkind
(Parent
(N
)) = N_Subprogram_Body
1985 or else Nkind_In
(Parent
(Parent
(N
)), N_Accept_Statement
,
1989 ("invalid use of untagged incomplete type&",
1993 -- The type must be completed in the current package. This
1994 -- is checked at the end of the package declaration when
1995 -- Taft-amendment types are identified. If the return type
1996 -- is class-wide, there is no required check, the type can
1997 -- be a bona fide TAT.
1999 if Ekind
(Scope
(Current_Scope
)) = E_Package
2000 and then In_Private_Part
(Scope
(Current_Scope
))
2001 and then not Is_Class_Wide_Type
(Typ
)
2003 Append_Elmt
(Designator
, Private_Dependents
(Typ
));
2008 ("invalid use of incomplete type&", Designator
, Typ
);
2013 -- Case where result definition does indicate an error
2016 Set_Etype
(Designator
, Any_Type
);
2018 end Analyze_Return_Type
;
2020 -----------------------------
2021 -- Analyze_Subprogram_Body --
2022 -----------------------------
2024 procedure Analyze_Subprogram_Body
(N
: Node_Id
) is
2025 Loc
: constant Source_Ptr
:= Sloc
(N
);
2026 Body_Spec
: constant Node_Id
:= Specification
(N
);
2027 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Spec
);
2030 if Debug_Flag_C
then
2031 Write_Str
("==> subprogram body ");
2032 Write_Name
(Chars
(Body_Id
));
2033 Write_Str
(" from ");
2034 Write_Location
(Loc
);
2039 Trace_Scope
(N
, Body_Id
, " Analyze subprogram: ");
2041 -- The real work is split out into the helper, so it can do "return;"
2042 -- without skipping the debug output:
2044 Analyze_Subprogram_Body_Helper
(N
);
2046 if Debug_Flag_C
then
2048 Write_Str
("<== subprogram body ");
2049 Write_Name
(Chars
(Body_Id
));
2050 Write_Str
(" from ");
2051 Write_Location
(Loc
);
2054 end Analyze_Subprogram_Body
;
2056 --------------------------------------
2057 -- Analyze_Subprogram_Body_Contract --
2058 --------------------------------------
2060 procedure Analyze_Subprogram_Body_Contract
(Body_Id
: Entity_Id
) is
2061 Body_Decl
: constant Node_Id
:= Parent
(Parent
(Body_Id
));
2062 Mode
: SPARK_Mode_Type
;
2064 Ref_Depends
: Node_Id
:= Empty
;
2065 Ref_Global
: Node_Id
:= Empty
;
2066 Spec_Id
: Entity_Id
;
2069 -- Due to the timing of contract analysis, delayed pragmas may be
2070 -- subject to the wrong SPARK_Mode, usually that of the enclosing
2071 -- context. To remedy this, restore the original SPARK_Mode of the
2072 -- related subprogram body.
2074 Save_SPARK_Mode_And_Set
(Body_Id
, Mode
);
2076 -- When a subprogram body declaration is illegal, its defining entity is
2077 -- left unanalyzed. There is nothing left to do in this case because the
2078 -- body lacks a contract, or even a proper Ekind.
2080 if Ekind
(Body_Id
) = E_Void
then
2084 if Nkind
(Body_Decl
) = N_Subprogram_Body_Stub
then
2085 Spec_Id
:= Corresponding_Spec_Of_Stub
(Body_Decl
);
2087 Spec_Id
:= Corresponding_Spec
(Body_Decl
);
2090 -- Locate and store pragmas Refined_Depends and Refined_Global since
2091 -- their order of analysis matters.
2093 Prag
:= Classifications
(Contract
(Body_Id
));
2094 while Present
(Prag
) loop
2095 if Pragma_Name
(Prag
) = Name_Refined_Depends
then
2096 Ref_Depends
:= Prag
;
2097 elsif Pragma_Name
(Prag
) = Name_Refined_Global
then
2101 Prag
:= Next_Pragma
(Prag
);
2104 -- Analyze Refined_Global first as Refined_Depends may mention items
2105 -- classified in the global refinement.
2107 if Present
(Ref_Global
) then
2108 Analyze_Refined_Global_In_Decl_Part
(Ref_Global
);
2110 -- When the corresponding Global aspect/pragma references a state with
2111 -- visible refinement, the body requires Refined_Global. Refinement is
2112 -- not required when SPARK checks are suppressed.
2114 elsif Present
(Spec_Id
) then
2115 Prag
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
2117 if SPARK_Mode
/= Off
2118 and then Present
(Prag
)
2119 and then Contains_Refined_State
(Prag
)
2122 ("body of subprogram & requires global refinement",
2123 Body_Decl
, Spec_Id
);
2127 -- Refined_Depends must be analyzed after Refined_Global in order to see
2128 -- the modes of all global refinements.
2130 if Present
(Ref_Depends
) then
2131 Analyze_Refined_Depends_In_Decl_Part
(Ref_Depends
);
2133 -- When the corresponding Depends aspect/pragma references a state with
2134 -- visible refinement, the body requires Refined_Depends. Refinement is
2135 -- not required when SPARK checks are suppressed.
2137 elsif Present
(Spec_Id
) then
2138 Prag
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
2140 if SPARK_Mode
/= Off
2141 and then Present
(Prag
)
2142 and then Contains_Refined_State
(Prag
)
2145 ("body of subprogram & requires dependance refinement",
2146 Body_Decl
, Spec_Id
);
2150 -- Restore the SPARK_Mode of the enclosing context after all delayed
2151 -- pragmas have been analyzed.
2153 Restore_SPARK_Mode
(Mode
);
2154 end Analyze_Subprogram_Body_Contract
;
2156 ------------------------------------
2157 -- Analyze_Subprogram_Body_Helper --
2158 ------------------------------------
2160 -- This procedure is called for regular subprogram bodies, generic bodies,
2161 -- and for subprogram stubs of both kinds. In the case of stubs, only the
2162 -- specification matters, and is used to create a proper declaration for
2163 -- the subprogram, or to perform conformance checks.
2165 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
) is
2166 Loc
: constant Source_Ptr
:= Sloc
(N
);
2167 Body_Spec
: constant Node_Id
:= Specification
(N
);
2168 Body_Id
: Entity_Id
:= Defining_Entity
(Body_Spec
);
2169 Prev_Id
: constant Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
2170 Conformant
: Boolean;
2172 Prot_Typ
: Entity_Id
:= Empty
;
2173 Spec_Id
: Entity_Id
;
2174 Spec_Decl
: Node_Id
:= Empty
;
2176 Last_Real_Spec_Entity
: Entity_Id
:= Empty
;
2177 -- When we analyze a separate spec, the entity chain ends up containing
2178 -- the formals, as well as any itypes generated during analysis of the
2179 -- default expressions for parameters, or the arguments of associated
2180 -- precondition/postcondition pragmas (which are analyzed in the context
2181 -- of the spec since they have visibility on formals).
2183 -- These entities belong with the spec and not the body. However we do
2184 -- the analysis of the body in the context of the spec (again to obtain
2185 -- visibility to the formals), and all the entities generated during
2186 -- this analysis end up also chained to the entity chain of the spec.
2187 -- But they really belong to the body, and there is circuitry to move
2188 -- them from the spec to the body.
2190 -- However, when we do this move, we don't want to move the real spec
2191 -- entities (first para above) to the body. The Last_Real_Spec_Entity
2192 -- variable points to the last real spec entity, so we only move those
2193 -- chained beyond that point. It is initialized to Empty to deal with
2194 -- the case where there is no separate spec.
2196 procedure Analyze_Aspects_On_Body_Or_Stub
;
2197 -- Analyze the aspect specifications of a subprogram body [stub]. It is
2198 -- assumed that N has aspects.
2200 function Body_Has_Contract
return Boolean;
2201 -- Check whether unanalyzed body has an aspect or pragma that may
2202 -- generate a SPARK contract.
2204 procedure Check_Anonymous_Return
;
2205 -- Ada 2005: if a function returns an access type that denotes a task,
2206 -- or a type that contains tasks, we must create a master entity for
2207 -- the anonymous type, which typically will be used in an allocator
2208 -- in the body of the function.
2210 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
);
2211 -- Look ahead to recognize a pragma that may appear after the body.
2212 -- If there is a previous spec, check that it appears in the same
2213 -- declarative part. If the pragma is Inline_Always, perform inlining
2214 -- unconditionally, otherwise only if Front_End_Inlining is requested.
2215 -- If the body acts as a spec, and inlining is required, we create a
2216 -- subprogram declaration for it, in order to attach the body to inline.
2217 -- If pragma does not appear after the body, check whether there is
2218 -- an inline pragma before any local declarations.
2220 procedure Check_Missing_Return
;
2221 -- Checks for a function with a no return statements, and also performs
2222 -- the warning checks implemented by Check_Returns. In formal mode, also
2223 -- verify that a function ends with a RETURN and that a procedure does
2224 -- not contain any RETURN.
2226 function Disambiguate_Spec
return Entity_Id
;
2227 -- When a primitive is declared between the private view and the full
2228 -- view of a concurrent type which implements an interface, a special
2229 -- mechanism is used to find the corresponding spec of the primitive
2232 procedure Exchange_Limited_Views
(Subp_Id
: Entity_Id
);
2233 -- Ada 2012 (AI05-0151): Detect whether the profile of Subp_Id contains
2234 -- incomplete types coming from a limited context and swap their limited
2235 -- views with the non-limited ones.
2237 function Is_Private_Concurrent_Primitive
2238 (Subp_Id
: Entity_Id
) return Boolean;
2239 -- Determine whether subprogram Subp_Id is a primitive of a concurrent
2240 -- type that implements an interface and has a private view.
2242 procedure Set_Trivial_Subprogram
(N
: Node_Id
);
2243 -- Sets the Is_Trivial_Subprogram flag in both spec and body of the
2244 -- subprogram whose body is being analyzed. N is the statement node
2245 -- causing the flag to be set, if the following statement is a return
2246 -- of an entity, we mark the entity as set in source to suppress any
2247 -- warning on the stylized use of function stubs with a dummy return.
2249 procedure Verify_Overriding_Indicator
;
2250 -- If there was a previous spec, the entity has been entered in the
2251 -- current scope previously. If the body itself carries an overriding
2252 -- indicator, check that it is consistent with the known status of the
2255 -------------------------------------
2256 -- Analyze_Aspects_On_Body_Or_Stub --
2257 -------------------------------------
2259 procedure Analyze_Aspects_On_Body_Or_Stub
is
2260 procedure Diagnose_Misplaced_Aspects
;
2261 -- Subprogram body [stub] N has aspects, but they are not properly
2262 -- placed. Provide precise diagnostics depending on the aspects
2265 --------------------------------
2266 -- Diagnose_Misplaced_Aspects --
2267 --------------------------------
2269 procedure Diagnose_Misplaced_Aspects
is
2273 -- The current aspect along with its name and id
2275 procedure SPARK_Aspect_Error
(Ref_Nam
: Name_Id
);
2276 -- Emit an error message concerning SPARK aspect Asp. Ref_Nam is
2277 -- the name of the refined version of the aspect.
2279 ------------------------
2280 -- SPARK_Aspect_Error --
2281 ------------------------
2283 procedure SPARK_Aspect_Error
(Ref_Nam
: Name_Id
) is
2285 -- The corresponding spec already contains the aspect in
2286 -- question and the one appearing on the body must be the
2289 -- procedure P with Global ...;
2290 -- procedure P with Global ... is ... end P;
2294 if Has_Aspect
(Spec_Id
, Asp_Id
) then
2295 Error_Msg_Name_1
:= Asp_Nam
;
2297 -- Subunits cannot carry aspects that apply to a subprogram
2300 if Nkind
(Parent
(N
)) = N_Subunit
then
2301 Error_Msg_N
("aspect % cannot apply to a subunit", Asp
);
2304 Error_Msg_Name_2
:= Ref_Nam
;
2305 Error_Msg_N
("aspect % should be %", Asp
);
2308 -- Otherwise the aspect must appear in the spec, not in the
2312 -- procedure P with Global ... is ... end P;
2316 ("aspect specification must appear in subprogram "
2317 & "declaration", Asp
);
2319 end SPARK_Aspect_Error
;
2321 -- Start of processing for Diagnose_Misplaced_Aspects
2324 -- Iterate over the aspect specifications and emit specific errors
2325 -- where applicable.
2327 Asp
:= First
(Aspect_Specifications
(N
));
2328 while Present
(Asp
) loop
2329 Asp_Nam
:= Chars
(Identifier
(Asp
));
2330 Asp_Id
:= Get_Aspect_Id
(Asp_Nam
);
2332 -- Do not emit errors on aspects that can appear on a
2333 -- subprogram body. This scenario occurs when the aspect
2334 -- specification list contains both misplaced and properly
2337 if Aspect_On_Body_Or_Stub_OK
(Asp_Id
) then
2340 -- Special diagnostics for SPARK aspects
2342 elsif Asp_Nam
= Name_Depends
then
2343 SPARK_Aspect_Error
(Name_Refined_Depends
);
2345 elsif Asp_Nam
= Name_Global
then
2346 SPARK_Aspect_Error
(Name_Refined_Global
);
2348 elsif Asp_Nam
= Name_Post
then
2349 SPARK_Aspect_Error
(Name_Refined_Post
);
2353 ("aspect specification must appear in subprogram "
2354 & "declaration", Asp
);
2359 end Diagnose_Misplaced_Aspects
;
2361 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
2364 -- Language-defined aspects cannot be associated with a subprogram
2365 -- body [stub] if the subprogram has a spec. Certain implementation
2366 -- defined aspects are allowed to break this rule (for list, see
2367 -- table Aspect_On_Body_Or_Stub_OK).
2369 if Present
(Spec_Id
) and then not Aspects_On_Body_Or_Stub_OK
(N
) then
2370 Diagnose_Misplaced_Aspects
;
2372 Analyze_Aspect_Specifications
(N
, Body_Id
);
2374 end Analyze_Aspects_On_Body_Or_Stub
;
2376 -----------------------
2377 -- Body_Has_Contract --
2378 -----------------------
2380 function Body_Has_Contract
return Boolean is
2381 Decls
: constant List_Id
:= Declarations
(N
);
2388 -- Check for unanalyzed aspects in the body that will
2389 -- generate a contract.
2391 if Present
(Aspect_Specifications
(N
)) then
2392 A_Spec
:= First
(Aspect_Specifications
(N
));
2393 while Present
(A_Spec
) loop
2394 A
:= Get_Aspect_Id
(Chars
(Identifier
(A_Spec
)));
2396 if A
= Aspect_Contract_Cases
or else
2397 A
= Aspect_Depends
or else
2398 A
= Aspect_Global
or else
2399 A
= Aspect_Pre
or else
2400 A
= Aspect_Precondition
or else
2401 A
= Aspect_Post
or else
2402 A
= Aspect_Postcondition
2411 -- Check for pragmas that may generate a contract
2413 if Present
(Decls
) then
2414 Decl
:= First
(Decls
);
2415 while Present
(Decl
) loop
2416 if Nkind
(Decl
) = N_Pragma
then
2417 P_Id
:= Get_Pragma_Id
(Pragma_Name
(Decl
));
2419 if P_Id
= Pragma_Contract_Cases
or else
2420 P_Id
= Pragma_Depends
or else
2421 P_Id
= Pragma_Global
or else
2422 P_Id
= Pragma_Pre
or else
2423 P_Id
= Pragma_Precondition
or else
2424 P_Id
= Pragma_Post
or else
2425 P_Id
= Pragma_Postcondition
2436 end Body_Has_Contract
;
2438 ----------------------------
2439 -- Check_Anonymous_Return --
2440 ----------------------------
2442 procedure Check_Anonymous_Return
is
2448 if Present
(Spec_Id
) then
2454 if Ekind
(Scop
) = E_Function
2455 and then Ekind
(Etype
(Scop
)) = E_Anonymous_Access_Type
2456 and then not Is_Thunk
(Scop
)
2457 and then (Has_Task
(Designated_Type
(Etype
(Scop
)))
2459 (Is_Class_Wide_Type
(Designated_Type
(Etype
(Scop
)))
2461 Is_Limited_Record
(Designated_Type
(Etype
(Scop
)))))
2462 and then Expander_Active
2464 -- Avoid cases with no tasking support
2466 and then RTE_Available
(RE_Current_Master
)
2467 and then not Restriction_Active
(No_Task_Hierarchy
)
2470 Make_Object_Declaration
(Loc
,
2471 Defining_Identifier
=>
2472 Make_Defining_Identifier
(Loc
, Name_uMaster
),
2473 Constant_Present
=> True,
2474 Object_Definition
=>
2475 New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
2477 Make_Explicit_Dereference
(Loc
,
2478 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
2480 if Present
(Declarations
(N
)) then
2481 Prepend
(Decl
, Declarations
(N
));
2483 Set_Declarations
(N
, New_List
(Decl
));
2486 Set_Master_Id
(Etype
(Scop
), Defining_Identifier
(Decl
));
2487 Set_Has_Master_Entity
(Scop
);
2489 -- Now mark the containing scope as a task master
2492 while Nkind
(Par
) /= N_Compilation_Unit
loop
2493 Par
:= Parent
(Par
);
2494 pragma Assert
(Present
(Par
));
2496 -- If we fall off the top, we are at the outer level, and
2497 -- the environment task is our effective master, so nothing
2501 (Par
, N_Task_Body
, N_Block_Statement
, N_Subprogram_Body
)
2503 Set_Is_Task_Master
(Par
, True);
2508 end Check_Anonymous_Return
;
2510 -------------------------
2511 -- Check_Inline_Pragma --
2512 -------------------------
2514 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
) is
2518 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean;
2519 -- True when N is a pragma Inline or Inline_Always that applies
2520 -- to this subprogram.
2522 -----------------------
2523 -- Is_Inline_Pragma --
2524 -----------------------
2526 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean is
2529 Nkind
(N
) = N_Pragma
2531 (Pragma_Name
(N
) = Name_Inline_Always
2534 and then Pragma_Name
(N
) = Name_Inline
))
2537 (Expression
(First
(Pragma_Argument_Associations
(N
)))) =
2539 end Is_Inline_Pragma
;
2541 -- Start of processing for Check_Inline_Pragma
2544 if not Expander_Active
then
2548 if Is_List_Member
(N
)
2549 and then Present
(Next
(N
))
2550 and then Is_Inline_Pragma
(Next
(N
))
2554 elsif Nkind
(N
) /= N_Subprogram_Body_Stub
2555 and then Present
(Declarations
(N
))
2556 and then Is_Inline_Pragma
(First
(Declarations
(N
)))
2558 Prag
:= First
(Declarations
(N
));
2564 if Present
(Prag
) then
2565 if Present
(Spec_Id
) then
2566 if In_Same_List
(N
, Unit_Declaration_Node
(Spec_Id
)) then
2571 -- Create a subprogram declaration, to make treatment uniform
2574 Subp
: constant Entity_Id
:=
2575 Make_Defining_Identifier
(Loc
, Chars
(Body_Id
));
2576 Decl
: constant Node_Id
:=
2577 Make_Subprogram_Declaration
(Loc
,
2579 New_Copy_Tree
(Specification
(N
)));
2582 Set_Defining_Unit_Name
(Specification
(Decl
), Subp
);
2584 if Present
(First_Formal
(Body_Id
)) then
2585 Plist
:= Copy_Parameter_List
(Body_Id
);
2586 Set_Parameter_Specifications
2587 (Specification
(Decl
), Plist
);
2590 Insert_Before
(N
, Decl
);
2593 Set_Has_Pragma_Inline
(Subp
);
2595 if Pragma_Name
(Prag
) = Name_Inline_Always
then
2596 Set_Is_Inlined
(Subp
);
2597 Set_Has_Pragma_Inline_Always
(Subp
);
2600 -- Prior to copying the subprogram body to create a template
2601 -- for it for subsequent inlining, remove the pragma from
2602 -- the current body so that the copy that will produce the
2603 -- new body will start from a completely unanalyzed tree.
2605 if Nkind
(Parent
(Prag
)) = N_Subprogram_Body
then
2606 Rewrite
(Prag
, Make_Null_Statement
(Sloc
(Prag
)));
2613 end Check_Inline_Pragma
;
2615 --------------------------
2616 -- Check_Missing_Return --
2617 --------------------------
2619 procedure Check_Missing_Return
is
2621 Missing_Ret
: Boolean;
2624 if Nkind
(Body_Spec
) = N_Function_Specification
then
2625 if Present
(Spec_Id
) then
2631 if Return_Present
(Id
) then
2632 Check_Returns
(HSS
, 'F', Missing_Ret
);
2635 Set_Has_Missing_Return
(Id
);
2638 elsif Is_Generic_Subprogram
(Id
)
2639 or else not Is_Machine_Code_Subprogram
(Id
)
2641 Error_Msg_N
("missing RETURN statement in function body", N
);
2644 -- If procedure with No_Return, check returns
2646 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
2647 and then Present
(Spec_Id
)
2648 and then No_Return
(Spec_Id
)
2650 Check_Returns
(HSS
, 'P', Missing_Ret
, Spec_Id
);
2653 -- Special checks in SPARK mode
2655 if Nkind
(Body_Spec
) = N_Function_Specification
then
2657 -- In SPARK mode, last statement of a function should be a return
2660 Stat
: constant Node_Id
:= Last_Source_Statement
(HSS
);
2663 and then not Nkind_In
(Stat
, N_Simple_Return_Statement
,
2664 N_Extended_Return_Statement
)
2666 Check_SPARK_Restriction
2667 ("last statement in function should be RETURN", Stat
);
2671 -- In SPARK mode, verify that a procedure has no return
2673 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
then
2674 if Present
(Spec_Id
) then
2680 -- Would be nice to point to return statement here, can we
2681 -- borrow the Check_Returns procedure here ???
2683 if Return_Present
(Id
) then
2684 Check_SPARK_Restriction
2685 ("procedure should not have RETURN", N
);
2688 end Check_Missing_Return
;
2690 -----------------------
2691 -- Disambiguate_Spec --
2692 -----------------------
2694 function Disambiguate_Spec
return Entity_Id
is
2695 Priv_Spec
: Entity_Id
;
2698 procedure Replace_Types
(To_Corresponding
: Boolean);
2699 -- Depending on the flag, replace the type of formal parameters of
2700 -- Body_Id if it is a concurrent type implementing interfaces with
2701 -- the corresponding record type or the other way around.
2703 procedure Replace_Types
(To_Corresponding
: Boolean) is
2705 Formal_Typ
: Entity_Id
;
2708 Formal
:= First_Formal
(Body_Id
);
2709 while Present
(Formal
) loop
2710 Formal_Typ
:= Etype
(Formal
);
2712 if Is_Class_Wide_Type
(Formal_Typ
) then
2713 Formal_Typ
:= Root_Type
(Formal_Typ
);
2716 -- From concurrent type to corresponding record
2718 if To_Corresponding
then
2719 if Is_Concurrent_Type
(Formal_Typ
)
2720 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
2721 and then Present
(Interfaces
(
2722 Corresponding_Record_Type
(Formal_Typ
)))
2725 Corresponding_Record_Type
(Formal_Typ
));
2728 -- From corresponding record to concurrent type
2731 if Is_Concurrent_Record_Type
(Formal_Typ
)
2732 and then Present
(Interfaces
(Formal_Typ
))
2735 Corresponding_Concurrent_Type
(Formal_Typ
));
2739 Next_Formal
(Formal
);
2743 -- Start of processing for Disambiguate_Spec
2746 -- Try to retrieve the specification of the body as is. All error
2747 -- messages are suppressed because the body may not have a spec in
2748 -- its current state.
2750 Spec_N
:= Find_Corresponding_Spec
(N
, False);
2752 -- It is possible that this is the body of a primitive declared
2753 -- between a private and a full view of a concurrent type. The
2754 -- controlling parameter of the spec carries the concurrent type,
2755 -- not the corresponding record type as transformed by Analyze_
2756 -- Subprogram_Specification. In such cases, we undo the change
2757 -- made by the analysis of the specification and try to find the
2760 -- Note that wrappers already have their corresponding specs and
2761 -- bodies set during their creation, so if the candidate spec is
2762 -- a wrapper, then we definitely need to swap all types to their
2763 -- original concurrent status.
2766 or else Is_Primitive_Wrapper
(Spec_N
)
2768 -- Restore all references of corresponding record types to the
2769 -- original concurrent types.
2771 Replace_Types
(To_Corresponding
=> False);
2772 Priv_Spec
:= Find_Corresponding_Spec
(N
, False);
2774 -- The current body truly belongs to a primitive declared between
2775 -- a private and a full view. We leave the modified body as is,
2776 -- and return the true spec.
2778 if Present
(Priv_Spec
)
2779 and then Is_Private_Primitive
(Priv_Spec
)
2784 -- In case that this is some sort of error, restore the original
2785 -- state of the body.
2787 Replace_Types
(To_Corresponding
=> True);
2791 end Disambiguate_Spec
;
2793 ----------------------------
2794 -- Exchange_Limited_Views --
2795 ----------------------------
2797 procedure Exchange_Limited_Views
(Subp_Id
: Entity_Id
) is
2798 procedure Detect_And_Exchange
(Id
: Entity_Id
);
2799 -- Determine whether Id's type denotes an incomplete type associated
2800 -- with a limited with clause and exchange the limited view with the
2803 -------------------------
2804 -- Detect_And_Exchange --
2805 -------------------------
2807 procedure Detect_And_Exchange
(Id
: Entity_Id
) is
2808 Typ
: constant Entity_Id
:= Etype
(Id
);
2811 if Ekind
(Typ
) = E_Incomplete_Type
2812 and then From_Limited_With
(Typ
)
2813 and then Present
(Non_Limited_View
(Typ
))
2815 Set_Etype
(Id
, Non_Limited_View
(Typ
));
2817 end Detect_And_Exchange
;
2823 -- Start of processing for Exchange_Limited_Views
2826 if No
(Subp_Id
) then
2829 -- Do not process subprogram bodies as they already use the non-
2830 -- limited view of types.
2832 elsif not Ekind_In
(Subp_Id
, E_Function
, E_Procedure
) then
2836 -- Examine all formals and swap views when applicable
2838 Formal
:= First_Formal
(Subp_Id
);
2839 while Present
(Formal
) loop
2840 Detect_And_Exchange
(Formal
);
2842 Next_Formal
(Formal
);
2845 -- Process the return type of a function
2847 if Ekind
(Subp_Id
) = E_Function
then
2848 Detect_And_Exchange
(Subp_Id
);
2850 end Exchange_Limited_Views
;
2852 -------------------------------------
2853 -- Is_Private_Concurrent_Primitive --
2854 -------------------------------------
2856 function Is_Private_Concurrent_Primitive
2857 (Subp_Id
: Entity_Id
) return Boolean
2859 Formal_Typ
: Entity_Id
;
2862 if Present
(First_Formal
(Subp_Id
)) then
2863 Formal_Typ
:= Etype
(First_Formal
(Subp_Id
));
2865 if Is_Concurrent_Record_Type
(Formal_Typ
) then
2866 if Is_Class_Wide_Type
(Formal_Typ
) then
2867 Formal_Typ
:= Root_Type
(Formal_Typ
);
2870 Formal_Typ
:= Corresponding_Concurrent_Type
(Formal_Typ
);
2873 -- The type of the first formal is a concurrent tagged type with
2877 Is_Concurrent_Type
(Formal_Typ
)
2878 and then Is_Tagged_Type
(Formal_Typ
)
2879 and then Has_Private_Declaration
(Formal_Typ
);
2883 end Is_Private_Concurrent_Primitive
;
2885 ----------------------------
2886 -- Set_Trivial_Subprogram --
2887 ----------------------------
2889 procedure Set_Trivial_Subprogram
(N
: Node_Id
) is
2890 Nxt
: constant Node_Id
:= Next
(N
);
2893 Set_Is_Trivial_Subprogram
(Body_Id
);
2895 if Present
(Spec_Id
) then
2896 Set_Is_Trivial_Subprogram
(Spec_Id
);
2900 and then Nkind
(Nxt
) = N_Simple_Return_Statement
2901 and then No
(Next
(Nxt
))
2902 and then Present
(Expression
(Nxt
))
2903 and then Is_Entity_Name
(Expression
(Nxt
))
2905 Set_Never_Set_In_Source
(Entity
(Expression
(Nxt
)), False);
2907 end Set_Trivial_Subprogram
;
2909 ---------------------------------
2910 -- Verify_Overriding_Indicator --
2911 ---------------------------------
2913 procedure Verify_Overriding_Indicator
is
2915 if Must_Override
(Body_Spec
) then
2916 if Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
2917 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
2921 elsif not Present
(Overridden_Operation
(Spec_Id
)) then
2923 ("subprogram& is not overriding", Body_Spec
, Spec_Id
);
2925 -- Overriding indicators aren't allowed for protected subprogram
2926 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
2927 -- this to a warning if -gnatd.E is enabled.
2929 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
2930 Error_Msg_Warn
:= Error_To_Warning
;
2932 ("<<overriding indicator not allowed for protected "
2933 & "subprogram body", Body_Spec
);
2936 elsif Must_Not_Override
(Body_Spec
) then
2937 if Present
(Overridden_Operation
(Spec_Id
)) then
2939 ("subprogram& overrides inherited operation",
2940 Body_Spec
, Spec_Id
);
2942 elsif Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
2943 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
2946 ("subprogram & overrides predefined operator ",
2947 Body_Spec
, Spec_Id
);
2949 -- Overriding indicators aren't allowed for protected subprogram
2950 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
2951 -- this to a warning if -gnatd.E is enabled.
2953 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
2954 Error_Msg_Warn
:= Error_To_Warning
;
2957 ("<<overriding indicator not allowed " &
2958 "for protected subprogram body",
2961 -- If this is not a primitive operation, then the overriding
2962 -- indicator is altogether illegal.
2964 elsif not Is_Primitive
(Spec_Id
) then
2966 ("overriding indicator only allowed " &
2967 "if subprogram is primitive",
2971 -- If checking the style rule and the operation overrides, then
2972 -- issue a warning about a missing overriding_indicator. Protected
2973 -- subprogram bodies are excluded from this style checking, since
2974 -- they aren't primitives (even though their declarations can
2975 -- override) and aren't allowed to have an overriding_indicator.
2978 and then Present
(Overridden_Operation
(Spec_Id
))
2979 and then Ekind
(Scope
(Spec_Id
)) /= E_Protected_Type
2981 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
2982 Style
.Missing_Overriding
(N
, Body_Id
);
2985 and then Can_Override_Operator
(Spec_Id
)
2986 and then not Is_Predefined_File_Name
2987 (Unit_File_Name
(Get_Source_Unit
(Spec_Id
)))
2989 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
2990 Style
.Missing_Overriding
(N
, Body_Id
);
2992 end Verify_Overriding_Indicator
;
2994 -- Start of processing for Analyze_Subprogram_Body_Helper
2997 -- Generic subprograms are handled separately. They always have a
2998 -- generic specification. Determine whether current scope has a
2999 -- previous declaration.
3001 -- If the subprogram body is defined within an instance of the same
3002 -- name, the instance appears as a package renaming, and will be hidden
3003 -- within the subprogram.
3005 if Present
(Prev_Id
)
3006 and then not Is_Overloadable
(Prev_Id
)
3007 and then (Nkind
(Parent
(Prev_Id
)) /= N_Package_Renaming_Declaration
3008 or else Comes_From_Source
(Prev_Id
))
3010 if Is_Generic_Subprogram
(Prev_Id
) then
3012 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3013 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3015 Analyze_Generic_Subprogram_Body
(N
, Spec_Id
);
3017 if Nkind
(N
) = N_Subprogram_Body
then
3018 HSS
:= Handled_Statement_Sequence
(N
);
3019 Check_Missing_Return
;
3025 -- Previous entity conflicts with subprogram name. Attempting to
3026 -- enter name will post error.
3028 Enter_Name
(Body_Id
);
3032 -- Non-generic case, find the subprogram declaration, if one was seen,
3033 -- or enter new overloaded entity in the current scope. If the
3034 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
3035 -- part of the context of one of its subunits. No need to redo the
3038 elsif Prev_Id
= Body_Id
and then Has_Completion
(Body_Id
) then
3042 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
3044 if Nkind
(N
) = N_Subprogram_Body_Stub
3045 or else No
(Corresponding_Spec
(N
))
3047 if Is_Private_Concurrent_Primitive
(Body_Id
) then
3048 Spec_Id
:= Disambiguate_Spec
;
3050 Spec_Id
:= Find_Corresponding_Spec
(N
);
3052 -- In GNATprove mode, if the body has no previous spec, create
3053 -- one so that the inlining machinery can operate properly.
3054 -- Transfer aspects, if any, to the new spec, so that they
3055 -- are legal and can be processed ahead of the body.
3056 -- We make two copies of the given spec, one for the new
3057 -- declaration, and one for the body.
3060 and then GNATprove_Mode
3062 -- Inlining does not apply during pre-analysis of code
3064 and then Full_Analysis
3066 -- Inlining only applies to full bodies, not stubs
3068 and then Nkind
(N
) /= N_Subprogram_Body_Stub
3070 -- Inlining only applies to bodies in the source code, not to
3071 -- those generated by the compiler. In particular, expression
3072 -- functions, whose body is generated by the compiler, are
3073 -- treated specially by GNATprove.
3075 and then Comes_From_Source
(Body_Id
)
3077 -- This cannot be done for a compilation unit, which is not
3078 -- in a context where we can insert a new spec.
3080 and then Is_List_Member
(N
)
3082 -- Inlining only applies to subprograms without contracts,
3083 -- as a contract is a sign that GNATprove should perform a
3084 -- modular analysis of the subprogram instead of a contextual
3085 -- analysis at each call site. The same test is performed in
3086 -- Inline.Can_Be_Inlined_In_GNATprove_Mode. It is repeated
3087 -- here in another form (because the contract has not
3088 -- been attached to the body) to avoid frontend errors in
3089 -- case pragmas are used instead of aspects, because the
3090 -- corresponding pragmas in the body would not be transferred
3091 -- to the spec, leading to legality errors.
3093 and then not Body_Has_Contract
3096 Body_Spec
: constant Node_Id
:=
3097 Copy_Separate_Tree
(Specification
(N
));
3098 New_Decl
: constant Node_Id
:=
3099 Make_Subprogram_Declaration
(Loc
,
3100 Copy_Separate_Tree
(Specification
(N
)));
3102 SPARK_Mode_Aspect
: Node_Id
;
3104 Prag
, Aspect
: Node_Id
;
3107 Insert_Before
(N
, New_Decl
);
3108 Move_Aspects
(From
=> N
, To
=> New_Decl
);
3110 -- Mark the newly moved aspects as not analyzed, so that
3111 -- their effect on New_Decl is properly analyzed.
3113 Aspect
:= First
(Aspect_Specifications
(New_Decl
));
3114 while Present
(Aspect
) loop
3115 Set_Analyzed
(Aspect
, False);
3121 -- The analysis of the generated subprogram declaration
3122 -- may have introduced pragmas that need to be analyzed.
3124 Prag
:= Next
(New_Decl
);
3125 while Prag
/= N
loop
3130 Spec_Id
:= Defining_Entity
(New_Decl
);
3132 -- As Body_Id originally comes from source, mark the new
3133 -- Spec_Id as such, which is required so that calls to
3134 -- this subprogram are registered in the local effects
3135 -- stored in ALI files for GNATprove.
3137 Set_Comes_From_Source
(Spec_Id
, True);
3139 -- If aspect SPARK_Mode was specified on the body, it
3140 -- needs to be repeated on the generated decl and the
3141 -- body. Since the original aspect was moved to the
3142 -- generated decl, copy it for the body.
3144 if Has_Aspect
(Spec_Id
, Aspect_SPARK_Mode
) then
3145 SPARK_Mode_Aspect
:=
3146 New_Copy
(Find_Aspect
(Spec_Id
, Aspect_SPARK_Mode
));
3147 Set_Analyzed
(SPARK_Mode_Aspect
, False);
3148 Aspects
:= New_List
(SPARK_Mode_Aspect
);
3149 Set_Aspect_Specifications
(N
, Aspects
);
3152 Set_Specification
(N
, Body_Spec
);
3153 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
3154 Set_Corresponding_Spec
(N
, Spec_Id
);
3159 -- If this is a duplicate body, no point in analyzing it
3161 if Error_Posted
(N
) then
3165 -- A subprogram body should cause freezing of its own declaration,
3166 -- but if there was no previous explicit declaration, then the
3167 -- subprogram will get frozen too late (there may be code within
3168 -- the body that depends on the subprogram having been frozen,
3169 -- such as uses of extra formals), so we force it to be frozen
3170 -- here. Same holds if the body and spec are compilation units.
3171 -- Finally, if the return type is an anonymous access to protected
3172 -- subprogram, it must be frozen before the body because its
3173 -- expansion has generated an equivalent type that is used when
3174 -- elaborating the body.
3176 -- An exception in the case of Ada 2012, AI05-177: The bodies
3177 -- created for expression functions do not freeze.
3180 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3182 Freeze_Before
(N
, Body_Id
);
3184 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3185 Freeze_Before
(N
, Spec_Id
);
3187 elsif Is_Access_Subprogram_Type
(Etype
(Body_Id
)) then
3188 Freeze_Before
(N
, Etype
(Body_Id
));
3192 Spec_Id
:= Corresponding_Spec
(N
);
3196 -- Previously we scanned the body to look for nested subprograms, and
3197 -- rejected an inline directive if nested subprograms were present,
3198 -- because the back-end would generate conflicting symbols for the
3199 -- nested bodies. This is now unnecessary.
3201 -- Look ahead to recognize a pragma Inline that appears after the body
3203 Check_Inline_Pragma
(Spec_Id
);
3205 -- Deal with special case of a fully private operation in the body of
3206 -- the protected type. We must create a declaration for the subprogram,
3207 -- in order to attach the protected subprogram that will be used in
3208 -- internal calls. We exclude compiler generated bodies from the
3209 -- expander since the issue does not arise for those cases.
3212 and then Comes_From_Source
(N
)
3213 and then Is_Protected_Type
(Current_Scope
)
3215 Spec_Id
:= Build_Private_Protected_Declaration
(N
);
3218 -- If a separate spec is present, then deal with freezing issues
3220 if Present
(Spec_Id
) then
3221 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
3222 Verify_Overriding_Indicator
;
3224 -- In general, the spec will be frozen when we start analyzing the
3225 -- body. However, for internally generated operations, such as
3226 -- wrapper functions for inherited operations with controlling
3227 -- results, the spec may not have been frozen by the time we expand
3228 -- the freeze actions that include the bodies. In particular, extra
3229 -- formals for accessibility or for return-in-place may need to be
3230 -- generated. Freeze nodes, if any, are inserted before the current
3231 -- body. These freeze actions are also needed in ASIS mode to enable
3232 -- the proper back-annotations.
3234 if not Is_Frozen
(Spec_Id
)
3235 and then (Expander_Active
or ASIS_Mode
)
3237 -- Force the generation of its freezing node to ensure proper
3238 -- management of access types in the backend.
3240 -- This is definitely needed for some cases, but it is not clear
3241 -- why, to be investigated further???
3243 Set_Has_Delayed_Freeze
(Spec_Id
);
3244 Freeze_Before
(N
, Spec_Id
);
3248 -- Mark presence of postcondition procedure in current scope and mark
3249 -- the procedure itself as needing debug info. The latter is important
3250 -- when analyzing decision coverage (for example, for MC/DC coverage).
3252 if Chars
(Body_Id
) = Name_uPostconditions
then
3253 Set_Has_Postconditions
(Current_Scope
);
3254 Set_Debug_Info_Needed
(Body_Id
);
3257 -- Place subprogram on scope stack, and make formals visible. If there
3258 -- is a spec, the visible entity remains that of the spec.
3260 if Present
(Spec_Id
) then
3261 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
3263 if Is_Child_Unit
(Spec_Id
) then
3264 Generate_Reference
(Spec_Id
, Scope
(Spec_Id
), 'k', False);
3268 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
3271 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3272 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3274 if Is_Abstract_Subprogram
(Spec_Id
) then
3275 Error_Msg_N
("an abstract subprogram cannot have a body", N
);
3279 Set_Convention
(Body_Id
, Convention
(Spec_Id
));
3280 Set_Has_Completion
(Spec_Id
);
3282 if Is_Protected_Type
(Scope
(Spec_Id
)) then
3283 Prot_Typ
:= Scope
(Spec_Id
);
3286 -- If this is a body generated for a renaming, do not check for
3287 -- full conformance. The check is redundant, because the spec of
3288 -- the body is a copy of the spec in the renaming declaration,
3289 -- and the test can lead to spurious errors on nested defaults.
3291 if Present
(Spec_Decl
)
3292 and then not Comes_From_Source
(N
)
3294 (Nkind
(Original_Node
(Spec_Decl
)) =
3295 N_Subprogram_Renaming_Declaration
3296 or else (Present
(Corresponding_Body
(Spec_Decl
))
3298 Nkind
(Unit_Declaration_Node
3299 (Corresponding_Body
(Spec_Decl
))) =
3300 N_Subprogram_Renaming_Declaration
))
3304 -- Conversely, the spec may have been generated for specless body
3305 -- with an inline pragma.
3307 elsif Comes_From_Source
(N
)
3308 and then not Comes_From_Source
(Spec_Id
)
3309 and then Has_Pragma_Inline
(Spec_Id
)
3316 Fully_Conformant
, True, Conformant
, Body_Id
);
3319 -- If the body is not fully conformant, we have to decide if we
3320 -- should analyze it or not. If it has a really messed up profile
3321 -- then we probably should not analyze it, since we will get too
3322 -- many bogus messages.
3324 -- Our decision is to go ahead in the non-fully conformant case
3325 -- only if it is at least mode conformant with the spec. Note
3326 -- that the call to Check_Fully_Conformant has issued the proper
3327 -- error messages to complain about the lack of conformance.
3330 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
3336 if Spec_Id
/= Body_Id
then
3337 Reference_Body_Formals
(Spec_Id
, Body_Id
);
3340 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
3342 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3343 Set_Corresponding_Spec_Of_Stub
(N
, Spec_Id
);
3348 Set_Corresponding_Spec
(N
, Spec_Id
);
3350 -- Ada 2005 (AI-345): If the operation is a primitive operation
3351 -- of a concurrent type, the type of the first parameter has been
3352 -- replaced with the corresponding record, which is the proper
3353 -- run-time structure to use. However, within the body there may
3354 -- be uses of the formals that depend on primitive operations
3355 -- of the type (in particular calls in prefixed form) for which
3356 -- we need the original concurrent type. The operation may have
3357 -- several controlling formals, so the replacement must be done
3360 if Comes_From_Source
(Spec_Id
)
3361 and then Present
(First_Entity
(Spec_Id
))
3362 and then Ekind
(Etype
(First_Entity
(Spec_Id
))) = E_Record_Type
3363 and then Is_Tagged_Type
(Etype
(First_Entity
(Spec_Id
)))
3364 and then Present
(Interfaces
(Etype
(First_Entity
(Spec_Id
))))
3365 and then Present
(Corresponding_Concurrent_Type
3366 (Etype
(First_Entity
(Spec_Id
))))
3369 Typ
: constant Entity_Id
:= Etype
(First_Entity
(Spec_Id
));
3373 Form
:= First_Formal
(Spec_Id
);
3374 while Present
(Form
) loop
3375 if Etype
(Form
) = Typ
then
3376 Set_Etype
(Form
, Corresponding_Concurrent_Type
(Typ
));
3384 -- Make the formals visible, and place subprogram on scope stack.
3385 -- This is also the point at which we set Last_Real_Spec_Entity
3386 -- to mark the entities which will not be moved to the body.
3388 Install_Formals
(Spec_Id
);
3389 Last_Real_Spec_Entity
:= Last_Entity
(Spec_Id
);
3391 -- Within an instance, add local renaming declarations so that
3392 -- gdb can retrieve the values of actuals more easily. This is
3393 -- only relevant if generating code (and indeed we definitely
3394 -- do not want these definitions -gnatc mode, because that would
3397 if Is_Generic_Instance
(Spec_Id
)
3398 and then Is_Wrapper_Package
(Current_Scope
)
3399 and then Expander_Active
3401 Build_Subprogram_Instance_Renamings
(N
, Current_Scope
);
3404 Push_Scope
(Spec_Id
);
3406 -- Make sure that the subprogram is immediately visible. For
3407 -- child units that have no separate spec this is indispensable.
3408 -- Otherwise it is safe albeit redundant.
3410 Set_Is_Immediately_Visible
(Spec_Id
);
3413 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
3414 Set_Contract
(Body_Id
, Make_Contract
(Sloc
(Body_Id
)));
3415 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
3416 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Spec_Id
));
3418 -- Case of subprogram body with no previous spec
3421 -- Check for style warning required
3425 -- Only apply check for source level subprograms for which checks
3426 -- have not been suppressed.
3428 and then Comes_From_Source
(Body_Id
)
3429 and then not Suppress_Style_Checks
(Body_Id
)
3431 -- No warnings within an instance
3433 and then not In_Instance
3435 -- No warnings for expression functions
3437 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3439 Style
.Body_With_No_Spec
(N
);
3442 New_Overloaded_Entity
(Body_Id
);
3444 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
3445 Set_Acts_As_Spec
(N
);
3446 Generate_Definition
(Body_Id
);
3447 Set_Contract
(Body_Id
, Make_Contract
(Sloc
(Body_Id
)));
3449 (Body_Id
, Body_Id
, 'b', Set_Ref
=> False, Force
=> True);
3450 Install_Formals
(Body_Id
);
3452 Push_Scope
(Body_Id
);
3455 -- For stubs and bodies with no previous spec, generate references to
3458 Generate_Reference_To_Formals
(Body_Id
);
3461 -- Set SPARK_Mode from context
3463 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
3464 Set_SPARK_Pragma_Inherited
(Body_Id
, True);
3466 -- If the return type is an anonymous access type whose designated type
3467 -- is the limited view of a class-wide type and the non-limited view is
3468 -- available, update the return type accordingly.
3470 if Ada_Version
>= Ada_2005
and then Comes_From_Source
(N
) then
3476 Rtyp
:= Etype
(Current_Scope
);
3478 if Ekind
(Rtyp
) = E_Anonymous_Access_Type
then
3479 Etyp
:= Directly_Designated_Type
(Rtyp
);
3481 if Is_Class_Wide_Type
(Etyp
)
3482 and then From_Limited_With
(Etyp
)
3484 Set_Directly_Designated_Type
3485 (Etype
(Current_Scope
), Available_View
(Etyp
));
3491 -- If this is the proper body of a stub, we must verify that the stub
3492 -- conforms to the body, and to the previous spec if one was present.
3493 -- We know already that the body conforms to that spec. This test is
3494 -- only required for subprograms that come from source.
3496 if Nkind
(Parent
(N
)) = N_Subunit
3497 and then Comes_From_Source
(N
)
3498 and then not Error_Posted
(Body_Id
)
3499 and then Nkind
(Corresponding_Stub
(Parent
(N
))) =
3500 N_Subprogram_Body_Stub
3503 Old_Id
: constant Entity_Id
:=
3505 (Specification
(Corresponding_Stub
(Parent
(N
))));
3507 Conformant
: Boolean := False;
3510 if No
(Spec_Id
) then
3511 Check_Fully_Conformant
(Body_Id
, Old_Id
);
3515 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
3517 if not Conformant
then
3519 -- The stub was taken to be a new declaration. Indicate that
3522 Set_Has_Completion
(Old_Id
, False);
3528 Set_Has_Completion
(Body_Id
);
3529 Check_Eliminated
(Body_Id
);
3531 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3533 -- Analyze any aspect specifications that appear on the subprogram
3536 if Has_Aspects
(N
) then
3537 Analyze_Aspects_On_Body_Or_Stub
;
3540 -- Stop the analysis now as the stub cannot be inlined, plus it does
3541 -- not have declarative or statement lists.
3546 -- Handle frontend inlining
3548 -- Note: Normally we don't do any inlining if expansion is off, since
3549 -- we won't generate code in any case. An exception arises in GNATprove
3550 -- mode where we want to expand some calls in place, even with expansion
3551 -- disabled, since the inlining eases formal verification.
3555 if not Debug_Flag_Dot_K
then
3556 if Present
(Spec_Id
)
3557 and then Expander_Active
3559 (Has_Pragma_Inline_Always
(Spec_Id
)
3560 or else (Has_Pragma_Inline
(Spec_Id
) and Front_End_Inlining
))
3562 Build_Body_To_Inline
(N
, Spec_Id
);
3564 -- In GNATprove mode, inline only when there is a separate subprogram
3565 -- declaration for now, as inlining of subprogram bodies acting as
3566 -- declarations, or subprogram stubs, are not supported by frontend
3567 -- inlining. This inlining should occur after analysis of the body,
3568 -- so that it is known whether the value of SPARK_Mode applicable to
3569 -- the body, which can be defined by a pragma inside the body.
3571 elsif GNATprove_Mode
3572 and then Full_Analysis
3573 and then not Inside_A_Generic
3574 and then Present
(Spec_Id
)
3576 Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Declaration
3577 and then Can_Be_Inlined_In_GNATprove_Mode
(Spec_Id
, Body_Id
)
3578 and then not Body_Has_Contract
3580 Build_Body_To_Inline
(N
, Spec_Id
);
3583 -- New semantics (enabled by debug flag gnatd.k for testing)
3585 elsif Expander_Active
3586 and then Serious_Errors_Detected
= 0
3587 and then Present
(Spec_Id
)
3588 and then Has_Pragma_Inline
(Spec_Id
)
3590 Check_And_Build_Body_To_Inline
(N
, Spec_Id
, Body_Id
);
3592 -- In GNATprove mode, inline only when there is a separate subprogram
3593 -- declaration for now, as inlining of subprogram bodies acting as
3594 -- declarations, or subprogram stubs, are not supported by frontend
3595 -- inlining. This inlining should occur after analysis of the body, so
3596 -- that it is known whether the value of SPARK_Mode applicable to the
3597 -- body, which can be defined by a pragma inside the body.
3599 elsif GNATprove_Mode
3600 and then Full_Analysis
3601 and then not Inside_A_Generic
3602 and then Present
(Spec_Id
)
3603 and then Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Declaration
3604 and then Can_Be_Inlined_In_GNATprove_Mode
(Spec_Id
, Body_Id
)
3605 and then not Body_Has_Contract
3607 Check_And_Build_Body_To_Inline
(N
, Spec_Id
, Body_Id
);
3610 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
3611 -- of the specification we have to install the private withed units.
3612 -- This holds for child units as well.
3614 if Is_Compilation_Unit
(Body_Id
)
3615 or else Nkind
(Parent
(N
)) = N_Compilation_Unit
3617 Install_Private_With_Clauses
(Body_Id
);
3620 Check_Anonymous_Return
;
3622 -- Set the Protected_Formal field of each extra formal of the protected
3623 -- subprogram to reference the corresponding extra formal of the
3624 -- subprogram that implements it. For regular formals this occurs when
3625 -- the protected subprogram's declaration is expanded, but the extra
3626 -- formals don't get created until the subprogram is frozen. We need to
3627 -- do this before analyzing the protected subprogram's body so that any
3628 -- references to the original subprogram's extra formals will be changed
3629 -- refer to the implementing subprogram's formals (see Expand_Formal).
3631 if Present
(Spec_Id
)
3632 and then Is_Protected_Type
(Scope
(Spec_Id
))
3633 and then Present
(Protected_Body_Subprogram
(Spec_Id
))
3636 Impl_Subp
: constant Entity_Id
:=
3637 Protected_Body_Subprogram
(Spec_Id
);
3638 Prot_Ext_Formal
: Entity_Id
:= Extra_Formals
(Spec_Id
);
3639 Impl_Ext_Formal
: Entity_Id
:= Extra_Formals
(Impl_Subp
);
3641 while Present
(Prot_Ext_Formal
) loop
3642 pragma Assert
(Present
(Impl_Ext_Formal
));
3643 Set_Protected_Formal
(Prot_Ext_Formal
, Impl_Ext_Formal
);
3644 Next_Formal_With_Extras
(Prot_Ext_Formal
);
3645 Next_Formal_With_Extras
(Impl_Ext_Formal
);
3650 -- Now we can go on to analyze the body
3652 HSS
:= Handled_Statement_Sequence
(N
);
3653 Set_Actual_Subtypes
(N
, Current_Scope
);
3655 -- Add a declaration for the Protection object, renaming declarations
3656 -- for discriminals and privals and finally a declaration for the entry
3657 -- family index (if applicable). This form of early expansion is done
3658 -- when the Expander is active because Install_Private_Data_Declarations
3659 -- references entities which were created during regular expansion. The
3660 -- subprogram entity must come from source, and not be an internally
3661 -- generated subprogram.
3664 and then Present
(Prot_Typ
)
3665 and then Present
(Spec_Id
)
3666 and then Comes_From_Source
(Spec_Id
)
3667 and then not Is_Eliminated
(Spec_Id
)
3669 Install_Private_Data_Declarations
3670 (Sloc
(N
), Spec_Id
, Prot_Typ
, N
, Declarations
(N
));
3673 -- Ada 2012 (AI05-0151): Incomplete types coming from a limited context
3674 -- may now appear in parameter and result profiles. Since the analysis
3675 -- of a subprogram body may use the parameter and result profile of the
3676 -- spec, swap any limited views with their non-limited counterpart.
3678 if Ada_Version
>= Ada_2012
then
3679 Exchange_Limited_Views
(Spec_Id
);
3682 -- Analyze any aspect specifications that appear on the subprogram body
3684 if Has_Aspects
(N
) then
3685 Analyze_Aspects_On_Body_Or_Stub
;
3688 -- Deal with [refined] preconditions, postconditions, Contract_Cases,
3689 -- invariants and predicates associated with the body and its spec.
3690 -- Note that this is not pure expansion as Expand_Subprogram_Contract
3691 -- prepares the contract assertions for generic subprograms or for ASIS.
3692 -- Do not generate contract checks in SPARK mode.
3694 if not GNATprove_Mode
then
3695 Expand_Subprogram_Contract
(N
, Spec_Id
, Body_Id
);
3698 -- Analyze the declarations (this call will analyze the precondition
3699 -- Check pragmas we prepended to the list, as well as the declaration
3700 -- of the _Postconditions procedure).
3702 Analyze_Declarations
(Declarations
(N
));
3704 -- After declarations have been analyzed, the body has been set
3705 -- its final value of SPARK_Mode. Check that SPARK_Mode for body
3706 -- is consistent with SPARK_Mode for spec.
3708 if Present
(Spec_Id
) and then Present
(SPARK_Pragma
(Body_Id
)) then
3709 if Present
(SPARK_Pragma
(Spec_Id
)) then
3710 if Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Spec_Id
)) = Off
3712 Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Body_Id
)) = On
3714 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
3715 Error_Msg_N
("incorrect application of SPARK_Mode#", N
);
3716 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Spec_Id
));
3718 ("\value Off was set for SPARK_Mode on&#", N
, Spec_Id
);
3721 elsif Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Body_Stub
then
3725 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
3726 Error_Msg_N
("incorrect application of SPARK_Mode#", N
);
3727 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
3728 Error_Msg_NE
("\no value was set for SPARK_Mode on&#", N
, Spec_Id
);
3732 -- If SPARK_Mode for body is not On, disable frontend inlining for this
3733 -- subprogram in GNATprove mode, as its body should not be analyzed.
3736 and then GNATprove_Mode
3737 and then Present
(Spec_Id
)
3738 and then Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Declaration
3740 Set_Body_To_Inline
(Parent
(Parent
(Spec_Id
)), Empty
);
3741 Set_Is_Inlined_Always
(Spec_Id
, False);
3744 -- Check completion, and analyze the statements
3747 Inspect_Deferred_Constant_Completion
(Declarations
(N
));
3750 -- Deal with end of scope processing for the body
3752 Process_End_Label
(HSS
, 't', Current_Scope
);
3754 Check_Subprogram_Order
(N
);
3755 Set_Analyzed
(Body_Id
);
3757 -- If we have a separate spec, then the analysis of the declarations
3758 -- caused the entities in the body to be chained to the spec id, but
3759 -- we want them chained to the body id. Only the formal parameters
3760 -- end up chained to the spec id in this case.
3762 if Present
(Spec_Id
) then
3764 -- We must conform to the categorization of our spec
3766 Validate_Categorization_Dependency
(N
, Spec_Id
);
3768 -- And if this is a child unit, the parent units must conform
3770 if Is_Child_Unit
(Spec_Id
) then
3771 Validate_Categorization_Dependency
3772 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
3775 -- Here is where we move entities from the spec to the body
3777 -- Case where there are entities that stay with the spec
3779 if Present
(Last_Real_Spec_Entity
) then
3781 -- No body entities (happens when the only real spec entities come
3782 -- from precondition and postcondition pragmas).
3784 if No
(Last_Entity
(Body_Id
)) then
3786 (Body_Id
, Next_Entity
(Last_Real_Spec_Entity
));
3788 -- Body entities present (formals), so chain stuff past them
3792 (Last_Entity
(Body_Id
), Next_Entity
(Last_Real_Spec_Entity
));
3795 Set_Next_Entity
(Last_Real_Spec_Entity
, Empty
);
3796 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
3797 Set_Last_Entity
(Spec_Id
, Last_Real_Spec_Entity
);
3799 -- Case where there are no spec entities, in this case there can be
3800 -- no body entities either, so just move everything.
3803 pragma Assert
(No
(Last_Entity
(Body_Id
)));
3804 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
3805 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
3806 Set_First_Entity
(Spec_Id
, Empty
);
3807 Set_Last_Entity
(Spec_Id
, Empty
);
3811 Check_Missing_Return
;
3813 -- Now we are going to check for variables that are never modified in
3814 -- the body of the procedure. But first we deal with a special case
3815 -- where we want to modify this check. If the body of the subprogram
3816 -- starts with a raise statement or its equivalent, or if the body
3817 -- consists entirely of a null statement, then it is pretty obvious that
3818 -- it is OK to not reference the parameters. For example, this might be
3819 -- the following common idiom for a stubbed function: statement of the
3820 -- procedure raises an exception. In particular this deals with the
3821 -- common idiom of a stubbed function, which appears something like:
3823 -- function F (A : Integer) return Some_Type;
3826 -- raise Program_Error;
3830 -- Here the purpose of X is simply to satisfy the annoying requirement
3831 -- in Ada that there be at least one return, and we certainly do not
3832 -- want to go posting warnings on X that it is not initialized. On
3833 -- the other hand, if X is entirely unreferenced that should still
3836 -- What we do is to detect these cases, and if we find them, flag the
3837 -- subprogram as being Is_Trivial_Subprogram and then use that flag to
3838 -- suppress unwanted warnings. For the case of the function stub above
3839 -- we have a special test to set X as apparently assigned to suppress
3846 -- Skip initial labels (for one thing this occurs when we are in
3847 -- front end ZCX mode, but in any case it is irrelevant), and also
3848 -- initial Push_xxx_Error_Label nodes, which are also irrelevant.
3850 Stm
:= First
(Statements
(HSS
));
3851 while Nkind
(Stm
) = N_Label
3852 or else Nkind
(Stm
) in N_Push_xxx_Label
3857 -- Do the test on the original statement before expansion
3860 Ostm
: constant Node_Id
:= Original_Node
(Stm
);
3863 -- If explicit raise statement, turn on flag
3865 if Nkind
(Ostm
) = N_Raise_Statement
then
3866 Set_Trivial_Subprogram
(Stm
);
3868 -- If null statement, and no following statements, turn on flag
3870 elsif Nkind
(Stm
) = N_Null_Statement
3871 and then Comes_From_Source
(Stm
)
3872 and then No
(Next
(Stm
))
3874 Set_Trivial_Subprogram
(Stm
);
3876 -- Check for explicit call cases which likely raise an exception
3878 elsif Nkind
(Ostm
) = N_Procedure_Call_Statement
then
3879 if Is_Entity_Name
(Name
(Ostm
)) then
3881 Ent
: constant Entity_Id
:= Entity
(Name
(Ostm
));
3884 -- If the procedure is marked No_Return, then likely it
3885 -- raises an exception, but in any case it is not coming
3886 -- back here, so turn on the flag.
3889 and then Ekind
(Ent
) = E_Procedure
3890 and then No_Return
(Ent
)
3892 Set_Trivial_Subprogram
(Stm
);
3900 -- Check for variables that are never modified
3906 -- If there is a separate spec, then transfer Never_Set_In_Source
3907 -- flags from out parameters to the corresponding entities in the
3908 -- body. The reason we do that is we want to post error flags on
3909 -- the body entities, not the spec entities.
3911 if Present
(Spec_Id
) then
3912 E1
:= First_Entity
(Spec_Id
);
3913 while Present
(E1
) loop
3914 if Ekind
(E1
) = E_Out_Parameter
then
3915 E2
:= First_Entity
(Body_Id
);
3916 while Present
(E2
) loop
3917 exit when Chars
(E1
) = Chars
(E2
);
3921 if Present
(E2
) then
3922 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
3930 -- Check references in body
3932 Check_References
(Body_Id
);
3934 end Analyze_Subprogram_Body_Helper
;
3936 ---------------------------------
3937 -- Analyze_Subprogram_Contract --
3938 ---------------------------------
3940 procedure Analyze_Subprogram_Contract
(Subp
: Entity_Id
) is
3941 Items
: constant Node_Id
:= Contract
(Subp
);
3942 Case_Prag
: Node_Id
:= Empty
;
3943 Depends
: Node_Id
:= Empty
;
3944 Global
: Node_Id
:= Empty
;
3945 Mode
: SPARK_Mode_Type
;
3947 Post_Prag
: Node_Id
:= Empty
;
3949 Seen_In_Case
: Boolean := False;
3950 Seen_In_Post
: Boolean := False;
3953 -- Due to the timing of contract analysis, delayed pragmas may be
3954 -- subject to the wrong SPARK_Mode, usually that of the enclosing
3955 -- context. To remedy this, restore the original SPARK_Mode of the
3956 -- related subprogram body.
3958 Save_SPARK_Mode_And_Set
(Subp
, Mode
);
3960 if Present
(Items
) then
3962 -- Analyze pre- and postconditions
3964 Prag
:= Pre_Post_Conditions
(Items
);
3965 while Present
(Prag
) loop
3966 Analyze_Pre_Post_Condition_In_Decl_Part
(Prag
, Subp
);
3968 -- Verify whether a postcondition mentions attribute 'Result and
3969 -- its expression introduces a post-state.
3971 if Warn_On_Suspicious_Contract
3972 and then Pragma_Name
(Prag
) = Name_Postcondition
3975 Check_Result_And_Post_State
(Prag
, Seen_In_Post
);
3978 Prag
:= Next_Pragma
(Prag
);
3981 -- Analyze contract-cases and test-cases
3983 Prag
:= Contract_Test_Cases
(Items
);
3984 while Present
(Prag
) loop
3985 Nam
:= Pragma_Name
(Prag
);
3987 if Nam
= Name_Contract_Cases
then
3988 Analyze_Contract_Cases_In_Decl_Part
(Prag
);
3990 -- Verify whether contract-cases mention attribute 'Result and
3991 -- its expression introduces a post-state. Perform the check
3992 -- only when the pragma is legal.
3994 if Warn_On_Suspicious_Contract
3995 and then not Error_Posted
(Prag
)
3998 Check_Result_And_Post_State
(Prag
, Seen_In_Case
);
4002 pragma Assert
(Nam
= Name_Test_Case
);
4003 Analyze_Test_Case_In_Decl_Part
(Prag
, Subp
);
4006 Prag
:= Next_Pragma
(Prag
);
4009 -- Analyze classification pragmas
4011 Prag
:= Classifications
(Items
);
4012 while Present
(Prag
) loop
4013 Nam
:= Pragma_Name
(Prag
);
4015 if Nam
= Name_Depends
then
4017 else pragma Assert
(Nam
= Name_Global
);
4021 Prag
:= Next_Pragma
(Prag
);
4024 -- Analyze Global first as Depends may mention items classified in
4025 -- the global categorization.
4027 if Present
(Global
) then
4028 Analyze_Global_In_Decl_Part
(Global
);
4031 -- Depends must be analyzed after Global in order to see the modes of
4032 -- all global items.
4034 if Present
(Depends
) then
4035 Analyze_Depends_In_Decl_Part
(Depends
);
4039 -- Emit an error when neither the postconditions nor the contract-cases
4040 -- mention attribute 'Result in the context of a function.
4042 if Warn_On_Suspicious_Contract
4043 and then Ekind_In
(Subp
, E_Function
, E_Generic_Function
)
4045 if Present
(Case_Prag
)
4046 and then not Seen_In_Case
4047 and then Present
(Post_Prag
)
4048 and then not Seen_In_Post
4051 ("neither function postcondition nor contract cases mention "
4052 & "result?T?", Post_Prag
);
4054 elsif Present
(Case_Prag
) and then not Seen_In_Case
then
4056 ("contract cases do not mention result?T?", Case_Prag
);
4058 -- OK if we have at least one IN OUT parameter
4060 elsif Present
(Post_Prag
) and then not Seen_In_Post
then
4064 F
:= First_Formal
(Subp
);
4065 while Present
(F
) loop
4066 if Ekind
(F
) = E_In_Out_Parameter
then
4074 -- If no in-out parameters and no mention of Result, the contract
4075 -- is certainly suspicious.
4078 ("function postcondition does not mention result?T?", Post_Prag
);
4082 -- Restore the SPARK_Mode of the enclosing context after all delayed
4083 -- pragmas have been analyzed.
4085 Restore_SPARK_Mode
(Mode
);
4086 end Analyze_Subprogram_Contract
;
4088 ------------------------------------
4089 -- Analyze_Subprogram_Declaration --
4090 ------------------------------------
4092 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
4093 Scop
: constant Entity_Id
:= Current_Scope
;
4094 Designator
: Entity_Id
;
4096 Is_Completion
: Boolean;
4097 -- Indicates whether a null procedure declaration is a completion
4100 -- Null procedures are not allowed in SPARK
4102 if Nkind
(Specification
(N
)) = N_Procedure_Specification
4103 and then Null_Present
(Specification
(N
))
4105 Check_SPARK_Restriction
("null procedure is not allowed", N
);
4107 if Is_Protected_Type
(Current_Scope
) then
4108 Error_Msg_N
("protected operation cannot be a null procedure", N
);
4111 Analyze_Null_Procedure
(N
, Is_Completion
);
4113 if Is_Completion
then
4115 -- The null procedure acts as a body, nothing further is needed.
4121 Designator
:= Analyze_Subprogram_Specification
(Specification
(N
));
4123 -- A reference may already have been generated for the unit name, in
4124 -- which case the following call is redundant. However it is needed for
4125 -- declarations that are the rewriting of an expression function.
4127 Generate_Definition
(Designator
);
4129 -- Set SPARK mode from current context (may be overwritten later with
4130 -- explicit pragma).
4132 Set_SPARK_Pragma
(Designator
, SPARK_Mode_Pragma
);
4133 Set_SPARK_Pragma_Inherited
(Designator
, True);
4135 if Debug_Flag_C
then
4136 Write_Str
("==> subprogram spec ");
4137 Write_Name
(Chars
(Designator
));
4138 Write_Str
(" from ");
4139 Write_Location
(Sloc
(N
));
4144 Validate_RCI_Subprogram_Declaration
(N
);
4145 New_Overloaded_Entity
(Designator
);
4146 Check_Delayed_Subprogram
(Designator
);
4148 -- If the type of the first formal of the current subprogram is a non-
4149 -- generic tagged private type, mark the subprogram as being a private
4150 -- primitive. Ditto if this is a function with controlling result, and
4151 -- the return type is currently private. In both cases, the type of the
4152 -- controlling argument or result must be in the current scope for the
4153 -- operation to be primitive.
4155 if Has_Controlling_Result
(Designator
)
4156 and then Is_Private_Type
(Etype
(Designator
))
4157 and then Scope
(Etype
(Designator
)) = Current_Scope
4158 and then not Is_Generic_Actual_Type
(Etype
(Designator
))
4160 Set_Is_Private_Primitive
(Designator
);
4162 elsif Present
(First_Formal
(Designator
)) then
4164 Formal_Typ
: constant Entity_Id
:=
4165 Etype
(First_Formal
(Designator
));
4167 Set_Is_Private_Primitive
(Designator
,
4168 Is_Tagged_Type
(Formal_Typ
)
4169 and then Scope
(Formal_Typ
) = Current_Scope
4170 and then Is_Private_Type
(Formal_Typ
)
4171 and then not Is_Generic_Actual_Type
(Formal_Typ
));
4175 -- Ada 2005 (AI-251): Abstract interface primitives must be abstract
4178 if Ada_Version
>= Ada_2005
4179 and then Comes_From_Source
(N
)
4180 and then Is_Dispatching_Operation
(Designator
)
4187 if Has_Controlling_Result
(Designator
) then
4188 Etyp
:= Etype
(Designator
);
4191 E
:= First_Entity
(Designator
);
4193 and then Is_Formal
(E
)
4194 and then not Is_Controlling_Formal
(E
)
4202 if Is_Access_Type
(Etyp
) then
4203 Etyp
:= Directly_Designated_Type
(Etyp
);
4206 if Is_Interface
(Etyp
)
4207 and then not Is_Abstract_Subprogram
(Designator
)
4208 and then not (Ekind
(Designator
) = E_Procedure
4209 and then Null_Present
(Specification
(N
)))
4211 Error_Msg_Name_1
:= Chars
(Defining_Entity
(N
));
4213 -- Specialize error message based on procedures vs. functions,
4214 -- since functions can't be null subprograms.
4216 if Ekind
(Designator
) = E_Procedure
then
4218 ("interface procedure % must be abstract or null", N
);
4221 ("interface function % must be abstract", N
);
4227 -- What is the following code for, it used to be
4229 -- ??? Set_Suppress_Elaboration_Checks
4230 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
4232 -- The following seems equivalent, but a bit dubious
4234 if Elaboration_Checks_Suppressed
(Designator
) then
4235 Set_Kill_Elaboration_Checks
(Designator
);
4238 if Scop
/= Standard_Standard
and then not Is_Child_Unit
(Designator
) then
4239 Set_Categorization_From_Scope
(Designator
, Scop
);
4242 -- For a compilation unit, check for library-unit pragmas
4244 Push_Scope
(Designator
);
4245 Set_Categorization_From_Pragmas
(N
);
4246 Validate_Categorization_Dependency
(N
, Designator
);
4250 -- For a compilation unit, set body required. This flag will only be
4251 -- reset if a valid Import or Interface pragma is processed later on.
4253 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
4254 Set_Body_Required
(Parent
(N
), True);
4256 if Ada_Version
>= Ada_2005
4257 and then Nkind
(Specification
(N
)) = N_Procedure_Specification
4258 and then Null_Present
(Specification
(N
))
4261 ("null procedure cannot be declared at library level", N
);
4265 Generate_Reference_To_Formals
(Designator
);
4266 Check_Eliminated
(Designator
);
4268 if Debug_Flag_C
then
4270 Write_Str
("<== subprogram spec ");
4271 Write_Name
(Chars
(Designator
));
4272 Write_Str
(" from ");
4273 Write_Location
(Sloc
(N
));
4277 if Is_Protected_Type
(Current_Scope
) then
4279 -- Indicate that this is a protected operation, because it may be
4280 -- used in subsequent declarations within the protected type.
4282 Set_Convention
(Designator
, Convention_Protected
);
4285 List_Inherited_Pre_Post_Aspects
(Designator
);
4287 if Has_Aspects
(N
) then
4288 Analyze_Aspect_Specifications
(N
, Designator
);
4290 end Analyze_Subprogram_Declaration
;
4292 --------------------------------------
4293 -- Analyze_Subprogram_Specification --
4294 --------------------------------------
4296 -- Reminder: N here really is a subprogram specification (not a subprogram
4297 -- declaration). This procedure is called to analyze the specification in
4298 -- both subprogram bodies and subprogram declarations (specs).
4300 function Analyze_Subprogram_Specification
(N
: Node_Id
) return Entity_Id
is
4301 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
4302 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
4304 -- Start of processing for Analyze_Subprogram_Specification
4307 -- User-defined operator is not allowed in SPARK, except as a renaming
4309 if Nkind
(Defining_Unit_Name
(N
)) = N_Defining_Operator_Symbol
4310 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
4312 Check_SPARK_Restriction
("user-defined operator is not allowed", N
);
4315 -- Proceed with analysis. Do not emit a cross-reference entry if the
4316 -- specification comes from an expression function, because it may be
4317 -- the completion of a previous declaration. It is is not, the cross-
4318 -- reference entry will be emitted for the new subprogram declaration.
4320 if Nkind
(Parent
(N
)) /= N_Expression_Function
then
4321 Generate_Definition
(Designator
);
4324 Set_Contract
(Designator
, Make_Contract
(Sloc
(Designator
)));
4326 if Nkind
(N
) = N_Function_Specification
then
4327 Set_Ekind
(Designator
, E_Function
);
4328 Set_Mechanism
(Designator
, Default_Mechanism
);
4330 Set_Ekind
(Designator
, E_Procedure
);
4331 Set_Etype
(Designator
, Standard_Void_Type
);
4334 -- Flag Is_Inlined_Always is True by default, and reversed to False for
4335 -- those subprograms which could be inlined in GNATprove mode (because
4336 -- Body_To_Inline is non-Empty) but cannot be inlined.
4338 if GNATprove_Mode
then
4339 Set_Is_Inlined_Always
(Designator
);
4342 -- Introduce new scope for analysis of the formals and the return type
4344 Set_Scope
(Designator
, Current_Scope
);
4346 if Present
(Formals
) then
4347 Push_Scope
(Designator
);
4348 Process_Formals
(Formals
, N
);
4350 -- Check dimensions in N for formals with default expression
4352 Analyze_Dimension_Formals
(N
, Formals
);
4354 -- Ada 2005 (AI-345): If this is an overriding operation of an
4355 -- inherited interface operation, and the controlling type is
4356 -- a synchronized type, replace the type with its corresponding
4357 -- record, to match the proper signature of an overriding operation.
4358 -- Same processing for an access parameter whose designated type is
4359 -- derived from a synchronized interface.
4361 if Ada_Version
>= Ada_2005
then
4364 Formal_Typ
: Entity_Id
;
4365 Rec_Typ
: Entity_Id
;
4366 Desig_Typ
: Entity_Id
;
4369 Formal
:= First_Formal
(Designator
);
4370 while Present
(Formal
) loop
4371 Formal_Typ
:= Etype
(Formal
);
4373 if Is_Concurrent_Type
(Formal_Typ
)
4374 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
4376 Rec_Typ
:= Corresponding_Record_Type
(Formal_Typ
);
4378 if Present
(Interfaces
(Rec_Typ
)) then
4379 Set_Etype
(Formal
, Rec_Typ
);
4382 elsif Ekind
(Formal_Typ
) = E_Anonymous_Access_Type
then
4383 Desig_Typ
:= Designated_Type
(Formal_Typ
);
4385 if Is_Concurrent_Type
(Desig_Typ
)
4386 and then Present
(Corresponding_Record_Type
(Desig_Typ
))
4388 Rec_Typ
:= Corresponding_Record_Type
(Desig_Typ
);
4390 if Present
(Interfaces
(Rec_Typ
)) then
4391 Set_Directly_Designated_Type
(Formal_Typ
, Rec_Typ
);
4396 Next_Formal
(Formal
);
4403 -- The subprogram scope is pushed and popped around the processing of
4404 -- the return type for consistency with call above to Process_Formals
4405 -- (which itself can call Analyze_Return_Type), and to ensure that any
4406 -- itype created for the return type will be associated with the proper
4409 elsif Nkind
(N
) = N_Function_Specification
then
4410 Push_Scope
(Designator
);
4411 Analyze_Return_Type
(N
);
4417 if Nkind
(N
) = N_Function_Specification
then
4419 -- Deal with operator symbol case
4421 if Nkind
(Designator
) = N_Defining_Operator_Symbol
then
4422 Valid_Operator_Definition
(Designator
);
4425 May_Need_Actuals
(Designator
);
4427 -- Ada 2005 (AI-251): If the return type is abstract, verify that
4428 -- the subprogram is abstract also. This does not apply to renaming
4429 -- declarations, where abstractness is inherited, and to subprogram
4430 -- bodies generated for stream operations, which become renamings as
4433 -- In case of primitives associated with abstract interface types
4434 -- the check is applied later (see Analyze_Subprogram_Declaration).
4436 if not Nkind_In
(Original_Node
(Parent
(N
)),
4437 N_Subprogram_Renaming_Declaration
,
4438 N_Abstract_Subprogram_Declaration
,
4439 N_Formal_Abstract_Subprogram_Declaration
)
4441 if Is_Abstract_Type
(Etype
(Designator
))
4442 and then not Is_Interface
(Etype
(Designator
))
4445 ("function that returns abstract type must be abstract", N
);
4447 -- Ada 2012 (AI-0073): Extend this test to subprograms with an
4448 -- access result whose designated type is abstract.
4450 elsif Nkind
(Result_Definition
(N
)) = N_Access_Definition
4452 not Is_Class_Wide_Type
(Designated_Type
(Etype
(Designator
)))
4453 and then Is_Abstract_Type
(Designated_Type
(Etype
(Designator
)))
4454 and then Ada_Version
>= Ada_2012
4456 Error_Msg_N
("function whose access result designates "
4457 & "abstract type must be abstract", N
);
4463 end Analyze_Subprogram_Specification
;
4465 -----------------------
4466 -- Check_Conformance --
4467 -----------------------
4469 procedure Check_Conformance
4470 (New_Id
: Entity_Id
;
4472 Ctype
: Conformance_Type
;
4474 Conforms
: out Boolean;
4475 Err_Loc
: Node_Id
:= Empty
;
4476 Get_Inst
: Boolean := False;
4477 Skip_Controlling_Formals
: Boolean := False)
4479 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
4480 -- Sets Conforms to False. If Errmsg is False, then that's all it does.
4481 -- If Errmsg is True, then processing continues to post an error message
4482 -- for conformance error on given node. Two messages are output. The
4483 -- first message points to the previous declaration with a general "no
4484 -- conformance" message. The second is the detailed reason, supplied as
4485 -- Msg. The parameter N provide information for a possible & insertion
4486 -- in the message, and also provides the location for posting the
4487 -- message in the absence of a specified Err_Loc location.
4489 -----------------------
4490 -- Conformance_Error --
4491 -----------------------
4493 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
4500 if No
(Err_Loc
) then
4506 Error_Msg_Sloc
:= Sloc
(Old_Id
);
4509 when Type_Conformant
=>
4510 Error_Msg_N
-- CODEFIX
4511 ("not type conformant with declaration#!", Enode
);
4513 when Mode_Conformant
=>
4514 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4516 ("not mode conformant with operation inherited#!",
4520 ("not mode conformant with declaration#!", Enode
);
4523 when Subtype_Conformant
=>
4524 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4526 ("not subtype conformant with operation inherited#!",
4530 ("not subtype conformant with declaration#!", Enode
);
4533 when Fully_Conformant
=>
4534 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
4535 Error_Msg_N
-- CODEFIX
4536 ("not fully conformant with operation inherited#!",
4539 Error_Msg_N
-- CODEFIX
4540 ("not fully conformant with declaration#!", Enode
);
4544 Error_Msg_NE
(Msg
, Enode
, N
);
4546 end Conformance_Error
;
4550 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
4551 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
4552 Old_Formal
: Entity_Id
;
4553 New_Formal
: Entity_Id
;
4554 Access_Types_Match
: Boolean;
4555 Old_Formal_Base
: Entity_Id
;
4556 New_Formal_Base
: Entity_Id
;
4558 -- Start of processing for Check_Conformance
4563 -- We need a special case for operators, since they don't appear
4566 if Ctype
= Type_Conformant
then
4567 if Ekind
(New_Id
) = E_Operator
4568 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
4574 -- If both are functions/operators, check return types conform
4576 if Old_Type
/= Standard_Void_Type
4577 and then New_Type
/= Standard_Void_Type
4580 -- If we are checking interface conformance we omit controlling
4581 -- arguments and result, because we are only checking the conformance
4582 -- of the remaining parameters.
4584 if Has_Controlling_Result
(Old_Id
)
4585 and then Has_Controlling_Result
(New_Id
)
4586 and then Skip_Controlling_Formals
4590 elsif not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
4591 if Ctype
>= Subtype_Conformant
4592 and then not Predicates_Match
(Old_Type
, New_Type
)
4595 ("\predicate of return type does not match!", New_Id
);
4598 ("\return type does not match!", New_Id
);
4604 -- Ada 2005 (AI-231): In case of anonymous access types check the
4605 -- null-exclusion and access-to-constant attributes match.
4607 if Ada_Version
>= Ada_2005
4608 and then Ekind
(Etype
(Old_Type
)) = E_Anonymous_Access_Type
4610 (Can_Never_Be_Null
(Old_Type
) /= Can_Never_Be_Null
(New_Type
)
4611 or else Is_Access_Constant
(Etype
(Old_Type
)) /=
4612 Is_Access_Constant
(Etype
(New_Type
)))
4614 Conformance_Error
("\return type does not match!", New_Id
);
4618 -- If either is a function/operator and the other isn't, error
4620 elsif Old_Type
/= Standard_Void_Type
4621 or else New_Type
/= Standard_Void_Type
4623 Conformance_Error
("\functions can only match functions!", New_Id
);
4627 -- In subtype conformant case, conventions must match (RM 6.3.1(16)).
4628 -- If this is a renaming as body, refine error message to indicate that
4629 -- the conflict is with the original declaration. If the entity is not
4630 -- frozen, the conventions don't have to match, the one of the renamed
4631 -- entity is inherited.
4633 if Ctype
>= Subtype_Conformant
then
4634 if Convention
(Old_Id
) /= Convention
(New_Id
) then
4635 if not Is_Frozen
(New_Id
) then
4638 elsif Present
(Err_Loc
)
4639 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
4640 and then Present
(Corresponding_Spec
(Err_Loc
))
4642 Error_Msg_Name_1
:= Chars
(New_Id
);
4644 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
4645 Conformance_Error
("\prior declaration for% has convention %!");
4648 Conformance_Error
("\calling conventions do not match!");
4653 elsif Is_Formal_Subprogram
(Old_Id
)
4654 or else Is_Formal_Subprogram
(New_Id
)
4656 Conformance_Error
("\formal subprograms not allowed!");
4661 -- Deal with parameters
4663 -- Note: we use the entity information, rather than going directly
4664 -- to the specification in the tree. This is not only simpler, but
4665 -- absolutely necessary for some cases of conformance tests between
4666 -- operators, where the declaration tree simply does not exist.
4668 Old_Formal
:= First_Formal
(Old_Id
);
4669 New_Formal
:= First_Formal
(New_Id
);
4670 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
4671 if Is_Controlling_Formal
(Old_Formal
)
4672 and then Is_Controlling_Formal
(New_Formal
)
4673 and then Skip_Controlling_Formals
4675 -- The controlling formals will have different types when
4676 -- comparing an interface operation with its match, but both
4677 -- or neither must be access parameters.
4679 if Is_Access_Type
(Etype
(Old_Formal
))
4681 Is_Access_Type
(Etype
(New_Formal
))
4683 goto Skip_Controlling_Formal
;
4686 ("\access parameter does not match!", New_Formal
);
4690 -- Ada 2012: Mode conformance also requires that formal parameters
4691 -- be both aliased, or neither.
4693 if Ctype
>= Mode_Conformant
and then Ada_Version
>= Ada_2012
then
4694 if Is_Aliased
(Old_Formal
) /= Is_Aliased
(New_Formal
) then
4696 ("\aliased parameter mismatch!", New_Formal
);
4700 if Ctype
= Fully_Conformant
then
4702 -- Names must match. Error message is more accurate if we do
4703 -- this before checking that the types of the formals match.
4705 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
4706 Conformance_Error
("\name & does not match!", New_Formal
);
4708 -- Set error posted flag on new formal as well to stop
4709 -- junk cascaded messages in some cases.
4711 Set_Error_Posted
(New_Formal
);
4715 -- Null exclusion must match
4717 if Null_Exclusion_Present
(Parent
(Old_Formal
))
4719 Null_Exclusion_Present
(Parent
(New_Formal
))
4721 -- Only give error if both come from source. This should be
4722 -- investigated some time, since it should not be needed ???
4724 if Comes_From_Source
(Old_Formal
)
4726 Comes_From_Source
(New_Formal
)
4729 ("\null exclusion for & does not match", New_Formal
);
4731 -- Mark error posted on the new formal to avoid duplicated
4732 -- complaint about types not matching.
4734 Set_Error_Posted
(New_Formal
);
4739 -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This
4740 -- case occurs whenever a subprogram is being renamed and one of its
4741 -- parameters imposes a null exclusion. For example:
4743 -- type T is null record;
4744 -- type Acc_T is access T;
4745 -- subtype Acc_T_Sub is Acc_T;
4747 -- procedure P (Obj : not null Acc_T_Sub); -- itype
4748 -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype
4751 Old_Formal_Base
:= Etype
(Old_Formal
);
4752 New_Formal_Base
:= Etype
(New_Formal
);
4755 Old_Formal_Base
:= Get_Instance_Of
(Old_Formal_Base
);
4756 New_Formal_Base
:= Get_Instance_Of
(New_Formal_Base
);
4759 Access_Types_Match
:= Ada_Version
>= Ada_2005
4761 -- Ensure that this rule is only applied when New_Id is a
4762 -- renaming of Old_Id.
4764 and then Nkind
(Parent
(Parent
(New_Id
))) =
4765 N_Subprogram_Renaming_Declaration
4766 and then Nkind
(Name
(Parent
(Parent
(New_Id
)))) in N_Has_Entity
4767 and then Present
(Entity
(Name
(Parent
(Parent
(New_Id
)))))
4768 and then Entity
(Name
(Parent
(Parent
(New_Id
)))) = Old_Id
4770 -- Now handle the allowed access-type case
4772 and then Is_Access_Type
(Old_Formal_Base
)
4773 and then Is_Access_Type
(New_Formal_Base
)
4775 -- The type kinds must match. The only exception occurs with
4776 -- multiple generics of the form:
4779 -- type F is private; type A is private;
4780 -- type F_Ptr is access F; type A_Ptr is access A;
4781 -- with proc F_P (X : F_Ptr); with proc A_P (X : A_Ptr);
4782 -- package F_Pack is ... package A_Pack is
4783 -- package F_Inst is
4784 -- new F_Pack (A, A_Ptr, A_P);
4786 -- When checking for conformance between the parameters of A_P
4787 -- and F_P, the type kinds of F_Ptr and A_Ptr will not match
4788 -- because the compiler has transformed A_Ptr into a subtype of
4789 -- F_Ptr. We catch this case in the code below.
4791 and then (Ekind
(Old_Formal_Base
) = Ekind
(New_Formal_Base
)
4793 (Is_Generic_Type
(Old_Formal_Base
)
4794 and then Is_Generic_Type
(New_Formal_Base
)
4795 and then Is_Internal
(New_Formal_Base
)
4796 and then Etype
(Etype
(New_Formal_Base
)) =
4798 and then Directly_Designated_Type
(Old_Formal_Base
) =
4799 Directly_Designated_Type
(New_Formal_Base
)
4800 and then ((Is_Itype
(Old_Formal_Base
)
4801 and then Can_Never_Be_Null
(Old_Formal_Base
))
4803 (Is_Itype
(New_Formal_Base
)
4804 and then Can_Never_Be_Null
(New_Formal_Base
)));
4806 -- Types must always match. In the visible part of an instance,
4807 -- usual overloading rules for dispatching operations apply, and
4808 -- we check base types (not the actual subtypes).
4810 if In_Instance_Visible_Part
4811 and then Is_Dispatching_Operation
(New_Id
)
4813 if not Conforming_Types
4814 (T1
=> Base_Type
(Etype
(Old_Formal
)),
4815 T2
=> Base_Type
(Etype
(New_Formal
)),
4817 Get_Inst
=> Get_Inst
)
4818 and then not Access_Types_Match
4820 Conformance_Error
("\type of & does not match!", New_Formal
);
4824 elsif not Conforming_Types
4825 (T1
=> Old_Formal_Base
,
4826 T2
=> New_Formal_Base
,
4828 Get_Inst
=> Get_Inst
)
4829 and then not Access_Types_Match
4831 -- Don't give error message if old type is Any_Type. This test
4832 -- avoids some cascaded errors, e.g. in case of a bad spec.
4834 if Errmsg
and then Old_Formal_Base
= Any_Type
then
4837 if Ctype
>= Subtype_Conformant
4839 not Predicates_Match
(Old_Formal_Base
, New_Formal_Base
)
4842 ("\predicate of & does not match!", New_Formal
);
4845 ("\type of & does not match!", New_Formal
);
4852 -- For mode conformance, mode must match
4854 if Ctype
>= Mode_Conformant
then
4855 if Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
) then
4856 if not Ekind_In
(New_Id
, E_Function
, E_Procedure
)
4857 or else not Is_Primitive_Wrapper
(New_Id
)
4859 Conformance_Error
("\mode of & does not match!", New_Formal
);
4863 T
: constant Entity_Id
:= Find_Dispatching_Type
(New_Id
);
4865 if Is_Protected_Type
4866 (Corresponding_Concurrent_Type
(T
))
4868 Error_Msg_PT
(T
, New_Id
);
4871 ("\mode of & does not match!", New_Formal
);
4878 -- Part of mode conformance for access types is having the same
4879 -- constant modifier.
4881 elsif Access_Types_Match
4882 and then Is_Access_Constant
(Old_Formal_Base
) /=
4883 Is_Access_Constant
(New_Formal_Base
)
4886 ("\constant modifier does not match!", New_Formal
);
4891 if Ctype
>= Subtype_Conformant
then
4893 -- Ada 2005 (AI-231): In case of anonymous access types check
4894 -- the null-exclusion and access-to-constant attributes must
4895 -- match. For null exclusion, we test the types rather than the
4896 -- formals themselves, since the attribute is only set reliably
4897 -- on the formals in the Ada 95 case, and we exclude the case
4898 -- where Old_Formal is marked as controlling, to avoid errors
4899 -- when matching completing bodies with dispatching declarations
4900 -- (access formals in the bodies aren't marked Can_Never_Be_Null).
4902 if Ada_Version
>= Ada_2005
4903 and then Ekind
(Etype
(Old_Formal
)) = E_Anonymous_Access_Type
4904 and then Ekind
(Etype
(New_Formal
)) = E_Anonymous_Access_Type
4906 ((Can_Never_Be_Null
(Etype
(Old_Formal
)) /=
4907 Can_Never_Be_Null
(Etype
(New_Formal
))
4909 not Is_Controlling_Formal
(Old_Formal
))
4911 Is_Access_Constant
(Etype
(Old_Formal
)) /=
4912 Is_Access_Constant
(Etype
(New_Formal
)))
4914 -- Do not complain if error already posted on New_Formal. This
4915 -- avoids some redundant error messages.
4917 and then not Error_Posted
(New_Formal
)
4919 -- It is allowed to omit the null-exclusion in case of stream
4920 -- attribute subprograms. We recognize stream subprograms
4921 -- through their TSS-generated suffix.
4924 TSS_Name
: constant TSS_Name_Type
:= Get_TSS_Name
(New_Id
);
4927 if TSS_Name
/= TSS_Stream_Read
4928 and then TSS_Name
/= TSS_Stream_Write
4929 and then TSS_Name
/= TSS_Stream_Input
4930 and then TSS_Name
/= TSS_Stream_Output
4932 -- Here we have a definite conformance error. It is worth
4933 -- special casing the error message for the case of a
4934 -- controlling formal (which excludes null).
4936 if Is_Controlling_Formal
(New_Formal
) then
4937 Error_Msg_Node_2
:= Scope
(New_Formal
);
4939 ("\controlling formal& of& excludes null, "
4940 & "declaration must exclude null as well",
4943 -- Normal case (couldn't we give more detail here???)
4947 ("\type of & does not match!", New_Formal
);
4956 -- Full conformance checks
4958 if Ctype
= Fully_Conformant
then
4960 -- We have checked already that names match
4962 if Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
4964 -- Check default expressions for in parameters
4967 NewD
: constant Boolean :=
4968 Present
(Default_Value
(New_Formal
));
4969 OldD
: constant Boolean :=
4970 Present
(Default_Value
(Old_Formal
));
4972 if NewD
or OldD
then
4974 -- The old default value has been analyzed because the
4975 -- current full declaration will have frozen everything
4976 -- before. The new default value has not been analyzed,
4977 -- so analyze it now before we check for conformance.
4980 Push_Scope
(New_Id
);
4981 Preanalyze_Spec_Expression
4982 (Default_Value
(New_Formal
), Etype
(New_Formal
));
4986 if not (NewD
and OldD
)
4987 or else not Fully_Conformant_Expressions
4988 (Default_Value
(Old_Formal
),
4989 Default_Value
(New_Formal
))
4992 ("\default expression for & does not match!",
5001 -- A couple of special checks for Ada 83 mode. These checks are
5002 -- skipped if either entity is an operator in package Standard,
5003 -- or if either old or new instance is not from the source program.
5005 if Ada_Version
= Ada_83
5006 and then Sloc
(Old_Id
) > Standard_Location
5007 and then Sloc
(New_Id
) > Standard_Location
5008 and then Comes_From_Source
(Old_Id
)
5009 and then Comes_From_Source
(New_Id
)
5012 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
5013 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
5016 -- Explicit IN must be present or absent in both cases. This
5017 -- test is required only in the full conformance case.
5019 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
5020 and then Ctype
= Fully_Conformant
5023 ("\(Ada 83) IN must appear in both declarations",
5028 -- Grouping (use of comma in param lists) must be the same
5029 -- This is where we catch a misconformance like:
5032 -- A : Integer; B : Integer
5034 -- which are represented identically in the tree except
5035 -- for the setting of the flags More_Ids and Prev_Ids.
5037 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
5038 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
5041 ("\grouping of & does not match!", New_Formal
);
5047 -- This label is required when skipping controlling formals
5049 <<Skip_Controlling_Formal
>>
5051 Next_Formal
(Old_Formal
);
5052 Next_Formal
(New_Formal
);
5055 if Present
(Old_Formal
) then
5056 Conformance_Error
("\too few parameters!");
5059 elsif Present
(New_Formal
) then
5060 Conformance_Error
("\too many parameters!", New_Formal
);
5063 end Check_Conformance
;
5065 -----------------------
5066 -- Check_Conventions --
5067 -----------------------
5069 procedure Check_Conventions
(Typ
: Entity_Id
) is
5070 Ifaces_List
: Elist_Id
;
5072 procedure Check_Convention
(Op
: Entity_Id
);
5073 -- Verify that the convention of inherited dispatching operation Op is
5074 -- consistent among all subprograms it overrides. In order to minimize
5075 -- the search, Search_From is utilized to designate a specific point in
5076 -- the list rather than iterating over the whole list once more.
5078 ----------------------
5079 -- Check_Convention --
5080 ----------------------
5082 procedure Check_Convention
(Op
: Entity_Id
) is
5083 function Convention_Of
(Id
: Entity_Id
) return Convention_Id
;
5084 -- Given an entity, return its convention. The function treats Ghost
5085 -- as convention Ada because the two have the same dynamic semantics.
5091 function Convention_Of
(Id
: Entity_Id
) return Convention_Id
is
5092 Conv
: constant Convention_Id
:= Convention
(Id
);
5094 if Conv
= Convention_Ghost
then
5095 return Convention_Ada
;
5103 Op_Conv
: constant Convention_Id
:= Convention_Of
(Op
);
5104 Iface_Conv
: Convention_Id
;
5105 Iface_Elmt
: Elmt_Id
;
5106 Iface_Prim_Elmt
: Elmt_Id
;
5107 Iface_Prim
: Entity_Id
;
5109 -- Start of processing for Check_Convention
5112 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
5113 while Present
(Iface_Elmt
) loop
5115 First_Elmt
(Primitive_Operations
(Node
(Iface_Elmt
)));
5116 while Present
(Iface_Prim_Elmt
) loop
5117 Iface_Prim
:= Node
(Iface_Prim_Elmt
);
5118 Iface_Conv
:= Convention_Of
(Iface_Prim
);
5120 if Is_Interface_Conformant
(Typ
, Iface_Prim
, Op
)
5121 and then Iface_Conv
/= Op_Conv
5124 ("inconsistent conventions in primitive operations", Typ
);
5126 Error_Msg_Name_1
:= Chars
(Op
);
5127 Error_Msg_Name_2
:= Get_Convention_Name
(Op_Conv
);
5128 Error_Msg_Sloc
:= Sloc
(Op
);
5130 if Comes_From_Source
(Op
) or else No
(Alias
(Op
)) then
5131 if not Present
(Overridden_Operation
(Op
)) then
5132 Error_Msg_N
("\\primitive % defined #", Typ
);
5135 ("\\overriding operation % with " &
5136 "convention % defined #", Typ
);
5139 else pragma Assert
(Present
(Alias
(Op
)));
5140 Error_Msg_Sloc
:= Sloc
(Alias
(Op
));
5142 ("\\inherited operation % with " &
5143 "convention % defined #", Typ
);
5146 Error_Msg_Name_1
:= Chars
(Op
);
5147 Error_Msg_Name_2
:= Get_Convention_Name
(Iface_Conv
);
5148 Error_Msg_Sloc
:= Sloc
(Iface_Prim
);
5150 ("\\overridden operation % with " &
5151 "convention % defined #", Typ
);
5153 -- Avoid cascading errors
5158 Next_Elmt
(Iface_Prim_Elmt
);
5161 Next_Elmt
(Iface_Elmt
);
5163 end Check_Convention
;
5167 Prim_Op
: Entity_Id
;
5168 Prim_Op_Elmt
: Elmt_Id
;
5170 -- Start of processing for Check_Conventions
5173 if not Has_Interfaces
(Typ
) then
5177 Collect_Interfaces
(Typ
, Ifaces_List
);
5179 -- The algorithm checks every overriding dispatching operation against
5180 -- all the corresponding overridden dispatching operations, detecting
5181 -- differences in conventions.
5183 Prim_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5184 while Present
(Prim_Op_Elmt
) loop
5185 Prim_Op
:= Node
(Prim_Op_Elmt
);
5187 -- A small optimization: skip the predefined dispatching operations
5188 -- since they always have the same convention.
5190 if not Is_Predefined_Dispatching_Operation
(Prim_Op
) then
5191 Check_Convention
(Prim_Op
);
5194 Next_Elmt
(Prim_Op_Elmt
);
5196 end Check_Conventions
;
5198 ------------------------------
5199 -- Check_Delayed_Subprogram --
5200 ------------------------------
5202 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
5205 procedure Possible_Freeze
(T
: Entity_Id
);
5206 -- T is the type of either a formal parameter or of the return type.
5207 -- If T is not yet frozen and needs a delayed freeze, then the
5208 -- subprogram itself must be delayed. If T is the limited view of an
5209 -- incomplete type the subprogram must be frozen as well, because
5210 -- T may depend on local types that have not been frozen yet.
5212 ---------------------
5213 -- Possible_Freeze --
5214 ---------------------
5216 procedure Possible_Freeze
(T
: Entity_Id
) is
5218 if Has_Delayed_Freeze
(T
) and then not Is_Frozen
(T
) then
5219 Set_Has_Delayed_Freeze
(Designator
);
5221 elsif Is_Access_Type
(T
)
5222 and then Has_Delayed_Freeze
(Designated_Type
(T
))
5223 and then not Is_Frozen
(Designated_Type
(T
))
5225 Set_Has_Delayed_Freeze
(Designator
);
5227 elsif Ekind
(T
) = E_Incomplete_Type
5228 and then From_Limited_With
(T
)
5230 Set_Has_Delayed_Freeze
(Designator
);
5232 -- AI05-0151: In Ada 2012, Incomplete types can appear in the profile
5233 -- of a subprogram or entry declaration.
5235 elsif Ekind
(T
) = E_Incomplete_Type
5236 and then Ada_Version
>= Ada_2012
5238 Set_Has_Delayed_Freeze
(Designator
);
5241 end Possible_Freeze
;
5243 -- Start of processing for Check_Delayed_Subprogram
5246 -- All subprograms, including abstract subprograms, may need a freeze
5247 -- node if some formal type or the return type needs one.
5249 Possible_Freeze
(Etype
(Designator
));
5250 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
5252 -- Need delayed freeze if any of the formal types themselves need
5253 -- a delayed freeze and are not yet frozen.
5255 F
:= First_Formal
(Designator
);
5256 while Present
(F
) loop
5257 Possible_Freeze
(Etype
(F
));
5258 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
5262 -- Mark functions that return by reference. Note that it cannot be
5263 -- done for delayed_freeze subprograms because the underlying
5264 -- returned type may not be known yet (for private types)
5266 if not Has_Delayed_Freeze
(Designator
) and then Expander_Active
then
5268 Typ
: constant Entity_Id
:= Etype
(Designator
);
5269 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
5271 if Is_Limited_View
(Typ
) then
5272 Set_Returns_By_Ref
(Designator
);
5273 elsif Present
(Utyp
) and then CW_Or_Has_Controlled_Part
(Utyp
) then
5274 Set_Returns_By_Ref
(Designator
);
5278 end Check_Delayed_Subprogram
;
5280 ------------------------------------
5281 -- Check_Discriminant_Conformance --
5282 ------------------------------------
5284 procedure Check_Discriminant_Conformance
5289 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
5290 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
5291 New_Discr_Id
: Entity_Id
;
5292 New_Discr_Type
: Entity_Id
;
5294 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
5295 -- Post error message for conformance error on given node. Two messages
5296 -- are output. The first points to the previous declaration with a
5297 -- general "no conformance" message. The second is the detailed reason,
5298 -- supplied as Msg. The parameter N provide information for a possible
5299 -- & insertion in the message.
5301 -----------------------
5302 -- Conformance_Error --
5303 -----------------------
5305 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
5307 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
5308 Error_Msg_N
-- CODEFIX
5309 ("not fully conformant with declaration#!", N
);
5310 Error_Msg_NE
(Msg
, N
, N
);
5311 end Conformance_Error
;
5313 -- Start of processing for Check_Discriminant_Conformance
5316 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
5317 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
5319 -- The subtype mark of the discriminant on the full type has not
5320 -- been analyzed so we do it here. For an access discriminant a new
5323 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
5325 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
5328 Analyze
(Discriminant_Type
(New_Discr
));
5329 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
5331 -- Ada 2005: if the discriminant definition carries a null
5332 -- exclusion, create an itype to check properly for consistency
5333 -- with partial declaration.
5335 if Is_Access_Type
(New_Discr_Type
)
5336 and then Null_Exclusion_Present
(New_Discr
)
5339 Create_Null_Excluding_Itype
5340 (T
=> New_Discr_Type
,
5341 Related_Nod
=> New_Discr
,
5342 Scope_Id
=> Current_Scope
);
5346 if not Conforming_Types
5347 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
5349 Conformance_Error
("type of & does not match!", New_Discr_Id
);
5352 -- Treat the new discriminant as an occurrence of the old one,
5353 -- for navigation purposes, and fill in some semantic
5354 -- information, for completeness.
5356 Generate_Reference
(Old_Discr
, New_Discr_Id
, 'r');
5357 Set_Etype
(New_Discr_Id
, Etype
(Old_Discr
));
5358 Set_Scope
(New_Discr_Id
, Scope
(Old_Discr
));
5363 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
5364 Conformance_Error
("name & does not match!", New_Discr_Id
);
5368 -- Default expressions must match
5371 NewD
: constant Boolean :=
5372 Present
(Expression
(New_Discr
));
5373 OldD
: constant Boolean :=
5374 Present
(Expression
(Parent
(Old_Discr
)));
5377 if NewD
or OldD
then
5379 -- The old default value has been analyzed and expanded,
5380 -- because the current full declaration will have frozen
5381 -- everything before. The new default values have not been
5382 -- expanded, so expand now to check conformance.
5385 Preanalyze_Spec_Expression
5386 (Expression
(New_Discr
), New_Discr_Type
);
5389 if not (NewD
and OldD
)
5390 or else not Fully_Conformant_Expressions
5391 (Expression
(Parent
(Old_Discr
)),
5392 Expression
(New_Discr
))
5396 ("default expression for & does not match!",
5403 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
5405 if Ada_Version
= Ada_83
then
5407 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
5410 -- Grouping (use of comma in param lists) must be the same
5411 -- This is where we catch a misconformance like:
5414 -- A : Integer; B : Integer
5416 -- which are represented identically in the tree except
5417 -- for the setting of the flags More_Ids and Prev_Ids.
5419 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
5420 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
5423 ("grouping of & does not match!", New_Discr_Id
);
5429 Next_Discriminant
(Old_Discr
);
5433 if Present
(Old_Discr
) then
5434 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
5437 elsif Present
(New_Discr
) then
5439 ("too many discriminants!", Defining_Identifier
(New_Discr
));
5442 end Check_Discriminant_Conformance
;
5444 ----------------------------
5445 -- Check_Fully_Conformant --
5446 ----------------------------
5448 procedure Check_Fully_Conformant
5449 (New_Id
: Entity_Id
;
5451 Err_Loc
: Node_Id
:= Empty
)
5454 pragma Warnings
(Off
, Result
);
5457 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
5458 end Check_Fully_Conformant
;
5460 ---------------------------
5461 -- Check_Mode_Conformant --
5462 ---------------------------
5464 procedure Check_Mode_Conformant
5465 (New_Id
: Entity_Id
;
5467 Err_Loc
: Node_Id
:= Empty
;
5468 Get_Inst
: Boolean := False)
5471 pragma Warnings
(Off
, Result
);
5474 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
5475 end Check_Mode_Conformant
;
5477 --------------------------------
5478 -- Check_Overriding_Indicator --
5479 --------------------------------
5481 procedure Check_Overriding_Indicator
5483 Overridden_Subp
: Entity_Id
;
5484 Is_Primitive
: Boolean)
5490 -- No overriding indicator for literals
5492 if Ekind
(Subp
) = E_Enumeration_Literal
then
5495 elsif Ekind
(Subp
) = E_Entry
then
5496 Decl
:= Parent
(Subp
);
5498 -- No point in analyzing a malformed operator
5500 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
5501 and then Error_Posted
(Subp
)
5506 Decl
:= Unit_Declaration_Node
(Subp
);
5509 if Nkind_In
(Decl
, N_Subprogram_Body
,
5510 N_Subprogram_Body_Stub
,
5511 N_Subprogram_Declaration
,
5512 N_Abstract_Subprogram_Declaration
,
5513 N_Subprogram_Renaming_Declaration
)
5515 Spec
:= Specification
(Decl
);
5517 elsif Nkind
(Decl
) = N_Entry_Declaration
then
5524 -- The overriding operation is type conformant with the overridden one,
5525 -- but the names of the formals are not required to match. If the names
5526 -- appear permuted in the overriding operation, this is a possible
5527 -- source of confusion that is worth diagnosing. Controlling formals
5528 -- often carry names that reflect the type, and it is not worthwhile
5529 -- requiring that their names match.
5531 if Present
(Overridden_Subp
)
5532 and then Nkind
(Subp
) /= N_Defining_Operator_Symbol
5539 Form1
:= First_Formal
(Subp
);
5540 Form2
:= First_Formal
(Overridden_Subp
);
5542 -- If the overriding operation is a synchronized operation, skip
5543 -- the first parameter of the overridden operation, which is
5544 -- implicit in the new one. If the operation is declared in the
5545 -- body it is not primitive and all formals must match.
5547 if Is_Concurrent_Type
(Scope
(Subp
))
5548 and then Is_Tagged_Type
(Scope
(Subp
))
5549 and then not Has_Completion
(Scope
(Subp
))
5551 Form2
:= Next_Formal
(Form2
);
5554 if Present
(Form1
) then
5555 Form1
:= Next_Formal
(Form1
);
5556 Form2
:= Next_Formal
(Form2
);
5559 while Present
(Form1
) loop
5560 if not Is_Controlling_Formal
(Form1
)
5561 and then Present
(Next_Formal
(Form2
))
5562 and then Chars
(Form1
) = Chars
(Next_Formal
(Form2
))
5564 Error_Msg_Node_2
:= Alias
(Overridden_Subp
);
5565 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
5567 ("& does not match corresponding formal of&#",
5572 Next_Formal
(Form1
);
5573 Next_Formal
(Form2
);
5578 -- If there is an overridden subprogram, then check that there is no
5579 -- "not overriding" indicator, and mark the subprogram as overriding.
5580 -- This is not done if the overridden subprogram is marked as hidden,
5581 -- which can occur for the case of inherited controlled operations
5582 -- (see Derive_Subprogram), unless the inherited subprogram's parent
5583 -- subprogram is not itself hidden. (Note: This condition could probably
5584 -- be simplified, leaving out the testing for the specific controlled
5585 -- cases, but it seems safer and clearer this way, and echoes similar
5586 -- special-case tests of this kind in other places.)
5588 if Present
(Overridden_Subp
)
5589 and then (not Is_Hidden
(Overridden_Subp
)
5591 (Nam_In
(Chars
(Overridden_Subp
), Name_Initialize
,
5594 and then Present
(Alias
(Overridden_Subp
))
5595 and then not Is_Hidden
(Alias
(Overridden_Subp
))))
5597 if Must_Not_Override
(Spec
) then
5598 Error_Msg_Sloc
:= Sloc
(Overridden_Subp
);
5600 if Ekind
(Subp
) = E_Entry
then
5602 ("entry & overrides inherited operation #", Spec
, Subp
);
5605 ("subprogram & overrides inherited operation #", Spec
, Subp
);
5608 -- Special-case to fix a GNAT oddity: Limited_Controlled is declared
5609 -- as an extension of Root_Controlled, and thus has a useless Adjust
5610 -- operation. This operation should not be inherited by other limited
5611 -- controlled types. An explicit Adjust for them is not overriding.
5613 elsif Must_Override
(Spec
)
5614 and then Chars
(Overridden_Subp
) = Name_Adjust
5615 and then Is_Limited_Type
(Etype
(First_Formal
(Subp
)))
5616 and then Present
(Alias
(Overridden_Subp
))
5618 Is_Predefined_File_Name
5619 (Unit_File_Name
(Get_Source_Unit
(Alias
(Overridden_Subp
))))
5621 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
5623 elsif Is_Subprogram
(Subp
) then
5624 if Is_Init_Proc
(Subp
) then
5627 elsif No
(Overridden_Operation
(Subp
)) then
5629 -- For entities generated by Derive_Subprograms the overridden
5630 -- operation is the inherited primitive (which is available
5631 -- through the attribute alias)
5633 if (Is_Dispatching_Operation
(Subp
)
5634 or else Is_Dispatching_Operation
(Overridden_Subp
))
5635 and then not Comes_From_Source
(Overridden_Subp
)
5636 and then Find_Dispatching_Type
(Overridden_Subp
) =
5637 Find_Dispatching_Type
(Subp
)
5638 and then Present
(Alias
(Overridden_Subp
))
5639 and then Comes_From_Source
(Alias
(Overridden_Subp
))
5641 Set_Overridden_Operation
(Subp
, Alias
(Overridden_Subp
));
5644 Set_Overridden_Operation
(Subp
, Overridden_Subp
);
5649 -- If primitive flag is set or this is a protected operation, then
5650 -- the operation is overriding at the point of its declaration, so
5651 -- warn if necessary. Otherwise it may have been declared before the
5652 -- operation it overrides and no check is required.
5655 and then not Must_Override
(Spec
)
5656 and then (Is_Primitive
5657 or else Ekind
(Scope
(Subp
)) = E_Protected_Type
)
5659 Style
.Missing_Overriding
(Decl
, Subp
);
5662 -- If Subp is an operator, it may override a predefined operation, if
5663 -- it is defined in the same scope as the type to which it applies.
5664 -- In that case Overridden_Subp is empty because of our implicit
5665 -- representation for predefined operators. We have to check whether the
5666 -- signature of Subp matches that of a predefined operator. Note that
5667 -- first argument provides the name of the operator, and the second
5668 -- argument the signature that may match that of a standard operation.
5669 -- If the indicator is overriding, then the operator must match a
5670 -- predefined signature, because we know already that there is no
5671 -- explicit overridden operation.
5673 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
then
5674 if Must_Not_Override
(Spec
) then
5676 -- If this is not a primitive or a protected subprogram, then
5677 -- "not overriding" is illegal.
5680 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
5683 ("overriding indicator only allowed "
5684 & "if subprogram is primitive", Subp
);
5686 elsif Can_Override_Operator
(Subp
) then
5688 ("subprogram& overrides predefined operator ", Spec
, Subp
);
5691 elsif Must_Override
(Spec
) then
5692 if No
(Overridden_Operation
(Subp
))
5693 and then not Can_Override_Operator
(Subp
)
5695 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
5698 elsif not Error_Posted
(Subp
)
5699 and then Style_Check
5700 and then Can_Override_Operator
(Subp
)
5702 not Is_Predefined_File_Name
5703 (Unit_File_Name
(Get_Source_Unit
(Subp
)))
5705 -- If style checks are enabled, indicate that the indicator is
5706 -- missing. However, at the point of declaration, the type of
5707 -- which this is a primitive operation may be private, in which
5708 -- case the indicator would be premature.
5710 if Has_Private_Declaration
(Etype
(Subp
))
5711 or else Has_Private_Declaration
(Etype
(First_Formal
(Subp
)))
5715 Style
.Missing_Overriding
(Decl
, Subp
);
5719 elsif Must_Override
(Spec
) then
5720 if Ekind
(Subp
) = E_Entry
then
5721 Error_Msg_NE
("entry & is not overriding", Spec
, Subp
);
5723 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
5726 -- If the operation is marked "not overriding" and it's not primitive
5727 -- then an error is issued, unless this is an operation of a task or
5728 -- protected type (RM05-8.3.1(3/2-4/2)). Error cases where "overriding"
5729 -- has been specified have already been checked above.
5731 elsif Must_Not_Override
(Spec
)
5732 and then not Is_Primitive
5733 and then Ekind
(Subp
) /= E_Entry
5734 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
5737 ("overriding indicator only allowed if subprogram is primitive",
5741 end Check_Overriding_Indicator
;
5747 -- Note: this procedure needs to know far too much about how the expander
5748 -- messes with exceptions. The use of the flag Exception_Junk and the
5749 -- incorporation of knowledge of Exp_Ch11.Expand_Local_Exception_Handlers
5750 -- works, but is not very clean. It would be better if the expansion
5751 -- routines would leave Original_Node working nicely, and we could use
5752 -- Original_Node here to ignore all the peculiar expander messing ???
5754 procedure Check_Returns
5758 Proc
: Entity_Id
:= Empty
)
5762 procedure Check_Statement_Sequence
(L
: List_Id
);
5763 -- Internal recursive procedure to check a list of statements for proper
5764 -- termination by a return statement (or a transfer of control or a
5765 -- compound statement that is itself internally properly terminated).
5767 ------------------------------
5768 -- Check_Statement_Sequence --
5769 ------------------------------
5771 procedure Check_Statement_Sequence
(L
: List_Id
) is
5776 function Assert_False
return Boolean;
5777 -- Returns True if Last_Stm is a pragma Assert (False) that has been
5778 -- rewritten as a null statement when assertions are off. The assert
5779 -- is not active, but it is still enough to kill the warning.
5785 function Assert_False
return Boolean is
5786 Orig
: constant Node_Id
:= Original_Node
(Last_Stm
);
5789 if Nkind
(Orig
) = N_Pragma
5790 and then Pragma_Name
(Orig
) = Name_Assert
5791 and then not Error_Posted
(Orig
)
5794 Arg
: constant Node_Id
:=
5795 First
(Pragma_Argument_Associations
(Orig
));
5796 Exp
: constant Node_Id
:= Expression
(Arg
);
5798 return Nkind
(Exp
) = N_Identifier
5799 and then Chars
(Exp
) = Name_False
;
5809 Raise_Exception_Call
: Boolean;
5810 -- Set True if statement sequence terminated by Raise_Exception call
5811 -- or a Reraise_Occurrence call.
5813 -- Start of processing for Check_Statement_Sequence
5816 Raise_Exception_Call
:= False;
5818 -- Get last real statement
5820 Last_Stm
:= Last
(L
);
5822 -- Deal with digging out exception handler statement sequences that
5823 -- have been transformed by the local raise to goto optimization.
5824 -- See Exp_Ch11.Expand_Local_Exception_Handlers for details. If this
5825 -- optimization has occurred, we are looking at something like:
5828 -- original stmts in block
5832 -- goto L1; | omitted if No_Exception_Propagation
5837 -- goto L3; -- skip handler when exception not raised
5839 -- <<L1>> -- target label for local exception
5853 -- and what we have to do is to dig out the estmts1 and estmts2
5854 -- sequences (which were the original sequences of statements in
5855 -- the exception handlers) and check them.
5857 if Nkind
(Last_Stm
) = N_Label
and then Exception_Junk
(Last_Stm
) then
5862 exit when Nkind
(Stm
) /= N_Block_Statement
;
5863 exit when not Exception_Junk
(Stm
);
5866 exit when Nkind
(Stm
) /= N_Label
;
5867 exit when not Exception_Junk
(Stm
);
5868 Check_Statement_Sequence
5869 (Statements
(Handled_Statement_Sequence
(Next
(Stm
))));
5874 exit when Nkind
(Stm
) /= N_Goto_Statement
;
5875 exit when not Exception_Junk
(Stm
);
5879 -- Don't count pragmas
5881 while Nkind
(Last_Stm
) = N_Pragma
5883 -- Don't count call to SS_Release (can happen after Raise_Exception)
5886 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
5888 Nkind
(Name
(Last_Stm
)) = N_Identifier
5890 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
5892 -- Don't count exception junk
5895 (Nkind_In
(Last_Stm
, N_Goto_Statement
,
5897 N_Object_Declaration
)
5898 and then Exception_Junk
(Last_Stm
))
5899 or else Nkind
(Last_Stm
) in N_Push_xxx_Label
5900 or else Nkind
(Last_Stm
) in N_Pop_xxx_Label
5902 -- Inserted code, such as finalization calls, is irrelevant: we only
5903 -- need to check original source.
5905 or else Is_Rewrite_Insertion
(Last_Stm
)
5910 -- Here we have the "real" last statement
5912 Kind
:= Nkind
(Last_Stm
);
5914 -- Transfer of control, OK. Note that in the No_Return procedure
5915 -- case, we already diagnosed any explicit return statements, so
5916 -- we can treat them as OK in this context.
5918 if Is_Transfer
(Last_Stm
) then
5921 -- Check cases of explicit non-indirect procedure calls
5923 elsif Kind
= N_Procedure_Call_Statement
5924 and then Is_Entity_Name
(Name
(Last_Stm
))
5926 -- Check call to Raise_Exception procedure which is treated
5927 -- specially, as is a call to Reraise_Occurrence.
5929 -- We suppress the warning in these cases since it is likely that
5930 -- the programmer really does not expect to deal with the case
5931 -- of Null_Occurrence, and thus would find a warning about a
5932 -- missing return curious, and raising Program_Error does not
5933 -- seem such a bad behavior if this does occur.
5935 -- Note that in the Ada 2005 case for Raise_Exception, the actual
5936 -- behavior will be to raise Constraint_Error (see AI-329).
5938 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
5940 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
5942 Raise_Exception_Call
:= True;
5944 -- For Raise_Exception call, test first argument, if it is
5945 -- an attribute reference for a 'Identity call, then we know
5946 -- that the call cannot possibly return.
5949 Arg
: constant Node_Id
:=
5950 Original_Node
(First_Actual
(Last_Stm
));
5952 if Nkind
(Arg
) = N_Attribute_Reference
5953 and then Attribute_Name
(Arg
) = Name_Identity
5960 -- If statement, need to look inside if there is an else and check
5961 -- each constituent statement sequence for proper termination.
5963 elsif Kind
= N_If_Statement
5964 and then Present
(Else_Statements
(Last_Stm
))
5966 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
5967 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
5969 if Present
(Elsif_Parts
(Last_Stm
)) then
5971 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
5974 while Present
(Elsif_Part
) loop
5975 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
5983 -- Case statement, check each case for proper termination
5985 elsif Kind
= N_Case_Statement
then
5989 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
5990 while Present
(Case_Alt
) loop
5991 Check_Statement_Sequence
(Statements
(Case_Alt
));
5992 Next_Non_Pragma
(Case_Alt
);
5998 -- Block statement, check its handled sequence of statements
6000 elsif Kind
= N_Block_Statement
then
6006 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
6015 -- Loop statement. If there is an iteration scheme, we can definitely
6016 -- fall out of the loop. Similarly if there is an exit statement, we
6017 -- can fall out. In either case we need a following return.
6019 elsif Kind
= N_Loop_Statement
then
6020 if Present
(Iteration_Scheme
(Last_Stm
))
6021 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
6025 -- A loop with no exit statement or iteration scheme is either
6026 -- an infinite loop, or it has some other exit (raise/return).
6027 -- In either case, no warning is required.
6033 -- Timed entry call, check entry call and delay alternatives
6035 -- Note: in expanded code, the timed entry call has been converted
6036 -- to a set of expanded statements on which the check will work
6037 -- correctly in any case.
6039 elsif Kind
= N_Timed_Entry_Call
then
6041 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
6042 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
6045 -- If statement sequence of entry call alternative is missing,
6046 -- then we can definitely fall through, and we post the error
6047 -- message on the entry call alternative itself.
6049 if No
(Statements
(ECA
)) then
6052 -- If statement sequence of delay alternative is missing, then
6053 -- we can definitely fall through, and we post the error
6054 -- message on the delay alternative itself.
6056 -- Note: if both ECA and DCA are missing the return, then we
6057 -- post only one message, should be enough to fix the bugs.
6058 -- If not we will get a message next time on the DCA when the
6061 elsif No
(Statements
(DCA
)) then
6064 -- Else check both statement sequences
6067 Check_Statement_Sequence
(Statements
(ECA
));
6068 Check_Statement_Sequence
(Statements
(DCA
));
6073 -- Conditional entry call, check entry call and else part
6075 -- Note: in expanded code, the conditional entry call has been
6076 -- converted to a set of expanded statements on which the check
6077 -- will work correctly in any case.
6079 elsif Kind
= N_Conditional_Entry_Call
then
6081 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
6084 -- If statement sequence of entry call alternative is missing,
6085 -- then we can definitely fall through, and we post the error
6086 -- message on the entry call alternative itself.
6088 if No
(Statements
(ECA
)) then
6091 -- Else check statement sequence and else part
6094 Check_Statement_Sequence
(Statements
(ECA
));
6095 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
6101 -- If we fall through, issue appropriate message
6105 -- Kill warning if last statement is a raise exception call,
6106 -- or a pragma Assert (False). Note that with assertions enabled,
6107 -- such a pragma has been converted into a raise exception call
6108 -- already, so the Assert_False is for the assertions off case.
6110 if not Raise_Exception_Call
and then not Assert_False
then
6112 -- In GNATprove mode, it is an error to have a missing return
6114 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6116 -- Issue error message or warning
6119 ("RETURN statement missing following this statement<<!",
6122 ("\Program_Error ]<<!", Last_Stm
);
6125 -- Note: we set Err even though we have not issued a warning
6126 -- because we still have a case of a missing return. This is
6127 -- an extremely marginal case, probably will never be noticed
6128 -- but we might as well get it right.
6132 -- Otherwise we have the case of a procedure marked No_Return
6135 if not Raise_Exception_Call
then
6136 if GNATprove_Mode
then
6138 ("implied return after this statement "
6139 & "would have raised Program_Error", Last_Stm
);
6142 ("implied return after this statement "
6143 & "will raise Program_Error??", Last_Stm
);
6146 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6148 ("\procedure & is marked as No_Return<<!", Last_Stm
, Proc
);
6152 RE
: constant Node_Id
:=
6153 Make_Raise_Program_Error
(Sloc
(Last_Stm
),
6154 Reason
=> PE_Implicit_Return
);
6156 Insert_After
(Last_Stm
, RE
);
6160 end Check_Statement_Sequence
;
6162 -- Start of processing for Check_Returns
6166 Check_Statement_Sequence
(Statements
(HSS
));
6168 if Present
(Exception_Handlers
(HSS
)) then
6169 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
6170 while Present
(Handler
) loop
6171 Check_Statement_Sequence
(Statements
(Handler
));
6172 Next_Non_Pragma
(Handler
);
6177 ----------------------------
6178 -- Check_Subprogram_Order --
6179 ----------------------------
6181 procedure Check_Subprogram_Order
(N
: Node_Id
) is
6183 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
6184 -- This is used to check if S1 > S2 in the sense required by this test,
6185 -- for example nameab < namec, but name2 < name10.
6187 -----------------------------
6188 -- Subprogram_Name_Greater --
6189 -----------------------------
6191 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
6196 -- Deal with special case where names are identical except for a
6197 -- numerical suffix. These are handled specially, taking the numeric
6198 -- ordering from the suffix into account.
6201 while S1
(L1
) in '0' .. '9' loop
6206 while S2
(L2
) in '0' .. '9' loop
6210 -- If non-numeric parts non-equal, do straight compare
6212 if S1
(S1
'First .. L1
) /= S2
(S2
'First .. L2
) then
6215 -- If non-numeric parts equal, compare suffixed numeric parts. Note
6216 -- that a missing suffix is treated as numeric zero in this test.
6220 while L1
< S1
'Last loop
6222 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
6226 while L2
< S2
'Last loop
6228 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
6233 end Subprogram_Name_Greater
;
6235 -- Start of processing for Check_Subprogram_Order
6238 -- Check body in alpha order if this is option
6241 and then Style_Check_Order_Subprograms
6242 and then Nkind
(N
) = N_Subprogram_Body
6243 and then Comes_From_Source
(N
)
6244 and then In_Extended_Main_Source_Unit
(N
)
6248 renames Scope_Stack
.Table
6249 (Scope_Stack
.Last
).Last_Subprogram_Name
;
6251 Body_Id
: constant Entity_Id
:=
6252 Defining_Entity
(Specification
(N
));
6255 Get_Decoded_Name_String
(Chars
(Body_Id
));
6258 if Subprogram_Name_Greater
6259 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
6261 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
6267 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
6270 end Check_Subprogram_Order;
6272 ------------------------------
6273 -- Check_Subtype_Conformant --
6274 ------------------------------
6276 procedure Check_Subtype_Conformant
6277 (New_Id : Entity_Id;
6279 Err_Loc : Node_Id := Empty;
6280 Skip_Controlling_Formals : Boolean := False;
6281 Get_Inst : Boolean := False)
6284 pragma Warnings (Off, Result);
6287 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc,
6288 Skip_Controlling_Formals => Skip_Controlling_Formals,
6289 Get_Inst => Get_Inst);
6290 end Check_Subtype_Conformant;
6292 ---------------------------
6293 -- Check_Type_Conformant --
6294 ---------------------------
6296 procedure Check_Type_Conformant
6297 (New_Id : Entity_Id;
6299 Err_Loc : Node_Id := Empty)
6302 pragma Warnings (Off, Result);
6305 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
6306 end Check_Type_Conformant;
6308 ---------------------------
6309 -- Can_Override_Operator --
6310 ---------------------------
6312 function Can_Override_Operator (Subp : Entity_Id) return Boolean is
6316 if Nkind (Subp) /= N_Defining_Operator_Symbol then
6320 Typ := Base_Type (Etype (First_Formal (Subp)));
6322 -- Check explicitly that the operation is a primitive of the type
6324 return Operator_Matches_Spec (Subp, Subp)
6325 and then not Is_Generic_Type (Typ)
6326 and then Scope (Subp) = Scope (Typ)
6327 and then not Is_Class_Wide_Type (Typ);
6329 end Can_Override_Operator;
6331 ----------------------
6332 -- Conforming_Types --
6333 ----------------------
6335 function Conforming_Types
6338 Ctype : Conformance_Type;
6339 Get_Inst : Boolean := False) return Boolean
6341 Type_1 : Entity_Id := T1;
6342 Type_2 : Entity_Id := T2;
6343 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
6345 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
6346 -- If neither T1 nor T2 are generic actual types, or if they are in
6347 -- different scopes (e.g. parent and child instances), then verify that
6348 -- the base types are equal. Otherwise T1 and T2 must be on the same
6349 -- subtype chain. The whole purpose of this procedure is to prevent
6350 -- spurious ambiguities in an instantiation that may arise if two
6351 -- distinct generic types are instantiated with the same actual.
6353 function Find_Designated_Type (T : Entity_Id) return Entity_Id;
6354 -- An access parameter can designate an incomplete type. If the
6355 -- incomplete type is the limited view of a type from a limited_
6356 -- with_clause, check whether the non-limited view is available. If
6357 -- it is a (non-limited) incomplete type, get the full view.
6359 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean;
6360 -- Returns True if and only if either T1 denotes a limited view of T2
6361 -- or T2 denotes a limited view of T1. This can arise when the limited
6362 -- with view of a type is used in a subprogram declaration and the
6363 -- subprogram body is in the scope of a regular with clause for the
6364 -- same unit. In such a case, the two type entities can be considered
6365 -- identical for purposes of conformance checking.
6367 ----------------------
6368 -- Base_Types_Match --
6369 ----------------------
6371 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
6372 BT1 : constant Entity_Id := Base_Type (T1);
6373 BT2 : constant Entity_Id := Base_Type (T2);
6379 elsif BT1 = BT2 then
6381 -- The following is too permissive. A more precise test should
6382 -- check that the generic actual is an ancestor subtype of the
6385 -- See code in Find_Corresponding_Spec that applies an additional
6386 -- filter to handle accidental amiguities in instances.
6388 return not Is_Generic_Actual_Type (T1)
6389 or else not Is_Generic_Actual_Type (T2)
6390 or else Scope (T1) /= Scope (T2);
6392 -- If T2 is a generic actual type it is declared as the subtype of
6393 -- the actual. If that actual is itself a subtype we need to use its
6394 -- own base type to check for compatibility.
6396 elsif Ekind (BT2) = Ekind (T2) and then BT1 = Base_Type (BT2) then
6399 elsif Ekind (BT1) = Ekind (T1) and then BT2 = Base_Type (BT1) then
6405 end Base_Types_Match;
6407 --------------------------
6408 -- Find_Designated_Type --
6409 --------------------------
6411 function Find_Designated_Type (T : Entity_Id) return Entity_Id is
6415 Desig := Directly_Designated_Type (T);
6417 if Ekind (Desig) = E_Incomplete_Type then
6419 -- If regular incomplete type, get full view if available
6421 if Present (Full_View (Desig)) then
6422 Desig := Full_View (Desig);
6424 -- If limited view of a type, get non-limited view if available,
6425 -- and check again for a regular incomplete type.
6427 elsif Present (Non_Limited_View (Desig)) then
6428 Desig := Get_Full_View (Non_Limited_View (Desig));
6433 end Find_Designated_Type;
6435 -------------------------------
6436 -- Matches_Limited_With_View --
6437 -------------------------------
6439 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean is
6441 -- In some cases a type imported through a limited_with clause, and
6442 -- its nonlimited view are both visible, for example in an anonymous
6443 -- access-to-class-wide type in a formal. Both entities designate the
6446 if From_Limited_With (T1) and then T2 = Available_View (T1) then
6449 elsif From_Limited_With (T2) and then T1 = Available_View (T2) then
6452 elsif From_Limited_With (T1)
6453 and then From_Limited_With (T2)
6454 and then Available_View (T1) = Available_View (T2)
6461 end Matches_Limited_With_View;
6463 -- Start of processing for Conforming_Types
6466 -- The context is an instance association for a formal access-to-
6467 -- subprogram type; the formal parameter types require mapping because
6468 -- they may denote other formal parameters of the generic unit.
6471 Type_1 := Get_Instance_Of (T1);
6472 Type_2 := Get_Instance_Of (T2);
6475 -- If one of the types is a view of the other introduced by a limited
6476 -- with clause, treat these as conforming for all purposes.
6478 if Matches_Limited_With_View (T1, T2) then
6481 elsif Base_Types_Match (Type_1, Type_2) then
6482 return Ctype <= Mode_Conformant
6483 or else Subtypes_Statically_Match (Type_1, Type_2);
6485 elsif Is_Incomplete_Or_Private_Type (Type_1)
6486 and then Present (Full_View (Type_1))
6487 and then Base_Types_Match (Full_View (Type_1), Type_2)
6489 return Ctype <= Mode_Conformant
6490 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
6492 elsif Ekind (Type_2) = E_Incomplete_Type
6493 and then Present (Full_View (Type_2))
6494 and then Base_Types_Match (Type_1, Full_View (Type_2))
6496 return Ctype <= Mode_Conformant
6497 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
6499 elsif Is_Private_Type (Type_2)
6500 and then In_Instance
6501 and then Present (Full_View (Type_2))
6502 and then Base_Types_Match (Type_1, Full_View (Type_2))
6504 return Ctype <= Mode_Conformant
6505 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
6508 -- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be
6509 -- treated recursively because they carry a signature. As far as
6510 -- conformance is concerned, convention plays no role, and either
6511 -- or both could be access to protected subprograms.
6513 Are_Anonymous_Access_To_Subprogram_Types :=
6514 Ekind_In (Type_1, E_Anonymous_Access_Subprogram_Type,
6515 E_Anonymous_Access_Protected_Subprogram_Type)
6517 Ekind_In (Type_2, E_Anonymous_Access_Subprogram_Type,
6518 E_Anonymous_Access_Protected_Subprogram_Type);
6520 -- Test anonymous access type case. For this case, static subtype
6521 -- matching is required for mode conformance (RM 6.3.1(15)). We check
6522 -- the base types because we may have built internal subtype entities
6523 -- to handle null-excluding types (see Process_Formals).
6525 if (Ekind (Base_Type (Type_1)) = E_Anonymous_Access_Type
6527 Ekind (Base_Type (Type_2)) = E_Anonymous_Access_Type)
6529 -- Ada 2005 (AI-254)
6531 or else Are_Anonymous_Access_To_Subprogram_Types
6534 Desig_1 : Entity_Id;
6535 Desig_2 : Entity_Id;
6538 -- In Ada 2005, access constant indicators must match for
6539 -- subtype conformance.
6541 if Ada_Version >= Ada_2005
6542 and then Ctype >= Subtype_Conformant
6544 Is_Access_Constant (Type_1) /= Is_Access_Constant (Type_2)
6549 Desig_1 := Find_Designated_Type (Type_1);
6550 Desig_2 := Find_Designated_Type (Type_2);
6552 -- If the context is an instance association for a formal
6553 -- access-to-subprogram type; formal access parameter designated
6554 -- types require mapping because they may denote other formal
6555 -- parameters of the generic unit.
6558 Desig_1 := Get_Instance_Of (Desig_1);
6559 Desig_2 := Get_Instance_Of (Desig_2);
6562 -- It is possible for a Class_Wide_Type to be introduced for an
6563 -- incomplete type, in which case there is a separate class_ wide
6564 -- type for the full view. The types conform if their Etypes
6565 -- conform, i.e. one may be the full view of the other. This can
6566 -- only happen in the context of an access parameter, other uses
6567 -- of an incomplete Class_Wide_Type are illegal.
6569 if Is_Class_Wide_Type (Desig_1)
6571 Is_Class_Wide_Type (Desig_2)
6575 (Etype (Base_Type (Desig_1)),
6576 Etype (Base_Type (Desig_2)), Ctype);
6578 elsif Are_Anonymous_Access_To_Subprogram_Types then
6579 if Ada_Version < Ada_2005 then
6580 return Ctype = Type_Conformant
6582 Subtypes_Statically_Match (Desig_1, Desig_2);
6584 -- We must check the conformance of the signatures themselves
6588 Conformant : Boolean;
6591 (Desig_1, Desig_2, Ctype, False, Conformant);
6597 return Base_Type (Desig_1) = Base_Type (Desig_2)
6598 and then (Ctype = Type_Conformant
6600 Subtypes_Statically_Match (Desig_1, Desig_2));
6604 -- Otherwise definitely no match
6607 if ((Ekind (Type_1) = E_Anonymous_Access_Type
6608 and then Is_Access_Type (Type_2))
6609 or else (Ekind (Type_2) = E_Anonymous_Access_Type
6610 and then Is_Access_Type (Type_1)))
6613 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
6615 May_Hide_Profile := True;
6620 end Conforming_Types;
6622 --------------------------
6623 -- Create_Extra_Formals --
6624 --------------------------
6626 procedure Create_Extra_Formals (E : Entity_Id) is
6628 First_Extra : Entity_Id := Empty;
6629 Last_Extra : Entity_Id;
6630 Formal_Type : Entity_Id;
6631 P_Formal : Entity_Id := Empty;
6633 function Add_Extra_Formal
6634 (Assoc_Entity : Entity_Id;
6637 Suffix : String) return Entity_Id;
6638 -- Add an extra formal to the current list of formals and extra formals.
6639 -- The extra formal is added to the end of the list of extra formals,
6640 -- and also returned as the result. These formals are always of mode IN.
6641 -- The new formal has the type Typ, is declared in Scope, and its name
6642 -- is given by a concatenation of the name of Assoc_Entity and Suffix.
6643 -- The following suffixes are currently used. They should not be changed
6644 -- without coordinating with CodePeer, which makes use of these to
6645 -- provide better messages.
6647 -- O denotes the Constrained bit.
6648 -- L denotes the accessibility level.
6649 -- BIP_xxx denotes an extra formal for a build-in-place function. See
6650 -- the full list in exp_ch6.BIP_Formal_Kind.
6652 ----------------------
6653 -- Add_Extra_Formal --
6654 ----------------------
6656 function Add_Extra_Formal
6657 (Assoc_Entity : Entity_Id;
6660 Suffix : String) return Entity_Id
6662 EF : constant Entity_Id :=
6663 Make_Defining_Identifier (Sloc (Assoc_Entity),
6664 Chars => New_External_Name (Chars (Assoc_Entity),
6668 -- A little optimization. Never generate an extra formal for the
6669 -- _init operand of an initialization procedure, since it could
6672 if Chars (Formal) = Name_uInit then
6676 Set_Ekind (EF, E_In_Parameter);
6677 Set_Actual_Subtype (EF, Typ);
6678 Set_Etype (EF, Typ);
6679 Set_Scope (EF, Scope);
6680 Set_Mechanism (EF, Default_Mechanism);
6681 Set_Formal_Validity (EF);
6683 if No (First_Extra) then
6685 Set_Extra_Formals (Scope, First_Extra);
6688 if Present (Last_Extra) then
6689 Set_Extra_Formal (Last_Extra, EF);
6695 end Add_Extra_Formal;
6697 -- Start of processing for Create_Extra_Formals
6700 -- We never generate extra formals if expansion is not active because we
6701 -- don't need them unless we are generating code.
6703 if not Expander_Active then
6707 -- No need to generate extra formals in interface thunks whose target
6708 -- primitive has no extra formals.
6710 if Is_Thunk (E) and then No (Extra_Formals (Thunk_Entity (E))) then
6714 -- If this is a derived subprogram then the subtypes of the parent
6715 -- subprogram's formal parameters will be used to determine the need
6716 -- for extra formals.
6718 if Is_Overloadable (E) and then Present (Alias (E)) then
6719 P_Formal := First_Formal (Alias (E));
6722 Last_Extra := Empty;
6723 Formal := First_Formal (E);
6724 while Present (Formal) loop
6725 Last_Extra := Formal;
6726 Next_Formal (Formal);
6729 -- If Extra_formals were already created, don't do it again. This
6730 -- situation may arise for subprogram types created as part of
6731 -- dispatching calls (see Expand_Dispatching_Call)
6733 if Present (Last_Extra) and then Present (Extra_Formal (Last_Extra)) then
6737 -- If the subprogram is a predefined dispatching subprogram then don't
6738 -- generate any extra constrained or accessibility level formals. In
6739 -- general we suppress these for internal subprograms (by not calling
6740 -- Freeze_Subprogram and Create_Extra_Formals at all), but internally
6741 -- generated stream attributes do get passed through because extra
6742 -- build-in-place formals are needed in some cases (limited 'Input
).
6744 if Is_Predefined_Internal_Operation
(E
) then
6745 goto Test_For_Func_Result_Extras
;
6748 Formal
:= First_Formal
(E
);
6749 while Present
(Formal
) loop
6751 -- Create extra formal for supporting the attribute 'Constrained.
6752 -- The case of a private type view without discriminants also
6753 -- requires the extra formal if the underlying type has defaulted
6756 if Ekind
(Formal
) /= E_In_Parameter
then
6757 if Present
(P_Formal
) then
6758 Formal_Type
:= Etype
(P_Formal
);
6760 Formal_Type
:= Etype
(Formal
);
6763 -- Do not produce extra formals for Unchecked_Union parameters.
6764 -- Jump directly to the end of the loop.
6766 if Is_Unchecked_Union
(Base_Type
(Formal_Type
)) then
6767 goto Skip_Extra_Formal_Generation
;
6770 if not Has_Discriminants
(Formal_Type
)
6771 and then Ekind
(Formal_Type
) in Private_Kind
6772 and then Present
(Underlying_Type
(Formal_Type
))
6774 Formal_Type
:= Underlying_Type
(Formal_Type
);
6777 -- Suppress the extra formal if formal's subtype is constrained or
6778 -- indefinite, or we're compiling for Ada 2012 and the underlying
6779 -- type is tagged and limited. In Ada 2012, a limited tagged type
6780 -- can have defaulted discriminants, but 'Constrained is required
6781 -- to return True, so the formal is never needed (see AI05-0214).
6782 -- Note that this ensures consistency of calling sequences for
6783 -- dispatching operations when some types in a class have defaults
6784 -- on discriminants and others do not (and requiring the extra
6785 -- formal would introduce distributed overhead).
6787 -- If the type does not have a completion yet, treat as prior to
6788 -- Ada 2012 for consistency.
6790 if Has_Discriminants
(Formal_Type
)
6791 and then not Is_Constrained
(Formal_Type
)
6792 and then not Is_Indefinite_Subtype
(Formal_Type
)
6793 and then (Ada_Version
< Ada_2012
6794 or else No
(Underlying_Type
(Formal_Type
))
6796 (Is_Limited_Type
(Formal_Type
)
6799 (Underlying_Type
(Formal_Type
)))))
6801 Set_Extra_Constrained
6802 (Formal
, Add_Extra_Formal
(Formal
, Standard_Boolean
, E
, "O"));
6806 -- Create extra formal for supporting accessibility checking. This
6807 -- is done for both anonymous access formals and formals of named
6808 -- access types that are marked as controlling formals. The latter
6809 -- case can occur when Expand_Dispatching_Call creates a subprogram
6810 -- type and substitutes the types of access-to-class-wide actuals
6811 -- for the anonymous access-to-specific-type of controlling formals.
6812 -- Base_Type is applied because in cases where there is a null
6813 -- exclusion the formal may have an access subtype.
6815 -- This is suppressed if we specifically suppress accessibility
6816 -- checks at the package level for either the subprogram, or the
6817 -- package in which it resides. However, we do not suppress it
6818 -- simply if the scope has accessibility checks suppressed, since
6819 -- this could cause trouble when clients are compiled with a
6820 -- different suppression setting. The explicit checks at the
6821 -- package level are safe from this point of view.
6823 if (Ekind
(Base_Type
(Etype
(Formal
))) = E_Anonymous_Access_Type
6824 or else (Is_Controlling_Formal
(Formal
)
6825 and then Is_Access_Type
(Base_Type
(Etype
(Formal
)))))
6827 (Explicit_Suppress
(E
, Accessibility_Check
)
6829 Explicit_Suppress
(Scope
(E
), Accessibility_Check
))
6832 or else Present
(Extra_Accessibility
(P_Formal
)))
6834 Set_Extra_Accessibility
6835 (Formal
, Add_Extra_Formal
(Formal
, Standard_Natural
, E
, "L"));
6838 -- This label is required when skipping extra formal generation for
6839 -- Unchecked_Union parameters.
6841 <<Skip_Extra_Formal_Generation
>>
6843 if Present
(P_Formal
) then
6844 Next_Formal
(P_Formal
);
6847 Next_Formal
(Formal
);
6850 <<Test_For_Func_Result_Extras
>>
6852 -- Ada 2012 (AI05-234): "the accessibility level of the result of a
6853 -- function call is ... determined by the point of call ...".
6855 if Needs_Result_Accessibility_Level
(E
) then
6856 Set_Extra_Accessibility_Of_Result
6857 (E
, Add_Extra_Formal
(E
, Standard_Natural
, E
, "L"));
6860 -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add
6861 -- appropriate extra formals. See type Exp_Ch6.BIP_Formal_Kind.
6863 if Ada_Version
>= Ada_2005
and then Is_Build_In_Place_Function
(E
) then
6865 Result_Subt
: constant Entity_Id
:= Etype
(E
);
6866 Full_Subt
: constant Entity_Id
:= Available_View
(Result_Subt
);
6867 Formal_Typ
: Entity_Id
;
6869 Discard
: Entity_Id
;
6870 pragma Warnings
(Off
, Discard
);
6873 -- In the case of functions with unconstrained result subtypes,
6874 -- add a 4-state formal indicating whether the return object is
6875 -- allocated by the caller (1), or should be allocated by the
6876 -- callee on the secondary stack (2), in the global heap (3), or
6877 -- in a user-defined storage pool (4). For the moment we just use
6878 -- Natural for the type of this formal. Note that this formal
6879 -- isn't usually needed in the case where the result subtype is
6880 -- constrained, but it is needed when the function has a tagged
6881 -- result, because generally such functions can be called in a
6882 -- dispatching context and such calls must be handled like calls
6883 -- to a class-wide function.
6885 if Needs_BIP_Alloc_Form
(E
) then
6888 (E
, Standard_Natural
,
6889 E
, BIP_Formal_Suffix
(BIP_Alloc_Form
));
6891 -- Add BIP_Storage_Pool, in case BIP_Alloc_Form indicates to
6892 -- use a user-defined pool. This formal is not added on
6893 -- .NET/JVM/ZFP as those targets do not support pools.
6895 if VM_Target
= No_VM
6896 and then RTE_Available
(RE_Root_Storage_Pool_Ptr
)
6900 (E
, RTE
(RE_Root_Storage_Pool_Ptr
),
6901 E
, BIP_Formal_Suffix
(BIP_Storage_Pool
));
6905 -- In the case of functions whose result type needs finalization,
6906 -- add an extra formal which represents the finalization master.
6908 if Needs_BIP_Finalization_Master
(E
) then
6911 (E
, RTE
(RE_Finalization_Master_Ptr
),
6912 E
, BIP_Formal_Suffix
(BIP_Finalization_Master
));
6915 -- When the result type contains tasks, add two extra formals: the
6916 -- master of the tasks to be created, and the caller's activation
6919 if Has_Task
(Full_Subt
) then
6922 (E
, RTE
(RE_Master_Id
),
6923 E
, BIP_Formal_Suffix
(BIP_Task_Master
));
6926 (E
, RTE
(RE_Activation_Chain_Access
),
6927 E
, BIP_Formal_Suffix
(BIP_Activation_Chain
));
6930 -- All build-in-place functions get an extra formal that will be
6931 -- passed the address of the return object within the caller.
6934 Create_Itype
(E_Anonymous_Access_Type
, E
, Scope_Id
=> Scope
(E
));
6936 Set_Directly_Designated_Type
(Formal_Typ
, Result_Subt
);
6937 Set_Etype
(Formal_Typ
, Formal_Typ
);
6938 Set_Depends_On_Private
6939 (Formal_Typ
, Has_Private_Component
(Formal_Typ
));
6940 Set_Is_Public
(Formal_Typ
, Is_Public
(Scope
(Formal_Typ
)));
6941 Set_Is_Access_Constant
(Formal_Typ
, False);
6943 -- Ada 2005 (AI-50217): Propagate the attribute that indicates
6944 -- the designated type comes from the limited view (for back-end
6947 Set_From_Limited_With
6948 (Formal_Typ
, From_Limited_With
(Result_Subt
));
6950 Layout_Type
(Formal_Typ
);
6954 (E
, Formal_Typ
, E
, BIP_Formal_Suffix
(BIP_Object_Access
));
6957 end Create_Extra_Formals
;
6959 -----------------------------
6960 -- Enter_Overloaded_Entity --
6961 -----------------------------
6963 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
6964 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
6965 C_E
: Entity_Id
:= Current_Entity
(S
);
6969 Set_Has_Homonym
(E
);
6970 Set_Has_Homonym
(S
);
6973 Set_Is_Immediately_Visible
(S
);
6974 Set_Scope
(S
, Current_Scope
);
6976 -- Chain new entity if front of homonym in current scope, so that
6977 -- homonyms are contiguous.
6979 if Present
(E
) and then E
/= C_E
then
6980 while Homonym
(C_E
) /= E
loop
6981 C_E
:= Homonym
(C_E
);
6984 Set_Homonym
(C_E
, S
);
6988 Set_Current_Entity
(S
);
6993 if Is_Inherited_Operation
(S
) then
6994 Append_Inherited_Subprogram
(S
);
6996 Append_Entity
(S
, Current_Scope
);
6999 Set_Public_Status
(S
);
7001 if Debug_Flag_E
then
7002 Write_Str
("New overloaded entity chain: ");
7003 Write_Name
(Chars
(S
));
7006 while Present
(E
) loop
7007 Write_Str
(" "); Write_Int
(Int
(E
));
7014 -- Generate warning for hiding
7017 and then Comes_From_Source
(S
)
7018 and then In_Extended_Main_Source_Unit
(S
)
7025 -- Warn unless genuine overloading. Do not emit warning on
7026 -- hiding predefined operators in Standard (these are either an
7027 -- (artifact of our implicit declarations, or simple noise) but
7028 -- keep warning on a operator defined on a local subtype, because
7029 -- of the real danger that different operators may be applied in
7030 -- various parts of the program.
7032 -- Note that if E and S have the same scope, there is never any
7033 -- hiding. Either the two conflict, and the program is illegal,
7034 -- or S is overriding an implicit inherited subprogram.
7036 if Scope
(E
) /= Scope
(S
)
7037 and then (not Is_Overloadable
(E
)
7038 or else Subtype_Conformant
(E
, S
))
7039 and then (Is_Immediately_Visible
(E
)
7041 Is_Potentially_Use_Visible
(S
))
7043 if Scope
(E
) /= Standard_Standard
then
7044 Error_Msg_Sloc
:= Sloc
(E
);
7045 Error_Msg_N
("declaration of & hides one#?h?", S
);
7047 elsif Nkind
(S
) = N_Defining_Operator_Symbol
7049 Scope
(Base_Type
(Etype
(First_Formal
(S
)))) /= Scope
(S
)
7052 ("declaration of & hides predefined operator?h?", S
);
7057 end Enter_Overloaded_Entity
;
7059 -----------------------------
7060 -- Check_Untagged_Equality --
7061 -----------------------------
7063 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
) is
7064 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Eq_Op
));
7065 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Eq_Op
);
7069 -- This check applies only if we have a subprogram declaration with an
7070 -- untagged record type.
7072 if Nkind
(Decl
) /= N_Subprogram_Declaration
7073 or else not Is_Record_Type
(Typ
)
7074 or else Is_Tagged_Type
(Typ
)
7079 -- In Ada 2012 case, we will output errors or warnings depending on
7080 -- the setting of debug flag -gnatd.E.
7082 if Ada_Version
>= Ada_2012
then
7083 Error_Msg_Warn
:= Debug_Flag_Dot_EE
;
7085 -- In earlier versions of Ada, nothing to do unless we are warning on
7086 -- Ada 2012 incompatibilities (Warn_On_Ada_2012_Incompatibility set).
7089 if not Warn_On_Ada_2012_Compatibility
then
7094 -- Cases where the type has already been frozen
7096 if Is_Frozen
(Typ
) then
7098 -- If the type is not declared in a package, or if we are in the body
7099 -- of the package or in some other scope, the new operation is not
7100 -- primitive, and therefore legal, though suspicious. Should we
7101 -- generate a warning in this case ???
7103 if Ekind
(Scope
(Typ
)) /= E_Package
7104 or else Scope
(Typ
) /= Current_Scope
7108 -- If the type is a generic actual (sub)type, the operation is not
7109 -- primitive either because the base type is declared elsewhere.
7111 elsif Is_Generic_Actual_Type
(Typ
) then
7114 -- Here we have a definite error of declaration after freezing
7117 if Ada_Version
>= Ada_2012
then
7119 ("equality operator must be declared before type& is "
7120 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)<<", Eq_Op
, Typ
);
7122 -- In Ada 2012 mode with error turned to warning, output one
7123 -- more warning to warn that the equality operation may not
7124 -- compose. This is the consequence of ignoring the error.
7126 if Error_Msg_Warn
then
7127 Error_Msg_N
("\equality operation may not compose??", Eq_Op
);
7132 ("equality operator must be declared before type& is "
7133 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)?y?", Eq_Op
, Typ
);
7136 -- If we are in the package body, we could just move the
7137 -- declaration to the package spec, so add a message saying that.
7139 if In_Package_Body
(Scope
(Typ
)) then
7140 if Ada_Version
>= Ada_2012
then
7142 ("\move declaration to package spec<<", Eq_Op
);
7145 ("\move declaration to package spec (Ada 2012)?y?", Eq_Op
);
7148 -- Otherwise try to find the freezing point
7151 Obj_Decl
:= Next
(Parent
(Typ
));
7152 while Present
(Obj_Decl
) and then Obj_Decl
/= Decl
loop
7153 if Nkind
(Obj_Decl
) = N_Object_Declaration
7154 and then Etype
(Defining_Identifier
(Obj_Decl
)) = Typ
7156 -- Freezing point, output warnings
7158 if Ada_Version
>= Ada_2012
then
7160 ("type& is frozen by declaration??", Obj_Decl
, Typ
);
7162 ("\an equality operator cannot be declared after "
7167 ("type& is frozen by declaration (Ada 2012)?y?",
7170 ("\an equality operator cannot be declared after "
7171 & "this point (Ada 2012)?y?",
7183 -- Here if type is not frozen yet. It is illegal to have a primitive
7184 -- equality declared in the private part if the type is visible.
7186 elsif not In_Same_List
(Parent
(Typ
), Decl
)
7187 and then not Is_Limited_Type
(Typ
)
7189 -- Shouldn't we give an RM reference here???
7191 if Ada_Version
>= Ada_2012
then
7193 ("equality operator appears too late<<", Eq_Op
);
7196 ("equality operator appears too late (Ada 2012)?y?", Eq_Op
);
7199 -- No error detected
7204 end Check_Untagged_Equality
;
7206 -----------------------------
7207 -- Find_Corresponding_Spec --
7208 -----------------------------
7210 function Find_Corresponding_Spec
7212 Post_Error
: Boolean := True) return Entity_Id
7214 Spec
: constant Node_Id
:= Specification
(N
);
7215 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
7219 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean;
7220 -- Even if fully conformant, a body may depend on a generic actual when
7221 -- the spec does not, or vice versa, in which case they were distinct
7222 -- entities in the generic.
7224 -------------------------------
7225 -- Different_Generic_Profile --
7226 -------------------------------
7228 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean is
7231 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean;
7232 -- Check that the types of corresponding formals have the same
7233 -- generic actual if any. We have to account for subtypes of a
7234 -- generic formal, declared between a spec and a body, which may
7235 -- appear distinct in an instance but matched in the generic.
7237 -------------------------
7238 -- Same_Generic_Actual --
7239 -------------------------
7241 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean is
7243 return Is_Generic_Actual_Type
(T1
) = Is_Generic_Actual_Type
(T2
)
7245 (Present
(Parent
(T1
))
7246 and then Comes_From_Source
(Parent
(T1
))
7247 and then Nkind
(Parent
(T1
)) = N_Subtype_Declaration
7248 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T1
)))
7249 and then Entity
(Subtype_Indication
(Parent
(T1
))) = T2
);
7250 end Same_Generic_Actual
;
7252 -- Start of processing for Different_Generic_Profile
7255 if not In_Instance
then
7258 elsif Ekind
(E
) = E_Function
7259 and then not Same_Generic_Actual
(Etype
(E
), Etype
(Designator
))
7264 F1
:= First_Formal
(Designator
);
7265 F2
:= First_Formal
(E
);
7266 while Present
(F1
) loop
7267 if not Same_Generic_Actual
(Etype
(F1
), Etype
(F2
)) then
7276 end Different_Generic_Profile
;
7278 -- Start of processing for Find_Corresponding_Spec
7281 E
:= Current_Entity
(Designator
);
7282 while Present
(E
) loop
7284 -- We are looking for a matching spec. It must have the same scope,
7285 -- and the same name, and either be type conformant, or be the case
7286 -- of a library procedure spec and its body (which belong to one
7287 -- another regardless of whether they are type conformant or not).
7289 if Scope
(E
) = Current_Scope
then
7290 if Current_Scope
= Standard_Standard
7291 or else (Ekind
(E
) = Ekind
(Designator
)
7292 and then Type_Conformant
(E
, Designator
))
7294 -- Within an instantiation, we know that spec and body are
7295 -- subtype conformant, because they were subtype conformant in
7296 -- the generic. We choose the subtype-conformant entity here as
7297 -- well, to resolve spurious ambiguities in the instance that
7298 -- were not present in the generic (i.e. when two different
7299 -- types are given the same actual). If we are looking for a
7300 -- spec to match a body, full conformance is expected.
7303 Set_Convention
(Designator
, Convention
(E
));
7305 -- Skip past subprogram bodies and subprogram renamings that
7306 -- may appear to have a matching spec, but that aren't fully
7307 -- conformant with it. That can occur in cases where an
7308 -- actual type causes unrelated homographs in the instance.
7310 if Nkind_In
(N
, N_Subprogram_Body
,
7311 N_Subprogram_Renaming_Declaration
)
7312 and then Present
(Homonym
(E
))
7313 and then not Fully_Conformant
(Designator
, E
)
7317 elsif not Subtype_Conformant
(Designator
, E
) then
7320 elsif Different_Generic_Profile
(E
) then
7325 -- Ada 2012 (AI05-0165): For internally generated bodies of
7326 -- null procedures locate the internally generated spec. We
7327 -- enforce mode conformance since a tagged type may inherit
7328 -- from interfaces several null primitives which differ only
7329 -- in the mode of the formals.
7331 if not (Comes_From_Source
(E
))
7332 and then Is_Null_Procedure
(E
)
7333 and then not Mode_Conformant
(Designator
, E
)
7337 -- For null procedures coming from source that are completions,
7338 -- analysis of the generated body will establish the link.
7340 elsif Comes_From_Source
(E
)
7341 and then Nkind
(Spec
) = N_Procedure_Specification
7342 and then Null_Present
(Spec
)
7346 elsif not Has_Completion
(E
) then
7347 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
7348 Set_Corresponding_Spec
(N
, E
);
7351 Set_Has_Completion
(E
);
7354 elsif Nkind
(Parent
(N
)) = N_Subunit
then
7356 -- If this is the proper body of a subunit, the completion
7357 -- flag is set when analyzing the stub.
7361 -- If E is an internal function with a controlling result that
7362 -- was created for an operation inherited by a null extension,
7363 -- it may be overridden by a body without a previous spec (one
7364 -- more reason why these should be shunned). In that case we
7365 -- remove the generated body if present, because the current
7366 -- one is the explicit overriding.
7368 elsif Ekind
(E
) = E_Function
7369 and then Ada_Version
>= Ada_2005
7370 and then not Comes_From_Source
(E
)
7371 and then Has_Controlling_Result
(E
)
7372 and then Is_Null_Extension
(Etype
(E
))
7373 and then Comes_From_Source
(Spec
)
7375 Set_Has_Completion
(E
, False);
7378 and then Nkind
(Parent
(E
)) = N_Function_Specification
7381 (Unit_Declaration_Node
7382 (Corresponding_Body
(Unit_Declaration_Node
(E
))));
7386 -- If expansion is disabled, or if the wrapper function has
7387 -- not been generated yet, this a late body overriding an
7388 -- inherited operation, or it is an overriding by some other
7389 -- declaration before the controlling result is frozen. In
7390 -- either case this is a declaration of a new entity.
7396 -- If the body already exists, then this is an error unless
7397 -- the previous declaration is the implicit declaration of a
7398 -- derived subprogram. It is also legal for an instance to
7399 -- contain type conformant overloadable declarations (but the
7400 -- generic declaration may not), per 8.3(26/2).
7402 elsif No
(Alias
(E
))
7403 and then not Is_Intrinsic_Subprogram
(E
)
7404 and then not In_Instance
7407 Error_Msg_Sloc
:= Sloc
(E
);
7409 if Is_Imported
(E
) then
7411 ("body not allowed for imported subprogram & declared#",
7414 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
7418 -- Child units cannot be overloaded, so a conformance mismatch
7419 -- between body and a previous spec is an error.
7421 elsif Is_Child_Unit
(E
)
7423 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
7425 Nkind
(Parent
(Unit_Declaration_Node
(Designator
))) =
7430 ("body of child unit does not match previous declaration", N
);
7438 -- On exit, we know that no previous declaration of subprogram exists
7441 end Find_Corresponding_Spec
;
7443 ----------------------
7444 -- Fully_Conformant --
7445 ----------------------
7447 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
7450 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
7452 end Fully_Conformant
;
7454 ----------------------------------
7455 -- Fully_Conformant_Expressions --
7456 ----------------------------------
7458 function Fully_Conformant_Expressions
7459 (Given_E1
: Node_Id
;
7460 Given_E2
: Node_Id
) return Boolean
7462 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
7463 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
7464 -- We always test conformance on original nodes, since it is possible
7465 -- for analysis and/or expansion to make things look as though they
7466 -- conform when they do not, e.g. by converting 1+2 into 3.
7468 function FCE
(Given_E1
, Given_E2
: Node_Id
) return Boolean
7469 renames Fully_Conformant_Expressions
;
7471 function FCL
(L1
, L2
: List_Id
) return Boolean;
7472 -- Compare elements of two lists for conformance. Elements have to be
7473 -- conformant, and actuals inserted as default parameters do not match
7474 -- explicit actuals with the same value.
7476 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean;
7477 -- Compare an operator node with a function call
7483 function FCL
(L1
, L2
: List_Id
) return Boolean is
7487 if L1
= No_List
then
7493 if L2
= No_List
then
7499 -- Compare two lists, skipping rewrite insertions (we want to compare
7500 -- the original trees, not the expanded versions).
7503 if Is_Rewrite_Insertion
(N1
) then
7505 elsif Is_Rewrite_Insertion
(N2
) then
7511 elsif not FCE
(N1
, N2
) then
7524 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean is
7525 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
7530 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
7535 Act
:= First
(Actuals
);
7537 if Nkind
(Op_Node
) in N_Binary_Op
then
7538 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
7545 return Present
(Act
)
7546 and then FCE
(Right_Opnd
(Op_Node
), Act
)
7547 and then No
(Next
(Act
));
7551 -- Start of processing for Fully_Conformant_Expressions
7554 -- Non-conformant if paren count does not match. Note: if some idiot
7555 -- complains that we don't do this right for more than 3 levels of
7556 -- parentheses, they will be treated with the respect they deserve.
7558 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
7561 -- If same entities are referenced, then they are conformant even if
7562 -- they have different forms (RM 8.3.1(19-20)).
7564 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
7565 if Present
(Entity
(E1
)) then
7566 return Entity
(E1
) = Entity
(E2
)
7567 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
7568 and then Ekind
(Entity
(E1
)) = E_Discriminant
7569 and then Ekind
(Entity
(E2
)) = E_In_Parameter
);
7571 elsif Nkind
(E1
) = N_Expanded_Name
7572 and then Nkind
(E2
) = N_Expanded_Name
7573 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
7574 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
7576 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
7579 -- Identifiers in component associations don't always have
7580 -- entities, but their names must conform.
7582 return Nkind
(E1
) = N_Identifier
7583 and then Nkind
(E2
) = N_Identifier
7584 and then Chars
(E1
) = Chars
(E2
);
7587 elsif Nkind
(E1
) = N_Character_Literal
7588 and then Nkind
(E2
) = N_Expanded_Name
7590 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
7591 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
7593 elsif Nkind
(E2
) = N_Character_Literal
7594 and then Nkind
(E1
) = N_Expanded_Name
7596 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
7597 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
7599 elsif Nkind
(E1
) in N_Op
and then Nkind
(E2
) = N_Function_Call
then
7600 return FCO
(E1
, E2
);
7602 elsif Nkind
(E2
) in N_Op
and then Nkind
(E1
) = N_Function_Call
then
7603 return FCO
(E2
, E1
);
7605 -- Otherwise we must have the same syntactic entity
7607 elsif Nkind
(E1
) /= Nkind
(E2
) then
7610 -- At this point, we specialize by node type
7617 FCL
(Expressions
(E1
), Expressions
(E2
))
7619 FCL
(Component_Associations
(E1
),
7620 Component_Associations
(E2
));
7623 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
7625 Nkind
(Expression
(E2
)) = N_Qualified_Expression
7627 return FCE
(Expression
(E1
), Expression
(E2
));
7629 -- Check that the subtype marks and any constraints
7634 Indic1
: constant Node_Id
:= Expression
(E1
);
7635 Indic2
: constant Node_Id
:= Expression
(E2
);
7640 if Nkind
(Indic1
) /= N_Subtype_Indication
then
7642 Nkind
(Indic2
) /= N_Subtype_Indication
7643 and then Entity
(Indic1
) = Entity
(Indic2
);
7645 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
7647 Nkind
(Indic1
) /= N_Subtype_Indication
7648 and then Entity
(Indic1
) = Entity
(Indic2
);
7651 if Entity
(Subtype_Mark
(Indic1
)) /=
7652 Entity
(Subtype_Mark
(Indic2
))
7657 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
7658 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
7659 while Present
(Elt1
) and then Present
(Elt2
) loop
7660 if not FCE
(Elt1
, Elt2
) then
7673 when N_Attribute_Reference
=>
7675 Attribute_Name
(E1
) = Attribute_Name
(E2
)
7676 and then FCL
(Expressions
(E1
), Expressions
(E2
));
7680 Entity
(E1
) = Entity
(E2
)
7681 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
7682 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
7684 when N_Short_Circuit | N_Membership_Test
=>
7686 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
7688 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
7690 when N_Case_Expression
=>
7696 if not FCE
(Expression
(E1
), Expression
(E2
)) then
7700 Alt1
:= First
(Alternatives
(E1
));
7701 Alt2
:= First
(Alternatives
(E2
));
7703 if Present
(Alt1
) /= Present
(Alt2
) then
7705 elsif No
(Alt1
) then
7709 if not FCE
(Expression
(Alt1
), Expression
(Alt2
))
7710 or else not FCL
(Discrete_Choices
(Alt1
),
7711 Discrete_Choices
(Alt2
))
7722 when N_Character_Literal
=>
7724 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
7726 when N_Component_Association
=>
7728 FCL
(Choices
(E1
), Choices
(E2
))
7730 FCE
(Expression
(E1
), Expression
(E2
));
7732 when N_Explicit_Dereference
=>
7734 FCE
(Prefix
(E1
), Prefix
(E2
));
7736 when N_Extension_Aggregate
=>
7738 FCL
(Expressions
(E1
), Expressions
(E2
))
7739 and then Null_Record_Present
(E1
) =
7740 Null_Record_Present
(E2
)
7741 and then FCL
(Component_Associations
(E1
),
7742 Component_Associations
(E2
));
7744 when N_Function_Call
=>
7746 FCE
(Name
(E1
), Name
(E2
))
7748 FCL
(Parameter_Associations
(E1
),
7749 Parameter_Associations
(E2
));
7751 when N_If_Expression
=>
7753 FCL
(Expressions
(E1
), Expressions
(E2
));
7755 when N_Indexed_Component
=>
7757 FCE
(Prefix
(E1
), Prefix
(E2
))
7759 FCL
(Expressions
(E1
), Expressions
(E2
));
7761 when N_Integer_Literal
=>
7762 return (Intval
(E1
) = Intval
(E2
));
7767 when N_Operator_Symbol
=>
7769 Chars
(E1
) = Chars
(E2
);
7771 when N_Others_Choice
=>
7774 when N_Parameter_Association
=>
7776 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
7777 and then FCE
(Explicit_Actual_Parameter
(E1
),
7778 Explicit_Actual_Parameter
(E2
));
7780 when N_Qualified_Expression
=>
7782 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
7784 FCE
(Expression
(E1
), Expression
(E2
));
7786 when N_Quantified_Expression
=>
7787 if not FCE
(Condition
(E1
), Condition
(E2
)) then
7791 if Present
(Loop_Parameter_Specification
(E1
))
7792 and then Present
(Loop_Parameter_Specification
(E2
))
7795 L1
: constant Node_Id
:=
7796 Loop_Parameter_Specification
(E1
);
7797 L2
: constant Node_Id
:=
7798 Loop_Parameter_Specification
(E2
);
7802 Reverse_Present
(L1
) = Reverse_Present
(L2
)
7804 FCE
(Defining_Identifier
(L1
),
7805 Defining_Identifier
(L2
))
7807 FCE
(Discrete_Subtype_Definition
(L1
),
7808 Discrete_Subtype_Definition
(L2
));
7811 elsif Present
(Iterator_Specification
(E1
))
7812 and then Present
(Iterator_Specification
(E2
))
7815 I1
: constant Node_Id
:= Iterator_Specification
(E1
);
7816 I2
: constant Node_Id
:= Iterator_Specification
(E2
);
7820 FCE
(Defining_Identifier
(I1
),
7821 Defining_Identifier
(I2
))
7823 Of_Present
(I1
) = Of_Present
(I2
)
7825 Reverse_Present
(I1
) = Reverse_Present
(I2
)
7826 and then FCE
(Name
(I1
), Name
(I2
))
7827 and then FCE
(Subtype_Indication
(I1
),
7828 Subtype_Indication
(I2
));
7831 -- The quantified expressions used different specifications to
7832 -- walk their respective ranges.
7840 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
7842 FCE
(High_Bound
(E1
), High_Bound
(E2
));
7844 when N_Real_Literal
=>
7845 return (Realval
(E1
) = Realval
(E2
));
7847 when N_Selected_Component
=>
7849 FCE
(Prefix
(E1
), Prefix
(E2
))
7851 FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
7855 FCE
(Prefix
(E1
), Prefix
(E2
))
7857 FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
7859 when N_String_Literal
=>
7861 S1
: constant String_Id
:= Strval
(E1
);
7862 S2
: constant String_Id
:= Strval
(E2
);
7863 L1
: constant Nat
:= String_Length
(S1
);
7864 L2
: constant Nat
:= String_Length
(S2
);
7871 for J
in 1 .. L1
loop
7872 if Get_String_Char
(S1
, J
) /=
7873 Get_String_Char
(S2
, J
)
7883 when N_Type_Conversion
=>
7885 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
7887 FCE
(Expression
(E1
), Expression
(E2
));
7891 Entity
(E1
) = Entity
(E2
)
7893 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
7895 when N_Unchecked_Type_Conversion
=>
7897 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
7899 FCE
(Expression
(E1
), Expression
(E2
));
7901 -- All other node types cannot appear in this context. Strictly
7902 -- we should raise a fatal internal error. Instead we just ignore
7903 -- the nodes. This means that if anyone makes a mistake in the
7904 -- expander and mucks an expression tree irretrievably, the result
7905 -- will be a failure to detect a (probably very obscure) case
7906 -- of non-conformance, which is better than bombing on some
7907 -- case where two expressions do in fact conform.
7914 end Fully_Conformant_Expressions
;
7916 ----------------------------------------
7917 -- Fully_Conformant_Discrete_Subtypes --
7918 ----------------------------------------
7920 function Fully_Conformant_Discrete_Subtypes
7921 (Given_S1
: Node_Id
;
7922 Given_S2
: Node_Id
) return Boolean
7924 S1
: constant Node_Id
:= Original_Node
(Given_S1
);
7925 S2
: constant Node_Id
:= Original_Node
(Given_S2
);
7927 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean;
7928 -- Special-case for a bound given by a discriminant, which in the body
7929 -- is replaced with the discriminal of the enclosing type.
7931 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean;
7932 -- Check both bounds
7934 -----------------------
7935 -- Conforming_Bounds --
7936 -----------------------
7938 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean is
7940 if Is_Entity_Name
(B1
)
7941 and then Is_Entity_Name
(B2
)
7942 and then Ekind
(Entity
(B1
)) = E_Discriminant
7944 return Chars
(B1
) = Chars
(B2
);
7947 return Fully_Conformant_Expressions
(B1
, B2
);
7949 end Conforming_Bounds
;
7951 -----------------------
7952 -- Conforming_Ranges --
7953 -----------------------
7955 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean is
7958 Conforming_Bounds
(Low_Bound
(R1
), Low_Bound
(R2
))
7960 Conforming_Bounds
(High_Bound
(R1
), High_Bound
(R2
));
7961 end Conforming_Ranges
;
7963 -- Start of processing for Fully_Conformant_Discrete_Subtypes
7966 if Nkind
(S1
) /= Nkind
(S2
) then
7969 elsif Is_Entity_Name
(S1
) then
7970 return Entity
(S1
) = Entity
(S2
);
7972 elsif Nkind
(S1
) = N_Range
then
7973 return Conforming_Ranges
(S1
, S2
);
7975 elsif Nkind
(S1
) = N_Subtype_Indication
then
7977 Entity
(Subtype_Mark
(S1
)) = Entity
(Subtype_Mark
(S2
))
7980 (Range_Expression
(Constraint
(S1
)),
7981 Range_Expression
(Constraint
(S2
)));
7985 end Fully_Conformant_Discrete_Subtypes
;
7987 --------------------
7988 -- Install_Entity --
7989 --------------------
7991 procedure Install_Entity
(E
: Entity_Id
) is
7992 Prev
: constant Entity_Id
:= Current_Entity
(E
);
7994 Set_Is_Immediately_Visible
(E
);
7995 Set_Current_Entity
(E
);
7996 Set_Homonym
(E
, Prev
);
7999 ---------------------
8000 -- Install_Formals --
8001 ---------------------
8003 procedure Install_Formals
(Id
: Entity_Id
) is
8006 F
:= First_Formal
(Id
);
8007 while Present
(F
) loop
8011 end Install_Formals
;
8013 -----------------------------
8014 -- Is_Interface_Conformant --
8015 -----------------------------
8017 function Is_Interface_Conformant
8018 (Tagged_Type
: Entity_Id
;
8019 Iface_Prim
: Entity_Id
;
8020 Prim
: Entity_Id
) return Boolean
8022 -- The operation may in fact be an inherited (implicit) operation
8023 -- rather than the original interface primitive, so retrieve the
8024 -- ultimate ancestor.
8026 Iface
: constant Entity_Id
:=
8027 Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
));
8028 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Prim
);
8030 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
;
8031 -- Return the controlling formal of Prim
8033 ------------------------
8034 -- Controlling_Formal --
8035 ------------------------
8037 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
is
8041 E
:= First_Entity
(Prim
);
8042 while Present
(E
) loop
8043 if Is_Formal
(E
) and then Is_Controlling_Formal
(E
) then
8051 end Controlling_Formal
;
8055 Iface_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Iface_Prim
);
8056 Prim_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Prim
);
8058 -- Start of processing for Is_Interface_Conformant
8061 pragma Assert
(Is_Subprogram
(Iface_Prim
)
8062 and then Is_Subprogram
(Prim
)
8063 and then Is_Dispatching_Operation
(Iface_Prim
)
8064 and then Is_Dispatching_Operation
(Prim
));
8066 pragma Assert
(Is_Interface
(Iface
)
8067 or else (Present
(Alias
(Iface_Prim
))
8070 (Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
)))));
8072 if Prim
= Iface_Prim
8073 or else not Is_Subprogram
(Prim
)
8074 or else Ekind
(Prim
) /= Ekind
(Iface_Prim
)
8075 or else not Is_Dispatching_Operation
(Prim
)
8076 or else Scope
(Prim
) /= Scope
(Tagged_Type
)
8078 or else Base_Type
(Typ
) /= Base_Type
(Tagged_Type
)
8079 or else not Primitive_Names_Match
(Iface_Prim
, Prim
)
8083 -- The mode of the controlling formals must match
8085 elsif Present
(Iface_Ctrl_F
)
8086 and then Present
(Prim_Ctrl_F
)
8087 and then Ekind
(Iface_Ctrl_F
) /= Ekind
(Prim_Ctrl_F
)
8091 -- Case of a procedure, or a function whose result type matches the
8092 -- result type of the interface primitive, or a function that has no
8093 -- controlling result (I or access I).
8095 elsif Ekind
(Iface_Prim
) = E_Procedure
8096 or else Etype
(Prim
) = Etype
(Iface_Prim
)
8097 or else not Has_Controlling_Result
(Prim
)
8099 return Type_Conformant
8100 (Iface_Prim
, Prim
, Skip_Controlling_Formals
=> True);
8102 -- Case of a function returning an interface, or an access to one. Check
8103 -- that the return types correspond.
8105 elsif Implements_Interface
(Typ
, Iface
) then
8106 if (Ekind
(Etype
(Prim
)) = E_Anonymous_Access_Type
)
8108 (Ekind
(Etype
(Iface_Prim
)) = E_Anonymous_Access_Type
)
8113 Type_Conformant
(Prim
, Ultimate_Alias
(Iface_Prim
),
8114 Skip_Controlling_Formals
=> True);
8120 end Is_Interface_Conformant
;
8122 ---------------------------------
8123 -- Is_Non_Overriding_Operation --
8124 ---------------------------------
8126 function Is_Non_Overriding_Operation
8127 (Prev_E
: Entity_Id
;
8128 New_E
: Entity_Id
) return Boolean
8132 G_Typ
: Entity_Id
:= Empty
;
8134 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
8135 -- If F_Type is a derived type associated with a generic actual subtype,
8136 -- then return its Generic_Parent_Type attribute, else return Empty.
8138 function Types_Correspond
8139 (P_Type
: Entity_Id
;
8140 N_Type
: Entity_Id
) return Boolean;
8141 -- Returns true if and only if the types (or designated types in the
8142 -- case of anonymous access types) are the same or N_Type is derived
8143 -- directly or indirectly from P_Type.
8145 -----------------------------
8146 -- Get_Generic_Parent_Type --
8147 -----------------------------
8149 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
8155 if Is_Derived_Type
(F_Typ
)
8156 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
8158 -- The tree must be traversed to determine the parent subtype in
8159 -- the generic unit, which unfortunately isn't always available
8160 -- via semantic attributes. ??? (Note: The use of Original_Node
8161 -- is needed for cases where a full derived type has been
8164 Defn
:= Type_Definition
(Original_Node
(Parent
(F_Typ
)));
8165 if Nkind
(Defn
) = N_Derived_Type_Definition
then
8166 Indic
:= Subtype_Indication
(Defn
);
8168 if Nkind
(Indic
) = N_Subtype_Indication
then
8169 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
8171 G_Typ
:= Entity
(Indic
);
8174 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
8175 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
8177 return Generic_Parent_Type
(Parent
(G_Typ
));
8183 end Get_Generic_Parent_Type
;
8185 ----------------------
8186 -- Types_Correspond --
8187 ----------------------
8189 function Types_Correspond
8190 (P_Type
: Entity_Id
;
8191 N_Type
: Entity_Id
) return Boolean
8193 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
8194 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
8197 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
8198 Prev_Type
:= Designated_Type
(Prev_Type
);
8201 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
8202 New_Type
:= Designated_Type
(New_Type
);
8205 if Prev_Type
= New_Type
then
8208 elsif not Is_Class_Wide_Type
(New_Type
) then
8209 while Etype
(New_Type
) /= New_Type
loop
8210 New_Type
:= Etype
(New_Type
);
8211 if New_Type
= Prev_Type
then
8217 end Types_Correspond
;
8219 -- Start of processing for Is_Non_Overriding_Operation
8222 -- In the case where both operations are implicit derived subprograms
8223 -- then neither overrides the other. This can only occur in certain
8224 -- obscure cases (e.g., derivation from homographs created in a generic
8227 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
8230 elsif Ekind
(Current_Scope
) = E_Package
8231 and then Is_Generic_Instance
(Current_Scope
)
8232 and then In_Private_Part
(Current_Scope
)
8233 and then Comes_From_Source
(New_E
)
8235 -- We examine the formals and result type of the inherited operation,
8236 -- to determine whether their type is derived from (the instance of)
8237 -- a generic type. The first such formal or result type is the one
8240 Formal
:= First_Formal
(Prev_E
);
8241 while Present
(Formal
) loop
8242 F_Typ
:= Base_Type
(Etype
(Formal
));
8244 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
8245 F_Typ
:= Designated_Type
(F_Typ
);
8248 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
8249 exit when Present
(G_Typ
);
8251 Next_Formal
(Formal
);
8254 if No
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
8255 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
8262 -- If the generic type is a private type, then the original operation
8263 -- was not overriding in the generic, because there was no primitive
8264 -- operation to override.
8266 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
8267 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
8268 N_Formal_Private_Type_Definition
8272 -- The generic parent type is the ancestor of a formal derived
8273 -- type declaration. We need to check whether it has a primitive
8274 -- operation that should be overridden by New_E in the generic.
8278 P_Formal
: Entity_Id
;
8279 N_Formal
: Entity_Id
;
8283 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
8286 while Present
(Prim_Elt
) loop
8287 P_Prim
:= Node
(Prim_Elt
);
8289 if Chars
(P_Prim
) = Chars
(New_E
)
8290 and then Ekind
(P_Prim
) = Ekind
(New_E
)
8292 P_Formal
:= First_Formal
(P_Prim
);
8293 N_Formal
:= First_Formal
(New_E
);
8294 while Present
(P_Formal
) and then Present
(N_Formal
) loop
8295 P_Typ
:= Etype
(P_Formal
);
8296 N_Typ
:= Etype
(N_Formal
);
8298 if not Types_Correspond
(P_Typ
, N_Typ
) then
8302 Next_Entity
(P_Formal
);
8303 Next_Entity
(N_Formal
);
8306 -- Found a matching primitive operation belonging to the
8307 -- formal ancestor type, so the new subprogram is
8311 and then No
(N_Formal
)
8312 and then (Ekind
(New_E
) /= E_Function
8315 (Etype
(P_Prim
), Etype
(New_E
)))
8321 Next_Elmt
(Prim_Elt
);
8324 -- If no match found, then the new subprogram does not override
8325 -- in the generic (nor in the instance).
8327 -- If the type in question is not abstract, and the subprogram
8328 -- is, this will be an error if the new operation is in the
8329 -- private part of the instance. Emit a warning now, which will
8330 -- make the subsequent error message easier to understand.
8332 if not Is_Abstract_Type
(F_Typ
)
8333 and then Is_Abstract_Subprogram
(Prev_E
)
8334 and then In_Private_Part
(Current_Scope
)
8336 Error_Msg_Node_2
:= F_Typ
;
8338 ("private operation& in generic unit does not override " &
8339 "any primitive operation of& (RM 12.3 (18))??",
8349 end Is_Non_Overriding_Operation
;
8351 -------------------------------------
8352 -- List_Inherited_Pre_Post_Aspects --
8353 -------------------------------------
8355 procedure List_Inherited_Pre_Post_Aspects
(E
: Entity_Id
) is
8357 if Opt
.List_Inherited_Aspects
8358 and then (Is_Subprogram
(E
) or else Is_Generic_Subprogram
(E
))
8361 Inherited
: constant Subprogram_List
:= Inherited_Subprograms
(E
);
8365 for J
in Inherited
'Range loop
8366 P
:= Pre_Post_Conditions
(Contract
(Inherited
(J
)));
8367 while Present
(P
) loop
8368 Error_Msg_Sloc
:= Sloc
(P
);
8370 if Class_Present
(P
) and then not Split_PPC
(P
) then
8371 if Pragma_Name
(P
) = Name_Precondition
then
8373 ("info: & inherits `Pre''Class` aspect from #?L?",
8377 ("info: & inherits `Post''Class` aspect from #?L?",
8382 P
:= Next_Pragma
(P
);
8387 end List_Inherited_Pre_Post_Aspects
;
8389 ------------------------------
8390 -- Make_Inequality_Operator --
8391 ------------------------------
8393 -- S is the defining identifier of an equality operator. We build a
8394 -- subprogram declaration with the right signature. This operation is
8395 -- intrinsic, because it is always expanded as the negation of the
8396 -- call to the equality function.
8398 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
8399 Loc
: constant Source_Ptr
:= Sloc
(S
);
8402 Op_Name
: Entity_Id
;
8404 FF
: constant Entity_Id
:= First_Formal
(S
);
8405 NF
: constant Entity_Id
:= Next_Formal
(FF
);
8408 -- Check that equality was properly defined, ignore call if not
8415 A
: constant Entity_Id
:=
8416 Make_Defining_Identifier
(Sloc
(FF
),
8417 Chars
=> Chars
(FF
));
8419 B
: constant Entity_Id
:=
8420 Make_Defining_Identifier
(Sloc
(NF
),
8421 Chars
=> Chars
(NF
));
8424 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
8426 Formals
:= New_List
(
8427 Make_Parameter_Specification
(Loc
,
8428 Defining_Identifier
=> A
,
8430 New_Occurrence_Of
(Etype
(First_Formal
(S
)),
8431 Sloc
(Etype
(First_Formal
(S
))))),
8433 Make_Parameter_Specification
(Loc
,
8434 Defining_Identifier
=> B
,
8436 New_Occurrence_Of
(Etype
(Next_Formal
(First_Formal
(S
))),
8437 Sloc
(Etype
(Next_Formal
(First_Formal
(S
)))))));
8440 Make_Subprogram_Declaration
(Loc
,
8442 Make_Function_Specification
(Loc
,
8443 Defining_Unit_Name
=> Op_Name
,
8444 Parameter_Specifications
=> Formals
,
8445 Result_Definition
=>
8446 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
8448 -- Insert inequality right after equality if it is explicit or after
8449 -- the derived type when implicit. These entities are created only
8450 -- for visibility purposes, and eventually replaced in the course
8451 -- of expansion, so they do not need to be attached to the tree and
8452 -- seen by the back-end. Keeping them internal also avoids spurious
8453 -- freezing problems. The declaration is inserted in the tree for
8454 -- analysis, and removed afterwards. If the equality operator comes
8455 -- from an explicit declaration, attach the inequality immediately
8456 -- after. Else the equality is inherited from a derived type
8457 -- declaration, so insert inequality after that declaration.
8459 if No
(Alias
(S
)) then
8460 Insert_After
(Unit_Declaration_Node
(S
), Decl
);
8461 elsif Is_List_Member
(Parent
(S
)) then
8462 Insert_After
(Parent
(S
), Decl
);
8464 Insert_After
(Parent
(Etype
(First_Formal
(S
))), Decl
);
8467 Mark_Rewrite_Insertion
(Decl
);
8468 Set_Is_Intrinsic_Subprogram
(Op_Name
);
8471 Set_Has_Completion
(Op_Name
);
8472 Set_Corresponding_Equality
(Op_Name
, S
);
8473 Set_Is_Abstract_Subprogram
(Op_Name
, Is_Abstract_Subprogram
(S
));
8475 end Make_Inequality_Operator
;
8477 ----------------------
8478 -- May_Need_Actuals --
8479 ----------------------
8481 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
8486 F
:= First_Formal
(Fun
);
8488 while Present
(F
) loop
8489 if No
(Default_Value
(F
)) then
8497 Set_Needs_No_Actuals
(Fun
, B
);
8498 end May_Need_Actuals
;
8500 ---------------------
8501 -- Mode_Conformant --
8502 ---------------------
8504 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
8507 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
8509 end Mode_Conformant
;
8511 ---------------------------
8512 -- New_Overloaded_Entity --
8513 ---------------------------
8515 procedure New_Overloaded_Entity
8517 Derived_Type
: Entity_Id
:= Empty
)
8519 Overridden_Subp
: Entity_Id
:= Empty
;
8520 -- Set if the current scope has an operation that is type-conformant
8521 -- with S, and becomes hidden by S.
8523 Is_Primitive_Subp
: Boolean;
8524 -- Set to True if the new subprogram is primitive
8527 -- Entity that S overrides
8529 Prev_Vis
: Entity_Id
:= Empty
;
8530 -- Predecessor of E in Homonym chain
8532 procedure Check_For_Primitive_Subprogram
8533 (Is_Primitive
: out Boolean;
8534 Is_Overriding
: Boolean := False);
8535 -- If the subprogram being analyzed is a primitive operation of the type
8536 -- of a formal or result, set the Has_Primitive_Operations flag on the
8537 -- type, and set Is_Primitive to True (otherwise set to False). Set the
8538 -- corresponding flag on the entity itself for later use.
8540 procedure Check_Synchronized_Overriding
8541 (Def_Id
: Entity_Id
;
8542 Overridden_Subp
: out Entity_Id
);
8543 -- First determine if Def_Id is an entry or a subprogram either defined
8544 -- in the scope of a task or protected type, or is a primitive of such
8545 -- a type. Check whether Def_Id overrides a subprogram of an interface
8546 -- implemented by the synchronized type, return the overridden entity
8549 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
8550 -- Check that E is declared in the private part of the current package,
8551 -- or in the package body, where it may hide a previous declaration.
8552 -- We can't use In_Private_Part by itself because this flag is also
8553 -- set when freezing entities, so we must examine the place of the
8554 -- declaration in the tree, and recognize wrapper packages as well.
8556 function Is_Overriding_Alias
8558 New_E
: Entity_Id
) return Boolean;
8559 -- Check whether new subprogram and old subprogram are both inherited
8560 -- from subprograms that have distinct dispatch table entries. This can
8561 -- occur with derivations from instances with accidental homonyms. The
8562 -- function is conservative given that the converse is only true within
8563 -- instances that contain accidental overloadings.
8565 ------------------------------------
8566 -- Check_For_Primitive_Subprogram --
8567 ------------------------------------
8569 procedure Check_For_Primitive_Subprogram
8570 (Is_Primitive
: out Boolean;
8571 Is_Overriding
: Boolean := False)
8577 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
8578 -- Returns true if T is declared in the visible part of the current
8579 -- package scope; otherwise returns false. Assumes that T is declared
8582 procedure Check_Private_Overriding
(T
: Entity_Id
);
8583 -- Checks that if a primitive abstract subprogram of a visible
8584 -- abstract type is declared in a private part, then it must override
8585 -- an abstract subprogram declared in the visible part. Also checks
8586 -- that if a primitive function with a controlling result is declared
8587 -- in a private part, then it must override a function declared in
8588 -- the visible part.
8590 ------------------------------
8591 -- Check_Private_Overriding --
8592 ------------------------------
8594 procedure Check_Private_Overriding
(T
: Entity_Id
) is
8596 if Is_Package_Or_Generic_Package
(Current_Scope
)
8597 and then In_Private_Part
(Current_Scope
)
8598 and then Visible_Part_Type
(T
)
8599 and then not In_Instance
8601 if Is_Abstract_Type
(T
)
8602 and then Is_Abstract_Subprogram
(S
)
8603 and then (not Is_Overriding
8604 or else not Is_Abstract_Subprogram
(E
))
8607 ("abstract subprograms must be visible "
8608 & "(RM 3.9.3(10))!", S
);
8610 elsif Ekind
(S
) = E_Function
and then not Is_Overriding
then
8611 if Is_Tagged_Type
(T
) and then T
= Base_Type
(Etype
(S
)) then
8613 ("private function with tagged result must"
8614 & " override visible-part function", S
);
8616 ("\move subprogram to the visible part"
8617 & " (RM 3.9.3(10))", S
);
8619 -- AI05-0073: extend this test to the case of a function
8620 -- with a controlling access result.
8622 elsif Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
8623 and then Is_Tagged_Type
(Designated_Type
(Etype
(S
)))
8625 not Is_Class_Wide_Type
(Designated_Type
(Etype
(S
)))
8626 and then Ada_Version
>= Ada_2012
8629 ("private function with controlling access result "
8630 & "must override visible-part function", S
);
8632 ("\move subprogram to the visible part"
8633 & " (RM 3.9.3(10))", S
);
8637 end Check_Private_Overriding
;
8639 -----------------------
8640 -- Visible_Part_Type --
8641 -----------------------
8643 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
8644 P
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
8648 -- If the entity is a private type, then it must be declared in a
8651 if Ekind
(T
) in Private_Kind
then
8655 -- Otherwise, we traverse the visible part looking for its
8656 -- corresponding declaration. We cannot use the declaration
8657 -- node directly because in the private part the entity of a
8658 -- private type is the one in the full view, which does not
8659 -- indicate that it is the completion of something visible.
8661 N
:= First
(Visible_Declarations
(Specification
(P
)));
8662 while Present
(N
) loop
8663 if Nkind
(N
) = N_Full_Type_Declaration
8664 and then Present
(Defining_Identifier
(N
))
8665 and then T
= Defining_Identifier
(N
)
8669 elsif Nkind_In
(N
, N_Private_Type_Declaration
,
8670 N_Private_Extension_Declaration
)
8671 and then Present
(Defining_Identifier
(N
))
8672 and then T
= Full_View
(Defining_Identifier
(N
))
8681 end Visible_Part_Type
;
8683 -- Start of processing for Check_For_Primitive_Subprogram
8686 Is_Primitive
:= False;
8688 if not Comes_From_Source
(S
) then
8691 -- If subprogram is at library level, it is not primitive operation
8693 elsif Current_Scope
= Standard_Standard
then
8696 elsif (Is_Package_Or_Generic_Package
(Current_Scope
)
8697 and then not In_Package_Body
(Current_Scope
))
8698 or else Is_Overriding
8700 -- For function, check return type
8702 if Ekind
(S
) = E_Function
then
8703 if Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
then
8704 F_Typ
:= Designated_Type
(Etype
(S
));
8709 B_Typ
:= Base_Type
(F_Typ
);
8711 if Scope
(B_Typ
) = Current_Scope
8712 and then not Is_Class_Wide_Type
(B_Typ
)
8713 and then not Is_Generic_Type
(B_Typ
)
8715 Is_Primitive
:= True;
8716 Set_Has_Primitive_Operations
(B_Typ
);
8717 Set_Is_Primitive
(S
);
8718 Check_Private_Overriding
(B_Typ
);
8722 -- For all subprograms, check formals
8724 Formal
:= First_Formal
(S
);
8725 while Present
(Formal
) loop
8726 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
8727 F_Typ
:= Designated_Type
(Etype
(Formal
));
8729 F_Typ
:= Etype
(Formal
);
8732 B_Typ
:= Base_Type
(F_Typ
);
8734 if Ekind
(B_Typ
) = E_Access_Subtype
then
8735 B_Typ
:= Base_Type
(B_Typ
);
8738 if Scope
(B_Typ
) = Current_Scope
8739 and then not Is_Class_Wide_Type
(B_Typ
)
8740 and then not Is_Generic_Type
(B_Typ
)
8742 Is_Primitive
:= True;
8743 Set_Is_Primitive
(S
);
8744 Set_Has_Primitive_Operations
(B_Typ
);
8745 Check_Private_Overriding
(B_Typ
);
8748 Next_Formal
(Formal
);
8751 -- Special case: An equality function can be redefined for a type
8752 -- occurring in a declarative part, and won't otherwise be treated as
8753 -- a primitive because it doesn't occur in a package spec and doesn't
8754 -- override an inherited subprogram. It's important that we mark it
8755 -- primitive so it can be returned by Collect_Primitive_Operations
8756 -- and be used in composing the equality operation of later types
8757 -- that have a component of the type.
8759 elsif Chars
(S
) = Name_Op_Eq
8760 and then Etype
(S
) = Standard_Boolean
8762 B_Typ
:= Base_Type
(Etype
(First_Formal
(S
)));
8764 if Scope
(B_Typ
) = Current_Scope
8766 Base_Type
(Etype
(Next_Formal
(First_Formal
(S
)))) = B_Typ
8767 and then not Is_Limited_Type
(B_Typ
)
8769 Is_Primitive
:= True;
8770 Set_Is_Primitive
(S
);
8771 Set_Has_Primitive_Operations
(B_Typ
);
8772 Check_Private_Overriding
(B_Typ
);
8775 end Check_For_Primitive_Subprogram
;
8777 -----------------------------------
8778 -- Check_Synchronized_Overriding --
8779 -----------------------------------
8781 procedure Check_Synchronized_Overriding
8782 (Def_Id
: Entity_Id
;
8783 Overridden_Subp
: out Entity_Id
)
8785 Ifaces_List
: Elist_Id
;
8789 function Matches_Prefixed_View_Profile
8790 (Prim_Params
: List_Id
;
8791 Iface_Params
: List_Id
) return Boolean;
8792 -- Determine whether a subprogram's parameter profile Prim_Params
8793 -- matches that of a potentially overridden interface subprogram
8794 -- Iface_Params. Also determine if the type of first parameter of
8795 -- Iface_Params is an implemented interface.
8797 -----------------------------------
8798 -- Matches_Prefixed_View_Profile --
8799 -----------------------------------
8801 function Matches_Prefixed_View_Profile
8802 (Prim_Params
: List_Id
;
8803 Iface_Params
: List_Id
) return Boolean
8805 Iface_Id
: Entity_Id
;
8806 Iface_Param
: Node_Id
;
8807 Iface_Typ
: Entity_Id
;
8808 Prim_Id
: Entity_Id
;
8809 Prim_Param
: Node_Id
;
8810 Prim_Typ
: Entity_Id
;
8812 function Is_Implemented
8813 (Ifaces_List
: Elist_Id
;
8814 Iface
: Entity_Id
) return Boolean;
8815 -- Determine if Iface is implemented by the current task or
8818 --------------------
8819 -- Is_Implemented --
8820 --------------------
8822 function Is_Implemented
8823 (Ifaces_List
: Elist_Id
;
8824 Iface
: Entity_Id
) return Boolean
8826 Iface_Elmt
: Elmt_Id
;
8829 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
8830 while Present
(Iface_Elmt
) loop
8831 if Node
(Iface_Elmt
) = Iface
then
8835 Next_Elmt
(Iface_Elmt
);
8841 -- Start of processing for Matches_Prefixed_View_Profile
8844 Iface_Param
:= First
(Iface_Params
);
8845 Iface_Typ
:= Etype
(Defining_Identifier
(Iface_Param
));
8847 if Is_Access_Type
(Iface_Typ
) then
8848 Iface_Typ
:= Designated_Type
(Iface_Typ
);
8851 Prim_Param
:= First
(Prim_Params
);
8853 -- The first parameter of the potentially overridden subprogram
8854 -- must be an interface implemented by Prim.
8856 if not Is_Interface
(Iface_Typ
)
8857 or else not Is_Implemented
(Ifaces_List
, Iface_Typ
)
8862 -- The checks on the object parameters are done, move onto the
8863 -- rest of the parameters.
8865 if not In_Scope
then
8866 Prim_Param
:= Next
(Prim_Param
);
8869 Iface_Param
:= Next
(Iface_Param
);
8870 while Present
(Iface_Param
) and then Present
(Prim_Param
) loop
8871 Iface_Id
:= Defining_Identifier
(Iface_Param
);
8872 Iface_Typ
:= Find_Parameter_Type
(Iface_Param
);
8874 Prim_Id
:= Defining_Identifier
(Prim_Param
);
8875 Prim_Typ
:= Find_Parameter_Type
(Prim_Param
);
8877 if Ekind
(Iface_Typ
) = E_Anonymous_Access_Type
8878 and then Ekind
(Prim_Typ
) = E_Anonymous_Access_Type
8879 and then Is_Concurrent_Type
(Designated_Type
(Prim_Typ
))
8881 Iface_Typ
:= Designated_Type
(Iface_Typ
);
8882 Prim_Typ
:= Designated_Type
(Prim_Typ
);
8885 -- Case of multiple interface types inside a parameter profile
8887 -- (Obj_Param : in out Iface; ...; Param : Iface)
8889 -- If the interface type is implemented, then the matching type
8890 -- in the primitive should be the implementing record type.
8892 if Ekind
(Iface_Typ
) = E_Record_Type
8893 and then Is_Interface
(Iface_Typ
)
8894 and then Is_Implemented
(Ifaces_List
, Iface_Typ
)
8896 if Prim_Typ
/= Typ
then
8900 -- The two parameters must be both mode and subtype conformant
8902 elsif Ekind
(Iface_Id
) /= Ekind
(Prim_Id
)
8904 Conforming_Types
(Iface_Typ
, Prim_Typ
, Subtype_Conformant
)
8913 -- One of the two lists contains more parameters than the other
8915 if Present
(Iface_Param
) or else Present
(Prim_Param
) then
8920 end Matches_Prefixed_View_Profile
;
8922 -- Start of processing for Check_Synchronized_Overriding
8925 Overridden_Subp
:= Empty
;
8927 -- Def_Id must be an entry or a subprogram. We should skip predefined
8928 -- primitives internally generated by the frontend; however at this
8929 -- stage predefined primitives are still not fully decorated. As a
8930 -- minor optimization we skip here internally generated subprograms.
8932 if (Ekind
(Def_Id
) /= E_Entry
8933 and then Ekind
(Def_Id
) /= E_Function
8934 and then Ekind
(Def_Id
) /= E_Procedure
)
8935 or else not Comes_From_Source
(Def_Id
)
8940 -- Search for the concurrent declaration since it contains the list
8941 -- of all implemented interfaces. In this case, the subprogram is
8942 -- declared within the scope of a protected or a task type.
8944 if Present
(Scope
(Def_Id
))
8945 and then Is_Concurrent_Type
(Scope
(Def_Id
))
8946 and then not Is_Generic_Actual_Type
(Scope
(Def_Id
))
8948 Typ
:= Scope
(Def_Id
);
8951 -- The enclosing scope is not a synchronized type and the subprogram
8954 elsif No
(First_Formal
(Def_Id
)) then
8957 -- The subprogram has formals and hence it may be a primitive of a
8961 Typ
:= Etype
(First_Formal
(Def_Id
));
8963 if Is_Access_Type
(Typ
) then
8964 Typ
:= Directly_Designated_Type
(Typ
);
8967 if Is_Concurrent_Type
(Typ
)
8968 and then not Is_Generic_Actual_Type
(Typ
)
8972 -- This case occurs when the concurrent type is declared within
8973 -- a generic unit. As a result the corresponding record has been
8974 -- built and used as the type of the first formal, we just have
8975 -- to retrieve the corresponding concurrent type.
8977 elsif Is_Concurrent_Record_Type
(Typ
)
8978 and then not Is_Class_Wide_Type
(Typ
)
8979 and then Present
(Corresponding_Concurrent_Type
(Typ
))
8981 Typ
:= Corresponding_Concurrent_Type
(Typ
);
8989 -- There is no overriding to check if is an inherited operation in a
8990 -- type derivation on for a generic actual.
8992 Collect_Interfaces
(Typ
, Ifaces_List
);
8994 if Is_Empty_Elmt_List
(Ifaces_List
) then
8998 -- Determine whether entry or subprogram Def_Id overrides a primitive
8999 -- operation that belongs to one of the interfaces in Ifaces_List.
9002 Candidate
: Entity_Id
:= Empty
;
9003 Hom
: Entity_Id
:= Empty
;
9004 Iface_Typ
: Entity_Id
;
9005 Subp
: Entity_Id
:= Empty
;
9008 -- Traverse the homonym chain, looking for a potentially
9009 -- overridden subprogram that belongs to an implemented
9012 Hom
:= Current_Entity_In_Scope
(Def_Id
);
9013 while Present
(Hom
) loop
9017 or else not Is_Overloadable
(Subp
)
9018 or else not Is_Primitive
(Subp
)
9019 or else not Is_Dispatching_Operation
(Subp
)
9020 or else not Present
(Find_Dispatching_Type
(Subp
))
9021 or else not Is_Interface
(Find_Dispatching_Type
(Subp
))
9025 -- Entries and procedures can override abstract or null
9026 -- interface procedures.
9028 elsif (Ekind
(Def_Id
) = E_Procedure
9029 or else Ekind
(Def_Id
) = E_Entry
)
9030 and then Ekind
(Subp
) = E_Procedure
9031 and then Matches_Prefixed_View_Profile
9032 (Parameter_Specifications
(Parent
(Def_Id
)),
9033 Parameter_Specifications
(Parent
(Subp
)))
9037 -- For an overridden subprogram Subp, check whether the mode
9038 -- of its first parameter is correct depending on the kind
9039 -- of synchronized type.
9042 Formal
: constant Node_Id
:= First_Formal
(Candidate
);
9045 -- In order for an entry or a protected procedure to
9046 -- override, the first parameter of the overridden
9047 -- routine must be of mode "out", "in out" or
9048 -- access-to-variable.
9050 if Ekind_In
(Candidate
, E_Entry
, E_Procedure
)
9051 and then Is_Protected_Type
(Typ
)
9052 and then Ekind
(Formal
) /= E_In_Out_Parameter
9053 and then Ekind
(Formal
) /= E_Out_Parameter
9054 and then Nkind
(Parameter_Type
(Parent
(Formal
))) /=
9059 -- All other cases are OK since a task entry or routine
9060 -- does not have a restriction on the mode of the first
9061 -- parameter of the overridden interface routine.
9064 Overridden_Subp
:= Candidate
;
9069 -- Functions can override abstract interface functions
9071 elsif Ekind
(Def_Id
) = E_Function
9072 and then Ekind
(Subp
) = E_Function
9073 and then Matches_Prefixed_View_Profile
9074 (Parameter_Specifications
(Parent
(Def_Id
)),
9075 Parameter_Specifications
(Parent
(Subp
)))
9076 and then Etype
(Result_Definition
(Parent
(Def_Id
))) =
9077 Etype
(Result_Definition
(Parent
(Subp
)))
9079 Overridden_Subp
:= Subp
;
9083 Hom
:= Homonym
(Hom
);
9086 -- After examining all candidates for overriding, we are left with
9087 -- the best match which is a mode incompatible interface routine.
9088 -- Do not emit an error if the Expander is active since this error
9089 -- will be detected later on after all concurrent types are
9090 -- expanded and all wrappers are built. This check is meant for
9091 -- spec-only compilations.
9093 if Present
(Candidate
) and then not Expander_Active
then
9095 Find_Parameter_Type
(Parent
(First_Formal
(Candidate
)));
9097 -- Def_Id is primitive of a protected type, declared inside the
9098 -- type, and the candidate is primitive of a limited or
9099 -- synchronized interface.
9102 and then Is_Protected_Type
(Typ
)
9104 (Is_Limited_Interface
(Iface_Typ
)
9105 or else Is_Protected_Interface
(Iface_Typ
)
9106 or else Is_Synchronized_Interface
(Iface_Typ
)
9107 or else Is_Task_Interface
(Iface_Typ
))
9109 Error_Msg_PT
(Parent
(Typ
), Candidate
);
9113 Overridden_Subp
:= Candidate
;
9116 end Check_Synchronized_Overriding
;
9118 ----------------------------
9119 -- Is_Private_Declaration --
9120 ----------------------------
9122 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
9123 Priv_Decls
: List_Id
;
9124 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
9127 if Is_Package_Or_Generic_Package
(Current_Scope
)
9128 and then In_Private_Part
(Current_Scope
)
9131 Private_Declarations
(Package_Specification
(Current_Scope
));
9133 return In_Package_Body
(Current_Scope
)
9135 (Is_List_Member
(Decl
)
9136 and then List_Containing
(Decl
) = Priv_Decls
)
9137 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
9140 (Defining_Entity
(Parent
(Decl
)))
9141 and then List_Containing
(Parent
(Parent
(Decl
))) =
9146 end Is_Private_Declaration
;
9148 --------------------------
9149 -- Is_Overriding_Alias --
9150 --------------------------
9152 function Is_Overriding_Alias
9154 New_E
: Entity_Id
) return Boolean
9156 AO
: constant Entity_Id
:= Alias
(Old_E
);
9157 AN
: constant Entity_Id
:= Alias
(New_E
);
9159 return Scope
(AO
) /= Scope
(AN
)
9160 or else No
(DTC_Entity
(AO
))
9161 or else No
(DTC_Entity
(AN
))
9162 or else DT_Position
(AO
) = DT_Position
(AN
);
9163 end Is_Overriding_Alias
;
9165 -- Start of processing for New_Overloaded_Entity
9168 -- We need to look for an entity that S may override. This must be a
9169 -- homonym in the current scope, so we look for the first homonym of
9170 -- S in the current scope as the starting point for the search.
9172 E
:= Current_Entity_In_Scope
(S
);
9174 -- Ada 2005 (AI-251): Derivation of abstract interface primitives.
9175 -- They are directly added to the list of primitive operations of
9176 -- Derived_Type, unless this is a rederivation in the private part
9177 -- of an operation that was already derived in the visible part of
9178 -- the current package.
9180 if Ada_Version
>= Ada_2005
9181 and then Present
(Derived_Type
)
9182 and then Present
(Alias
(S
))
9183 and then Is_Dispatching_Operation
(Alias
(S
))
9184 and then Present
(Find_Dispatching_Type
(Alias
(S
)))
9185 and then Is_Interface
(Find_Dispatching_Type
(Alias
(S
)))
9187 -- For private types, when the full-view is processed we propagate to
9188 -- the full view the non-overridden entities whose attribute "alias"
9189 -- references an interface primitive. These entities were added by
9190 -- Derive_Subprograms to ensure that interface primitives are
9193 -- Inside_Freeze_Actions is non zero when S corresponds with an
9194 -- internal entity that links an interface primitive with its
9195 -- covering primitive through attribute Interface_Alias (see
9196 -- Add_Internal_Interface_Entities).
9198 if Inside_Freezing_Actions
= 0
9199 and then Is_Package_Or_Generic_Package
(Current_Scope
)
9200 and then In_Private_Part
(Current_Scope
)
9201 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
9202 and then Nkind
(Parent
(S
)) = N_Full_Type_Declaration
9203 and then Full_View
(Defining_Identifier
(Parent
(E
)))
9204 = Defining_Identifier
(Parent
(S
))
9205 and then Alias
(E
) = Alias
(S
)
9207 Check_Operation_From_Private_View
(S
, E
);
9208 Set_Is_Dispatching_Operation
(S
);
9213 Enter_Overloaded_Entity
(S
);
9214 Check_Dispatching_Operation
(S
, Empty
);
9215 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
9221 -- If there is no homonym then this is definitely not overriding
9224 Enter_Overloaded_Entity
(S
);
9225 Check_Dispatching_Operation
(S
, Empty
);
9226 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
9228 -- If subprogram has an explicit declaration, check whether it has an
9229 -- overriding indicator.
9231 if Comes_From_Source
(S
) then
9232 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
9234 -- (Ada 2012: AI05-0125-1): If S is a dispatching operation then
9235 -- it may have overridden some hidden inherited primitive. Update
9236 -- Overridden_Subp to avoid spurious errors when checking the
9237 -- overriding indicator.
9239 if Ada_Version
>= Ada_2012
9240 and then No
(Overridden_Subp
)
9241 and then Is_Dispatching_Operation
(S
)
9242 and then Present
(Overridden_Operation
(S
))
9244 Overridden_Subp
:= Overridden_Operation
(S
);
9247 Check_Overriding_Indicator
9248 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
9251 -- If there is a homonym that is not overloadable, then we have an
9252 -- error, except for the special cases checked explicitly below.
9254 elsif not Is_Overloadable
(E
) then
9256 -- Check for spurious conflict produced by a subprogram that has the
9257 -- same name as that of the enclosing generic package. The conflict
9258 -- occurs within an instance, between the subprogram and the renaming
9259 -- declaration for the package. After the subprogram, the package
9260 -- renaming declaration becomes hidden.
9262 if Ekind
(E
) = E_Package
9263 and then Present
(Renamed_Object
(E
))
9264 and then Renamed_Object
(E
) = Current_Scope
9265 and then Nkind
(Parent
(Renamed_Object
(E
))) =
9266 N_Package_Specification
9267 and then Present
(Generic_Parent
(Parent
(Renamed_Object
(E
))))
9270 Set_Is_Immediately_Visible
(E
, False);
9271 Enter_Overloaded_Entity
(S
);
9272 Set_Homonym
(S
, Homonym
(E
));
9273 Check_Dispatching_Operation
(S
, Empty
);
9274 Check_Overriding_Indicator
(S
, Empty
, Is_Primitive
=> False);
9276 -- If the subprogram is implicit it is hidden by the previous
9277 -- declaration. However if it is dispatching, it must appear in the
9278 -- dispatch table anyway, because it can be dispatched to even if it
9279 -- cannot be called directly.
9281 elsif Present
(Alias
(S
)) and then not Comes_From_Source
(S
) then
9282 Set_Scope
(S
, Current_Scope
);
9284 if Is_Dispatching_Operation
(Alias
(S
)) then
9285 Check_Dispatching_Operation
(S
, Empty
);
9291 Error_Msg_Sloc
:= Sloc
(E
);
9293 -- Generate message, with useful additional warning if in generic
9295 if Is_Generic_Unit
(E
) then
9296 Error_Msg_N
("previous generic unit cannot be overloaded", S
);
9297 Error_Msg_N
("\& conflicts with declaration#", S
);
9299 Error_Msg_N
("& conflicts with declaration#", S
);
9305 -- E exists and is overloadable
9308 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
9310 -- Loop through E and its homonyms to determine if any of them is
9311 -- the candidate for overriding by S.
9313 while Present
(E
) loop
9315 -- Definitely not interesting if not in the current scope
9317 if Scope
(E
) /= Current_Scope
then
9320 -- A function can overload the name of an abstract state. The
9321 -- state can be viewed as a function with a profile that cannot
9322 -- be matched by anything.
9324 elsif Ekind
(S
) = E_Function
9325 and then Ekind
(E
) = E_Abstract_State
9327 Enter_Overloaded_Entity
(S
);
9330 -- Ada 2012 (AI05-0165): For internally generated bodies of null
9331 -- procedures locate the internally generated spec. We enforce
9332 -- mode conformance since a tagged type may inherit from
9333 -- interfaces several null primitives which differ only in
9334 -- the mode of the formals.
9336 elsif not Comes_From_Source
(S
)
9337 and then Is_Null_Procedure
(S
)
9338 and then not Mode_Conformant
(E
, S
)
9342 -- Check if we have type conformance
9344 elsif Type_Conformant
(E
, S
) then
9346 -- If the old and new entities have the same profile and one
9347 -- is not the body of the other, then this is an error, unless
9348 -- one of them is implicitly declared.
9350 -- There are some cases when both can be implicit, for example
9351 -- when both a literal and a function that overrides it are
9352 -- inherited in a derivation, or when an inherited operation
9353 -- of a tagged full type overrides the inherited operation of
9354 -- a private extension. Ada 83 had a special rule for the
9355 -- literal case. In Ada 95, the later implicit operation hides
9356 -- the former, and the literal is always the former. In the
9357 -- odd case where both are derived operations declared at the
9358 -- same point, both operations should be declared, and in that
9359 -- case we bypass the following test and proceed to the next
9360 -- part. This can only occur for certain obscure cases in
9361 -- instances, when an operation on a type derived from a formal
9362 -- private type does not override a homograph inherited from
9363 -- the actual. In subsequent derivations of such a type, the
9364 -- DT positions of these operations remain distinct, if they
9367 if Present
(Alias
(S
))
9368 and then (No
(Alias
(E
))
9369 or else Comes_From_Source
(E
)
9370 or else Is_Abstract_Subprogram
(S
)
9372 (Is_Dispatching_Operation
(E
)
9373 and then Is_Overriding_Alias
(E
, S
)))
9374 and then Ekind
(E
) /= E_Enumeration_Literal
9376 -- When an derived operation is overloaded it may be due to
9377 -- the fact that the full view of a private extension
9378 -- re-inherits. It has to be dealt with.
9380 if Is_Package_Or_Generic_Package
(Current_Scope
)
9381 and then In_Private_Part
(Current_Scope
)
9383 Check_Operation_From_Private_View
(S
, E
);
9386 -- In any case the implicit operation remains hidden by the
9387 -- existing declaration, which is overriding. Indicate that
9388 -- E overrides the operation from which S is inherited.
9390 if Present
(Alias
(S
)) then
9391 Set_Overridden_Operation
(E
, Alias
(S
));
9393 Set_Overridden_Operation
(E
, S
);
9396 if Comes_From_Source
(E
) then
9397 Check_Overriding_Indicator
(E
, S
, Is_Primitive
=> False);
9402 -- Within an instance, the renaming declarations for actual
9403 -- subprograms may become ambiguous, but they do not hide each
9406 elsif Ekind
(E
) /= E_Entry
9407 and then not Comes_From_Source
(E
)
9408 and then not Is_Generic_Instance
(E
)
9409 and then (Present
(Alias
(E
))
9410 or else Is_Intrinsic_Subprogram
(E
))
9411 and then (not In_Instance
9412 or else No
(Parent
(E
))
9413 or else Nkind
(Unit_Declaration_Node
(E
)) /=
9414 N_Subprogram_Renaming_Declaration
)
9416 -- A subprogram child unit is not allowed to override an
9417 -- inherited subprogram (10.1.1(20)).
9419 if Is_Child_Unit
(S
) then
9421 ("child unit overrides inherited subprogram in parent",
9426 if Is_Non_Overriding_Operation
(E
, S
) then
9427 Enter_Overloaded_Entity
(S
);
9429 if No
(Derived_Type
)
9430 or else Is_Tagged_Type
(Derived_Type
)
9432 Check_Dispatching_Operation
(S
, Empty
);
9438 -- E is a derived operation or an internal operator which
9439 -- is being overridden. Remove E from further visibility.
9440 -- Furthermore, if E is a dispatching operation, it must be
9441 -- replaced in the list of primitive operations of its type
9442 -- (see Override_Dispatching_Operation).
9444 Overridden_Subp
:= E
;
9450 Prev
:= First_Entity
(Current_Scope
);
9451 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
9455 -- It is possible for E to be in the current scope and
9456 -- yet not in the entity chain. This can only occur in a
9457 -- generic context where E is an implicit concatenation
9458 -- in the formal part, because in a generic body the
9459 -- entity chain starts with the formals.
9462 (Present
(Prev
) or else Chars
(E
) = Name_Op_Concat
);
9464 -- E must be removed both from the entity_list of the
9465 -- current scope, and from the visibility chain
9467 if Debug_Flag_E
then
9468 Write_Str
("Override implicit operation ");
9469 Write_Int
(Int
(E
));
9473 -- If E is a predefined concatenation, it stands for four
9474 -- different operations. As a result, a single explicit
9475 -- declaration does not hide it. In a possible ambiguous
9476 -- situation, Disambiguate chooses the user-defined op,
9477 -- so it is correct to retain the previous internal one.
9479 if Chars
(E
) /= Name_Op_Concat
9480 or else Ekind
(E
) /= E_Operator
9482 -- For nondispatching derived operations that are
9483 -- overridden by a subprogram declared in the private
9484 -- part of a package, we retain the derived subprogram
9485 -- but mark it as not immediately visible. If the
9486 -- derived operation was declared in the visible part
9487 -- then this ensures that it will still be visible
9488 -- outside the package with the proper signature
9489 -- (calls from outside must also be directed to this
9490 -- version rather than the overriding one, unlike the
9491 -- dispatching case). Calls from inside the package
9492 -- will still resolve to the overriding subprogram
9493 -- since the derived one is marked as not visible
9494 -- within the package.
9496 -- If the private operation is dispatching, we achieve
9497 -- the overriding by keeping the implicit operation
9498 -- but setting its alias to be the overriding one. In
9499 -- this fashion the proper body is executed in all
9500 -- cases, but the original signature is used outside
9503 -- If the overriding is not in the private part, we
9504 -- remove the implicit operation altogether.
9506 if Is_Private_Declaration
(S
) then
9507 if not Is_Dispatching_Operation
(E
) then
9508 Set_Is_Immediately_Visible
(E
, False);
9510 -- Work done in Override_Dispatching_Operation,
9511 -- so nothing else needs to be done here.
9517 -- Find predecessor of E in Homonym chain
9519 if E
= Current_Entity
(E
) then
9522 Prev_Vis
:= Current_Entity
(E
);
9523 while Homonym
(Prev_Vis
) /= E
loop
9524 Prev_Vis
:= Homonym
(Prev_Vis
);
9528 if Prev_Vis
/= Empty
then
9530 -- Skip E in the visibility chain
9532 Set_Homonym
(Prev_Vis
, Homonym
(E
));
9535 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
9538 Set_Next_Entity
(Prev
, Next_Entity
(E
));
9540 if No
(Next_Entity
(Prev
)) then
9541 Set_Last_Entity
(Current_Scope
, Prev
);
9546 Enter_Overloaded_Entity
(S
);
9548 -- For entities generated by Derive_Subprograms the
9549 -- overridden operation is the inherited primitive
9550 -- (which is available through the attribute alias).
9552 if not (Comes_From_Source
(E
))
9553 and then Is_Dispatching_Operation
(E
)
9554 and then Find_Dispatching_Type
(E
) =
9555 Find_Dispatching_Type
(S
)
9556 and then Present
(Alias
(E
))
9557 and then Comes_From_Source
(Alias
(E
))
9559 Set_Overridden_Operation
(S
, Alias
(E
));
9561 -- Normal case of setting entity as overridden
9563 -- Note: Static_Initialization and Overridden_Operation
9564 -- attributes use the same field in subprogram entities.
9565 -- Static_Initialization is only defined for internal
9566 -- initialization procedures, where Overridden_Operation
9567 -- is irrelevant. Therefore the setting of this attribute
9568 -- must check whether the target is an init_proc.
9570 elsif not Is_Init_Proc
(S
) then
9571 Set_Overridden_Operation
(S
, E
);
9574 Check_Overriding_Indicator
(S
, E
, Is_Primitive
=> True);
9576 -- If S is a user-defined subprogram or a null procedure
9577 -- expanded to override an inherited null procedure, or a
9578 -- predefined dispatching primitive then indicate that E
9579 -- overrides the operation from which S is inherited.
9581 if Comes_From_Source
(S
)
9583 (Present
(Parent
(S
))
9585 Nkind
(Parent
(S
)) = N_Procedure_Specification
9587 Null_Present
(Parent
(S
)))
9589 (Present
(Alias
(E
))
9591 Is_Predefined_Dispatching_Operation
(Alias
(E
)))
9593 if Present
(Alias
(E
)) then
9594 Set_Overridden_Operation
(S
, Alias
(E
));
9598 if Is_Dispatching_Operation
(E
) then
9600 -- An overriding dispatching subprogram inherits the
9601 -- convention of the overridden subprogram (AI-117).
9603 Set_Convention
(S
, Convention
(E
));
9604 Check_Dispatching_Operation
(S
, E
);
9607 Check_Dispatching_Operation
(S
, Empty
);
9610 Check_For_Primitive_Subprogram
9611 (Is_Primitive_Subp
, Is_Overriding
=> True);
9612 goto Check_Inequality
;
9615 -- Apparent redeclarations in instances can occur when two
9616 -- formal types get the same actual type. The subprograms in
9617 -- in the instance are legal, even if not callable from the
9618 -- outside. Calls from within are disambiguated elsewhere.
9619 -- For dispatching operations in the visible part, the usual
9620 -- rules apply, and operations with the same profile are not
9623 elsif (In_Instance_Visible_Part
9624 and then not Is_Dispatching_Operation
(E
))
9625 or else In_Instance_Not_Visible
9629 -- Here we have a real error (identical profile)
9632 Error_Msg_Sloc
:= Sloc
(E
);
9634 -- Avoid cascaded errors if the entity appears in
9635 -- subsequent calls.
9637 Set_Scope
(S
, Current_Scope
);
9639 -- Generate error, with extra useful warning for the case
9640 -- of a generic instance with no completion.
9642 if Is_Generic_Instance
(S
)
9643 and then not Has_Completion
(E
)
9646 ("instantiation cannot provide body for&", S
);
9647 Error_Msg_N
("\& conflicts with declaration#", S
);
9649 Error_Msg_N
("& conflicts with declaration#", S
);
9656 -- If one subprogram has an access parameter and the other
9657 -- a parameter of an access type, calls to either might be
9658 -- ambiguous. Verify that parameters match except for the
9659 -- access parameter.
9661 if May_Hide_Profile
then
9667 F1
:= First_Formal
(S
);
9668 F2
:= First_Formal
(E
);
9669 while Present
(F1
) and then Present
(F2
) loop
9670 if Is_Access_Type
(Etype
(F1
)) then
9671 if not Is_Access_Type
(Etype
(F2
))
9672 or else not Conforming_Types
9673 (Designated_Type
(Etype
(F1
)),
9674 Designated_Type
(Etype
(F2
)),
9677 May_Hide_Profile
:= False;
9681 not Conforming_Types
9682 (Etype
(F1
), Etype
(F2
), Type_Conformant
)
9684 May_Hide_Profile
:= False;
9695 Error_Msg_NE
("calls to& may be ambiguous??", S
, S
);
9704 -- On exit, we know that S is a new entity
9706 Enter_Overloaded_Entity
(S
);
9707 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
9708 Check_Overriding_Indicator
9709 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
9711 -- Overloading is not allowed in SPARK, except for operators
9713 if Nkind
(S
) /= N_Defining_Operator_Symbol
then
9714 Error_Msg_Sloc
:= Sloc
(Homonym
(S
));
9715 Check_SPARK_Restriction
9716 ("overloading not allowed with entity#", S
);
9719 -- If S is a derived operation for an untagged type then by
9720 -- definition it's not a dispatching operation (even if the parent
9721 -- operation was dispatching), so Check_Dispatching_Operation is not
9722 -- called in that case.
9724 if No
(Derived_Type
)
9725 or else Is_Tagged_Type
(Derived_Type
)
9727 Check_Dispatching_Operation
(S
, Empty
);
9731 -- If this is a user-defined equality operator that is not a derived
9732 -- subprogram, create the corresponding inequality. If the operation is
9733 -- dispatching, the expansion is done elsewhere, and we do not create
9734 -- an explicit inequality operation.
9736 <<Check_Inequality
>>
9737 if Chars
(S
) = Name_Op_Eq
9738 and then Etype
(S
) = Standard_Boolean
9739 and then Present
(Parent
(S
))
9740 and then not Is_Dispatching_Operation
(S
)
9742 Make_Inequality_Operator
(S
);
9743 Check_Untagged_Equality
(S
);
9745 end New_Overloaded_Entity
;
9747 ---------------------
9748 -- Process_Formals --
9749 ---------------------
9751 procedure Process_Formals
9753 Related_Nod
: Node_Id
)
9755 Param_Spec
: Node_Id
;
9757 Formal_Type
: Entity_Id
;
9761 Num_Out_Params
: Nat
:= 0;
9762 First_Out_Param
: Entity_Id
:= Empty
;
9763 -- Used for setting Is_Only_Out_Parameter
9765 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean;
9766 -- Determine whether an access type designates a type coming from a
9769 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean;
9770 -- Check whether the default has a class-wide type. After analysis the
9771 -- default has the type of the formal, so we must also check explicitly
9772 -- for an access attribute.
9774 ----------------------------------
9775 -- Designates_From_Limited_With --
9776 ----------------------------------
9778 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean is
9779 Desig
: Entity_Id
:= Typ
;
9782 if Is_Access_Type
(Desig
) then
9783 Desig
:= Directly_Designated_Type
(Desig
);
9786 if Is_Class_Wide_Type
(Desig
) then
9787 Desig
:= Root_Type
(Desig
);
9791 Ekind
(Desig
) = E_Incomplete_Type
9792 and then From_Limited_With
(Desig
);
9793 end Designates_From_Limited_With
;
9795 ---------------------------
9796 -- Is_Class_Wide_Default --
9797 ---------------------------
9799 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean is
9801 return Is_Class_Wide_Type
(Designated_Type
(Etype
(D
)))
9802 or else (Nkind
(D
) = N_Attribute_Reference
9803 and then Attribute_Name
(D
) = Name_Access
9804 and then Is_Class_Wide_Type
(Etype
(Prefix
(D
))));
9805 end Is_Class_Wide_Default
;
9807 -- Start of processing for Process_Formals
9810 -- In order to prevent premature use of the formals in the same formal
9811 -- part, the Ekind is left undefined until all default expressions are
9812 -- analyzed. The Ekind is established in a separate loop at the end.
9814 Param_Spec
:= First
(T
);
9815 while Present
(Param_Spec
) loop
9816 Formal
:= Defining_Identifier
(Param_Spec
);
9817 Set_Never_Set_In_Source
(Formal
, True);
9818 Enter_Name
(Formal
);
9820 -- Case of ordinary parameters
9822 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
9823 Find_Type
(Parameter_Type
(Param_Spec
));
9824 Ptype
:= Parameter_Type
(Param_Spec
);
9826 if Ptype
= Error
then
9830 Formal_Type
:= Entity
(Ptype
);
9832 if Is_Incomplete_Type
(Formal_Type
)
9834 (Is_Class_Wide_Type
(Formal_Type
)
9835 and then Is_Incomplete_Type
(Root_Type
(Formal_Type
)))
9837 -- Ada 2005 (AI-326): Tagged incomplete types allowed in
9838 -- primitive operations, as long as their completion is
9839 -- in the same declarative part. If in the private part
9840 -- this means that the type cannot be a Taft-amendment type.
9841 -- Check is done on package exit. For access to subprograms,
9842 -- the use is legal for Taft-amendment types.
9844 -- Ada 2012: tagged incomplete types are allowed as generic
9845 -- formal types. They do not introduce dependencies and the
9846 -- corresponding generic subprogram does not have a delayed
9847 -- freeze, because it does not need a freeze node. However,
9848 -- it is still the case that untagged incomplete types cannot
9849 -- be Taft-amendment types and must be completed in private
9850 -- part, so the subprogram must appear in the list of private
9851 -- dependents of the type.
9853 if Is_Tagged_Type
(Formal_Type
)
9854 or else (Ada_Version
>= Ada_2012
9855 and then not From_Limited_With
(Formal_Type
)
9856 and then not Is_Generic_Type
(Formal_Type
))
9858 if Ekind
(Scope
(Current_Scope
)) = E_Package
9859 and then not Is_Generic_Type
(Formal_Type
)
9860 and then not Is_Class_Wide_Type
(Formal_Type
)
9863 (Parent
(T
), N_Access_Function_Definition
,
9864 N_Access_Procedure_Definition
)
9868 Private_Dependents
(Base_Type
(Formal_Type
)));
9870 -- Freezing is delayed to ensure that Register_Prim
9871 -- will get called for this operation, which is needed
9872 -- in cases where static dispatch tables aren't built.
9873 -- (Note that the same is done for controlling access
9874 -- parameter cases in function Access_Definition.)
9876 Set_Has_Delayed_Freeze
(Current_Scope
);
9880 -- Special handling of Value_Type for CIL case
9882 elsif Is_Value_Type
(Formal_Type
) then
9885 elsif not Nkind_In
(Parent
(T
), N_Access_Function_Definition
,
9886 N_Access_Procedure_Definition
)
9888 -- AI05-0151: Tagged incomplete types are allowed in all
9889 -- formal parts. Untagged incomplete types are not allowed
9890 -- in bodies. Limited views of either kind are not allowed
9891 -- if there is no place at which the non-limited view can
9892 -- become available.
9894 -- Incomplete formal untagged types are not allowed in
9895 -- subprogram bodies (but are legal in their declarations).
9897 if Is_Generic_Type
(Formal_Type
)
9898 and then not Is_Tagged_Type
(Formal_Type
)
9899 and then Nkind
(Parent
(Related_Nod
)) = N_Subprogram_Body
9902 ("invalid use of formal incomplete type", Param_Spec
);
9904 elsif Ada_Version
>= Ada_2012
then
9905 if Is_Tagged_Type
(Formal_Type
)
9906 and then (not From_Limited_With
(Formal_Type
)
9907 or else not In_Package_Body
)
9911 elsif Nkind_In
(Parent
(Parent
(T
)), N_Accept_Statement
,
9912 N_Accept_Alternative
,
9917 ("invalid use of untagged incomplete type&",
9918 Ptype
, Formal_Type
);
9923 ("invalid use of incomplete type&",
9924 Param_Spec
, Formal_Type
);
9926 -- Further checks on the legality of incomplete types
9927 -- in formal parts are delayed until the freeze point
9928 -- of the enclosing subprogram or access to subprogram.
9932 elsif Ekind
(Formal_Type
) = E_Void
then
9934 ("premature use of&",
9935 Parameter_Type
(Param_Spec
), Formal_Type
);
9938 -- Ada 2012 (AI-142): Handle aliased parameters
9940 if Ada_Version
>= Ada_2012
9941 and then Aliased_Present
(Param_Spec
)
9943 Set_Is_Aliased
(Formal
);
9946 -- Ada 2005 (AI-231): Create and decorate an internal subtype
9947 -- declaration corresponding to the null-excluding type of the
9948 -- formal in the enclosing scope. Finally, replace the parameter
9949 -- type of the formal with the internal subtype.
9951 if Ada_Version
>= Ada_2005
9952 and then Null_Exclusion_Present
(Param_Spec
)
9954 if not Is_Access_Type
(Formal_Type
) then
9956 ("`NOT NULL` allowed only for an access type", Param_Spec
);
9959 if Can_Never_Be_Null
(Formal_Type
)
9960 and then Comes_From_Source
(Related_Nod
)
9963 ("`NOT NULL` not allowed (& already excludes null)",
9964 Param_Spec
, Formal_Type
);
9968 Create_Null_Excluding_Itype
9970 Related_Nod
=> Related_Nod
,
9971 Scope_Id
=> Scope
(Current_Scope
));
9973 -- If the designated type of the itype is an itype that is
9974 -- not frozen yet, we set the Has_Delayed_Freeze attribute
9975 -- on the access subtype, to prevent order-of-elaboration
9976 -- issues in the backend.
9979 -- type T is access procedure;
9980 -- procedure Op (O : not null T);
9982 if Is_Itype
(Directly_Designated_Type
(Formal_Type
))
9984 not Is_Frozen
(Directly_Designated_Type
(Formal_Type
))
9986 Set_Has_Delayed_Freeze
(Formal_Type
);
9991 -- An access formal type
9995 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
9997 -- No need to continue if we already notified errors
9999 if not Present
(Formal_Type
) then
10003 -- Ada 2005 (AI-254)
10006 AD
: constant Node_Id
:=
10007 Access_To_Subprogram_Definition
10008 (Parameter_Type
(Param_Spec
));
10010 if Present
(AD
) and then Protected_Present
(AD
) then
10012 Replace_Anonymous_Access_To_Protected_Subprogram
10018 Set_Etype
(Formal
, Formal_Type
);
10020 -- Deal with default expression if present
10022 Default
:= Expression
(Param_Spec
);
10024 if Present
(Default
) then
10025 Check_SPARK_Restriction
10026 ("default expression is not allowed", Default
);
10028 if Out_Present
(Param_Spec
) then
10030 ("default initialization only allowed for IN parameters",
10034 -- Do the special preanalysis of the expression (see section on
10035 -- "Handling of Default Expressions" in the spec of package Sem).
10037 Preanalyze_Spec_Expression
(Default
, Formal_Type
);
10039 -- An access to constant cannot be the default for
10040 -- an access parameter that is an access to variable.
10042 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
10043 and then not Is_Access_Constant
(Formal_Type
)
10044 and then Is_Access_Type
(Etype
(Default
))
10045 and then Is_Access_Constant
(Etype
(Default
))
10048 ("formal that is access to variable cannot be initialized "
10049 & "with an access-to-constant expression", Default
);
10052 -- Check that the designated type of an access parameter's default
10053 -- is not a class-wide type unless the parameter's designated type
10054 -- is also class-wide.
10056 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
10057 and then not Designates_From_Limited_With
(Formal_Type
)
10058 and then Is_Class_Wide_Default
(Default
)
10059 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
10062 ("access to class-wide expression not allowed here", Default
);
10065 -- Check incorrect use of dynamically tagged expressions
10067 if Is_Tagged_Type
(Formal_Type
) then
10068 Check_Dynamically_Tagged_Expression
10070 Typ
=> Formal_Type
,
10071 Related_Nod
=> Default
);
10075 -- Ada 2005 (AI-231): Static checks
10077 if Ada_Version
>= Ada_2005
10078 and then Is_Access_Type
(Etype
(Formal
))
10079 and then Can_Never_Be_Null
(Etype
(Formal
))
10081 Null_Exclusion_Static_Checks
(Param_Spec
);
10084 -- The following checks are relevant when SPARK_Mode is on as these
10085 -- are not standard Ada legality rules.
10087 if SPARK_Mode
= On
then
10088 if Ekind_In
(Scope
(Formal
), E_Function
, E_Generic_Function
) then
10090 -- A function cannot have a parameter of mode IN OUT or OUT
10093 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_Out_Parameter
) then
10095 ("function cannot have parameter of mode `OUT` or "
10096 & "`IN OUT`", Formal
);
10098 -- A function cannot have an effectively volatile formal
10099 -- parameter (SPARK RM 7.1.3(10)).
10101 elsif Is_Effectively_Volatile
(Formal
) then
10103 ("function cannot have a volatile formal parameter",
10107 -- A procedure cannot have an effectively volatile formal
10108 -- parameter of mode IN because it behaves as a constant
10109 -- (SPARK RM 7.1.3(6)).
10111 elsif Ekind
(Scope
(Formal
)) = E_Procedure
10112 and then Ekind
(Formal
) = E_In_Parameter
10113 and then Is_Effectively_Volatile
(Formal
)
10116 ("formal parameter of mode `IN` cannot be volatile", Formal
);
10124 -- If this is the formal part of a function specification, analyze the
10125 -- subtype mark in the context where the formals are visible but not
10126 -- yet usable, and may hide outer homographs.
10128 if Nkind
(Related_Nod
) = N_Function_Specification
then
10129 Analyze_Return_Type
(Related_Nod
);
10132 -- Now set the kind (mode) of each formal
10134 Param_Spec
:= First
(T
);
10135 while Present
(Param_Spec
) loop
10136 Formal
:= Defining_Identifier
(Param_Spec
);
10137 Set_Formal_Mode
(Formal
);
10139 if Ekind
(Formal
) = E_In_Parameter
then
10140 Set_Default_Value
(Formal
, Expression
(Param_Spec
));
10142 if Present
(Expression
(Param_Spec
)) then
10143 Default
:= Expression
(Param_Spec
);
10145 if Is_Scalar_Type
(Etype
(Default
)) then
10146 if Nkind
(Parameter_Type
(Param_Spec
)) /=
10147 N_Access_Definition
10149 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
10153 (Related_Nod
, Parameter_Type
(Param_Spec
));
10156 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
10160 elsif Ekind
(Formal
) = E_Out_Parameter
then
10161 Num_Out_Params
:= Num_Out_Params
+ 1;
10163 if Num_Out_Params
= 1 then
10164 First_Out_Param
:= Formal
;
10167 elsif Ekind
(Formal
) = E_In_Out_Parameter
then
10168 Num_Out_Params
:= Num_Out_Params
+ 1;
10171 -- Skip remaining processing if formal type was in error
10173 if Etype
(Formal
) = Any_Type
or else Error_Posted
(Formal
) then
10174 goto Next_Parameter
;
10177 -- Force call by reference if aliased
10179 if Is_Aliased
(Formal
) then
10180 Set_Mechanism
(Formal
, By_Reference
);
10182 -- Warn if user asked this to be passed by copy
10184 if Convention
(Formal_Type
) = Convention_Ada_Pass_By_Copy
then
10186 ("cannot pass aliased parameter & by copy??", Formal
);
10189 -- Force mechanism if type has Convention Ada_Pass_By_Ref/Copy
10191 elsif Convention
(Formal_Type
) = Convention_Ada_Pass_By_Copy
then
10192 Set_Mechanism
(Formal
, By_Copy
);
10194 elsif Convention
(Formal_Type
) = Convention_Ada_Pass_By_Reference
then
10195 Set_Mechanism
(Formal
, By_Reference
);
10202 if Present
(First_Out_Param
) and then Num_Out_Params
= 1 then
10203 Set_Is_Only_Out_Parameter
(First_Out_Param
);
10205 end Process_Formals
;
10207 ----------------------------
10208 -- Reference_Body_Formals --
10209 ----------------------------
10211 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
) is
10216 if Error_Posted
(Spec
) then
10220 -- Iterate over both lists. They may be of different lengths if the two
10221 -- specs are not conformant.
10223 Fs
:= First_Formal
(Spec
);
10224 Fb
:= First_Formal
(Bod
);
10225 while Present
(Fs
) and then Present
(Fb
) loop
10226 Generate_Reference
(Fs
, Fb
, 'b');
10228 if Style_Check
then
10229 Style
.Check_Identifier
(Fb
, Fs
);
10232 Set_Spec_Entity
(Fb
, Fs
);
10233 Set_Referenced
(Fs
, False);
10237 end Reference_Body_Formals
;
10239 -------------------------
10240 -- Set_Actual_Subtypes --
10241 -------------------------
10243 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
10245 Formal
: Entity_Id
;
10247 First_Stmt
: Node_Id
:= Empty
;
10248 AS_Needed
: Boolean;
10251 -- If this is an empty initialization procedure, no need to create
10252 -- actual subtypes (small optimization).
10254 if Ekind
(Subp
) = E_Procedure
and then Is_Null_Init_Proc
(Subp
) then
10258 Formal
:= First_Formal
(Subp
);
10259 while Present
(Formal
) loop
10260 T
:= Etype
(Formal
);
10262 -- We never need an actual subtype for a constrained formal
10264 if Is_Constrained
(T
) then
10265 AS_Needed
:= False;
10267 -- If we have unknown discriminants, then we do not need an actual
10268 -- subtype, or more accurately we cannot figure it out. Note that
10269 -- all class-wide types have unknown discriminants.
10271 elsif Has_Unknown_Discriminants
(T
) then
10272 AS_Needed
:= False;
10274 -- At this stage we have an unconstrained type that may need an
10275 -- actual subtype. For sure the actual subtype is needed if we have
10276 -- an unconstrained array type.
10278 elsif Is_Array_Type
(T
) then
10281 -- The only other case needing an actual subtype is an unconstrained
10282 -- record type which is an IN parameter (we cannot generate actual
10283 -- subtypes for the OUT or IN OUT case, since an assignment can
10284 -- change the discriminant values. However we exclude the case of
10285 -- initialization procedures, since discriminants are handled very
10286 -- specially in this context, see the section entitled "Handling of
10287 -- Discriminants" in Einfo.
10289 -- We also exclude the case of Discrim_SO_Functions (functions used
10290 -- in front end layout mode for size/offset values), since in such
10291 -- functions only discriminants are referenced, and not only are such
10292 -- subtypes not needed, but they cannot always be generated, because
10293 -- of order of elaboration issues.
10295 elsif Is_Record_Type
(T
)
10296 and then Ekind
(Formal
) = E_In_Parameter
10297 and then Chars
(Formal
) /= Name_uInit
10298 and then not Is_Unchecked_Union
(T
)
10299 and then not Is_Discrim_SO_Function
(Subp
)
10303 -- All other cases do not need an actual subtype
10306 AS_Needed
:= False;
10309 -- Generate actual subtypes for unconstrained arrays and
10310 -- unconstrained discriminated records.
10313 if Nkind
(N
) = N_Accept_Statement
then
10315 -- If expansion is active, the formal is replaced by a local
10316 -- variable that renames the corresponding entry of the
10317 -- parameter block, and it is this local variable that may
10318 -- require an actual subtype.
10320 if Expander_Active
then
10321 Decl
:= Build_Actual_Subtype
(T
, Renamed_Object
(Formal
));
10323 Decl
:= Build_Actual_Subtype
(T
, Formal
);
10326 if Present
(Handled_Statement_Sequence
(N
)) then
10328 First
(Statements
(Handled_Statement_Sequence
(N
)));
10329 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
10330 Mark_Rewrite_Insertion
(Decl
);
10332 -- If the accept statement has no body, there will be no
10333 -- reference to the actuals, so no need to compute actual
10340 Decl
:= Build_Actual_Subtype
(T
, Formal
);
10341 Prepend
(Decl
, Declarations
(N
));
10342 Mark_Rewrite_Insertion
(Decl
);
10345 -- The declaration uses the bounds of an existing object, and
10346 -- therefore needs no constraint checks.
10348 Analyze
(Decl
, Suppress
=> All_Checks
);
10350 -- We need to freeze manually the generated type when it is
10351 -- inserted anywhere else than in a declarative part.
10353 if Present
(First_Stmt
) then
10354 Insert_List_Before_And_Analyze
(First_Stmt
,
10355 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
10357 -- Ditto if the type has a dynamic predicate, because the
10358 -- generated function will mention the actual subtype.
10360 elsif Has_Dynamic_Predicate_Aspect
(T
) then
10361 Insert_List_Before_And_Analyze
(Decl
,
10362 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
10365 if Nkind
(N
) = N_Accept_Statement
10366 and then Expander_Active
10368 Set_Actual_Subtype
(Renamed_Object
(Formal
),
10369 Defining_Identifier
(Decl
));
10371 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
10375 Next_Formal
(Formal
);
10377 end Set_Actual_Subtypes
;
10379 ---------------------
10380 -- Set_Formal_Mode --
10381 ---------------------
10383 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
10384 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
10387 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
10388 -- since we ensure that corresponding actuals are always valid at the
10389 -- point of the call.
10391 if Out_Present
(Spec
) then
10392 if Ekind_In
(Scope
(Formal_Id
), E_Function
, E_Generic_Function
) then
10394 -- [IN] OUT parameters allowed for functions in Ada 2012
10396 if Ada_Version
>= Ada_2012
then
10398 -- Even in Ada 2012 operators can only have IN parameters
10400 if Is_Operator_Symbol_Name
(Chars
(Scope
(Formal_Id
))) then
10401 Error_Msg_N
("operators can only have IN parameters", Spec
);
10404 if In_Present
(Spec
) then
10405 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
10407 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
10410 Set_Has_Out_Or_In_Out_Parameter
(Scope
(Formal_Id
), True);
10412 -- But not in earlier versions of Ada
10415 Error_Msg_N
("functions can only have IN parameters", Spec
);
10416 Set_Ekind
(Formal_Id
, E_In_Parameter
);
10419 elsif In_Present
(Spec
) then
10420 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
10423 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
10424 Set_Never_Set_In_Source
(Formal_Id
, True);
10425 Set_Is_True_Constant
(Formal_Id
, False);
10426 Set_Current_Value
(Formal_Id
, Empty
);
10430 Set_Ekind
(Formal_Id
, E_In_Parameter
);
10433 -- Set Is_Known_Non_Null for access parameters since the language
10434 -- guarantees that access parameters are always non-null. We also set
10435 -- Can_Never_Be_Null, since there is no way to change the value.
10437 if Nkind
(Parameter_Type
(Spec
)) = N_Access_Definition
then
10439 -- Ada 2005 (AI-231): In Ada 95, access parameters are always non-
10440 -- null; In Ada 2005, only if then null_exclusion is explicit.
10442 if Ada_Version
< Ada_2005
10443 or else Can_Never_Be_Null
(Etype
(Formal_Id
))
10445 Set_Is_Known_Non_Null
(Formal_Id
);
10446 Set_Can_Never_Be_Null
(Formal_Id
);
10449 -- Ada 2005 (AI-231): Null-exclusion access subtype
10451 elsif Is_Access_Type
(Etype
(Formal_Id
))
10452 and then Can_Never_Be_Null
(Etype
(Formal_Id
))
10454 Set_Is_Known_Non_Null
(Formal_Id
);
10456 -- We can also set Can_Never_Be_Null (thus preventing some junk
10457 -- access checks) for the case of an IN parameter, which cannot
10458 -- be changed, or for an IN OUT parameter, which can be changed but
10459 -- not to a null value. But for an OUT parameter, the initial value
10460 -- passed in can be null, so we can't set this flag in that case.
10462 if Ekind
(Formal_Id
) /= E_Out_Parameter
then
10463 Set_Can_Never_Be_Null
(Formal_Id
);
10467 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
10468 Set_Formal_Validity
(Formal_Id
);
10469 end Set_Formal_Mode
;
10471 -------------------------
10472 -- Set_Formal_Validity --
10473 -------------------------
10475 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
10477 -- If no validity checking, then we cannot assume anything about the
10478 -- validity of parameters, since we do not know there is any checking
10479 -- of the validity on the call side.
10481 if not Validity_Checks_On
then
10484 -- If validity checking for parameters is enabled, this means we are
10485 -- not supposed to make any assumptions about argument values.
10487 elsif Validity_Check_Parameters
then
10490 -- If we are checking in parameters, we will assume that the caller is
10491 -- also checking parameters, so we can assume the parameter is valid.
10493 elsif Ekind
(Formal_Id
) = E_In_Parameter
10494 and then Validity_Check_In_Params
10496 Set_Is_Known_Valid
(Formal_Id
, True);
10498 -- Similar treatment for IN OUT parameters
10500 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
10501 and then Validity_Check_In_Out_Params
10503 Set_Is_Known_Valid
(Formal_Id
, True);
10505 end Set_Formal_Validity
;
10507 ------------------------
10508 -- Subtype_Conformant --
10509 ------------------------
10511 function Subtype_Conformant
10512 (New_Id
: Entity_Id
;
10513 Old_Id
: Entity_Id
;
10514 Skip_Controlling_Formals
: Boolean := False) return Boolean
10518 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
,
10519 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
10521 end Subtype_Conformant
;
10523 ---------------------
10524 -- Type_Conformant --
10525 ---------------------
10527 function Type_Conformant
10528 (New_Id
: Entity_Id
;
10529 Old_Id
: Entity_Id
;
10530 Skip_Controlling_Formals
: Boolean := False) return Boolean
10534 May_Hide_Profile
:= False;
10536 (New_Id
, Old_Id
, Type_Conformant
, False, Result
,
10537 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
10539 end Type_Conformant
;
10541 -------------------------------
10542 -- Valid_Operator_Definition --
10543 -------------------------------
10545 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
10548 Id
: constant Name_Id
:= Chars
(Designator
);
10552 F
:= First_Formal
(Designator
);
10553 while Present
(F
) loop
10556 if Present
(Default_Value
(F
)) then
10558 ("default values not allowed for operator parameters",
10561 -- For function instantiations that are operators, we must check
10562 -- separately that the corresponding generic only has in-parameters.
10563 -- For subprogram declarations this is done in Set_Formal_Mode. Such
10564 -- an error could not arise in earlier versions of the language.
10566 elsif Ekind
(F
) /= E_In_Parameter
then
10567 Error_Msg_N
("operators can only have IN parameters", F
);
10573 -- Verify that user-defined operators have proper number of arguments
10574 -- First case of operators which can only be unary
10576 if Nam_In
(Id
, Name_Op_Not
, Name_Op_Abs
) then
10579 -- Case of operators which can be unary or binary
10581 elsif Nam_In
(Id
, Name_Op_Add
, Name_Op_Subtract
) then
10582 N_OK
:= (N
in 1 .. 2);
10584 -- All other operators can only be binary
10592 ("incorrect number of arguments for operator", Designator
);
10596 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
10597 and then not Is_Intrinsic_Subprogram
(Designator
)
10600 ("explicit definition of inequality not allowed", Designator
);
10602 end Valid_Operator_Definition
;