1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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 Itypes
; use Itypes
;
44 with Lib
.Xref
; use Lib
.Xref
;
45 with Layout
; use Layout
;
46 with Namet
; use Namet
;
48 with Nlists
; use Nlists
;
49 with Nmake
; use Nmake
;
51 with Output
; use Output
;
52 with Restrict
; use Restrict
;
53 with Rident
; use Rident
;
54 with Rtsfind
; use Rtsfind
;
56 with Sem_Aux
; use Sem_Aux
;
57 with Sem_Cat
; use Sem_Cat
;
58 with Sem_Ch3
; use Sem_Ch3
;
59 with Sem_Ch4
; use Sem_Ch4
;
60 with Sem_Ch5
; use Sem_Ch5
;
61 with Sem_Ch8
; use Sem_Ch8
;
62 with Sem_Ch10
; use Sem_Ch10
;
63 with Sem_Ch12
; use Sem_Ch12
;
64 with Sem_Ch13
; use Sem_Ch13
;
65 with Sem_Dim
; use Sem_Dim
;
66 with Sem_Disp
; use Sem_Disp
;
67 with Sem_Dist
; use Sem_Dist
;
68 with Sem_Elim
; use Sem_Elim
;
69 with Sem_Eval
; use Sem_Eval
;
70 with Sem_Mech
; use Sem_Mech
;
71 with Sem_Prag
; use Sem_Prag
;
72 with Sem_Res
; use Sem_Res
;
73 with Sem_Util
; use Sem_Util
;
74 with Sem_Type
; use Sem_Type
;
75 with Sem_Warn
; use Sem_Warn
;
76 with Sinput
; use Sinput
;
77 with Stand
; use Stand
;
78 with Sinfo
; use Sinfo
;
79 with Sinfo
.CN
; use Sinfo
.CN
;
80 with Snames
; use Snames
;
81 with Stringt
; use Stringt
;
83 with Stylesw
; use Stylesw
;
84 with Targparm
; use Targparm
;
85 with Tbuild
; use Tbuild
;
86 with Uintp
; use Uintp
;
87 with Urealp
; use Urealp
;
88 with Validsw
; use Validsw
;
90 package body Sem_Ch6
is
92 May_Hide_Profile
: Boolean := False;
93 -- This flag is used to indicate that two formals in two subprograms being
94 -- checked for conformance differ only in that one is an access parameter
95 -- while the other is of a general access type with the same designated
96 -- type. In this case, if the rest of the signatures match, a call to
97 -- either subprogram may be ambiguous, which is worth a warning. The flag
98 -- is set in Compatible_Types, and the warning emitted in
99 -- New_Overloaded_Entity.
101 -----------------------
102 -- Local Subprograms --
103 -----------------------
105 procedure Analyze_Null_Procedure
107 Is_Completion
: out Boolean);
108 -- A null procedure can be a declaration or (Ada 2012) a completion.
110 procedure Analyze_Return_Statement
(N
: Node_Id
);
111 -- Common processing for simple and extended return statements
113 procedure Analyze_Function_Return
(N
: Node_Id
);
114 -- Subsidiary to Analyze_Return_Statement. Called when the return statement
115 -- applies to a [generic] function.
117 procedure Analyze_Return_Type
(N
: Node_Id
);
118 -- Subsidiary to Process_Formals: analyze subtype mark in function
119 -- specification in a context where the formals are visible and hide
122 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
);
123 -- Does all the real work of Analyze_Subprogram_Body. This is split out so
124 -- that we can use RETURN but not skip the debug output at the end.
126 procedure Analyze_Generic_Subprogram_Body
(N
: Node_Id
; Gen_Id
: Entity_Id
);
127 -- Analyze a generic subprogram body. N is the body to be analyzed, and
128 -- Gen_Id is the defining entity Id for the corresponding spec.
130 procedure Build_Body_To_Inline
(N
: Node_Id
; Subp
: Entity_Id
);
131 -- If a subprogram has pragma Inline and inlining is active, use generic
132 -- machinery to build an unexpanded body for the subprogram. This body is
133 -- subsequently used for inline expansions at call sites. If subprogram can
134 -- be inlined (depending on size and nature of local declarations) this
135 -- function returns true. Otherwise subprogram body is treated normally.
136 -- If proper warnings are enabled and the subprogram contains a construct
137 -- that cannot be inlined, the offending construct is flagged accordingly.
139 function Can_Override_Operator
(Subp
: Entity_Id
) return Boolean;
140 -- Returns true if Subp can override a predefined operator.
142 procedure Check_And_Build_Body_To_Inline
145 Body_Id
: Entity_Id
);
146 -- Spec_Id and Body_Id are the entities of the specification and body of
147 -- the subprogram body N. If N can be inlined by the frontend (supported
148 -- cases documented in Check_Body_To_Inline) then build the body-to-inline
149 -- associated with N and attach it to the declaration node of Spec_Id.
151 procedure Check_Conformance
154 Ctype
: Conformance_Type
;
156 Conforms
: out Boolean;
157 Err_Loc
: Node_Id
:= Empty
;
158 Get_Inst
: Boolean := False;
159 Skip_Controlling_Formals
: Boolean := False);
160 -- Given two entities, this procedure checks that the profiles associated
161 -- with these entities meet the conformance criterion given by the third
162 -- parameter. If they conform, Conforms is set True and control returns
163 -- to the caller. If they do not conform, Conforms is set to False, and
164 -- in addition, if Errmsg is True on the call, proper messages are output
165 -- to complain about the conformance failure. If Err_Loc is non_Empty
166 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
167 -- error messages are placed on the appropriate part of the construct
168 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
169 -- against a formal access-to-subprogram type so Get_Instance_Of must
172 procedure Check_Subprogram_Order
(N
: Node_Id
);
173 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
174 -- the alpha ordering rule for N if this ordering requirement applicable.
176 procedure Check_Returns
180 Proc
: Entity_Id
:= Empty
);
181 -- Called to check for missing return statements in a function body, or for
182 -- returns present in a procedure body which has No_Return set. HSS is the
183 -- handled statement sequence for the subprogram body. This procedure
184 -- checks all flow paths to make sure they either have return (Mode = 'F',
185 -- used for functions) or do not have a return (Mode = 'P', used for
186 -- No_Return procedures). The flag Err is set if there are any control
187 -- paths not explicitly terminated by a return in the function case, and is
188 -- True otherwise. Proc is the entity for the procedure case and is used
189 -- in posting the warning message.
191 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
);
192 -- In Ada 2012, a primitive equality operator on an untagged record type
193 -- must appear before the type is frozen, and have the same visibility as
194 -- that of the type. This procedure checks that this rule is met, and
195 -- otherwise emits an error on the subprogram declaration and a warning
196 -- on the earlier freeze point if it is easy to locate. In Ada 2012 mode,
197 -- this routine outputs errors (or warnings if -gnatd.E is set). In earlier
198 -- versions of Ada, warnings are output if Warn_On_Ada_2012_Incompatibility
199 -- is set, otherwise the call has no effect.
201 procedure Enter_Overloaded_Entity
(S
: Entity_Id
);
202 -- This procedure makes S, a new overloaded entity, into the first visible
203 -- entity with that name.
205 function Is_Non_Overriding_Operation
207 New_E
: Entity_Id
) return Boolean;
208 -- Enforce the rule given in 12.3(18): a private operation in an instance
209 -- overrides an inherited operation only if the corresponding operation
210 -- was overriding in the generic. This needs to be checked for primitive
211 -- operations of types derived (in the generic unit) from formal private
212 -- or formal derived types.
214 procedure Make_Inequality_Operator
(S
: Entity_Id
);
215 -- Create the declaration for an inequality operator that is implicitly
216 -- created by a user-defined equality operator that yields a boolean.
218 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
);
219 -- Formal_Id is an formal parameter entity. This procedure deals with
220 -- setting the proper validity status for this entity, which depends on
221 -- the kind of parameter and the validity checking mode.
223 ---------------------------------------------
224 -- Analyze_Abstract_Subprogram_Declaration --
225 ---------------------------------------------
227 procedure Analyze_Abstract_Subprogram_Declaration
(N
: Node_Id
) is
228 Designator
: constant Entity_Id
:=
229 Analyze_Subprogram_Specification
(Specification
(N
));
230 Scop
: constant Entity_Id
:= Current_Scope
;
233 Check_SPARK_Restriction
("abstract subprogram is not allowed", N
);
235 Generate_Definition
(Designator
);
236 Set_Contract
(Designator
, Make_Contract
(Sloc
(Designator
)));
237 Set_Is_Abstract_Subprogram
(Designator
);
238 New_Overloaded_Entity
(Designator
);
239 Check_Delayed_Subprogram
(Designator
);
241 Set_Categorization_From_Scope
(Designator
, Scop
);
243 if Ekind
(Scope
(Designator
)) = E_Protected_Type
then
245 ("abstract subprogram not allowed in protected type", N
);
247 -- Issue a warning if the abstract subprogram is neither a dispatching
248 -- operation nor an operation that overrides an inherited subprogram or
249 -- predefined operator, since this most likely indicates a mistake.
251 elsif Warn_On_Redundant_Constructs
252 and then not Is_Dispatching_Operation
(Designator
)
253 and then not Present
(Overridden_Operation
(Designator
))
254 and then (not Is_Operator_Symbol_Name
(Chars
(Designator
))
255 or else Scop
/= Scope
(Etype
(First_Formal
(Designator
))))
258 ("abstract subprogram is not dispatching or overriding?r?", N
);
261 Generate_Reference_To_Formals
(Designator
);
262 Check_Eliminated
(Designator
);
264 if Has_Aspects
(N
) then
265 Analyze_Aspect_Specifications
(N
, Designator
);
267 end Analyze_Abstract_Subprogram_Declaration
;
269 ---------------------------------
270 -- Analyze_Expression_Function --
271 ---------------------------------
273 procedure Analyze_Expression_Function
(N
: Node_Id
) is
274 Loc
: constant Source_Ptr
:= Sloc
(N
);
275 LocX
: constant Source_Ptr
:= Sloc
(Expression
(N
));
276 Expr
: constant Node_Id
:= Expression
(N
);
277 Spec
: constant Node_Id
:= Specification
(N
);
282 -- If the expression is a completion, Prev is the entity whose
283 -- declaration is completed. Def_Id is needed to analyze the spec.
291 -- This is one of the occasions on which we transform the tree during
292 -- semantic analysis. If this is a completion, transform the expression
293 -- function into an equivalent subprogram body, and analyze it.
295 -- Expression functions are inlined unconditionally. The back-end will
296 -- determine whether this is possible.
298 Inline_Processing_Required
:= True;
300 -- Create a specification for the generated body. Types and defauts in
301 -- the profile are copies of the spec, but new entities must be created
302 -- for the unit name and the formals.
304 New_Spec
:= New_Copy_Tree
(Spec
);
305 Set_Defining_Unit_Name
(New_Spec
,
306 Make_Defining_Identifier
(Sloc
(Defining_Unit_Name
(Spec
)),
307 Chars
(Defining_Unit_Name
(Spec
))));
309 if Present
(Parameter_Specifications
(New_Spec
)) then
311 Formal_Spec
: Node_Id
;
313 Formal_Spec
:= First
(Parameter_Specifications
(New_Spec
));
314 while Present
(Formal_Spec
) loop
315 Set_Defining_Identifier
317 Make_Defining_Identifier
(Sloc
(Formal_Spec
),
318 Chars
=> Chars
(Defining_Identifier
(Formal_Spec
))));
324 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
326 -- If there are previous overloadable entities with the same name,
327 -- check whether any of them is completed by the expression function.
329 if Present
(Prev
) and then Is_Overloadable
(Prev
) then
330 Def_Id
:= Analyze_Subprogram_Specification
(Spec
);
331 Prev
:= Find_Corresponding_Spec
(N
);
334 Ret
:= Make_Simple_Return_Statement
(LocX
, Expression
(N
));
337 Make_Subprogram_Body
(Loc
,
338 Specification
=> New_Spec
,
339 Declarations
=> Empty_List
,
340 Handled_Statement_Sequence
=>
341 Make_Handled_Sequence_Of_Statements
(LocX
,
342 Statements
=> New_List
(Ret
)));
344 -- If the expression completes a generic subprogram, we must create a
345 -- separate node for the body, because at instantiation the original
346 -- node of the generic copy must be a generic subprogram body, and
347 -- cannot be a expression function. Otherwise we just rewrite the
348 -- expression with the non-generic body.
350 if Present
(Prev
) and then Ekind
(Prev
) = E_Generic_Function
then
351 Insert_After
(N
, New_Body
);
353 -- Propagate any aspects or pragmas that apply to the expression
354 -- function to the proper body when the expression function acts
357 if Has_Aspects
(N
) then
358 Move_Aspects
(N
, To
=> New_Body
);
361 Relocate_Pragmas_To_Body
(New_Body
);
363 Rewrite
(N
, Make_Null_Statement
(Loc
));
364 Set_Has_Completion
(Prev
, False);
367 Set_Is_Inlined
(Prev
);
369 elsif Present
(Prev
) and then Comes_From_Source
(Prev
) then
370 Set_Has_Completion
(Prev
, False);
372 -- For navigation purposes, indicate that the function is a body
374 Generate_Reference
(Prev
, Defining_Entity
(N
), 'b', Force
=> True);
375 Rewrite
(N
, New_Body
);
377 -- Propagate any pragmas that apply to the expression function to the
378 -- proper body when the expression function acts as a completion.
379 -- Aspects are automatically transfered because of node rewriting.
381 Relocate_Pragmas_To_Body
(N
);
384 -- Prev is the previous entity with the same name, but it is can
385 -- be an unrelated spec that is not completed by the expression
386 -- function. In that case the relevant entity is the one in the body.
387 -- Not clear that the backend can inline it in this case ???
389 if Has_Completion
(Prev
) then
390 Set_Is_Inlined
(Prev
);
392 -- The formals of the expression function are body formals,
393 -- and do not appear in the ali file, which will only contain
394 -- references to the formals of the original subprogram spec.
401 F1
:= First_Formal
(Def_Id
);
402 F2
:= First_Formal
(Prev
);
404 while Present
(F1
) loop
405 Set_Spec_Entity
(F1
, F2
);
412 Set_Is_Inlined
(Defining_Entity
(New_Body
));
415 -- If this is not a completion, create both a declaration and a body, so
416 -- that the expression can be inlined whenever possible.
419 -- An expression function that is not a completion is not a
420 -- subprogram declaration, and thus cannot appear in a protected
423 if Nkind
(Parent
(N
)) = N_Protected_Definition
then
425 ("an expression function is not a legal protected operation", N
);
429 Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
431 Rewrite
(N
, New_Decl
);
433 Set_Is_Inlined
(Defining_Entity
(New_Decl
));
435 -- To prevent premature freeze action, insert the new body at the end
436 -- of the current declarations, or at the end of the package spec.
437 -- However, resolve usage names now, to prevent spurious visibility
438 -- on later entities. Note that the function can now be called in
439 -- the current declarative part, which will appear to be prior to
440 -- the presence of the body in the code. There are nevertheless no
441 -- order of elaboration issues because all name resolution has taken
442 -- place at the point of declaration.
445 Decls
: List_Id
:= List_Containing
(N
);
446 Par
: constant Node_Id
:= Parent
(Decls
);
447 Id
: constant Entity_Id
:= Defining_Entity
(New_Decl
);
450 if Nkind
(Par
) = N_Package_Specification
451 and then Decls
= Visible_Declarations
(Par
)
452 and then Present
(Private_Declarations
(Par
))
453 and then not Is_Empty_List
(Private_Declarations
(Par
))
455 Decls
:= Private_Declarations
(Par
);
458 Insert_After
(Last
(Decls
), New_Body
);
460 Install_Formals
(Id
);
462 -- Preanalyze the expression for name capture, except in an
463 -- instance, where this has been done during generic analysis,
464 -- and will be redone when analyzing the body.
467 Expr
: constant Node_Id
:= Expression
(Ret
);
470 Set_Parent
(Expr
, Ret
);
472 if not In_Instance
then
473 Preanalyze_Spec_Expression
(Expr
, Etype
(Id
));
481 -- If the return expression is a static constant, we suppress warning
482 -- messages on unused formals, which in most cases will be noise.
484 Set_Is_Trivial_Subprogram
(Defining_Entity
(New_Body
),
485 Is_OK_Static_Expression
(Expr
));
486 end Analyze_Expression_Function
;
488 ----------------------------------------
489 -- Analyze_Extended_Return_Statement --
490 ----------------------------------------
492 procedure Analyze_Extended_Return_Statement
(N
: Node_Id
) is
494 Analyze_Return_Statement
(N
);
495 end Analyze_Extended_Return_Statement
;
497 ----------------------------
498 -- Analyze_Function_Call --
499 ----------------------------
501 procedure Analyze_Function_Call
(N
: Node_Id
) is
502 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
503 Func_Nam
: constant Node_Id
:= Name
(N
);
509 -- A call of the form A.B (X) may be an Ada 2005 call, which is
510 -- rewritten as B (A, X). If the rewriting is successful, the call
511 -- has been analyzed and we just return.
513 if Nkind
(Func_Nam
) = N_Selected_Component
514 and then Name
(N
) /= Func_Nam
515 and then Is_Rewrite_Substitution
(N
)
516 and then Present
(Etype
(N
))
521 -- If error analyzing name, then set Any_Type as result type and return
523 if Etype
(Func_Nam
) = Any_Type
then
524 Set_Etype
(N
, Any_Type
);
528 -- Otherwise analyze the parameters
530 if Present
(Actuals
) then
531 Actual
:= First
(Actuals
);
532 while Present
(Actual
) loop
534 Check_Parameterless_Call
(Actual
);
540 end Analyze_Function_Call
;
542 -----------------------------
543 -- Analyze_Function_Return --
544 -----------------------------
546 procedure Analyze_Function_Return
(N
: Node_Id
) is
547 Loc
: constant Source_Ptr
:= Sloc
(N
);
548 Stm_Entity
: constant Entity_Id
:= Return_Statement_Entity
(N
);
549 Scope_Id
: constant Entity_Id
:= Return_Applies_To
(Stm_Entity
);
551 R_Type
: constant Entity_Id
:= Etype
(Scope_Id
);
552 -- Function result subtype
554 procedure Check_Limited_Return
(Expr
: Node_Id
);
555 -- Check the appropriate (Ada 95 or Ada 2005) rules for returning
556 -- limited types. Used only for simple return statements.
557 -- Expr is the expression returned.
559 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
);
560 -- Check that the return_subtype_indication properly matches the result
561 -- subtype of the function, as required by RM-6.5(5.1/2-5.3/2).
563 --------------------------
564 -- Check_Limited_Return --
565 --------------------------
567 procedure Check_Limited_Return
(Expr
: Node_Id
) is
569 -- Ada 2005 (AI-318-02): Return-by-reference types have been
570 -- removed and replaced by anonymous access results. This is an
571 -- incompatibility with Ada 95. Not clear whether this should be
572 -- enforced yet or perhaps controllable with special switch. ???
574 -- A limited interface that is not immutably limited is OK.
576 if Is_Limited_Interface
(R_Type
)
578 not (Is_Task_Interface
(R_Type
)
579 or else Is_Protected_Interface
(R_Type
)
580 or else Is_Synchronized_Interface
(R_Type
))
584 elsif Is_Limited_Type
(R_Type
)
585 and then not Is_Interface
(R_Type
)
586 and then Comes_From_Source
(N
)
587 and then not In_Instance_Body
588 and then not OK_For_Limited_Init_In_05
(R_Type
, Expr
)
592 if Ada_Version
>= Ada_2005
593 and then not Debug_Flag_Dot_L
594 and then not GNAT_Mode
597 ("(Ada 2005) cannot copy object of a limited type " &
598 "(RM-2005 6.5(5.5/2))", Expr
);
600 if Is_Limited_View
(R_Type
) then
602 ("\return by reference not permitted in Ada 2005", Expr
);
605 -- Warn in Ada 95 mode, to give folks a heads up about this
608 -- In GNAT mode, this is just a warning, to allow it to be
609 -- evilly turned off. Otherwise it is a real error.
611 -- In a generic context, simplify the warning because it makes
612 -- no sense to discuss pass-by-reference or copy.
614 elsif Warn_On_Ada_2005_Compatibility
or GNAT_Mode
then
615 if Inside_A_Generic
then
617 ("return of limited object not permitted in Ada 2005 "
618 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
620 elsif Is_Limited_View
(R_Type
) then
622 ("return by reference not permitted in Ada 2005 "
623 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
626 ("cannot copy object of a limited type in Ada 2005 "
627 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
630 -- Ada 95 mode, compatibility warnings disabled
633 return; -- skip continuation messages below
636 if not Inside_A_Generic
then
638 ("\consider switching to return of access type", Expr
);
639 Explain_Limited_Type
(R_Type
, Expr
);
642 end Check_Limited_Return
;
644 -------------------------------------
645 -- Check_Return_Subtype_Indication --
646 -------------------------------------
648 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
) is
649 Return_Obj
: constant Node_Id
:= Defining_Identifier
(Obj_Decl
);
651 R_Stm_Type
: constant Entity_Id
:= Etype
(Return_Obj
);
652 -- Subtype given in the extended return statement (must match R_Type)
654 Subtype_Ind
: constant Node_Id
:=
655 Object_Definition
(Original_Node
(Obj_Decl
));
657 R_Type_Is_Anon_Access
:
659 Ekind
(R_Type
) = E_Anonymous_Access_Subprogram_Type
661 Ekind
(R_Type
) = E_Anonymous_Access_Protected_Subprogram_Type
663 Ekind
(R_Type
) = E_Anonymous_Access_Type
;
664 -- True if return type of the function is an anonymous access type
665 -- Can't we make Is_Anonymous_Access_Type in einfo ???
667 R_Stm_Type_Is_Anon_Access
:
669 Ekind
(R_Stm_Type
) = E_Anonymous_Access_Subprogram_Type
671 Ekind
(R_Stm_Type
) = E_Anonymous_Access_Protected_Subprogram_Type
673 Ekind
(R_Stm_Type
) = E_Anonymous_Access_Type
;
674 -- True if type of the return object is an anonymous access type
677 -- First, avoid cascaded errors
679 if Error_Posted
(Obj_Decl
) or else Error_Posted
(Subtype_Ind
) then
683 -- "return access T" case; check that the return statement also has
684 -- "access T", and that the subtypes statically match:
685 -- if this is an access to subprogram the signatures must match.
687 if R_Type_Is_Anon_Access
then
688 if R_Stm_Type_Is_Anon_Access
then
690 Ekind
(Designated_Type
(R_Stm_Type
)) /= E_Subprogram_Type
692 if Base_Type
(Designated_Type
(R_Stm_Type
)) /=
693 Base_Type
(Designated_Type
(R_Type
))
694 or else not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
)
697 ("subtype must statically match function result subtype",
698 Subtype_Mark
(Subtype_Ind
));
702 -- For two anonymous access to subprogram types, the
703 -- types themselves must be type conformant.
705 if not Conforming_Types
706 (R_Stm_Type
, R_Type
, Fully_Conformant
)
709 ("subtype must statically match function result subtype",
715 Error_Msg_N
("must use anonymous access type", Subtype_Ind
);
718 -- If the return object is of an anonymous access type, then report
719 -- an error if the function's result type is not also anonymous.
721 elsif R_Stm_Type_Is_Anon_Access
722 and then not R_Type_Is_Anon_Access
724 Error_Msg_N
("anonymous access not allowed for function with " &
725 "named access result", Subtype_Ind
);
727 -- Subtype indication case: check that the return object's type is
728 -- covered by the result type, and that the subtypes statically match
729 -- when the result subtype is constrained. Also handle record types
730 -- with unknown discriminants for which we have built the underlying
731 -- record view. Coverage is needed to allow specific-type return
732 -- objects when the result type is class-wide (see AI05-32).
734 elsif Covers
(Base_Type
(R_Type
), Base_Type
(R_Stm_Type
))
735 or else (Is_Underlying_Record_View
(Base_Type
(R_Stm_Type
))
739 Underlying_Record_View
(Base_Type
(R_Stm_Type
))))
741 -- A null exclusion may be present on the return type, on the
742 -- function specification, on the object declaration or on the
745 if Is_Access_Type
(R_Type
)
747 (Can_Never_Be_Null
(R_Type
)
748 or else Null_Exclusion_Present
(Parent
(Scope_Id
))) /=
749 Can_Never_Be_Null
(R_Stm_Type
)
752 ("subtype must statically match function result subtype",
756 -- AI05-103: for elementary types, subtypes must statically match
758 if Is_Constrained
(R_Type
)
759 or else Is_Access_Type
(R_Type
)
761 if not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
) then
763 ("subtype must statically match function result subtype",
768 elsif Etype
(Base_Type
(R_Type
)) = R_Stm_Type
769 and then Is_Null_Extension
(Base_Type
(R_Type
))
775 ("wrong type for return_subtype_indication", Subtype_Ind
);
777 end Check_Return_Subtype_Indication
;
779 ---------------------
780 -- Local Variables --
781 ---------------------
785 -- Start of processing for Analyze_Function_Return
788 Set_Return_Present
(Scope_Id
);
790 if Nkind
(N
) = N_Simple_Return_Statement
then
791 Expr
:= Expression
(N
);
793 -- Guard against a malformed expression. The parser may have tried to
794 -- recover but the node is not analyzable.
796 if Nkind
(Expr
) = N_Error
then
797 Set_Etype
(Expr
, Any_Type
);
798 Expander_Mode_Save_And_Set
(False);
802 -- The resolution of a controlled [extension] aggregate associated
803 -- with a return statement creates a temporary which needs to be
804 -- finalized on function exit. Wrap the return statement inside a
805 -- block so that the finalization machinery can detect this case.
806 -- This early expansion is done only when the return statement is
807 -- not part of a handled sequence of statements.
809 if Nkind_In
(Expr
, N_Aggregate
,
810 N_Extension_Aggregate
)
811 and then Needs_Finalization
(R_Type
)
812 and then Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
815 Make_Block_Statement
(Loc
,
816 Handled_Statement_Sequence
=>
817 Make_Handled_Sequence_Of_Statements
(Loc
,
818 Statements
=> New_List
(Relocate_Node
(N
)))));
824 Analyze_And_Resolve
(Expr
, R_Type
);
825 Check_Limited_Return
(Expr
);
828 -- RETURN only allowed in SPARK as the last statement in function
830 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
832 (Nkind
(Parent
(Parent
(N
))) /= N_Subprogram_Body
833 or else Present
(Next
(N
)))
835 Check_SPARK_Restriction
836 ("RETURN should be the last statement in function", N
);
840 Check_SPARK_Restriction
("extended RETURN is not allowed", N
);
842 -- Analyze parts specific to extended_return_statement:
845 Obj_Decl
: constant Node_Id
:=
846 Last
(Return_Object_Declarations
(N
));
847 Has_Aliased
: constant Boolean := Aliased_Present
(Obj_Decl
);
848 HSS
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
851 Expr
:= Expression
(Obj_Decl
);
853 -- Note: The check for OK_For_Limited_Init will happen in
854 -- Analyze_Object_Declaration; we treat it as a normal
855 -- object declaration.
857 Set_Is_Return_Object
(Defining_Identifier
(Obj_Decl
));
860 Check_Return_Subtype_Indication
(Obj_Decl
);
862 if Present
(HSS
) then
865 if Present
(Exception_Handlers
(HSS
)) then
867 -- ???Has_Nested_Block_With_Handler needs to be set.
868 -- Probably by creating an actual N_Block_Statement.
869 -- Probably in Expand.
875 -- Mark the return object as referenced, since the return is an
876 -- implicit reference of the object.
878 Set_Referenced
(Defining_Identifier
(Obj_Decl
));
880 Check_References
(Stm_Entity
);
882 -- Check RM 6.5 (5.9/3)
885 if Ada_Version
< Ada_2012
then
887 -- Shouldn't this test Warn_On_Ada_2012_Compatibility ???
888 -- Can it really happen (extended return???)
891 ("aliased only allowed for limited"
892 & " return objects in Ada 2012?", N
);
894 elsif not Is_Limited_View
(R_Type
) then
895 Error_Msg_N
("aliased only allowed for limited"
896 & " return objects", N
);
902 -- Case of Expr present
906 -- Defend against previous errors
908 and then Nkind
(Expr
) /= N_Empty
909 and then Present
(Etype
(Expr
))
911 -- Apply constraint check. Note that this is done before the implicit
912 -- conversion of the expression done for anonymous access types to
913 -- ensure correct generation of the null-excluding check associated
914 -- with null-excluding expressions found in return statements.
916 Apply_Constraint_Check
(Expr
, R_Type
);
918 -- Ada 2005 (AI-318-02): When the result type is an anonymous access
919 -- type, apply an implicit conversion of the expression to that type
920 -- to force appropriate static and run-time accessibility checks.
922 if Ada_Version
>= Ada_2005
923 and then Ekind
(R_Type
) = E_Anonymous_Access_Type
925 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
926 Analyze_And_Resolve
(Expr
, R_Type
);
928 -- If this is a local anonymous access to subprogram, the
929 -- accessibility check can be applied statically. The return is
930 -- illegal if the access type of the return expression is declared
931 -- inside of the subprogram (except if it is the subtype indication
932 -- of an extended return statement).
934 elsif Ekind
(R_Type
) = E_Anonymous_Access_Subprogram_Type
then
935 if not Comes_From_Source
(Current_Scope
)
936 or else Ekind
(Current_Scope
) = E_Return_Statement
941 Scope_Depth
(Scope
(Etype
(Expr
))) >= Scope_Depth
(Scope_Id
)
943 Error_Msg_N
("cannot return local access to subprogram", N
);
947 -- If the result type is class-wide, then check that the return
948 -- expression's type is not declared at a deeper level than the
949 -- function (RM05-6.5(5.6/2)).
951 if Ada_Version
>= Ada_2005
952 and then Is_Class_Wide_Type
(R_Type
)
954 if Type_Access_Level
(Etype
(Expr
)) >
955 Subprogram_Access_Level
(Scope_Id
)
958 ("level of return expression type is deeper than " &
959 "class-wide function!", Expr
);
963 -- Check incorrect use of dynamically tagged expression
965 if Is_Tagged_Type
(R_Type
) then
966 Check_Dynamically_Tagged_Expression
972 -- ??? A real run-time accessibility check is needed in cases
973 -- involving dereferences of access parameters. For now we just
974 -- check the static cases.
976 if (Ada_Version
< Ada_2005
or else Debug_Flag_Dot_L
)
977 and then Is_Limited_View
(Etype
(Scope_Id
))
978 and then Object_Access_Level
(Expr
) >
979 Subprogram_Access_Level
(Scope_Id
)
981 -- Suppress the message in a generic, where the rewriting
984 if Inside_A_Generic
then
989 Make_Raise_Program_Error
(Loc
,
990 Reason
=> PE_Accessibility_Check_Failed
));
993 Error_Msg_Warn
:= SPARK_Mode
/= On
;
994 Error_Msg_N
("cannot return a local value by reference<<", N
);
995 Error_Msg_NE
("\& [<<", N
, Standard_Program_Error
);
1000 and then Nkind
(Parent
(Scope_Id
)) = N_Function_Specification
1001 and then Null_Exclusion_Present
(Parent
(Scope_Id
))
1003 Apply_Compile_Time_Constraint_Error
1005 Msg
=> "(Ada 2005) null not allowed for "
1006 & "null-excluding return??",
1007 Reason
=> CE_Null_Not_Allowed
);
1010 end Analyze_Function_Return
;
1012 -------------------------------------
1013 -- Analyze_Generic_Subprogram_Body --
1014 -------------------------------------
1016 procedure Analyze_Generic_Subprogram_Body
1020 Gen_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Gen_Id
);
1021 Kind
: constant Entity_Kind
:= Ekind
(Gen_Id
);
1022 Body_Id
: Entity_Id
;
1027 -- Copy body and disable expansion while analyzing the generic For a
1028 -- stub, do not copy the stub (which would load the proper body), this
1029 -- will be done when the proper body is analyzed.
1031 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1032 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
1037 Spec
:= Specification
(N
);
1039 -- Within the body of the generic, the subprogram is callable, and
1040 -- behaves like the corresponding non-generic unit.
1042 Body_Id
:= Defining_Entity
(Spec
);
1044 if Kind
= E_Generic_Procedure
1045 and then Nkind
(Spec
) /= N_Procedure_Specification
1047 Error_Msg_N
("invalid body for generic procedure ", Body_Id
);
1050 elsif Kind
= E_Generic_Function
1051 and then Nkind
(Spec
) /= N_Function_Specification
1053 Error_Msg_N
("invalid body for generic function ", Body_Id
);
1057 Set_Corresponding_Body
(Gen_Decl
, Body_Id
);
1059 if Has_Completion
(Gen_Id
)
1060 and then Nkind
(Parent
(N
)) /= N_Subunit
1062 Error_Msg_N
("duplicate generic body", N
);
1065 Set_Has_Completion
(Gen_Id
);
1068 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1069 Set_Ekind
(Defining_Entity
(Specification
(N
)), Kind
);
1071 Set_Corresponding_Spec
(N
, Gen_Id
);
1074 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1075 Set_Cunit_Entity
(Current_Sem_Unit
, Defining_Entity
(N
));
1078 -- Make generic parameters immediately visible in the body. They are
1079 -- needed to process the formals declarations. Then make the formals
1080 -- visible in a separate step.
1082 Push_Scope
(Gen_Id
);
1086 First_Ent
: Entity_Id
;
1089 First_Ent
:= First_Entity
(Gen_Id
);
1092 while Present
(E
) and then not Is_Formal
(E
) loop
1097 Set_Use
(Generic_Formal_Declarations
(Gen_Decl
));
1099 -- Now generic formals are visible, and the specification can be
1100 -- analyzed, for subsequent conformance check.
1102 Body_Id
:= Analyze_Subprogram_Specification
(Spec
);
1104 -- Make formal parameters visible
1108 -- E is the first formal parameter, we loop through the formals
1109 -- installing them so that they will be visible.
1111 Set_First_Entity
(Gen_Id
, E
);
1112 while Present
(E
) loop
1118 -- Visible generic entity is callable within its own body
1120 Set_Ekind
(Gen_Id
, Ekind
(Body_Id
));
1121 Set_Contract
(Body_Id
, Make_Contract
(Sloc
(Body_Id
)));
1122 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
1123 Set_Convention
(Body_Id
, Convention
(Gen_Id
));
1124 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Gen_Id
));
1125 Set_Scope
(Body_Id
, Scope
(Gen_Id
));
1126 Check_Fully_Conformant
(Body_Id
, Gen_Id
, Body_Id
);
1128 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1130 -- No body to analyze, so restore state of generic unit
1132 Set_Ekind
(Gen_Id
, Kind
);
1133 Set_Ekind
(Body_Id
, Kind
);
1135 if Present
(First_Ent
) then
1136 Set_First_Entity
(Gen_Id
, First_Ent
);
1143 -- If this is a compilation unit, it must be made visible explicitly,
1144 -- because the compilation of the declaration, unlike other library
1145 -- unit declarations, does not. If it is not a unit, the following
1146 -- is redundant but harmless.
1148 Set_Is_Immediately_Visible
(Gen_Id
);
1149 Reference_Body_Formals
(Gen_Id
, Body_Id
);
1151 if Is_Child_Unit
(Gen_Id
) then
1152 Generate_Reference
(Gen_Id
, Scope
(Gen_Id
), 'k', False);
1155 Set_Actual_Subtypes
(N
, Current_Scope
);
1157 -- Deal with [refined] preconditions, postconditions, Contract_Cases,
1158 -- invariants and predicates associated with the body and its spec.
1159 -- Note that this is not pure expansion as Expand_Subprogram_Contract
1160 -- prepares the contract assertions for generic subprograms or for
1161 -- ASIS. Do not generate contract checks in SPARK mode.
1163 if not GNATprove_Mode
then
1164 Expand_Subprogram_Contract
(N
, Gen_Id
, Body_Id
);
1167 -- If the generic unit carries pre- or post-conditions, copy them
1168 -- to the original generic tree, so that they are properly added
1169 -- to any instantiation.
1172 Orig
: constant Node_Id
:= Original_Node
(N
);
1176 Cond
:= First
(Declarations
(N
));
1177 while Present
(Cond
) loop
1178 if Nkind
(Cond
) = N_Pragma
1179 and then Pragma_Name
(Cond
) = Name_Check
1181 Prepend
(New_Copy_Tree
(Cond
), Declarations
(Orig
));
1183 elsif Nkind
(Cond
) = N_Pragma
1184 and then Pragma_Name
(Cond
) = Name_Postcondition
1186 Set_Ekind
(Defining_Entity
(Orig
), Ekind
(Gen_Id
));
1187 Prepend
(New_Copy_Tree
(Cond
), Declarations
(Orig
));
1196 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
1197 Set_SPARK_Pragma_Inherited
(Body_Id
, True);
1199 Analyze_Declarations
(Declarations
(N
));
1201 Analyze
(Handled_Statement_Sequence
(N
));
1203 Save_Global_References
(Original_Node
(N
));
1205 -- Prior to exiting the scope, include generic formals again (if any
1206 -- are present) in the set of local entities.
1208 if Present
(First_Ent
) then
1209 Set_First_Entity
(Gen_Id
, First_Ent
);
1212 Check_References
(Gen_Id
);
1215 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Current_Scope
);
1217 Check_Subprogram_Order
(N
);
1219 -- Outside of its body, unit is generic again
1221 Set_Ekind
(Gen_Id
, Kind
);
1222 Generate_Reference
(Gen_Id
, Body_Id
, 'b', Set_Ref
=> False);
1225 Style
.Check_Identifier
(Body_Id
, Gen_Id
);
1229 end Analyze_Generic_Subprogram_Body
;
1231 ----------------------------
1232 -- Analyze_Null_Procedure --
1233 ----------------------------
1235 procedure Analyze_Null_Procedure
1237 Is_Completion
: out Boolean)
1239 Loc
: constant Source_Ptr
:= Sloc
(N
);
1240 Spec
: constant Node_Id
:= Specification
(N
);
1241 Designator
: Entity_Id
;
1243 Null_Body
: Node_Id
:= Empty
;
1247 -- Capture the profile of the null procedure before analysis, for
1248 -- expansion at the freeze point and at each point of call. The body is
1249 -- used if the procedure has preconditions, or if it is a completion. In
1250 -- the first case the body is analyzed at the freeze point, in the other
1251 -- it replaces the null procedure declaration.
1254 Make_Subprogram_Body
(Loc
,
1255 Specification
=> New_Copy_Tree
(Spec
),
1256 Declarations
=> New_List
,
1257 Handled_Statement_Sequence
=>
1258 Make_Handled_Sequence_Of_Statements
(Loc
,
1259 Statements
=> New_List
(Make_Null_Statement
(Loc
))));
1261 -- Create new entities for body and formals
1263 Set_Defining_Unit_Name
(Specification
(Null_Body
),
1264 Make_Defining_Identifier
(Loc
, Chars
(Defining_Entity
(N
))));
1266 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1267 while Present
(Form
) loop
1268 Set_Defining_Identifier
(Form
,
1269 Make_Defining_Identifier
(Loc
, Chars
(Defining_Identifier
(Form
))));
1273 -- Determine whether the null procedure may be a completion of a generic
1274 -- suprogram, in which case we use the new null body as the completion
1275 -- and set minimal semantic information on the original declaration,
1276 -- which is rewritten as a null statement.
1278 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
1280 if Present
(Prev
) and then Is_Generic_Subprogram
(Prev
) then
1281 Insert_Before
(N
, Null_Body
);
1282 Set_Ekind
(Defining_Entity
(N
), Ekind
(Prev
));
1283 Set_Contract
(Defining_Entity
(N
), Make_Contract
(Loc
));
1285 Rewrite
(N
, Make_Null_Statement
(Loc
));
1286 Analyze_Generic_Subprogram_Body
(Null_Body
, Prev
);
1287 Is_Completion
:= True;
1291 -- Resolve the types of the formals now, because the freeze point
1292 -- may appear in a different context, e.g. an instantiation.
1294 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1295 while Present
(Form
) loop
1296 if Nkind
(Parameter_Type
(Form
)) /= N_Access_Definition
then
1297 Find_Type
(Parameter_Type
(Form
));
1300 No
(Access_To_Subprogram_Definition
(Parameter_Type
(Form
)))
1302 Find_Type
(Subtype_Mark
(Parameter_Type
(Form
)));
1305 -- The case of a null procedure with a formal that is an
1306 -- access_to_subprogram type, and that is used as an actual
1307 -- in an instantiation is left to the enthusiastic reader.
1316 -- If there are previous overloadable entities with the same name,
1317 -- check whether any of them is completed by the null procedure.
1319 if Present
(Prev
) and then Is_Overloadable
(Prev
) then
1320 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1321 Prev
:= Find_Corresponding_Spec
(N
);
1324 if No
(Prev
) or else not Comes_From_Source
(Prev
) then
1325 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1326 Set_Has_Completion
(Designator
);
1328 -- Signal to caller that this is a procedure declaration
1330 Is_Completion
:= False;
1332 -- Null procedures are always inlined, but generic formal subprograms
1333 -- which appear as such in the internal instance of formal packages,
1334 -- need no completion and are not marked Inline.
1337 and then Nkind
(N
) /= N_Formal_Concrete_Subprogram_Declaration
1339 Set_Corresponding_Body
(N
, Defining_Entity
(Null_Body
));
1340 Set_Body_To_Inline
(N
, Null_Body
);
1341 Set_Is_Inlined
(Designator
);
1345 -- The null procedure is a completion
1347 Is_Completion
:= True;
1349 if Expander_Active
then
1350 Rewrite
(N
, Null_Body
);
1354 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1355 Set_Has_Completion
(Designator
);
1356 Set_Has_Completion
(Prev
);
1359 end Analyze_Null_Procedure
;
1361 -----------------------------
1362 -- Analyze_Operator_Symbol --
1363 -----------------------------
1365 -- An operator symbol such as "+" or "and" may appear in context where the
1366 -- literal denotes an entity name, such as "+"(x, y) or in context when it
1367 -- is just a string, as in (conjunction = "or"). In these cases the parser
1368 -- generates this node, and the semantics does the disambiguation. Other
1369 -- such case are actuals in an instantiation, the generic unit in an
1370 -- instantiation, and pragma arguments.
1372 procedure Analyze_Operator_Symbol
(N
: Node_Id
) is
1373 Par
: constant Node_Id
:= Parent
(N
);
1376 if (Nkind
(Par
) = N_Function_Call
and then N
= Name
(Par
))
1377 or else Nkind
(Par
) = N_Function_Instantiation
1378 or else (Nkind
(Par
) = N_Indexed_Component
and then N
= Prefix
(Par
))
1379 or else (Nkind
(Par
) = N_Pragma_Argument_Association
1380 and then not Is_Pragma_String_Literal
(Par
))
1381 or else Nkind
(Par
) = N_Subprogram_Renaming_Declaration
1382 or else (Nkind
(Par
) = N_Attribute_Reference
1383 and then Attribute_Name
(Par
) /= Name_Value
)
1385 Find_Direct_Name
(N
);
1388 Change_Operator_Symbol_To_String_Literal
(N
);
1391 end Analyze_Operator_Symbol
;
1393 -----------------------------------
1394 -- Analyze_Parameter_Association --
1395 -----------------------------------
1397 procedure Analyze_Parameter_Association
(N
: Node_Id
) is
1399 Analyze
(Explicit_Actual_Parameter
(N
));
1400 end Analyze_Parameter_Association
;
1402 ----------------------------
1403 -- Analyze_Procedure_Call --
1404 ----------------------------
1406 procedure Analyze_Procedure_Call
(N
: Node_Id
) is
1407 Loc
: constant Source_Ptr
:= Sloc
(N
);
1408 P
: constant Node_Id
:= Name
(N
);
1409 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
1413 procedure Analyze_Call_And_Resolve
;
1414 -- Do Analyze and Resolve calls for procedure call
1415 -- At end, check illegal order dependence.
1417 ------------------------------
1418 -- Analyze_Call_And_Resolve --
1419 ------------------------------
1421 procedure Analyze_Call_And_Resolve
is
1423 if Nkind
(N
) = N_Procedure_Call_Statement
then
1425 Resolve
(N
, Standard_Void_Type
);
1429 end Analyze_Call_And_Resolve
;
1431 -- Start of processing for Analyze_Procedure_Call
1434 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
1435 -- a procedure call or an entry call. The prefix may denote an access
1436 -- to subprogram type, in which case an implicit dereference applies.
1437 -- If the prefix is an indexed component (without implicit dereference)
1438 -- then the construct denotes a call to a member of an entire family.
1439 -- If the prefix is a simple name, it may still denote a call to a
1440 -- parameterless member of an entry family. Resolution of these various
1441 -- interpretations is delicate.
1445 -- If this is a call of the form Obj.Op, the call may have been
1446 -- analyzed and possibly rewritten into a block, in which case
1449 if Analyzed
(N
) then
1453 -- If there is an error analyzing the name (which may have been
1454 -- rewritten if the original call was in prefix notation) then error
1455 -- has been emitted already, mark node and return.
1457 if Error_Posted
(N
) or else Etype
(Name
(N
)) = Any_Type
then
1458 Set_Etype
(N
, Any_Type
);
1462 -- Otherwise analyze the parameters
1464 if Present
(Actuals
) then
1465 Actual
:= First
(Actuals
);
1467 while Present
(Actual
) loop
1469 Check_Parameterless_Call
(Actual
);
1474 -- Special processing for Elab_Spec, Elab_Body and Elab_Subp_Body calls
1476 if Nkind
(P
) = N_Attribute_Reference
1477 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Spec
,
1479 Name_Elab_Subp_Body
)
1481 if Present
(Actuals
) then
1483 ("no parameters allowed for this call", First
(Actuals
));
1487 Set_Etype
(N
, Standard_Void_Type
);
1490 elsif Is_Entity_Name
(P
)
1491 and then Is_Record_Type
(Etype
(Entity
(P
)))
1492 and then Remote_AST_I_Dereference
(P
)
1496 elsif Is_Entity_Name
(P
)
1497 and then Ekind
(Entity
(P
)) /= E_Entry_Family
1499 if Is_Access_Type
(Etype
(P
))
1500 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1501 and then No
(Actuals
)
1502 and then Comes_From_Source
(N
)
1504 Error_Msg_N
("missing explicit dereference in call", N
);
1507 Analyze_Call_And_Resolve
;
1509 -- If the prefix is the simple name of an entry family, this is
1510 -- a parameterless call from within the task body itself.
1512 elsif Is_Entity_Name
(P
)
1513 and then Nkind
(P
) = N_Identifier
1514 and then Ekind
(Entity
(P
)) = E_Entry_Family
1515 and then Present
(Actuals
)
1516 and then No
(Next
(First
(Actuals
)))
1518 -- Can be call to parameterless entry family. What appears to be the
1519 -- sole argument is in fact the entry index. Rewrite prefix of node
1520 -- accordingly. Source representation is unchanged by this
1524 Make_Indexed_Component
(Loc
,
1526 Make_Selected_Component
(Loc
,
1527 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(P
)), Loc
),
1528 Selector_Name
=> New_Occurrence_Of
(Entity
(P
), Loc
)),
1529 Expressions
=> Actuals
);
1530 Set_Name
(N
, New_N
);
1531 Set_Etype
(New_N
, Standard_Void_Type
);
1532 Set_Parameter_Associations
(N
, No_List
);
1533 Analyze_Call_And_Resolve
;
1535 elsif Nkind
(P
) = N_Explicit_Dereference
then
1536 if Ekind
(Etype
(P
)) = E_Subprogram_Type
then
1537 Analyze_Call_And_Resolve
;
1539 Error_Msg_N
("expect access to procedure in call", P
);
1542 -- The name can be a selected component or an indexed component that
1543 -- yields an access to subprogram. Such a prefix is legal if the call
1544 -- has parameter associations.
1546 elsif Is_Access_Type
(Etype
(P
))
1547 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1549 if Present
(Actuals
) then
1550 Analyze_Call_And_Resolve
;
1552 Error_Msg_N
("missing explicit dereference in call ", N
);
1555 -- If not an access to subprogram, then the prefix must resolve to the
1556 -- name of an entry, entry family, or protected operation.
1558 -- For the case of a simple entry call, P is a selected component where
1559 -- the prefix is the task and the selector name is the entry. A call to
1560 -- a protected procedure will have the same syntax. If the protected
1561 -- object contains overloaded operations, the entity may appear as a
1562 -- function, the context will select the operation whose type is Void.
1564 elsif Nkind
(P
) = N_Selected_Component
1565 and then Ekind_In
(Entity
(Selector_Name
(P
)), E_Entry
,
1569 Analyze_Call_And_Resolve
;
1571 elsif Nkind
(P
) = N_Selected_Component
1572 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
1573 and then Present
(Actuals
)
1574 and then No
(Next
(First
(Actuals
)))
1576 -- Can be call to parameterless entry family. What appears to be the
1577 -- sole argument is in fact the entry index. Rewrite prefix of node
1578 -- accordingly. Source representation is unchanged by this
1582 Make_Indexed_Component
(Loc
,
1583 Prefix
=> New_Copy
(P
),
1584 Expressions
=> Actuals
);
1585 Set_Name
(N
, New_N
);
1586 Set_Etype
(New_N
, Standard_Void_Type
);
1587 Set_Parameter_Associations
(N
, No_List
);
1588 Analyze_Call_And_Resolve
;
1590 -- For the case of a reference to an element of an entry family, P is
1591 -- an indexed component whose prefix is a selected component (task and
1592 -- entry family), and whose index is the entry family index.
1594 elsif Nkind
(P
) = N_Indexed_Component
1595 and then Nkind
(Prefix
(P
)) = N_Selected_Component
1596 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) = E_Entry_Family
1598 Analyze_Call_And_Resolve
;
1600 -- If the prefix is the name of an entry family, it is a call from
1601 -- within the task body itself.
1603 elsif Nkind
(P
) = N_Indexed_Component
1604 and then Nkind
(Prefix
(P
)) = N_Identifier
1605 and then Ekind
(Entity
(Prefix
(P
))) = E_Entry_Family
1608 Make_Selected_Component
(Loc
,
1609 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(Prefix
(P
))), Loc
),
1610 Selector_Name
=> New_Occurrence_Of
(Entity
(Prefix
(P
)), Loc
));
1611 Rewrite
(Prefix
(P
), New_N
);
1613 Analyze_Call_And_Resolve
;
1615 -- In Ada 2012. a qualified expression is a name, but it cannot be a
1616 -- procedure name, so the construct can only be a qualified expression.
1618 elsif Nkind
(P
) = N_Qualified_Expression
1619 and then Ada_Version
>= Ada_2012
1621 Rewrite
(N
, Make_Code_Statement
(Loc
, Expression
=> P
));
1624 -- Anything else is an error
1627 Error_Msg_N
("invalid procedure or entry call", N
);
1629 end Analyze_Procedure_Call
;
1631 ------------------------------
1632 -- Analyze_Return_Statement --
1633 ------------------------------
1635 procedure Analyze_Return_Statement
(N
: Node_Id
) is
1637 pragma Assert
(Nkind_In
(N
, N_Simple_Return_Statement
,
1638 N_Extended_Return_Statement
));
1640 Returns_Object
: constant Boolean :=
1641 Nkind
(N
) = N_Extended_Return_Statement
1643 (Nkind
(N
) = N_Simple_Return_Statement
1644 and then Present
(Expression
(N
)));
1645 -- True if we're returning something; that is, "return <expression>;"
1646 -- or "return Result : T [:= ...]". False for "return;". Used for error
1647 -- checking: If Returns_Object is True, N should apply to a function
1648 -- body; otherwise N should apply to a procedure body, entry body,
1649 -- accept statement, or extended return statement.
1651 function Find_What_It_Applies_To
return Entity_Id
;
1652 -- Find the entity representing the innermost enclosing body, accept
1653 -- statement, or extended return statement. If the result is a callable
1654 -- construct or extended return statement, then this will be the value
1655 -- of the Return_Applies_To attribute. Otherwise, the program is
1656 -- illegal. See RM-6.5(4/2).
1658 -----------------------------
1659 -- Find_What_It_Applies_To --
1660 -----------------------------
1662 function Find_What_It_Applies_To
return Entity_Id
is
1663 Result
: Entity_Id
:= Empty
;
1666 -- Loop outward through the Scope_Stack, skipping blocks, loops,
1667 -- and postconditions.
1669 for J
in reverse 0 .. Scope_Stack
.Last
loop
1670 Result
:= Scope_Stack
.Table
(J
).Entity
;
1671 exit when not Ekind_In
(Result
, E_Block
, E_Loop
)
1672 and then Chars
(Result
) /= Name_uPostconditions
;
1675 pragma Assert
(Present
(Result
));
1677 end Find_What_It_Applies_To
;
1679 -- Local declarations
1681 Scope_Id
: constant Entity_Id
:= Find_What_It_Applies_To
;
1682 Kind
: constant Entity_Kind
:= Ekind
(Scope_Id
);
1683 Loc
: constant Source_Ptr
:= Sloc
(N
);
1684 Stm_Entity
: constant Entity_Id
:=
1686 (E_Return_Statement
, Current_Scope
, Loc
, 'R');
1688 -- Start of processing for Analyze_Return_Statement
1691 Set_Return_Statement_Entity
(N
, Stm_Entity
);
1693 Set_Etype
(Stm_Entity
, Standard_Void_Type
);
1694 Set_Return_Applies_To
(Stm_Entity
, Scope_Id
);
1696 -- Place Return entity on scope stack, to simplify enforcement of 6.5
1697 -- (4/2): an inner return statement will apply to this extended return.
1699 if Nkind
(N
) = N_Extended_Return_Statement
then
1700 Push_Scope
(Stm_Entity
);
1703 -- Check that pragma No_Return is obeyed. Don't complain about the
1704 -- implicitly-generated return that is placed at the end.
1706 if No_Return
(Scope_Id
) and then Comes_From_Source
(N
) then
1707 Error_Msg_N
("RETURN statement not allowed (No_Return)", N
);
1710 -- Warn on any unassigned OUT parameters if in procedure
1712 if Ekind
(Scope_Id
) = E_Procedure
then
1713 Warn_On_Unassigned_Out_Parameter
(N
, Scope_Id
);
1716 -- Check that functions return objects, and other things do not
1718 if Kind
= E_Function
or else Kind
= E_Generic_Function
then
1719 if not Returns_Object
then
1720 Error_Msg_N
("missing expression in return from function", N
);
1723 elsif Kind
= E_Procedure
or else Kind
= E_Generic_Procedure
then
1724 if Returns_Object
then
1725 Error_Msg_N
("procedure cannot return value (use function)", N
);
1728 elsif Kind
= E_Entry
or else Kind
= E_Entry_Family
then
1729 if Returns_Object
then
1730 if Is_Protected_Type
(Scope
(Scope_Id
)) then
1731 Error_Msg_N
("entry body cannot return value", N
);
1733 Error_Msg_N
("accept statement cannot return value", N
);
1737 elsif Kind
= E_Return_Statement
then
1739 -- We are nested within another return statement, which must be an
1740 -- extended_return_statement.
1742 if Returns_Object
then
1743 if Nkind
(N
) = N_Extended_Return_Statement
then
1745 ("extended return statement cannot be nested (use `RETURN;`)",
1748 -- Case of a simple return statement with a value inside extended
1749 -- return statement.
1753 ("return nested in extended return statement cannot return " &
1754 "value (use `RETURN;`)", N
);
1759 Error_Msg_N
("illegal context for return statement", N
);
1762 if Ekind_In
(Kind
, E_Function
, E_Generic_Function
) then
1763 Analyze_Function_Return
(N
);
1765 elsif Ekind_In
(Kind
, E_Procedure
, E_Generic_Procedure
) then
1766 Set_Return_Present
(Scope_Id
);
1769 if Nkind
(N
) = N_Extended_Return_Statement
then
1773 Kill_Current_Values
(Last_Assignment_Only
=> True);
1774 Check_Unreachable_Code
(N
);
1776 Analyze_Dimension
(N
);
1777 end Analyze_Return_Statement
;
1779 -------------------------------------
1780 -- Analyze_Simple_Return_Statement --
1781 -------------------------------------
1783 procedure Analyze_Simple_Return_Statement
(N
: Node_Id
) is
1785 if Present
(Expression
(N
)) then
1786 Mark_Coextensions
(N
, Expression
(N
));
1789 Analyze_Return_Statement
(N
);
1790 end Analyze_Simple_Return_Statement
;
1792 -------------------------
1793 -- Analyze_Return_Type --
1794 -------------------------
1796 procedure Analyze_Return_Type
(N
: Node_Id
) is
1797 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
1798 Typ
: Entity_Id
:= Empty
;
1801 -- Normal case where result definition does not indicate an error
1803 if Result_Definition
(N
) /= Error
then
1804 if Nkind
(Result_Definition
(N
)) = N_Access_Definition
then
1805 Check_SPARK_Restriction
1806 ("access result is not allowed", Result_Definition
(N
));
1808 -- Ada 2005 (AI-254): Handle anonymous access to subprograms
1811 AD
: constant Node_Id
:=
1812 Access_To_Subprogram_Definition
(Result_Definition
(N
));
1814 if Present
(AD
) and then Protected_Present
(AD
) then
1815 Typ
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
1817 Typ
:= Access_Definition
(N
, Result_Definition
(N
));
1821 Set_Parent
(Typ
, Result_Definition
(N
));
1822 Set_Is_Local_Anonymous_Access
(Typ
);
1823 Set_Etype
(Designator
, Typ
);
1825 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1827 Null_Exclusion_Static_Checks
(N
);
1829 -- Subtype_Mark case
1832 Find_Type
(Result_Definition
(N
));
1833 Typ
:= Entity
(Result_Definition
(N
));
1834 Set_Etype
(Designator
, Typ
);
1836 -- Unconstrained array as result is not allowed in SPARK
1838 if Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
1839 Check_SPARK_Restriction
1840 ("returning an unconstrained array is not allowed",
1841 Result_Definition
(N
));
1844 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1846 Null_Exclusion_Static_Checks
(N
);
1848 -- If a null exclusion is imposed on the result type, then create
1849 -- a null-excluding itype (an access subtype) and use it as the
1850 -- function's Etype. Note that the null exclusion checks are done
1851 -- right before this, because they don't get applied to types that
1852 -- do not come from source.
1854 if Is_Access_Type
(Typ
) and then Null_Exclusion_Present
(N
) then
1855 Set_Etype
(Designator
,
1856 Create_Null_Excluding_Itype
1859 Scope_Id
=> Scope
(Current_Scope
)));
1861 -- The new subtype must be elaborated before use because
1862 -- it is visible outside of the function. However its base
1863 -- type may not be frozen yet, so the reference that will
1864 -- force elaboration must be attached to the freezing of
1867 -- If the return specification appears on a proper body,
1868 -- the subtype will have been created already on the spec.
1870 if Is_Frozen
(Typ
) then
1871 if Nkind
(Parent
(N
)) = N_Subprogram_Body
1872 and then Nkind
(Parent
(Parent
(N
))) = N_Subunit
1876 Build_Itype_Reference
(Etype
(Designator
), Parent
(N
));
1880 Ensure_Freeze_Node
(Typ
);
1883 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(N
));
1885 Set_Itype
(IR
, Etype
(Designator
));
1886 Append_Freeze_Actions
(Typ
, New_List
(IR
));
1891 Set_Etype
(Designator
, Typ
);
1894 if Ekind
(Typ
) = E_Incomplete_Type
1895 and then Is_Value_Type
(Typ
)
1899 elsif Ekind
(Typ
) = E_Incomplete_Type
1900 or else (Is_Class_Wide_Type
(Typ
)
1901 and then Ekind
(Root_Type
(Typ
)) = E_Incomplete_Type
)
1903 -- AI05-0151: Tagged incomplete types are allowed in all formal
1904 -- parts. Untagged incomplete types are not allowed in bodies.
1906 if Ada_Version
>= Ada_2012
then
1907 if Is_Tagged_Type
(Typ
) then
1910 elsif Nkind_In
(Parent
(Parent
(N
)),
1916 ("invalid use of untagged incomplete type&",
1920 -- The type must be completed in the current package. This
1921 -- is checked at the end of the package declaraton, when
1922 -- Taft-amendment types are identified. If the return type
1923 -- is class-wide, there is no required check, the type can
1924 -- be a bona fide TAT.
1926 if Ekind
(Scope
(Current_Scope
)) = E_Package
1927 and then In_Private_Part
(Scope
(Current_Scope
))
1928 and then not Is_Class_Wide_Type
(Typ
)
1930 Append_Elmt
(Designator
, Private_Dependents
(Typ
));
1935 ("invalid use of incomplete type&", Designator
, Typ
);
1940 -- Case where result definition does indicate an error
1943 Set_Etype
(Designator
, Any_Type
);
1945 end Analyze_Return_Type
;
1947 -----------------------------
1948 -- Analyze_Subprogram_Body --
1949 -----------------------------
1951 procedure Analyze_Subprogram_Body
(N
: Node_Id
) is
1952 Loc
: constant Source_Ptr
:= Sloc
(N
);
1953 Body_Spec
: constant Node_Id
:= Specification
(N
);
1954 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Spec
);
1957 if Debug_Flag_C
then
1958 Write_Str
("==> subprogram body ");
1959 Write_Name
(Chars
(Body_Id
));
1960 Write_Str
(" from ");
1961 Write_Location
(Loc
);
1966 Trace_Scope
(N
, Body_Id
, " Analyze subprogram: ");
1968 -- The real work is split out into the helper, so it can do "return;"
1969 -- without skipping the debug output:
1971 Analyze_Subprogram_Body_Helper
(N
);
1973 if Debug_Flag_C
then
1975 Write_Str
("<== subprogram body ");
1976 Write_Name
(Chars
(Body_Id
));
1977 Write_Str
(" from ");
1978 Write_Location
(Loc
);
1981 end Analyze_Subprogram_Body
;
1983 --------------------------------------
1984 -- Analyze_Subprogram_Body_Contract --
1985 --------------------------------------
1987 procedure Analyze_Subprogram_Body_Contract
(Body_Id
: Entity_Id
) is
1988 Body_Decl
: constant Node_Id
:= Parent
(Parent
(Body_Id
));
1989 Spec_Id
: constant Entity_Id
:= Corresponding_Spec
(Body_Decl
);
1991 Ref_Depends
: Node_Id
:= Empty
;
1992 Ref_Global
: Node_Id
:= Empty
;
1995 -- When a subprogram body declaration is erroneous, its defining entity
1996 -- is left unanalyzed. There is nothing left to do in this case because
1997 -- the body lacks a contract.
1999 if not Analyzed
(Body_Id
) then
2003 -- Locate and store pragmas Refined_Depends and Refined_Global since
2004 -- their order of analysis matters.
2006 Prag
:= Classifications
(Contract
(Body_Id
));
2007 while Present
(Prag
) loop
2008 if Pragma_Name
(Prag
) = Name_Refined_Depends
then
2009 Ref_Depends
:= Prag
;
2010 elsif Pragma_Name
(Prag
) = Name_Refined_Global
then
2014 Prag
:= Next_Pragma
(Prag
);
2017 -- Analyze Refined_Global first as Refined_Depends may mention items
2018 -- classified in the global refinement.
2020 if Present
(Ref_Global
) then
2021 Analyze_Refined_Global_In_Decl_Part
(Ref_Global
);
2023 -- When the corresponding Global aspect/pragma references a state with
2024 -- visible refinement, the body requires Refined_Global.
2026 elsif Present
(Spec_Id
) then
2027 Prag
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
2029 if Present
(Prag
) and then Contains_Refined_State
(Prag
) then
2031 ("body of subprogram & requires global refinement",
2032 Body_Decl
, Spec_Id
);
2036 -- Refined_Depends must be analyzed after Refined_Global in order to see
2037 -- the modes of all global refinements.
2039 if Present
(Ref_Depends
) then
2040 Analyze_Refined_Depends_In_Decl_Part
(Ref_Depends
);
2042 -- When the corresponding Depends aspect/pragma references a state with
2043 -- visible refinement, the body requires Refined_Depends.
2045 elsif Present
(Spec_Id
) then
2046 Prag
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
2048 if Present
(Prag
) and then Contains_Refined_State
(Prag
) then
2050 ("body of subprogram & requires dependance refinement",
2051 Body_Decl
, Spec_Id
);
2054 end Analyze_Subprogram_Body_Contract
;
2056 ------------------------------------
2057 -- Analyze_Subprogram_Body_Helper --
2058 ------------------------------------
2060 -- This procedure is called for regular subprogram bodies, generic bodies,
2061 -- and for subprogram stubs of both kinds. In the case of stubs, only the
2062 -- specification matters, and is used to create a proper declaration for
2063 -- the subprogram, or to perform conformance checks.
2065 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
) is
2066 Loc
: constant Source_Ptr
:= Sloc
(N
);
2067 Body_Spec
: constant Node_Id
:= Specification
(N
);
2068 Body_Id
: Entity_Id
:= Defining_Entity
(Body_Spec
);
2069 Prev_Id
: constant Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
2070 Conformant
: Boolean;
2072 Prot_Typ
: Entity_Id
:= Empty
;
2073 Spec_Id
: Entity_Id
;
2074 Spec_Decl
: Node_Id
:= Empty
;
2076 Last_Real_Spec_Entity
: Entity_Id
:= Empty
;
2077 -- When we analyze a separate spec, the entity chain ends up containing
2078 -- the formals, as well as any itypes generated during analysis of the
2079 -- default expressions for parameters, or the arguments of associated
2080 -- precondition/postcondition pragmas (which are analyzed in the context
2081 -- of the spec since they have visibility on formals).
2083 -- These entities belong with the spec and not the body. However we do
2084 -- the analysis of the body in the context of the spec (again to obtain
2085 -- visibility to the formals), and all the entities generated during
2086 -- this analysis end up also chained to the entity chain of the spec.
2087 -- But they really belong to the body, and there is circuitry to move
2088 -- them from the spec to the body.
2090 -- However, when we do this move, we don't want to move the real spec
2091 -- entities (first para above) to the body. The Last_Real_Spec_Entity
2092 -- variable points to the last real spec entity, so we only move those
2093 -- chained beyond that point. It is initialized to Empty to deal with
2094 -- the case where there is no separate spec.
2096 procedure Check_Anonymous_Return
;
2097 -- Ada 2005: if a function returns an access type that denotes a task,
2098 -- or a type that contains tasks, we must create a master entity for
2099 -- the anonymous type, which typically will be used in an allocator
2100 -- in the body of the function.
2102 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
);
2103 -- Look ahead to recognize a pragma that may appear after the body.
2104 -- If there is a previous spec, check that it appears in the same
2105 -- declarative part. If the pragma is Inline_Always, perform inlining
2106 -- unconditionally, otherwise only if Front_End_Inlining is requested.
2107 -- If the body acts as a spec, and inlining is required, we create a
2108 -- subprogram declaration for it, in order to attach the body to inline.
2109 -- If pragma does not appear after the body, check whether there is
2110 -- an inline pragma before any local declarations.
2112 procedure Check_Missing_Return
;
2113 -- Checks for a function with a no return statements, and also performs
2114 -- the warning checks implemented by Check_Returns. In formal mode, also
2115 -- verify that a function ends with a RETURN and that a procedure does
2116 -- not contain any RETURN.
2118 function Disambiguate_Spec
return Entity_Id
;
2119 -- When a primitive is declared between the private view and the full
2120 -- view of a concurrent type which implements an interface, a special
2121 -- mechanism is used to find the corresponding spec of the primitive
2124 procedure Exchange_Limited_Views
(Subp_Id
: Entity_Id
);
2125 -- Ada 2012 (AI05-0151): Detect whether the profile of Subp_Id contains
2126 -- incomplete types coming from a limited context and swap their limited
2127 -- views with the non-limited ones.
2129 function Is_Private_Concurrent_Primitive
2130 (Subp_Id
: Entity_Id
) return Boolean;
2131 -- Determine whether subprogram Subp_Id is a primitive of a concurrent
2132 -- type that implements an interface and has a private view.
2134 procedure Set_Trivial_Subprogram
(N
: Node_Id
);
2135 -- Sets the Is_Trivial_Subprogram flag in both spec and body of the
2136 -- subprogram whose body is being analyzed. N is the statement node
2137 -- causing the flag to be set, if the following statement is a return
2138 -- of an entity, we mark the entity as set in source to suppress any
2139 -- warning on the stylized use of function stubs with a dummy return.
2141 procedure Verify_Overriding_Indicator
;
2142 -- If there was a previous spec, the entity has been entered in the
2143 -- current scope previously. If the body itself carries an overriding
2144 -- indicator, check that it is consistent with the known status of the
2147 ----------------------------
2148 -- Check_Anonymous_Return --
2149 ----------------------------
2151 procedure Check_Anonymous_Return
is
2157 if Present
(Spec_Id
) then
2163 if Ekind
(Scop
) = E_Function
2164 and then Ekind
(Etype
(Scop
)) = E_Anonymous_Access_Type
2165 and then not Is_Thunk
(Scop
)
2166 and then (Has_Task
(Designated_Type
(Etype
(Scop
)))
2168 (Is_Class_Wide_Type
(Designated_Type
(Etype
(Scop
)))
2170 Is_Limited_Record
(Designated_Type
(Etype
(Scop
)))))
2171 and then Expander_Active
2173 -- Avoid cases with no tasking support
2175 and then RTE_Available
(RE_Current_Master
)
2176 and then not Restriction_Active
(No_Task_Hierarchy
)
2179 Make_Object_Declaration
(Loc
,
2180 Defining_Identifier
=>
2181 Make_Defining_Identifier
(Loc
, Name_uMaster
),
2182 Constant_Present
=> True,
2183 Object_Definition
=>
2184 New_Reference_To
(RTE
(RE_Master_Id
), Loc
),
2186 Make_Explicit_Dereference
(Loc
,
2187 New_Reference_To
(RTE
(RE_Current_Master
), Loc
)));
2189 if Present
(Declarations
(N
)) then
2190 Prepend
(Decl
, Declarations
(N
));
2192 Set_Declarations
(N
, New_List
(Decl
));
2195 Set_Master_Id
(Etype
(Scop
), Defining_Identifier
(Decl
));
2196 Set_Has_Master_Entity
(Scop
);
2198 -- Now mark the containing scope as a task master
2201 while Nkind
(Par
) /= N_Compilation_Unit
loop
2202 Par
:= Parent
(Par
);
2203 pragma Assert
(Present
(Par
));
2205 -- If we fall off the top, we are at the outer level, and
2206 -- the environment task is our effective master, so nothing
2210 (Par
, N_Task_Body
, N_Block_Statement
, N_Subprogram_Body
)
2212 Set_Is_Task_Master
(Par
, True);
2217 end Check_Anonymous_Return
;
2219 -------------------------
2220 -- Check_Inline_Pragma --
2221 -------------------------
2223 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
) is
2227 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean;
2228 -- True when N is a pragma Inline or Inline_Always that applies
2229 -- to this subprogram.
2231 -----------------------
2232 -- Is_Inline_Pragma --
2233 -----------------------
2235 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean is
2238 Nkind
(N
) = N_Pragma
2240 (Pragma_Name
(N
) = Name_Inline_Always
2243 and then Pragma_Name
(N
) = Name_Inline
))
2246 (Expression
(First
(Pragma_Argument_Associations
(N
)))) =
2248 end Is_Inline_Pragma
;
2250 -- Start of processing for Check_Inline_Pragma
2253 if not Expander_Active
then
2257 if Is_List_Member
(N
)
2258 and then Present
(Next
(N
))
2259 and then Is_Inline_Pragma
(Next
(N
))
2263 elsif Nkind
(N
) /= N_Subprogram_Body_Stub
2264 and then Present
(Declarations
(N
))
2265 and then Is_Inline_Pragma
(First
(Declarations
(N
)))
2267 Prag
:= First
(Declarations
(N
));
2273 if Present
(Prag
) then
2274 if Present
(Spec_Id
) then
2275 if In_Same_List
(N
, Unit_Declaration_Node
(Spec_Id
)) then
2280 -- Create a subprogram declaration, to make treatment uniform
2283 Subp
: constant Entity_Id
:=
2284 Make_Defining_Identifier
(Loc
, Chars
(Body_Id
));
2285 Decl
: constant Node_Id
:=
2286 Make_Subprogram_Declaration
(Loc
,
2288 New_Copy_Tree
(Specification
(N
)));
2291 Set_Defining_Unit_Name
(Specification
(Decl
), Subp
);
2293 if Present
(First_Formal
(Body_Id
)) then
2294 Plist
:= Copy_Parameter_List
(Body_Id
);
2295 Set_Parameter_Specifications
2296 (Specification
(Decl
), Plist
);
2299 Insert_Before
(N
, Decl
);
2302 Set_Has_Pragma_Inline
(Subp
);
2304 if Pragma_Name
(Prag
) = Name_Inline_Always
then
2305 Set_Is_Inlined
(Subp
);
2306 Set_Has_Pragma_Inline_Always
(Subp
);
2313 end Check_Inline_Pragma
;
2315 --------------------------
2316 -- Check_Missing_Return --
2317 --------------------------
2319 procedure Check_Missing_Return
is
2321 Missing_Ret
: Boolean;
2324 if Nkind
(Body_Spec
) = N_Function_Specification
then
2325 if Present
(Spec_Id
) then
2331 if Return_Present
(Id
) then
2332 Check_Returns
(HSS
, 'F', Missing_Ret
);
2335 Set_Has_Missing_Return
(Id
);
2338 elsif Is_Generic_Subprogram
(Id
)
2339 or else not Is_Machine_Code_Subprogram
(Id
)
2341 Error_Msg_N
("missing RETURN statement in function body", N
);
2344 -- If procedure with No_Return, check returns
2346 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
2347 and then Present
(Spec_Id
)
2348 and then No_Return
(Spec_Id
)
2350 Check_Returns
(HSS
, 'P', Missing_Ret
, Spec_Id
);
2353 -- Special checks in SPARK mode
2355 if Nkind
(Body_Spec
) = N_Function_Specification
then
2357 -- In SPARK mode, last statement of a function should be a return
2360 Stat
: constant Node_Id
:= Last_Source_Statement
(HSS
);
2363 and then not Nkind_In
(Stat
, N_Simple_Return_Statement
,
2364 N_Extended_Return_Statement
)
2366 Check_SPARK_Restriction
2367 ("last statement in function should be RETURN", Stat
);
2371 -- In SPARK mode, verify that a procedure has no return
2373 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
then
2374 if Present
(Spec_Id
) then
2380 -- Would be nice to point to return statement here, can we
2381 -- borrow the Check_Returns procedure here ???
2383 if Return_Present
(Id
) then
2384 Check_SPARK_Restriction
2385 ("procedure should not have RETURN", N
);
2388 end Check_Missing_Return
;
2390 -----------------------
2391 -- Disambiguate_Spec --
2392 -----------------------
2394 function Disambiguate_Spec
return Entity_Id
is
2395 Priv_Spec
: Entity_Id
;
2398 procedure Replace_Types
(To_Corresponding
: Boolean);
2399 -- Depending on the flag, replace the type of formal parameters of
2400 -- Body_Id if it is a concurrent type implementing interfaces with
2401 -- the corresponding record type or the other way around.
2403 procedure Replace_Types
(To_Corresponding
: Boolean) is
2405 Formal_Typ
: Entity_Id
;
2408 Formal
:= First_Formal
(Body_Id
);
2409 while Present
(Formal
) loop
2410 Formal_Typ
:= Etype
(Formal
);
2412 if Is_Class_Wide_Type
(Formal_Typ
) then
2413 Formal_Typ
:= Root_Type
(Formal_Typ
);
2416 -- From concurrent type to corresponding record
2418 if To_Corresponding
then
2419 if Is_Concurrent_Type
(Formal_Typ
)
2420 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
2421 and then Present
(Interfaces
(
2422 Corresponding_Record_Type
(Formal_Typ
)))
2425 Corresponding_Record_Type
(Formal_Typ
));
2428 -- From corresponding record to concurrent type
2431 if Is_Concurrent_Record_Type
(Formal_Typ
)
2432 and then Present
(Interfaces
(Formal_Typ
))
2435 Corresponding_Concurrent_Type
(Formal_Typ
));
2439 Next_Formal
(Formal
);
2443 -- Start of processing for Disambiguate_Spec
2446 -- Try to retrieve the specification of the body as is. All error
2447 -- messages are suppressed because the body may not have a spec in
2448 -- its current state.
2450 Spec_N
:= Find_Corresponding_Spec
(N
, False);
2452 -- It is possible that this is the body of a primitive declared
2453 -- between a private and a full view of a concurrent type. The
2454 -- controlling parameter of the spec carries the concurrent type,
2455 -- not the corresponding record type as transformed by Analyze_
2456 -- Subprogram_Specification. In such cases, we undo the change
2457 -- made by the analysis of the specification and try to find the
2460 -- Note that wrappers already have their corresponding specs and
2461 -- bodies set during their creation, so if the candidate spec is
2462 -- a wrapper, then we definitely need to swap all types to their
2463 -- original concurrent status.
2466 or else Is_Primitive_Wrapper
(Spec_N
)
2468 -- Restore all references of corresponding record types to the
2469 -- original concurrent types.
2471 Replace_Types
(To_Corresponding
=> False);
2472 Priv_Spec
:= Find_Corresponding_Spec
(N
, False);
2474 -- The current body truly belongs to a primitive declared between
2475 -- a private and a full view. We leave the modified body as is,
2476 -- and return the true spec.
2478 if Present
(Priv_Spec
)
2479 and then Is_Private_Primitive
(Priv_Spec
)
2484 -- In case that this is some sort of error, restore the original
2485 -- state of the body.
2487 Replace_Types
(To_Corresponding
=> True);
2491 end Disambiguate_Spec
;
2493 ----------------------------
2494 -- Exchange_Limited_Views --
2495 ----------------------------
2497 procedure Exchange_Limited_Views
(Subp_Id
: Entity_Id
) is
2498 procedure Detect_And_Exchange
(Id
: Entity_Id
);
2499 -- Determine whether Id's type denotes an incomplete type associated
2500 -- with a limited with clause and exchange the limited view with the
2503 -------------------------
2504 -- Detect_And_Exchange --
2505 -------------------------
2507 procedure Detect_And_Exchange
(Id
: Entity_Id
) is
2508 Typ
: constant Entity_Id
:= Etype
(Id
);
2511 if Ekind
(Typ
) = E_Incomplete_Type
2512 and then From_Limited_With
(Typ
)
2513 and then Present
(Non_Limited_View
(Typ
))
2515 Set_Etype
(Id
, Non_Limited_View
(Typ
));
2517 end Detect_And_Exchange
;
2523 -- Start of processing for Exchange_Limited_Views
2526 if No
(Subp_Id
) then
2529 -- Do not process subprogram bodies as they already use the non-
2530 -- limited view of types.
2532 elsif not Ekind_In
(Subp_Id
, E_Function
, E_Procedure
) then
2536 -- Examine all formals and swap views when applicable
2538 Formal
:= First_Formal
(Subp_Id
);
2539 while Present
(Formal
) loop
2540 Detect_And_Exchange
(Formal
);
2542 Next_Formal
(Formal
);
2545 -- Process the return type of a function
2547 if Ekind
(Subp_Id
) = E_Function
then
2548 Detect_And_Exchange
(Subp_Id
);
2550 end Exchange_Limited_Views
;
2552 -------------------------------------
2553 -- Is_Private_Concurrent_Primitive --
2554 -------------------------------------
2556 function Is_Private_Concurrent_Primitive
2557 (Subp_Id
: Entity_Id
) return Boolean
2559 Formal_Typ
: Entity_Id
;
2562 if Present
(First_Formal
(Subp_Id
)) then
2563 Formal_Typ
:= Etype
(First_Formal
(Subp_Id
));
2565 if Is_Concurrent_Record_Type
(Formal_Typ
) then
2566 if Is_Class_Wide_Type
(Formal_Typ
) then
2567 Formal_Typ
:= Root_Type
(Formal_Typ
);
2570 Formal_Typ
:= Corresponding_Concurrent_Type
(Formal_Typ
);
2573 -- The type of the first formal is a concurrent tagged type with
2577 Is_Concurrent_Type
(Formal_Typ
)
2578 and then Is_Tagged_Type
(Formal_Typ
)
2579 and then Has_Private_Declaration
(Formal_Typ
);
2583 end Is_Private_Concurrent_Primitive
;
2585 ----------------------------
2586 -- Set_Trivial_Subprogram --
2587 ----------------------------
2589 procedure Set_Trivial_Subprogram
(N
: Node_Id
) is
2590 Nxt
: constant Node_Id
:= Next
(N
);
2593 Set_Is_Trivial_Subprogram
(Body_Id
);
2595 if Present
(Spec_Id
) then
2596 Set_Is_Trivial_Subprogram
(Spec_Id
);
2600 and then Nkind
(Nxt
) = N_Simple_Return_Statement
2601 and then No
(Next
(Nxt
))
2602 and then Present
(Expression
(Nxt
))
2603 and then Is_Entity_Name
(Expression
(Nxt
))
2605 Set_Never_Set_In_Source
(Entity
(Expression
(Nxt
)), False);
2607 end Set_Trivial_Subprogram
;
2609 ---------------------------------
2610 -- Verify_Overriding_Indicator --
2611 ---------------------------------
2613 procedure Verify_Overriding_Indicator
is
2615 if Must_Override
(Body_Spec
) then
2616 if Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
2617 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
2621 elsif not Present
(Overridden_Operation
(Spec_Id
)) then
2623 ("subprogram& is not overriding", Body_Spec
, Spec_Id
);
2626 elsif Must_Not_Override
(Body_Spec
) then
2627 if Present
(Overridden_Operation
(Spec_Id
)) then
2629 ("subprogram& overrides inherited operation",
2630 Body_Spec
, Spec_Id
);
2632 elsif Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
2633 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
2636 ("subprogram & overrides predefined operator ",
2637 Body_Spec
, Spec_Id
);
2639 -- If this is not a primitive operation or protected subprogram,
2640 -- then the overriding indicator is altogether illegal.
2642 elsif not Is_Primitive
(Spec_Id
)
2643 and then Ekind
(Scope
(Spec_Id
)) /= E_Protected_Type
2646 ("overriding indicator only allowed " &
2647 "if subprogram is primitive",
2652 and then Present
(Overridden_Operation
(Spec_Id
))
2654 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
2655 Style
.Missing_Overriding
(N
, Body_Id
);
2658 and then Can_Override_Operator
(Spec_Id
)
2659 and then not Is_Predefined_File_Name
2660 (Unit_File_Name
(Get_Source_Unit
(Spec_Id
)))
2662 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
2663 Style
.Missing_Overriding
(N
, Body_Id
);
2665 end Verify_Overriding_Indicator
;
2667 -- Start of processing for Analyze_Subprogram_Body_Helper
2670 -- Generic subprograms are handled separately. They always have a
2671 -- generic specification. Determine whether current scope has a
2672 -- previous declaration.
2674 -- If the subprogram body is defined within an instance of the same
2675 -- name, the instance appears as a package renaming, and will be hidden
2676 -- within the subprogram.
2678 if Present
(Prev_Id
)
2679 and then not Is_Overloadable
(Prev_Id
)
2680 and then (Nkind
(Parent
(Prev_Id
)) /= N_Package_Renaming_Declaration
2681 or else Comes_From_Source
(Prev_Id
))
2683 if Is_Generic_Subprogram
(Prev_Id
) then
2685 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
2686 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
2688 Analyze_Generic_Subprogram_Body
(N
, Spec_Id
);
2690 if Nkind
(N
) = N_Subprogram_Body
then
2691 HSS
:= Handled_Statement_Sequence
(N
);
2692 Check_Missing_Return
;
2698 -- Previous entity conflicts with subprogram name. Attempting to
2699 -- enter name will post error.
2701 Enter_Name
(Body_Id
);
2705 -- Non-generic case, find the subprogram declaration, if one was seen,
2706 -- or enter new overloaded entity in the current scope. If the
2707 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
2708 -- part of the context of one of its subunits. No need to redo the
2711 elsif Prev_Id
= Body_Id
and then Has_Completion
(Body_Id
) then
2715 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
2717 if Nkind
(N
) = N_Subprogram_Body_Stub
2718 or else No
(Corresponding_Spec
(N
))
2720 if Is_Private_Concurrent_Primitive
(Body_Id
) then
2721 Spec_Id
:= Disambiguate_Spec
;
2723 Spec_Id
:= Find_Corresponding_Spec
(N
);
2726 -- If this is a duplicate body, no point in analyzing it
2728 if Error_Posted
(N
) then
2732 -- A subprogram body should cause freezing of its own declaration,
2733 -- but if there was no previous explicit declaration, then the
2734 -- subprogram will get frozen too late (there may be code within
2735 -- the body that depends on the subprogram having been frozen,
2736 -- such as uses of extra formals), so we force it to be frozen
2737 -- here. Same holds if the body and spec are compilation units.
2738 -- Finally, if the return type is an anonymous access to protected
2739 -- subprogram, it must be frozen before the body because its
2740 -- expansion has generated an equivalent type that is used when
2741 -- elaborating the body.
2743 -- An exception in the case of Ada 2012, AI05-177: The bodies
2744 -- created for expression functions do not freeze.
2747 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
2749 Freeze_Before
(N
, Body_Id
);
2751 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
2752 Freeze_Before
(N
, Spec_Id
);
2754 elsif Is_Access_Subprogram_Type
(Etype
(Body_Id
)) then
2755 Freeze_Before
(N
, Etype
(Body_Id
));
2759 Spec_Id
:= Corresponding_Spec
(N
);
2763 -- Language-defined aspects cannot appear in a subprogram body [stub] if
2764 -- the subprogram has a separate spec. Certainly implementation-defined
2765 -- aspects are allowed to appear (per Aspects_On_Body_Of_Stub_OK).
2767 if Has_Aspects
(N
) then
2768 if Present
(Spec_Id
)
2769 and then not Aspects_On_Body_Or_Stub_OK
(N
)
2771 -- Do not emit an error on a subprogram body stub that act as
2774 and then Nkind
(Parent
(Parent
(Spec_Id
))) /= N_Subprogram_Body_Stub
2777 ("aspect specifications must appear in subprogram declaration",
2780 -- Delay the analysis of aspect specifications that apply to a body
2781 -- stub until the proper body is analyzed. If the corresponding body
2782 -- is missing, the aspects are still analyzed in Analyze_Proper_Body.
2784 elsif Nkind
(N
) in N_Body_Stub
then
2788 Analyze_Aspect_Specifications
(N
, Body_Id
);
2792 -- Previously we scanned the body to look for nested subprograms, and
2793 -- rejected an inline directive if nested subprograms were present,
2794 -- because the back-end would generate conflicting symbols for the
2795 -- nested bodies. This is now unnecessary.
2797 -- Look ahead to recognize a pragma Inline that appears after the body
2799 Check_Inline_Pragma
(Spec_Id
);
2801 -- Deal with special case of a fully private operation in the body of
2802 -- the protected type. We must create a declaration for the subprogram,
2803 -- in order to attach the protected subprogram that will be used in
2804 -- internal calls. We exclude compiler generated bodies from the
2805 -- expander since the issue does not arise for those cases.
2808 and then Comes_From_Source
(N
)
2809 and then Is_Protected_Type
(Current_Scope
)
2811 Spec_Id
:= Build_Private_Protected_Declaration
(N
);
2814 -- If a separate spec is present, then deal with freezing issues
2816 if Present
(Spec_Id
) then
2817 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
2818 Verify_Overriding_Indicator
;
2820 -- In general, the spec will be frozen when we start analyzing the
2821 -- body. However, for internally generated operations, such as
2822 -- wrapper functions for inherited operations with controlling
2823 -- results, the spec may not have been frozen by the time we expand
2824 -- the freeze actions that include the bodies. In particular, extra
2825 -- formals for accessibility or for return-in-place may need to be
2826 -- generated. Freeze nodes, if any, are inserted before the current
2827 -- body. These freeze actions are also needed in ASIS mode to enable
2828 -- the proper back-annotations.
2830 if not Is_Frozen
(Spec_Id
)
2831 and then (Expander_Active
or ASIS_Mode
)
2833 -- Force the generation of its freezing node to ensure proper
2834 -- management of access types in the backend.
2836 -- This is definitely needed for some cases, but it is not clear
2837 -- why, to be investigated further???
2839 Set_Has_Delayed_Freeze
(Spec_Id
);
2840 Freeze_Before
(N
, Spec_Id
);
2844 -- Mark presence of postcondition procedure in current scope and mark
2845 -- the procedure itself as needing debug info. The latter is important
2846 -- when analyzing decision coverage (for example, for MC/DC coverage).
2848 if Chars
(Body_Id
) = Name_uPostconditions
then
2849 Set_Has_Postconditions
(Current_Scope
);
2850 Set_Debug_Info_Needed
(Body_Id
);
2853 -- Place subprogram on scope stack, and make formals visible. If there
2854 -- is a spec, the visible entity remains that of the spec.
2856 if Present
(Spec_Id
) then
2857 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
2859 if Is_Child_Unit
(Spec_Id
) then
2860 Generate_Reference
(Spec_Id
, Scope
(Spec_Id
), 'k', False);
2864 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
2867 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
2868 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
2870 if Is_Abstract_Subprogram
(Spec_Id
) then
2871 Error_Msg_N
("an abstract subprogram cannot have a body", N
);
2875 Set_Convention
(Body_Id
, Convention
(Spec_Id
));
2876 Set_Has_Completion
(Spec_Id
);
2878 if Is_Protected_Type
(Scope
(Spec_Id
)) then
2879 Prot_Typ
:= Scope
(Spec_Id
);
2882 -- If this is a body generated for a renaming, do not check for
2883 -- full conformance. The check is redundant, because the spec of
2884 -- the body is a copy of the spec in the renaming declaration,
2885 -- and the test can lead to spurious errors on nested defaults.
2887 if Present
(Spec_Decl
)
2888 and then not Comes_From_Source
(N
)
2890 (Nkind
(Original_Node
(Spec_Decl
)) =
2891 N_Subprogram_Renaming_Declaration
2892 or else (Present
(Corresponding_Body
(Spec_Decl
))
2894 Nkind
(Unit_Declaration_Node
2895 (Corresponding_Body
(Spec_Decl
))) =
2896 N_Subprogram_Renaming_Declaration
))
2900 -- Conversely, the spec may have been generated for specless body
2901 -- with an inline pragma.
2903 elsif Comes_From_Source
(N
)
2904 and then not Comes_From_Source
(Spec_Id
)
2905 and then Has_Pragma_Inline
(Spec_Id
)
2912 Fully_Conformant
, True, Conformant
, Body_Id
);
2915 -- If the body is not fully conformant, we have to decide if we
2916 -- should analyze it or not. If it has a really messed up profile
2917 -- then we probably should not analyze it, since we will get too
2918 -- many bogus messages.
2920 -- Our decision is to go ahead in the non-fully conformant case
2921 -- only if it is at least mode conformant with the spec. Note
2922 -- that the call to Check_Fully_Conformant has issued the proper
2923 -- error messages to complain about the lack of conformance.
2926 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
2932 if Spec_Id
/= Body_Id
then
2933 Reference_Body_Formals
(Spec_Id
, Body_Id
);
2936 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
2938 if Nkind
(N
) = N_Subprogram_Body_Stub
then
2939 Set_Corresponding_Spec_Of_Stub
(N
, Spec_Id
);
2944 Set_Corresponding_Spec
(N
, Spec_Id
);
2946 -- Ada 2005 (AI-345): If the operation is a primitive operation
2947 -- of a concurrent type, the type of the first parameter has been
2948 -- replaced with the corresponding record, which is the proper
2949 -- run-time structure to use. However, within the body there may
2950 -- be uses of the formals that depend on primitive operations
2951 -- of the type (in particular calls in prefixed form) for which
2952 -- we need the original concurrent type. The operation may have
2953 -- several controlling formals, so the replacement must be done
2956 if Comes_From_Source
(Spec_Id
)
2957 and then Present
(First_Entity
(Spec_Id
))
2958 and then Ekind
(Etype
(First_Entity
(Spec_Id
))) = E_Record_Type
2959 and then Is_Tagged_Type
(Etype
(First_Entity
(Spec_Id
)))
2960 and then Present
(Interfaces
(Etype
(First_Entity
(Spec_Id
))))
2961 and then Present
(Corresponding_Concurrent_Type
2962 (Etype
(First_Entity
(Spec_Id
))))
2965 Typ
: constant Entity_Id
:= Etype
(First_Entity
(Spec_Id
));
2969 Form
:= First_Formal
(Spec_Id
);
2970 while Present
(Form
) loop
2971 if Etype
(Form
) = Typ
then
2972 Set_Etype
(Form
, Corresponding_Concurrent_Type
(Typ
));
2980 -- Make the formals visible, and place subprogram on scope stack.
2981 -- This is also the point at which we set Last_Real_Spec_Entity
2982 -- to mark the entities which will not be moved to the body.
2984 Install_Formals
(Spec_Id
);
2985 Last_Real_Spec_Entity
:= Last_Entity
(Spec_Id
);
2987 -- Within an instance, add local renaming declarations so that
2988 -- gdb can retrieve the values of actuals more easily. This is
2989 -- only relevant if generating code (and indeed we definitely
2990 -- do not want these definitions -gnatc mode, because that would
2993 if Is_Generic_Instance
(Spec_Id
)
2994 and then Is_Wrapper_Package
(Current_Scope
)
2995 and then Expander_Active
2997 Build_Subprogram_Instance_Renamings
(N
, Current_Scope
);
3000 Push_Scope
(Spec_Id
);
3002 -- Set SPARK_Mode from context
3004 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
3005 Set_SPARK_Pragma_Inherited
(Body_Id
, True);
3007 -- Make sure that the subprogram is immediately visible. For
3008 -- child units that have no separate spec this is indispensable.
3009 -- Otherwise it is safe albeit redundant.
3011 Set_Is_Immediately_Visible
(Spec_Id
);
3014 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
3015 Set_Contract
(Body_Id
, Make_Contract
(Sloc
(Body_Id
)));
3016 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
3017 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Spec_Id
));
3019 -- Case of subprogram body with no previous spec
3022 -- Check for style warning required
3026 -- Only apply check for source level subprograms for which checks
3027 -- have not been suppressed.
3029 and then Comes_From_Source
(Body_Id
)
3030 and then not Suppress_Style_Checks
(Body_Id
)
3032 -- No warnings within an instance
3034 and then not In_Instance
3036 -- No warnings for expression functions
3038 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3040 Style
.Body_With_No_Spec
(N
);
3043 New_Overloaded_Entity
(Body_Id
);
3045 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
3046 Set_Acts_As_Spec
(N
);
3047 Generate_Definition
(Body_Id
);
3048 Set_Contract
(Body_Id
, Make_Contract
(Sloc
(Body_Id
)));
3050 (Body_Id
, Body_Id
, 'b', Set_Ref
=> False, Force
=> True);
3051 Install_Formals
(Body_Id
);
3053 Push_Scope
(Body_Id
);
3055 -- Set SPARK_Mode from context
3057 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
3058 Set_SPARK_Pragma_Inherited
(Body_Id
, True);
3061 -- For stubs and bodies with no previous spec, generate references to
3064 Generate_Reference_To_Formals
(Body_Id
);
3067 -- If the return type is an anonymous access type whose designated type
3068 -- is the limited view of a class-wide type and the non-limited view is
3069 -- available, update the return type accordingly.
3071 if Ada_Version
>= Ada_2005
and then Comes_From_Source
(N
) then
3077 Rtyp
:= Etype
(Current_Scope
);
3079 if Ekind
(Rtyp
) = E_Anonymous_Access_Type
then
3080 Etyp
:= Directly_Designated_Type
(Rtyp
);
3082 if Is_Class_Wide_Type
(Etyp
)
3083 and then From_Limited_With
(Etyp
)
3085 Set_Directly_Designated_Type
3086 (Etype
(Current_Scope
), Available_View
(Etyp
));
3092 -- If this is the proper body of a stub, we must verify that the stub
3093 -- conforms to the body, and to the previous spec if one was present.
3094 -- We know already that the body conforms to that spec. This test is
3095 -- only required for subprograms that come from source.
3097 if Nkind
(Parent
(N
)) = N_Subunit
3098 and then Comes_From_Source
(N
)
3099 and then not Error_Posted
(Body_Id
)
3100 and then Nkind
(Corresponding_Stub
(Parent
(N
))) =
3101 N_Subprogram_Body_Stub
3104 Old_Id
: constant Entity_Id
:=
3106 (Specification
(Corresponding_Stub
(Parent
(N
))));
3108 Conformant
: Boolean := False;
3111 if No
(Spec_Id
) then
3112 Check_Fully_Conformant
(Body_Id
, Old_Id
);
3116 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
3118 if not Conformant
then
3120 -- The stub was taken to be a new declaration. Indicate that
3123 Set_Has_Completion
(Old_Id
, False);
3129 Set_Has_Completion
(Body_Id
);
3130 Check_Eliminated
(Body_Id
);
3132 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3136 -- Handle frontend inlining. There is no need to prepare us for inlining
3137 -- if we will not generate the code.
3141 if not Debug_Flag_Dot_K
then
3142 if Present
(Spec_Id
)
3143 and then Expander_Active
3145 (Has_Pragma_Inline_Always
(Spec_Id
)
3146 or else (Has_Pragma_Inline
(Spec_Id
) and Front_End_Inlining
))
3148 Build_Body_To_Inline
(N
, Spec_Id
);
3153 elsif Expander_Active
3154 and then Serious_Errors_Detected
= 0
3155 and then Present
(Spec_Id
)
3156 and then Has_Pragma_Inline
(Spec_Id
)
3158 Check_And_Build_Body_To_Inline
(N
, Spec_Id
, Body_Id
);
3161 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
3162 -- of the specification we have to install the private withed units.
3163 -- This holds for child units as well.
3165 if Is_Compilation_Unit
(Body_Id
)
3166 or else Nkind
(Parent
(N
)) = N_Compilation_Unit
3168 Install_Private_With_Clauses
(Body_Id
);
3171 Check_Anonymous_Return
;
3173 -- Set the Protected_Formal field of each extra formal of the protected
3174 -- subprogram to reference the corresponding extra formal of the
3175 -- subprogram that implements it. For regular formals this occurs when
3176 -- the protected subprogram's declaration is expanded, but the extra
3177 -- formals don't get created until the subprogram is frozen. We need to
3178 -- do this before analyzing the protected subprogram's body so that any
3179 -- references to the original subprogram's extra formals will be changed
3180 -- refer to the implementing subprogram's formals (see Expand_Formal).
3182 if Present
(Spec_Id
)
3183 and then Is_Protected_Type
(Scope
(Spec_Id
))
3184 and then Present
(Protected_Body_Subprogram
(Spec_Id
))
3187 Impl_Subp
: constant Entity_Id
:=
3188 Protected_Body_Subprogram
(Spec_Id
);
3189 Prot_Ext_Formal
: Entity_Id
:= Extra_Formals
(Spec_Id
);
3190 Impl_Ext_Formal
: Entity_Id
:= Extra_Formals
(Impl_Subp
);
3192 while Present
(Prot_Ext_Formal
) loop
3193 pragma Assert
(Present
(Impl_Ext_Formal
));
3194 Set_Protected_Formal
(Prot_Ext_Formal
, Impl_Ext_Formal
);
3195 Next_Formal_With_Extras
(Prot_Ext_Formal
);
3196 Next_Formal_With_Extras
(Impl_Ext_Formal
);
3201 -- Now we can go on to analyze the body
3203 HSS
:= Handled_Statement_Sequence
(N
);
3204 Set_Actual_Subtypes
(N
, Current_Scope
);
3206 -- Deal with [refined] preconditions, postconditions, Contract_Cases,
3207 -- invariants and predicates associated with the body and its spec.
3208 -- Note that this is not pure expansion as Expand_Subprogram_Contract
3209 -- prepares the contract assertions for generic subprograms or for ASIS.
3210 -- Do not generate contract checks in SPARK mode.
3212 if not GNATprove_Mode
then
3213 Expand_Subprogram_Contract
(N
, Spec_Id
, Body_Id
);
3216 -- Add a declaration for the Protection object, renaming declarations
3217 -- for discriminals and privals and finally a declaration for the entry
3218 -- family index (if applicable). This form of early expansion is done
3219 -- when the Expander is active because Install_Private_Data_Declarations
3220 -- references entities which were created during regular expansion. The
3221 -- subprogram entity must come from source, and not be an internally
3222 -- generated subprogram.
3225 and then Present
(Prot_Typ
)
3226 and then Present
(Spec_Id
)
3227 and then Comes_From_Source
(Spec_Id
)
3228 and then not Is_Eliminated
(Spec_Id
)
3230 Install_Private_Data_Declarations
3231 (Sloc
(N
), Spec_Id
, Prot_Typ
, N
, Declarations
(N
));
3234 -- Ada 2012 (AI05-0151): Incomplete types coming from a limited context
3235 -- may now appear in parameter and result profiles. Since the analysis
3236 -- of a subprogram body may use the parameter and result profile of the
3237 -- spec, swap any limited views with their non-limited counterpart.
3239 if Ada_Version
>= Ada_2012
then
3240 Exchange_Limited_Views
(Spec_Id
);
3243 -- Analyze the declarations (this call will analyze the precondition
3244 -- Check pragmas we prepended to the list, as well as the declaration
3245 -- of the _Postconditions procedure).
3247 Analyze_Declarations
(Declarations
(N
));
3249 -- After declarations have been analyzed, the body has been set
3250 -- its final value of SPARK_Mode. Check that SPARK_Mode for body
3251 -- is consistent with SPARK_Mode for spec.
3253 if Present
(Spec_Id
) and then Present
(SPARK_Pragma
(Body_Id
)) then
3254 if Present
(SPARK_Pragma
(Spec_Id
)) then
3255 if Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Spec_Id
)) = Off
3257 Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Body_Id
)) = On
3259 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
3260 Error_Msg_N
("incorrect application of SPARK_Mode#", N
);
3261 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Spec_Id
));
3263 ("\value Off was set for SPARK_Mode on&#", N
, Spec_Id
);
3266 elsif Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Body_Stub
then
3270 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
3271 Error_Msg_N
("incorrect application of SPARK_Mode#", N
);
3272 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
3273 Error_Msg_NE
("\no value was set for SPARK_Mode on&#", N
, Spec_Id
);
3277 -- Check completion, and analyze the statements
3280 Inspect_Deferred_Constant_Completion
(Declarations
(N
));
3283 -- Deal with end of scope processing for the body
3285 Process_End_Label
(HSS
, 't', Current_Scope
);
3287 Check_Subprogram_Order
(N
);
3288 Set_Analyzed
(Body_Id
);
3290 -- If we have a separate spec, then the analysis of the declarations
3291 -- caused the entities in the body to be chained to the spec id, but
3292 -- we want them chained to the body id. Only the formal parameters
3293 -- end up chained to the spec id in this case.
3295 if Present
(Spec_Id
) then
3297 -- We must conform to the categorization of our spec
3299 Validate_Categorization_Dependency
(N
, Spec_Id
);
3301 -- And if this is a child unit, the parent units must conform
3303 if Is_Child_Unit
(Spec_Id
) then
3304 Validate_Categorization_Dependency
3305 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
3308 -- Here is where we move entities from the spec to the body
3310 -- Case where there are entities that stay with the spec
3312 if Present
(Last_Real_Spec_Entity
) then
3314 -- No body entities (happens when the only real spec entities come
3315 -- from precondition and postcondition pragmas).
3317 if No
(Last_Entity
(Body_Id
)) then
3319 (Body_Id
, Next_Entity
(Last_Real_Spec_Entity
));
3321 -- Body entities present (formals), so chain stuff past them
3325 (Last_Entity
(Body_Id
), Next_Entity
(Last_Real_Spec_Entity
));
3328 Set_Next_Entity
(Last_Real_Spec_Entity
, Empty
);
3329 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
3330 Set_Last_Entity
(Spec_Id
, Last_Real_Spec_Entity
);
3332 -- Case where there are no spec entities, in this case there can be
3333 -- no body entities either, so just move everything.
3336 pragma Assert
(No
(Last_Entity
(Body_Id
)));
3337 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
3338 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
3339 Set_First_Entity
(Spec_Id
, Empty
);
3340 Set_Last_Entity
(Spec_Id
, Empty
);
3344 Check_Missing_Return
;
3346 -- Now we are going to check for variables that are never modified in
3347 -- the body of the procedure. But first we deal with a special case
3348 -- where we want to modify this check. If the body of the subprogram
3349 -- starts with a raise statement or its equivalent, or if the body
3350 -- consists entirely of a null statement, then it is pretty obvious that
3351 -- it is OK to not reference the parameters. For example, this might be
3352 -- the following common idiom for a stubbed function: statement of the
3353 -- procedure raises an exception. In particular this deals with the
3354 -- common idiom of a stubbed function, which appears something like:
3356 -- function F (A : Integer) return Some_Type;
3359 -- raise Program_Error;
3363 -- Here the purpose of X is simply to satisfy the annoying requirement
3364 -- in Ada that there be at least one return, and we certainly do not
3365 -- want to go posting warnings on X that it is not initialized. On
3366 -- the other hand, if X is entirely unreferenced that should still
3369 -- What we do is to detect these cases, and if we find them, flag the
3370 -- subprogram as being Is_Trivial_Subprogram and then use that flag to
3371 -- suppress unwanted warnings. For the case of the function stub above
3372 -- we have a special test to set X as apparently assigned to suppress
3379 -- Skip initial labels (for one thing this occurs when we are in
3380 -- front end ZCX mode, but in any case it is irrelevant), and also
3381 -- initial Push_xxx_Error_Label nodes, which are also irrelevant.
3383 Stm
:= First
(Statements
(HSS
));
3384 while Nkind
(Stm
) = N_Label
3385 or else Nkind
(Stm
) in N_Push_xxx_Label
3390 -- Do the test on the original statement before expansion
3393 Ostm
: constant Node_Id
:= Original_Node
(Stm
);
3396 -- If explicit raise statement, turn on flag
3398 if Nkind
(Ostm
) = N_Raise_Statement
then
3399 Set_Trivial_Subprogram
(Stm
);
3401 -- If null statement, and no following statements, turn on flag
3403 elsif Nkind
(Stm
) = N_Null_Statement
3404 and then Comes_From_Source
(Stm
)
3405 and then No
(Next
(Stm
))
3407 Set_Trivial_Subprogram
(Stm
);
3409 -- Check for explicit call cases which likely raise an exception
3411 elsif Nkind
(Ostm
) = N_Procedure_Call_Statement
then
3412 if Is_Entity_Name
(Name
(Ostm
)) then
3414 Ent
: constant Entity_Id
:= Entity
(Name
(Ostm
));
3417 -- If the procedure is marked No_Return, then likely it
3418 -- raises an exception, but in any case it is not coming
3419 -- back here, so turn on the flag.
3422 and then Ekind
(Ent
) = E_Procedure
3423 and then No_Return
(Ent
)
3425 Set_Trivial_Subprogram
(Stm
);
3433 -- Check for variables that are never modified
3439 -- If there is a separate spec, then transfer Never_Set_In_Source
3440 -- flags from out parameters to the corresponding entities in the
3441 -- body. The reason we do that is we want to post error flags on
3442 -- the body entities, not the spec entities.
3444 if Present
(Spec_Id
) then
3445 E1
:= First_Entity
(Spec_Id
);
3446 while Present
(E1
) loop
3447 if Ekind
(E1
) = E_Out_Parameter
then
3448 E2
:= First_Entity
(Body_Id
);
3449 while Present
(E2
) loop
3450 exit when Chars
(E1
) = Chars
(E2
);
3454 if Present
(E2
) then
3455 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
3463 -- Check references in body
3465 Check_References
(Body_Id
);
3467 end Analyze_Subprogram_Body_Helper
;
3469 ---------------------------------
3470 -- Analyze_Subprogram_Contract --
3471 ---------------------------------
3473 procedure Analyze_Subprogram_Contract
(Subp
: Entity_Id
) is
3474 Items
: constant Node_Id
:= Contract
(Subp
);
3475 Case_Prag
: Node_Id
:= Empty
;
3476 Depends
: Node_Id
:= Empty
;
3477 Global
: Node_Id
:= Empty
;
3479 Post_Prag
: Node_Id
:= Empty
;
3481 Seen_In_Case
: Boolean := False;
3482 Seen_In_Post
: Boolean := False;
3485 if Present
(Items
) then
3487 -- Analyze pre- and postconditions
3489 Prag
:= Pre_Post_Conditions
(Items
);
3490 while Present
(Prag
) loop
3491 Analyze_Pre_Post_Condition_In_Decl_Part
(Prag
, Subp
);
3493 -- Verify whether a postcondition mentions attribute 'Result and
3494 -- its expression introduces a post-state.
3496 if Warn_On_Suspicious_Contract
3497 and then Pragma_Name
(Prag
) = Name_Postcondition
3500 Check_Result_And_Post_State
(Prag
, Seen_In_Post
);
3503 Prag
:= Next_Pragma
(Prag
);
3506 -- Analyze contract-cases and test-cases
3508 Prag
:= Contract_Test_Cases
(Items
);
3509 while Present
(Prag
) loop
3510 Nam
:= Pragma_Name
(Prag
);
3512 if Nam
= Name_Contract_Cases
then
3513 Analyze_Contract_Cases_In_Decl_Part
(Prag
);
3515 -- Verify whether contract-cases mention attribute 'Result and
3516 -- its expression introduces a post-state. Perform the check
3517 -- only when the pragma is legal.
3519 if Warn_On_Suspicious_Contract
3520 and then not Error_Posted
(Prag
)
3523 Check_Result_And_Post_State
(Prag
, Seen_In_Case
);
3527 pragma Assert
(Nam
= Name_Test_Case
);
3528 Analyze_Test_Case_In_Decl_Part
(Prag
, Subp
);
3531 Prag
:= Next_Pragma
(Prag
);
3534 -- Analyze classification pragmas
3536 Prag
:= Classifications
(Items
);
3537 while Present
(Prag
) loop
3538 Nam
:= Pragma_Name
(Prag
);
3540 if Nam
= Name_Depends
then
3542 else pragma Assert
(Nam
= Name_Global
);
3546 Prag
:= Next_Pragma
(Prag
);
3549 -- Analyze Global first as Depends may mention items classified in
3550 -- the global categorization.
3552 if Present
(Global
) then
3553 Analyze_Global_In_Decl_Part
(Global
);
3556 -- Depends must be analyzed after Global in order to see the modes of
3557 -- all global items.
3559 if Present
(Depends
) then
3560 Analyze_Depends_In_Decl_Part
(Depends
);
3564 -- Emit an error when neither the postconditions nor the contract-cases
3565 -- mention attribute 'Result in the context of a function.
3567 if Warn_On_Suspicious_Contract
3568 and then Ekind_In
(Subp
, E_Function
, E_Generic_Function
)
3570 if Present
(Case_Prag
)
3571 and then not Seen_In_Case
3572 and then Present
(Post_Prag
)
3573 and then not Seen_In_Post
3576 ("neither function postcondition nor contract cases mention "
3577 & "result?T?", Post_Prag
);
3579 elsif Present
(Case_Prag
) and then not Seen_In_Case
then
3581 ("contract cases do not mention result?T?", Case_Prag
);
3583 elsif Present
(Post_Prag
) and then not Seen_In_Post
then
3585 ("function postcondition does not mention result?T?", Post_Prag
);
3588 end Analyze_Subprogram_Contract
;
3590 ------------------------------------
3591 -- Analyze_Subprogram_Declaration --
3592 ------------------------------------
3594 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
3595 Scop
: constant Entity_Id
:= Current_Scope
;
3596 Designator
: Entity_Id
;
3598 Is_Completion
: Boolean;
3599 -- Indicates whether a null procedure declaration is a completion
3602 -- Null procedures are not allowed in SPARK
3604 if Nkind
(Specification
(N
)) = N_Procedure_Specification
3605 and then Null_Present
(Specification
(N
))
3607 Check_SPARK_Restriction
("null procedure is not allowed", N
);
3609 if Is_Protected_Type
(Current_Scope
) then
3610 Error_Msg_N
("protected operation cannot be a null procedure", N
);
3613 Analyze_Null_Procedure
(N
, Is_Completion
);
3615 if Is_Completion
then
3617 -- The null procedure acts as a body, nothing further is needed.
3623 Designator
:= Analyze_Subprogram_Specification
(Specification
(N
));
3625 -- A reference may already have been generated for the unit name, in
3626 -- which case the following call is redundant. However it is needed for
3627 -- declarations that are the rewriting of an expression function.
3629 Generate_Definition
(Designator
);
3631 -- Set SPARK mode from current context (may be overwritten later with
3632 -- explicit pragma).
3634 Set_SPARK_Pragma
(Designator
, SPARK_Mode_Pragma
);
3635 Set_SPARK_Pragma_Inherited
(Designator
, True);
3637 if Debug_Flag_C
then
3638 Write_Str
("==> subprogram spec ");
3639 Write_Name
(Chars
(Designator
));
3640 Write_Str
(" from ");
3641 Write_Location
(Sloc
(N
));
3646 Validate_RCI_Subprogram_Declaration
(N
);
3647 New_Overloaded_Entity
(Designator
);
3648 Check_Delayed_Subprogram
(Designator
);
3650 -- If the type of the first formal of the current subprogram is a non-
3651 -- generic tagged private type, mark the subprogram as being a private
3652 -- primitive. Ditto if this is a function with controlling result, and
3653 -- the return type is currently private. In both cases, the type of the
3654 -- controlling argument or result must be in the current scope for the
3655 -- operation to be primitive.
3657 if Has_Controlling_Result
(Designator
)
3658 and then Is_Private_Type
(Etype
(Designator
))
3659 and then Scope
(Etype
(Designator
)) = Current_Scope
3660 and then not Is_Generic_Actual_Type
(Etype
(Designator
))
3662 Set_Is_Private_Primitive
(Designator
);
3664 elsif Present
(First_Formal
(Designator
)) then
3666 Formal_Typ
: constant Entity_Id
:=
3667 Etype
(First_Formal
(Designator
));
3669 Set_Is_Private_Primitive
(Designator
,
3670 Is_Tagged_Type
(Formal_Typ
)
3671 and then Scope
(Formal_Typ
) = Current_Scope
3672 and then Is_Private_Type
(Formal_Typ
)
3673 and then not Is_Generic_Actual_Type
(Formal_Typ
));
3677 -- Ada 2005 (AI-251): Abstract interface primitives must be abstract
3680 if Ada_Version
>= Ada_2005
3681 and then Comes_From_Source
(N
)
3682 and then Is_Dispatching_Operation
(Designator
)
3689 if Has_Controlling_Result
(Designator
) then
3690 Etyp
:= Etype
(Designator
);
3693 E
:= First_Entity
(Designator
);
3695 and then Is_Formal
(E
)
3696 and then not Is_Controlling_Formal
(E
)
3704 if Is_Access_Type
(Etyp
) then
3705 Etyp
:= Directly_Designated_Type
(Etyp
);
3708 if Is_Interface
(Etyp
)
3709 and then not Is_Abstract_Subprogram
(Designator
)
3710 and then not (Ekind
(Designator
) = E_Procedure
3711 and then Null_Present
(Specification
(N
)))
3713 Error_Msg_Name_1
:= Chars
(Defining_Entity
(N
));
3715 -- Specialize error message based on procedures vs. functions,
3716 -- since functions can't be null subprograms.
3718 if Ekind
(Designator
) = E_Procedure
then
3720 ("interface procedure % must be abstract or null", N
);
3722 Error_Msg_N
("interface function % must be abstract", N
);
3728 -- What is the following code for, it used to be
3730 -- ??? Set_Suppress_Elaboration_Checks
3731 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
3733 -- The following seems equivalent, but a bit dubious
3735 if Elaboration_Checks_Suppressed
(Designator
) then
3736 Set_Kill_Elaboration_Checks
(Designator
);
3739 if Scop
/= Standard_Standard
and then not Is_Child_Unit
(Designator
) then
3740 Set_Categorization_From_Scope
(Designator
, Scop
);
3743 -- For a compilation unit, check for library-unit pragmas
3745 Push_Scope
(Designator
);
3746 Set_Categorization_From_Pragmas
(N
);
3747 Validate_Categorization_Dependency
(N
, Designator
);
3751 -- For a compilation unit, set body required. This flag will only be
3752 -- reset if a valid Import or Interface pragma is processed later on.
3754 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3755 Set_Body_Required
(Parent
(N
), True);
3757 if Ada_Version
>= Ada_2005
3758 and then Nkind
(Specification
(N
)) = N_Procedure_Specification
3759 and then Null_Present
(Specification
(N
))
3762 ("null procedure cannot be declared at library level", N
);
3766 Generate_Reference_To_Formals
(Designator
);
3767 Check_Eliminated
(Designator
);
3769 if Debug_Flag_C
then
3771 Write_Str
("<== subprogram spec ");
3772 Write_Name
(Chars
(Designator
));
3773 Write_Str
(" from ");
3774 Write_Location
(Sloc
(N
));
3778 if Is_Protected_Type
(Current_Scope
) then
3780 -- Indicate that this is a protected operation, because it may be
3781 -- used in subsequent declarations within the protected type.
3783 Set_Convention
(Designator
, Convention_Protected
);
3786 List_Inherited_Pre_Post_Aspects
(Designator
);
3788 if Has_Aspects
(N
) then
3789 Analyze_Aspect_Specifications
(N
, Designator
);
3791 end Analyze_Subprogram_Declaration
;
3793 --------------------------------------
3794 -- Analyze_Subprogram_Specification --
3795 --------------------------------------
3797 -- Reminder: N here really is a subprogram specification (not a subprogram
3798 -- declaration). This procedure is called to analyze the specification in
3799 -- both subprogram bodies and subprogram declarations (specs).
3801 function Analyze_Subprogram_Specification
(N
: Node_Id
) return Entity_Id
is
3802 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
3803 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
3805 -- Start of processing for Analyze_Subprogram_Specification
3808 -- User-defined operator is not allowed in SPARK, except as a renaming
3810 if Nkind
(Defining_Unit_Name
(N
)) = N_Defining_Operator_Symbol
3811 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
3813 Check_SPARK_Restriction
("user-defined operator is not allowed", N
);
3816 -- Proceed with analysis. Do not emit a cross-reference entry if the
3817 -- specification comes from an expression function, because it may be
3818 -- the completion of a previous declaration. It is is not, the cross-
3819 -- reference entry will be emitted for the new subprogram declaration.
3821 if Nkind
(Parent
(N
)) /= N_Expression_Function
then
3822 Generate_Definition
(Designator
);
3825 Set_Contract
(Designator
, Make_Contract
(Sloc
(Designator
)));
3827 if Nkind
(N
) = N_Function_Specification
then
3828 Set_Ekind
(Designator
, E_Function
);
3829 Set_Mechanism
(Designator
, Default_Mechanism
);
3831 Set_Ekind
(Designator
, E_Procedure
);
3832 Set_Etype
(Designator
, Standard_Void_Type
);
3835 -- Introduce new scope for analysis of the formals and the return type
3837 Set_Scope
(Designator
, Current_Scope
);
3839 if Present
(Formals
) then
3840 Push_Scope
(Designator
);
3841 Process_Formals
(Formals
, N
);
3843 -- Check dimensions in N for formals with default expression
3845 Analyze_Dimension_Formals
(N
, Formals
);
3847 -- Ada 2005 (AI-345): If this is an overriding operation of an
3848 -- inherited interface operation, and the controlling type is
3849 -- a synchronized type, replace the type with its corresponding
3850 -- record, to match the proper signature of an overriding operation.
3851 -- Same processing for an access parameter whose designated type is
3852 -- derived from a synchronized interface.
3854 if Ada_Version
>= Ada_2005
then
3857 Formal_Typ
: Entity_Id
;
3858 Rec_Typ
: Entity_Id
;
3859 Desig_Typ
: Entity_Id
;
3862 Formal
:= First_Formal
(Designator
);
3863 while Present
(Formal
) loop
3864 Formal_Typ
:= Etype
(Formal
);
3866 if Is_Concurrent_Type
(Formal_Typ
)
3867 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
3869 Rec_Typ
:= Corresponding_Record_Type
(Formal_Typ
);
3871 if Present
(Interfaces
(Rec_Typ
)) then
3872 Set_Etype
(Formal
, Rec_Typ
);
3875 elsif Ekind
(Formal_Typ
) = E_Anonymous_Access_Type
then
3876 Desig_Typ
:= Designated_Type
(Formal_Typ
);
3878 if Is_Concurrent_Type
(Desig_Typ
)
3879 and then Present
(Corresponding_Record_Type
(Desig_Typ
))
3881 Rec_Typ
:= Corresponding_Record_Type
(Desig_Typ
);
3883 if Present
(Interfaces
(Rec_Typ
)) then
3884 Set_Directly_Designated_Type
(Formal_Typ
, Rec_Typ
);
3889 Next_Formal
(Formal
);
3896 -- The subprogram scope is pushed and popped around the processing of
3897 -- the return type for consistency with call above to Process_Formals
3898 -- (which itself can call Analyze_Return_Type), and to ensure that any
3899 -- itype created for the return type will be associated with the proper
3902 elsif Nkind
(N
) = N_Function_Specification
then
3903 Push_Scope
(Designator
);
3904 Analyze_Return_Type
(N
);
3910 if Nkind
(N
) = N_Function_Specification
then
3912 -- Deal with operator symbol case
3914 if Nkind
(Designator
) = N_Defining_Operator_Symbol
then
3915 Valid_Operator_Definition
(Designator
);
3918 May_Need_Actuals
(Designator
);
3920 -- Ada 2005 (AI-251): If the return type is abstract, verify that
3921 -- the subprogram is abstract also. This does not apply to renaming
3922 -- declarations, where abstractness is inherited, and to subprogram
3923 -- bodies generated for stream operations, which become renamings as
3926 -- In case of primitives associated with abstract interface types
3927 -- the check is applied later (see Analyze_Subprogram_Declaration).
3929 if not Nkind_In
(Original_Node
(Parent
(N
)),
3930 N_Subprogram_Renaming_Declaration
,
3931 N_Abstract_Subprogram_Declaration
,
3932 N_Formal_Abstract_Subprogram_Declaration
)
3934 if Is_Abstract_Type
(Etype
(Designator
))
3935 and then not Is_Interface
(Etype
(Designator
))
3938 ("function that returns abstract type must be abstract", N
);
3940 -- Ada 2012 (AI-0073): Extend this test to subprograms with an
3941 -- access result whose designated type is abstract.
3943 elsif Nkind
(Result_Definition
(N
)) = N_Access_Definition
3945 not Is_Class_Wide_Type
(Designated_Type
(Etype
(Designator
)))
3946 and then Is_Abstract_Type
(Designated_Type
(Etype
(Designator
)))
3947 and then Ada_Version
>= Ada_2012
3949 Error_Msg_N
("function whose access result designates "
3950 & "abstract type must be abstract", N
);
3956 end Analyze_Subprogram_Specification
;
3958 --------------------------
3959 -- Build_Body_To_Inline --
3960 --------------------------
3962 procedure Build_Body_To_Inline
(N
: Node_Id
; Subp
: Entity_Id
) is
3963 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
3964 Original_Body
: Node_Id
;
3965 Body_To_Analyze
: Node_Id
;
3966 Max_Size
: constant := 10;
3967 Stat_Count
: Integer := 0;
3969 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean;
3970 -- Check for declarations that make inlining not worthwhile
3972 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean;
3973 -- Check for statements that make inlining not worthwhile: any tasking
3974 -- statement, nested at any level. Keep track of total number of
3975 -- elementary statements, as a measure of acceptable size.
3977 function Has_Pending_Instantiation
return Boolean;
3978 -- If some enclosing body contains instantiations that appear before the
3979 -- corresponding generic body, the enclosing body has a freeze node so
3980 -- that it can be elaborated after the generic itself. This might
3981 -- conflict with subsequent inlinings, so that it is unsafe to try to
3982 -- inline in such a case.
3984 function Has_Single_Return
return Boolean;
3985 -- In general we cannot inline functions that return unconstrained type.
3986 -- However, we can handle such functions if all return statements return
3987 -- a local variable that is the only declaration in the body of the
3988 -- function. In that case the call can be replaced by that local
3989 -- variable as is done for other inlined calls.
3991 procedure Remove_Pragmas
;
3992 -- A pragma Unreferenced or pragma Unmodified that mentions a formal
3993 -- parameter has no meaning when the body is inlined and the formals
3994 -- are rewritten. Remove it from body to inline. The analysis of the
3995 -- non-inlined body will handle the pragma properly.
3997 function Uses_Secondary_Stack
(Bod
: Node_Id
) return Boolean;
3998 -- If the body of the subprogram includes a call that returns an
3999 -- unconstrained type, the secondary stack is involved, and it
4000 -- is not worth inlining.
4002 ------------------------------
4003 -- Has_Excluded_Declaration --
4004 ------------------------------
4006 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean is
4009 function Is_Unchecked_Conversion
(D
: Node_Id
) return Boolean;
4010 -- Nested subprograms make a given body ineligible for inlining, but
4011 -- we make an exception for instantiations of unchecked conversion.
4012 -- The body has not been analyzed yet, so check the name, and verify
4013 -- that the visible entity with that name is the predefined unit.
4015 -----------------------------
4016 -- Is_Unchecked_Conversion --
4017 -----------------------------
4019 function Is_Unchecked_Conversion
(D
: Node_Id
) return Boolean is
4020 Id
: constant Node_Id
:= Name
(D
);
4024 if Nkind
(Id
) = N_Identifier
4025 and then Chars
(Id
) = Name_Unchecked_Conversion
4027 Conv
:= Current_Entity
(Id
);
4029 elsif Nkind_In
(Id
, N_Selected_Component
, N_Expanded_Name
)
4030 and then Chars
(Selector_Name
(Id
)) = Name_Unchecked_Conversion
4032 Conv
:= Current_Entity
(Selector_Name
(Id
));
4037 return Present
(Conv
)
4038 and then Is_Predefined_File_Name
4039 (Unit_File_Name
(Get_Source_Unit
(Conv
)))
4040 and then Is_Intrinsic_Subprogram
(Conv
);
4041 end Is_Unchecked_Conversion
;
4043 -- Start of processing for Has_Excluded_Declaration
4047 while Present
(D
) loop
4048 if (Nkind
(D
) = N_Function_Instantiation
4049 and then not Is_Unchecked_Conversion
(D
))
4050 or else Nkind_In
(D
, N_Protected_Type_Declaration
,
4051 N_Package_Declaration
,
4052 N_Package_Instantiation
,
4054 N_Procedure_Instantiation
,
4055 N_Task_Type_Declaration
)
4058 ("cannot inline & (non-allowed declaration)?", D
, Subp
);
4066 end Has_Excluded_Declaration
;
4068 ----------------------------
4069 -- Has_Excluded_Statement --
4070 ----------------------------
4072 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean is
4078 while Present
(S
) loop
4079 Stat_Count
:= Stat_Count
+ 1;
4081 if Nkind_In
(S
, N_Abort_Statement
,
4082 N_Asynchronous_Select
,
4083 N_Conditional_Entry_Call
,
4084 N_Delay_Relative_Statement
,
4085 N_Delay_Until_Statement
,
4090 ("cannot inline & (non-allowed statement)?", S
, Subp
);
4093 elsif Nkind
(S
) = N_Block_Statement
then
4094 if Present
(Declarations
(S
))
4095 and then Has_Excluded_Declaration
(Declarations
(S
))
4099 elsif Present
(Handled_Statement_Sequence
(S
))
4102 (Exception_Handlers
(Handled_Statement_Sequence
(S
)))
4104 Has_Excluded_Statement
4105 (Statements
(Handled_Statement_Sequence
(S
))))
4110 elsif Nkind
(S
) = N_Case_Statement
then
4111 E
:= First
(Alternatives
(S
));
4112 while Present
(E
) loop
4113 if Has_Excluded_Statement
(Statements
(E
)) then
4120 elsif Nkind
(S
) = N_If_Statement
then
4121 if Has_Excluded_Statement
(Then_Statements
(S
)) then
4125 if Present
(Elsif_Parts
(S
)) then
4126 E
:= First
(Elsif_Parts
(S
));
4127 while Present
(E
) loop
4128 if Has_Excluded_Statement
(Then_Statements
(E
)) then
4136 if Present
(Else_Statements
(S
))
4137 and then Has_Excluded_Statement
(Else_Statements
(S
))
4142 elsif Nkind
(S
) = N_Loop_Statement
4143 and then Has_Excluded_Statement
(Statements
(S
))
4147 elsif Nkind
(S
) = N_Extended_Return_Statement
then
4148 if Has_Excluded_Statement
4149 (Statements
(Handled_Statement_Sequence
(S
)))
4151 (Exception_Handlers
(Handled_Statement_Sequence
(S
)))
4161 end Has_Excluded_Statement
;
4163 -------------------------------
4164 -- Has_Pending_Instantiation --
4165 -------------------------------
4167 function Has_Pending_Instantiation
return Boolean is
4172 while Present
(S
) loop
4173 if Is_Compilation_Unit
(S
)
4174 or else Is_Child_Unit
(S
)
4178 elsif Ekind
(S
) = E_Package
4179 and then Has_Forward_Instantiation
(S
)
4188 end Has_Pending_Instantiation
;
4190 ------------------------
4191 -- Has_Single_Return --
4192 ------------------------
4194 function Has_Single_Return
return Boolean is
4195 Return_Statement
: Node_Id
:= Empty
;
4197 function Check_Return
(N
: Node_Id
) return Traverse_Result
;
4203 function Check_Return
(N
: Node_Id
) return Traverse_Result
is
4205 if Nkind
(N
) = N_Simple_Return_Statement
then
4206 if Present
(Expression
(N
))
4207 and then Is_Entity_Name
(Expression
(N
))
4209 if No
(Return_Statement
) then
4210 Return_Statement
:= N
;
4213 elsif Chars
(Expression
(N
)) =
4214 Chars
(Expression
(Return_Statement
))
4222 -- A return statement within an extended return is a noop
4225 elsif No
(Expression
(N
))
4226 and then Nkind
(Parent
(Parent
(N
))) =
4227 N_Extended_Return_Statement
4232 -- Expression has wrong form
4237 -- We can only inline a build-in-place function if
4238 -- it has a single extended return.
4240 elsif Nkind
(N
) = N_Extended_Return_Statement
then
4241 if No
(Return_Statement
) then
4242 Return_Statement
:= N
;
4254 function Check_All_Returns
is new Traverse_Func
(Check_Return
);
4256 -- Start of processing for Has_Single_Return
4259 if Check_All_Returns
(N
) /= OK
then
4262 elsif Nkind
(Return_Statement
) = N_Extended_Return_Statement
then
4266 return Present
(Declarations
(N
))
4267 and then Present
(First
(Declarations
(N
)))
4268 and then Chars
(Expression
(Return_Statement
)) =
4269 Chars
(Defining_Identifier
(First
(Declarations
(N
))));
4271 end Has_Single_Return
;
4273 --------------------
4274 -- Remove_Pragmas --
4275 --------------------
4277 procedure Remove_Pragmas
is
4282 Decl
:= First
(Declarations
(Body_To_Analyze
));
4283 while Present
(Decl
) loop
4286 if Nkind
(Decl
) = N_Pragma
4287 and then Nam_In
(Pragma_Name
(Decl
), Name_Unreferenced
,
4297 --------------------------
4298 -- Uses_Secondary_Stack --
4299 --------------------------
4301 function Uses_Secondary_Stack
(Bod
: Node_Id
) return Boolean is
4302 function Check_Call
(N
: Node_Id
) return Traverse_Result
;
4303 -- Look for function calls that return an unconstrained type
4309 function Check_Call
(N
: Node_Id
) return Traverse_Result
is
4311 if Nkind
(N
) = N_Function_Call
4312 and then Is_Entity_Name
(Name
(N
))
4313 and then Is_Composite_Type
(Etype
(Entity
(Name
(N
))))
4314 and then not Is_Constrained
(Etype
(Entity
(Name
(N
))))
4317 ("cannot inline & (call returns unconstrained type)?",
4325 function Check_Calls
is new Traverse_Func
(Check_Call
);
4328 return Check_Calls
(Bod
) = Abandon
;
4329 end Uses_Secondary_Stack
;
4331 -- Start of processing for Build_Body_To_Inline
4334 -- Return immediately if done already
4336 if Nkind
(Decl
) = N_Subprogram_Declaration
4337 and then Present
(Body_To_Inline
(Decl
))
4341 -- Functions that return unconstrained composite types require
4342 -- secondary stack handling, and cannot currently be inlined, unless
4343 -- all return statements return a local variable that is the first
4344 -- local declaration in the body.
4346 elsif Ekind
(Subp
) = E_Function
4347 and then not Is_Scalar_Type
(Etype
(Subp
))
4348 and then not Is_Access_Type
(Etype
(Subp
))
4349 and then not Is_Constrained
(Etype
(Subp
))
4351 if not Has_Single_Return
then
4353 ("cannot inline & (unconstrained return type)?", N
, Subp
);
4357 -- Ditto for functions that return controlled types, where controlled
4358 -- actions interfere in complex ways with inlining.
4360 elsif Ekind
(Subp
) = E_Function
4361 and then Needs_Finalization
(Etype
(Subp
))
4364 ("cannot inline & (controlled return type)?", N
, Subp
);
4368 if Present
(Declarations
(N
))
4369 and then Has_Excluded_Declaration
(Declarations
(N
))
4374 if Present
(Handled_Statement_Sequence
(N
)) then
4375 if Present
(Exception_Handlers
(Handled_Statement_Sequence
(N
))) then
4377 ("cannot inline& (exception handler)?",
4378 First
(Exception_Handlers
(Handled_Statement_Sequence
(N
))),
4382 Has_Excluded_Statement
4383 (Statements
(Handled_Statement_Sequence
(N
)))
4389 -- We do not inline a subprogram that is too large, unless it is
4390 -- marked Inline_Always. This pragma does not suppress the other
4391 -- checks on inlining (forbidden declarations, handlers, etc).
4393 if Stat_Count
> Max_Size
4394 and then not Has_Pragma_Inline_Always
(Subp
)
4396 Cannot_Inline
("cannot inline& (body too large)?", N
, Subp
);
4400 if Has_Pending_Instantiation
then
4402 ("cannot inline& (forward instance within enclosing body)?",
4407 -- Within an instance, the body to inline must be treated as a nested
4408 -- generic, so that the proper global references are preserved.
4410 -- Note that we do not do this at the library level, because it is not
4411 -- needed, and furthermore this causes trouble if front end inlining
4412 -- is activated (-gnatN).
4414 if In_Instance
and then Scope
(Current_Scope
) /= Standard_Standard
then
4415 Save_Env
(Scope
(Current_Scope
), Scope
(Current_Scope
));
4416 Original_Body
:= Copy_Generic_Node
(N
, Empty
, True);
4418 Original_Body
:= Copy_Separate_Tree
(N
);
4421 -- We need to capture references to the formals in order to substitute
4422 -- the actuals at the point of inlining, i.e. instantiation. To treat
4423 -- the formals as globals to the body to inline, we nest it within
4424 -- a dummy parameterless subprogram, declared within the real one.
4425 -- To avoid generating an internal name (which is never public, and
4426 -- which affects serial numbers of other generated names), we use
4427 -- an internal symbol that cannot conflict with user declarations.
4429 Set_Parameter_Specifications
(Specification
(Original_Body
), No_List
);
4430 Set_Defining_Unit_Name
4431 (Specification
(Original_Body
),
4432 Make_Defining_Identifier
(Sloc
(N
), Name_uParent
));
4433 Set_Corresponding_Spec
(Original_Body
, Empty
);
4435 Body_To_Analyze
:= Copy_Generic_Node
(Original_Body
, Empty
, False);
4437 -- Set return type of function, which is also global and does not need
4440 if Ekind
(Subp
) = E_Function
then
4441 Set_Result_Definition
(Specification
(Body_To_Analyze
),
4442 New_Occurrence_Of
(Etype
(Subp
), Sloc
(N
)));
4445 if No
(Declarations
(N
)) then
4446 Set_Declarations
(N
, New_List
(Body_To_Analyze
));
4448 Append
(Body_To_Analyze
, Declarations
(N
));
4451 Expander_Mode_Save_And_Set
(False);
4454 Analyze
(Body_To_Analyze
);
4455 Push_Scope
(Defining_Entity
(Body_To_Analyze
));
4456 Save_Global_References
(Original_Body
);
4458 Remove
(Body_To_Analyze
);
4460 Expander_Mode_Restore
;
4462 -- Restore environment if previously saved
4464 if In_Instance
and then Scope
(Current_Scope
) /= Standard_Standard
then
4468 -- If secondary stk used there is no point in inlining. We have
4469 -- already issued the warning in this case, so nothing to do.
4471 if Uses_Secondary_Stack
(Body_To_Analyze
) then
4475 Set_Body_To_Inline
(Decl
, Original_Body
);
4476 Set_Ekind
(Defining_Entity
(Original_Body
), Ekind
(Subp
));
4477 Set_Is_Inlined
(Subp
);
4478 end Build_Body_To_Inline
;
4484 procedure Cannot_Inline
4488 Is_Serious
: Boolean := False)
4491 pragma Assert
(Msg
(Msg
'Last) = '?');
4495 if not Debug_Flag_Dot_K
then
4497 -- Do not emit warning if this is a predefined unit which is not
4498 -- the main unit. With validity checks enabled, some predefined
4499 -- subprograms may contain nested subprograms and become ineligible
4502 if Is_Predefined_File_Name
(Unit_File_Name
(Get_Source_Unit
(Subp
)))
4503 and then not In_Extended_Main_Source_Unit
(Subp
)
4507 elsif Has_Pragma_Inline_Always
(Subp
) then
4509 -- Remove last character (question mark) to make this into an
4510 -- error, because the Inline_Always pragma cannot be obeyed.
4512 Error_Msg_NE
(Msg
(Msg
'First .. Msg
'Last - 1), N
, Subp
);
4514 elsif Ineffective_Inline_Warnings
then
4515 Error_Msg_NE
(Msg
& "p?", N
, Subp
);
4522 elsif Is_Serious
then
4524 -- Remove last character (question mark) to make this into an error.
4526 Error_Msg_NE
(Msg
(Msg
'First .. Msg
'Last - 1), N
, Subp
);
4528 elsif Optimization_Level
= 0 then
4530 -- Do not emit warning if this is a predefined unit which is not
4531 -- the main unit. This behavior is currently provided for backward
4532 -- compatibility but it will be removed when we enforce the
4533 -- strictness of the new rules.
4535 if Is_Predefined_File_Name
(Unit_File_Name
(Get_Source_Unit
(Subp
)))
4536 and then not In_Extended_Main_Source_Unit
(Subp
)
4540 elsif Has_Pragma_Inline_Always
(Subp
) then
4542 -- Emit a warning if this is a call to a runtime subprogram
4543 -- which is located inside a generic. Previously this call
4544 -- was silently skipped.
4546 if Is_Generic_Instance
(Subp
) then
4548 Gen_P
: constant Entity_Id
:= Generic_Parent
(Parent
(Subp
));
4550 if Is_Predefined_File_Name
4551 (Unit_File_Name
(Get_Source_Unit
(Gen_P
)))
4553 Set_Is_Inlined
(Subp
, False);
4554 Error_Msg_NE
(Msg
& "p?", N
, Subp
);
4560 -- Remove last character (question mark) to make this into an
4561 -- error, because the Inline_Always pragma cannot be obeyed.
4563 Error_Msg_NE
(Msg
(Msg
'First .. Msg
'Last - 1), N
, Subp
);
4565 else pragma Assert
(Front_End_Inlining
);
4566 Set_Is_Inlined
(Subp
, False);
4568 -- When inlining cannot take place we must issue an error.
4569 -- For backward compatibility we still report a warning.
4571 if Ineffective_Inline_Warnings
then
4572 Error_Msg_NE
(Msg
& "p?", N
, Subp
);
4576 -- Compiling with optimizations enabled it is too early to report
4577 -- problems since the backend may still perform inlining. In order
4578 -- to report unhandled inlinings the program must be compiled with
4579 -- -Winline and the error is reported by the backend.
4586 ------------------------------------
4587 -- Check_And_Build_Body_To_Inline --
4588 ------------------------------------
4590 procedure Check_And_Build_Body_To_Inline
4592 Spec_Id
: Entity_Id
;
4593 Body_Id
: Entity_Id
)
4595 procedure Build_Body_To_Inline
(N
: Node_Id
; Spec_Id
: Entity_Id
);
4596 -- Use generic machinery to build an unexpanded body for the subprogram.
4597 -- This body is subsequently used for inline expansions at call sites.
4599 function Can_Split_Unconstrained_Function
(N
: Node_Id
) return Boolean;
4600 -- Return true if we generate code for the function body N, the function
4601 -- body N has no local declarations and its unique statement is a single
4602 -- extended return statement with a handled statements sequence.
4604 function Check_Body_To_Inline
4606 Subp
: Entity_Id
) return Boolean;
4607 -- N is the N_Subprogram_Body of Subp. Return true if Subp can be
4608 -- inlined by the frontend. These are the rules:
4609 -- * At -O0 use fe inlining when inline_always is specified except if
4610 -- the function returns a controlled type.
4611 -- * At other optimization levels use the fe inlining for both inline
4612 -- and inline_always in the following cases:
4613 -- - function returning a known at compile time constant
4614 -- - function returning a call to an intrinsic function
4615 -- - function returning an unconstrained type (see Can_Split
4616 -- Unconstrained_Function).
4617 -- - function returning a call to a frontend-inlined function
4618 -- Use the back-end mechanism otherwise
4620 -- In addition, in the following cases the function cannot be inlined by
4622 -- - functions that uses the secondary stack
4623 -- - functions that have declarations of:
4624 -- - Concurrent types
4628 -- - functions that have some of the following statements:
4630 -- - asynchronous-select
4631 -- - conditional-entry-call
4634 -- - selective-accept
4635 -- - timed-entry-call
4636 -- - functions that have exception handlers
4637 -- - functions that have some enclosing body containing instantiations
4638 -- that appear before the corresponding generic body.
4640 procedure Generate_Body_To_Inline
4642 Body_To_Inline
: out Node_Id
);
4643 -- Generate a parameterless duplicate of subprogram body N. Occurrences
4644 -- of pragmas referencing the formals are removed since they have no
4645 -- meaning when the body is inlined and the formals are rewritten (the
4646 -- analysis of the non-inlined body will handle these pragmas properly).
4647 -- A new internal name is associated with Body_To_Inline.
4649 procedure Split_Unconstrained_Function
4651 Spec_Id
: Entity_Id
);
4652 -- N is an inlined function body that returns an unconstrained type and
4653 -- has a single extended return statement. Split N in two subprograms:
4654 -- a procedure P' and a function F'. The formals of P' duplicate the
4655 -- formals of N plus an extra formal which is used return a value;
4656 -- its body is composed by the declarations and list of statements
4657 -- of the extended return statement of N.
4659 --------------------------
4660 -- Build_Body_To_Inline --
4661 --------------------------
4663 procedure Build_Body_To_Inline
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
4664 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Spec_Id
);
4665 Original_Body
: Node_Id
;
4666 Body_To_Analyze
: Node_Id
;
4669 pragma Assert
(Current_Scope
= Spec_Id
);
4671 -- Within an instance, the body to inline must be treated as a nested
4672 -- generic, so that the proper global references are preserved. We
4673 -- do not do this at the library level, because it is not needed, and
4674 -- furthermore this causes trouble if front end inlining is activated
4678 and then Scope
(Current_Scope
) /= Standard_Standard
4680 Save_Env
(Scope
(Current_Scope
), Scope
(Current_Scope
));
4683 -- We need to capture references to the formals in order
4684 -- to substitute the actuals at the point of inlining, i.e.
4685 -- instantiation. To treat the formals as globals to the body to
4686 -- inline, we nest it within a dummy parameterless subprogram,
4687 -- declared within the real one.
4689 Generate_Body_To_Inline
(N
, Original_Body
);
4690 Body_To_Analyze
:= Copy_Generic_Node
(Original_Body
, Empty
, False);
4692 -- Set return type of function, which is also global and does not
4693 -- need to be resolved.
4695 if Ekind
(Spec_Id
) = E_Function
then
4696 Set_Result_Definition
(Specification
(Body_To_Analyze
),
4697 New_Occurrence_Of
(Etype
(Spec_Id
), Sloc
(N
)));
4700 if No
(Declarations
(N
)) then
4701 Set_Declarations
(N
, New_List
(Body_To_Analyze
));
4703 Append_To
(Declarations
(N
), Body_To_Analyze
);
4706 Preanalyze
(Body_To_Analyze
);
4708 Push_Scope
(Defining_Entity
(Body_To_Analyze
));
4709 Save_Global_References
(Original_Body
);
4711 Remove
(Body_To_Analyze
);
4713 -- Restore environment if previously saved
4716 and then Scope
(Current_Scope
) /= Standard_Standard
4721 pragma Assert
(No
(Body_To_Inline
(Decl
)));
4722 Set_Body_To_Inline
(Decl
, Original_Body
);
4723 Set_Ekind
(Defining_Entity
(Original_Body
), Ekind
(Spec_Id
));
4724 end Build_Body_To_Inline
;
4726 --------------------------
4727 -- Check_Body_To_Inline --
4728 --------------------------
4730 function Check_Body_To_Inline
4732 Subp
: Entity_Id
) return Boolean
4734 Max_Size
: constant := 10;
4735 Stat_Count
: Integer := 0;
4737 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean;
4738 -- Check for declarations that make inlining not worthwhile
4740 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean;
4741 -- Check for statements that make inlining not worthwhile: any
4742 -- tasking statement, nested at any level. Keep track of total
4743 -- number of elementary statements, as a measure of acceptable size.
4745 function Has_Pending_Instantiation
return Boolean;
4746 -- Return True if some enclosing body contains instantiations that
4747 -- appear before the corresponding generic body.
4749 function Returns_Compile_Time_Constant
(N
: Node_Id
) return Boolean;
4750 -- Return True if all the return statements of the function body N
4751 -- are simple return statements and return a compile time constant
4753 function Returns_Intrinsic_Function_Call
(N
: Node_Id
) return Boolean;
4754 -- Return True if all the return statements of the function body N
4755 -- are simple return statements and return an intrinsic function call
4757 function Uses_Secondary_Stack
(N
: Node_Id
) return Boolean;
4758 -- If the body of the subprogram includes a call that returns an
4759 -- unconstrained type, the secondary stack is involved, and it
4760 -- is not worth inlining.
4762 ------------------------------
4763 -- Has_Excluded_Declaration --
4764 ------------------------------
4766 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean is
4769 function Is_Unchecked_Conversion
(D
: Node_Id
) return Boolean;
4770 -- Nested subprograms make a given body ineligible for inlining,
4771 -- but we make an exception for instantiations of unchecked
4772 -- conversion. The body has not been analyzed yet, so check the
4773 -- name, and verify that the visible entity with that name is the
4776 -----------------------------
4777 -- Is_Unchecked_Conversion --
4778 -----------------------------
4780 function Is_Unchecked_Conversion
(D
: Node_Id
) return Boolean is
4781 Id
: constant Node_Id
:= Name
(D
);
4785 if Nkind
(Id
) = N_Identifier
4786 and then Chars
(Id
) = Name_Unchecked_Conversion
4788 Conv
:= Current_Entity
(Id
);
4790 elsif Nkind_In
(Id
, N_Selected_Component
, N_Expanded_Name
)
4792 Chars
(Selector_Name
(Id
)) = Name_Unchecked_Conversion
4794 Conv
:= Current_Entity
(Selector_Name
(Id
));
4799 return Present
(Conv
)
4800 and then Is_Predefined_File_Name
4801 (Unit_File_Name
(Get_Source_Unit
(Conv
)))
4802 and then Is_Intrinsic_Subprogram
(Conv
);
4803 end Is_Unchecked_Conversion
;
4805 -- Start of processing for Has_Excluded_Declaration
4809 while Present
(D
) loop
4810 if (Nkind
(D
) = N_Function_Instantiation
4811 and then not Is_Unchecked_Conversion
(D
))
4812 or else Nkind_In
(D
, N_Protected_Type_Declaration
,
4813 N_Package_Declaration
,
4814 N_Package_Instantiation
,
4816 N_Procedure_Instantiation
,
4817 N_Task_Type_Declaration
)
4820 ("cannot inline & (non-allowed declaration)?", D
, Subp
);
4829 end Has_Excluded_Declaration
;
4831 ----------------------------
4832 -- Has_Excluded_Statement --
4833 ----------------------------
4835 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean is
4841 while Present
(S
) loop
4842 Stat_Count
:= Stat_Count
+ 1;
4844 if Nkind_In
(S
, N_Abort_Statement
,
4845 N_Asynchronous_Select
,
4846 N_Conditional_Entry_Call
,
4847 N_Delay_Relative_Statement
,
4848 N_Delay_Until_Statement
,
4853 ("cannot inline & (non-allowed statement)?", S
, Subp
);
4856 elsif Nkind
(S
) = N_Block_Statement
then
4857 if Present
(Declarations
(S
))
4858 and then Has_Excluded_Declaration
(Declarations
(S
))
4862 elsif Present
(Handled_Statement_Sequence
(S
)) then
4864 (Exception_Handlers
(Handled_Statement_Sequence
(S
)))
4867 ("cannot inline& (exception handler)?",
4868 First
(Exception_Handlers
4869 (Handled_Statement_Sequence
(S
))),
4873 elsif Has_Excluded_Statement
4874 (Statements
(Handled_Statement_Sequence
(S
)))
4880 elsif Nkind
(S
) = N_Case_Statement
then
4881 E
:= First
(Alternatives
(S
));
4882 while Present
(E
) loop
4883 if Has_Excluded_Statement
(Statements
(E
)) then
4890 elsif Nkind
(S
) = N_If_Statement
then
4891 if Has_Excluded_Statement
(Then_Statements
(S
)) then
4895 if Present
(Elsif_Parts
(S
)) then
4896 E
:= First
(Elsif_Parts
(S
));
4897 while Present
(E
) loop
4898 if Has_Excluded_Statement
(Then_Statements
(E
)) then
4905 if Present
(Else_Statements
(S
))
4906 and then Has_Excluded_Statement
(Else_Statements
(S
))
4911 elsif Nkind
(S
) = N_Loop_Statement
4912 and then Has_Excluded_Statement
(Statements
(S
))
4916 elsif Nkind
(S
) = N_Extended_Return_Statement
then
4917 if Present
(Handled_Statement_Sequence
(S
))
4919 Has_Excluded_Statement
4920 (Statements
(Handled_Statement_Sequence
(S
)))
4924 elsif Present
(Handled_Statement_Sequence
(S
))
4926 Present
(Exception_Handlers
4927 (Handled_Statement_Sequence
(S
)))
4930 ("cannot inline& (exception handler)?",
4931 First
(Exception_Handlers
4932 (Handled_Statement_Sequence
(S
))),
4942 end Has_Excluded_Statement
;
4944 -------------------------------
4945 -- Has_Pending_Instantiation --
4946 -------------------------------
4948 function Has_Pending_Instantiation
return Boolean is
4953 while Present
(S
) loop
4954 if Is_Compilation_Unit
(S
)
4955 or else Is_Child_Unit
(S
)
4959 elsif Ekind
(S
) = E_Package
4960 and then Has_Forward_Instantiation
(S
)
4969 end Has_Pending_Instantiation
;
4971 ------------------------------------
4972 -- Returns_Compile_Time_Constant --
4973 ------------------------------------
4975 function Returns_Compile_Time_Constant
(N
: Node_Id
) return Boolean is
4977 function Check_Return
(N
: Node_Id
) return Traverse_Result
;
4983 function Check_Return
(N
: Node_Id
) return Traverse_Result
is
4985 if Nkind
(N
) = N_Extended_Return_Statement
then
4988 elsif Nkind
(N
) = N_Simple_Return_Statement
then
4989 if Present
(Expression
(N
)) then
4991 Orig_Expr
: constant Node_Id
:=
4992 Original_Node
(Expression
(N
));
4995 if Nkind_In
(Orig_Expr
, N_Integer_Literal
,
4997 N_Character_Literal
)
5001 elsif Is_Entity_Name
(Orig_Expr
)
5002 and then Ekind
(Entity
(Orig_Expr
)) = E_Constant
5003 and then Is_Static_Expression
(Orig_Expr
)
5011 -- Expression has wrong form
5017 -- Continue analyzing statements
5024 function Check_All_Returns
is new Traverse_Func
(Check_Return
);
5026 -- Start of processing for Returns_Compile_Time_Constant
5029 return Check_All_Returns
(N
) = OK
;
5030 end Returns_Compile_Time_Constant
;
5032 --------------------------------------
5033 -- Returns_Intrinsic_Function_Call --
5034 --------------------------------------
5036 function Returns_Intrinsic_Function_Call
5037 (N
: Node_Id
) return Boolean
5039 function Check_Return
(N
: Node_Id
) return Traverse_Result
;
5045 function Check_Return
(N
: Node_Id
) return Traverse_Result
is
5047 if Nkind
(N
) = N_Extended_Return_Statement
then
5050 elsif Nkind
(N
) = N_Simple_Return_Statement
then
5051 if Present
(Expression
(N
)) then
5053 Orig_Expr
: constant Node_Id
:=
5054 Original_Node
(Expression
(N
));
5057 if Nkind
(Orig_Expr
) in N_Op
5058 and then Is_Intrinsic_Subprogram
(Entity
(Orig_Expr
))
5062 elsif Nkind
(Orig_Expr
) in N_Has_Entity
5063 and then Present
(Entity
(Orig_Expr
))
5064 and then Ekind
(Entity
(Orig_Expr
)) = E_Function
5065 and then Is_Inlined
(Entity
(Orig_Expr
))
5069 elsif Nkind
(Orig_Expr
) in N_Has_Entity
5070 and then Present
(Entity
(Orig_Expr
))
5071 and then Is_Intrinsic_Subprogram
(Entity
(Orig_Expr
))
5080 -- Expression has wrong form
5086 -- Continue analyzing statements
5093 function Check_All_Returns
is new Traverse_Func
(Check_Return
);
5095 -- Start of processing for Returns_Intrinsic_Function_Call
5098 return Check_All_Returns
(N
) = OK
;
5099 end Returns_Intrinsic_Function_Call
;
5101 --------------------------
5102 -- Uses_Secondary_Stack --
5103 --------------------------
5105 function Uses_Secondary_Stack
(N
: Node_Id
) return Boolean is
5107 function Check_Call
(N
: Node_Id
) return Traverse_Result
;
5108 -- Look for function calls that return an unconstrained type
5114 function Check_Call
(N
: Node_Id
) return Traverse_Result
is
5116 if Nkind
(N
) = N_Function_Call
5117 and then Is_Entity_Name
(Name
(N
))
5118 and then Is_Composite_Type
(Etype
(Entity
(Name
(N
))))
5119 and then not Is_Constrained
(Etype
(Entity
(Name
(N
))))
5122 ("cannot inline & (call returns unconstrained type)?",
5131 function Check_Calls
is new Traverse_Func
(Check_Call
);
5133 -- Start of processing for Uses_Secondary_Stack
5136 return Check_Calls
(N
) = Abandon
;
5137 end Uses_Secondary_Stack
;
5141 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Spec_Id
);
5142 May_Inline
: constant Boolean :=
5143 Has_Pragma_Inline_Always
(Spec_Id
)
5144 or else (Has_Pragma_Inline
(Spec_Id
)
5145 and then ((Optimization_Level
> 0
5146 and then Ekind
(Spec_Id
)
5148 or else Front_End_Inlining
));
5149 Body_To_Analyze
: Node_Id
;
5151 -- Start of processing for Check_Body_To_Inline
5154 -- No action needed in stubs since the attribute Body_To_Inline
5157 if Nkind
(Decl
) = N_Subprogram_Body_Stub
then
5160 -- Cannot build the body to inline if the attribute is already set.
5161 -- This attribute may have been set if this is a subprogram renaming
5162 -- declarations (see Freeze.Build_Renamed_Body).
5164 elsif Present
(Body_To_Inline
(Decl
)) then
5167 -- No action needed if the subprogram does not fulfill the minimum
5168 -- conditions to be inlined by the frontend
5170 elsif not May_Inline
then
5174 -- Check excluded declarations
5176 if Present
(Declarations
(N
))
5177 and then Has_Excluded_Declaration
(Declarations
(N
))
5182 -- Check excluded statements
5184 if Present
(Handled_Statement_Sequence
(N
)) then
5186 (Exception_Handlers
(Handled_Statement_Sequence
(N
)))
5189 ("cannot inline& (exception handler)?",
5191 (Exception_Handlers
(Handled_Statement_Sequence
(N
))),
5196 elsif Has_Excluded_Statement
5197 (Statements
(Handled_Statement_Sequence
(N
)))
5203 -- For backward compatibility, compiling under -gnatN we do not
5204 -- inline a subprogram that is too large, unless it is marked
5205 -- Inline_Always. This pragma does not suppress the other checks
5206 -- on inlining (forbidden declarations, handlers, etc).
5208 if Front_End_Inlining
5209 and then not Has_Pragma_Inline_Always
(Subp
)
5210 and then Stat_Count
> Max_Size
5212 Cannot_Inline
("cannot inline& (body too large)?", N
, Subp
);
5216 -- If some enclosing body contains instantiations that appear before
5217 -- the corresponding generic body, the enclosing body has a freeze
5218 -- node so that it can be elaborated after the generic itself. This
5219 -- might conflict with subsequent inlinings, so that it is unsafe to
5220 -- try to inline in such a case.
5222 if Has_Pending_Instantiation
then
5224 ("cannot inline& (forward instance within enclosing body)?",
5230 -- Generate and preanalyze the body to inline (needed to perform
5231 -- the rest of the checks)
5233 Generate_Body_To_Inline
(N
, Body_To_Analyze
);
5235 if Ekind
(Subp
) = E_Function
then
5236 Set_Result_Definition
(Specification
(Body_To_Analyze
),
5237 New_Occurrence_Of
(Etype
(Subp
), Sloc
(N
)));
5240 -- Nest the body to analyze within the real one
5242 if No
(Declarations
(N
)) then
5243 Set_Declarations
(N
, New_List
(Body_To_Analyze
));
5245 Append_To
(Declarations
(N
), Body_To_Analyze
);
5248 Preanalyze
(Body_To_Analyze
);
5249 Remove
(Body_To_Analyze
);
5251 -- Keep separate checks needed when compiling without optimizations
5253 if Optimization_Level
= 0
5255 -- AAMP and VM targets have no support for inlining in the backend
5256 -- and hence we use frontend inlining at all optimization levels.
5258 or else AAMP_On_Target
5259 or else VM_Target
/= No_VM
5261 -- Cannot inline functions whose body has a call that returns an
5262 -- unconstrained type since the secondary stack is involved, and
5263 -- it is not worth inlining.
5265 if Uses_Secondary_Stack
(Body_To_Analyze
) then
5268 -- Cannot inline functions that return controlled types since
5269 -- controlled actions interfere in complex ways with inlining.
5271 elsif Ekind
(Subp
) = E_Function
5272 and then Needs_Finalization
(Etype
(Subp
))
5275 ("cannot inline & (controlled return type)?", N
, Subp
);
5278 elsif Returns_Unconstrained_Type
(Subp
) then
5280 ("cannot inline & (unconstrained return type)?", N
, Subp
);
5284 -- Compiling with optimizations enabled
5287 -- Procedures are never frontend inlined in this case
5289 if Ekind
(Subp
) /= E_Function
then
5292 -- Functions returning unconstrained types are tested
5293 -- separately (see Can_Split_Unconstrained_Function).
5295 elsif Returns_Unconstrained_Type
(Subp
) then
5298 -- Check supported cases
5300 elsif not Returns_Compile_Time_Constant
(Body_To_Analyze
)
5301 and then Convention
(Subp
) /= Convention_Intrinsic
5302 and then not Returns_Intrinsic_Function_Call
(Body_To_Analyze
)
5309 end Check_Body_To_Inline
;
5311 --------------------------------------
5312 -- Can_Split_Unconstrained_Function --
5313 --------------------------------------
5315 function Can_Split_Unconstrained_Function
(N
: Node_Id
) return Boolean
5317 Ret_Node
: constant Node_Id
:=
5318 First
(Statements
(Handled_Statement_Sequence
(N
)));
5322 -- No user defined declarations allowed in the function except inside
5323 -- the unique return statement; implicit labels are the only allowed
5326 if not Is_Empty_List
(Declarations
(N
)) then
5327 D
:= First
(Declarations
(N
));
5328 while Present
(D
) loop
5329 if Nkind
(D
) /= N_Implicit_Label_Declaration
then
5337 -- We only split the inlined function when we are generating the code
5338 -- of its body; otherwise we leave duplicated split subprograms in
5339 -- the tree which (if referenced) generate wrong references at link
5342 return In_Extended_Main_Code_Unit
(N
)
5343 and then Present
(Ret_Node
)
5344 and then Nkind
(Ret_Node
) = N_Extended_Return_Statement
5345 and then No
(Next
(Ret_Node
))
5346 and then Present
(Handled_Statement_Sequence
(Ret_Node
));
5347 end Can_Split_Unconstrained_Function
;
5349 -----------------------------
5350 -- Generate_Body_To_Inline --
5351 -----------------------------
5353 procedure Generate_Body_To_Inline
5355 Body_To_Inline
: out Node_Id
)
5357 procedure Remove_Pragmas
(N
: Node_Id
);
5358 -- Remove occurrences of pragmas that may reference the formals of
5359 -- N. The analysis of the non-inlined body will handle these pragmas
5362 --------------------
5363 -- Remove_Pragmas --
5364 --------------------
5366 procedure Remove_Pragmas
(N
: Node_Id
) is
5371 Decl
:= First
(Declarations
(N
));
5372 while Present
(Decl
) loop
5375 if Nkind
(Decl
) = N_Pragma
5376 and then Nam_In
(Pragma_Name
(Decl
), Name_Unreferenced
,
5386 -- Start of processing for Generate_Body_To_Inline
5389 -- Within an instance, the body to inline must be treated as a nested
5390 -- generic, so that the proper global references are preserved.
5392 -- Note that we do not do this at the library level, because it
5393 -- is not needed, and furthermore this causes trouble if front
5394 -- end inlining is activated (-gnatN).
5397 and then Scope
(Current_Scope
) /= Standard_Standard
5399 Body_To_Inline
:= Copy_Generic_Node
(N
, Empty
, True);
5401 Body_To_Inline
:= Copy_Separate_Tree
(N
);
5404 -- A pragma Unreferenced or pragma Unmodified that mentions a formal
5405 -- parameter has no meaning when the body is inlined and the formals
5406 -- are rewritten. Remove it from body to inline. The analysis of the
5407 -- non-inlined body will handle the pragma properly.
5409 Remove_Pragmas
(Body_To_Inline
);
5411 -- We need to capture references to the formals in order
5412 -- to substitute the actuals at the point of inlining, i.e.
5413 -- instantiation. To treat the formals as globals to the body to
5414 -- inline, we nest it within a dummy parameterless subprogram,
5415 -- declared within the real one.
5417 Set_Parameter_Specifications
5418 (Specification
(Body_To_Inline
), No_List
);
5420 -- A new internal name is associated with Body_To_Inline to avoid
5421 -- conflicts when the non-inlined body N is analyzed.
5423 Set_Defining_Unit_Name
(Specification
(Body_To_Inline
),
5424 Make_Defining_Identifier
(Sloc
(N
), New_Internal_Name
('P')));
5425 Set_Corresponding_Spec
(Body_To_Inline
, Empty
);
5426 end Generate_Body_To_Inline
;
5428 ----------------------------------
5429 -- Split_Unconstrained_Function --
5430 ----------------------------------
5432 procedure Split_Unconstrained_Function
5434 Spec_Id
: Entity_Id
)
5436 Loc
: constant Source_Ptr
:= Sloc
(N
);
5437 Ret_Node
: constant Node_Id
:=
5438 First
(Statements
(Handled_Statement_Sequence
(N
)));
5439 Ret_Obj
: constant Node_Id
:=
5440 First
(Return_Object_Declarations
(Ret_Node
));
5442 procedure Build_Procedure
5443 (Proc_Id
: out Entity_Id
;
5444 Decl_List
: out List_Id
);
5445 -- Build a procedure containing the statements found in the extended
5446 -- return statement of the unconstrained function body N.
5448 procedure Build_Procedure
5449 (Proc_Id
: out Entity_Id
;
5450 Decl_List
: out List_Id
)
5453 Formal_List
: constant List_Id
:= New_List
;
5454 Proc_Spec
: Node_Id
;
5455 Proc_Body
: Node_Id
;
5456 Subp_Name
: constant Name_Id
:= New_Internal_Name
('F');
5457 Body_Decl_List
: List_Id
:= No_List
;
5458 Param_Type
: Node_Id
;
5461 if Nkind
(Object_Definition
(Ret_Obj
)) = N_Identifier
then
5462 Param_Type
:= New_Copy
(Object_Definition
(Ret_Obj
));
5465 New_Copy
(Subtype_Mark
(Object_Definition
(Ret_Obj
)));
5468 Append_To
(Formal_List
,
5469 Make_Parameter_Specification
(Loc
,
5470 Defining_Identifier
=>
5471 Make_Defining_Identifier
(Loc
,
5472 Chars
=> Chars
(Defining_Identifier
(Ret_Obj
))),
5473 In_Present
=> False,
5474 Out_Present
=> True,
5475 Null_Exclusion_Present
=> False,
5476 Parameter_Type
=> Param_Type
));
5478 Formal
:= First_Formal
(Spec_Id
);
5479 while Present
(Formal
) loop
5480 Append_To
(Formal_List
,
5481 Make_Parameter_Specification
(Loc
,
5482 Defining_Identifier
=>
5483 Make_Defining_Identifier
(Sloc
(Formal
),
5484 Chars
=> Chars
(Formal
)),
5485 In_Present
=> In_Present
(Parent
(Formal
)),
5486 Out_Present
=> Out_Present
(Parent
(Formal
)),
5487 Null_Exclusion_Present
=>
5488 Null_Exclusion_Present
(Parent
(Formal
)),
5490 New_Reference_To
(Etype
(Formal
), Loc
),
5492 Copy_Separate_Tree
(Expression
(Parent
(Formal
)))));
5494 Next_Formal
(Formal
);
5498 Make_Defining_Identifier
(Loc
, Chars
=> Subp_Name
);
5501 Make_Procedure_Specification
(Loc
,
5502 Defining_Unit_Name
=> Proc_Id
,
5503 Parameter_Specifications
=> Formal_List
);
5505 Decl_List
:= New_List
;
5507 Append_To
(Decl_List
,
5508 Make_Subprogram_Declaration
(Loc
, Proc_Spec
));
5510 -- Can_Convert_Unconstrained_Function checked that the function
5511 -- has no local declarations except implicit label declarations.
5512 -- Copy these declarations to the built procedure.
5514 if Present
(Declarations
(N
)) then
5515 Body_Decl_List
:= New_List
;
5522 D
:= First
(Declarations
(N
));
5523 while Present
(D
) loop
5524 pragma Assert
(Nkind
(D
) = N_Implicit_Label_Declaration
);
5527 Make_Implicit_Label_Declaration
(Loc
,
5528 Make_Defining_Identifier
(Loc
,
5529 Chars
=> Chars
(Defining_Identifier
(D
))),
5530 Label_Construct
=> Empty
);
5531 Append_To
(Body_Decl_List
, New_D
);
5538 pragma Assert
(Present
(Handled_Statement_Sequence
(Ret_Node
)));
5541 Make_Subprogram_Body
(Loc
,
5542 Specification
=> Copy_Separate_Tree
(Proc_Spec
),
5543 Declarations
=> Body_Decl_List
,
5544 Handled_Statement_Sequence
=>
5545 Copy_Separate_Tree
(Handled_Statement_Sequence
(Ret_Node
)));
5547 Set_Defining_Unit_Name
(Specification
(Proc_Body
),
5548 Make_Defining_Identifier
(Loc
, Subp_Name
));
5550 Append_To
(Decl_List
, Proc_Body
);
5551 end Build_Procedure
;
5555 New_Obj
: constant Node_Id
:= Copy_Separate_Tree
(Ret_Obj
);
5557 Proc_Id
: Entity_Id
;
5558 Proc_Call
: Node_Id
;
5560 -- Start of processing for Split_Unconstrained_Function
5563 -- Build the associated procedure, analyze it and insert it before
5564 -- the function body N
5567 Scope
: constant Entity_Id
:= Current_Scope
;
5568 Decl_List
: List_Id
;
5571 Build_Procedure
(Proc_Id
, Decl_List
);
5572 Insert_Actions
(N
, Decl_List
);
5576 -- Build the call to the generated procedure
5579 Actual_List
: constant List_Id
:= New_List
;
5583 Append_To
(Actual_List
,
5584 New_Reference_To
(Defining_Identifier
(New_Obj
), Loc
));
5586 Formal
:= First_Formal
(Spec_Id
);
5587 while Present
(Formal
) loop
5588 Append_To
(Actual_List
, New_Reference_To
(Formal
, Loc
));
5590 -- Avoid spurious warning on unreferenced formals
5592 Set_Referenced
(Formal
);
5593 Next_Formal
(Formal
);
5597 Make_Procedure_Call_Statement
(Loc
,
5598 Name
=> New_Reference_To
(Proc_Id
, Loc
),
5599 Parameter_Associations
=> Actual_List
);
5607 -- main_1__F1b (New_Obj, ...);
5612 Make_Block_Statement
(Loc
,
5613 Declarations
=> New_List
(New_Obj
),
5614 Handled_Statement_Sequence
=>
5615 Make_Handled_Sequence_Of_Statements
(Loc
,
5616 Statements
=> New_List
(
5620 Make_Simple_Return_Statement
(Loc
,
5623 (Defining_Identifier
(New_Obj
), Loc
)))));
5625 Rewrite
(Ret_Node
, Blk_Stmt
);
5626 end Split_Unconstrained_Function
;
5628 -- Start of processing for Check_And_Build_Body_To_Inline
5631 -- Do not inline any subprogram that contains nested subprograms, since
5632 -- the backend inlining circuit seems to generate uninitialized
5633 -- references in this case. We know this happens in the case of front
5634 -- end ZCX support, but it also appears it can happen in other cases as
5635 -- well. The backend often rejects attempts to inline in the case of
5636 -- nested procedures anyway, so little if anything is lost by this.
5637 -- Note that this is test is for the benefit of the back-end. There is
5638 -- a separate test for front-end inlining that also rejects nested
5641 -- Do not do this test if errors have been detected, because in some
5642 -- error cases, this code blows up, and we don't need it anyway if
5643 -- there have been errors, since we won't get to the linker anyway.
5645 if Comes_From_Source
(Body_Id
)
5646 and then (Has_Pragma_Inline_Always
(Spec_Id
)
5647 or else Optimization_Level
> 0)
5648 and then Serious_Errors_Detected
= 0
5656 P_Ent
:= Scope
(P_Ent
);
5657 exit when No
(P_Ent
) or else P_Ent
= Standard_Standard
;
5659 if Is_Subprogram
(P_Ent
) then
5660 Set_Is_Inlined
(P_Ent
, False);
5662 if Comes_From_Source
(P_Ent
)
5663 and then Has_Pragma_Inline
(P_Ent
)
5666 ("cannot inline& (nested subprogram)?", N
, P_Ent
,
5667 Is_Serious
=> True);
5674 -- Build the body to inline only if really needed
5676 if Check_Body_To_Inline
(N
, Spec_Id
)
5677 and then Serious_Errors_Detected
= 0
5679 if Returns_Unconstrained_Type
(Spec_Id
) then
5680 if Can_Split_Unconstrained_Function
(N
) then
5681 Split_Unconstrained_Function
(N
, Spec_Id
);
5682 Build_Body_To_Inline
(N
, Spec_Id
);
5683 Set_Is_Inlined
(Spec_Id
);
5686 Build_Body_To_Inline
(N
, Spec_Id
);
5687 Set_Is_Inlined
(Spec_Id
);
5690 end Check_And_Build_Body_To_Inline
;
5692 -----------------------
5693 -- Check_Conformance --
5694 -----------------------
5696 procedure Check_Conformance
5697 (New_Id
: Entity_Id
;
5699 Ctype
: Conformance_Type
;
5701 Conforms
: out Boolean;
5702 Err_Loc
: Node_Id
:= Empty
;
5703 Get_Inst
: Boolean := False;
5704 Skip_Controlling_Formals
: Boolean := False)
5706 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
5707 -- Sets Conforms to False. If Errmsg is False, then that's all it does.
5708 -- If Errmsg is True, then processing continues to post an error message
5709 -- for conformance error on given node. Two messages are output. The
5710 -- first message points to the previous declaration with a general "no
5711 -- conformance" message. The second is the detailed reason, supplied as
5712 -- Msg. The parameter N provide information for a possible & insertion
5713 -- in the message, and also provides the location for posting the
5714 -- message in the absence of a specified Err_Loc location.
5716 -----------------------
5717 -- Conformance_Error --
5718 -----------------------
5720 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
5727 if No
(Err_Loc
) then
5733 Error_Msg_Sloc
:= Sloc
(Old_Id
);
5736 when Type_Conformant
=>
5737 Error_Msg_N
-- CODEFIX
5738 ("not type conformant with declaration#!", Enode
);
5740 when Mode_Conformant
=>
5741 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
5743 ("not mode conformant with operation inherited#!",
5747 ("not mode conformant with declaration#!", Enode
);
5750 when Subtype_Conformant
=>
5751 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
5753 ("not subtype conformant with operation inherited#!",
5757 ("not subtype conformant with declaration#!", Enode
);
5760 when Fully_Conformant
=>
5761 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
5762 Error_Msg_N
-- CODEFIX
5763 ("not fully conformant with operation inherited#!",
5766 Error_Msg_N
-- CODEFIX
5767 ("not fully conformant with declaration#!", Enode
);
5771 Error_Msg_NE
(Msg
, Enode
, N
);
5773 end Conformance_Error
;
5777 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
5778 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
5779 Old_Formal
: Entity_Id
;
5780 New_Formal
: Entity_Id
;
5781 Access_Types_Match
: Boolean;
5782 Old_Formal_Base
: Entity_Id
;
5783 New_Formal_Base
: Entity_Id
;
5785 -- Start of processing for Check_Conformance
5790 -- We need a special case for operators, since they don't appear
5793 if Ctype
= Type_Conformant
then
5794 if Ekind
(New_Id
) = E_Operator
5795 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
5801 -- If both are functions/operators, check return types conform
5803 if Old_Type
/= Standard_Void_Type
5804 and then New_Type
/= Standard_Void_Type
5807 -- If we are checking interface conformance we omit controlling
5808 -- arguments and result, because we are only checking the conformance
5809 -- of the remaining parameters.
5811 if Has_Controlling_Result
(Old_Id
)
5812 and then Has_Controlling_Result
(New_Id
)
5813 and then Skip_Controlling_Formals
5817 elsif not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
5818 Conformance_Error
("\return type does not match!", New_Id
);
5822 -- Ada 2005 (AI-231): In case of anonymous access types check the
5823 -- null-exclusion and access-to-constant attributes match.
5825 if Ada_Version
>= Ada_2005
5826 and then Ekind
(Etype
(Old_Type
)) = E_Anonymous_Access_Type
5828 (Can_Never_Be_Null
(Old_Type
) /= Can_Never_Be_Null
(New_Type
)
5829 or else Is_Access_Constant
(Etype
(Old_Type
)) /=
5830 Is_Access_Constant
(Etype
(New_Type
)))
5832 Conformance_Error
("\return type does not match!", New_Id
);
5836 -- If either is a function/operator and the other isn't, error
5838 elsif Old_Type
/= Standard_Void_Type
5839 or else New_Type
/= Standard_Void_Type
5841 Conformance_Error
("\functions can only match functions!", New_Id
);
5845 -- In subtype conformant case, conventions must match (RM 6.3.1(16)).
5846 -- If this is a renaming as body, refine error message to indicate that
5847 -- the conflict is with the original declaration. If the entity is not
5848 -- frozen, the conventions don't have to match, the one of the renamed
5849 -- entity is inherited.
5851 if Ctype
>= Subtype_Conformant
then
5852 if Convention
(Old_Id
) /= Convention
(New_Id
) then
5853 if not Is_Frozen
(New_Id
) then
5856 elsif Present
(Err_Loc
)
5857 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
5858 and then Present
(Corresponding_Spec
(Err_Loc
))
5860 Error_Msg_Name_1
:= Chars
(New_Id
);
5862 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
5863 Conformance_Error
("\prior declaration for% has convention %!");
5866 Conformance_Error
("\calling conventions do not match!");
5871 elsif Is_Formal_Subprogram
(Old_Id
)
5872 or else Is_Formal_Subprogram
(New_Id
)
5874 Conformance_Error
("\formal subprograms not allowed!");
5879 -- Deal with parameters
5881 -- Note: we use the entity information, rather than going directly
5882 -- to the specification in the tree. This is not only simpler, but
5883 -- absolutely necessary for some cases of conformance tests between
5884 -- operators, where the declaration tree simply does not exist.
5886 Old_Formal
:= First_Formal
(Old_Id
);
5887 New_Formal
:= First_Formal
(New_Id
);
5888 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
5889 if Is_Controlling_Formal
(Old_Formal
)
5890 and then Is_Controlling_Formal
(New_Formal
)
5891 and then Skip_Controlling_Formals
5893 -- The controlling formals will have different types when
5894 -- comparing an interface operation with its match, but both
5895 -- or neither must be access parameters.
5897 if Is_Access_Type
(Etype
(Old_Formal
))
5899 Is_Access_Type
(Etype
(New_Formal
))
5901 goto Skip_Controlling_Formal
;
5904 ("\access parameter does not match!", New_Formal
);
5908 -- Ada 2012: Mode conformance also requires that formal parameters
5909 -- be both aliased, or neither.
5911 if Ctype
>= Mode_Conformant
and then Ada_Version
>= Ada_2012
then
5912 if Is_Aliased
(Old_Formal
) /= Is_Aliased
(New_Formal
) then
5914 ("\aliased parameter mismatch!", New_Formal
);
5918 if Ctype
= Fully_Conformant
then
5920 -- Names must match. Error message is more accurate if we do
5921 -- this before checking that the types of the formals match.
5923 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
5924 Conformance_Error
("\name & does not match!", New_Formal
);
5926 -- Set error posted flag on new formal as well to stop
5927 -- junk cascaded messages in some cases.
5929 Set_Error_Posted
(New_Formal
);
5933 -- Null exclusion must match
5935 if Null_Exclusion_Present
(Parent
(Old_Formal
))
5937 Null_Exclusion_Present
(Parent
(New_Formal
))
5939 -- Only give error if both come from source. This should be
5940 -- investigated some time, since it should not be needed ???
5942 if Comes_From_Source
(Old_Formal
)
5944 Comes_From_Source
(New_Formal
)
5947 ("\null exclusion for & does not match", New_Formal
);
5949 -- Mark error posted on the new formal to avoid duplicated
5950 -- complaint about types not matching.
5952 Set_Error_Posted
(New_Formal
);
5957 -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This
5958 -- case occurs whenever a subprogram is being renamed and one of its
5959 -- parameters imposes a null exclusion. For example:
5961 -- type T is null record;
5962 -- type Acc_T is access T;
5963 -- subtype Acc_T_Sub is Acc_T;
5965 -- procedure P (Obj : not null Acc_T_Sub); -- itype
5966 -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype
5969 Old_Formal_Base
:= Etype
(Old_Formal
);
5970 New_Formal_Base
:= Etype
(New_Formal
);
5973 Old_Formal_Base
:= Get_Instance_Of
(Old_Formal_Base
);
5974 New_Formal_Base
:= Get_Instance_Of
(New_Formal_Base
);
5977 Access_Types_Match
:= Ada_Version
>= Ada_2005
5979 -- Ensure that this rule is only applied when New_Id is a
5980 -- renaming of Old_Id.
5982 and then Nkind
(Parent
(Parent
(New_Id
))) =
5983 N_Subprogram_Renaming_Declaration
5984 and then Nkind
(Name
(Parent
(Parent
(New_Id
)))) in N_Has_Entity
5985 and then Present
(Entity
(Name
(Parent
(Parent
(New_Id
)))))
5986 and then Entity
(Name
(Parent
(Parent
(New_Id
)))) = Old_Id
5988 -- Now handle the allowed access-type case
5990 and then Is_Access_Type
(Old_Formal_Base
)
5991 and then Is_Access_Type
(New_Formal_Base
)
5993 -- The type kinds must match. The only exception occurs with
5994 -- multiple generics of the form:
5997 -- type F is private; type A is private;
5998 -- type F_Ptr is access F; type A_Ptr is access A;
5999 -- with proc F_P (X : F_Ptr); with proc A_P (X : A_Ptr);
6000 -- package F_Pack is ... package A_Pack is
6001 -- package F_Inst is
6002 -- new F_Pack (A, A_Ptr, A_P);
6004 -- When checking for conformance between the parameters of A_P
6005 -- and F_P, the type kinds of F_Ptr and A_Ptr will not match
6006 -- because the compiler has transformed A_Ptr into a subtype of
6007 -- F_Ptr. We catch this case in the code below.
6009 and then (Ekind
(Old_Formal_Base
) = Ekind
(New_Formal_Base
)
6011 (Is_Generic_Type
(Old_Formal_Base
)
6012 and then Is_Generic_Type
(New_Formal_Base
)
6013 and then Is_Internal
(New_Formal_Base
)
6014 and then Etype
(Etype
(New_Formal_Base
)) =
6016 and then Directly_Designated_Type
(Old_Formal_Base
) =
6017 Directly_Designated_Type
(New_Formal_Base
)
6018 and then ((Is_Itype
(Old_Formal_Base
)
6019 and then Can_Never_Be_Null
(Old_Formal_Base
))
6021 (Is_Itype
(New_Formal_Base
)
6022 and then Can_Never_Be_Null
(New_Formal_Base
)));
6024 -- Types must always match. In the visible part of an instance,
6025 -- usual overloading rules for dispatching operations apply, and
6026 -- we check base types (not the actual subtypes).
6028 if In_Instance_Visible_Part
6029 and then Is_Dispatching_Operation
(New_Id
)
6031 if not Conforming_Types
6032 (T1
=> Base_Type
(Etype
(Old_Formal
)),
6033 T2
=> Base_Type
(Etype
(New_Formal
)),
6035 Get_Inst
=> Get_Inst
)
6036 and then not Access_Types_Match
6038 Conformance_Error
("\type of & does not match!", New_Formal
);
6042 elsif not Conforming_Types
6043 (T1
=> Old_Formal_Base
,
6044 T2
=> New_Formal_Base
,
6046 Get_Inst
=> Get_Inst
)
6047 and then not Access_Types_Match
6049 -- Don't give error message if old type is Any_Type. This test
6050 -- avoids some cascaded errors, e.g. in case of a bad spec.
6052 if Errmsg
and then Old_Formal_Base
= Any_Type
then
6055 Conformance_Error
("\type of & does not match!", New_Formal
);
6061 -- For mode conformance, mode must match
6063 if Ctype
>= Mode_Conformant
then
6064 if Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
) then
6065 if not Ekind_In
(New_Id
, E_Function
, E_Procedure
)
6066 or else not Is_Primitive_Wrapper
(New_Id
)
6068 Conformance_Error
("\mode of & does not match!", New_Formal
);
6072 T
: constant Entity_Id
:= Find_Dispatching_Type
(New_Id
);
6074 if Is_Protected_Type
6075 (Corresponding_Concurrent_Type
(T
))
6077 Error_Msg_PT
(T
, New_Id
);
6080 ("\mode of & does not match!", New_Formal
);
6087 -- Part of mode conformance for access types is having the same
6088 -- constant modifier.
6090 elsif Access_Types_Match
6091 and then Is_Access_Constant
(Old_Formal_Base
) /=
6092 Is_Access_Constant
(New_Formal_Base
)
6095 ("\constant modifier does not match!", New_Formal
);
6100 if Ctype
>= Subtype_Conformant
then
6102 -- Ada 2005 (AI-231): In case of anonymous access types check
6103 -- the null-exclusion and access-to-constant attributes must
6104 -- match. For null exclusion, we test the types rather than the
6105 -- formals themselves, since the attribute is only set reliably
6106 -- on the formals in the Ada 95 case, and we exclude the case
6107 -- where Old_Formal is marked as controlling, to avoid errors
6108 -- when matching completing bodies with dispatching declarations
6109 -- (access formals in the bodies aren't marked Can_Never_Be_Null).
6111 if Ada_Version
>= Ada_2005
6112 and then Ekind
(Etype
(Old_Formal
)) = E_Anonymous_Access_Type
6113 and then Ekind
(Etype
(New_Formal
)) = E_Anonymous_Access_Type
6115 ((Can_Never_Be_Null
(Etype
(Old_Formal
)) /=
6116 Can_Never_Be_Null
(Etype
(New_Formal
))
6118 not Is_Controlling_Formal
(Old_Formal
))
6120 Is_Access_Constant
(Etype
(Old_Formal
)) /=
6121 Is_Access_Constant
(Etype
(New_Formal
)))
6123 -- Do not complain if error already posted on New_Formal. This
6124 -- avoids some redundant error messages.
6126 and then not Error_Posted
(New_Formal
)
6128 -- It is allowed to omit the null-exclusion in case of stream
6129 -- attribute subprograms. We recognize stream subprograms
6130 -- through their TSS-generated suffix.
6133 TSS_Name
: constant TSS_Name_Type
:= Get_TSS_Name
(New_Id
);
6136 if TSS_Name
/= TSS_Stream_Read
6137 and then TSS_Name
/= TSS_Stream_Write
6138 and then TSS_Name
/= TSS_Stream_Input
6139 and then TSS_Name
/= TSS_Stream_Output
6141 -- Here we have a definite conformance error. It is worth
6142 -- special casing the error message for the case of a
6143 -- controlling formal (which excludes null).
6145 if Is_Controlling_Formal
(New_Formal
) then
6146 Error_Msg_Node_2
:= Scope
(New_Formal
);
6148 ("\controlling formal& of& excludes null, "
6149 & "declaration must exclude null as well",
6152 -- Normal case (couldn't we give more detail here???)
6156 ("\type of & does not match!", New_Formal
);
6165 -- Full conformance checks
6167 if Ctype
= Fully_Conformant
then
6169 -- We have checked already that names match
6171 if Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
6173 -- Check default expressions for in parameters
6176 NewD
: constant Boolean :=
6177 Present
(Default_Value
(New_Formal
));
6178 OldD
: constant Boolean :=
6179 Present
(Default_Value
(Old_Formal
));
6181 if NewD
or OldD
then
6183 -- The old default value has been analyzed because the
6184 -- current full declaration will have frozen everything
6185 -- before. The new default value has not been analyzed,
6186 -- so analyze it now before we check for conformance.
6189 Push_Scope
(New_Id
);
6190 Preanalyze_Spec_Expression
6191 (Default_Value
(New_Formal
), Etype
(New_Formal
));
6195 if not (NewD
and OldD
)
6196 or else not Fully_Conformant_Expressions
6197 (Default_Value
(Old_Formal
),
6198 Default_Value
(New_Formal
))
6201 ("\default expression for & does not match!",
6210 -- A couple of special checks for Ada 83 mode. These checks are
6211 -- skipped if either entity is an operator in package Standard,
6212 -- or if either old or new instance is not from the source program.
6214 if Ada_Version
= Ada_83
6215 and then Sloc
(Old_Id
) > Standard_Location
6216 and then Sloc
(New_Id
) > Standard_Location
6217 and then Comes_From_Source
(Old_Id
)
6218 and then Comes_From_Source
(New_Id
)
6221 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
6222 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
6225 -- Explicit IN must be present or absent in both cases. This
6226 -- test is required only in the full conformance case.
6228 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
6229 and then Ctype
= Fully_Conformant
6232 ("\(Ada 83) IN must appear in both declarations",
6237 -- Grouping (use of comma in param lists) must be the same
6238 -- This is where we catch a misconformance like:
6241 -- A : Integer; B : Integer
6243 -- which are represented identically in the tree except
6244 -- for the setting of the flags More_Ids and Prev_Ids.
6246 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
6247 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
6250 ("\grouping of & does not match!", New_Formal
);
6256 -- This label is required when skipping controlling formals
6258 <<Skip_Controlling_Formal
>>
6260 Next_Formal
(Old_Formal
);
6261 Next_Formal
(New_Formal
);
6264 if Present
(Old_Formal
) then
6265 Conformance_Error
("\too few parameters!");
6268 elsif Present
(New_Formal
) then
6269 Conformance_Error
("\too many parameters!", New_Formal
);
6272 end Check_Conformance
;
6274 -----------------------
6275 -- Check_Conventions --
6276 -----------------------
6278 procedure Check_Conventions
(Typ
: Entity_Id
) is
6279 Ifaces_List
: Elist_Id
;
6281 procedure Check_Convention
(Op
: Entity_Id
);
6282 -- Verify that the convention of inherited dispatching operation Op is
6283 -- consistent among all subprograms it overrides. In order to minimize
6284 -- the search, Search_From is utilized to designate a specific point in
6285 -- the list rather than iterating over the whole list once more.
6287 ----------------------
6288 -- Check_Convention --
6289 ----------------------
6291 procedure Check_Convention
(Op
: Entity_Id
) is
6292 function Convention_Of
(Id
: Entity_Id
) return Convention_Id
;
6293 -- Given an entity, return its convention. The function treats Ghost
6294 -- as convention Ada because the two have the same dynamic semantics.
6300 function Convention_Of
(Id
: Entity_Id
) return Convention_Id
is
6301 Conv
: constant Convention_Id
:= Convention
(Id
);
6303 if Conv
= Convention_Ghost
then
6304 return Convention_Ada
;
6312 Op_Conv
: constant Convention_Id
:= Convention_Of
(Op
);
6313 Iface_Conv
: Convention_Id
;
6314 Iface_Elmt
: Elmt_Id
;
6315 Iface_Prim_Elmt
: Elmt_Id
;
6316 Iface_Prim
: Entity_Id
;
6318 -- Start of processing for Check_Convention
6321 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
6322 while Present
(Iface_Elmt
) loop
6324 First_Elmt
(Primitive_Operations
(Node
(Iface_Elmt
)));
6325 while Present
(Iface_Prim_Elmt
) loop
6326 Iface_Prim
:= Node
(Iface_Prim_Elmt
);
6327 Iface_Conv
:= Convention_Of
(Iface_Prim
);
6329 if Is_Interface_Conformant
(Typ
, Iface_Prim
, Op
)
6330 and then Iface_Conv
/= Op_Conv
6333 ("inconsistent conventions in primitive operations", Typ
);
6335 Error_Msg_Name_1
:= Chars
(Op
);
6336 Error_Msg_Name_2
:= Get_Convention_Name
(Op_Conv
);
6337 Error_Msg_Sloc
:= Sloc
(Op
);
6339 if Comes_From_Source
(Op
) or else No
(Alias
(Op
)) then
6340 if not Present
(Overridden_Operation
(Op
)) then
6341 Error_Msg_N
("\\primitive % defined #", Typ
);
6344 ("\\overriding operation % with " &
6345 "convention % defined #", Typ
);
6348 else pragma Assert
(Present
(Alias
(Op
)));
6349 Error_Msg_Sloc
:= Sloc
(Alias
(Op
));
6351 ("\\inherited operation % with " &
6352 "convention % defined #", Typ
);
6355 Error_Msg_Name_1
:= Chars
(Op
);
6356 Error_Msg_Name_2
:= Get_Convention_Name
(Iface_Conv
);
6357 Error_Msg_Sloc
:= Sloc
(Iface_Prim
);
6359 ("\\overridden operation % with " &
6360 "convention % defined #", Typ
);
6362 -- Avoid cascading errors
6367 Next_Elmt
(Iface_Prim_Elmt
);
6370 Next_Elmt
(Iface_Elmt
);
6372 end Check_Convention
;
6376 Prim_Op
: Entity_Id
;
6377 Prim_Op_Elmt
: Elmt_Id
;
6379 -- Start of processing for Check_Conventions
6382 if not Has_Interfaces
(Typ
) then
6386 Collect_Interfaces
(Typ
, Ifaces_List
);
6388 -- The algorithm checks every overriding dispatching operation against
6389 -- all the corresponding overridden dispatching operations, detecting
6390 -- differences in conventions.
6392 Prim_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6393 while Present
(Prim_Op_Elmt
) loop
6394 Prim_Op
:= Node
(Prim_Op_Elmt
);
6396 -- A small optimization: skip the predefined dispatching operations
6397 -- since they always have the same convention.
6399 if not Is_Predefined_Dispatching_Operation
(Prim_Op
) then
6400 Check_Convention
(Prim_Op
);
6403 Next_Elmt
(Prim_Op_Elmt
);
6405 end Check_Conventions
;
6407 ------------------------------
6408 -- Check_Delayed_Subprogram --
6409 ------------------------------
6411 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
6414 procedure Possible_Freeze
(T
: Entity_Id
);
6415 -- T is the type of either a formal parameter or of the return type.
6416 -- If T is not yet frozen and needs a delayed freeze, then the
6417 -- subprogram itself must be delayed. If T is the limited view of an
6418 -- incomplete type the subprogram must be frozen as well, because
6419 -- T may depend on local types that have not been frozen yet.
6421 ---------------------
6422 -- Possible_Freeze --
6423 ---------------------
6425 procedure Possible_Freeze
(T
: Entity_Id
) is
6427 if Has_Delayed_Freeze
(T
) and then not Is_Frozen
(T
) then
6428 Set_Has_Delayed_Freeze
(Designator
);
6430 elsif Is_Access_Type
(T
)
6431 and then Has_Delayed_Freeze
(Designated_Type
(T
))
6432 and then not Is_Frozen
(Designated_Type
(T
))
6434 Set_Has_Delayed_Freeze
(Designator
);
6436 elsif Ekind
(T
) = E_Incomplete_Type
6437 and then From_Limited_With
(T
)
6439 Set_Has_Delayed_Freeze
(Designator
);
6441 -- AI05-0151: In Ada 2012, Incomplete types can appear in the profile
6442 -- of a subprogram or entry declaration.
6444 elsif Ekind
(T
) = E_Incomplete_Type
6445 and then Ada_Version
>= Ada_2012
6447 Set_Has_Delayed_Freeze
(Designator
);
6450 end Possible_Freeze
;
6452 -- Start of processing for Check_Delayed_Subprogram
6455 -- All subprograms, including abstract subprograms, may need a freeze
6456 -- node if some formal type or the return type needs one.
6458 Possible_Freeze
(Etype
(Designator
));
6459 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
6461 -- Need delayed freeze if any of the formal types themselves need
6462 -- a delayed freeze and are not yet frozen.
6464 F
:= First_Formal
(Designator
);
6465 while Present
(F
) loop
6466 Possible_Freeze
(Etype
(F
));
6467 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
6471 -- Mark functions that return by reference. Note that it cannot be
6472 -- done for delayed_freeze subprograms because the underlying
6473 -- returned type may not be known yet (for private types)
6475 if not Has_Delayed_Freeze
(Designator
) and then Expander_Active
then
6477 Typ
: constant Entity_Id
:= Etype
(Designator
);
6478 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
6480 if Is_Limited_View
(Typ
) then
6481 Set_Returns_By_Ref
(Designator
);
6482 elsif Present
(Utyp
) and then CW_Or_Has_Controlled_Part
(Utyp
) then
6483 Set_Returns_By_Ref
(Designator
);
6487 end Check_Delayed_Subprogram
;
6489 ------------------------------------
6490 -- Check_Discriminant_Conformance --
6491 ------------------------------------
6493 procedure Check_Discriminant_Conformance
6498 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
6499 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
6500 New_Discr_Id
: Entity_Id
;
6501 New_Discr_Type
: Entity_Id
;
6503 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
6504 -- Post error message for conformance error on given node. Two messages
6505 -- are output. The first points to the previous declaration with a
6506 -- general "no conformance" message. The second is the detailed reason,
6507 -- supplied as Msg. The parameter N provide information for a possible
6508 -- & insertion in the message.
6510 -----------------------
6511 -- Conformance_Error --
6512 -----------------------
6514 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
6516 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
6517 Error_Msg_N
-- CODEFIX
6518 ("not fully conformant with declaration#!", N
);
6519 Error_Msg_NE
(Msg
, N
, N
);
6520 end Conformance_Error
;
6522 -- Start of processing for Check_Discriminant_Conformance
6525 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
6526 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
6528 -- The subtype mark of the discriminant on the full type has not
6529 -- been analyzed so we do it here. For an access discriminant a new
6532 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
6534 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
6537 Analyze
(Discriminant_Type
(New_Discr
));
6538 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
6540 -- Ada 2005: if the discriminant definition carries a null
6541 -- exclusion, create an itype to check properly for consistency
6542 -- with partial declaration.
6544 if Is_Access_Type
(New_Discr_Type
)
6545 and then Null_Exclusion_Present
(New_Discr
)
6548 Create_Null_Excluding_Itype
6549 (T
=> New_Discr_Type
,
6550 Related_Nod
=> New_Discr
,
6551 Scope_Id
=> Current_Scope
);
6555 if not Conforming_Types
6556 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
6558 Conformance_Error
("type of & does not match!", New_Discr_Id
);
6561 -- Treat the new discriminant as an occurrence of the old one,
6562 -- for navigation purposes, and fill in some semantic
6563 -- information, for completeness.
6565 Generate_Reference
(Old_Discr
, New_Discr_Id
, 'r');
6566 Set_Etype
(New_Discr_Id
, Etype
(Old_Discr
));
6567 Set_Scope
(New_Discr_Id
, Scope
(Old_Discr
));
6572 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
6573 Conformance_Error
("name & does not match!", New_Discr_Id
);
6577 -- Default expressions must match
6580 NewD
: constant Boolean :=
6581 Present
(Expression
(New_Discr
));
6582 OldD
: constant Boolean :=
6583 Present
(Expression
(Parent
(Old_Discr
)));
6586 if NewD
or OldD
then
6588 -- The old default value has been analyzed and expanded,
6589 -- because the current full declaration will have frozen
6590 -- everything before. The new default values have not been
6591 -- expanded, so expand now to check conformance.
6594 Preanalyze_Spec_Expression
6595 (Expression
(New_Discr
), New_Discr_Type
);
6598 if not (NewD
and OldD
)
6599 or else not Fully_Conformant_Expressions
6600 (Expression
(Parent
(Old_Discr
)),
6601 Expression
(New_Discr
))
6605 ("default expression for & does not match!",
6612 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
6614 if Ada_Version
= Ada_83
then
6616 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
6619 -- Grouping (use of comma in param lists) must be the same
6620 -- This is where we catch a misconformance like:
6623 -- A : Integer; B : Integer
6625 -- which are represented identically in the tree except
6626 -- for the setting of the flags More_Ids and Prev_Ids.
6628 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
6629 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
6632 ("grouping of & does not match!", New_Discr_Id
);
6638 Next_Discriminant
(Old_Discr
);
6642 if Present
(Old_Discr
) then
6643 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
6646 elsif Present
(New_Discr
) then
6648 ("too many discriminants!", Defining_Identifier
(New_Discr
));
6651 end Check_Discriminant_Conformance
;
6653 ----------------------------
6654 -- Check_Fully_Conformant --
6655 ----------------------------
6657 procedure Check_Fully_Conformant
6658 (New_Id
: Entity_Id
;
6660 Err_Loc
: Node_Id
:= Empty
)
6663 pragma Warnings
(Off
, Result
);
6666 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
6667 end Check_Fully_Conformant
;
6669 ---------------------------
6670 -- Check_Mode_Conformant --
6671 ---------------------------
6673 procedure Check_Mode_Conformant
6674 (New_Id
: Entity_Id
;
6676 Err_Loc
: Node_Id
:= Empty
;
6677 Get_Inst
: Boolean := False)
6680 pragma Warnings
(Off
, Result
);
6683 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
6684 end Check_Mode_Conformant
;
6686 --------------------------------
6687 -- Check_Overriding_Indicator --
6688 --------------------------------
6690 procedure Check_Overriding_Indicator
6692 Overridden_Subp
: Entity_Id
;
6693 Is_Primitive
: Boolean)
6699 -- No overriding indicator for literals
6701 if Ekind
(Subp
) = E_Enumeration_Literal
then
6704 elsif Ekind
(Subp
) = E_Entry
then
6705 Decl
:= Parent
(Subp
);
6707 -- No point in analyzing a malformed operator
6709 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
6710 and then Error_Posted
(Subp
)
6715 Decl
:= Unit_Declaration_Node
(Subp
);
6718 if Nkind_In
(Decl
, N_Subprogram_Body
,
6719 N_Subprogram_Body_Stub
,
6720 N_Subprogram_Declaration
,
6721 N_Abstract_Subprogram_Declaration
,
6722 N_Subprogram_Renaming_Declaration
)
6724 Spec
:= Specification
(Decl
);
6726 elsif Nkind
(Decl
) = N_Entry_Declaration
then
6733 -- The overriding operation is type conformant with the overridden one,
6734 -- but the names of the formals are not required to match. If the names
6735 -- appear permuted in the overriding operation, this is a possible
6736 -- source of confusion that is worth diagnosing. Controlling formals
6737 -- often carry names that reflect the type, and it is not worthwhile
6738 -- requiring that their names match.
6740 if Present
(Overridden_Subp
)
6741 and then Nkind
(Subp
) /= N_Defining_Operator_Symbol
6748 Form1
:= First_Formal
(Subp
);
6749 Form2
:= First_Formal
(Overridden_Subp
);
6751 -- If the overriding operation is a synchronized operation, skip
6752 -- the first parameter of the overridden operation, which is
6753 -- implicit in the new one. If the operation is declared in the
6754 -- body it is not primitive and all formals must match.
6756 if Is_Concurrent_Type
(Scope
(Subp
))
6757 and then Is_Tagged_Type
(Scope
(Subp
))
6758 and then not Has_Completion
(Scope
(Subp
))
6760 Form2
:= Next_Formal
(Form2
);
6763 if Present
(Form1
) then
6764 Form1
:= Next_Formal
(Form1
);
6765 Form2
:= Next_Formal
(Form2
);
6768 while Present
(Form1
) loop
6769 if not Is_Controlling_Formal
(Form1
)
6770 and then Present
(Next_Formal
(Form2
))
6771 and then Chars
(Form1
) = Chars
(Next_Formal
(Form2
))
6773 Error_Msg_Node_2
:= Alias
(Overridden_Subp
);
6774 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
6776 ("& does not match corresponding formal of&#",
6781 Next_Formal
(Form1
);
6782 Next_Formal
(Form2
);
6787 -- If there is an overridden subprogram, then check that there is no
6788 -- "not overriding" indicator, and mark the subprogram as overriding.
6789 -- This is not done if the overridden subprogram is marked as hidden,
6790 -- which can occur for the case of inherited controlled operations
6791 -- (see Derive_Subprogram), unless the inherited subprogram's parent
6792 -- subprogram is not itself hidden. (Note: This condition could probably
6793 -- be simplified, leaving out the testing for the specific controlled
6794 -- cases, but it seems safer and clearer this way, and echoes similar
6795 -- special-case tests of this kind in other places.)
6797 if Present
(Overridden_Subp
)
6798 and then (not Is_Hidden
(Overridden_Subp
)
6800 (Nam_In
(Chars
(Overridden_Subp
), Name_Initialize
,
6803 and then Present
(Alias
(Overridden_Subp
))
6804 and then not Is_Hidden
(Alias
(Overridden_Subp
))))
6806 if Must_Not_Override
(Spec
) then
6807 Error_Msg_Sloc
:= Sloc
(Overridden_Subp
);
6809 if Ekind
(Subp
) = E_Entry
then
6811 ("entry & overrides inherited operation #", Spec
, Subp
);
6814 ("subprogram & overrides inherited operation #", Spec
, Subp
);
6817 -- Special-case to fix a GNAT oddity: Limited_Controlled is declared
6818 -- as an extension of Root_Controlled, and thus has a useless Adjust
6819 -- operation. This operation should not be inherited by other limited
6820 -- controlled types. An explicit Adjust for them is not overriding.
6822 elsif Must_Override
(Spec
)
6823 and then Chars
(Overridden_Subp
) = Name_Adjust
6824 and then Is_Limited_Type
(Etype
(First_Formal
(Subp
)))
6825 and then Present
(Alias
(Overridden_Subp
))
6827 Is_Predefined_File_Name
6828 (Unit_File_Name
(Get_Source_Unit
(Alias
(Overridden_Subp
))))
6830 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6832 elsif Is_Subprogram
(Subp
) then
6833 if Is_Init_Proc
(Subp
) then
6836 elsif No
(Overridden_Operation
(Subp
)) then
6838 -- For entities generated by Derive_Subprograms the overridden
6839 -- operation is the inherited primitive (which is available
6840 -- through the attribute alias)
6842 if (Is_Dispatching_Operation
(Subp
)
6843 or else Is_Dispatching_Operation
(Overridden_Subp
))
6844 and then not Comes_From_Source
(Overridden_Subp
)
6845 and then Find_Dispatching_Type
(Overridden_Subp
) =
6846 Find_Dispatching_Type
(Subp
)
6847 and then Present
(Alias
(Overridden_Subp
))
6848 and then Comes_From_Source
(Alias
(Overridden_Subp
))
6850 Set_Overridden_Operation
(Subp
, Alias
(Overridden_Subp
));
6853 Set_Overridden_Operation
(Subp
, Overridden_Subp
);
6858 -- If primitive flag is set or this is a protected operation, then
6859 -- the operation is overriding at the point of its declaration, so
6860 -- warn if necessary. Otherwise it may have been declared before the
6861 -- operation it overrides and no check is required.
6864 and then not Must_Override
(Spec
)
6865 and then (Is_Primitive
6866 or else Ekind
(Scope
(Subp
)) = E_Protected_Type
)
6868 Style
.Missing_Overriding
(Decl
, Subp
);
6871 -- If Subp is an operator, it may override a predefined operation, if
6872 -- it is defined in the same scope as the type to which it applies.
6873 -- In that case Overridden_Subp is empty because of our implicit
6874 -- representation for predefined operators. We have to check whether the
6875 -- signature of Subp matches that of a predefined operator. Note that
6876 -- first argument provides the name of the operator, and the second
6877 -- argument the signature that may match that of a standard operation.
6878 -- If the indicator is overriding, then the operator must match a
6879 -- predefined signature, because we know already that there is no
6880 -- explicit overridden operation.
6882 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
then
6883 if Must_Not_Override
(Spec
) then
6885 -- If this is not a primitive or a protected subprogram, then
6886 -- "not overriding" is illegal.
6889 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
6892 ("overriding indicator only allowed "
6893 & "if subprogram is primitive", Subp
);
6895 elsif Can_Override_Operator
(Subp
) then
6897 ("subprogram& overrides predefined operator ", Spec
, Subp
);
6900 elsif Must_Override
(Spec
) then
6901 if No
(Overridden_Operation
(Subp
))
6902 and then not Can_Override_Operator
(Subp
)
6904 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6907 elsif not Error_Posted
(Subp
)
6908 and then Style_Check
6909 and then Can_Override_Operator
(Subp
)
6911 not Is_Predefined_File_Name
6912 (Unit_File_Name
(Get_Source_Unit
(Subp
)))
6914 -- If style checks are enabled, indicate that the indicator is
6915 -- missing. However, at the point of declaration, the type of
6916 -- which this is a primitive operation may be private, in which
6917 -- case the indicator would be premature.
6919 if Has_Private_Declaration
(Etype
(Subp
))
6920 or else Has_Private_Declaration
(Etype
(First_Formal
(Subp
)))
6924 Style
.Missing_Overriding
(Decl
, Subp
);
6928 elsif Must_Override
(Spec
) then
6929 if Ekind
(Subp
) = E_Entry
then
6930 Error_Msg_NE
("entry & is not overriding", Spec
, Subp
);
6932 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6935 -- If the operation is marked "not overriding" and it's not primitive
6936 -- then an error is issued, unless this is an operation of a task or
6937 -- protected type (RM05-8.3.1(3/2-4/2)). Error cases where "overriding"
6938 -- has been specified have already been checked above.
6940 elsif Must_Not_Override
(Spec
)
6941 and then not Is_Primitive
6942 and then Ekind
(Subp
) /= E_Entry
6943 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
6946 ("overriding indicator only allowed if subprogram is primitive",
6950 end Check_Overriding_Indicator
;
6956 -- Note: this procedure needs to know far too much about how the expander
6957 -- messes with exceptions. The use of the flag Exception_Junk and the
6958 -- incorporation of knowledge of Exp_Ch11.Expand_Local_Exception_Handlers
6959 -- works, but is not very clean. It would be better if the expansion
6960 -- routines would leave Original_Node working nicely, and we could use
6961 -- Original_Node here to ignore all the peculiar expander messing ???
6963 procedure Check_Returns
6967 Proc
: Entity_Id
:= Empty
)
6971 procedure Check_Statement_Sequence
(L
: List_Id
);
6972 -- Internal recursive procedure to check a list of statements for proper
6973 -- termination by a return statement (or a transfer of control or a
6974 -- compound statement that is itself internally properly terminated).
6976 ------------------------------
6977 -- Check_Statement_Sequence --
6978 ------------------------------
6980 procedure Check_Statement_Sequence
(L
: List_Id
) is
6985 Raise_Exception_Call
: Boolean;
6986 -- Set True if statement sequence terminated by Raise_Exception call
6987 -- or a Reraise_Occurrence call.
6990 Raise_Exception_Call
:= False;
6992 -- Get last real statement
6994 Last_Stm
:= Last
(L
);
6996 -- Deal with digging out exception handler statement sequences that
6997 -- have been transformed by the local raise to goto optimization.
6998 -- See Exp_Ch11.Expand_Local_Exception_Handlers for details. If this
6999 -- optimization has occurred, we are looking at something like:
7002 -- original stmts in block
7006 -- goto L1; | omitted if No_Exception_Propagation
7011 -- goto L3; -- skip handler when exception not raised
7013 -- <<L1>> -- target label for local exception
7027 -- and what we have to do is to dig out the estmts1 and estmts2
7028 -- sequences (which were the original sequences of statements in
7029 -- the exception handlers) and check them.
7031 if Nkind
(Last_Stm
) = N_Label
and then Exception_Junk
(Last_Stm
) then
7036 exit when Nkind
(Stm
) /= N_Block_Statement
;
7037 exit when not Exception_Junk
(Stm
);
7040 exit when Nkind
(Stm
) /= N_Label
;
7041 exit when not Exception_Junk
(Stm
);
7042 Check_Statement_Sequence
7043 (Statements
(Handled_Statement_Sequence
(Next
(Stm
))));
7048 exit when Nkind
(Stm
) /= N_Goto_Statement
;
7049 exit when not Exception_Junk
(Stm
);
7053 -- Don't count pragmas
7055 while Nkind
(Last_Stm
) = N_Pragma
7057 -- Don't count call to SS_Release (can happen after Raise_Exception)
7060 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
7062 Nkind
(Name
(Last_Stm
)) = N_Identifier
7064 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
7066 -- Don't count exception junk
7069 (Nkind_In
(Last_Stm
, N_Goto_Statement
,
7071 N_Object_Declaration
)
7072 and then Exception_Junk
(Last_Stm
))
7073 or else Nkind
(Last_Stm
) in N_Push_xxx_Label
7074 or else Nkind
(Last_Stm
) in N_Pop_xxx_Label
7076 -- Inserted code, such as finalization calls, is irrelevant: we only
7077 -- need to check original source.
7079 or else Is_Rewrite_Insertion
(Last_Stm
)
7084 -- Here we have the "real" last statement
7086 Kind
:= Nkind
(Last_Stm
);
7088 -- Transfer of control, OK. Note that in the No_Return procedure
7089 -- case, we already diagnosed any explicit return statements, so
7090 -- we can treat them as OK in this context.
7092 if Is_Transfer
(Last_Stm
) then
7095 -- Check cases of explicit non-indirect procedure calls
7097 elsif Kind
= N_Procedure_Call_Statement
7098 and then Is_Entity_Name
(Name
(Last_Stm
))
7100 -- Check call to Raise_Exception procedure which is treated
7101 -- specially, as is a call to Reraise_Occurrence.
7103 -- We suppress the warning in these cases since it is likely that
7104 -- the programmer really does not expect to deal with the case
7105 -- of Null_Occurrence, and thus would find a warning about a
7106 -- missing return curious, and raising Program_Error does not
7107 -- seem such a bad behavior if this does occur.
7109 -- Note that in the Ada 2005 case for Raise_Exception, the actual
7110 -- behavior will be to raise Constraint_Error (see AI-329).
7112 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
7114 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
7116 Raise_Exception_Call
:= True;
7118 -- For Raise_Exception call, test first argument, if it is
7119 -- an attribute reference for a 'Identity call, then we know
7120 -- that the call cannot possibly return.
7123 Arg
: constant Node_Id
:=
7124 Original_Node
(First_Actual
(Last_Stm
));
7126 if Nkind
(Arg
) = N_Attribute_Reference
7127 and then Attribute_Name
(Arg
) = Name_Identity
7134 -- If statement, need to look inside if there is an else and check
7135 -- each constituent statement sequence for proper termination.
7137 elsif Kind
= N_If_Statement
7138 and then Present
(Else_Statements
(Last_Stm
))
7140 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
7141 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
7143 if Present
(Elsif_Parts
(Last_Stm
)) then
7145 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
7148 while Present
(Elsif_Part
) loop
7149 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
7157 -- Case statement, check each case for proper termination
7159 elsif Kind
= N_Case_Statement
then
7163 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
7164 while Present
(Case_Alt
) loop
7165 Check_Statement_Sequence
(Statements
(Case_Alt
));
7166 Next_Non_Pragma
(Case_Alt
);
7172 -- Block statement, check its handled sequence of statements
7174 elsif Kind
= N_Block_Statement
then
7180 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
7189 -- Loop statement. If there is an iteration scheme, we can definitely
7190 -- fall out of the loop. Similarly if there is an exit statement, we
7191 -- can fall out. In either case we need a following return.
7193 elsif Kind
= N_Loop_Statement
then
7194 if Present
(Iteration_Scheme
(Last_Stm
))
7195 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
7199 -- A loop with no exit statement or iteration scheme is either
7200 -- an infinite loop, or it has some other exit (raise/return).
7201 -- In either case, no warning is required.
7207 -- Timed entry call, check entry call and delay alternatives
7209 -- Note: in expanded code, the timed entry call has been converted
7210 -- to a set of expanded statements on which the check will work
7211 -- correctly in any case.
7213 elsif Kind
= N_Timed_Entry_Call
then
7215 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
7216 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
7219 -- If statement sequence of entry call alternative is missing,
7220 -- then we can definitely fall through, and we post the error
7221 -- message on the entry call alternative itself.
7223 if No
(Statements
(ECA
)) then
7226 -- If statement sequence of delay alternative is missing, then
7227 -- we can definitely fall through, and we post the error
7228 -- message on the delay alternative itself.
7230 -- Note: if both ECA and DCA are missing the return, then we
7231 -- post only one message, should be enough to fix the bugs.
7232 -- If not we will get a message next time on the DCA when the
7235 elsif No
(Statements
(DCA
)) then
7238 -- Else check both statement sequences
7241 Check_Statement_Sequence
(Statements
(ECA
));
7242 Check_Statement_Sequence
(Statements
(DCA
));
7247 -- Conditional entry call, check entry call and else part
7249 -- Note: in expanded code, the conditional entry call has been
7250 -- converted to a set of expanded statements on which the check
7251 -- will work correctly in any case.
7253 elsif Kind
= N_Conditional_Entry_Call
then
7255 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
7258 -- If statement sequence of entry call alternative is missing,
7259 -- then we can definitely fall through, and we post the error
7260 -- message on the entry call alternative itself.
7262 if No
(Statements
(ECA
)) then
7265 -- Else check statement sequence and else part
7268 Check_Statement_Sequence
(Statements
(ECA
));
7269 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
7275 -- If we fall through, issue appropriate message
7278 if not Raise_Exception_Call
then
7280 -- In GNATprove mode, it is an error to have a missing return
7282 Error_Msg_Warn
:= SPARK_Mode
/= On
;
7284 ("RETURN statement missing following this statement<<!",
7287 ("\Program_Error ]<<!", Last_Stm
);
7290 -- Note: we set Err even though we have not issued a warning
7291 -- because we still have a case of a missing return. This is
7292 -- an extremely marginal case, probably will never be noticed
7293 -- but we might as well get it right.
7297 -- Otherwise we have the case of a procedure marked No_Return
7300 if not Raise_Exception_Call
then
7301 if GNATprove_Mode
then
7303 ("implied return after this statement "
7304 & "would have raised Program_Error", Last_Stm
);
7307 ("implied return after this statement "
7308 & "will raise Program_Error??", Last_Stm
);
7311 Error_Msg_Warn
:= SPARK_Mode
/= On
;
7313 ("\procedure & is marked as No_Return<<!", Last_Stm
, Proc
);
7317 RE
: constant Node_Id
:=
7318 Make_Raise_Program_Error
(Sloc
(Last_Stm
),
7319 Reason
=> PE_Implicit_Return
);
7321 Insert_After
(Last_Stm
, RE
);
7325 end Check_Statement_Sequence
;
7327 -- Start of processing for Check_Returns
7331 Check_Statement_Sequence
(Statements
(HSS
));
7333 if Present
(Exception_Handlers
(HSS
)) then
7334 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
7335 while Present
(Handler
) loop
7336 Check_Statement_Sequence
(Statements
(Handler
));
7337 Next_Non_Pragma
(Handler
);
7342 ----------------------------
7343 -- Check_Subprogram_Order --
7344 ----------------------------
7346 procedure Check_Subprogram_Order
(N
: Node_Id
) is
7348 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
7349 -- This is used to check if S1 > S2 in the sense required by this test,
7350 -- for example nameab < namec, but name2 < name10.
7352 -----------------------------
7353 -- Subprogram_Name_Greater --
7354 -----------------------------
7356 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
7361 -- Deal with special case where names are identical except for a
7362 -- numerical suffix. These are handled specially, taking the numeric
7363 -- ordering from the suffix into account.
7366 while S1
(L1
) in '0' .. '9' loop
7371 while S2
(L2
) in '0' .. '9' loop
7375 -- If non-numeric parts non-equal, do straight compare
7377 if S1
(S1
'First .. L1
) /= S2
(S2
'First .. L2
) then
7380 -- If non-numeric parts equal, compare suffixed numeric parts. Note
7381 -- that a missing suffix is treated as numeric zero in this test.
7385 while L1
< S1
'Last loop
7387 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
7391 while L2
< S2
'Last loop
7393 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
7398 end Subprogram_Name_Greater
;
7400 -- Start of processing for Check_Subprogram_Order
7403 -- Check body in alpha order if this is option
7406 and then Style_Check_Order_Subprograms
7407 and then Nkind
(N
) = N_Subprogram_Body
7408 and then Comes_From_Source
(N
)
7409 and then In_Extended_Main_Source_Unit
(N
)
7413 renames Scope_Stack
.Table
7414 (Scope_Stack
.Last
).Last_Subprogram_Name
;
7416 Body_Id
: constant Entity_Id
:=
7417 Defining_Entity
(Specification
(N
));
7420 Get_Decoded_Name_String
(Chars
(Body_Id
));
7423 if Subprogram_Name_Greater
7424 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
7426 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
7432 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
7435 end Check_Subprogram_Order;
7437 ------------------------------
7438 -- Check_Subtype_Conformant --
7439 ------------------------------
7441 procedure Check_Subtype_Conformant
7442 (New_Id : Entity_Id;
7444 Err_Loc : Node_Id := Empty;
7445 Skip_Controlling_Formals : Boolean := False;
7446 Get_Inst : Boolean := False)
7449 pragma Warnings (Off, Result);
7452 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc,
7453 Skip_Controlling_Formals => Skip_Controlling_Formals,
7454 Get_Inst => Get_Inst);
7455 end Check_Subtype_Conformant;
7457 ---------------------------
7458 -- Check_Type_Conformant --
7459 ---------------------------
7461 procedure Check_Type_Conformant
7462 (New_Id : Entity_Id;
7464 Err_Loc : Node_Id := Empty)
7467 pragma Warnings (Off, Result);
7470 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
7471 end Check_Type_Conformant;
7473 ---------------------------
7474 -- Can_Override_Operator --
7475 ---------------------------
7477 function Can_Override_Operator (Subp : Entity_Id) return Boolean is
7481 if Nkind (Subp) /= N_Defining_Operator_Symbol then
7485 Typ := Base_Type (Etype (First_Formal (Subp)));
7487 -- Check explicitly that the operation is a primitive of the type
7489 return Operator_Matches_Spec (Subp, Subp)
7490 and then not Is_Generic_Type (Typ)
7491 and then Scope (Subp) = Scope (Typ)
7492 and then not Is_Class_Wide_Type (Typ);
7494 end Can_Override_Operator;
7496 ----------------------
7497 -- Conforming_Types --
7498 ----------------------
7500 function Conforming_Types
7503 Ctype : Conformance_Type;
7504 Get_Inst : Boolean := False) return Boolean
7506 Type_1 : Entity_Id := T1;
7507 Type_2 : Entity_Id := T2;
7508 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
7510 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
7511 -- If neither T1 nor T2 are generic actual types, or if they are in
7512 -- different scopes (e.g. parent and child instances), then verify that
7513 -- the base types are equal. Otherwise T1 and T2 must be on the same
7514 -- subtype chain. The whole purpose of this procedure is to prevent
7515 -- spurious ambiguities in an instantiation that may arise if two
7516 -- distinct generic types are instantiated with the same actual.
7518 function Find_Designated_Type (T : Entity_Id) return Entity_Id;
7519 -- An access parameter can designate an incomplete type. If the
7520 -- incomplete type is the limited view of a type from a limited_
7521 -- with_clause, check whether the non-limited view is available. If
7522 -- it is a (non-limited) incomplete type, get the full view.
7524 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean;
7525 -- Returns True if and only if either T1 denotes a limited view of T2
7526 -- or T2 denotes a limited view of T1. This can arise when the limited
7527 -- with view of a type is used in a subprogram declaration and the
7528 -- subprogram body is in the scope of a regular with clause for the
7529 -- same unit. In such a case, the two type entities can be considered
7530 -- identical for purposes of conformance checking.
7532 ----------------------
7533 -- Base_Types_Match --
7534 ----------------------
7536 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
7537 BT1 : constant Entity_Id := Base_Type (T1);
7538 BT2 : constant Entity_Id := Base_Type (T2);
7544 elsif BT1 = BT2 then
7546 -- The following is too permissive. A more precise test should
7547 -- check that the generic actual is an ancestor subtype of the
7550 -- See code in Find_Corresponding_Spec that applies an additional
7551 -- filter to handle accidental amiguities in instances.
7553 return not Is_Generic_Actual_Type (T1)
7554 or else not Is_Generic_Actual_Type (T2)
7555 or else Scope (T1) /= Scope (T2);
7557 -- If T2 is a generic actual type it is declared as the subtype of
7558 -- the actual. If that actual is itself a subtype we need to use its
7559 -- own base type to check for compatibility.
7561 elsif Ekind (BT2) = Ekind (T2) and then BT1 = Base_Type (BT2) then
7564 elsif Ekind (BT1) = Ekind (T1) and then BT2 = Base_Type (BT1) then
7570 end Base_Types_Match;
7572 --------------------------
7573 -- Find_Designated_Type --
7574 --------------------------
7576 function Find_Designated_Type (T : Entity_Id) return Entity_Id is
7580 Desig := Directly_Designated_Type (T);
7582 if Ekind (Desig) = E_Incomplete_Type then
7584 -- If regular incomplete type, get full view if available
7586 if Present (Full_View (Desig)) then
7587 Desig := Full_View (Desig);
7589 -- If limited view of a type, get non-limited view if available,
7590 -- and check again for a regular incomplete type.
7592 elsif Present (Non_Limited_View (Desig)) then
7593 Desig := Get_Full_View (Non_Limited_View (Desig));
7598 end Find_Designated_Type;
7600 -------------------------------
7601 -- Matches_Limited_With_View --
7602 -------------------------------
7604 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean is
7606 -- In some cases a type imported through a limited_with clause, and
7607 -- its nonlimited view are both visible, for example in an anonymous
7608 -- access-to-class-wide type in a formal. Both entities designate the
7611 if From_Limited_With (T1) and then T2 = Available_View (T1) then
7614 elsif From_Limited_With (T2) and then T1 = Available_View (T2) then
7617 elsif From_Limited_With (T1)
7618 and then From_Limited_With (T2)
7619 and then Available_View (T1) = Available_View (T2)
7626 end Matches_Limited_With_View;
7628 -- Start of processing for Conforming_Types
7631 -- The context is an instance association for a formal access-to-
7632 -- subprogram type; the formal parameter types require mapping because
7633 -- they may denote other formal parameters of the generic unit.
7636 Type_1 := Get_Instance_Of (T1);
7637 Type_2 := Get_Instance_Of (T2);
7640 -- If one of the types is a view of the other introduced by a limited
7641 -- with clause, treat these as conforming for all purposes.
7643 if Matches_Limited_With_View (T1, T2) then
7646 elsif Base_Types_Match (Type_1, Type_2) then
7647 return Ctype <= Mode_Conformant
7648 or else Subtypes_Statically_Match (Type_1, Type_2);
7650 elsif Is_Incomplete_Or_Private_Type (Type_1)
7651 and then Present (Full_View (Type_1))
7652 and then Base_Types_Match (Full_View (Type_1), Type_2)
7654 return Ctype <= Mode_Conformant
7655 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
7657 elsif Ekind (Type_2) = E_Incomplete_Type
7658 and then Present (Full_View (Type_2))
7659 and then Base_Types_Match (Type_1, Full_View (Type_2))
7661 return Ctype <= Mode_Conformant
7662 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
7664 elsif Is_Private_Type (Type_2)
7665 and then In_Instance
7666 and then Present (Full_View (Type_2))
7667 and then Base_Types_Match (Type_1, Full_View (Type_2))
7669 return Ctype <= Mode_Conformant
7670 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
7673 -- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be
7674 -- treated recursively because they carry a signature. As far as
7675 -- conformance is concerned, convention plays no role, and either
7676 -- or both could be access to protected subprograms.
7678 Are_Anonymous_Access_To_Subprogram_Types :=
7679 Ekind_In (Type_1, E_Anonymous_Access_Subprogram_Type,
7680 E_Anonymous_Access_Protected_Subprogram_Type)
7682 Ekind_In (Type_2, E_Anonymous_Access_Subprogram_Type,
7683 E_Anonymous_Access_Protected_Subprogram_Type);
7685 -- Test anonymous access type case. For this case, static subtype
7686 -- matching is required for mode conformance (RM 6.3.1(15)). We check
7687 -- the base types because we may have built internal subtype entities
7688 -- to handle null-excluding types (see Process_Formals).
7690 if (Ekind (Base_Type (Type_1)) = E_Anonymous_Access_Type
7692 Ekind (Base_Type (Type_2)) = E_Anonymous_Access_Type)
7694 -- Ada 2005 (AI-254)
7696 or else Are_Anonymous_Access_To_Subprogram_Types
7699 Desig_1 : Entity_Id;
7700 Desig_2 : Entity_Id;
7703 -- In Ada 2005, access constant indicators must match for
7704 -- subtype conformance.
7706 if Ada_Version >= Ada_2005
7707 and then Ctype >= Subtype_Conformant
7709 Is_Access_Constant (Type_1) /= Is_Access_Constant (Type_2)
7714 Desig_1 := Find_Designated_Type (Type_1);
7715 Desig_2 := Find_Designated_Type (Type_2);
7717 -- If the context is an instance association for a formal
7718 -- access-to-subprogram type; formal access parameter designated
7719 -- types require mapping because they may denote other formal
7720 -- parameters of the generic unit.
7723 Desig_1 := Get_Instance_Of (Desig_1);
7724 Desig_2 := Get_Instance_Of (Desig_2);
7727 -- It is possible for a Class_Wide_Type to be introduced for an
7728 -- incomplete type, in which case there is a separate class_ wide
7729 -- type for the full view. The types conform if their Etypes
7730 -- conform, i.e. one may be the full view of the other. This can
7731 -- only happen in the context of an access parameter, other uses
7732 -- of an incomplete Class_Wide_Type are illegal.
7734 if Is_Class_Wide_Type (Desig_1)
7736 Is_Class_Wide_Type (Desig_2)
7740 (Etype (Base_Type (Desig_1)),
7741 Etype (Base_Type (Desig_2)), Ctype);
7743 elsif Are_Anonymous_Access_To_Subprogram_Types then
7744 if Ada_Version < Ada_2005 then
7745 return Ctype = Type_Conformant
7747 Subtypes_Statically_Match (Desig_1, Desig_2);
7749 -- We must check the conformance of the signatures themselves
7753 Conformant : Boolean;
7756 (Desig_1, Desig_2, Ctype, False, Conformant);
7762 return Base_Type (Desig_1) = Base_Type (Desig_2)
7763 and then (Ctype = Type_Conformant
7765 Subtypes_Statically_Match (Desig_1, Desig_2));
7769 -- Otherwise definitely no match
7772 if ((Ekind (Type_1) = E_Anonymous_Access_Type
7773 and then Is_Access_Type (Type_2))
7774 or else (Ekind (Type_2) = E_Anonymous_Access_Type
7775 and then Is_Access_Type (Type_1)))
7778 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
7780 May_Hide_Profile := True;
7785 end Conforming_Types;
7787 --------------------------
7788 -- Create_Extra_Formals --
7789 --------------------------
7791 procedure Create_Extra_Formals (E : Entity_Id) is
7793 First_Extra : Entity_Id := Empty;
7794 Last_Extra : Entity_Id;
7795 Formal_Type : Entity_Id;
7796 P_Formal : Entity_Id := Empty;
7798 function Add_Extra_Formal
7799 (Assoc_Entity : Entity_Id;
7802 Suffix : String) return Entity_Id;
7803 -- Add an extra formal to the current list of formals and extra formals.
7804 -- The extra formal is added to the end of the list of extra formals,
7805 -- and also returned as the result. These formals are always of mode IN.
7806 -- The new formal has the type Typ, is declared in Scope, and its name
7807 -- is given by a concatenation of the name of Assoc_Entity and Suffix.
7808 -- The following suffixes are currently used. They should not be changed
7809 -- without coordinating with CodePeer, which makes use of these to
7810 -- provide better messages.
7812 -- O denotes the Constrained bit.
7813 -- L denotes the accessibility level.
7814 -- BIP_xxx denotes an extra formal for a build-in-place function. See
7815 -- the full list in exp_ch6.BIP_Formal_Kind.
7817 ----------------------
7818 -- Add_Extra_Formal --
7819 ----------------------
7821 function Add_Extra_Formal
7822 (Assoc_Entity : Entity_Id;
7825 Suffix : String) return Entity_Id
7827 EF : constant Entity_Id :=
7828 Make_Defining_Identifier (Sloc (Assoc_Entity),
7829 Chars => New_External_Name (Chars (Assoc_Entity),
7833 -- A little optimization. Never generate an extra formal for the
7834 -- _init operand of an initialization procedure, since it could
7837 if Chars (Formal) = Name_uInit then
7841 Set_Ekind (EF, E_In_Parameter);
7842 Set_Actual_Subtype (EF, Typ);
7843 Set_Etype (EF, Typ);
7844 Set_Scope (EF, Scope);
7845 Set_Mechanism (EF, Default_Mechanism);
7846 Set_Formal_Validity (EF);
7848 if No (First_Extra) then
7850 Set_Extra_Formals (Scope, First_Extra);
7853 if Present (Last_Extra) then
7854 Set_Extra_Formal (Last_Extra, EF);
7860 end Add_Extra_Formal;
7862 -- Start of processing for Create_Extra_Formals
7865 -- We never generate extra formals if expansion is not active because we
7866 -- don't need them unless we are generating code.
7868 if not Expander_Active then
7872 -- No need to generate extra formals in interface thunks whose target
7873 -- primitive has no extra formals.
7875 if Is_Thunk (E) and then No (Extra_Formals (Thunk_Entity (E))) then
7879 -- If this is a derived subprogram then the subtypes of the parent
7880 -- subprogram's formal parameters will be used to determine the need
7881 -- for extra formals.
7883 if Is_Overloadable (E) and then Present (Alias (E)) then
7884 P_Formal := First_Formal (Alias (E));
7887 Last_Extra := Empty;
7888 Formal := First_Formal (E);
7889 while Present (Formal) loop
7890 Last_Extra := Formal;
7891 Next_Formal (Formal);
7894 -- If Extra_formals were already created, don't do it again. This
7895 -- situation may arise for subprogram types created as part of
7896 -- dispatching calls (see Expand_Dispatching_Call)
7898 if Present (Last_Extra) and then Present (Extra_Formal (Last_Extra)) then
7902 -- If the subprogram is a predefined dispatching subprogram then don't
7903 -- generate any extra constrained or accessibility level formals. In
7904 -- general we suppress these for internal subprograms (by not calling
7905 -- Freeze_Subprogram and Create_Extra_Formals at all), but internally
7906 -- generated stream attributes do get passed through because extra
7907 -- build-in-place formals are needed in some cases (limited 'Input
).
7909 if Is_Predefined_Internal_Operation
(E
) then
7910 goto Test_For_Func_Result_Extras
;
7913 Formal
:= First_Formal
(E
);
7914 while Present
(Formal
) loop
7916 -- Create extra formal for supporting the attribute 'Constrained.
7917 -- The case of a private type view without discriminants also
7918 -- requires the extra formal if the underlying type has defaulted
7921 if Ekind
(Formal
) /= E_In_Parameter
then
7922 if Present
(P_Formal
) then
7923 Formal_Type
:= Etype
(P_Formal
);
7925 Formal_Type
:= Etype
(Formal
);
7928 -- Do not produce extra formals for Unchecked_Union parameters.
7929 -- Jump directly to the end of the loop.
7931 if Is_Unchecked_Union
(Base_Type
(Formal_Type
)) then
7932 goto Skip_Extra_Formal_Generation
;
7935 if not Has_Discriminants
(Formal_Type
)
7936 and then Ekind
(Formal_Type
) in Private_Kind
7937 and then Present
(Underlying_Type
(Formal_Type
))
7939 Formal_Type
:= Underlying_Type
(Formal_Type
);
7942 -- Suppress the extra formal if formal's subtype is constrained or
7943 -- indefinite, or we're compiling for Ada 2012 and the underlying
7944 -- type is tagged and limited. In Ada 2012, a limited tagged type
7945 -- can have defaulted discriminants, but 'Constrained is required
7946 -- to return True, so the formal is never needed (see AI05-0214).
7947 -- Note that this ensures consistency of calling sequences for
7948 -- dispatching operations when some types in a class have defaults
7949 -- on discriminants and others do not (and requiring the extra
7950 -- formal would introduce distributed overhead).
7952 -- If the type does not have a completion yet, treat as prior to
7953 -- Ada 2012 for consistency.
7955 if Has_Discriminants
(Formal_Type
)
7956 and then not Is_Constrained
(Formal_Type
)
7957 and then not Is_Indefinite_Subtype
(Formal_Type
)
7958 and then (Ada_Version
< Ada_2012
7959 or else No
(Underlying_Type
(Formal_Type
))
7961 (Is_Limited_Type
(Formal_Type
)
7964 (Underlying_Type
(Formal_Type
)))))
7966 Set_Extra_Constrained
7967 (Formal
, Add_Extra_Formal
(Formal
, Standard_Boolean
, E
, "O"));
7971 -- Create extra formal for supporting accessibility checking. This
7972 -- is done for both anonymous access formals and formals of named
7973 -- access types that are marked as controlling formals. The latter
7974 -- case can occur when Expand_Dispatching_Call creates a subprogram
7975 -- type and substitutes the types of access-to-class-wide actuals
7976 -- for the anonymous access-to-specific-type of controlling formals.
7977 -- Base_Type is applied because in cases where there is a null
7978 -- exclusion the formal may have an access subtype.
7980 -- This is suppressed if we specifically suppress accessibility
7981 -- checks at the package level for either the subprogram, or the
7982 -- package in which it resides. However, we do not suppress it
7983 -- simply if the scope has accessibility checks suppressed, since
7984 -- this could cause trouble when clients are compiled with a
7985 -- different suppression setting. The explicit checks at the
7986 -- package level are safe from this point of view.
7988 if (Ekind
(Base_Type
(Etype
(Formal
))) = E_Anonymous_Access_Type
7989 or else (Is_Controlling_Formal
(Formal
)
7990 and then Is_Access_Type
(Base_Type
(Etype
(Formal
)))))
7992 (Explicit_Suppress
(E
, Accessibility_Check
)
7994 Explicit_Suppress
(Scope
(E
), Accessibility_Check
))
7997 or else Present
(Extra_Accessibility
(P_Formal
)))
7999 Set_Extra_Accessibility
8000 (Formal
, Add_Extra_Formal
(Formal
, Standard_Natural
, E
, "L"));
8003 -- This label is required when skipping extra formal generation for
8004 -- Unchecked_Union parameters.
8006 <<Skip_Extra_Formal_Generation
>>
8008 if Present
(P_Formal
) then
8009 Next_Formal
(P_Formal
);
8012 Next_Formal
(Formal
);
8015 <<Test_For_Func_Result_Extras
>>
8017 -- Ada 2012 (AI05-234): "the accessibility level of the result of a
8018 -- function call is ... determined by the point of call ...".
8020 if Needs_Result_Accessibility_Level
(E
) then
8021 Set_Extra_Accessibility_Of_Result
8022 (E
, Add_Extra_Formal
(E
, Standard_Natural
, E
, "L"));
8025 -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add
8026 -- appropriate extra formals. See type Exp_Ch6.BIP_Formal_Kind.
8028 if Ada_Version
>= Ada_2005
and then Is_Build_In_Place_Function
(E
) then
8030 Result_Subt
: constant Entity_Id
:= Etype
(E
);
8031 Full_Subt
: constant Entity_Id
:= Available_View
(Result_Subt
);
8032 Formal_Typ
: Entity_Id
;
8034 Discard
: Entity_Id
;
8035 pragma Warnings
(Off
, Discard
);
8038 -- In the case of functions with unconstrained result subtypes,
8039 -- add a 4-state formal indicating whether the return object is
8040 -- allocated by the caller (1), or should be allocated by the
8041 -- callee on the secondary stack (2), in the global heap (3), or
8042 -- in a user-defined storage pool (4). For the moment we just use
8043 -- Natural for the type of this formal. Note that this formal
8044 -- isn't usually needed in the case where the result subtype is
8045 -- constrained, but it is needed when the function has a tagged
8046 -- result, because generally such functions can be called in a
8047 -- dispatching context and such calls must be handled like calls
8048 -- to a class-wide function.
8050 if Needs_BIP_Alloc_Form
(E
) then
8053 (E
, Standard_Natural
,
8054 E
, BIP_Formal_Suffix
(BIP_Alloc_Form
));
8056 -- Add BIP_Storage_Pool, in case BIP_Alloc_Form indicates to
8057 -- use a user-defined pool. This formal is not added on
8058 -- .NET/JVM/ZFP as those targets do not support pools.
8060 if VM_Target
= No_VM
8061 and then RTE_Available
(RE_Root_Storage_Pool_Ptr
)
8065 (E
, RTE
(RE_Root_Storage_Pool_Ptr
),
8066 E
, BIP_Formal_Suffix
(BIP_Storage_Pool
));
8070 -- In the case of functions whose result type needs finalization,
8071 -- add an extra formal which represents the finalization master.
8073 if Needs_BIP_Finalization_Master
(E
) then
8076 (E
, RTE
(RE_Finalization_Master_Ptr
),
8077 E
, BIP_Formal_Suffix
(BIP_Finalization_Master
));
8080 -- When the result type contains tasks, add two extra formals: the
8081 -- master of the tasks to be created, and the caller's activation
8084 if Has_Task
(Full_Subt
) then
8087 (E
, RTE
(RE_Master_Id
),
8088 E
, BIP_Formal_Suffix
(BIP_Task_Master
));
8091 (E
, RTE
(RE_Activation_Chain_Access
),
8092 E
, BIP_Formal_Suffix
(BIP_Activation_Chain
));
8095 -- All build-in-place functions get an extra formal that will be
8096 -- passed the address of the return object within the caller.
8099 Create_Itype
(E_Anonymous_Access_Type
, E
, Scope_Id
=> Scope
(E
));
8101 Set_Directly_Designated_Type
(Formal_Typ
, Result_Subt
);
8102 Set_Etype
(Formal_Typ
, Formal_Typ
);
8103 Set_Depends_On_Private
8104 (Formal_Typ
, Has_Private_Component
(Formal_Typ
));
8105 Set_Is_Public
(Formal_Typ
, Is_Public
(Scope
(Formal_Typ
)));
8106 Set_Is_Access_Constant
(Formal_Typ
, False);
8108 -- Ada 2005 (AI-50217): Propagate the attribute that indicates
8109 -- the designated type comes from the limited view (for back-end
8112 Set_From_Limited_With
8113 (Formal_Typ
, From_Limited_With
(Result_Subt
));
8115 Layout_Type
(Formal_Typ
);
8119 (E
, Formal_Typ
, E
, BIP_Formal_Suffix
(BIP_Object_Access
));
8122 end Create_Extra_Formals
;
8124 -----------------------------
8125 -- Enter_Overloaded_Entity --
8126 -----------------------------
8128 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
8129 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
8130 C_E
: Entity_Id
:= Current_Entity
(S
);
8134 Set_Has_Homonym
(E
);
8135 Set_Has_Homonym
(S
);
8138 Set_Is_Immediately_Visible
(S
);
8139 Set_Scope
(S
, Current_Scope
);
8141 -- Chain new entity if front of homonym in current scope, so that
8142 -- homonyms are contiguous.
8144 if Present
(E
) and then E
/= C_E
then
8145 while Homonym
(C_E
) /= E
loop
8146 C_E
:= Homonym
(C_E
);
8149 Set_Homonym
(C_E
, S
);
8153 Set_Current_Entity
(S
);
8158 if Is_Inherited_Operation
(S
) then
8159 Append_Inherited_Subprogram
(S
);
8161 Append_Entity
(S
, Current_Scope
);
8164 Set_Public_Status
(S
);
8166 if Debug_Flag_E
then
8167 Write_Str
("New overloaded entity chain: ");
8168 Write_Name
(Chars
(S
));
8171 while Present
(E
) loop
8172 Write_Str
(" "); Write_Int
(Int
(E
));
8179 -- Generate warning for hiding
8182 and then Comes_From_Source
(S
)
8183 and then In_Extended_Main_Source_Unit
(S
)
8190 -- Warn unless genuine overloading. Do not emit warning on
8191 -- hiding predefined operators in Standard (these are either an
8192 -- (artifact of our implicit declarations, or simple noise) but
8193 -- keep warning on a operator defined on a local subtype, because
8194 -- of the real danger that different operators may be applied in
8195 -- various parts of the program.
8197 -- Note that if E and S have the same scope, there is never any
8198 -- hiding. Either the two conflict, and the program is illegal,
8199 -- or S is overriding an implicit inherited subprogram.
8201 if Scope
(E
) /= Scope
(S
)
8202 and then (not Is_Overloadable
(E
)
8203 or else Subtype_Conformant
(E
, S
))
8204 and then (Is_Immediately_Visible
(E
)
8206 Is_Potentially_Use_Visible
(S
))
8208 if Scope
(E
) /= Standard_Standard
then
8209 Error_Msg_Sloc
:= Sloc
(E
);
8210 Error_Msg_N
("declaration of & hides one#?h?", S
);
8212 elsif Nkind
(S
) = N_Defining_Operator_Symbol
8214 Scope
(Base_Type
(Etype
(First_Formal
(S
)))) /= Scope
(S
)
8217 ("declaration of & hides predefined operator?h?", S
);
8222 end Enter_Overloaded_Entity
;
8224 -----------------------------
8225 -- Check_Untagged_Equality --
8226 -----------------------------
8228 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
) is
8229 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Eq_Op
));
8230 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Eq_Op
);
8234 -- This check applies only if we have a subprogram declaration with a
8235 -- non-tagged record type.
8237 if Nkind
(Decl
) /= N_Subprogram_Declaration
8238 or else not Is_Record_Type
(Typ
)
8239 or else Is_Tagged_Type
(Typ
)
8244 -- In Ada 2012 case, we will output errors or warnings depending on
8245 -- the setting of debug flag -gnatd.E.
8247 if Ada_Version
>= Ada_2012
then
8248 Error_Msg_Warn
:= Debug_Flag_Dot_EE
;
8250 -- In earlier versions of Ada, nothing to do unless we are warning on
8251 -- Ada 2012 incompatibilities (Warn_On_Ada_2012_Incompatibility set).
8254 if not Warn_On_Ada_2012_Compatibility
then
8259 -- Cases where the type has already been frozen
8261 if Is_Frozen
(Typ
) then
8263 -- If the type is not declared in a package, or if we are in the body
8264 -- of the package or in some other scope, the new operation is not
8265 -- primitive, and therefore legal, though suspicious. Should we
8266 -- generate a warning in this case ???
8268 if Ekind
(Scope
(Typ
)) /= E_Package
8269 or else Scope
(Typ
) /= Current_Scope
8273 -- If the type is a generic actual (sub)type, the operation is not
8274 -- primitive either because the base type is declared elsewhere.
8276 elsif Is_Generic_Actual_Type
(Typ
) then
8279 -- Here we have a definite error of declaration after freezing
8282 if Ada_Version
>= Ada_2012
then
8284 ("equality operator must be declared before type& is "
8285 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)<<", Eq_Op
, Typ
);
8287 -- In Ada 2012 mode with error turned to warning, output one
8288 -- more warning to warn that the equality operation may not
8289 -- compose. This is the consequence of ignoring the error.
8291 if Error_Msg_Warn
then
8292 Error_Msg_N
("\equality operation may not compose??", Eq_Op
);
8297 ("equality operator must be declared before type& is "
8298 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)?y?", Eq_Op
, Typ
);
8301 -- If we are in the package body, we could just move the
8302 -- declaration to the package spec, so add a message saying that.
8304 if In_Package_Body
(Scope
(Typ
)) then
8305 if Ada_Version
>= Ada_2012
then
8307 ("\move declaration to package spec<<", Eq_Op
);
8310 ("\move declaration to package spec (Ada 2012)?y?", Eq_Op
);
8313 -- Otherwise try to find the freezing point
8316 Obj_Decl
:= Next
(Parent
(Typ
));
8317 while Present
(Obj_Decl
) and then Obj_Decl
/= Decl
loop
8318 if Nkind
(Obj_Decl
) = N_Object_Declaration
8319 and then Etype
(Defining_Identifier
(Obj_Decl
)) = Typ
8321 -- Freezing point, output warnings
8323 if Ada_Version
>= Ada_2012
then
8325 ("type& is frozen by declaration??", Obj_Decl
, Typ
);
8327 ("\an equality operator cannot be declared after "
8332 ("type& is frozen by declaration (Ada 2012)?y?",
8335 ("\an equality operator cannot be declared after "
8336 & "this point (Ada 2012)?y?",
8348 -- Here if type is not frozen yet. It is illegal to have a primitive
8349 -- equality declared in the private part if the type is visible.
8351 elsif not In_Same_List
(Parent
(Typ
), Decl
)
8352 and then not Is_Limited_Type
(Typ
)
8354 -- Shouldn't we give an RM reference here???
8356 if Ada_Version
>= Ada_2012
then
8358 ("equality operator appears too late<<", Eq_Op
);
8361 ("equality operator appears too late (Ada 2012)?y?", Eq_Op
);
8364 -- No error detected
8369 end Check_Untagged_Equality
;
8371 -----------------------------
8372 -- Find_Corresponding_Spec --
8373 -----------------------------
8375 function Find_Corresponding_Spec
8377 Post_Error
: Boolean := True) return Entity_Id
8379 Spec
: constant Node_Id
:= Specification
(N
);
8380 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
8384 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean;
8385 -- Even if fully conformant, a body may depend on a generic actual when
8386 -- the spec does not, or vice versa, in which case they were distinct
8387 -- entities in the generic.
8389 -------------------------------
8390 -- Different_Generic_Profile --
8391 -------------------------------
8393 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean is
8396 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean;
8397 -- Check that the types of corresponding formals have the same
8398 -- generic actual if any. We have to account for subtypes of a
8399 -- generic formal, declared between a spec and a body, which may
8400 -- appear distinct in an instance but matched in the generic.
8402 -------------------------
8403 -- Same_Generic_Actual --
8404 -------------------------
8406 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean is
8408 return Is_Generic_Actual_Type
(T1
) = Is_Generic_Actual_Type
(T2
)
8410 (Present
(Parent
(T1
))
8411 and then Comes_From_Source
(Parent
(T1
))
8412 and then Nkind
(Parent
(T1
)) = N_Subtype_Declaration
8413 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T1
)))
8414 and then Entity
(Subtype_Indication
(Parent
(T1
))) = T2
);
8415 end Same_Generic_Actual
;
8417 -- Start of processing for Different_Generic_Profile
8420 if not In_Instance
then
8423 elsif Ekind
(E
) = E_Function
8424 and then not Same_Generic_Actual
(Etype
(E
), Etype
(Designator
))
8429 F1
:= First_Formal
(Designator
);
8430 F2
:= First_Formal
(E
);
8431 while Present
(F1
) loop
8432 if not Same_Generic_Actual
(Etype
(F1
), Etype
(F2
)) then
8441 end Different_Generic_Profile
;
8443 -- Start of processing for Find_Corresponding_Spec
8446 E
:= Current_Entity
(Designator
);
8447 while Present
(E
) loop
8449 -- We are looking for a matching spec. It must have the same scope,
8450 -- and the same name, and either be type conformant, or be the case
8451 -- of a library procedure spec and its body (which belong to one
8452 -- another regardless of whether they are type conformant or not).
8454 if Scope
(E
) = Current_Scope
then
8455 if Current_Scope
= Standard_Standard
8456 or else (Ekind
(E
) = Ekind
(Designator
)
8457 and then Type_Conformant
(E
, Designator
))
8459 -- Within an instantiation, we know that spec and body are
8460 -- subtype conformant, because they were subtype conformant in
8461 -- the generic. We choose the subtype-conformant entity here as
8462 -- well, to resolve spurious ambiguities in the instance that
8463 -- were not present in the generic (i.e. when two different
8464 -- types are given the same actual). If we are looking for a
8465 -- spec to match a body, full conformance is expected.
8468 Set_Convention
(Designator
, Convention
(E
));
8470 -- Skip past subprogram bodies and subprogram renamings that
8471 -- may appear to have a matching spec, but that aren't fully
8472 -- conformant with it. That can occur in cases where an
8473 -- actual type causes unrelated homographs in the instance.
8475 if Nkind_In
(N
, N_Subprogram_Body
,
8476 N_Subprogram_Renaming_Declaration
)
8477 and then Present
(Homonym
(E
))
8478 and then not Fully_Conformant
(Designator
, E
)
8482 elsif not Subtype_Conformant
(Designator
, E
) then
8485 elsif Different_Generic_Profile
(E
) then
8490 -- Ada 2012 (AI05-0165): For internally generated bodies of
8491 -- null procedures locate the internally generated spec. We
8492 -- enforce mode conformance since a tagged type may inherit
8493 -- from interfaces several null primitives which differ only
8494 -- in the mode of the formals.
8496 if not (Comes_From_Source
(E
))
8497 and then Is_Null_Procedure
(E
)
8498 and then not Mode_Conformant
(Designator
, E
)
8502 -- For null procedures coming from source that are completions,
8503 -- analysis of the generated body will establish the link.
8505 elsif Comes_From_Source
(E
)
8506 and then Nkind
(Spec
) = N_Procedure_Specification
8507 and then Null_Present
(Spec
)
8511 elsif not Has_Completion
(E
) then
8512 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
8513 Set_Corresponding_Spec
(N
, E
);
8516 Set_Has_Completion
(E
);
8519 elsif Nkind
(Parent
(N
)) = N_Subunit
then
8521 -- If this is the proper body of a subunit, the completion
8522 -- flag is set when analyzing the stub.
8526 -- If E is an internal function with a controlling result that
8527 -- was created for an operation inherited by a null extension,
8528 -- it may be overridden by a body without a previous spec (one
8529 -- more reason why these should be shunned). In that case we
8530 -- remove the generated body if present, because the current
8531 -- one is the explicit overriding.
8533 elsif Ekind
(E
) = E_Function
8534 and then Ada_Version
>= Ada_2005
8535 and then not Comes_From_Source
(E
)
8536 and then Has_Controlling_Result
(E
)
8537 and then Is_Null_Extension
(Etype
(E
))
8538 and then Comes_From_Source
(Spec
)
8540 Set_Has_Completion
(E
, False);
8543 and then Nkind
(Parent
(E
)) = N_Function_Specification
8546 (Unit_Declaration_Node
8547 (Corresponding_Body
(Unit_Declaration_Node
(E
))));
8551 -- If expansion is disabled, or if the wrapper function has
8552 -- not been generated yet, this a late body overriding an
8553 -- inherited operation, or it is an overriding by some other
8554 -- declaration before the controlling result is frozen. In
8555 -- either case this is a declaration of a new entity.
8561 -- If the body already exists, then this is an error unless
8562 -- the previous declaration is the implicit declaration of a
8563 -- derived subprogram. It is also legal for an instance to
8564 -- contain type conformant overloadable declarations (but the
8565 -- generic declaration may not), per 8.3(26/2).
8567 elsif No
(Alias
(E
))
8568 and then not Is_Intrinsic_Subprogram
(E
)
8569 and then not In_Instance
8572 Error_Msg_Sloc
:= Sloc
(E
);
8574 if Is_Imported
(E
) then
8576 ("body not allowed for imported subprogram & declared#",
8579 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
8583 -- Child units cannot be overloaded, so a conformance mismatch
8584 -- between body and a previous spec is an error.
8586 elsif Is_Child_Unit
(E
)
8588 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
8590 Nkind
(Parent
(Unit_Declaration_Node
(Designator
))) =
8595 ("body of child unit does not match previous declaration", N
);
8603 -- On exit, we know that no previous declaration of subprogram exists
8606 end Find_Corresponding_Spec
;
8608 ----------------------
8609 -- Fully_Conformant --
8610 ----------------------
8612 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
8615 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
8617 end Fully_Conformant
;
8619 ----------------------------------
8620 -- Fully_Conformant_Expressions --
8621 ----------------------------------
8623 function Fully_Conformant_Expressions
8624 (Given_E1
: Node_Id
;
8625 Given_E2
: Node_Id
) return Boolean
8627 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
8628 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
8629 -- We always test conformance on original nodes, since it is possible
8630 -- for analysis and/or expansion to make things look as though they
8631 -- conform when they do not, e.g. by converting 1+2 into 3.
8633 function FCE
(Given_E1
, Given_E2
: Node_Id
) return Boolean
8634 renames Fully_Conformant_Expressions
;
8636 function FCL
(L1
, L2
: List_Id
) return Boolean;
8637 -- Compare elements of two lists for conformance. Elements have to be
8638 -- conformant, and actuals inserted as default parameters do not match
8639 -- explicit actuals with the same value.
8641 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean;
8642 -- Compare an operator node with a function call
8648 function FCL
(L1
, L2
: List_Id
) return Boolean is
8652 if L1
= No_List
then
8658 if L2
= No_List
then
8664 -- Compare two lists, skipping rewrite insertions (we want to compare
8665 -- the original trees, not the expanded versions).
8668 if Is_Rewrite_Insertion
(N1
) then
8670 elsif Is_Rewrite_Insertion
(N2
) then
8676 elsif not FCE
(N1
, N2
) then
8689 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean is
8690 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
8695 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
8700 Act
:= First
(Actuals
);
8702 if Nkind
(Op_Node
) in N_Binary_Op
then
8703 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
8710 return Present
(Act
)
8711 and then FCE
(Right_Opnd
(Op_Node
), Act
)
8712 and then No
(Next
(Act
));
8716 -- Start of processing for Fully_Conformant_Expressions
8719 -- Non-conformant if paren count does not match. Note: if some idiot
8720 -- complains that we don't do this right for more than 3 levels of
8721 -- parentheses, they will be treated with the respect they deserve.
8723 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
8726 -- If same entities are referenced, then they are conformant even if
8727 -- they have different forms (RM 8.3.1(19-20)).
8729 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
8730 if Present
(Entity
(E1
)) then
8731 return Entity
(E1
) = Entity
(E2
)
8732 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
8733 and then Ekind
(Entity
(E1
)) = E_Discriminant
8734 and then Ekind
(Entity
(E2
)) = E_In_Parameter
);
8736 elsif Nkind
(E1
) = N_Expanded_Name
8737 and then Nkind
(E2
) = N_Expanded_Name
8738 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
8739 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
8741 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
8744 -- Identifiers in component associations don't always have
8745 -- entities, but their names must conform.
8747 return Nkind
(E1
) = N_Identifier
8748 and then Nkind
(E2
) = N_Identifier
8749 and then Chars
(E1
) = Chars
(E2
);
8752 elsif Nkind
(E1
) = N_Character_Literal
8753 and then Nkind
(E2
) = N_Expanded_Name
8755 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
8756 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
8758 elsif Nkind
(E2
) = N_Character_Literal
8759 and then Nkind
(E1
) = N_Expanded_Name
8761 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
8762 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
8764 elsif Nkind
(E1
) in N_Op
and then Nkind
(E2
) = N_Function_Call
then
8765 return FCO
(E1
, E2
);
8767 elsif Nkind
(E2
) in N_Op
and then Nkind
(E1
) = N_Function_Call
then
8768 return FCO
(E2
, E1
);
8770 -- Otherwise we must have the same syntactic entity
8772 elsif Nkind
(E1
) /= Nkind
(E2
) then
8775 -- At this point, we specialize by node type
8782 FCL
(Expressions
(E1
), Expressions
(E2
))
8784 FCL
(Component_Associations
(E1
),
8785 Component_Associations
(E2
));
8788 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
8790 Nkind
(Expression
(E2
)) = N_Qualified_Expression
8792 return FCE
(Expression
(E1
), Expression
(E2
));
8794 -- Check that the subtype marks and any constraints
8799 Indic1
: constant Node_Id
:= Expression
(E1
);
8800 Indic2
: constant Node_Id
:= Expression
(E2
);
8805 if Nkind
(Indic1
) /= N_Subtype_Indication
then
8807 Nkind
(Indic2
) /= N_Subtype_Indication
8808 and then Entity
(Indic1
) = Entity
(Indic2
);
8810 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
8812 Nkind
(Indic1
) /= N_Subtype_Indication
8813 and then Entity
(Indic1
) = Entity
(Indic2
);
8816 if Entity
(Subtype_Mark
(Indic1
)) /=
8817 Entity
(Subtype_Mark
(Indic2
))
8822 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
8823 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
8824 while Present
(Elt1
) and then Present
(Elt2
) loop
8825 if not FCE
(Elt1
, Elt2
) then
8838 when N_Attribute_Reference
=>
8840 Attribute_Name
(E1
) = Attribute_Name
(E2
)
8841 and then FCL
(Expressions
(E1
), Expressions
(E2
));
8845 Entity
(E1
) = Entity
(E2
)
8846 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
8847 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
8849 when N_Short_Circuit | N_Membership_Test
=>
8851 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
8853 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
8855 when N_Case_Expression
=>
8861 if not FCE
(Expression
(E1
), Expression
(E2
)) then
8865 Alt1
:= First
(Alternatives
(E1
));
8866 Alt2
:= First
(Alternatives
(E2
));
8868 if Present
(Alt1
) /= Present
(Alt2
) then
8870 elsif No
(Alt1
) then
8874 if not FCE
(Expression
(Alt1
), Expression
(Alt2
))
8875 or else not FCL
(Discrete_Choices
(Alt1
),
8876 Discrete_Choices
(Alt2
))
8887 when N_Character_Literal
=>
8889 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
8891 when N_Component_Association
=>
8893 FCL
(Choices
(E1
), Choices
(E2
))
8895 FCE
(Expression
(E1
), Expression
(E2
));
8897 when N_Explicit_Dereference
=>
8899 FCE
(Prefix
(E1
), Prefix
(E2
));
8901 when N_Extension_Aggregate
=>
8903 FCL
(Expressions
(E1
), Expressions
(E2
))
8904 and then Null_Record_Present
(E1
) =
8905 Null_Record_Present
(E2
)
8906 and then FCL
(Component_Associations
(E1
),
8907 Component_Associations
(E2
));
8909 when N_Function_Call
=>
8911 FCE
(Name
(E1
), Name
(E2
))
8913 FCL
(Parameter_Associations
(E1
),
8914 Parameter_Associations
(E2
));
8916 when N_If_Expression
=>
8918 FCL
(Expressions
(E1
), Expressions
(E2
));
8920 when N_Indexed_Component
=>
8922 FCE
(Prefix
(E1
), Prefix
(E2
))
8924 FCL
(Expressions
(E1
), Expressions
(E2
));
8926 when N_Integer_Literal
=>
8927 return (Intval
(E1
) = Intval
(E2
));
8932 when N_Operator_Symbol
=>
8934 Chars
(E1
) = Chars
(E2
);
8936 when N_Others_Choice
=>
8939 when N_Parameter_Association
=>
8941 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
8942 and then FCE
(Explicit_Actual_Parameter
(E1
),
8943 Explicit_Actual_Parameter
(E2
));
8945 when N_Qualified_Expression
=>
8947 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
8949 FCE
(Expression
(E1
), Expression
(E2
));
8951 when N_Quantified_Expression
=>
8952 if not FCE
(Condition
(E1
), Condition
(E2
)) then
8956 if Present
(Loop_Parameter_Specification
(E1
))
8957 and then Present
(Loop_Parameter_Specification
(E2
))
8960 L1
: constant Node_Id
:=
8961 Loop_Parameter_Specification
(E1
);
8962 L2
: constant Node_Id
:=
8963 Loop_Parameter_Specification
(E2
);
8967 Reverse_Present
(L1
) = Reverse_Present
(L2
)
8969 FCE
(Defining_Identifier
(L1
),
8970 Defining_Identifier
(L2
))
8972 FCE
(Discrete_Subtype_Definition
(L1
),
8973 Discrete_Subtype_Definition
(L2
));
8976 elsif Present
(Iterator_Specification
(E1
))
8977 and then Present
(Iterator_Specification
(E2
))
8980 I1
: constant Node_Id
:= Iterator_Specification
(E1
);
8981 I2
: constant Node_Id
:= Iterator_Specification
(E2
);
8985 FCE
(Defining_Identifier
(I1
),
8986 Defining_Identifier
(I2
))
8988 Of_Present
(I1
) = Of_Present
(I2
)
8990 Reverse_Present
(I1
) = Reverse_Present
(I2
)
8991 and then FCE
(Name
(I1
), Name
(I2
))
8992 and then FCE
(Subtype_Indication
(I1
),
8993 Subtype_Indication
(I2
));
8996 -- The quantified expressions used different specifications to
8997 -- walk their respective ranges.
9005 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
9007 FCE
(High_Bound
(E1
), High_Bound
(E2
));
9009 when N_Real_Literal
=>
9010 return (Realval
(E1
) = Realval
(E2
));
9012 when N_Selected_Component
=>
9014 FCE
(Prefix
(E1
), Prefix
(E2
))
9016 FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
9020 FCE
(Prefix
(E1
), Prefix
(E2
))
9022 FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
9024 when N_String_Literal
=>
9026 S1
: constant String_Id
:= Strval
(E1
);
9027 S2
: constant String_Id
:= Strval
(E2
);
9028 L1
: constant Nat
:= String_Length
(S1
);
9029 L2
: constant Nat
:= String_Length
(S2
);
9036 for J
in 1 .. L1
loop
9037 if Get_String_Char
(S1
, J
) /=
9038 Get_String_Char
(S2
, J
)
9048 when N_Type_Conversion
=>
9050 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
9052 FCE
(Expression
(E1
), Expression
(E2
));
9056 Entity
(E1
) = Entity
(E2
)
9058 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
9060 when N_Unchecked_Type_Conversion
=>
9062 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
9064 FCE
(Expression
(E1
), Expression
(E2
));
9066 -- All other node types cannot appear in this context. Strictly
9067 -- we should raise a fatal internal error. Instead we just ignore
9068 -- the nodes. This means that if anyone makes a mistake in the
9069 -- expander and mucks an expression tree irretrievably, the result
9070 -- will be a failure to detect a (probably very obscure) case
9071 -- of non-conformance, which is better than bombing on some
9072 -- case where two expressions do in fact conform.
9079 end Fully_Conformant_Expressions
;
9081 ----------------------------------------
9082 -- Fully_Conformant_Discrete_Subtypes --
9083 ----------------------------------------
9085 function Fully_Conformant_Discrete_Subtypes
9086 (Given_S1
: Node_Id
;
9087 Given_S2
: Node_Id
) return Boolean
9089 S1
: constant Node_Id
:= Original_Node
(Given_S1
);
9090 S2
: constant Node_Id
:= Original_Node
(Given_S2
);
9092 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean;
9093 -- Special-case for a bound given by a discriminant, which in the body
9094 -- is replaced with the discriminal of the enclosing type.
9096 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean;
9097 -- Check both bounds
9099 -----------------------
9100 -- Conforming_Bounds --
9101 -----------------------
9103 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean is
9105 if Is_Entity_Name
(B1
)
9106 and then Is_Entity_Name
(B2
)
9107 and then Ekind
(Entity
(B1
)) = E_Discriminant
9109 return Chars
(B1
) = Chars
(B2
);
9112 return Fully_Conformant_Expressions
(B1
, B2
);
9114 end Conforming_Bounds
;
9116 -----------------------
9117 -- Conforming_Ranges --
9118 -----------------------
9120 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean is
9123 Conforming_Bounds
(Low_Bound
(R1
), Low_Bound
(R2
))
9125 Conforming_Bounds
(High_Bound
(R1
), High_Bound
(R2
));
9126 end Conforming_Ranges
;
9128 -- Start of processing for Fully_Conformant_Discrete_Subtypes
9131 if Nkind
(S1
) /= Nkind
(S2
) then
9134 elsif Is_Entity_Name
(S1
) then
9135 return Entity
(S1
) = Entity
(S2
);
9137 elsif Nkind
(S1
) = N_Range
then
9138 return Conforming_Ranges
(S1
, S2
);
9140 elsif Nkind
(S1
) = N_Subtype_Indication
then
9142 Entity
(Subtype_Mark
(S1
)) = Entity
(Subtype_Mark
(S2
))
9145 (Range_Expression
(Constraint
(S1
)),
9146 Range_Expression
(Constraint
(S2
)));
9150 end Fully_Conformant_Discrete_Subtypes
;
9152 --------------------
9153 -- Install_Entity --
9154 --------------------
9156 procedure Install_Entity
(E
: Entity_Id
) is
9157 Prev
: constant Entity_Id
:= Current_Entity
(E
);
9159 Set_Is_Immediately_Visible
(E
);
9160 Set_Current_Entity
(E
);
9161 Set_Homonym
(E
, Prev
);
9164 ---------------------
9165 -- Install_Formals --
9166 ---------------------
9168 procedure Install_Formals
(Id
: Entity_Id
) is
9171 F
:= First_Formal
(Id
);
9172 while Present
(F
) loop
9176 end Install_Formals
;
9178 -----------------------------
9179 -- Is_Interface_Conformant --
9180 -----------------------------
9182 function Is_Interface_Conformant
9183 (Tagged_Type
: Entity_Id
;
9184 Iface_Prim
: Entity_Id
;
9185 Prim
: Entity_Id
) return Boolean
9187 -- The operation may in fact be an inherited (implicit) operation
9188 -- rather than the original interface primitive, so retrieve the
9189 -- ultimate ancestor.
9191 Iface
: constant Entity_Id
:=
9192 Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
));
9193 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Prim
);
9195 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
;
9196 -- Return the controlling formal of Prim
9198 ------------------------
9199 -- Controlling_Formal --
9200 ------------------------
9202 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
is
9206 E
:= First_Entity
(Prim
);
9207 while Present
(E
) loop
9208 if Is_Formal
(E
) and then Is_Controlling_Formal
(E
) then
9216 end Controlling_Formal
;
9220 Iface_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Iface_Prim
);
9221 Prim_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Prim
);
9223 -- Start of processing for Is_Interface_Conformant
9226 pragma Assert
(Is_Subprogram
(Iface_Prim
)
9227 and then Is_Subprogram
(Prim
)
9228 and then Is_Dispatching_Operation
(Iface_Prim
)
9229 and then Is_Dispatching_Operation
(Prim
));
9231 pragma Assert
(Is_Interface
(Iface
)
9232 or else (Present
(Alias
(Iface_Prim
))
9235 (Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
)))));
9237 if Prim
= Iface_Prim
9238 or else not Is_Subprogram
(Prim
)
9239 or else Ekind
(Prim
) /= Ekind
(Iface_Prim
)
9240 or else not Is_Dispatching_Operation
(Prim
)
9241 or else Scope
(Prim
) /= Scope
(Tagged_Type
)
9243 or else Base_Type
(Typ
) /= Base_Type
(Tagged_Type
)
9244 or else not Primitive_Names_Match
(Iface_Prim
, Prim
)
9248 -- The mode of the controlling formals must match
9250 elsif Present
(Iface_Ctrl_F
)
9251 and then Present
(Prim_Ctrl_F
)
9252 and then Ekind
(Iface_Ctrl_F
) /= Ekind
(Prim_Ctrl_F
)
9256 -- Case of a procedure, or a function whose result type matches the
9257 -- result type of the interface primitive, or a function that has no
9258 -- controlling result (I or access I).
9260 elsif Ekind
(Iface_Prim
) = E_Procedure
9261 or else Etype
(Prim
) = Etype
(Iface_Prim
)
9262 or else not Has_Controlling_Result
(Prim
)
9264 return Type_Conformant
9265 (Iface_Prim
, Prim
, Skip_Controlling_Formals
=> True);
9267 -- Case of a function returning an interface, or an access to one. Check
9268 -- that the return types correspond.
9270 elsif Implements_Interface
(Typ
, Iface
) then
9271 if (Ekind
(Etype
(Prim
)) = E_Anonymous_Access_Type
)
9273 (Ekind
(Etype
(Iface_Prim
)) = E_Anonymous_Access_Type
)
9278 Type_Conformant
(Prim
, Ultimate_Alias
(Iface_Prim
),
9279 Skip_Controlling_Formals
=> True);
9285 end Is_Interface_Conformant
;
9287 ---------------------------------
9288 -- Is_Non_Overriding_Operation --
9289 ---------------------------------
9291 function Is_Non_Overriding_Operation
9292 (Prev_E
: Entity_Id
;
9293 New_E
: Entity_Id
) return Boolean
9297 G_Typ
: Entity_Id
:= Empty
;
9299 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
9300 -- If F_Type is a derived type associated with a generic actual subtype,
9301 -- then return its Generic_Parent_Type attribute, else return Empty.
9303 function Types_Correspond
9304 (P_Type
: Entity_Id
;
9305 N_Type
: Entity_Id
) return Boolean;
9306 -- Returns true if and only if the types (or designated types in the
9307 -- case of anonymous access types) are the same or N_Type is derived
9308 -- directly or indirectly from P_Type.
9310 -----------------------------
9311 -- Get_Generic_Parent_Type --
9312 -----------------------------
9314 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
9320 if Is_Derived_Type
(F_Typ
)
9321 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
9323 -- The tree must be traversed to determine the parent subtype in
9324 -- the generic unit, which unfortunately isn't always available
9325 -- via semantic attributes. ??? (Note: The use of Original_Node
9326 -- is needed for cases where a full derived type has been
9329 Defn
:= Type_Definition
(Original_Node
(Parent
(F_Typ
)));
9330 if Nkind
(Defn
) = N_Derived_Type_Definition
then
9331 Indic
:= Subtype_Indication
(Defn
);
9333 if Nkind
(Indic
) = N_Subtype_Indication
then
9334 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
9336 G_Typ
:= Entity
(Indic
);
9339 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
9340 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
9342 return Generic_Parent_Type
(Parent
(G_Typ
));
9348 end Get_Generic_Parent_Type
;
9350 ----------------------
9351 -- Types_Correspond --
9352 ----------------------
9354 function Types_Correspond
9355 (P_Type
: Entity_Id
;
9356 N_Type
: Entity_Id
) return Boolean
9358 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
9359 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
9362 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
9363 Prev_Type
:= Designated_Type
(Prev_Type
);
9366 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
9367 New_Type
:= Designated_Type
(New_Type
);
9370 if Prev_Type
= New_Type
then
9373 elsif not Is_Class_Wide_Type
(New_Type
) then
9374 while Etype
(New_Type
) /= New_Type
loop
9375 New_Type
:= Etype
(New_Type
);
9376 if New_Type
= Prev_Type
then
9382 end Types_Correspond
;
9384 -- Start of processing for Is_Non_Overriding_Operation
9387 -- In the case where both operations are implicit derived subprograms
9388 -- then neither overrides the other. This can only occur in certain
9389 -- obscure cases (e.g., derivation from homographs created in a generic
9392 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
9395 elsif Ekind
(Current_Scope
) = E_Package
9396 and then Is_Generic_Instance
(Current_Scope
)
9397 and then In_Private_Part
(Current_Scope
)
9398 and then Comes_From_Source
(New_E
)
9400 -- We examine the formals and result type of the inherited operation,
9401 -- to determine whether their type is derived from (the instance of)
9402 -- a generic type. The first such formal or result type is the one
9405 Formal
:= First_Formal
(Prev_E
);
9406 while Present
(Formal
) loop
9407 F_Typ
:= Base_Type
(Etype
(Formal
));
9409 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
9410 F_Typ
:= Designated_Type
(F_Typ
);
9413 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
9414 exit when Present
(G_Typ
);
9416 Next_Formal
(Formal
);
9419 if No
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
9420 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
9427 -- If the generic type is a private type, then the original operation
9428 -- was not overriding in the generic, because there was no primitive
9429 -- operation to override.
9431 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
9432 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
9433 N_Formal_Private_Type_Definition
9437 -- The generic parent type is the ancestor of a formal derived
9438 -- type declaration. We need to check whether it has a primitive
9439 -- operation that should be overridden by New_E in the generic.
9443 P_Formal
: Entity_Id
;
9444 N_Formal
: Entity_Id
;
9448 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
9451 while Present
(Prim_Elt
) loop
9452 P_Prim
:= Node
(Prim_Elt
);
9454 if Chars
(P_Prim
) = Chars
(New_E
)
9455 and then Ekind
(P_Prim
) = Ekind
(New_E
)
9457 P_Formal
:= First_Formal
(P_Prim
);
9458 N_Formal
:= First_Formal
(New_E
);
9459 while Present
(P_Formal
) and then Present
(N_Formal
) loop
9460 P_Typ
:= Etype
(P_Formal
);
9461 N_Typ
:= Etype
(N_Formal
);
9463 if not Types_Correspond
(P_Typ
, N_Typ
) then
9467 Next_Entity
(P_Formal
);
9468 Next_Entity
(N_Formal
);
9471 -- Found a matching primitive operation belonging to the
9472 -- formal ancestor type, so the new subprogram is
9476 and then No
(N_Formal
)
9477 and then (Ekind
(New_E
) /= E_Function
9480 (Etype
(P_Prim
), Etype
(New_E
)))
9486 Next_Elmt
(Prim_Elt
);
9489 -- If no match found, then the new subprogram does not override
9490 -- in the generic (nor in the instance).
9492 -- If the type in question is not abstract, and the subprogram
9493 -- is, this will be an error if the new operation is in the
9494 -- private part of the instance. Emit a warning now, which will
9495 -- make the subsequent error message easier to understand.
9497 if not Is_Abstract_Type
(F_Typ
)
9498 and then Is_Abstract_Subprogram
(Prev_E
)
9499 and then In_Private_Part
(Current_Scope
)
9501 Error_Msg_Node_2
:= F_Typ
;
9503 ("private operation& in generic unit does not override " &
9504 "any primitive operation of& (RM 12.3 (18))??",
9514 end Is_Non_Overriding_Operation
;
9516 -------------------------------------
9517 -- List_Inherited_Pre_Post_Aspects --
9518 -------------------------------------
9520 procedure List_Inherited_Pre_Post_Aspects
(E
: Entity_Id
) is
9522 if Opt
.List_Inherited_Aspects
9523 and then (Is_Subprogram
(E
) or else Is_Generic_Subprogram
(E
))
9526 Inherited
: constant Subprogram_List
:= Inherited_Subprograms
(E
);
9530 for J
in Inherited
'Range loop
9531 P
:= Pre_Post_Conditions
(Contract
(Inherited
(J
)));
9532 while Present
(P
) loop
9533 Error_Msg_Sloc
:= Sloc
(P
);
9535 if Class_Present
(P
) and then not Split_PPC
(P
) then
9536 if Pragma_Name
(P
) = Name_Precondition
then
9538 ("info: & inherits `Pre''Class` aspect from #?L?",
9542 ("info: & inherits `Post''Class` aspect from #?L?",
9547 P
:= Next_Pragma
(P
);
9552 end List_Inherited_Pre_Post_Aspects
;
9554 ------------------------------
9555 -- Make_Inequality_Operator --
9556 ------------------------------
9558 -- S is the defining identifier of an equality operator. We build a
9559 -- subprogram declaration with the right signature. This operation is
9560 -- intrinsic, because it is always expanded as the negation of the
9561 -- call to the equality function.
9563 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
9564 Loc
: constant Source_Ptr
:= Sloc
(S
);
9567 Op_Name
: Entity_Id
;
9569 FF
: constant Entity_Id
:= First_Formal
(S
);
9570 NF
: constant Entity_Id
:= Next_Formal
(FF
);
9573 -- Check that equality was properly defined, ignore call if not
9580 A
: constant Entity_Id
:=
9581 Make_Defining_Identifier
(Sloc
(FF
),
9582 Chars
=> Chars
(FF
));
9584 B
: constant Entity_Id
:=
9585 Make_Defining_Identifier
(Sloc
(NF
),
9586 Chars
=> Chars
(NF
));
9589 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
9591 Formals
:= New_List
(
9592 Make_Parameter_Specification
(Loc
,
9593 Defining_Identifier
=> A
,
9595 New_Reference_To
(Etype
(First_Formal
(S
)),
9596 Sloc
(Etype
(First_Formal
(S
))))),
9598 Make_Parameter_Specification
(Loc
,
9599 Defining_Identifier
=> B
,
9601 New_Reference_To
(Etype
(Next_Formal
(First_Formal
(S
))),
9602 Sloc
(Etype
(Next_Formal
(First_Formal
(S
)))))));
9605 Make_Subprogram_Declaration
(Loc
,
9607 Make_Function_Specification
(Loc
,
9608 Defining_Unit_Name
=> Op_Name
,
9609 Parameter_Specifications
=> Formals
,
9610 Result_Definition
=>
9611 New_Reference_To
(Standard_Boolean
, Loc
)));
9613 -- Insert inequality right after equality if it is explicit or after
9614 -- the derived type when implicit. These entities are created only
9615 -- for visibility purposes, and eventually replaced in the course
9616 -- of expansion, so they do not need to be attached to the tree and
9617 -- seen by the back-end. Keeping them internal also avoids spurious
9618 -- freezing problems. The declaration is inserted in the tree for
9619 -- analysis, and removed afterwards. If the equality operator comes
9620 -- from an explicit declaration, attach the inequality immediately
9621 -- after. Else the equality is inherited from a derived type
9622 -- declaration, so insert inequality after that declaration.
9624 if No
(Alias
(S
)) then
9625 Insert_After
(Unit_Declaration_Node
(S
), Decl
);
9626 elsif Is_List_Member
(Parent
(S
)) then
9627 Insert_After
(Parent
(S
), Decl
);
9629 Insert_After
(Parent
(Etype
(First_Formal
(S
))), Decl
);
9632 Mark_Rewrite_Insertion
(Decl
);
9633 Set_Is_Intrinsic_Subprogram
(Op_Name
);
9636 Set_Has_Completion
(Op_Name
);
9637 Set_Corresponding_Equality
(Op_Name
, S
);
9638 Set_Is_Abstract_Subprogram
(Op_Name
, Is_Abstract_Subprogram
(S
));
9640 end Make_Inequality_Operator
;
9642 ----------------------
9643 -- May_Need_Actuals --
9644 ----------------------
9646 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
9651 F
:= First_Formal
(Fun
);
9653 while Present
(F
) loop
9654 if No
(Default_Value
(F
)) then
9662 Set_Needs_No_Actuals
(Fun
, B
);
9663 end May_Need_Actuals
;
9665 ---------------------
9666 -- Mode_Conformant --
9667 ---------------------
9669 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
9672 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
9674 end Mode_Conformant
;
9676 ---------------------------
9677 -- New_Overloaded_Entity --
9678 ---------------------------
9680 procedure New_Overloaded_Entity
9682 Derived_Type
: Entity_Id
:= Empty
)
9684 Overridden_Subp
: Entity_Id
:= Empty
;
9685 -- Set if the current scope has an operation that is type-conformant
9686 -- with S, and becomes hidden by S.
9688 Is_Primitive_Subp
: Boolean;
9689 -- Set to True if the new subprogram is primitive
9692 -- Entity that S overrides
9694 Prev_Vis
: Entity_Id
:= Empty
;
9695 -- Predecessor of E in Homonym chain
9697 procedure Check_For_Primitive_Subprogram
9698 (Is_Primitive
: out Boolean;
9699 Is_Overriding
: Boolean := False);
9700 -- If the subprogram being analyzed is a primitive operation of the type
9701 -- of a formal or result, set the Has_Primitive_Operations flag on the
9702 -- type, and set Is_Primitive to True (otherwise set to False). Set the
9703 -- corresponding flag on the entity itself for later use.
9705 procedure Check_Synchronized_Overriding
9706 (Def_Id
: Entity_Id
;
9707 Overridden_Subp
: out Entity_Id
);
9708 -- First determine if Def_Id is an entry or a subprogram either defined
9709 -- in the scope of a task or protected type, or is a primitive of such
9710 -- a type. Check whether Def_Id overrides a subprogram of an interface
9711 -- implemented by the synchronized type, return the overridden entity
9714 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
9715 -- Check that E is declared in the private part of the current package,
9716 -- or in the package body, where it may hide a previous declaration.
9717 -- We can't use In_Private_Part by itself because this flag is also
9718 -- set when freezing entities, so we must examine the place of the
9719 -- declaration in the tree, and recognize wrapper packages as well.
9721 function Is_Overriding_Alias
9723 New_E
: Entity_Id
) return Boolean;
9724 -- Check whether new subprogram and old subprogram are both inherited
9725 -- from subprograms that have distinct dispatch table entries. This can
9726 -- occur with derivations from instances with accidental homonyms. The
9727 -- function is conservative given that the converse is only true within
9728 -- instances that contain accidental overloadings.
9730 ------------------------------------
9731 -- Check_For_Primitive_Subprogram --
9732 ------------------------------------
9734 procedure Check_For_Primitive_Subprogram
9735 (Is_Primitive
: out Boolean;
9736 Is_Overriding
: Boolean := False)
9742 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
9743 -- Returns true if T is declared in the visible part of the current
9744 -- package scope; otherwise returns false. Assumes that T is declared
9747 procedure Check_Private_Overriding
(T
: Entity_Id
);
9748 -- Checks that if a primitive abstract subprogram of a visible
9749 -- abstract type is declared in a private part, then it must override
9750 -- an abstract subprogram declared in the visible part. Also checks
9751 -- that if a primitive function with a controlling result is declared
9752 -- in a private part, then it must override a function declared in
9753 -- the visible part.
9755 ------------------------------
9756 -- Check_Private_Overriding --
9757 ------------------------------
9759 procedure Check_Private_Overriding
(T
: Entity_Id
) is
9761 if Is_Package_Or_Generic_Package
(Current_Scope
)
9762 and then In_Private_Part
(Current_Scope
)
9763 and then Visible_Part_Type
(T
)
9764 and then not In_Instance
9766 if Is_Abstract_Type
(T
)
9767 and then Is_Abstract_Subprogram
(S
)
9768 and then (not Is_Overriding
9769 or else not Is_Abstract_Subprogram
(E
))
9772 ("abstract subprograms must be visible "
9773 & "(RM 3.9.3(10))!", S
);
9775 elsif Ekind
(S
) = E_Function
and then not Is_Overriding
then
9776 if Is_Tagged_Type
(T
) and then T
= Base_Type
(Etype
(S
)) then
9778 ("private function with tagged result must"
9779 & " override visible-part function", S
);
9781 ("\move subprogram to the visible part"
9782 & " (RM 3.9.3(10))", S
);
9784 -- AI05-0073: extend this test to the case of a function
9785 -- with a controlling access result.
9787 elsif Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
9788 and then Is_Tagged_Type
(Designated_Type
(Etype
(S
)))
9790 not Is_Class_Wide_Type
(Designated_Type
(Etype
(S
)))
9791 and then Ada_Version
>= Ada_2012
9794 ("private function with controlling access result "
9795 & "must override visible-part function", S
);
9797 ("\move subprogram to the visible part"
9798 & " (RM 3.9.3(10))", S
);
9802 end Check_Private_Overriding
;
9804 -----------------------
9805 -- Visible_Part_Type --
9806 -----------------------
9808 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
9809 P
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
9813 -- If the entity is a private type, then it must be declared in a
9816 if Ekind
(T
) in Private_Kind
then
9820 -- Otherwise, we traverse the visible part looking for its
9821 -- corresponding declaration. We cannot use the declaration
9822 -- node directly because in the private part the entity of a
9823 -- private type is the one in the full view, which does not
9824 -- indicate that it is the completion of something visible.
9826 N
:= First
(Visible_Declarations
(Specification
(P
)));
9827 while Present
(N
) loop
9828 if Nkind
(N
) = N_Full_Type_Declaration
9829 and then Present
(Defining_Identifier
(N
))
9830 and then T
= Defining_Identifier
(N
)
9834 elsif Nkind_In
(N
, N_Private_Type_Declaration
,
9835 N_Private_Extension_Declaration
)
9836 and then Present
(Defining_Identifier
(N
))
9837 and then T
= Full_View
(Defining_Identifier
(N
))
9846 end Visible_Part_Type
;
9848 -- Start of processing for Check_For_Primitive_Subprogram
9851 Is_Primitive
:= False;
9853 if not Comes_From_Source
(S
) then
9856 -- If subprogram is at library level, it is not primitive operation
9858 elsif Current_Scope
= Standard_Standard
then
9861 elsif (Is_Package_Or_Generic_Package
(Current_Scope
)
9862 and then not In_Package_Body
(Current_Scope
))
9863 or else Is_Overriding
9865 -- For function, check return type
9867 if Ekind
(S
) = E_Function
then
9868 if Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
then
9869 F_Typ
:= Designated_Type
(Etype
(S
));
9874 B_Typ
:= Base_Type
(F_Typ
);
9876 if Scope
(B_Typ
) = Current_Scope
9877 and then not Is_Class_Wide_Type
(B_Typ
)
9878 and then not Is_Generic_Type
(B_Typ
)
9880 Is_Primitive
:= True;
9881 Set_Has_Primitive_Operations
(B_Typ
);
9882 Set_Is_Primitive
(S
);
9883 Check_Private_Overriding
(B_Typ
);
9887 -- For all subprograms, check formals
9889 Formal
:= First_Formal
(S
);
9890 while Present
(Formal
) loop
9891 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
9892 F_Typ
:= Designated_Type
(Etype
(Formal
));
9894 F_Typ
:= Etype
(Formal
);
9897 B_Typ
:= Base_Type
(F_Typ
);
9899 if Ekind
(B_Typ
) = E_Access_Subtype
then
9900 B_Typ
:= Base_Type
(B_Typ
);
9903 if Scope
(B_Typ
) = Current_Scope
9904 and then not Is_Class_Wide_Type
(B_Typ
)
9905 and then not Is_Generic_Type
(B_Typ
)
9907 Is_Primitive
:= True;
9908 Set_Is_Primitive
(S
);
9909 Set_Has_Primitive_Operations
(B_Typ
);
9910 Check_Private_Overriding
(B_Typ
);
9913 Next_Formal
(Formal
);
9916 -- Special case: An equality function can be redefined for a type
9917 -- occurring in a declarative part, and won't otherwise be treated as
9918 -- a primitive because it doesn't occur in a package spec and doesn't
9919 -- override an inherited subprogram. It's important that we mark it
9920 -- primitive so it can be returned by Collect_Primitive_Operations
9921 -- and be used in composing the equality operation of later types
9922 -- that have a component of the type.
9924 elsif Chars
(S
) = Name_Op_Eq
9925 and then Etype
(S
) = Standard_Boolean
9927 B_Typ
:= Base_Type
(Etype
(First_Formal
(S
)));
9929 if Scope
(B_Typ
) = Current_Scope
9931 Base_Type
(Etype
(Next_Formal
(First_Formal
(S
)))) = B_Typ
9932 and then not Is_Limited_Type
(B_Typ
)
9934 Is_Primitive
:= True;
9935 Set_Is_Primitive
(S
);
9936 Set_Has_Primitive_Operations
(B_Typ
);
9937 Check_Private_Overriding
(B_Typ
);
9940 end Check_For_Primitive_Subprogram
;
9942 -----------------------------------
9943 -- Check_Synchronized_Overriding --
9944 -----------------------------------
9946 procedure Check_Synchronized_Overriding
9947 (Def_Id
: Entity_Id
;
9948 Overridden_Subp
: out Entity_Id
)
9950 Ifaces_List
: Elist_Id
;
9954 function Matches_Prefixed_View_Profile
9955 (Prim_Params
: List_Id
;
9956 Iface_Params
: List_Id
) return Boolean;
9957 -- Determine whether a subprogram's parameter profile Prim_Params
9958 -- matches that of a potentially overridden interface subprogram
9959 -- Iface_Params. Also determine if the type of first parameter of
9960 -- Iface_Params is an implemented interface.
9962 -----------------------------------
9963 -- Matches_Prefixed_View_Profile --
9964 -----------------------------------
9966 function Matches_Prefixed_View_Profile
9967 (Prim_Params
: List_Id
;
9968 Iface_Params
: List_Id
) return Boolean
9970 Iface_Id
: Entity_Id
;
9971 Iface_Param
: Node_Id
;
9972 Iface_Typ
: Entity_Id
;
9973 Prim_Id
: Entity_Id
;
9974 Prim_Param
: Node_Id
;
9975 Prim_Typ
: Entity_Id
;
9977 function Is_Implemented
9978 (Ifaces_List
: Elist_Id
;
9979 Iface
: Entity_Id
) return Boolean;
9980 -- Determine if Iface is implemented by the current task or
9983 --------------------
9984 -- Is_Implemented --
9985 --------------------
9987 function Is_Implemented
9988 (Ifaces_List
: Elist_Id
;
9989 Iface
: Entity_Id
) return Boolean
9991 Iface_Elmt
: Elmt_Id
;
9994 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
9995 while Present
(Iface_Elmt
) loop
9996 if Node
(Iface_Elmt
) = Iface
then
10000 Next_Elmt
(Iface_Elmt
);
10004 end Is_Implemented
;
10006 -- Start of processing for Matches_Prefixed_View_Profile
10009 Iface_Param
:= First
(Iface_Params
);
10010 Iface_Typ
:= Etype
(Defining_Identifier
(Iface_Param
));
10012 if Is_Access_Type
(Iface_Typ
) then
10013 Iface_Typ
:= Designated_Type
(Iface_Typ
);
10016 Prim_Param
:= First
(Prim_Params
);
10018 -- The first parameter of the potentially overridden subprogram
10019 -- must be an interface implemented by Prim.
10021 if not Is_Interface
(Iface_Typ
)
10022 or else not Is_Implemented
(Ifaces_List
, Iface_Typ
)
10027 -- The checks on the object parameters are done, move onto the
10028 -- rest of the parameters.
10030 if not In_Scope
then
10031 Prim_Param
:= Next
(Prim_Param
);
10034 Iface_Param
:= Next
(Iface_Param
);
10035 while Present
(Iface_Param
) and then Present
(Prim_Param
) loop
10036 Iface_Id
:= Defining_Identifier
(Iface_Param
);
10037 Iface_Typ
:= Find_Parameter_Type
(Iface_Param
);
10039 Prim_Id
:= Defining_Identifier
(Prim_Param
);
10040 Prim_Typ
:= Find_Parameter_Type
(Prim_Param
);
10042 if Ekind
(Iface_Typ
) = E_Anonymous_Access_Type
10043 and then Ekind
(Prim_Typ
) = E_Anonymous_Access_Type
10044 and then Is_Concurrent_Type
(Designated_Type
(Prim_Typ
))
10046 Iface_Typ
:= Designated_Type
(Iface_Typ
);
10047 Prim_Typ
:= Designated_Type
(Prim_Typ
);
10050 -- Case of multiple interface types inside a parameter profile
10052 -- (Obj_Param : in out Iface; ...; Param : Iface)
10054 -- If the interface type is implemented, then the matching type
10055 -- in the primitive should be the implementing record type.
10057 if Ekind
(Iface_Typ
) = E_Record_Type
10058 and then Is_Interface
(Iface_Typ
)
10059 and then Is_Implemented
(Ifaces_List
, Iface_Typ
)
10061 if Prim_Typ
/= Typ
then
10065 -- The two parameters must be both mode and subtype conformant
10067 elsif Ekind
(Iface_Id
) /= Ekind
(Prim_Id
)
10069 Conforming_Types
(Iface_Typ
, Prim_Typ
, Subtype_Conformant
)
10074 Next
(Iface_Param
);
10078 -- One of the two lists contains more parameters than the other
10080 if Present
(Iface_Param
) or else Present
(Prim_Param
) then
10085 end Matches_Prefixed_View_Profile
;
10087 -- Start of processing for Check_Synchronized_Overriding
10090 Overridden_Subp
:= Empty
;
10092 -- Def_Id must be an entry or a subprogram. We should skip predefined
10093 -- primitives internally generated by the frontend; however at this
10094 -- stage predefined primitives are still not fully decorated. As a
10095 -- minor optimization we skip here internally generated subprograms.
10097 if (Ekind
(Def_Id
) /= E_Entry
10098 and then Ekind
(Def_Id
) /= E_Function
10099 and then Ekind
(Def_Id
) /= E_Procedure
)
10100 or else not Comes_From_Source
(Def_Id
)
10105 -- Search for the concurrent declaration since it contains the list
10106 -- of all implemented interfaces. In this case, the subprogram is
10107 -- declared within the scope of a protected or a task type.
10109 if Present
(Scope
(Def_Id
))
10110 and then Is_Concurrent_Type
(Scope
(Def_Id
))
10111 and then not Is_Generic_Actual_Type
(Scope
(Def_Id
))
10113 Typ
:= Scope
(Def_Id
);
10116 -- The enclosing scope is not a synchronized type and the subprogram
10119 elsif No
(First_Formal
(Def_Id
)) then
10122 -- The subprogram has formals and hence it may be a primitive of a
10123 -- concurrent type.
10126 Typ
:= Etype
(First_Formal
(Def_Id
));
10128 if Is_Access_Type
(Typ
) then
10129 Typ
:= Directly_Designated_Type
(Typ
);
10132 if Is_Concurrent_Type
(Typ
)
10133 and then not Is_Generic_Actual_Type
(Typ
)
10137 -- This case occurs when the concurrent type is declared within
10138 -- a generic unit. As a result the corresponding record has been
10139 -- built and used as the type of the first formal, we just have
10140 -- to retrieve the corresponding concurrent type.
10142 elsif Is_Concurrent_Record_Type
(Typ
)
10143 and then not Is_Class_Wide_Type
(Typ
)
10144 and then Present
(Corresponding_Concurrent_Type
(Typ
))
10146 Typ
:= Corresponding_Concurrent_Type
(Typ
);
10154 -- There is no overriding to check if is an inherited operation in a
10155 -- type derivation on for a generic actual.
10157 Collect_Interfaces
(Typ
, Ifaces_List
);
10159 if Is_Empty_Elmt_List
(Ifaces_List
) then
10163 -- Determine whether entry or subprogram Def_Id overrides a primitive
10164 -- operation that belongs to one of the interfaces in Ifaces_List.
10167 Candidate
: Entity_Id
:= Empty
;
10168 Hom
: Entity_Id
:= Empty
;
10169 Iface_Typ
: Entity_Id
;
10170 Subp
: Entity_Id
:= Empty
;
10173 -- Traverse the homonym chain, looking for a potentially
10174 -- overridden subprogram that belongs to an implemented
10177 Hom
:= Current_Entity_In_Scope
(Def_Id
);
10178 while Present
(Hom
) loop
10182 or else not Is_Overloadable
(Subp
)
10183 or else not Is_Primitive
(Subp
)
10184 or else not Is_Dispatching_Operation
(Subp
)
10185 or else not Present
(Find_Dispatching_Type
(Subp
))
10186 or else not Is_Interface
(Find_Dispatching_Type
(Subp
))
10190 -- Entries and procedures can override abstract or null
10191 -- interface procedures.
10193 elsif (Ekind
(Def_Id
) = E_Procedure
10194 or else Ekind
(Def_Id
) = E_Entry
)
10195 and then Ekind
(Subp
) = E_Procedure
10196 and then Matches_Prefixed_View_Profile
10197 (Parameter_Specifications
(Parent
(Def_Id
)),
10198 Parameter_Specifications
(Parent
(Subp
)))
10202 -- For an overridden subprogram Subp, check whether the mode
10203 -- of its first parameter is correct depending on the kind
10204 -- of synchronized type.
10207 Formal
: constant Node_Id
:= First_Formal
(Candidate
);
10210 -- In order for an entry or a protected procedure to
10211 -- override, the first parameter of the overridden
10212 -- routine must be of mode "out", "in out" or
10213 -- access-to-variable.
10215 if Ekind_In
(Candidate
, E_Entry
, E_Procedure
)
10216 and then Is_Protected_Type
(Typ
)
10217 and then Ekind
(Formal
) /= E_In_Out_Parameter
10218 and then Ekind
(Formal
) /= E_Out_Parameter
10219 and then Nkind
(Parameter_Type
(Parent
(Formal
))) /=
10220 N_Access_Definition
10224 -- All other cases are OK since a task entry or routine
10225 -- does not have a restriction on the mode of the first
10226 -- parameter of the overridden interface routine.
10229 Overridden_Subp
:= Candidate
;
10234 -- Functions can override abstract interface functions
10236 elsif Ekind
(Def_Id
) = E_Function
10237 and then Ekind
(Subp
) = E_Function
10238 and then Matches_Prefixed_View_Profile
10239 (Parameter_Specifications
(Parent
(Def_Id
)),
10240 Parameter_Specifications
(Parent
(Subp
)))
10241 and then Etype
(Result_Definition
(Parent
(Def_Id
))) =
10242 Etype
(Result_Definition
(Parent
(Subp
)))
10244 Overridden_Subp
:= Subp
;
10248 Hom
:= Homonym
(Hom
);
10251 -- After examining all candidates for overriding, we are left with
10252 -- the best match which is a mode incompatible interface routine.
10253 -- Do not emit an error if the Expander is active since this error
10254 -- will be detected later on after all concurrent types are
10255 -- expanded and all wrappers are built. This check is meant for
10256 -- spec-only compilations.
10258 if Present
(Candidate
) and then not Expander_Active
then
10260 Find_Parameter_Type
(Parent
(First_Formal
(Candidate
)));
10262 -- Def_Id is primitive of a protected type, declared inside the
10263 -- type, and the candidate is primitive of a limited or
10264 -- synchronized interface.
10267 and then Is_Protected_Type
(Typ
)
10269 (Is_Limited_Interface
(Iface_Typ
)
10270 or else Is_Protected_Interface
(Iface_Typ
)
10271 or else Is_Synchronized_Interface
(Iface_Typ
)
10272 or else Is_Task_Interface
(Iface_Typ
))
10274 Error_Msg_PT
(Parent
(Typ
), Candidate
);
10278 Overridden_Subp
:= Candidate
;
10281 end Check_Synchronized_Overriding
;
10283 ----------------------------
10284 -- Is_Private_Declaration --
10285 ----------------------------
10287 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
10288 Priv_Decls
: List_Id
;
10289 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
10292 if Is_Package_Or_Generic_Package
(Current_Scope
)
10293 and then In_Private_Part
(Current_Scope
)
10296 Private_Declarations
(Package_Specification
(Current_Scope
));
10298 return In_Package_Body
(Current_Scope
)
10300 (Is_List_Member
(Decl
)
10301 and then List_Containing
(Decl
) = Priv_Decls
)
10302 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
10304 Is_Compilation_Unit
10305 (Defining_Entity
(Parent
(Decl
)))
10306 and then List_Containing
(Parent
(Parent
(Decl
))) =
10311 end Is_Private_Declaration
;
10313 --------------------------
10314 -- Is_Overriding_Alias --
10315 --------------------------
10317 function Is_Overriding_Alias
10318 (Old_E
: Entity_Id
;
10319 New_E
: Entity_Id
) return Boolean
10321 AO
: constant Entity_Id
:= Alias
(Old_E
);
10322 AN
: constant Entity_Id
:= Alias
(New_E
);
10325 return Scope
(AO
) /= Scope
(AN
)
10326 or else No
(DTC_Entity
(AO
))
10327 or else No
(DTC_Entity
(AN
))
10328 or else DT_Position
(AO
) = DT_Position
(AN
);
10329 end Is_Overriding_Alias
;
10331 -- Start of processing for New_Overloaded_Entity
10334 -- We need to look for an entity that S may override. This must be a
10335 -- homonym in the current scope, so we look for the first homonym of
10336 -- S in the current scope as the starting point for the search.
10338 E
:= Current_Entity_In_Scope
(S
);
10340 -- Ada 2005 (AI-251): Derivation of abstract interface primitives.
10341 -- They are directly added to the list of primitive operations of
10342 -- Derived_Type, unless this is a rederivation in the private part
10343 -- of an operation that was already derived in the visible part of
10344 -- the current package.
10346 if Ada_Version
>= Ada_2005
10347 and then Present
(Derived_Type
)
10348 and then Present
(Alias
(S
))
10349 and then Is_Dispatching_Operation
(Alias
(S
))
10350 and then Present
(Find_Dispatching_Type
(Alias
(S
)))
10351 and then Is_Interface
(Find_Dispatching_Type
(Alias
(S
)))
10353 -- For private types, when the full-view is processed we propagate to
10354 -- the full view the non-overridden entities whose attribute "alias"
10355 -- references an interface primitive. These entities were added by
10356 -- Derive_Subprograms to ensure that interface primitives are
10359 -- Inside_Freeze_Actions is non zero when S corresponds with an
10360 -- internal entity that links an interface primitive with its
10361 -- covering primitive through attribute Interface_Alias (see
10362 -- Add_Internal_Interface_Entities).
10364 if Inside_Freezing_Actions
= 0
10365 and then Is_Package_Or_Generic_Package
(Current_Scope
)
10366 and then In_Private_Part
(Current_Scope
)
10367 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
10368 and then Nkind
(Parent
(S
)) = N_Full_Type_Declaration
10369 and then Full_View
(Defining_Identifier
(Parent
(E
)))
10370 = Defining_Identifier
(Parent
(S
))
10371 and then Alias
(E
) = Alias
(S
)
10373 Check_Operation_From_Private_View
(S
, E
);
10374 Set_Is_Dispatching_Operation
(S
);
10379 Enter_Overloaded_Entity
(S
);
10380 Check_Dispatching_Operation
(S
, Empty
);
10381 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
10387 -- If there is no homonym then this is definitely not overriding
10390 Enter_Overloaded_Entity
(S
);
10391 Check_Dispatching_Operation
(S
, Empty
);
10392 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
10394 -- If subprogram has an explicit declaration, check whether it has an
10395 -- overriding indicator.
10397 if Comes_From_Source
(S
) then
10398 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
10400 -- (Ada 2012: AI05-0125-1): If S is a dispatching operation then
10401 -- it may have overridden some hidden inherited primitive. Update
10402 -- Overridden_Subp to avoid spurious errors when checking the
10403 -- overriding indicator.
10405 if Ada_Version
>= Ada_2012
10406 and then No
(Overridden_Subp
)
10407 and then Is_Dispatching_Operation
(S
)
10408 and then Present
(Overridden_Operation
(S
))
10410 Overridden_Subp
:= Overridden_Operation
(S
);
10413 Check_Overriding_Indicator
10414 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
10417 -- If there is a homonym that is not overloadable, then we have an
10418 -- error, except for the special cases checked explicitly below.
10420 elsif not Is_Overloadable
(E
) then
10422 -- Check for spurious conflict produced by a subprogram that has the
10423 -- same name as that of the enclosing generic package. The conflict
10424 -- occurs within an instance, between the subprogram and the renaming
10425 -- declaration for the package. After the subprogram, the package
10426 -- renaming declaration becomes hidden.
10428 if Ekind
(E
) = E_Package
10429 and then Present
(Renamed_Object
(E
))
10430 and then Renamed_Object
(E
) = Current_Scope
10431 and then Nkind
(Parent
(Renamed_Object
(E
))) =
10432 N_Package_Specification
10433 and then Present
(Generic_Parent
(Parent
(Renamed_Object
(E
))))
10436 Set_Is_Immediately_Visible
(E
, False);
10437 Enter_Overloaded_Entity
(S
);
10438 Set_Homonym
(S
, Homonym
(E
));
10439 Check_Dispatching_Operation
(S
, Empty
);
10440 Check_Overriding_Indicator
(S
, Empty
, Is_Primitive
=> False);
10442 -- If the subprogram is implicit it is hidden by the previous
10443 -- declaration. However if it is dispatching, it must appear in the
10444 -- dispatch table anyway, because it can be dispatched to even if it
10445 -- cannot be called directly.
10447 elsif Present
(Alias
(S
)) and then not Comes_From_Source
(S
) then
10448 Set_Scope
(S
, Current_Scope
);
10450 if Is_Dispatching_Operation
(Alias
(S
)) then
10451 Check_Dispatching_Operation
(S
, Empty
);
10457 Error_Msg_Sloc
:= Sloc
(E
);
10459 -- Generate message, with useful additional warning if in generic
10461 if Is_Generic_Unit
(E
) then
10462 Error_Msg_N
("previous generic unit cannot be overloaded", S
);
10463 Error_Msg_N
("\& conflicts with declaration#", S
);
10465 Error_Msg_N
("& conflicts with declaration#", S
);
10471 -- E exists and is overloadable
10474 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
10476 -- Loop through E and its homonyms to determine if any of them is
10477 -- the candidate for overriding by S.
10479 while Present
(E
) loop
10481 -- Definitely not interesting if not in the current scope
10483 if Scope
(E
) /= Current_Scope
then
10486 -- A function can overload the name of an abstract state. The
10487 -- state can be viewed as a function with a profile that cannot
10488 -- be matched by anything.
10490 elsif Ekind
(S
) = E_Function
10491 and then Ekind
(E
) = E_Abstract_State
10493 Enter_Overloaded_Entity
(S
);
10496 -- Ada 2012 (AI05-0165): For internally generated bodies of null
10497 -- procedures locate the internally generated spec. We enforce
10498 -- mode conformance since a tagged type may inherit from
10499 -- interfaces several null primitives which differ only in
10500 -- the mode of the formals.
10502 elsif not Comes_From_Source
(S
)
10503 and then Is_Null_Procedure
(S
)
10504 and then not Mode_Conformant
(E
, S
)
10508 -- Check if we have type conformance
10510 elsif Type_Conformant
(E
, S
) then
10512 -- If the old and new entities have the same profile and one
10513 -- is not the body of the other, then this is an error, unless
10514 -- one of them is implicitly declared.
10516 -- There are some cases when both can be implicit, for example
10517 -- when both a literal and a function that overrides it are
10518 -- inherited in a derivation, or when an inherited operation
10519 -- of a tagged full type overrides the inherited operation of
10520 -- a private extension. Ada 83 had a special rule for the
10521 -- literal case. In Ada 95, the later implicit operation hides
10522 -- the former, and the literal is always the former. In the
10523 -- odd case where both are derived operations declared at the
10524 -- same point, both operations should be declared, and in that
10525 -- case we bypass the following test and proceed to the next
10526 -- part. This can only occur for certain obscure cases in
10527 -- instances, when an operation on a type derived from a formal
10528 -- private type does not override a homograph inherited from
10529 -- the actual. In subsequent derivations of such a type, the
10530 -- DT positions of these operations remain distinct, if they
10533 if Present
(Alias
(S
))
10534 and then (No
(Alias
(E
))
10535 or else Comes_From_Source
(E
)
10536 or else Is_Abstract_Subprogram
(S
)
10538 (Is_Dispatching_Operation
(E
)
10539 and then Is_Overriding_Alias
(E
, S
)))
10540 and then Ekind
(E
) /= E_Enumeration_Literal
10542 -- When an derived operation is overloaded it may be due to
10543 -- the fact that the full view of a private extension
10544 -- re-inherits. It has to be dealt with.
10546 if Is_Package_Or_Generic_Package
(Current_Scope
)
10547 and then In_Private_Part
(Current_Scope
)
10549 Check_Operation_From_Private_View
(S
, E
);
10552 -- In any case the implicit operation remains hidden by the
10553 -- existing declaration, which is overriding. Indicate that
10554 -- E overrides the operation from which S is inherited.
10556 if Present
(Alias
(S
)) then
10557 Set_Overridden_Operation
(E
, Alias
(S
));
10559 Set_Overridden_Operation
(E
, S
);
10562 if Comes_From_Source
(E
) then
10563 Check_Overriding_Indicator
(E
, S
, Is_Primitive
=> False);
10568 -- Within an instance, the renaming declarations for actual
10569 -- subprograms may become ambiguous, but they do not hide each
10572 elsif Ekind
(E
) /= E_Entry
10573 and then not Comes_From_Source
(E
)
10574 and then not Is_Generic_Instance
(E
)
10575 and then (Present
(Alias
(E
))
10576 or else Is_Intrinsic_Subprogram
(E
))
10577 and then (not In_Instance
10578 or else No
(Parent
(E
))
10579 or else Nkind
(Unit_Declaration_Node
(E
)) /=
10580 N_Subprogram_Renaming_Declaration
)
10582 -- A subprogram child unit is not allowed to override an
10583 -- inherited subprogram (10.1.1(20)).
10585 if Is_Child_Unit
(S
) then
10587 ("child unit overrides inherited subprogram in parent",
10592 if Is_Non_Overriding_Operation
(E
, S
) then
10593 Enter_Overloaded_Entity
(S
);
10595 if No
(Derived_Type
)
10596 or else Is_Tagged_Type
(Derived_Type
)
10598 Check_Dispatching_Operation
(S
, Empty
);
10604 -- E is a derived operation or an internal operator which
10605 -- is being overridden. Remove E from further visibility.
10606 -- Furthermore, if E is a dispatching operation, it must be
10607 -- replaced in the list of primitive operations of its type
10608 -- (see Override_Dispatching_Operation).
10610 Overridden_Subp
:= E
;
10616 Prev
:= First_Entity
(Current_Scope
);
10617 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
10618 Next_Entity
(Prev
);
10621 -- It is possible for E to be in the current scope and
10622 -- yet not in the entity chain. This can only occur in a
10623 -- generic context where E is an implicit concatenation
10624 -- in the formal part, because in a generic body the
10625 -- entity chain starts with the formals.
10628 (Present
(Prev
) or else Chars
(E
) = Name_Op_Concat
);
10630 -- E must be removed both from the entity_list of the
10631 -- current scope, and from the visibility chain
10633 if Debug_Flag_E
then
10634 Write_Str
("Override implicit operation ");
10635 Write_Int
(Int
(E
));
10639 -- If E is a predefined concatenation, it stands for four
10640 -- different operations. As a result, a single explicit
10641 -- declaration does not hide it. In a possible ambiguous
10642 -- situation, Disambiguate chooses the user-defined op,
10643 -- so it is correct to retain the previous internal one.
10645 if Chars
(E
) /= Name_Op_Concat
10646 or else Ekind
(E
) /= E_Operator
10648 -- For nondispatching derived operations that are
10649 -- overridden by a subprogram declared in the private
10650 -- part of a package, we retain the derived subprogram
10651 -- but mark it as not immediately visible. If the
10652 -- derived operation was declared in the visible part
10653 -- then this ensures that it will still be visible
10654 -- outside the package with the proper signature
10655 -- (calls from outside must also be directed to this
10656 -- version rather than the overriding one, unlike the
10657 -- dispatching case). Calls from inside the package
10658 -- will still resolve to the overriding subprogram
10659 -- since the derived one is marked as not visible
10660 -- within the package.
10662 -- If the private operation is dispatching, we achieve
10663 -- the overriding by keeping the implicit operation
10664 -- but setting its alias to be the overriding one. In
10665 -- this fashion the proper body is executed in all
10666 -- cases, but the original signature is used outside
10669 -- If the overriding is not in the private part, we
10670 -- remove the implicit operation altogether.
10672 if Is_Private_Declaration
(S
) then
10673 if not Is_Dispatching_Operation
(E
) then
10674 Set_Is_Immediately_Visible
(E
, False);
10676 -- Work done in Override_Dispatching_Operation,
10677 -- so nothing else needs to be done here.
10683 -- Find predecessor of E in Homonym chain
10685 if E
= Current_Entity
(E
) then
10688 Prev_Vis
:= Current_Entity
(E
);
10689 while Homonym
(Prev_Vis
) /= E
loop
10690 Prev_Vis
:= Homonym
(Prev_Vis
);
10694 if Prev_Vis
/= Empty
then
10696 -- Skip E in the visibility chain
10698 Set_Homonym
(Prev_Vis
, Homonym
(E
));
10701 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
10704 Set_Next_Entity
(Prev
, Next_Entity
(E
));
10706 if No
(Next_Entity
(Prev
)) then
10707 Set_Last_Entity
(Current_Scope
, Prev
);
10712 Enter_Overloaded_Entity
(S
);
10714 -- For entities generated by Derive_Subprograms the
10715 -- overridden operation is the inherited primitive
10716 -- (which is available through the attribute alias).
10718 if not (Comes_From_Source
(E
))
10719 and then Is_Dispatching_Operation
(E
)
10720 and then Find_Dispatching_Type
(E
) =
10721 Find_Dispatching_Type
(S
)
10722 and then Present
(Alias
(E
))
10723 and then Comes_From_Source
(Alias
(E
))
10725 Set_Overridden_Operation
(S
, Alias
(E
));
10727 -- Normal case of setting entity as overridden
10729 -- Note: Static_Initialization and Overridden_Operation
10730 -- attributes use the same field in subprogram entities.
10731 -- Static_Initialization is only defined for internal
10732 -- initialization procedures, where Overridden_Operation
10733 -- is irrelevant. Therefore the setting of this attribute
10734 -- must check whether the target is an init_proc.
10736 elsif not Is_Init_Proc
(S
) then
10737 Set_Overridden_Operation
(S
, E
);
10740 Check_Overriding_Indicator
(S
, E
, Is_Primitive
=> True);
10742 -- If S is a user-defined subprogram or a null procedure
10743 -- expanded to override an inherited null procedure, or a
10744 -- predefined dispatching primitive then indicate that E
10745 -- overrides the operation from which S is inherited.
10747 if Comes_From_Source
(S
)
10749 (Present
(Parent
(S
))
10751 Nkind
(Parent
(S
)) = N_Procedure_Specification
10753 Null_Present
(Parent
(S
)))
10755 (Present
(Alias
(E
))
10757 Is_Predefined_Dispatching_Operation
(Alias
(E
)))
10759 if Present
(Alias
(E
)) then
10760 Set_Overridden_Operation
(S
, Alias
(E
));
10764 if Is_Dispatching_Operation
(E
) then
10766 -- An overriding dispatching subprogram inherits the
10767 -- convention of the overridden subprogram (AI-117).
10769 Set_Convention
(S
, Convention
(E
));
10770 Check_Dispatching_Operation
(S
, E
);
10773 Check_Dispatching_Operation
(S
, Empty
);
10776 Check_For_Primitive_Subprogram
10777 (Is_Primitive_Subp
, Is_Overriding
=> True);
10778 goto Check_Inequality
;
10781 -- Apparent redeclarations in instances can occur when two
10782 -- formal types get the same actual type. The subprograms in
10783 -- in the instance are legal, even if not callable from the
10784 -- outside. Calls from within are disambiguated elsewhere.
10785 -- For dispatching operations in the visible part, the usual
10786 -- rules apply, and operations with the same profile are not
10787 -- legal (B830001).
10789 elsif (In_Instance_Visible_Part
10790 and then not Is_Dispatching_Operation
(E
))
10791 or else In_Instance_Not_Visible
10795 -- Here we have a real error (identical profile)
10798 Error_Msg_Sloc
:= Sloc
(E
);
10800 -- Avoid cascaded errors if the entity appears in
10801 -- subsequent calls.
10803 Set_Scope
(S
, Current_Scope
);
10805 -- Generate error, with extra useful warning for the case
10806 -- of a generic instance with no completion.
10808 if Is_Generic_Instance
(S
)
10809 and then not Has_Completion
(E
)
10812 ("instantiation cannot provide body for&", S
);
10813 Error_Msg_N
("\& conflicts with declaration#", S
);
10815 Error_Msg_N
("& conflicts with declaration#", S
);
10822 -- If one subprogram has an access parameter and the other
10823 -- a parameter of an access type, calls to either might be
10824 -- ambiguous. Verify that parameters match except for the
10825 -- access parameter.
10827 if May_Hide_Profile
then
10833 F1
:= First_Formal
(S
);
10834 F2
:= First_Formal
(E
);
10835 while Present
(F1
) and then Present
(F2
) loop
10836 if Is_Access_Type
(Etype
(F1
)) then
10837 if not Is_Access_Type
(Etype
(F2
))
10838 or else not Conforming_Types
10839 (Designated_Type
(Etype
(F1
)),
10840 Designated_Type
(Etype
(F2
)),
10843 May_Hide_Profile
:= False;
10847 not Conforming_Types
10848 (Etype
(F1
), Etype
(F2
), Type_Conformant
)
10850 May_Hide_Profile
:= False;
10857 if May_Hide_Profile
10861 Error_Msg_NE
("calls to& may be ambiguous??", S
, S
);
10870 -- On exit, we know that S is a new entity
10872 Enter_Overloaded_Entity
(S
);
10873 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
10874 Check_Overriding_Indicator
10875 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
10877 -- Overloading is not allowed in SPARK, except for operators
10879 if Nkind
(S
) /= N_Defining_Operator_Symbol
then
10880 Error_Msg_Sloc
:= Sloc
(Homonym
(S
));
10881 Check_SPARK_Restriction
10882 ("overloading not allowed with entity#", S
);
10885 -- If S is a derived operation for an untagged type then by
10886 -- definition it's not a dispatching operation (even if the parent
10887 -- operation was dispatching), so Check_Dispatching_Operation is not
10888 -- called in that case.
10890 if No
(Derived_Type
)
10891 or else Is_Tagged_Type
(Derived_Type
)
10893 Check_Dispatching_Operation
(S
, Empty
);
10897 -- If this is a user-defined equality operator that is not a derived
10898 -- subprogram, create the corresponding inequality. If the operation is
10899 -- dispatching, the expansion is done elsewhere, and we do not create
10900 -- an explicit inequality operation.
10902 <<Check_Inequality
>>
10903 if Chars
(S
) = Name_Op_Eq
10904 and then Etype
(S
) = Standard_Boolean
10905 and then Present
(Parent
(S
))
10906 and then not Is_Dispatching_Operation
(S
)
10908 Make_Inequality_Operator
(S
);
10909 Check_Untagged_Equality
(S
);
10911 end New_Overloaded_Entity
;
10913 ---------------------
10914 -- Process_Formals --
10915 ---------------------
10917 procedure Process_Formals
10919 Related_Nod
: Node_Id
)
10921 Param_Spec
: Node_Id
;
10922 Formal
: Entity_Id
;
10923 Formal_Type
: Entity_Id
;
10927 Num_Out_Params
: Nat
:= 0;
10928 First_Out_Param
: Entity_Id
:= Empty
;
10929 -- Used for setting Is_Only_Out_Parameter
10931 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean;
10932 -- Determine whether an access type designates a type coming from a
10935 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean;
10936 -- Check whether the default has a class-wide type. After analysis the
10937 -- default has the type of the formal, so we must also check explicitly
10938 -- for an access attribute.
10940 ----------------------------------
10941 -- Designates_From_Limited_With --
10942 ----------------------------------
10944 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean is
10945 Desig
: Entity_Id
:= Typ
;
10948 if Is_Access_Type
(Desig
) then
10949 Desig
:= Directly_Designated_Type
(Desig
);
10952 if Is_Class_Wide_Type
(Desig
) then
10953 Desig
:= Root_Type
(Desig
);
10957 Ekind
(Desig
) = E_Incomplete_Type
10958 and then From_Limited_With
(Desig
);
10959 end Designates_From_Limited_With
;
10961 ---------------------------
10962 -- Is_Class_Wide_Default --
10963 ---------------------------
10965 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean is
10967 return Is_Class_Wide_Type
(Designated_Type
(Etype
(D
)))
10968 or else (Nkind
(D
) = N_Attribute_Reference
10969 and then Attribute_Name
(D
) = Name_Access
10970 and then Is_Class_Wide_Type
(Etype
(Prefix
(D
))));
10971 end Is_Class_Wide_Default
;
10973 -- Start of processing for Process_Formals
10976 -- In order to prevent premature use of the formals in the same formal
10977 -- part, the Ekind is left undefined until all default expressions are
10978 -- analyzed. The Ekind is established in a separate loop at the end.
10980 Param_Spec
:= First
(T
);
10981 while Present
(Param_Spec
) loop
10982 Formal
:= Defining_Identifier
(Param_Spec
);
10983 Set_Never_Set_In_Source
(Formal
, True);
10984 Enter_Name
(Formal
);
10986 -- Case of ordinary parameters
10988 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
10989 Find_Type
(Parameter_Type
(Param_Spec
));
10990 Ptype
:= Parameter_Type
(Param_Spec
);
10992 if Ptype
= Error
then
10996 Formal_Type
:= Entity
(Ptype
);
10998 if Is_Incomplete_Type
(Formal_Type
)
11000 (Is_Class_Wide_Type
(Formal_Type
)
11001 and then Is_Incomplete_Type
(Root_Type
(Formal_Type
)))
11003 -- Ada 2005 (AI-326): Tagged incomplete types allowed in
11004 -- primitive operations, as long as their completion is
11005 -- in the same declarative part. If in the private part
11006 -- this means that the type cannot be a Taft-amendment type.
11007 -- Check is done on package exit. For access to subprograms,
11008 -- the use is legal for Taft-amendment types.
11010 -- Ada 2012: tagged incomplete types are allowed as generic
11011 -- formal types. They do not introduce dependencies and the
11012 -- corresponding generic subprogram does not have a delayed
11013 -- freeze, because it does not need a freeze node.
11015 if Is_Tagged_Type
(Formal_Type
) then
11016 if Ekind
(Scope
(Current_Scope
)) = E_Package
11017 and then not From_Limited_With
(Formal_Type
)
11018 and then not Is_Generic_Type
(Formal_Type
)
11019 and then not Is_Class_Wide_Type
(Formal_Type
)
11022 (Parent
(T
), N_Access_Function_Definition
,
11023 N_Access_Procedure_Definition
)
11027 Private_Dependents
(Base_Type
(Formal_Type
)));
11029 -- Freezing is delayed to ensure that Register_Prim
11030 -- will get called for this operation, which is needed
11031 -- in cases where static dispatch tables aren't built.
11032 -- (Note that the same is done for controlling access
11033 -- parameter cases in function Access_Definition.)
11035 Set_Has_Delayed_Freeze
(Current_Scope
);
11039 -- Special handling of Value_Type for CIL case
11041 elsif Is_Value_Type
(Formal_Type
) then
11044 elsif not Nkind_In
(Parent
(T
), N_Access_Function_Definition
,
11045 N_Access_Procedure_Definition
)
11047 -- AI05-0151: Tagged incomplete types are allowed in all
11048 -- formal parts. Untagged incomplete types are not allowed
11051 if Ada_Version
>= Ada_2012
then
11052 if Is_Tagged_Type
(Formal_Type
) then
11055 elsif Nkind_In
(Parent
(Parent
(T
)), N_Accept_Statement
,
11060 ("invalid use of untagged incomplete type&",
11061 Ptype
, Formal_Type
);
11066 ("invalid use of incomplete type&",
11067 Param_Spec
, Formal_Type
);
11069 -- Further checks on the legality of incomplete types
11070 -- in formal parts are delayed until the freeze point
11071 -- of the enclosing subprogram or access to subprogram.
11075 elsif Ekind
(Formal_Type
) = E_Void
then
11077 ("premature use of&",
11078 Parameter_Type
(Param_Spec
), Formal_Type
);
11081 -- Ada 2012 (AI-142): Handle aliased parameters
11083 if Ada_Version
>= Ada_2012
11084 and then Aliased_Present
(Param_Spec
)
11086 Set_Is_Aliased
(Formal
);
11089 -- Ada 2005 (AI-231): Create and decorate an internal subtype
11090 -- declaration corresponding to the null-excluding type of the
11091 -- formal in the enclosing scope. Finally, replace the parameter
11092 -- type of the formal with the internal subtype.
11094 if Ada_Version
>= Ada_2005
11095 and then Null_Exclusion_Present
(Param_Spec
)
11097 if not Is_Access_Type
(Formal_Type
) then
11099 ("`NOT NULL` allowed only for an access type", Param_Spec
);
11102 if Can_Never_Be_Null
(Formal_Type
)
11103 and then Comes_From_Source
(Related_Nod
)
11106 ("`NOT NULL` not allowed (& already excludes null)",
11107 Param_Spec
, Formal_Type
);
11111 Create_Null_Excluding_Itype
11113 Related_Nod
=> Related_Nod
,
11114 Scope_Id
=> Scope
(Current_Scope
));
11116 -- If the designated type of the itype is an itype that is
11117 -- not frozen yet, we set the Has_Delayed_Freeze attribute
11118 -- on the access subtype, to prevent order-of-elaboration
11119 -- issues in the backend.
11122 -- type T is access procedure;
11123 -- procedure Op (O : not null T);
11125 if Is_Itype
(Directly_Designated_Type
(Formal_Type
))
11127 not Is_Frozen
(Directly_Designated_Type
(Formal_Type
))
11129 Set_Has_Delayed_Freeze
(Formal_Type
);
11134 -- An access formal type
11138 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
11140 -- No need to continue if we already notified errors
11142 if not Present
(Formal_Type
) then
11146 -- Ada 2005 (AI-254)
11149 AD
: constant Node_Id
:=
11150 Access_To_Subprogram_Definition
11151 (Parameter_Type
(Param_Spec
));
11153 if Present
(AD
) and then Protected_Present
(AD
) then
11155 Replace_Anonymous_Access_To_Protected_Subprogram
11161 Set_Etype
(Formal
, Formal_Type
);
11163 -- Deal with default expression if present
11165 Default
:= Expression
(Param_Spec
);
11167 if Present
(Default
) then
11168 Check_SPARK_Restriction
11169 ("default expression is not allowed", Default
);
11171 if Out_Present
(Param_Spec
) then
11173 ("default initialization only allowed for IN parameters",
11177 -- Do the special preanalysis of the expression (see section on
11178 -- "Handling of Default Expressions" in the spec of package Sem).
11180 Preanalyze_Spec_Expression
(Default
, Formal_Type
);
11182 -- An access to constant cannot be the default for
11183 -- an access parameter that is an access to variable.
11185 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
11186 and then not Is_Access_Constant
(Formal_Type
)
11187 and then Is_Access_Type
(Etype
(Default
))
11188 and then Is_Access_Constant
(Etype
(Default
))
11191 ("formal that is access to variable cannot be initialized " &
11192 "with an access-to-constant expression", Default
);
11195 -- Check that the designated type of an access parameter's default
11196 -- is not a class-wide type unless the parameter's designated type
11197 -- is also class-wide.
11199 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
11200 and then not Designates_From_Limited_With
(Formal_Type
)
11201 and then Is_Class_Wide_Default
(Default
)
11202 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
11205 ("access to class-wide expression not allowed here", Default
);
11208 -- Check incorrect use of dynamically tagged expressions
11210 if Is_Tagged_Type
(Formal_Type
) then
11211 Check_Dynamically_Tagged_Expression
11213 Typ
=> Formal_Type
,
11214 Related_Nod
=> Default
);
11218 -- Ada 2005 (AI-231): Static checks
11220 if Ada_Version
>= Ada_2005
11221 and then Is_Access_Type
(Etype
(Formal
))
11222 and then Can_Never_Be_Null
(Etype
(Formal
))
11224 Null_Exclusion_Static_Checks
(Param_Spec
);
11227 -- The following checks are relevant when SPARK_Mode is on as these
11228 -- are not standard Ada legality rules.
11231 and then Ekind_In
(Scope
(Formal
), E_Function
, E_Generic_Function
)
11233 -- A function cannot have a parameter of mode IN OUT or OUT
11235 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_Out_Parameter
) then
11237 ("function cannot have parameter of mode `OUT` or `IN OUT` "
11238 & "(SPARK RM 6.1)", Formal
);
11240 -- A function cannot have a volatile formal parameter
11242 elsif Is_SPARK_Volatile_Object
(Formal
) then
11244 ("function cannot have a volatile formal parameter (SPARK RM "
11245 & "7.1.3(10))", Formal
);
11253 -- If this is the formal part of a function specification, analyze the
11254 -- subtype mark in the context where the formals are visible but not
11255 -- yet usable, and may hide outer homographs.
11257 if Nkind
(Related_Nod
) = N_Function_Specification
then
11258 Analyze_Return_Type
(Related_Nod
);
11261 -- Now set the kind (mode) of each formal
11263 Param_Spec
:= First
(T
);
11264 while Present
(Param_Spec
) loop
11265 Formal
:= Defining_Identifier
(Param_Spec
);
11266 Set_Formal_Mode
(Formal
);
11268 if Ekind
(Formal
) = E_In_Parameter
then
11269 Set_Default_Value
(Formal
, Expression
(Param_Spec
));
11271 if Present
(Expression
(Param_Spec
)) then
11272 Default
:= Expression
(Param_Spec
);
11274 if Is_Scalar_Type
(Etype
(Default
)) then
11275 if Nkind
(Parameter_Type
(Param_Spec
)) /=
11276 N_Access_Definition
11278 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
11282 (Related_Nod
, Parameter_Type
(Param_Spec
));
11285 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
11289 elsif Ekind
(Formal
) = E_Out_Parameter
then
11290 Num_Out_Params
:= Num_Out_Params
+ 1;
11292 if Num_Out_Params
= 1 then
11293 First_Out_Param
:= Formal
;
11296 elsif Ekind
(Formal
) = E_In_Out_Parameter
then
11297 Num_Out_Params
:= Num_Out_Params
+ 1;
11300 -- Skip remaining processing if formal type was in error
11302 if Etype
(Formal
) = Any_Type
or else Error_Posted
(Formal
) then
11303 goto Next_Parameter
;
11306 -- Force call by reference if aliased
11308 if Is_Aliased
(Formal
) then
11309 Set_Mechanism
(Formal
, By_Reference
);
11311 -- Warn if user asked this to be passed by copy
11313 if Convention
(Formal_Type
) = Convention_Ada_Pass_By_Copy
then
11315 ("cannot pass aliased parameter & by copy?", Formal
);
11318 -- Force mechanism if type has Convention Ada_Pass_By_Ref/Copy
11320 elsif Convention
(Formal_Type
) = Convention_Ada_Pass_By_Copy
then
11321 Set_Mechanism
(Formal
, By_Copy
);
11323 elsif Convention
(Formal_Type
) = Convention_Ada_Pass_By_Reference
then
11324 Set_Mechanism
(Formal
, By_Reference
);
11331 if Present
(First_Out_Param
) and then Num_Out_Params
= 1 then
11332 Set_Is_Only_Out_Parameter
(First_Out_Param
);
11334 end Process_Formals
;
11336 ----------------------------
11337 -- Reference_Body_Formals --
11338 ----------------------------
11340 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
) is
11345 if Error_Posted
(Spec
) then
11349 -- Iterate over both lists. They may be of different lengths if the two
11350 -- specs are not conformant.
11352 Fs
:= First_Formal
(Spec
);
11353 Fb
:= First_Formal
(Bod
);
11354 while Present
(Fs
) and then Present
(Fb
) loop
11355 Generate_Reference
(Fs
, Fb
, 'b');
11357 if Style_Check
then
11358 Style
.Check_Identifier
(Fb
, Fs
);
11361 Set_Spec_Entity
(Fb
, Fs
);
11362 Set_Referenced
(Fs
, False);
11366 end Reference_Body_Formals
;
11368 -------------------------
11369 -- Set_Actual_Subtypes --
11370 -------------------------
11372 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
11374 Formal
: Entity_Id
;
11376 First_Stmt
: Node_Id
:= Empty
;
11377 AS_Needed
: Boolean;
11380 -- If this is an empty initialization procedure, no need to create
11381 -- actual subtypes (small optimization).
11383 if Ekind
(Subp
) = E_Procedure
and then Is_Null_Init_Proc
(Subp
) then
11387 Formal
:= First_Formal
(Subp
);
11388 while Present
(Formal
) loop
11389 T
:= Etype
(Formal
);
11391 -- We never need an actual subtype for a constrained formal
11393 if Is_Constrained
(T
) then
11394 AS_Needed
:= False;
11396 -- If we have unknown discriminants, then we do not need an actual
11397 -- subtype, or more accurately we cannot figure it out. Note that
11398 -- all class-wide types have unknown discriminants.
11400 elsif Has_Unknown_Discriminants
(T
) then
11401 AS_Needed
:= False;
11403 -- At this stage we have an unconstrained type that may need an
11404 -- actual subtype. For sure the actual subtype is needed if we have
11405 -- an unconstrained array type.
11407 elsif Is_Array_Type
(T
) then
11410 -- The only other case needing an actual subtype is an unconstrained
11411 -- record type which is an IN parameter (we cannot generate actual
11412 -- subtypes for the OUT or IN OUT case, since an assignment can
11413 -- change the discriminant values. However we exclude the case of
11414 -- initialization procedures, since discriminants are handled very
11415 -- specially in this context, see the section entitled "Handling of
11416 -- Discriminants" in Einfo.
11418 -- We also exclude the case of Discrim_SO_Functions (functions used
11419 -- in front end layout mode for size/offset values), since in such
11420 -- functions only discriminants are referenced, and not only are such
11421 -- subtypes not needed, but they cannot always be generated, because
11422 -- of order of elaboration issues.
11424 elsif Is_Record_Type
(T
)
11425 and then Ekind
(Formal
) = E_In_Parameter
11426 and then Chars
(Formal
) /= Name_uInit
11427 and then not Is_Unchecked_Union
(T
)
11428 and then not Is_Discrim_SO_Function
(Subp
)
11432 -- All other cases do not need an actual subtype
11435 AS_Needed
:= False;
11438 -- Generate actual subtypes for unconstrained arrays and
11439 -- unconstrained discriminated records.
11442 if Nkind
(N
) = N_Accept_Statement
then
11444 -- If expansion is active, the formal is replaced by a local
11445 -- variable that renames the corresponding entry of the
11446 -- parameter block, and it is this local variable that may
11447 -- require an actual subtype.
11449 if Expander_Active
then
11450 Decl
:= Build_Actual_Subtype
(T
, Renamed_Object
(Formal
));
11452 Decl
:= Build_Actual_Subtype
(T
, Formal
);
11455 if Present
(Handled_Statement_Sequence
(N
)) then
11457 First
(Statements
(Handled_Statement_Sequence
(N
)));
11458 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
11459 Mark_Rewrite_Insertion
(Decl
);
11461 -- If the accept statement has no body, there will be no
11462 -- reference to the actuals, so no need to compute actual
11469 Decl
:= Build_Actual_Subtype
(T
, Formal
);
11470 Prepend
(Decl
, Declarations
(N
));
11471 Mark_Rewrite_Insertion
(Decl
);
11474 -- The declaration uses the bounds of an existing object, and
11475 -- therefore needs no constraint checks.
11477 Analyze
(Decl
, Suppress
=> All_Checks
);
11479 -- We need to freeze manually the generated type when it is
11480 -- inserted anywhere else than in a declarative part.
11482 if Present
(First_Stmt
) then
11483 Insert_List_Before_And_Analyze
(First_Stmt
,
11484 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
11486 -- Ditto if the type has a dynamic predicate, because the
11487 -- generated function will mention the actual subtype.
11489 elsif Has_Dynamic_Predicate_Aspect
(T
) then
11490 Insert_List_Before_And_Analyze
(Decl
,
11491 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
11494 if Nkind
(N
) = N_Accept_Statement
11495 and then Expander_Active
11497 Set_Actual_Subtype
(Renamed_Object
(Formal
),
11498 Defining_Identifier
(Decl
));
11500 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
11504 Next_Formal
(Formal
);
11506 end Set_Actual_Subtypes
;
11508 ---------------------
11509 -- Set_Formal_Mode --
11510 ---------------------
11512 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
11513 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
11516 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
11517 -- since we ensure that corresponding actuals are always valid at the
11518 -- point of the call.
11520 if Out_Present
(Spec
) then
11521 if Ekind
(Scope
(Formal_Id
)) = E_Function
11522 or else Ekind
(Scope
(Formal_Id
)) = E_Generic_Function
11524 -- [IN] OUT parameters allowed for functions in Ada 2012
11526 if Ada_Version
>= Ada_2012
then
11528 -- Even in Ada 2012 operators can only have IN parameters
11530 if Is_Operator_Symbol_Name
(Chars
(Scope
(Formal_Id
))) then
11531 Error_Msg_N
("operators can only have IN parameters", Spec
);
11534 if In_Present
(Spec
) then
11535 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
11537 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
11540 -- But not in earlier versions of Ada
11543 Error_Msg_N
("functions can only have IN parameters", Spec
);
11544 Set_Ekind
(Formal_Id
, E_In_Parameter
);
11547 elsif In_Present
(Spec
) then
11548 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
11551 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
11552 Set_Never_Set_In_Source
(Formal_Id
, True);
11553 Set_Is_True_Constant
(Formal_Id
, False);
11554 Set_Current_Value
(Formal_Id
, Empty
);
11558 Set_Ekind
(Formal_Id
, E_In_Parameter
);
11561 -- Set Is_Known_Non_Null for access parameters since the language
11562 -- guarantees that access parameters are always non-null. We also set
11563 -- Can_Never_Be_Null, since there is no way to change the value.
11565 if Nkind
(Parameter_Type
(Spec
)) = N_Access_Definition
then
11567 -- Ada 2005 (AI-231): In Ada 95, access parameters are always non-
11568 -- null; In Ada 2005, only if then null_exclusion is explicit.
11570 if Ada_Version
< Ada_2005
11571 or else Can_Never_Be_Null
(Etype
(Formal_Id
))
11573 Set_Is_Known_Non_Null
(Formal_Id
);
11574 Set_Can_Never_Be_Null
(Formal_Id
);
11577 -- Ada 2005 (AI-231): Null-exclusion access subtype
11579 elsif Is_Access_Type
(Etype
(Formal_Id
))
11580 and then Can_Never_Be_Null
(Etype
(Formal_Id
))
11582 Set_Is_Known_Non_Null
(Formal_Id
);
11584 -- We can also set Can_Never_Be_Null (thus preventing some junk
11585 -- access checks) for the case of an IN parameter, which cannot
11586 -- be changed, or for an IN OUT parameter, which can be changed but
11587 -- not to a null value. But for an OUT parameter, the initial value
11588 -- passed in can be null, so we can't set this flag in that case.
11590 if Ekind
(Formal_Id
) /= E_Out_Parameter
then
11591 Set_Can_Never_Be_Null
(Formal_Id
);
11595 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
11596 Set_Formal_Validity
(Formal_Id
);
11597 end Set_Formal_Mode
;
11599 -------------------------
11600 -- Set_Formal_Validity --
11601 -------------------------
11603 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
11605 -- If no validity checking, then we cannot assume anything about the
11606 -- validity of parameters, since we do not know there is any checking
11607 -- of the validity on the call side.
11609 if not Validity_Checks_On
then
11612 -- If validity checking for parameters is enabled, this means we are
11613 -- not supposed to make any assumptions about argument values.
11615 elsif Validity_Check_Parameters
then
11618 -- If we are checking in parameters, we will assume that the caller is
11619 -- also checking parameters, so we can assume the parameter is valid.
11621 elsif Ekind
(Formal_Id
) = E_In_Parameter
11622 and then Validity_Check_In_Params
11624 Set_Is_Known_Valid
(Formal_Id
, True);
11626 -- Similar treatment for IN OUT parameters
11628 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
11629 and then Validity_Check_In_Out_Params
11631 Set_Is_Known_Valid
(Formal_Id
, True);
11633 end Set_Formal_Validity
;
11635 ------------------------
11636 -- Subtype_Conformant --
11637 ------------------------
11639 function Subtype_Conformant
11640 (New_Id
: Entity_Id
;
11641 Old_Id
: Entity_Id
;
11642 Skip_Controlling_Formals
: Boolean := False) return Boolean
11646 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
,
11647 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
11649 end Subtype_Conformant
;
11651 ---------------------
11652 -- Type_Conformant --
11653 ---------------------
11655 function Type_Conformant
11656 (New_Id
: Entity_Id
;
11657 Old_Id
: Entity_Id
;
11658 Skip_Controlling_Formals
: Boolean := False) return Boolean
11662 May_Hide_Profile
:= False;
11665 (New_Id
, Old_Id
, Type_Conformant
, False, Result
,
11666 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
11668 end Type_Conformant
;
11670 -------------------------------
11671 -- Valid_Operator_Definition --
11672 -------------------------------
11674 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
11677 Id
: constant Name_Id
:= Chars
(Designator
);
11681 F
:= First_Formal
(Designator
);
11682 while Present
(F
) loop
11685 if Present
(Default_Value
(F
)) then
11687 ("default values not allowed for operator parameters",
11694 -- Verify that user-defined operators have proper number of arguments
11695 -- First case of operators which can only be unary
11697 if Nam_In
(Id
, Name_Op_Not
, Name_Op_Abs
) then
11700 -- Case of operators which can be unary or binary
11702 elsif Nam_In
(Id
, Name_Op_Add
, Name_Op_Subtract
) then
11703 N_OK
:= (N
in 1 .. 2);
11705 -- All other operators can only be binary
11713 ("incorrect number of arguments for operator", Designator
);
11717 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
11718 and then not Is_Intrinsic_Subprogram
(Designator
)
11721 ("explicit definition of inequality not allowed", Designator
);
11723 end Valid_Operator_Definition
;